/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\PDM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOM') 
CREATE TABLE T_PDM_MFTBOM
   (	
      FID            BIGINT 		DEFAULT 0 NOT NULL,
	  FNUMBER        NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FSTATUS        NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FCREATORID     BIGINT 		DEFAULT 0 NOT NULL,
	  FMODIFIERID    BIGINT 		DEFAULT 0 NOT NULL,
	  FENABLE        NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FCREATETIME    datetime,
	  FMODIFYTIME    datetime,
	  FMASTERID      BIGINT 		DEFAULT 0 NOT NULL,
	  FGROUPID       BIGINT 		DEFAULT 0 NOT NULL,
	  FORGID         BIGINT 		DEFAULT 0 NOT NULL,
	  FCREATEORGID   BIGINT 		DEFAULT 0 NOT NULL,
	  FCTRLSTRATEGY  NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FMATERIALID    BIGINT 		DEFAULT 0 NOT NULL,
	  FVERSIONID     BIGINT 		DEFAULT 0 NOT NULL,
	  FREPLACENOID   BIGINT 		DEFAULT 0 NOT NULL,
	  FYIELDRATE     DECIMAL(23,10) DEFAULT 0 NOT NULL,
	  FAUXPROPERTYID BIGINT 		DEFAULT 0 NOT NULL,
	  FISCOPRODUCT   CHAR(1) DEFAULT '0' NOT NULL,
	  FTYPEID        BIGINT 		DEFAULT 0 NOT NULL,
	  FAUDITORID     BIGINT 		DEFAULT 0 NOT NULL,
	  FAUDITDATE     datetime,
	  FDISABLEUSERID BIGINT 		DEFAULT 0 NOT NULL,
	  FDISABLEDATE   datetime,
	  FENABLEUSERID  BIGINT 		DEFAULT 0 NOT NULL,
	  FENABLEDATE    datetime,
	  FECNVERSION    NVARCHAR(50) DEFAULT ' ' NOT NULL,
	  FECN           BIGINT 		DEFAULT 0 NOT NULL,
	  FBASEDATAFIELD BIGINT 		DEFAULT 0 NOT NULL	  
   );
