/**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_BUSPLANENTRY' AND KSQL_COL_NAME IN ('FFINALRECAMOUNT')) 
 ALTER TABLE T_AR_BUSPLANENTRY ADD (FFINALRECAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSPLANENTRY' AND KSQL_COL_NAME IN ('FFINALRECLOCALAMT')) 
 ALTER TABLE T_AR_BUSPLANENTRY ADD (FFINALRECLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSPLANENTRY', 'FNOINVOICEAMT', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSPLANENTRY', 'FNOINVOICELOCAMT', 'NULL', 'NULL', '1001', 'NULL';

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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INITENTRY' AND KSQL_COL_NAME IN ('FBADDEBTAMT')) 
 ALTER TABLE T_AR_INITENTRY ADD (FBADDEBTAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FPOLICYTYPEID')) 
 ALTER TABLE T_AR_INIT ADD (FPOLICYTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FPERIODTYPEID')) 
 ALTER TABLE T_AR_INIT ADD (FPERIODTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FSTARTPERIODID')) 
 ALTER TABLE T_AR_INIT ADD (FSTARTPERIODID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FCURRENTPERIODID')) 
 ALTER TABLE T_AR_INIT ADD (FCURRENTPERIODID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FBADDEBTPOLICY')) 
 ALTER TABLE T_AR_INIT ADD (FBADDEBTPOLICY VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INIT' AND KSQL_COL_NAME IN ('FPOLICYID')) 
 ALTER TABLE T_AR_INIT ADD (FPOLICYID BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FCREATEORGID', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FORGID', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FUSEORGID', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FCTRLSTRATEGY', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FPERIODTYPEID', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_ACCRUALSCHEME', 'FBADDEBTPOLICY', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_FINARBILL_E') 
 CREATE TABLE T_AR_FINARBILL_E (
FID BIGINT DEFAULT 0 NOT NULL,
FBADDEBTCAUSE VARCHAR(30) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_RECEIVEDBILLENTRY' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_RECEIVEDBILLENTRY ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_RECEIVEDBILL' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_RECEIVEDBILL ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INVOICEENTRY' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_INVOICEENTRY ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_LOSSBILLENTRY' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_LOSSBILLENTRY ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTLOSSBILL' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_BADDEBTLOSSBILL ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_INVOICE' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_INVOICE ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FFINALQTY')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FFINALQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FINVOICEDQTY')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FINVOICEDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FUNINVOICEDQTY')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FUNINVOICEDQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FFINALRECAMOUNT')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FFINALRECAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FFINALRECLOCALAMT')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FFINALRECLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILLENTRY' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_BUSBILLENTRY ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSBILLENTRY', 'FNOINVOICEAMT', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSBILLENTRY', 'FNOINVOICELOCAMT', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILL' AND KSQL_COL_NAME IN ('FFINALRECAMOUNT')) 
 ALTER TABLE T_AR_BUSBILL ADD (FFINALRECAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILL' AND KSQL_COL_NAME IN ('FFINALRECLOCALAMT')) 
 ALTER TABLE T_AR_BUSBILL ADD (FFINALRECLOCALAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILL' AND KSQL_COL_NAME IN ('FISWRITEOFF')) 
 ALTER TABLE T_AR_BUSBILL ADD (FISWRITEOFF CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BUSBILL' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_BUSBILL ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSBILL', 'FNOINVOICEAMT', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_AR_BUSBILL', 'FNOINVOICELOCAMT', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVE' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_BADDEBTRESERVE ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVE' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_BADDEBTRESERVE ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVE' AND KSQL_COL_NAME IN ('FSOURCEBILLTYPE')) 
 ALTER TABLE T_AR_BADDEBTRESERVE ADD (FSOURCEBILLTYPE VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVEBILL' AND KSQL_COL_NAME IN ('FDEPARTMENTID')) 
 ALTER TABLE T_AR_BADDEBTRESERVEBILL ADD (FDEPARTMENTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVEBILL' AND KSQL_COL_NAME IN ('FPROJECTID')) 
 ALTER TABLE T_AR_BADDEBTRESERVEBILL ADD (FPROJECTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVEBILL' AND KSQL_COL_NAME IN ('FAUDITORID')) 
 ALTER TABLE T_AR_BADDEBTRESERVEBILL ADD (FAUDITORID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVEBILL' AND KSQL_COL_NAME IN ('FAUDITDATE')) 
 ALTER TABLE T_AR_BADDEBTRESERVEBILL ADD (FAUDITDATE DATETIME );

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