/**Begin D:\PDM_UPGRADE_1.3\PDM_UPGRADE\pdm1\RIM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM' AND KSQL_COL_NAME ='FSECOND_DEPT_NAME') 
 ALTER TABLE T_RIM_INV_CUSTOM ADD (FSECOND_DEPT_NAME NVARCHAR(80) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM' AND KSQL_COL_NAME ='FSECOND_DEPT_TAX_NO') 
 ALTER TABLE T_RIM_INV_CUSTOM ADD (FSECOND_DEPT_TAX_NO NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM' AND KSQL_COL_NAME ='FPORT_CODE') 
 ALTER TABLE T_RIM_INV_CUSTOM ADD (FPORT_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM' AND KSQL_COL_NAME ='FCUSTOMS_NAME') 
 ALTER TABLE T_RIM_INV_CUSTOM ADD (FCUSTOMS_NAME NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM' AND KSQL_COL_NAME ='FDATA_SOURCE') 
 ALTER TABLE T_RIM_INV_CUSTOM ADD (FDATA_SOURCE NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM_ITEM' AND KSQL_COL_NAME ='FORDER_NUMBER') 
 ALTER TABLE T_RIM_INV_CUSTOM_ITEM ADD (FORDER_NUMBER INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_RIM_INV_CUSTOM_ITEM' AND KSQL_COL_NAME ='FITEM_SOURCE') 
 ALTER TABLE T_RIM_INV_CUSTOM_ITEM ADD (FITEM_SOURCE NVARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_RIM_INV_TRAIN_REFUND') 
 CREATE TABLE T_RIM_INV_TRAIN_REFUND (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(2) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FSERIAL_NO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FAWS_SERIAL_NO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FNUMBER NVARCHAR(32) DEFAULT ' ' NOT NULL,
FTOTAL_AMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINVOICE_DATE DATETIME,
FVOUCHER_TITLE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTENANT_NO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FTAX_ORG BIGINT DEFAULT 0 NOT NULL,
FINVOICE_TYPE BIGINT DEFAULT 0 NOT NULL,
FORG_ID BIGINT DEFAULT 0 NOT NULL,
FRESOURCE NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_RIM_INV_FINANCIAL') 
 CREATE TABLE T_RIM_INV_FINANCIAL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(2) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FSERIAL_NO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FAWS_SERIAL_NO NVARCHAR(36) DEFAULT ' ' NOT NULL,
FINVOICE_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FINVOICE_CODE NVARCHAR(12) DEFAULT ' ' NOT NULL,
FINVOICE_NO NVARCHAR(10) DEFAULT ' ' NOT NULL,
FCHECK_CODE NVARCHAR(10) DEFAULT ' ' NOT NULL,
FINVOICE_DATE DATETIME,
FINVOICE_TIME DATETIME,
FTOTAL_AMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINVOICING_PARTY_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICING_PARTY_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FBIZ_CODE NVARCHAR(32) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(500) DEFAULT ' ' NOT NULL,
FPAYER_PARTY_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FPAYER_PARTY_NAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FHANDLING_PERSON NVARCHAR(20) DEFAULT ' ' NOT NULL,
FCHECKER NVARCHAR(20) DEFAULT ' ' NOT NULL,
FRELATED_INVOICE_CODE NVARCHAR(12) DEFAULT ' ' NOT NULL,
FRELATED_INVOICE_NO NVARCHAR(10) DEFAULT ' ' NOT NULL,
FPAYER_PARTY_TYPE NVARCHAR(10) DEFAULT ' ' NOT NULL,
FPAY_MODE NVARCHAR(10) DEFAULT ' ' NOT NULL,
FORG_ID BIGINT DEFAULT 0 NOT NULL,
FTAX_ORG BIGINT DEFAULT 0 NOT NULL,
FTENANT_NO NVARCHAR(30) DEFAULT ' ' NOT NULL,
FINVOICE_TYPE BIGINT DEFAULT 0 NOT NULL,
FRESOURCE NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_RIM_INV_FINANCIAL_ITEM') 
 CREATE TABLE T_RIM_INV_FINANCIAL_ITEM (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FITEM_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FITEM_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FITEM_QUANTITY INT DEFAULT 0 NOT NULL,
FITEM_UNIT NVARCHAR(30) DEFAULT ' ' NOT NULL,
FITEM_STD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEM_AMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FITEM_REMARK NVARCHAR(200) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_RIM_INV_FINANCIAL_ITEMA') 
 CREATE TABLE T_RIM_INV_FINANCIAL_ITEMA (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FAUX_ITEM_RELATED_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAUX_ITEM_RELATED_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAUX_ITEM_REMARK NVARCHAR(200) DEFAULT ' ' NOT NULL,
FAUX_ITEM_CODE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAUX_ITEM_QUANTITY INT DEFAULT 0 NOT NULL,
FAUX_ITEM_UNIT NVARCHAR(30) DEFAULT ' ' NOT NULL,
FAUX_ITEM_STD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAUX_ITEM_AMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL
);



/**End D:\PDM_UPGRADE_1.3\PDM_UPGRADE\pdm1\RIM_table.sql **/
