<?
include "connect_mysql.php";

$sql1 = " CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`user_tb` ( ";
$sql1 .= " `userid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , "; //id
$sql1 .= " `usercode` VARCHAR(10) NOT NULL , "; //code *
$sql1 .= " `usernameth` VARCHAR(150)  NULL  , ";
$sql1 .= " `userlnameth` VARCHAR(150)  NULL , ";
$sql1 .= " `usernameen` VARCHAR(150)  NULL , ";
$sql1 .= " `userlnameen` VARCHAR(150)  NULL , ";
$sql1 .= " `usersex` VARCHAR(10)  NULL , "; // เพศ *
$sql1 .= " `userposition` INT  NULL , "; // ตำแหน่งงาน *
$sql1 .= " `userdepartment` INT  NULL , "; //แผนก , ฝ่าย *
$sql1 .= " `usercompany` INT  NULL , "; //สังกัดบริษัท ยงเฮาส์, ยงคอนกรีต, พร้อมขนส่ง, ทั้งหมด *
$sql1 .= " `userbranch` INT  NULL , ";
$sql1 .= " `userloginname` VARCHAR(10)  NULL , ";
$sql1 .= " `userpassword` VARCHAR(10)  NULL , ";
$sql1 .= " `userpin` VARCHAR(6)  NULL , "; //pin สำหรับเข้าสู่ระบบ*
$sql1 .= " `userpicpath` TEXT  NULL , ";
$sql1 .= " `createby` VARCHAR(300)  NULL , ";
$sql1 .= " `createtime` DATETIME  NULL , ";
$sql1 .= " `updateby` VARCHAR(300)  NULL , ";
$sql1 .= " `updatetime` DATETIME  NULL , ";
$sql1 .= " `statustrans` VARCHAR(50)  NULL , "; //สถานะการโอนข้อมูลอัตโนมัติ N, Y
$sql1 .= " `statonline` VARCHAR(50)  NULL , ";
$sql1 .= " `lasttimeonline` DATETIME  NULL , ";
$sql1 .= " `remark` TEXT  NULL , ";
$sql1 .= "  INDEX(usercode,usersex,userposition,userdepartment,usercompany,userpin,statustrans) ";
$sql1 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

 $create_tb1 = mysql_query($sql1) or die(mysql_error());


