--商旅付款申请单单头增加字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAY' AND KSQL_COL_NAME IN ('FSETTLEAMOUNT'))
ALTER TABLE T_ER_CHECKINGPAY ADD (FSETTLEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAY' AND KSQL_COL_NAME IN ('FTOTALACCLOANAMOUNT'))
ALTER TABLE T_ER_CHECKINGPAY ADD (FTOTALACCLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CHECKINGPAYWRIOFF')
CREATE TABLE T_ER_CHECKINGPAYWRIOFF (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FLOANEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURRACCLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FACCLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOANCURRENCY BIGINT DEFAULT 0 NOT NULL,
FLOANPERSON VARCHAR(200) DEFAULT ' ' NOT NULL,
FLOANBILLNOV1 VARCHAR(100) DEFAULT '0' NOT NULL,
FLOANAPPLYDATEV1 DATETIME,
FLOANDESCRIPTIONV1 NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FSOURCESIGN CHAR(1) DEFAULT '0' NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FSOURCEBILLID VARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEEXPENSEITEMID BIGINT DEFAULT 0 NOT NULL,
FSRCBILLTYPE VARCHAR(200) DEFAULT ' ' NOT NULL,
FCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FSRCOFSRCENTRYID BIGINT DEFAULT 0 NOT NULL,
FQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
FENTRYWLTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FENTRYWLUNIT BIGINT DEFAULT 0 NOT NULL,
FSTDENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FLOANCONTRACTNO VARCHAR(500) DEFAULT ' ' NOT NULL,
FLOANPROJECTNO VARCHAR(200) DEFAULT ' ' NOT NULL
);
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CHECKINGPAYWRIOFF_LK')
CREATE TABLE T_ER_CHECKINGPAYWRIOFF_LK (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_CHECKINGPAYWRIOFF', 'T_ER_CHECKINGPAYWRIOFF', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'T_ER_CHECKINGPAYWRIOFF_FID') CREATE INDEX T_ER_CHECKINGPAYWRIOFF_FID ON T_ER_CHECKINGPAYWRIOFF ( FID );


EXEC P_ALTERPK 'PK_T_ER_CHECKINGPAYWRIOFF_LK', 'T_ER_CHECKINGPAYWRIOFF_LK', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'T_ER_CHECKINGPAYWRIOFF_LK_FID') CREATE INDEX T_ER_CHECKINGPAYWRIOFF_LK_FID ON T_ER_CHECKINGPAYWRIOFF_LK ( FENTRYID );
