/**Begin C:\PDM_UPGRADE\PDM1\PUR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_CALFORMULA' AND KSQL_COL_NAME IN ('FISPREINSDATA')) 
 ALTER TABLE T_PUR_CALFORMULA ADD (FISPREINSDATA CHAR(1) DEFAULT '0' NOT NULL );
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_CALFORMULA' AND KSQL_COL_NAME IN ('FREMARK')) 
 ALTER TABLE T_PUR_CALFORMULA ADD (FREMARK NVARCHAR(2000) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_CALRESULTENTITY' AND KSQL_COL_NAME IN ('FSTATUS')) 
 ALTER TABLE T_PUR_CALRESULTENTITY ADD (FSTATUS CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_ORDER_SYNC') 
 CREATE TABLE T_SRM_ORDER_SYNC (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBILLDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FLOCCURRID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_ORDER_SYNCENTITY') 
 CREATE TABLE T_SRM_ORDER_SYNCENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASICUNITID BIGINT DEFAULT 0 NOT NULL,
FBASICQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDELIDATE DATETIME,
FLOCAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOCTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOCTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPOBILLID VARCHAR(50) DEFAULT ' ' NOT NULL,
FPOENTRYID VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_RECEIPT_SYNC') 
 CREATE TABLE T_SRM_RECEIPT_SYNC (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FBILLDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_RECEIPT_SYNCENTITY') 
 CREATE TABLE T_SRM_RECEIPT_SYNCENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPOBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPOBILLID VARCHAR(50) DEFAULT ' ' NOT NULL,
FPOENTRYID VARCHAR(50) DEFAULT ' ' NOT NULL,
FBASICUNITID BIGINT DEFAULT 0 NOT NULL,
FORDERQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRECEIPTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTIMELYRECEIPTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNTIMELYRECEIPTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRECEIPTRETURNQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDELIDATE DATETIME,
FLOCTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOCCURRID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_INSPECTBILL') 
 CREATE TABLE T_SRM_INSPECTBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) DEFAULT ' ' NOT NULL,
FINSPEENDDATE DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SRM_INSPECTENTITY') 
 CREATE TABLE T_SRM_INSPECTENTITY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASICUNITID BIGINT DEFAULT 0 NOT NULL,
FQUALIFIEDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASICQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNQUALIFIEDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQUALIQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEUNQLYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SRM_RECEIPT_SYNC' AND KSQL_COL_NAME IN ('FSTATUS')) 
 ALTER TABLE T_SRM_RECEIPT_SYNC ADD (FSTATUS CHAR(1) DEFAULT '0' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SRM_ORDER_SYNC' AND KSQL_COL_NAME IN ('FCURRID')) 
 ALTER TABLE T_SRM_ORDER_SYNC ADD (FCURRID BIGINT DEFAULT 0 NOT NULL );
/**End C:\PDM_UPGRADE\PDM1\PUR_table.sql **/
