/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_WAREHOUSESETUP' AND KSQL_COL_NAME ='FSETUPTIME') 
 ALTER TABLE T_IM_WAREHOUSESETUP ADD (FSETUPTIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVMISETTLEQTY') 
 ALTER TABLE T_IM_MREQOUTBILLENTRY_R ADD (FVMISETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVMISETTLEBASEQTY') 
 ALTER TABLE T_IM_MREQOUTBILLENTRY_R ADD (FVMISETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVMIREMAINSETTLEQTY') 
 ALTER TABLE T_IM_MREQOUTBILLENTRY_R ADD (FVMIREMAINSETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVMIREMAINSETTLEBASEQTY') 
 ALTER TABLE T_IM_MREQOUTBILLENTRY_R ADD (FVMIREMAINSETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME ='FVMISETTLEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVMISETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME ='FVMISETTLEBASEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVMISETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME ='FVMIREMAINSETTLEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVMIREMAINSETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME ='FVMIREMAINSETTLEBASEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVMIREMAINSETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_CLOSEACCTRECORD') 
 CREATE TABLE T_IM_CLOSEACCTRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FCLOSEDATE DATETIME,
FISDELETE CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INVBALANCE') 
 CREATE TABLE T_IM_INVBALANCE (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FKEEPERID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FUNIT3RDID BIGINT DEFAULT 0 NOT NULL,
FBGNQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBGNBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBGNQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBGNQTY3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINQTY3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTQTY3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENDBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENDQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENDQTY3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSTARTDATE DATETIME,
FENDDATE DATETIME,
FDIMSTR NVARCHAR(1200) DEFAULT ' ' NOT NULL,
FISINIT CHAR(1) DEFAULT ' ' NOT NULL,
FDIMMD5STR VARCHAR(36) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INVSNAPSHOOT') 
 CREATE TABLE T_IM_INVSNAPSHOOT (
FID BIGINT DEFAULT 0 NOT NULL,
FBIZTIME DATETIME,
FFORMID NVARCHAR(100) DEFAULT ' ' NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FDIMSTR NVARCHAR(1200) DEFAULT ' ' NOT NULL,
FDIMMD5STR VARCHAR(36) DEFAULT ' ' NOT NULL
);



/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
