/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MREQBILL') 
 CREATE TABLE T_IM_MREQBILL (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS CHAR(1) 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,
FORGID BIGINT DEFAULT 0 NOT NULL,
FBIZTIME DATETIME,
FBIZTYPEID BIGINT DEFAULT 0 NOT NULL,
FBILLTYPEID BIGINT DEFAULT 0 NOT NULL,
FDEPTID BIGINT DEFAULT 0 NOT NULL,
FAPPLYUSERID BIGINT DEFAULT 0 NOT NULL,
FSUPPLYOWNER BIGINT DEFAULT 0 NOT NULL,
FBIZORGID BIGINT DEFAULT 0 NOT NULL,
FCOSTCENTERORG BIGINT DEFAULT 0 NOT NULL,
FSETTLEORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MREQBILLENTRY') 
 CREATE TABLE T_IM_MREQBILLENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ DECIMAL(23,10) DEFAULT 0 NOT NULL,
FMATERIALID BIGINT DEFAULT 0 NOT NULL,
FAUXPTYID BIGINT DEFAULT 0 NOT NULL,
FQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNITID BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBASEUNITID BIGINT DEFAULT 0 NOT NULL,
FWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
FLOCATIONID BIGINT DEFAULT 0 NOT NULL,
FLOTID BIGINT DEFAULT 0 NOT NULL,
FLOTNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FPRODUCEDATE DATETIME,
FEXPIRYDATE DATETIME,
FENTRYCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL,
FPROJECTID BIGINT DEFAULT 0 NOT NULL,
FAUDITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTYUNIT2ND DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT2NDID BIGINT DEFAULT 0 NOT NULL,
FUNIT2NDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FQTYUNIT3RD DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNIT3RDID BIGINT DEFAULT 0 NOT NULL,
FUNIT3RDRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FUNITRATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINOUTBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREMAINOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FISFREEGIFT CHAR(1) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MREQBILLSNENTRY') 
 CREATE TABLE T_IM_MREQBILLSNENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSERIALNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FSERIALID BIGINT DEFAULT 0 NOT NULL,
FSERIALCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSAPPLYENTRY' AND KSQL_COL_NAME IN ('FMATERIALMASTERID')) 
 ALTER TABLE T_IM_TRANSAPPLYENTRY ADD (FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MREQBILL_L') 
 CREATE TABLE T_IM_MREQBILL_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCOMMENT NVARCHAR(510) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MREQOUTBILL_L') 
 CREATE TABLE T_IM_MREQOUTBILL_L (
FPKID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID NVARCHAR(30) DEFAULT ' ' NOT NULL,
FCOMMENT NVARCHAR(510) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTOWNERTYPE')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTOWNERID')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTOWNERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTKEEPERTYPE')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTKEEPERID')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTKEEPERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQOUTBILLENTRY' AND KSQL_COL_NAME IN ('FISFREEGIFT')) 
 ALTER TABLE T_IM_MREQOUTBILLENTRY ADD (FISFREEGIFT CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILL' AND KSQL_COL_NAME IN ('FISVIRTUALBILL')) 
 ALTER TABLE T_IM_SALOUTBILL ADD (FISVIRTUALBILL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILL' AND KSQL_COL_NAME IN ('FISVIRTUALBILL')) 
 ALTER TABLE T_IM_PURINBILL ADD (FISVIRTUALBILL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSOUTBILL' AND KSQL_COL_NAME IN ('FISVIRTUALBILL')) 
 ALTER TABLE T_IM_TRANSOUTBILL ADD (FISVIRTUALBILL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_TRANSINBILL' AND KSQL_COL_NAME IN ('FISVIRTUALBILL')) 
 ALTER TABLE T_IM_TRANSINBILL ADD (FISVIRTUALBILL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_TRANSAPPLYENTRY_Y') 
 CREATE TABLE T_IM_TRANSAPPLYENTRY_Y (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FINLOCATION BIGINT DEFAULT 0 NOT NULL
);



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