/*差旅报销主表*/


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CGRID_TRIPREIMBURSE')
CREATE TABLE T_ER_CGRID_TRIPREIMBURSE (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FUNAUDITMSG NVARCHAR(1000)  DEFAULT ' ' NOT NULL   ,
FAUTOGENSHARE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FPAYCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FINVOKEINVOICECLOUD CHAR(1)  DEFAULT ' ' NOT NULL   ,
FORGID BIGINT  DEFAULT 0 NOT NULL   ,
FISBEFORESHARE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FMONTHRULESTARTDATE DATETIME  ,
FRVEHICLE VARCHAR(10)  DEFAULT ' ' NOT NULL   ,
FMODIFYTIME DATETIME  ,
FSTDCOSTCENTERID BIGINT  DEFAULT 0 NOT NULL   ,
FNEEDUPLOADINVOICE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FBILLNO NVARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FLOANCHECKTYPE VARCHAR(1)  DEFAULT ' ' NOT NULL   ,
FSTDBILLTYPE BIGINT  DEFAULT 0 NOT NULL   ,
FWITHHOLDINGAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICEOFFSETAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FOFFSETAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FRSTARTDATE DATETIME  ,
FAUDITORID BIGINT  DEFAULT 0 NOT NULL   ,
FISOVERBUDGET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISSHARED CHAR(1)  DEFAULT ' ' NOT NULL   ,
FAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCREATORID BIGINT  DEFAULT 0 NOT NULL   ,
FMODIFIERID BIGINT  DEFAULT 0 NOT NULL   ,
FCREATETIME DATETIME  ,
FISCURRENCY CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISINVOICEMODIFIED CHAR(1)  DEFAULT ' ' NOT NULL   ,
FMONTHRULEENDDATE DATETIME  ,
FBIZITEM BIGINT  DEFAULT 0 NOT NULL   ,
FSHAREMETHOD VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FRTO VARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FRENDDATE DATETIME  ,
FNOINVOICE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FHASVOUCHER CHAR(1)  DEFAULT ' ' NOT NULL   ,
FHEAD_PAYDATE DATETIME  ,
FATTACHMENTCOUNT BIGINT  DEFAULT 0 NOT NULL   ,
FBILLSTATUS VARCHAR(5)  DEFAULT ' ' NOT NULL   ,
FMONTHSETTLEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FAUDITDATE DATETIME  ,
FAUTOMAPINVOICE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FSHARERULE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FNEEDIMAGESCAN CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISTRAVELERS CHAR(1)  DEFAULT ' ' NOT NULL   ,
FPROJECTSHARECOUNT BIGINT  DEFAULT 0 NOT NULL   ,
FSHAREDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FBILLKIND CHAR(1)  DEFAULT ' ' NOT NULL   ,
FABOVEQUOTADEPT VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FIS_ALL_EINVOICE CHAR(1) DEFAULT ' ' NOT NULL   ,
FABOVEQUOTAEMP VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FISSTDOVER CHAR(1)  DEFAULT ' ' NOT NULL   ,
FAPPLIERPOSITION NVARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FRFROM VARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FISPAYBYHEAD CHAR(1)  DEFAULT ' ' NOT NULL,
FCOSTDEPTID BIGINT  DEFAULT 0 NOT NULL   ,
FBOOKEDDATE DATETIME     ,
FDESCRIPTION NVARCHAR(1000)  DEFAULT ' ' NOT NULL   ,
FNOTPAYAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FNEXTAUDITOR VARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FPAYAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENCASHAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCOSTCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FISLOAN CHAR(1)  DEFAULT ' ' NOT NULL   ,
FCHECKLOANAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORIGIN VARCHAR(10)  DEFAULT ' ' NOT NULL   ,
FIMAGENO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FAPPROVEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FFORMID NVARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FTRIPTYPEID BIGINT  DEFAULT 0 NOT NULL   ,
FAPPLIERID BIGINT  DEFAULT 0 NOT NULL   ,
FBIZDATE DATETIME     ,
FCURRENCYID BIGINT  DEFAULT 0 NOT NULL ,
FISSMALLREIM CHAR(1)  DEFAULT ' '  NOT NULL
);