$sql2 = " CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`position_tb` ( ";
$sql2 .= " `posid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
$sql2 .= " `poscode` VARCHAR( 10 )  NULL , ";
$sql2 .= " `posname` VARCHAR( 150 )  NULL , ";
$sql2 .= " `posremark` TEXT  NULL , ";
$sql2 .= " `poscreateby` VARCHAR(300)  NULL , ";
$sql2 .= " `poscreatetime` DATETIME  NULL , ";
$sql2 .= " `posupdateby` VARCHAR(300)  NULL , ";
$sql2 .= " `posupdatetime` DATETIME  NULL , ";
$sql2 .= " `posstatus` VARCHAR(1)  NOT NULL DEFAULT  'Y' COMMENT  'Y = มีตำแหน่งอยู่  N = ตำแหน่งถูกปิดแล้ว'  ";
$sql2 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

 $create_tb2 = mysql_query($sql2) or die(mysql_error());


 $sql3 = " CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`company_tb` ( ";
 $sql3 .= " `compid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
 $sql3 .= " `compcode` VARCHAR( 10 ) NULL , ";
 $sql3 .= " `compnameth` VARCHAR( 150 )  NULL , ";
 $sql3 .= " `compnameen` VARCHAR( 150 )  NULL , ";
 $sql3 .= " `compmark` TEXT  NULL , ";
 $sql3 .= " `compcreateby` VARCHAR( 300 )  NULL , ";
 $sql3 .= " `compcreatetime` DATETIME  NULL , ";
 $sql3 .= " `compupdateby` VARCHAR( 300 )  NULL , ";
 $sql3 .= " `compupdatetime` DATETIME  NULL , ";
 $sql3 .= " `compstatus` VARCHAR( 1 )  NOT NULL DEFAULT  'Y' COMMENT  'Y = เปิดทำการปกติ  N = หยุดทำการ' ";
 $sql3 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

  $create_tb3 = mysql_query($sql3) or die(mysql_error());

  $sql4 = " CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`branch_tb` ( ";
  $sql4 .= " `branid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
  $sql4 .= " `brancode` VARCHAR( 10 ) NULL , ";
  $sql4 .= " `branname` VARCHAR( 150 )  NULL , ";
  $sql4 .= " `branmark` TEXT  NULL , ";
  $sql4 .= " `brancomid` INT  NULL , ";
  $sql4 .= " `brancreateby` VARCHAR( 300 )  NULL , ";
  $sql4 .= " `brancreatetime` DATETIME  NULL , ";
  $sql4 .= " `branupdateby` VARCHAR( 300 )  NULL , ";
  $sql4 .= " `branupdatetime` DATETIME  NULL , ";
  $sql4 .= " `branstatus` VARCHAR( 1 )  NOT NULL DEFAULT  'Y' COMMENT  'Y = เปิดทำการปกติ  N = หยุดทำการ'  ";
  $sql4 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

   $create_tb4 = mysql_query($sql4) or die(mysql_error());


   $sql5 = " CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`department_tb` ( ";
   $sql5 .= " `dpmid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
   $sql5 .= " `dpmcode` VARCHAR( 10 ) NULL , ";
   $sql5 .= " `dpmname` VARCHAR( 150 )  NULL , ";
   $sql5 .= " `dpmmark` TEXT  NULL , ";
   $sql5 .= " `dpmcreateby` VARCHAR( 300 )  NULL , ";
   $sql5 .= " `dpmcreatetime` DATETIME  NULL , ";
   $sql5 .= " `dpmupdateby` VARCHAR( 300 )  NULL , ";
   $sql5 .= " `dpmupdatetime` DATETIME  NULL , ";
   $sql5 .= " `dpmstatus` VARCHAR( 1 )  NOT NULL DEFAULT  'Y' COMMENT  'Y = มีแผนกอยู่  N = แผนกถูกยุบแล้ว'  ";
   $sql5 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

    $create_tb5 = mysql_query($sql5) or die(mysql_error());
