/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INV_REALBALANCE') 
 CREATE TABLE T_IM_INV_REALBALANCE (
FID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FOWNERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FKEEPERTYPE VARCHAR(20) DEFAULT ' ' NOT NULL,
FKEEPERID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FLOTNUM NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_INV_REALBALANCE_SP') 
 CREATE TABLE T_IM_INV_REALBALANCE_SP (
FID BIGINT DEFAULT 0 NOT NULL,
FKEYCOL VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLNAME VARCHAR(50) DEFAULT ' ' NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FUPDATETIME BIGINT DEFAULT 0 NOT NULL,
FISNEW CHAR(1) DEFAULT '0' NOT NULL,
FSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
FUPDATETYPE INT DEFAULT 1 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY_SP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTY2ND_SP DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_TRANSDIRBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PRODUCTINBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_PRODUCTINBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_MREQOUTBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_TRANSOUTBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ADJUSTBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_ADJUSTBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_ASSEMBBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_ASSEMBBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_LOCATIONTRANSFER' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_LOCATIONTRANSFER ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_SALOUTBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHEROUTBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_OTHEROUTBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_OTHERINBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_OTHERINBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILL' AND KSQL_COL_NAME ='FASYNCSTATUS') 
 ALTER TABLE T_IM_PURRECBILL ADD (FASYNCSTATUS CHAR(1) DEFAULT 'B' NOT NULL );

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