/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INVOICEENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_AR_INVOICEENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_JOURNAL' AND KSQL_COL_NAME ='FSOURCEENTRYID') 
 ALTER TABLE T_AR_JOURNAL ADD (FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_JOURNAL' AND KSQL_COL_NAME ='FBIZTYPE') 
 ALTER TABLE T_AR_JOURNAL ADD (FBIZTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_LIQUIDATION') 
 CREATE TABLE T_AR_LIQUIDATION (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS VARCHAR(5) 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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FLIQUIDATIONDATE DATETIME,
FLIQUIDATERID BIGINT DEFAULT 0 NOT NULL,
FCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FEXCHANGERATE DECIMAL(19,6) DEFAULT 0 NOT NULL,
FLIQUIDATIONAMT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FLIQUIDATIONLOCALAMT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FDESCRIPTION NVARCHAR(255),
FASSTACTTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FASSTACT BIGINT DEFAULT 0 NOT NULL,
FISSETTLED CHAR(1) DEFAULT ' ' NOT NULL,
FBASECURRENCYID BIGINT DEFAULT 0 NOT NULL,
FISVOUCHER CHAR(1) DEFAULT ' ' NOT NULL,
FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL,
FEXRATETABLEID BIGINT DEFAULT 0 NOT NULL,
FEXRATEDATE DATETIME
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_LIQUIDATIONENTRY') 
 CREATE TABLE T_AR_LIQUIDATIONENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSOURCEBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSOURCEBILLDATE DATETIME,
FITEMTYPE VARCHAR(30) DEFAULT ' ' NOT NULL,
FITEMID BIGINT DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FUNSETTLEAMT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILL_E' AND KSQL_COL_NAME ='FISINTERTAX') 
 ALTER TABLE T_AR_BUSBILL_E ADD (FISINTERTAX CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_FINARBILL_E' AND KSQL_COL_NAME ='FDEPARTMENTID') 
 ALTER TABLE T_AR_FINARBILL_E ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_FINARBILL_E' AND KSQL_COL_NAME ='FISINTERTAX') 
 ALTER TABLE T_AR_FINARBILL_E ADD (FISINTERTAX CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_BUSBILLTAXENTRY') 
 CREATE TABLE T_AR_BUSBILLTAXENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FTAXCATEGORYID BIGINT,
FISINPRICETAX CHAR(1),
FISINPUTTAX CHAR(1),
FTAXRATEID BIGINT DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXTIME NVARCHAR(255),
FINCLUDETAIL CHAR(1),
FDISCOUNTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINCLUDEDISCOUNT CHAR(1),
FINCLUDEVAT CHAR(1),
FTAXBASE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCANDEDUCTIBLE CHAR(1),
FDEDUCTIONRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDEDUCTIBLE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FNONDEDUCTIBLE DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_FINARBILLTAXENTRY') 
 CREATE TABLE T_AR_FINARBILLTAXENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FTAXCATEGORYID BIGINT,
FISINPRICETAX CHAR(1),
FISINPUTTAX CHAR(1),
FTAXRATEID BIGINT DEFAULT 0 NOT NULL,
FTAXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAXTIME NVARCHAR(255),
FINCLUDETAIL CHAR(1),
FDISCOUNTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINCLUDEDISCOUNT CHAR(1),
FINCLUDEVAT CHAR(1),
FTAXBASE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCANDEDUCTIBLE CHAR(1),
FDEDUCTIONRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDEDUCTIBLE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FNONDEDUCTIBLE DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_FINARBILLENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_AR_FINARBILLENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_FINARBILLENTRY' AND KSQL_COL_NAME ='FPROJECTID') 
 ALTER TABLE T_AR_FINARBILLENTRY ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_FINARBILLENTRY_E') 
 CREATE TABLE T_AR_FINARBILLENTRY_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FVATTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRECTAX DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_BUSBILLENTRY_E') 
 CREATE TABLE T_AR_BUSBILLENTRY_E (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FVATTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FRECTAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCONFIRMEDAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNCONFIRMAMT DECIMAL(23,10) DEFAULT 0 NOT NULL
);



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