/**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_SALSAGENCY') 
 CREATE TABLE T_SM_SALSAGENCY (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLTYPEID BIGINT DEFAULT 0 NOT NULL,
FBIZTYPEID BIGINT DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FBILLSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FDEPTID BIGINT DEFAULT 0 NOT NULL,
FOPERATORGROUPID BIGINT DEFAULT 0 NOT NULL,
FOPERATORID BIGINT DEFAULT 0 NOT NULL,
FCUSTOMERID BIGINT DEFAULT 0 NOT NULL,
FISVERIFY CHAR(1) DEFAULT '0' NOT NULL,
FRECCUSTOMERID BIGINT DEFAULT 0 NOT NULL,
FSETTLECUSTOMERID BIGINT DEFAULT 0 NOT NULL,
FPAYINGCUSTOMERID BIGINT DEFAULT 0 NOT NULL,
FLINKMANID BIGINT DEFAULT 0 NOT NULL,
FADDRESS NVARCHAR(512),
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FBILLCRETYPE VARCHAR(5) DEFAULT '0' NOT NULL,
FCOMMENT NVARCHAR(512),
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FSETTLECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FEXRATETABLEID BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXRATEDATE DATETIME,
FPAYMODE VARCHAR(30) DEFAULT 'CREDIT' NOT NULL,
FSETTLETYPEID BIGINT DEFAULT 0 NOT NULL,
FISTAX CHAR(1) DEFAULT '0' NOT NULL,
FRECEIPTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SM_SALSAGENCYENTRY') 
 CREATE TABLE T_SM_SALSAGENCYENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSALESORGID BIGINT DEFAULT 0 NOT NULL,
FSETTLEMENTTYPE VARCHAR(5) DEFAULT ' ' NOT NULL,
FMATERIALNAME NVARCHAR(255),
FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAUXUNITID BIGINT DEFAULT 0 NOT NULL,
FAUXQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICEANDTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXRATEID BIGINT DEFAULT 0 NOT NULL,
FDISCOUNTTYPE VARCHAR(5) DEFAULT ' ' NOT NULL,
FDISCOUNTRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDISCOUNTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNTANDTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURAMOUNTANDTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISPRESENT CHAR(1) DEFAULT '0' NOT NULL,
FSTOCKORGID BIGINT DEFAULT 0 NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FJOINPRICEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEARQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FARAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRUSTUNVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRUSTUNVERIFYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRUSTVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRUSTVERIFYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' '
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FENTRUSTVERIFYQTY') 
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FENTRUSTVERIFYQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FENTRUSTVERIFYBASEQTY') 
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FENTRUSTVERIFYBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );

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