 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMBURSEBILLDS_L') 
 CREATE TABLE T_ER_REIMBURSEBILLDS_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FAPPLIERPOSITIONSTR VARCHAR(100) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMBURSEBILLDS_A') 
 CREATE TABLE T_ER_REIMBURSEBILLDS_A (
FID BIGINT DEFAULT 0 NOT NULL,
FABOVEQUOTA VARCHAR(30) DEFAULT ' ' NOT NULL,
FISBEFORESHARE CHAR(1) DEFAULT '0' NOT NULL,
FSHARERULE VARCHAR(30) DEFAULT ' ' NOT NULL,
FSHAREMETHOD VARCHAR(30) DEFAULT ' ' NOT NULL,
FMONTHRULESTARTDATE DATETIME,
FMONTHRULEENDDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_REIMBURSEBILLDS') 
 CREATE TABLE T_ER_REIMBURSEBILLDS (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO VARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(30) DEFAULT ' ' 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,
FCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FPAYCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FISCURRENCY CHAR(1) DEFAULT '0' NOT NULL,
FDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
FCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FAPPLIERID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FTEL VARCHAR(100) DEFAULT ' ' NOT NULL,
FREIMBURSEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAPPROVEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSECURRENCY BIGINT DEFAULT 0 NOT NULL,
FPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPAYCURRENCY BIGINT DEFAULT 0 NOT NULL,
FNEXTAUDITOR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FCASHIER BIGINT DEFAULT 0 NOT NULL,
FAUDITOPINION VARCHAR(100) DEFAULT ' ' NOT NULL,
FIMAGENUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
FFORMID VARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLTYPEFIELD BIGINT DEFAULT 0 NOT NULL,
FTOTALACCLOANAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSOURCEBILLTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FHASVOUCHER CHAR(1) DEFAULT '0' NOT NULL,
FBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FNOTPAYAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FATTACHMENTACOUNT BIGINT DEFAULT 0 NOT NULL,
FPAYEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREIMBURSECONTROLCOMANY BIGINT DEFAULT 0 NOT NULL,
FOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOFFSETINVOICENO VARCHAR(255) DEFAULT ' ' NOT NULL,
FSPECIALBILL CHAR(1) DEFAULT ' ' NOT NULL,
FISMULTIREIMBURSER CHAR(1) DEFAULT ' ' NOT NULL,
FAUTOMAPINVOICE CHAR(1) DEFAULT '1' NOT NULL,
FAPPLIERPOSITIONSTR NVARCHAR(100) DEFAULT ' ' NOT NULL,
FHEAD_PAYDATE DATETIME,
FISOVERBUDGET CHAR(1) DEFAULT '0' NOT NULL,
FNOINVOICE CHAR(1) DEFAULT '0' NOT NULL,
FPROXYTAX CHAR(1) DEFAULT '0' NOT NULL,
FTARBILLSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FPROJECTSHARECOUNT INT DEFAULT 0 NOT NULL,
FISPAYBYHEAD CHAR(1) DEFAULT '0' NOT NULL,
FISSHARED CHAR(1) DEFAULT '0' NOT NULL,
FSHAREDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FIS_ALL_EINVOICE CHAR(1) DEFAULT '0' NOT NULL,
FWITHHOLDINGAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FNEEDSUPPLEINVOICE CHAR(1) DEFAULT '0' NOT NULL,
FSTDBILLTYPE BIGINT DEFAULT 0 NOT NULL,
FINVOICEOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSTDCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
FUNAUDITMSG NVARCHAR(1000)
);
 
EXEC P_ALTERPK 'PK_T_ER_REIMBURSEBILLDS_L', 'T_ER_REIMBURSEBILLDS_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_REIMDS_REIMBURSEDS_L_ID') CREATE INDEX IDX_REIMDS_REIMBURSEDS_L_ID ON T_ER_REIMBURSEBILLDS_L ( FID ,FLOCALEID );


EXEC P_ALTERPK 'PK_T_ER_REIMBURSEBILLDS_A', 'T_ER_REIMBURSEBILLDS_A', 'FID', '1';

-- IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FNEEDIMAGESCAN') CREATE INDEX IDX_ER_REIMDS_FNEEDIMAGESCAN ON T_ER_REIMBURSEBILLDS_A ( FNEEDIMAGESCAN );


