/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\SM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SM_REPORTTASK') 
 CREATE TABLE T_SM_REPORTTASK (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FPROGRESS DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSTARTTIME DATETIME,
FENDTIME DATETIME,
FMIDDLEREPORT VARCHAR(36) DEFAULT ' ' NOT NULL,
FREPORT VARCHAR(80) DEFAULT ' ' NOT NULL,
FREPORTNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FCONDITIONJSON_TAG NCLOB,
FCONDITIONJSON NVARCHAR(512),
FCONDITIONTEXT_TAG NCLOB,
FCONDITIONTEXT NVARCHAR(512),
FTASKEXP_TAG NCLOB,
FTASKEXP NVARCHAR(512),
FTASKSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FTASKCLASS VARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SM_SALPROFITMIDRESULT') 
 CREATE TABLE T_SM_SALPROFITMIDRESULT (
FID BIGINT DEFAULT 0 NOT NULL,
FREPORTTASK BIGINT DEFAULT 0 NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL,
FSALORG BIGINT DEFAULT 0 NOT NULL,
FCUSTOMER BIGINT DEFAULT 0 NOT NULL,
FBIZOPERATOR BIGINT DEFAULT 0 NOT NULL,
FGROUP BIGINT DEFAULT 0 NOT NULL,
FMATERIAL BIGINT DEFAULT 0 NOT NULL,
FAUXPTY BIGINT DEFAULT 0 NOT NULL,
FBASEUNIT BIGINT DEFAULT 0 NOT NULL,
FCURRENCY BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXSALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNITCOST DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACTUALCOST DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNITGROSSPROFIT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSALGROSSPROFIT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOCALVERIFYAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBUSAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTITY') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLENTITY VARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLNUMBER') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLID') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTRYID') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLROWNUM') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLROWNUM VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTRYSEQ') 
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FCONBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTITY') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLENTITY VARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLNUMBER') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLID') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTRYID') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLROWNUM') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLROWNUM VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FCONBILLENTRYSEQ') 
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FCONBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLENTITY') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLENTITY VARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLNUMBER') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLID') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLENTRYID') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLROWNUM') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLROWNUM VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_RETURNAPPLYENTRY' AND KSQL_COL_NAME ='FCONBILLENTRYSEQ') 
 ALTER TABLE T_SM_RETURNAPPLYENTRY ADD (FCONBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL );

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