/**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_INVCOUNTBILLENTRY_X' AND KSQL_COL_NAME ='FSRCBILLENTITY') 
 ALTER TABLE T_IM_INVCOUNTBILLENTRY_X ADD (FSRCBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_INVCOUNTBILLENTRY_X' AND KSQL_COL_NAME ='FSRCBILLID') 
 ALTER TABLE T_IM_INVCOUNTBILLENTRY_X ADD (FSRCBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_INVCOUNTBILLENTRY_X' AND KSQL_COL_NAME ='FSRCBILLENTRYID') 
 ALTER TABLE T_IM_INVCOUNTBILLENTRY_X ADD (FSRCBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_ADJUSTBILL') 
 CREATE TABLE T_IM_ADJUSTBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(60) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FBIZTYPEID BIGINT DEFAULT 0 NOT NULL,
FBIZTIME DATETIME,
FDEPTID BIGINT DEFAULT 0 NOT NULL,
FOPERATORID BIGINT DEFAULT 0 NOT NULL,
FOPERATORGROUPID BIGINT DEFAULT 0 NOT NULL,
FBILLTYPEID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_ADJUSTBILLENTRY') 
 CREATE TABLE T_IM_ADJUSTBILLENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID 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,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOMMENT NVARCHAR(100) DEFAULT ' ' NOT NULL,
FINVACCID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_ADJUSTBILLSUBENTRY') 
 CREATE TABLE T_IM_ADJUSTBILLSUBENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FINVTYPE BIGINT DEFAULT 0 NOT NULL,
FINVSTATUS BIGINT DEFAULT 0 NOT NULL,
FOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOWNER BIGINT DEFAULT 0 NOT NULL,
FKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FKEEPER BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOMMENT NVARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME ='FVERIFYQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVERIFYQTY 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 ='FVERIFYBASEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FVERIFYBASEQTY 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 ='FUNVERIFYQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FUNVERIFYQTY 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 ='FUNVERIFYBASEQTY') 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FUNVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVERIFYQTY') 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FVERIFYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME ='FVERIFYBASEQTY') 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME ='FUNVERIFYQTY') 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FUNVERIFYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME ='FUNVERIFYBASEQTY') 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FUNVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );

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