EXEC P_ALTERPK 'PK_PDM_MFTBOM', 'T_PDM_MFTBOM', 'FID', '1';   
   
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOM_L') 
CREATE TABLE T_PDM_MFTBOM_L
(
  FPKID     NVARCHAR(18) DEFAULT ' ' NOT NULL,
  FID       BIGINT 		DEFAULT 0 NOT NULL,
  FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
  FNAME     NVARCHAR(50) DEFAULT ' ' NOT NULL,
  FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL 
);
EXEC P_ALTERPK 'PK_PDM_MFTBOM_L', 'T_PDM_MFTBOM_L', 'FPKID', '1';   

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMCOPENTRY') 
CREATE TABLE T_PDM_MFTBOMCOPENTRY
(
  FID            BIGINT 		DEFAULT 0 NOT NULL,
  FENTRYID       BIGINT 		DEFAULT 0 NOT NULL,
  FSEQ           INT 		DEFAULT 0 NOT NULL,
  FTYPE          NVARCHAR(30) 	DEFAULT ' ' NOT NULL,
  FMATERIALID    BIGINT 		DEFAULT 0 NOT NULL,
  FUNITID        BIGINT 		DEFAULT 0 NOT NULL,
  FQTY           DECIMAL(23,10)	DEFAULT 0 NOT NULL,
  FOPERATIONID   BIGINT 		DEFAULT 0 NOT NULL,
  FVALIDDATE     DATETIME,
  FINVALIDDATE   DATETIME,
  FVERSIONID     BIGINT 		DEFAULT 0 NOT NULL,
  FAUXPROPERTYID BIGINT 		DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMCOPENTRY', 'T_PDM_MFTBOMCOPENTRY', 'FENTRYID', '1';   

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMCOPENTRY_L') 
CREATE TABLE T_PDM_MFTBOMCOPENTRY_L
(
  FPKID     NVARCHAR(18) DEFAULT ' ' NOT NULL,
  FENTRYID  BIGINT 		DEFAULT 0 NOT NULL,
  FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
  FREMARK   NVARCHAR(255) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMCOPENTRY_L', 'T_PDM_MFTBOMCOPENTRY_L', 'FPKID', '1';  

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMENTRY') 
CREATE TABLE T_PDM_MFTBOMENTRY
   (	
	  FID              BIGINT 		DEFAULT 0 NOT NULL,
	  FENTRYID         BIGINT 		DEFAULT 0 NOT NULL,
	  FSEQ             INT 		DEFAULT 0 NOT NULL,
	  FTYPE            NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FMATERIALID      BIGINT 		DEFAULT 0 NOT NULL,
	  FQTY             BIGINT 		DEFAULT 0 NOT NULL,
	  FUNITID          BIGINT 		DEFAULT 0 NOT NULL,
	  FVERSIONID       BIGINT 		DEFAULT 0 NOT NULL,
	  FQTYTYPE         NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FQTYNUMERATOR   DECIMAL(23,10) DEFAULT 0 NOT NULL,
	  FQTYDENOMINATOR  DECIMAL(23,10) DEFAULT 0 NOT NULL,
	  FFIXSCRAP        DECIMAL(23,10) DEFAULT 0 NOT NULL,
	  FSCRAPRATE       DECIMAL(23,10) DEFAULT 0 NOT NULL,
	  FVALIDDATE       datetime,
	  FINVALIDDATE     datetime,
	  FAUXPROPERTYID   BIGINT 		DEFAULT 0 NOT NULL,
	  FISREPLACEPLANMM CHAR(1) DEFAULT '0' NOT NULL,
	  FECNNO           NVARCHAR(50) DEFAULT ' ' NOT NULL,
	  FMATERIALATTR    NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FISJUMPLEVEL     CHAR(1) DEFAULT '0' NOT NULL,
	  FOWNERTYPE       NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FOWNERID         BIGINT 		DEFAULT 0 NOT NULL,
	  FISSUEMODE       NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FISKEY           CHAR(1) DEFAULT '0' NOT NULL,
	  FISSTOCKALLOC    CHAR(1) DEFAULT '0' NOT NULL,
	  FOUTORGID        BIGINT 		DEFAULT 0 NOT NULL,
	  FOUTWAREHOUSEID  BIGINT 		DEFAULT 0 NOT NULL,
	  FREPLACEPLANID   BIGINT 		DEFAULT 0 NOT NULL,
	  FISBACKFLUSH     CHAR(1) DEFAULT '0' NOT NULL,
	  FLEADTIME        BIGINT 		DEFAULT 0 NOT NULL,
	  FTIMEUNIT        NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FSUPPLYTYPE      NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FSUPPLYORGID     BIGINT 		DEFAULT 0 NOT NULL,
	  FSUPPLYMODE      NVARCHAR(30) DEFAULT ' ' NOT NULL,
	  FWAREHOUSEID     BIGINT 		DEFAULT 0 NOT NULL,
	  FLOCATIONID      BIGINT 		DEFAULT 0 NOT NULL,
	  FISREPLACE       CHAR(1) DEFAULT '0' NOT NULL,
	  FOPERATIONNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL,
	  FPROCESSSEQ      NVARCHAR(50) DEFAULT ' ' NOT NULL,
	  FECNVERION       NVARCHAR(50) DEFAULT ' ' NOT NULL,
	  FECNVALIDDATE    datetime,
	  FENTRYECN        BIGINT 		DEFAULT 0 NOT NULL	  
   );
   EXEC P_ALTERPK 'PK_PDM_MFTBOMENTRY', 'T_PDM_MFTBOMENTRY', 'FENTRYID', '1';  

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMENTRY_L') 
CREATE TABLE T_PDM_MFTBOMENTRY_L
(
  FPKID     NVARCHAR(18) DEFAULT ' ' NOT NULL,
  FENTRYID  BIGINT 		DEFAULT 0 NOT NULL,
  FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
  FREMARK   NVARCHAR(255) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMENTRY_L', 'T_PDM_MFTBOMENTRY_L', 'FPKID', '1'; 

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMQTYENTRY') 
CREATE TABLE T_PDM_MFTBOMQTYENTRY
(
  FENTRYID        BIGINT 		DEFAULT 0 NOT NULL,
  FDETAILID       BIGINT 		DEFAULT 0 NOT NULL,
  FSEQ            INT 		DEFAULT 0 NOT NULL,
  FBATCHSTARTQTY  DECIMAL(23,10) DEFAULT 0 NOT NULL,
  FBATCHENDQTY    DECIMAL(23,10) DEFAULT 0 NOT NULL,
  FISSTEPFIX      CHAR(1) 		DEFAULT '0' NOT NULL,
  FQTYNUMERATOR   DECIMAL(23,10) DEFAULT 0 NOT NULL,
  FQTYDENOMINATOR DECIMAL(23,10) DEFAULT 0 NOT NULL,
  FFIXSCRAP       DECIMAL(23,10) DEFAULT 0 NOT NULL,
  FSCRAPRATE     DECIMAL(23,10) DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMQTYENTRY', 'T_PDM_MFTBOMQTYENTRY', 'FDETAILID', '1'; 


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMSETUPENTRY') 
CREATE TABLE T_PDM_MFTBOMSETUPENTRY
(
  FENTRYID  BIGINT 		DEFAULT 0 NOT NULL,
  FDETAILID BIGINT 		DEFAULT 0 NOT NULL,
  FSEQ      INT 		DEFAULT 0 NOT NULL,
  FQTY      DECIMAL(23,10) 		DEFAULT 0 NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMSETUPENTRY', 'T_PDM_MFTBOMSETUPENTRY', 'FDETAILID', '1'; 

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PDM_MFTBOMSETUPENTRY_L') 
CREATE TABLE T_PDM_MFTBOMSETUPENTRY_L
(
  FPKID     NVARCHAR(18) DEFAULT ' ' NOT NULL,
  FDETAILID  BIGINT 		DEFAULT 0 NOT NULL,
  FLOCALEID NVARCHAR(10) DEFAULT ' ' NOT NULL,
  FSETUPLOCATION NVARCHAR(50) DEFAULT ' ' NOT NULL,
  FREMARK        NVARCHAR(100) DEFAULT ' ' NOT NULL
);
EXEC P_ALTERPK 'PK_PDM_MFTBOMSETUPENTRY_L', 'T_PDM_MFTBOMSETUPENTRY_L', 'FPKID', '1'; 

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


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