EXEC P_ALTERPK 'PK_T_ER_REIMBURSEBILLDS', 'T_ER_REIMBURSEBILLDS', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FBILLSTATUS') CREATE INDEX IDX_ER_REIMDS_FBILLSTATUS ON T_ER_REIMBURSEBILLDS ( FBILLSTATUS );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FAPPLIERID') CREATE INDEX IDX_ER_REIMDS_FAPPLIERID ON T_ER_REIMBURSEBILLDS ( FAPPLIERID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FCREATORID') CREATE INDEX IDX_ER_REIMDS_FCREATORID ON T_ER_REIMBURSEBILLDS ( FCREATORID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FCOMPANYID') CREATE INDEX IDX_ER_REIMDS_FCOMPANYID ON T_ER_REIMBURSEBILLDS ( FCOMPANYID );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FBIZDATE_FBILLNO') CREATE INDEX IDX_ER_REIMDS_FBIZDATE_FBILLNO ON T_ER_REIMBURSEBILLDS ( FBIZDATE ,FBILLNO );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMDS_FBILLNO') CREATE INDEX IDX_ER_REIMDS_FBILLNO ON T_ER_REIMBURSEBILLDS ( FBILLNO );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICEENTRY') 
 CREATE TABLE T_ER_INVOICEENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINVOICETYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICENO NVARCHAR(129) DEFAULT ' ' NOT NULL,
FINVOICECODE NVARCHAR(129) DEFAULT ' ' NOT NULL,
FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FTAXAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FSERIALNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBUYERNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FMAKEOUTCOMPNAME NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCOUNT INT DEFAULT 0 NOT NULL,
FFROMINVOICECLOUD CHAR(1) DEFAULT '0' NOT NULL,
FBUYERORGID BIGINT DEFAULT 0 NOT NULL,
FOFFSET CHAR(1) DEFAULT '0' NOT NULL,
FOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINOUTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FVALIDATEMESSAGE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVOICEDATE DATETIME,
FPASSENGERNAME NVARCHAR(255),
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FALLTAXRATE VARCHAR(100) DEFAULT ' ' NOT NULL,
FINVOICEFROM VARCHAR(30) DEFAULT '1' NOT NULL,
FISMAPEXPENSE CHAR(1) DEFAULT '1' NOT NULL,
FFROMCITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTOCITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FIEVALIDATEST CHAR(1) DEFAULT '3' NOT NULL,
FMAPEXPENSEINFO NVARCHAR(255) DEFAULT ' ',
FSEATGRADE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISTARTCITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FIDESTCITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FISTARTPROVINCE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FIDESTPROVINCE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FINVOICENOTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTRANSPORTNOTE VARCHAR(30) DEFAULT ' ' NOT NULL,
FREASONFORTRANSFEROUT VARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICEISCHANGE VARCHAR(30) DEFAULT ' ' NOT NULL,
FBUYERTAXNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTICKETCHANGES VARCHAR(30) DEFAULT ' ' NOT NULL,
FSEQUENCENUM VARCHAR(30) DEFAULT ' ' NOT NULL,
FFLIGHTTRAINNUMS VARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICESRCBILLID BIGINT DEFAULT 0 NOT NULL,
FINVOICESRCENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICESRCBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FBILLCREATETIME DATETIME,
FISSUPPLEMENT VARCHAR(30) DEFAULT ' ' NOT NULL,
FPASSVERIFYBUYERNAME VARCHAR(30) DEFAULT ' ' NOT NULL,
FPASSVERIFYBUYERTAXNO VARCHAR(30) DEFAULT ' ' NOT NULL,
FPERSONALINVOICE VARCHAR(30) DEFAULT ' ' NOT NULL,
FORDERTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FINVOICECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEGOODSNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FINVOICEALLTAXCODE NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCUSTOMERIDNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
FAIRCONSTFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOTHERTOTALTAXAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINSURANCEPREMIUM DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL
);


 EXEC P_ALTERPK 'PK_T_ER_INVOICEENTRY', 'T_ER_INVOICEENTRY', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOENTRY_FSEQ') CREATE INDEX IDX_ER_INVOENTRY_FSEQ ON T_ER_INVOICEENTRY ( FID ,FSEQ );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOENTRY_QUERY') CREATE INDEX IDX_ER_INVOENTRY_QUERY ON T_ER_INVOICEENTRY ( FINVOICETYPE ,FINVOICEDATE );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOENTRY_SERIALNO') CREATE INDEX IDX_ER_INVOENTRY_SERIALNO ON T_ER_INVOICEENTRY ( FSERIALNO );
