/**Begin D:\nextcloud\dev2main2bizline\PDM_UPGRADE\pdm1\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLNUMBER')) 
 ALTER TABLE T_IM_TRANSINBILLENTRY_R ADD (FMAINBILLNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYSEQ')) 
 ALTER TABLE T_IM_TRANSINBILLENTRY_R ADD (FMAINBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTITY')) 
 ALTER TABLE T_IM_TRANSINBILLENTRY_R ADD (FMAINBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLID')) 
 ALTER TABLE T_IM_TRANSINBILLENTRY_R ADD (FMAINBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYID')) 
 ALTER TABLE T_IM_TRANSINBILLENTRY_R ADD (FMAINBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLNUMBER')) 
 ALTER TABLE T_IM_TRANSDIRBILLENTRY_R ADD (FMAINBILLNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYSEQ')) 
 ALTER TABLE T_IM_TRANSDIRBILLENTRY_R ADD (FMAINBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTITY')) 
 ALTER TABLE T_IM_TRANSDIRBILLENTRY_R ADD (FMAINBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLID')) 
 ALTER TABLE T_IM_TRANSDIRBILLENTRY_R ADD (FMAINBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSDIRBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYID')) 
 ALTER TABLE T_IM_TRANSDIRBILLENTRY_R ADD (FMAINBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLNUMBER')) 
 ALTER TABLE T_IM_TRANSOUTBILLENTRY_R ADD (FMAINBILLNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYSEQ')) 
 ALTER TABLE T_IM_TRANSOUTBILLENTRY_R ADD (FMAINBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTITY')) 
 ALTER TABLE T_IM_TRANSOUTBILLENTRY_R ADD (FMAINBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLID')) 
 ALTER TABLE T_IM_TRANSOUTBILLENTRY_R ADD (FMAINBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FMAINBILLENTRYID')) 
 ALTER TABLE T_IM_TRANSOUTBILLENTRY_R ADD (FMAINBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y' AND KSQL_COL_NAME IN ('FTRANSRATEDOWN')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY_Y ADD (FTRANSRATEDOWN DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y' AND KSQL_COL_NAME IN ('FTRANSRATEUP')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY_Y ADD (FTRANSRATEUP DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y' AND KSQL_COL_NAME IN ('FROWBILLSTATUS')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY_Y ADD (FROWBILLSTATUS CHAR(1) DEFAULT 'A' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y' AND KSQL_COL_NAME IN ('FREMTRSINQTY')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY_Y ADD (FREMTRSINQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y' AND KSQL_COL_NAME IN ('FREMTRSINBASEQTY')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY_Y ADD (FREMTRSINBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTREQOUTBILL') 
 CREATE TABLE T_IM_MDC_MFTREQOUTBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) 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,
FBILLTYPEID BIGINT DEFAULT 0 NOT NULL,
FBIZORGID BIGINT DEFAULT 0 NOT NULL,
FBIZDEPTID BIGINT DEFAULT 0 NOT NULL,
FDEPTID BIGINT DEFAULT 0 NOT NULL,
FOPERATORGROUPID BIGINT DEFAULT 0 NOT NULL,
FOPERATORID BIGINT DEFAULT 0 NOT NULL,
FBIZTIME DATETIME,
FBIZTYPEID BIGINT DEFAULT 0 NOT NULL,
FINVSCHEMEID BIGINT DEFAULT 0 NOT NULL,
FSUPPLYOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSUPPLYOWNER BIGINT DEFAULT 0 NOT NULL,
FSETTLEORG BIGINT DEFAULT 0 NOT NULL,
FREQUSERID BIGINT DEFAULT 0 NOT NULL,
FCOSTCENTERORG BIGINT DEFAULT 0 NOT NULL,
FSETTLECURRENCY BIGINT DEFAULT 0 NOT NULL,
FISVIRTUALBILL CHAR(1) DEFAULT '0' NOT NULL,
FBILLCRETYPE CHAR(1) DEFAULT '0' NOT NULL,
FNEEDTIME DATETIME,
FWORKSHOP NVARCHAR(80) DEFAULT ' ' NOT NULL,
FWORKSHOPID BIGINT DEFAULT 0 NOT NULL,
FWAREHOSUE BIGINT DEFAULT 0 NOT NULL,
FSUPPLIER BIGINT DEFAULT 0 NOT NULL,
FDOCTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FBOOKDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTREQOUTBILL_L') 
 CREATE TABLE T_IM_MDC_MFTREQOUTBILL_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FCOMMENT NVARCHAR(510) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTREQOUTENTRY') 
 CREATE TABLE T_IM_MDC_MFTREQOUTENTRY (
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,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYORGID BIGINT DEFAULT 0 NOT NULL,
FQTYUNIT3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDID BIGINT DEFAULT 0 NOT NULL,
FUNITRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPRODUCEDATE DATETIME,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FEXPIRYDATE DATETIME,
FENTRYCOMMENT NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FKEEPERID BIGINT DEFAULT 0 NOT NULL,
FINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FOUTINVSTATUSID BIGINT DEFAULT 0 NOT NULL,
FOUTINVTYPEID BIGINT DEFAULT 0 NOT NULL,
FOUTOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOUTOWNERID BIGINT DEFAULT 0 NOT NULL,
FOUTKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FOUTKEEPERID BIGINT DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISFREEGIFT CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTREQOUTENTRY_R') 
 CREATE TABLE T_IM_MDC_MFTREQOUTENTRY_R (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSRCBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSRCBILLID BIGINT DEFAULT 0 NOT NULL,
FSRCBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FSRCBILLNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSRCBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
FMAINBILLNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FMAINBILLID BIGINT DEFAULT 0 NOT NULL,
FMAINBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FMAINBILLENTITY NVARCHAR(100) DEFAULT ' ' NOT NULL,
FMAINBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
FRETURNBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINRETURNBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRETURNQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINRETURNQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVMISETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVMISETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVMIREMAINSETTLEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVMIREMAINSETTLEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPURCHASEDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINPURQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPURCHASEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINPURAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOGISTICSBILL CHAR(1) DEFAULT '0' NOT NULL,
FMVERSION BIGINT DEFAULT 0 NOT NULL,
FMANUBILL NVARCHAR(100) DEFAULT ' ' NOT NULL,
FMANUBILLID BIGINT DEFAULT 0 NOT NULL,
FMANUENTRY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMANUENTRYID BIGINT DEFAULT 0 NOT NULL,
FOPERATION NVARCHAR(100) DEFAULT ' ' NOT NULL,
FOPERATIONID BIGINT DEFAULT 0 NOT NULL,
FWORKCENTER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FWORKCENTERID BIGINT DEFAULT 0 NOT NULL,
FSRCSYSBILLENTRYID NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSRCSYSTEM NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSRCSYSBILLID NVARCHAR(100) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MREQOUTSNENTRY') 
 CREATE TABLE T_IM_MDC_MREQOUTSNENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSERIALNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSERIALCOMMENT NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSERIALID BIGINT DEFAULT 0 NOT NULL
);



/**End D:\nextcloud\dev2main2bizline\PDM_UPGRADE\pdm1\IM_table.sql **/