EXEC P_ALTERPK 'PK_T_ER_CGRID_TRIPREIMBURSE', 'T_ER_CGRID_TRIPREIMBURSE', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIM_FAPPLIERID') CREATE INDEX IDX_ER_NREIM_FAPPLIERID ON T_ER_CGRID_TRIPREIMBURSE ( FAPPLIERID );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIM_CCOM_ADATE') CREATE INDEX IDX_ER_NREIM_CCOM_ADATE ON T_ER_CGRID_TRIPREIMBURSE ( FCOSTCOMPANYID,FAUDITDATE );

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

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

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

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

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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CGRID_TRIPREIMBURSE_A')
CREATE TABLE T_ER_CGRID_TRIPREIMBURSE_A (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FTARBILLSTATUS VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FPROJECTTYPE  BIGINT  DEFAULT 0 NOT NULL ,
FUNREPAYMENTAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FRECEIVEIMAGETIME DATETIME  ,
FTEL VARCHAR(25)  DEFAULT ' ' NOT NULL   ,
FHEADEXPENSEITEM BIGINT  DEFAULT 0 NOT NULL   ,
FHEADPROJECT BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_CGRID_TRIPREIMBURSE_A', 'T_ER_CGRID_TRIPREIMBURSE_A', 'FID', '1';


/*差旅报销多语言表*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CGRID_TRIPREIMBURSE_L')
CREATE TABLE T_ER_CGRID_TRIPREIMBURSE_L (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FLOCALEID VARCHAR(36)  DEFAULT ' ' NOT NULL   ,
FPKID VARCHAR(18)  DEFAULT ' ' NOT NULL   ,
FAPPLIERPOSITION NVARCHAR(100)  DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_CGRID_TRIPREIMBURSE_L', 'T_ER_CGRID_TRIPREIMBURSE_L', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIMBURSEBILL_L_FID') CREATE INDEX IDX_ER_NREIMBURSEBILL_L_FID ON T_ER_CGRID_TRIPREIMBURSE_L ( FID,FLOCALEID	 );


/*单头lk*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREIMBURSE_LK')
CREATE TABLE T_ER_NTRIPREIMBURSE_LK (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FSBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPREIMBURSE_LK', 'T_ER_NTRIPREIMBURSE_LK', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_REIMBURSEBILL_LK_FID') CREATE INDEX IDX_ER_REIMBURSEBILL_LK_FID ON T_ER_NTRIPREIMBURSE_LK (FID);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREIMBURSE_WB')
CREATE TABLE T_ER_NTRIPREIMBURSE_WB (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FOPERATE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FRULEVERID BIGINT  DEFAULT 0 NOT NULL   ,
FSBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSID BIGINT  DEFAULT 0 NOT NULL   ,
FWRITEVALUE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FRULEITEMID BIGINT  DEFAULT 0 NOT NULL
);


EXEC P_ALTERPK 'PK_T_ER_NTRIPREIMBURSE_WB', 'T_ER_NTRIPREIMBURSE_WB', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPREIMBURSEN_WB') CREATE INDEX IDX_ER_NTRIPREIMBURSEN_WB ON T_ER_NTRIPREIMBURSE_WB (FID);


/*行程信息*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREIMBURSETRIPENTRY')
CREATE TABLE T_ER_NREIMBURSETRIPENTRY (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FISCREATEPROJECTCOSTSHARE BIGINT  DEFAULT 0 NOT NULL   ,
FTRIPENTRYSTATUS VARCHAR(5)  DEFAULT ' ' NOT NULL   ,
FENDDATE DATETIME  ,
FVEHICLE VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FSTDENTRYCOSTCENTERID BIGINT  DEFAULT 0 NOT NULL   ,
FPROJECTID BIGINT  DEFAULT 0 NOT NULL   ,
FTRIPEXPENSEITEMID BIGINT  DEFAULT 0 NOT NULL   ,
FTRIPISOVERBUDGET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FSTARTDATE DATETIME  ,
FTAXAMOUNTTOTALORI DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTRIPDEDUCTIBLETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FNOTAXAMOUNTTOTALORI DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYCOSTCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FSHAREDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FEXPWITHHOLDINGAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTRIPHAPPENDATE DATETIME  ,
FTRIPENTRYSOURCEID BIGINT  DEFAULT 0 NOT NULL   ,
FTRIPAPPNOTTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTRIPENTRYKEY CHAR(1)  DEFAULT ' ' NOT NULL   ,
FTRIPENTRYAREA BIGINT  DEFAULT 0 NOT NULL   ,
FORISHAREDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYCOSTDEPTID BIGINT  DEFAULT 0 NOT NULL,
FTRIPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTOPLACEID BIGINT  DEFAULT 0 NOT NULL   ,
FTRIPAPPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTRIPDAY BIGINT  DEFAULT 0 NOT NULL   ,
FFROMPLACEID BIGINT  DEFAULT 0 NOT NULL   ,
FISEXISTMONTHLY CHAR(1)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NREIMBURSETRIPENTRY', 'T_ER_NREIMBURSETRIPENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIMBURSETRIPENTRY_FID') CREATE INDEX IDX_ER_NREIMBURSETRIPENTRY_FID ON T_ER_NREIMBURSETRIPENTRY ( FID);

/*行程-出差人*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREIMBURSEPARTNE')
 CREATE TABLE T_ER_NTRIPREIMBURSEPARTNE (
FPKID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL
);

 EXEC P_ALTERPK 'PK_T_ER_NTRIPREIMBURSEPARTNE', 'T_ER_NTRIPREIMBURSEPARTNE', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPPARTNER_FENTRYID') CREATE INDEX IDX_ER_NTRIPPARTNER_FENTRYID ON T_ER_NTRIPREIMBURSEPARTNE ( FENTRYID );

/*行程途径地*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPENTRYMULWAYTO')
CREATE TABLE T_ER_NTRIPENTRYMULWAYTO (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL
);

 EXEC P_ALTERPK 'PK_T_ER_NTRIPENTRYMULWAYTO', 'T_ER_NTRIPENTRYMULWAYTO', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NMULWAYTO_ENTRYID') CREATE INDEX IDX_ER_NMULWAYTO_ENTRYID ON T_ER_NTRIPENTRYMULWAYTO ( FENTRYID );


/*明细信息*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREIMBURSEENTRY')
CREATE TABLE T_ER_NREIMBURSEENTRY (
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FTRAVELEXPENSEITEM BIGINT  DEFAULT 0 NOT NULL   ,
FDEDUCTIBLETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTAXRATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORDERNUM VARCHAR(2000)  DEFAULT ' ' NOT NULL   ,
FOFFSET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FITEMNODEDUCTIONREASON VARCHAR(2)  DEFAULT ' ' NOT NULL   ,
FEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCURPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSETTLEMENTTYPE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICETYPEITEM VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FINVOICEFROMPARENT CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISCANCELORDER CHAR(1)  DEFAULT ' ' NOT NULL   ,
FORDERFORMID NVARCHAR(1000)  DEFAULT ' ' NOT NULL   ,
FTAXCLASSCODEID BIGINT  DEFAULT 0 NOT NULL   ,
FTRAVELCOSTDEPT BIGINT  DEFAULT 0 NOT NULL   ,
FINVOICENO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FOVERDESC NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FEXPENSEITEMID BIGINT  DEFAULT 0 NOT NULL   ,
FAPPROVETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSTDEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FNOTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCHECKINDATESTR VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FCALDAYCOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCHECKOUTDATESTR VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FCONTROLAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FFROMCITYSTR VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FDISTANCE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORISTDQUOTETYPE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FORIENTRYAPPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FISDEFAULT CHAR(1)  DEFAULT ' ' NOT NULL   ,
FPROVIDER VARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FENTRYAPPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTRAVELHAPPENDATE DATETIME      ,
FSTDEXPQUOTETYPE CHAR(1)   DEFAULT ' ' NOT NULL   ,
FORIAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FHIGHSEASONDAYCOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORISTDEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FISVACTAX CHAR(1)  DEFAULT ' ' NOT NULL   ,
FTRAVELCOSTCOMPANY BIGINT  DEFAULT 0 NOT NULL   ,
FTAXAMOUNTTWO DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPULLTRAVELORDER CHAR(1)  DEFAULT ' ' NOT NULL   ,
FTOCITYSTR VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FTRAVELCOSTCENTER BIGINT  DEFAULT 0 NOT NULL   ,
FITEMFROM VARCHAR(2)  DEFAULT ' ' NOT NULL   ,
FTRAVELQUOTACTLDEPT BIGINT  DEFAULT 0 NOT NULL   ,
FSTDENTRYCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FCOMMENT NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FAPPROVETAXTWO DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYAPPAMOUNTSTD DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICELINK NVARCHAR(129)  DEFAULT ' ' NOT NULL   ,
FCURCONTROLAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FITEMINOUTAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCURRENCYID BIGINT  DEFAULT 0 NOT NULL   ,
FQUOTETYPE CHAR(1)  DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NREIMBURSEENTRY', 'T_ER_NREIMBURSEENTRY', 'FDETAILID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_NREIMBURSEENTRY_FSEQ') CREATE INDEX IDX_T_ER_NREIMBURSEENTRY_FSEQ  ON T_ER_NREIMBURSEENTRY ( FENTRYID,FSEQ);



/*差旅明细扩展表*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREIMBURSEENTRY_A')
CREATE TABLE T_ER_NREIMBURSEENTRY_A (
FTRIP2TRAVELERSCOUNT BIGINT  DEFAULT 0 NOT NULL   ,
FSPLITPARENT VARCHAR(32)  DEFAULT ' ' NOT NULL   ,
FISOVER CHAR(1)  DEFAULT ' ' NOT NULL   ,
FUSEROUTSTDCTRL CHAR(1)  DEFAULT ' ' NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL ,
FTRIPSTANDDESC   VARCHAR(50) DEFAULT ' ' NOT NULL   ,
FTRIPSTANDDESC_TAG NCLOB  ,
FITEMREASONFORTRANSFEROUT VARCHAR(30)  DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NREIMBURSEENTRY_A' AND KSQL_COL_NAME IN ('FACCSTANDJSON'))
ALTER TABLE T_ER_NREIMBURSEENTRY_A ADD (FACCSTANDJSON NCLOB);

EXEC P_ALTERPK 'PK_T_ER_NREIMBURSEENTRY_A', 'T_ER_NREIMBURSEENTRY_A', 'FDETAILID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIMBURSEENTRY_A_FSEQ') CREATE INDEX IDX_ER_NREIMBURSEENTRY_A_FSEQ  ON T_ER_NREIMBURSEENTRY_A ( FENTRYID);

/*明细出差人*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIP2REIMPARTNER')
CREATE TABLE T_ER_NTRIP2REIMPARTNER (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIP2REIMPARTNER', 'T_ER_NTRIP2REIMPARTNER', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIP2REIMPARTNER') CREATE INDEX IDX_ER_NTRIP2REIMPARTNER  ON T_ER_NTRIP2REIMPARTNER ( FDETAILID);

/*明细交通工具标准*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_VEHSTANDS')
CREATE TABLE T_ER_VEHSTANDS (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_VEHSTANDS', 'T_ER_VEHSTANDS', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_VEHSTANDS_FDETAILID') CREATE INDEX IDX_ER_VEHSTANDS_FDETAILID  ON T_ER_VEHSTANDS ( FDETAILID);

/*明细住宿标准*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_ACCSTANDS')
CREATE TABLE T_ER_ACCSTANDS (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_ACCSTANDS', 'T_ER_ACCSTANDS', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_ACCSTANDS_FDETAILID') CREATE INDEX IDX_ER_ACCSTANDS_FDETAILID  ON T_ER_ACCSTANDS ( FDETAILID);

/*明细标准座位等级*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPSTDSEATGRADE')
CREATE TABLE T_ER_NTRIPSTDSEATGRADE (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NTRIPSTDSEATGRADE', 'T_ER_NTRIPSTDSEATGRADE', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPSTDSEATGRA_DETAIL') CREATE INDEX IDX_ER_NTRIPSTDSEATGRA_DETAIL  ON T_ER_NTRIPSTDSEATGRADE ( FDETAILID);

/*明细座位等级*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPITEMSEATGRADE')
CREATE TABLE T_ER_NTRIPITEMSEATGRADE (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NTRIPITEMSEATGRADE', 'T_ER_NTRIPITEMSEATGRADE', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPITEMSEATGRA_DETAIL') CREATE INDEX IDX_ER_NTRIPITEMSEATGRA_DETAIL  ON T_ER_NTRIPITEMSEATGRADE ( FDETAILID);




/*冲借款*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPCLEARLOANENTRY')
CREATE TABLE T_ER_TRIPCLEARLOANENTRY (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FEXPENSEITEMID BIGINT  DEFAULT 0 NOT NULL   ,
FSTDENTRYCOSTCENTERID BIGINT  DEFAULT 0 NOT NULL   ,
FLOANBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSNAPCLEARORIAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FLOANBILLNO NVARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FCOSTDEPTID BIGINT  DEFAULT 0 NOT NULL   ,
FCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FDESCRIPTION NVARCHAR(1000)  DEFAULT ' ' NOT NULL   ,
FSNAPCLEARAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCLEARORIAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FBIZDATE DATETIME    ,
FCLEARAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FREQACCOUNTENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FORIBALANCEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCOSTCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FSRCBILLTYPE VARCHAR(200)  DEFAULT ' ' NOT NULL   ,
FACCBALANCEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FQUOTETYPE CHAR(1)  DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_TRIPCLEARLOANENTRY', 'T_ER_TRIPCLEARLOANENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIMCLELANENT_FSEQ') CREATE INDEX IDX_ER_NREIMCLELANENT_FSEQ  ON T_ER_TRIPCLEARLOANENTRY (FID,FSEQ);



/*冲借款LK*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPCLEARLOANENTRY_LK')
CREATE TABLE T_ER_TRIPCLEARLOANENTRY_LK (
FSBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_TRIPCLEARLOANENTRY_LK', 'T_ER_TRIPCLEARLOANENTRY_LK', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_TRIPLOANENTRY_FENTRYID') CREATE INDEX IDX_TRIPLOANENTRY_FENTRYID  ON T_ER_TRIPCLEARLOANENTRY_LK (FENTRYID);


/*冲申请*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREIMAPPLYENTRY')
CREATE TABLE T_ER_NREIMAPPLYENTRY (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FAPPLYTOCITY BIGINT  DEFAULT 0 NOT NULL   ,
FREIMBURSEDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FAPPLYSTARTDATE DATETIME    ,
FAPPLYFROMCITY BIGINT  DEFAULT 0 NOT NULL   ,
FAPPLYRVEHICLE VARCHAR(10)  DEFAULT ' ' NOT NULL   ,
FAPPLYPERSON BIGINT  DEFAULT 0 NOT NULL   ,
FAPPLYBILLDATE DATETIME    ,
FAPPLYCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FSOURCEAPPLYBILLID VARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FSRCAPPLYBILLTYPE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FAPPLYBILLNO NVARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FAPPLYDESCRIPTION VARCHAR(1000)  DEFAULT ' ' NOT NULL   ,
FAPPLYENDDATE DATETIME    ,
FAPPLYEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NREIMAPPLYENTRY', 'T_ER_NREIMAPPLYENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NCLEARAPPLYENT_FID') CREATE INDEX IDX_ER_NCLEARAPPLYENT_FID  ON T_ER_NREIMAPPLYENTRY (FID);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NCLEARAPPLYENT_FAPPLYNO') CREATE INDEX IDX_ER_NCLEARAPPLYENT_FAPPLYNO  ON T_ER_NREIMAPPLYENTRY (FAPPLYBILLNO);

/*冲申请lk*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NREIMAPPLYENTRY_LK')
CREATE TABLE T_ER_NREIMAPPLYENTRY_LK (
FSBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NREIMAPPLYENTRY_LK', 'T_ER_NREIMAPPLYENTRY_LK', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_ER_NREIMAPPLYENT_LK_FENT') CREATE INDEX IDX_T_ER_NREIMAPPLYENT_LK_FENT  ON T_ER_NREIMAPPLYENTRY_LK (FENTRYID);


/*冲申请出差人*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPAPPLYTRAVELERS')
CREATE TABLE T_ER_NTRIPAPPLYTRAVELERS (
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NTRIPAPPLYTRAVELERS', 'T_ER_NTRIPAPPLYTRAVELERS', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NAPPTRAVELERS_FENTRYID') CREATE INDEX IDX_ER_NAPPTRAVELERS_FENTRYID  ON T_ER_NTRIPAPPLYTRAVELERS (FENTRYID);


/*发票分录*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NINVOICEINFO')
CREATE TABLE T_ER_NINVOICEINFO (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FMAPEXPENSEINFO VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FTOTALAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FUPLOADSEQ BIGINT  DEFAULT 0 NOT NULL   ,
FOFFSET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FBUYERADDRESSPHONE NVARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FPASSENGERNAME NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FISEXCESSREIM CHAR(1)  DEFAULT ' ' NOT NULL   ,
FENDDATE DATETIME    ,
FUNITPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FFUELSURCHARGE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORDERTYPE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICECODE NVARCHAR(129)  DEFAULT ' ' NOT NULL   ,
FORIBALANCEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCITY NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FBUYERNAME NVARCHAR(250)  DEFAULT ' ' NOT NULL   ,
FINVOICENO NVARCHAR(129)  DEFAULT ' ' NOT NULL   ,
FSALERTAXNO NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSERIALNO NVARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FTAXDETAILS VARCHAR(500)  DEFAULT ' ' NOT NULL   ,
FPOOLREIMBURSEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FOFFSETAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSELLERORGID BIGINT  DEFAULT 0 NOT NULL   ,
FINVOICECURRENCYID BIGINT  DEFAULT 0 NOT NULL   ,
FCUSTOMERIDNUMBER NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICETYPE BIGINT  DEFAULT 0 NOT NULL   ,
FSTARTDATE DATETIME    ,
FFAIRTIME VARCHAR(20)  DEFAULT ' ' NOT NULL   ,
FSEQUENCENUM VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FTRANSPORTNOTE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FFROMINVOICECLOUD CHAR(1)  DEFAULT ' ' NOT NULL   ,
FEXCESSDESC VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FINOUTAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FUNIT NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FSEQUENCENUMINFO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FTICKETCHANGES VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FINVOICESRCBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FINVOICEISCHANGE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FALLTAXRATE VARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FIEVALIDATEST CHAR(1)  DEFAULT ' ' NOT NULL   ,
FOTHERTOTALTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FNUM DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICESRCENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FINSURANCEPREMIUM DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSPECMODEL NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FVALIDATEMESSAGE NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FAIRCONSTFEE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICEDATE DATETIME    ,
FINVOICEALLTAXCODE NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FBUYERORG BIGINT  DEFAULT 0 NOT NULL   ,
FISLINKAGEDETAIL CHAR(1)  DEFAULT ' ' NOT NULL   ,
FCOUNT BIGINT  DEFAULT 0 NOT NULL   ,
FINVOICENOTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FISMUTILREIMBURSE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISPOOL CHAR(1)  DEFAULT ' ' NOT NULL   ,
FBILLCREATETIME DATETIME    ,
FINVOICEFROM VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FREMARK VARCHAR(1024)  DEFAULT ' ' NOT NULL   ,
FBUYERTAXNO NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FMAKEOUTCOMPNAME NVARCHAR(250)  DEFAULT ' ' NOT NULL   ,
FFLIGHTTRAINNUMS VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FBILLINGPOOLID BIGINT  DEFAULT 0 NOT NULL   ,
FISMAPEXPENSE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICESRCBILLTYPE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FINVOICEGOODSNAME NVARCHAR(255)  DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEINFO' AND KSQL_COL_NAME ='FCARRIERDATE')
ALTER TABLE T_ER_NINVOICEINFO ADD (FCARRIERDATE   DATETIME    );

EXEC P_ALTERPK 'PK_T_ER_NINVOICEINFO', 'T_ER_NINVOICEINFO', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEINFO_QUERY') CREATE INDEX IDX_ER_NINVOICEINFO_QUERY  ON T_ER_NINVOICEINFO (FINVOICETYPE,FINVOICEDATE);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICE_FSERIALNO') CREATE INDEX IDX_ER_NINVOICE_FSERIALNO  ON T_ER_NINVOICEINFO (FSERIALNO);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEINFO_FSEQ') CREATE INDEX IDX_ER_NINVOICEINFO_FSEQ  ON T_ER_NINVOICEINFO (FID,FSEQ);



/*发票分录*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NINVOICEINFO_A')
CREATE TABLE T_ER_NINVOICEINFO_A (
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FISSUPPLEMENT CHAR(1)  DEFAULT ' ' NOT NULL   ,
FNODEDUCTIONREASON VARCHAR(2)  DEFAULT ' ' NOT NULL   ,
FEXPIRYPAYDATE DATETIME    ,
FCOUNTRYSTR VARCHAR(500)  DEFAULT ' ' NOT NULL   ,
FCOUNTRY BIGINT  DEFAULT 0 NOT NULL   ,
FTIMEGETON DATETIME    ,
FTIMEGETOFF DATETIME    ,
FFROMCITY NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FTOCITY NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FSEATGRADE NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FISTARTPROVINCE NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FIDESTPROVINCE NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FISTARTCITY NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FIDESTCITY NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FREASONFORTRANSFEROUT VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FISRED CHAR(1)  DEFAULT ' ' NOT NULL   ,
FREGION CHAR(1)  DEFAULT ' ' NOT NULL   ,
FISXBRL CHAR(1)  DEFAULT ' ' NOT NULL   ,
FBLOCKCHAIN CHAR(1)  DEFAULT ' ' NOT NULL   ,
FENDORSEMENT VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FINVOICEORDERNUM NVARCHAR(500)  DEFAULT ' ' NOT NULL   ,
FPERSONALINVOICE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FPASSVERIFYBUYERNAME VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FPASSVERIFYBUYERTAXNO VARCHAR(30)  DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NINVOICEINFO_A', 'T_ER_NINVOICEINFO_A', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEINFO_A' AND KSQL_COL_NAME ='FID')
ALTER TABLE T_ER_NINVOICEINFO_A ADD (FID BIGINT  DEFAULT 0 NOT NULL );

/*发票明细*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NINVOICEITEM')
CREATE TABLE T_ER_NINVOICEITEM (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FEXCLUDEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTAXRATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICEITEMOFFSET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FTOTALAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICEITEMISUNBIND CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICEITEMSERIALNO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FINVOICECURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FNUM DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICEHEADENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FUNITPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FGOODSCODE VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FINVOICETYPE BIGINT  DEFAULT 0 NOT NULL   ,
FSPECMODEL NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FGOODSNAME VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FINVOICECLOUDOFFSET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICEDATE DATETIME    ,
FINVOICENO VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FUNIT NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FSALERTAXNO NVARCHAR(50)  DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NINVOICEITEM', 'T_ER_NINVOICEITEM', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEITEM_FID') CREATE INDEX IDX_ER_NINVOICEITEM_FID  ON T_ER_NINVOICEITEM (FID);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEITEM_INVHEA') CREATE INDEX IDX_ER_NINVOICEITEM_INVHEA  ON T_ER_NINVOICEITEM (FINVOICEHEADENTRYID);

/*发票和费用明细关联关系*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NINVOICEANDEXP')
CREATE TABLE T_ER_NINVOICEANDEXP (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FKEYPROPERTY CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICEEXPISUNBIND CHAR(1)  DEFAULT ' ' NOT NULL   ,
FINVOICEENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FINVOICEEXPSERIALNO VARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FEXPENSEENTRYID BIGINT  DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_T_ER_NINVOICEANDEXP', 'T_ER_NINVOICEANDEXP', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEENTRYID') CREATE INDEX IDX_ER_NINVOICEENTRYID  ON T_ER_NINVOICEANDEXP (FINVOICEENTRYID);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEEXPENSEENTRYID') CREATE INDEX IDX_ER_NINVOICEEXPENSEENTRYID  ON T_ER_NINVOICEANDEXP (FEXPENSEENTRYID);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NINVOICEEXPENSEID') CREATE INDEX IDX_ER_NINVOICEEXPENSEID  ON T_ER_NINVOICEANDEXP (FID);


/*分摊明细*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPRESHARERULE')
 CREATE TABLE T_ER_NTRIPRESHARERULE (
FID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
FENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSHARERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENTRYMONTH DATETIME,
FSHAREREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTDENTRYCOSTCENTERID BIGINT  DEFAULT 0 NOT NULL   ,
FSHARERULEKEY CHAR(1)  DEFAULT ' ' NOT NULL   ,
FSHAREAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPRESHARERULE', 'T_ER_NTRIPRESHARERULE', 'FDETAILID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPRESHARERULE_FSEQ') CREATE INDEX IDX_ER_NTRIPRESHARERULE_FSEQ  ON T_ER_NTRIPRESHARERULE ( FID,FSEQ);

/*干系人*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREIMBURSEOWER')
CREATE TABLE T_ER_NTRIPREIMBURSEOWER (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FBASEDATAID BIGINT  DEFAULT 0 NOT NULL   ,
FPKID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPREIMBURSEOWER', 'T_ER_NTRIPREIMBURSEOWER', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPREIMBURSEOWER_FID') CREATE INDEX IDX_ER_NTRIPREIMBURSEOWER_FID  ON T_ER_NTRIPREIMBURSEOWER ( FID);

/*付款信息*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPPAYENTRY')
CREATE TABLE T_ER_NTRIPPAYENTRY (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FTARGETPAYORG BIGINT  DEFAULT 0 NOT NULL   ,
FTARGETBIZDATE DATETIME    ,
FTARGETBILLNO NVARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FDPCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FFEE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FDPEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FLOSSAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETENTRUSTORG BIGINT  DEFAULT 0 NOT NULL   ,
FDPAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FAGREEDRATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETPAYACCTID BIGINT  DEFAULT 0 NOT NULL   ,
FTARGETLOCALAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETEXCHANGE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETPAYBANK BIGINT  DEFAULT 0 NOT NULL   ,
FFEECURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FDPLOCALAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETPAYAMT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTARGETPAYACCT VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FTARGETOPENORG BIGINT  DEFAULT 0 NOT NULL   ,
FTARGETPAYDATE DATETIME    ,
FTARGETBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FTARGETCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FTARGETSETTLETYPE BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPPAYENTRY', 'T_ER_NTRIPPAYENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPPAYENTRY_FID') CREATE INDEX IDX_ER_NTRIPPAYENTRY_FID  ON T_ER_NTRIPPAYENTRY ( FID,FSEQ);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPPAYENT_FTARGET') CREATE INDEX IDX_ER_NTRIPPAYENT_FTARGET  ON T_ER_NTRIPPAYENTRY ( FTARGETBILLID);

/*摊销明细*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPRESHAREDETAIL')
CREATE TABLE T_ER_NTRIPRESHAREDETAIL (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FDETAILID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FINVOICETYPEITEM VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FHAPPENDATE DATETIME    ,
FENTRYCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FDEDUCTIBLETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTAXRATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FORIAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYMONTH DATETIME    ,
FOFFSET CHAR(1)  DEFAULT ' ' NOT NULL   ,
FTRIPITEMID BIGINT  DEFAULT 0 NOT NULL   ,
FPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FREIMBURSEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYCOSTCOMPANYID BIGINT  DEFAULT 0 NOT NULL   ,
FEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCURRREIMBURSEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FISSPECIALINVOICE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FGOODSNAME NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FCURPRICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FTAXCLASSCODEID BIGINT  DEFAULT 0 NOT NULL   ,
FSHARERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICENO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FITEMFROM VARCHAR(2)  DEFAULT ' ' NOT NULL   ,
FEXPENSEITEMID BIGINT  DEFAULT 0 NOT NULL   ,
FTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FREMARK NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FSTDENTRYCOSTCENTERID BIGINT  DEFAULT 0 NOT NULL   ,
FAPPROVETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPROJECTID BIGINT  DEFAULT 0 NOT NULL   ,
FSERIALNO NVARCHAR(80)  DEFAULT ' ' NOT NULL   ,
FSDINVOICETYPEITEM BIGINT  DEFAULT 0 NOT NULL   ,
FEXPEAPPROVECURRAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FINVOICELINK NVARCHAR(129)  DEFAULT ' ' NOT NULL   ,
FAIRPORTCONSTRUCTIONFEE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FLKWAITENTRYID VARCHAR(200)  DEFAULT ' ' NOT NULL   ,
FITEMINOUTAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FENTRYCOSTDEPTID BIGINT  DEFAULT 0 NOT NULL   ,
FQUOTETYPE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FEXPEAPPROVEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPRESHAREDETAIL', 'T_ER_NTRIPRESHAREDETAIL', 'FDETAILID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPRESHAREDETAI_FSEQ') CREATE INDEX IDX_ER_NTRIPRESHAREDETAI_FSEQ  ON T_ER_NTRIPRESHAREDETAIL ( FID,FSEQ);

/*收款信息*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPACCOUNT')
CREATE TABLE T_ER_NTRIPACCOUNT (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FBUILDEDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPAYERTYPE VARCHAR(30)  DEFAULT ' ' NOT NULL   ,
FENTRYSTATUS CHAR(1)  DEFAULT ' ' NOT NULL   ,
FORIACCNOTPAYAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPAYERNAME NVARCHAR(100)  DEFAULT ' ' NOT NULL   ,
FSUPPLIER BIGINT  DEFAULT 0 NOT NULL   ,
FPAYERACCOUNTNAME NVARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FACCCOSTCOMPANY BIGINT  DEFAULT 0 NOT NULL   ,
FCUSTOMER BIGINT  DEFAULT 0 NOT NULL   ,
FORIACCPAYEDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FACCPAYEDAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FCASORG BIGINT  DEFAULT 0 NOT NULL   ,
FACCNOTPAYAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FQUOTETYPE CHAR(1)  DEFAULT ' ' NOT NULL,
FORIAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPAYERACCOUNT01 VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FEXCHANGERATE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPAYERID BIGINT  DEFAULT 0 NOT NULL   ,
FACCBALANCEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FPAYERBANKID BIGINT  DEFAULT 0 NOT NULL   ,
FPAYMODEID BIGINT  DEFAULT 0 NOT NULL   ,
FORIACCBALANCEAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FBANKLOGO NVARCHAR(255)  DEFAULT ' ' NOT NULL   ,
FPAYERACCOUNT02 VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FPAYERACCOUNT VARCHAR(50)  DEFAULT ' ' NOT NULL   ,
FCURRENCYID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPACCOUNT', 'T_ER_NTRIPACCOUNT', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NTRIPACCOUNT_FSEQ') CREATE INDEX IDX_ER_NTRIPACCOUNT_FSEQ  ON T_ER_NTRIPACCOUNT ( FID,FSEQ);



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_NTRIPREIMBURSE_TC')
CREATE TABLE T_ER_NTRIPREIMBURSE_TC (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FTBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FTTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSBILLID BIGINT  DEFAULT 0 NOT NULL   ,
FSTABLEID BIGINT  DEFAULT 0 NOT NULL   ,
FSID BIGINT  DEFAULT 0 NOT NULL   ,
FTID BIGINT  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_NTRIPREIMBURSE_TC', 'T_ER_NTRIPREIMBURSE_TC', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIMBURSEBILL_TC_TBILL') CREATE INDEX IDX_ER_NREIMBURSEBILL_TC_TBILL  ON T_ER_NTRIPREIMBURSE_TC ( FTBILLID);
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_NREIM_TC_FSBILLID') CREATE INDEX IDX_ER_NREIM_TC_FSBILLID  ON T_ER_NTRIPREIMBURSE_TC ( FSBILLID);

/*汇总信息*/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_SUMMARYAMOUNTENTRY')
CREATE TABLE T_ER_SUMMARYAMOUNTENTRY (
FID BIGINT  DEFAULT 0 NOT NULL   ,
FENTRYID BIGINT  DEFAULT 0 NOT NULL   ,
FSEQ INT  DEFAULT 0 NOT NULL   ,
FSUMMONTHSETTLE CHAR(1)  DEFAULT ' ' NOT NULL   ,
FSUMORITRIPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMTAXAMOUNTINVOICE DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMOFFSETAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMDEDUCTIBLETAX DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMCURRENCY BIGINT  DEFAULT 0 NOT NULL   ,
FSUMORITRIPAPPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMTRIPAPPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMTRIPAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL   ,
FSUMTAXAMOUNT DECIMAL(23,10)  DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_SUMMARYAMOUNTENTRY', 'T_ER_SUMMARYAMOUNTENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_SUMMTENTRY_FENTTRYID') CREATE INDEX IDX_ER_SUMMTENTRY_FENTTRYID  ON T_ER_SUMMARYAMOUNTENTRY ( FID);

-- 发票信息对平字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEINFO' AND KSQL_COL_NAME ='FINVOICEITEMEQUAL')
ALTER TABLE T_ER_NINVOICEINFO ADD (FINVOICEITEMEQUAL CHAR(1) DEFAULT '1' NOT NULL );

-- 发票明细单头税率字段
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_NINVOICEITEM' AND KSQL_COL_NAME ='FINVOICETAXRATE')
ALTER TABLE T_ER_NINVOICEITEM ADD (FINVOICETAXRATE NVARCHAR(500) DEFAULT ' ' NOT NULL );