/**BEGIN E:\NEXTERP_PDM\PDM_UPGRADE\PDMS\BRANCH_LASTEST\PDM\POM_TABLE.SQL **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL') 
CREATE TABLE T_IM_MDC_MFTRETURNBILL (
	FID BIGINT DEFAULT 0 NOT NULL,
	FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL,
	FBILLSTATUS NVARCHAR(50) 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,
	FCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL,
	FAPPLYUSERID BIGINT DEFAULT 0 NOT NULL,
	FSETTLECURRENCY BIGINT DEFAULT 0 NOT NULL,
	FBILLCRETYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FLASTUPDATEUSERID BIGINT DEFAULT 0 NOT NULL,
	FLASTUPDATETIME DATETIME,
	FUNITSRCTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FMATERIALTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FREQTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FINVORG BIGINT DEFAULT 0 NOT NULL,
	FACCOUNTORG BIGINT DEFAULT 0 NOT NULL,
	FSUPPLIER BIGINT DEFAULT 0 NOT NULL,
	FCLOSER BIGINT DEFAULT 0 NOT NULL,
	FCLOSEDATE DATETIME
);
 EXEC P_ALTERPK 'PK_IM_MDC_MFTRETURNBILL', 'T_IM_MDC_MFTRETURNBILL', 'FID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTRETURNBILL_FNO') CREATE INDEX IDX_IM_MDC_MFTRETURNBILL_FNO ON T_IM_MDC_MFTRETURNBILL ( FBILLNO );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTRETURNBILL_FCTIME') CREATE INDEX IDX_IM_MDC_MFTRETURNBILL_FCTIME ON T_IM_MDC_MFTRETURNBILL ( FCREATETIME );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL_L') 
CREATE TABLE T_IM_MDC_MFTRETURNBILL_L (
	FPKID NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FID BIGINT DEFAULT 0 NOT NULL,
	FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
	FCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL
);

 EXEC P_ALTERPK 'PK_IM_MDC_MFTRETURNBILL_L', 'T_IM_MDC_MFTRETURNBILL_L', 'FPKID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL_L' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTRETURNBILL_L_FID') CREATE INDEX IDX_IM_MDC_MFTRETURNBILL_L_FID ON T_IM_MDC_MFTRETURNBILL_L ( FID ,FLOCALEID );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTRETURNBILL_L' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTRETURNBILL_L_FCOM') CREATE INDEX IDX_IM_MDC_MFTRETURNBILL_L_FCOM ON T_IM_MDC_MFTRETURNBILL_L ( FCOMMENT );


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTAPPREQENTRY') 
CREATE TABLE T_IM_MDC_MFTAPPREQENTRY (
	FID BIGINT DEFAULT 0 NOT NULL,
	FENTRYID BIGINT DEFAULT 0 NOT NULL,
	FSEQ BIGINT 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(50) DEFAULT ' ' NOT NULL,
	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,
	FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL,
	FPRODUCEDATE DATETIME,
	FEXPIRYDATE DATETIME,
	FLOGISTICSBILL CHAR(1) DEFAULT '0' NOT NULL,
	FMVERSION BIGINT DEFAULT 0 NOT NULL,
	FSRCSYSBILLENTRYID NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCSYSBILLID NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCSYSTEM NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FLINETYPEID BIGINT DEFAULT 0 NOT NULL,
	FMATERIALNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
	FTRACKNUMBERID BIGINT DEFAULT 0 NOT NULL,
	FCONFIGUREDCODEID BIGINT DEFAULT 0 NOT NULL,
	FECOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
	FSERIALNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FORDERNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FORDERENTRYSEQ NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FORDERID BIGINT DEFAULT 0 NOT NULL,
	FORDERENTRYID BIGINT DEFAULT 0 NOT NULL,
	FNEEDDATE DATETIME,
	FAUDITBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FAVAILAQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FISSTOCKALLOT CHAR(1) DEFAULT '0' NOT NULL,
	FOUTINVORG BIGINT DEFAULT 0 NOT NULL,
	FOUTWAREHOUSEID BIGINT DEFAULT 0 NOT NULL,
	FOUTLOCATION BIGINT DEFAULT 0 NOT NULL,
	FSUPPLYMODE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSUPPLIERID BIGINT DEFAULT 0 NOT NULL,
	FREWORK CHAR(1) DEFAULT '0' NOT NULL,
	FOUTBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FUNPICKBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FUSEOUTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FUSEOUTBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FUNPICKQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FROWSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCBILLNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCBILLID BIGINT DEFAULT 0 NOT NULL,
	FSRCBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
	FSRCBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
	FMAINBILLENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
	FMAINBILLID BIGINT DEFAULT 0 NOT NULL,
	FMAINBILLENTRYID BIGINT DEFAULT 0 NOT NULL,
	FMAINBILLNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FPROCESSSEQ BIGINT DEFAULT 0 NOT NULL,
	FPROCESSNO BIGINT DEFAULT 0 NOT NULL,
	FTEXTFIELD NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FPROCESSINFO NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FWORKCENTER BIGINT DEFAULT 0 NOT NULL,
	FWORKSTATION BIGINT DEFAULT 0 NOT NULL,
	FSUPPLY BIGINT DEFAULT 0 NOT NULL,
	FMACHININGTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FISADD CHAR(1) DEFAULT '1' NOT NULL,
	FUPDATESTOCKRESULT NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FMAINBILLENTITY NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSRCBILLTYPE BIGINT DEFAULT 0 NOT NULL,
	FMATERIALREPLACE NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FMATERIALREP BIGINT DEFAULT 0 NOT NULL,
	FSTOCKBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FSTOCKENTRYSEQ BIGINT DEFAULT 0 NOT NULL,
	FSTOCKENTRYID BIGINT DEFAULT 0 NOT NULL,
	FTARGETID BIGINT DEFAULT 0 NOT NULL,
	FTARGETNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
	FFEEDREASON BIGINT DEFAULT 0 NOT NULL,
	FBACKREASON BIGINT DEFAULT 0 NOT NULL,
	FCHECKBACK CHAR(1) DEFAULT '0' NOT NULL,
	FQCORG BIGINT DEFAULT 0 NOT NULL,
	FPCHECKBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FCHECKBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FGDBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FCOACCPBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FPOINCBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FPOWORKBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
	FMATERIELMASTERID BIGINT DEFAULT 0 NOT NULL,
	FSRCBILLENTITY NVARCHAR(50) DEFAULT ' ' NOT NULL
);

 EXEC P_ALTERPK 'PK_IM_MDC_MFTAPPREQENTRY', 'T_IM_MDC_MFTAPPREQENTRY', 'FENTRYID', '1';
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTAPPREQENTRY' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTAPPREQENTRY_FID') CREATE INDEX IDX_IM_MDC_MFTAPPREQENTRY_FID ON T_IM_MDC_MFTAPPREQENTRY ( FID );
 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_TABNAME = 'T_IM_MDC_MFTAPPREQENTRY' AND KSQL_INDNAME = 'IDX_IM_MDC_MFTAPPREQENTRY_FSEQ') CREATE INDEX IDX_IM_MDC_MFTAPPREQENTRY_FSEQ ON T_IM_MDC_MFTAPPREQENTRY ( FSEQ );

/**END E:\NEXTERP_PDM\PDM_UPGRADE\PDMS\BRANCH_LASTEST\PDM\POM_TABLE.SQL **/
