/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\AR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRRESERVECONFIG') 
 CREATE TABLE T_AR_ACCRRESERVECONFIG (
FID BIGINT DEFAULT 0 NOT NULL,
FENTITYID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FSERVICE NVARCHAR(200) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRUALFACTOR') 
 CREATE TABLE T_AR_ACCRUALFACTOR (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL,
FBASEDATAMAIN NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FFACTORTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRUALFACTOR_ENTRY') 
 CREATE TABLE T_AR_ACCRUALFACTOR_ENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FENTRYTISDEFAULT CHAR(1) DEFAULT ' ' NOT NULL,
FMAPPINGFIELD NVARCHAR(50) DEFAULT ' ' NOT NULL,
FMAPPINGFIELDNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBIZMAIN NVARCHAR(36) DEFAULT ' ' NOT NULL,
FRESERVEFIELD NVARCHAR(50) DEFAULT ' ' NOT NULL,
FRESERVEFIELDNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRUALSCHM_IND') 
 CREATE TABLE T_AR_ACCRUALSCHM_IND (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY NVARCHAR(30) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FACCRUALFACTORDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
FACCRUALFACTOR NVARCHAR(255) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRUALSCHM_INDENTRY') 
 CREATE TABLE T_AR_ACCRUALSCHM_INDENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FFILTERTEXT VARCHAR(2000) DEFAULT ' ' NOT NULL,
FRANGE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FDAYS INT DEFAULT 0 NOT NULL,
FENDDAYS INT DEFAULT 0 NOT NULL,
FISABOVE CHAR(1) DEFAULT ' ' NOT NULL,
FACCRUALRATE DECIMAL(19,6) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_ACCRUALSOURCE') 
 CREATE TABLE T_AR_ACCRUALSOURCE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FISDEFAULT CHAR(1) DEFAULT '0' NOT NULL,
FDATEFIELDDESC NVARCHAR(50) DEFAULT ' ' NOT NULL,
FDATEFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FBASEAMFIELDDESC NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBASEAMFIELD VARCHAR(50) DEFAULT ' ' NOT NULL,
FAMTTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FFILTERDESC NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FFILTER VARCHAR(2000) DEFAULT ' ' NOT NULL,
FWOFFFILTERDESC NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FWOFFFILTER VARCHAR(2000) DEFAULT ' ' NOT NULL,
FENTITYOBJECTID NVARCHAR(36) DEFAULT ' ' NOT NULL,
FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL
);


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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_MULACCRUALSOURCE') 
 CREATE TABLE T_AR_MULACCRUALSOURCE (
FPKID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_AR_MULACCRUALSOURCE_IND') 
 CREATE TABLE T_AR_MULACCRUALSOURCE_IND (
FPKID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVE' AND KSQL_COL_NAME ='FACCRUALSCHTYPE') 
 ALTER TABLE T_AR_BADDEBTRESERVE ADD (FACCRUALSCHTYPE VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_BADDEBTRESERVE' AND KSQL_COL_NAME ='FACCRUALSCHTYPEID') 
 ALTER TABLE T_AR_BADDEBTRESERVE ADD (FACCRUALSCHTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_ACCRUALSCHEMEENTRY' AND KSQL_COL_NAME ='FFILTERTEXT') 
 ALTER TABLE T_AR_ACCRUALSCHEMEENTRY ADD (FFILTERTEXT VARCHAR(2000) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_ACCRUALSCHEME' AND KSQL_COL_NAME ='FACCRUALFACTORDESC') 
 ALTER TABLE T_AR_ACCRUALSCHEME ADD (FACCRUALFACTORDESC NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_AR_ACCRUALSOURCE' AND KSQL_COL_NAME ='FENABLE') 
 ALTER TABLE T_AR_ACCRUALSOURCE ADD (FENABLE VARCHAR(5) DEFAULT ' ' NOT NULL );

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