/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHMAPPING')
 CREATE TABLE T_AP_MATCHMAPPING (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATEDATE DATETIME,
FMODIFYDATE DATETIME,
FBIZAPPID VARCHAR(30) DEFAULT ' ' NOT NULL,
FISENABLE CHAR(1) DEFAULT '1' NOT NULL,
FISSYSINIT CHAR(1) DEFAULT '1' NOT NULL,
FSOURCEBILL VARCHAR(36) DEFAULT ' ' NOT NULL,
FTARGETOBJ VARCHAR(36) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHMAPPING_E')
 CREATE TABLE T_AP_MATCHMAPPING_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FTARGETOBJCOLNO NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEBILLCOL NVARCHAR(100) DEFAULT ' ' NOT NULL,
FTARGETOBJCOL NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSOURCEBILLCOLNO NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSELECTVALUE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FFORMULA NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFORMULADESC NVARCHAR(500) DEFAULT ' ' NOT NULL,
FFORMULA_TAG NCLOB
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHRELATION')
 CREATE TABLE T_AP_MATCHRELATION (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL,
FISPRESET CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHRELATION_E')
 CREATE TABLE T_AP_MATCHRELATION_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FMATCHOBJECT NVARCHAR(36) DEFAULT ' ' NOT NULL,
FPRESETFILTER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRESETFILTERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPRESETFILTERDESC_TAG NCLOB,
FCUSTOMERFILTER NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCUSTOMERFILTERDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FCUSTOMERFILTERDESC_TAG NCLOB,
FBIZTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHSCHEMEV2')
 CREATE TABLE T_AP_MATCHSCHEMEV2 (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT ' ' NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL,
FISPRESET CHAR(1) DEFAULT '0' NOT NULL,
FMATCHRELATION BIGINT DEFAULT 0 NOT NULL,
FMATCHMODE VARCHAR(30) DEFAULT ' ' NOT NULL,
FTOLERANCESCHEME BIGINT DEFAULT 0 NOT NULL,
FEXECUTERID BIGINT DEFAULT 0 NOT NULL,
FEXCEPLANDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSHEDULEPLANID VARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHSCHEMEV2_ALGO')
 CREATE TABLE T_AP_MATCHSCHEMEV2_ALGO (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINVOICEFIELD NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCOMPARISON NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHOBJECTALGO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHOBJECTFIELD NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHALGO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHALGODESC NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHSCHEMEV2_ALGO_L')
 CREATE TABLE T_AP_MATCHSCHEMEV2_ALGO_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FMATCHALGODESC NVARCHAR(1000) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHSCHEMEV2_C')
 CREATE TABLE T_AP_MATCHSCHEMEV2_C (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINVOICEKEY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FINVOICEKEYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FCOMPARISON NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHOBJECTKEY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMATCHOBJECTKEYNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FISNULLMATCH CHAR(1) DEFAULT '0' NOT NULL,
FISPRESET CHAR(1) DEFAULT '0' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_MATCHSCHEMEV2_O')
 CREATE TABLE T_AP_MATCHSCHEMEV2_O (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FMATCHOBJECT NVARCHAR(36) DEFAULT ' ' NOT NULL
);

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

/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AP_INVOICEENTRY' AND KSQL_COL_NAME ='FBASEUNIT')
 ALTER TABLE T_AP_INVOICEENTRY ADD (FBASEUNIT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AP_INVOICEENTRY' AND KSQL_COL_NAME ='FBASEUNITQTY')
 ALTER TABLE T_AP_INVOICEENTRY ADD (FBASEUNITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AP_INVOICEENTRY' AND KSQL_COL_NAME ='FUNMATCHBASEQTY')
 ALTER TABLE T_AP_INVOICEENTRY ADD (FUNMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AP_INVOICEENTRY' AND KSQL_COL_NAME ='FTAXLOCALAMT')
 ALTER TABLE T_AP_INVOICEENTRY ADD (FTAXLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AP_INVOICE' AND KSQL_COL_NAME ='FMATCHSTATUS')
 ALTER TABLE T_AP_INVOICE ADD (FMATCHSTATUS VARCHAR(30) DEFAULT '0' NOT NULL );

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

/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_INVMATCH')
 CREATE TABLE T_AP_INVMATCH (
FID BIGINT DEFAULT 0 NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMATCHDATE DATETIME,
FMODIFYTIME DATETIME,
FBILLSTATUS VARCHAR(30) DEFAULT 'A' NOT NULL,
FMATCHRELATION BIGINT DEFAULT 0 NOT NULL,
FMATCHSCHEME BIGINT DEFAULT 0 NOT NULL,
FTOLERANCESCHEME BIGINT DEFAULT 0 NOT NULL,
FCURRENCY BIGINT DEFAULT 0 NOT NULL,
FMATCHMODE VARCHAR(30) DEFAULT 'total' NOT NULL,
FMATCHSTATUS VARCHAR(30) DEFAULT '0' NOT NULL,
FISDIFFMATCH CHAR(1) DEFAULT '0' NOT NULL,
FISCONFIRMFINAP CHAR(1) DEFAULT '0' NOT NULL,
FAMTTOTAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXTOTAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICETOTAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FMATCHENTRYAMTINFO NVARCHAR(255) DEFAULT ' ' NOT NULL,
FMATCHENTRYAMTINFO_TAG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_INVMATCHIENTRY')
 CREATE TABLE T_AP_INVMATCHIENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FINVOICEID BIGINT DEFAULT 0 NOT NULL,
FINVOICEENTRYID BIGINT DEFAULT 0 NOT NULL,
FMATERIAL BIGINT DEFAULT 0 NOT NULL,
FAMTDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICETOTALDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEQTYDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_INVMATCHOBJAENTRY')
 CREATE TABLE T_AP_INVMATCHOBJAENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FFINAPBILLID BIGINT DEFAULT 0 NOT NULL,
FCURMATCHAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHPRICETAXTOTAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICETOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICELOCALAMT DECIMAL(23,10) DEFAULT 0,
FCURINVOICELOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICELOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICEDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_INVMATCHOBJBENTRY')
 CREATE TABLE T_AP_INVMATCHOBJBENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FFINAPBILLID BIGINT DEFAULT 0 NOT NULL,
FCURMATCHAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHPRICETAXTOTAL DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHLOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHLOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNMATCHBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICEAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICETOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICELOCALAMT DECIMAL(23,10) DEFAULT 0,
FCURINVOICELOCALTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCURINVOICELOCALTOTALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICEDIFF DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AP_INVMATCHOBJCENTRY')
 CREATE TABLE T_AP_INVMATCHOBJCENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBILLID BIGINT DEFAULT 0 NOT NULL,
FBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEBILLENTRYID BIGINT DEFAULT 0 NOT NULL
);



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