//----------------------------------------------------------------------------------------------
   $sql6 = "CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`group_tb` (";
   $sql6.=  "`GroupID` INT(4) NOT NULL AUTO_INCREMENT ,";
   $sql6.=  "`GroupName` VARCHAR(100) NULL ,";
   $sql6.=  "`GroupCreateTime` DATETIME NULL ,";
   $sql6.=  "`GroupCreateBy` VARCHAR(60) NULL ,";
   $sql6.=  "`GroupUpdateTime` DATETIME NULL ,";
   $sql6.=  "`GroupUpdateBy` VARCHAR(60) NULL ,";
   $sql6.=  "PRIMARY KEY (`GroupID`)  ) ";
   $sql6.=  "ENGINE = InnoDB ";
   $sql6.=  "DEFAULT CHARACTER SET = utf8 ";
   $sql6.=  "COLLATE = utf8_general_ci";

    $create_tb6 = mysql_query($sql6) or die(mysql_error());

   $sql7 = "CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`report_tb` (";
   $sql7.= "  `repID` INT(4) NOT NULL AUTO_INCREMENT ,";
   $sql7.= "  `repName` VARCHAR(100) NULL ,";
   $sql7.= "  `repLink` TEXT NULL ,";
   $sql7.= "  `repCreateTime` DATETIME NULL ,";
   $sql7.= "  `repCreateBy` VARCHAR(60) NULL ,";
   $sql7.= "  `repUpdateTime` DATETIME NULL ,";
   $sql7.= "  `repUpdateBy` VARCHAR(60) NULL ,";
   $sql7.= "  PRIMARY KEY (`repID`)  )";
   $sql7.= "  ENGINE = InnoDB";
   $sql7.= "  DEFAULT CHARACTER SET = utf8";
   $sql7.= "  COLLATE = utf8_general_ci";

    $create_tb7 = mysql_query($sql7) or die(mysql_error());

   $sql8 = "CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`groupreport_tb` (";
   $sql8.= " `groprpID` INT(4) NOT NULL AUTO_INCREMENT,";
   $sql8.= " `groprpRepID` INT(4) NULL ,";
   $sql8.= " `groprpGTeamID` INT(4) NULL ,";
   $sql8.= " `groprpCreateTime` DATETIME NULL ,";
   $sql8.= " `groprpCreateBy` VARCHAR(60) NULL ,";
   $sql8.= " `groprpUpdateTime` DATETIME NULL ,";
   $sql8.= " `groprpUpdateBy` VARCHAR(60) NULL ,";
   $sql8.= " PRIMARY KEY (`groprpID`)  )";
   $sql8.= " ENGINE = InnoDB";
   $sql8.= " DEFAULT CHARACTER SET = utf8";
   $sql8.= " COLLATE = utf8_general_ci";

    $create_tb8 = mysql_query($sql8) or die(mysql_error());

    $sql9 = "CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`groupteam_tb` (";
    $sql9.= " `groptID` INT NOT NULL AUTO_INCREMENT ,";
    $sql9.= " `groptUserID` INT NULL ,";
    $sql9.= " `groptGroupID` INT NULL ,";
    $sql9.= " `groptCreateTime` DATETIME NULL ,";
    $sql9.= " `groptCreateBy` VARCHAR(60) NULL ,";
    $sql9.= " `groptUpdateTime` DATETIME NULL ,";
    $sql9.= " `groptUpdateBy` VARCHAR(60) NULL ,";
    $sql9.= " PRIMARY KEY (`groptID`)  )";
    $sql9.= " ENGINE = InnoDB";
    $sql9.= " DEFAULT CHARACTER SET = utf8";
    $sql9.= " COLLATE = utf8_general_ci ";

    $create_tb9 = mysql_query($sql9) or die(mysql_error());
	
	$sql10 = "CREATE TABLE IF NOT EXISTS `intrayon_yongbi`.`dashboard_tb` (";
    $sql10.= " `daboid` INT NOT NULL AUTO_INCREMENT ,";
    $sql10.= " `dabouserid` INT NULL ,";
    $sql10.= " `dabowindowid` INT NULL ,"; // 1 , 2
    $sql10.= " `daboreptid` INT NULL ,";  
    $sql10.= " `groptcreatetime` DATETIME NULL ,";
    $sql10.= " `groptcreateby` VARCHAR(60) NULL ,";
    $sql10.= " `groptupdatetime` DATETIME NULL ,";
    $sql10.= " `groptupdateby` VARCHAR(60) NULL ,";
    $sql10.= " PRIMARY KEY (`daboid`)  )";
    $sql10.= " ENGINE = InnoDB";
    $sql10.= " DEFAULT CHARACTER SET = utf8";
    $sql10.= " COLLATE = utf8_general_ci ";

    $create_tb10 = mysql_query($sql10) or die(mysql_error());

    $sql11 = " CREATE TABLE IF NOT EXISTS `history_tb` ( ";
    $sql11 .= " `histid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , ";
    $sql11 .= " `histuserid` INT( 11 ) NULL , ";
    $sql11 .= " `histlogin` DATETIME  NULL , ";
    $sql11 .= " `histlogout` DATETIME  NULL , ";
    $sql11 .= "  INDEX(histuserid) ";
    $sql11 .= " ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci ";

   $create_tb11 = mysql_query($sql11) or die(mysql_error());	

mysql_close($c);
?>
