CREATE TABLE [dbo].[Erp_Users_Run] (
	[Pc_Name] [nvarchar] (200) NULL ,
	[User_Id] [nvarchar] (20) NULL ,
	[User_Name] [nvarchar] (20) NULL ,
	[Logon_Time] [datetime] NULL ,
	[Kill_It] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[FieldUseInformation] (
	[Key_No] [int] IDENTITY (1, 1) NOT NULL ,
	[Field_Key] [nvarchar] (20) NOT NULL ,
	[Table_Key] [nvarchar] (20) NOT NULL ,
	[Table_Name] [nvarchar] (20) NOT NULL ,
	[Field_Name] [nvarchar] (20) NOT NULL ,
	[Table_Descption] [nvarchar] (20) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Mmst1041] (
	[Rec_1041] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1040] [int] NULL ,
	[Rec_611] [int] NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[cust_order] [nvarchar] (20) NULL ,
	[Cust_Mtr] [nvarchar] (80) NULL ,
	[Cust_Mtr_Name] [nvarchar] (100) NULL ,
	[Cust_Color] [nvarchar] (80) NULL ,
	[Mtr_Amt] [decimal](18, 8) NULL ,
	[Mtr_Prs] [decimal](18, 8) NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Mmst1042] (
	[Rec_1042] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1040] [int] NULL ,
	[SC_No] [nvarchar] (20) NULL ,
	[Deliv_Cust] [nvarchar] (10) NULL ,
	[Pay_Cust] [nvarchar] (10) NULL ,
	[From_Port] [nvarchar] (30) NULL ,
	[To_Port] [nvarchar] (30) NULL ,
	[Deliv_Date] [datetime] NULL ,
	[Cnt_Amt] [int] NULL ,
	[Cnt_Low] [int] NULL ,
	[Cnt_High] [int] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Remark] [ntext] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[Mmst4012] (
	[Rec_4012] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_4011] [int] NOT NULL ,
	[Rec_401] [int] NOT NULL ,
	[Rec_3032] [int] NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Mtr_Amt_Supl] [decimal](18, 6) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 6) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Mmst4062] (
	[Rec_4062] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_4061] [int] NOT NULL ,
	[Rec_406] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Mtr_Amt_InBar] [decimal](18, 6) NOT NULL ,
	[Mtr_Amt_Real] [decimal](18, 6) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[No_Std] (
	[Menu_Id] [nvarchar] (15) NULL ,
	[Item_Using] [bit] NULL ,
	[FWord] [nvarchar] (10) NULL ,
	[Len_A] [int] NULL ,
	[Len_B] [int] NULL ,
	[Bit_1] [bit] NULL ,
	[Bit_2] [bit] NULL ,
	[Bit_3] [bit] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Oper_History] (
	[Rec_NO] [int] IDENTITY (1, 1) NOT NULL ,
	[Oper] [nvarchar] (20) NULL ,
	[User_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Table_Name] [nvarchar] (100) NULL ,
	[Field_Name] [nvarchar] (20) NULL ,
	[Old_Value] [nvarchar] (50) NULL ,
	[New_Value] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Rec_NO] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[Flag] [bit] NOT NULL ,
	[user_id] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Rpt] (
	[Rec_NO] [int] IDENTITY (1, 1) NOT NULL ,
	[Rpt_Name] [nvarchar] (20) NULL ,
	[Rpt_Dir] [nvarchar] (20) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Rpt_Data] [image] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[Upd_Item] (
	[Loc_Id] [nvarchar] (1) NULL ,
	[Upd_Item] [nvarchar] (12) NULL ,
	[Upd_Value] [decimal](18, 4) NULL ,
	[S_Date] [datetime] NULL ,
	[E_Date] [datetime] NULL ,
	[OUpd_Value] [decimal](18, 4) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Upd_Item_No] (
	[Item_No1] [nvarchar] (12) NULL ,
	[Item_No2] [nvarchar] (12) NULL ,
	[Loc_Id] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[User_Field] (
	[Form_Id] [nvarchar] (50) NULL ,
	[Ser_No] [int] NULL ,
	[Inner_FieldName] [nvarchar] (50) NULL ,
	[Inner_ColName] [nvarchar] (50) NULL ,
	[Outer_ColName] [nvarchar] (50) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Data_Type] [nvarchar] (10) NULL ,
	[Fill_From_History] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[User_History] (
	[Rec_NO] [int] IDENTITY (1, 1) NOT NULL ,
	[User_Name] [nvarchar] (50) NULL ,
	[Info_Type] [nvarchar] (50) NULL ,
	[Information] [nvarchar] (100) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[System_ID] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[User_oper_history] (
	[Rec_NO] [int] IDENTITY (1, 1) NOT NULL ,
	[system_id] [int] NULL ,
	[Prog_ID] [nvarchar] (20) NULL ,
	[Oper] [nvarchar] (100) NULL ,
	[User_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Table_Name] [nvarchar] (100) NULL ,
	[Field_Name] [nvarchar] (20) NULL ,
	[Old_Value] [nvarchar] (50) NULL ,
	[New_Value] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst000] (
	[Loc_id] [nvarchar] (1) NULL ,
	[loc_name] [nvarchar] (20) NULL ,
	[cmp_cname] [nvarchar] (50) NULL ,
	[cmp_ename] [nvarchar] (80) NULL ,
	[cmp_addr] [nvarchar] (200) NULL ,
	[cmp_eaddr] [nvarchar] (200) NULL ,
	[resp_name] [nvarchar] (20) NULL ,
	[post_code] [nvarchar] (6) NULL ,
	[cmp_tel] [nvarchar] (30) NULL ,
	[cmp_fax] [nvarchar] (30) NULL ,
	[cmp_email] [nvarchar] (40) NULL ,
	[cmp_http] [nvarchar] (40) NULL ,
	[cmp_sign] [ntext] NULL ,
	[cmp_logo] [nvarchar] (200) NULL ,
	[Rpt_Dir] [nvarchar] (20) NULL ,
	[Pist_Out] [bit] NULL ,
	[Last_Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst001] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[Level_No] [nvarchar] (29) NULL ,
	[Org_No] [nvarchar] (6) NOT NULL ,
	[Org_Name] [nvarchar] (50) NULL ,
	[Org_Rights] [ntext] NULL ,
	[Resp_Name] [nvarchar] (20) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[org_amt] [int] NULL ,
	[code_flag] [nvarchar] (20) NULL ,
	[Card_No_Pre] [nvarchar] (10) NULL ,
	[Ser_Len] [nvarchar] (10) NULL ,
	[Bar_No] [nvarchar] (20) NULL ,
	[loc_id2] [nvarchar] (4) NULL ,
	[disp_no] [int] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst100] (
	[Loc_Id] [nvarchar] (4) NOT NULL ,
	[Loc_Name] [nvarchar] (20) NULL ,
	[Cmp_Cname] [nvarchar] (50) NULL ,
	[Cmp_Ename] [nvarchar] (80) NULL ,
	[Cmp_Addr] [nvarchar] (200) NULL ,
	[Cmp_Eaddr] [nvarchar] (200) NULL ,
	[Resp_Name] [nvarchar] (12) NULL ,
	[Post_Code] [nvarchar] (6) NULL ,
	[Cmp_Tel] [nvarchar] (30) NULL ,
	[Cmp_Fax] [nvarchar] (30) NULL ,
	[Cmp_Email] [nvarchar] (40) NULL ,
	[Cmp_Http] [nvarchar] (40) NULL ,
	[Cmp_Sign] [ntext] NULL ,
	[Cmp_Logo] [nvarchar] (200) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst102] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_102] [int] IDENTITY (1, 1) NOT NULL ,
	[Quot_No] [nvarchar] (20) NOT NULL ,
	[Quot_Date] [smalldatetime] NOT NULL ,
	[Start_Date] [smalldatetime] NOT NULL ,
	[Quot_Type] [nvarchar] (20) NULL ,
	[Cust_No] [nvarchar] (20) NOT NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Money_No] [nvarchar] (10) NOT NULL ,
	[tax_Ratio] [decimal](18, 4) NULL ,
	[Deliv_Mode] [nvarchar] (100) NULL ,
	[Remark] [ntext] NULL ,
	[Quot_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1021] (
	[Rec_1021] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_102] [int] NOT NULL ,
	[Rec_611] [int] NULL ,
	[Mtr_Amt_Cust] [decimal](18, 8) NOT NULL ,
	[Mtr_Prs_Cust] [decimal](18, 8) NOT NULL ,
	[Unit_Id_Cust] [nvarchar] (4) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Ass_Rate] [decimal](18, 6) NULL ,
	[Photo] [ntext] NULL ,
	[Cust_Mtr_No] [nvarchar] (80) NULL ,
	[Cust_Mtr_Name] [nvarchar] (100) NULL ,
	[Cust_Color] [nvarchar] (80) NULL ,
	[Mtr_Note] [nvarchar] (200) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1022] (
	[Rec_1022] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1021] [int] NOT NULL ,
	[Rec_102] [int] NOT NULL ,
	[Mtr_Amt_Cust] [decimal](18, 6) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 6) NULL ,
	[Mtr_Prs_Cust] [decimal](18, 6) NOT NULL ,
	[Is_Main] [bit] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103] (
	[Rec_103] [int] IDENTITY (1, 1) NOT NULL ,
	[Loc_Id] [nvarchar] (4) NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Order_Date] [smalldatetime] NOT NULL ,
	[Order_Type] [nvarchar] (20) NULL ,
	[Cust_No] [nvarchar] (20) NOT NULL ,
	[Cust_Order] [nvarchar] (20) NULL ,
	[Same_Cust_Order] [bit] NULL ,
	[Same_Cust] [bit] NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[tax_Ratio] [decimal](18, 4) NULL ,
	[Deliv_Mode] [nvarchar] (100) NULL ,
	[Deliv_Cust_No] [nvarchar] (50) NULL ,
	[Deliv_Cust_Name] [nvarchar] (100) NULL ,
	[Deliv_Addr] [nvarchar] (100) NULL ,
	[Remark] [ntext] NULL ,
	[Sale_Org_No] [nvarchar] (6) NULL ,
	[Sale_Man] [nvarchar] (20) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Deliv_Date_Min] [smalldatetime] NULL ,
	[Deliv_Date_Max] [smalldatetime] NULL ,
	[deliv_date] [smalldatetime] NULL ,
	[Close_Man] [nvarchar] (10) NULL ,
	[Close_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1031] (
	[Rec_1031] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_103] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt] [decimal](18, 8) NOT NULL ,
	[Manu_Amt] [decimal](18, 8) NULL ,
	[Mtr_Prs] [decimal](18, 8) NULL ,
	[Photo] [ntext] NULL ,
	[Cust_Order] [nvarchar] (30) NULL ,
	[Cust_Mtr_No] [nvarchar] (80) NULL ,
	[Cust_Mtr_Name] [nvarchar] (100) NULL ,
	[Cust_Color] [nvarchar] (80) NULL ,
	[Deliv_Date] [smalldatetime] NULL ,
	[Remark] [ntext] NULL ,
	[Is_Material] [bit] NULL ,
	[Ass_Rate] [decimal](18, 8) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[User_Field5] [nvarchar] (100) NULL ,
	[User_Field6] [nvarchar] (100) NULL ,
	[User_Field7] [nvarchar] (100) NULL ,
	[User_Field8] [nvarchar] (100) NULL ,
	[User_Field9] [nvarchar] (100) NULL ,
	[User_Field10] [nvarchar] (100) NULL ,
	[User_Field11] [nvarchar] (100) NULL ,
	[BOM_upd_Name] [nvarchar] (10) NULL ,
	[BOM_upd_date] [smalldatetime] NULL ,
	[bom_ver] [nvarchar] (20) NULL ,
	[Is_Auto_BOM] [bit] NOT NULL ,
	[make_org_no] [nvarchar] (6) NULL ,
	[bom_start_date] [smalldatetime] NULL ,
	[bom_Error] [ntext] NULL ,
	[bom_status] [nvarchar] (1) NULL ,
	[Mtr_Source] [nvarchar] (1) NOT NULL ,
	[cur_po_name] [nvarchar] (50) NULL ,
	[Forbid_Refresh_BOM] [bit] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1032] (
	[Rec_1032] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_103] [int] NOT NULL ,
	[Rec_1031] [int] NULL ,
	[Ser_No] [int] NOT NULL ,
	[Item_Big_Type] [nvarchar] (50) NULL ,
	[Item_Small_Type] [nvarchar] (50) NOT NULL ,
	[Item_Desc] [nvarchar] (500) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1034] (
	[Rec_1034] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1031] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Forbid_Refresh_BOM] [bit] NULL ,
	[Reason] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103A] (
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103M] (
	[Rec_103M] [int] IDENTITY (1, 1) NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Rec_611_P] [int] NULL ,
	[Rec_611] [int] NOT NULL ,
	[Rec_611_Parent] [int] NOT NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Total_Amt] [decimal](18, 9) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Grade] [int] NOT NULL ,
	[Level_No] [nvarchar] (420) NOT NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[BOM_Rate] [decimal](18, 8) NULL ,
	[BOM] [bit] NULL ,
	[Color_Rec_501] [int] NULL ,
	[is_last] [bit] NULL ,
	[ver] [nvarchar] (20) NULL ,
	[start_date] [smalldatetime] NULL ,
	[feature_type] [nvarchar] (1) NOT NULL ,
	[feature_group] [nvarchar] (50) NULL ,
	[feature_Cond] [nvarchar] (200) NULL ,
	[rec_1031] [int] NOT NULL ,
	[mat_used] [bit] NULL ,
	[Set_bom_ver] [nvarchar] (20) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[P_Manu_Dim] [nvarchar] (100) NULL ,
	[IS_Max_Parent] [bit] NULL ,
	[next_po_name] [nvarchar] (50) NULL ,
	[cur_po_name] [nvarchar] (50) NULL ,
	[rec_611_BOM] [int] NULL ,
	[Is_Std_Bom] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103MP] (
	[Rec_103MP] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_103M] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Rec_611_P] [int] NULL ,
	[Rec_611_Parent] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Part_No] [nvarchar] (10) NULL ,
	[Part_Name] [nvarchar] (30) NOT NULL ,
	[Part_Dim] [nvarchar] (50) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Cut_Amt] [decimal](18, 4) NULL ,
	[Part_Amt] [decimal](18, 6) NULL ,
	[Loss_Amt] [decimal](18, 6) NULL ,
	[Part_Loss_Rate] [decimal](18, 6) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 6) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[BOM_Rate] [decimal](18, 8) NULL ,
	[Rec_1031] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103M_Feature] (
	[Rec_103M_Feature] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1031] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[rec_611_new] [int] NULL ,
	[Feature_Group] [nvarchar] (50) NOT NULL ,
	[Feature_Type] [nvarchar] (1) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[remark] [nvarchar] (200) NULL ,
	[bom_ver] [nvarchar] (20) NULL ,
	[Bom_Ver_New] [nvarchar] (20) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Source_New] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst103M_P_History] (
	[Rec_103M_P] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_1031] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[rec_611] [int] NOT NULL ,
	[Reason] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst104] (
	[Rec_104] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Multi_Order] [bit] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Remark] [ntext] NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst1040] (
	[Rec_1040] [int] IDENTITY (1, 1) NOT NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[Pack_No] [nvarchar] (30) NULL ,
	[Cust_pack] [nvarchar] (30) NULL ,
	[Cnt_Low] [int] NULL ,
	[Cnt_High] [int] NULL ,
	[Cnt_Amt] [int] NULL ,
	[Mtr_Amt] [int] NULL ,
	[Mtr_Amt_Unit] [nvarchar] (5) NULL ,
	[Cnt_Dim] [nvarchar] (30) NULL ,
	[Cnt_Meas] [decimal](18, 8) NULL ,
	[Cnt_Meas_Unit] [nvarchar] (5) NULL ,
	[Pack_Type] [nvarchar] (30) NULL ,
	[N_Wei] [decimal](18, 8) NULL ,
	[G_Wei] [decimal](18, 8) NULL ,
	[Left_Marco] [ntext] NULL ,
	[Mid_Marco] [ntext] NULL ,
	[Top_Marco] [ntext] NULL ,
	[Left_Num] [int] NULL ,
	[Mid_Num] [int] NULL ,
	[Top_Num] [int] NULL ,
	[Tail_Flag] [nvarchar] (1) NULL ,
	[Prod_Desc] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Remark] [nvarchar] (100) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst201] (
	[Ser_No] [int] NULL ,
	[Title_No] [nvarchar] (20) NOT NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Cal_No] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst202] (
	[Rec_202] [int] IDENTITY (1, 1) NOT NULL ,
	[Ser_no] [int] NOT NULL ,
	[Cal_no] [int] NULL ,
	[Is_Show] [bit] NOT NULL ,
	[Is_End] [bit] NOT NULL ,
	[Is_Numeric] [bit] NOT NULL ,
	[Item_Name] [nvarchar] (50) NOT NULL ,
	[Item_value] [nvarchar] (50) NULL ,
	[Scale_Value] [int] NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (12) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2021] (
	[Rec_2021] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_202] [int] NOT NULL ,
	[Press_Name] [nvarchar] (50) NOT NULL ,
	[Press_value] [nvarchar] (500) NULL ,
	[Is_Default] [bit] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst204] (
	[Rec_204] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [datetime] NOT NULL ,
	[Inv_Type] [nvarchar] (1) NOT NULL ,
	[Cost_Type] [nvarchar] (50) NULL ,
	[Mtr_no] [nvarchar] (50) NULL ,
	[Mtr_Name] [nvarchar] (80) NULL ,
	[Mtr_Dim] [nvarchar] (130) NULL ,
	[Color_Name] [nvarchar] (50) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Photo] [ntext] NULL ,
	[Cost_Value] [decimal](18, 8) NULL ,
	[Cust_NO] [nvarchar] (20) NULL ,
	[Cust_CName] [nvarchar] (100) NULL ,
	[Cust_Attn_Man] [nvarchar] (100) NULL ,
	[Cust_Mtr_No] [nvarchar] (80) NULL ,
	[Cust_Order] [nvarchar] (30) NULL ,
	[Quot_NO] [nvarchar] (20) NULL ,
	[Sample_No] [nvarchar] (30) NULL ,
	[Order_No] [nvarchar] (30) NULL ,
	[Quot_Money_Name] [nvarchar] (20) NULL ,
	[Quot_Amt] [decimal](18, 8) NULL ,
	[Quot_Ratio] [decimal](18, 8) NULL ,
	[Quot_Value] [decimal](18, 8) NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Proc_Man] [nvarchar] (10) NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (12) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Need_ReCal] [bit] NULL ,
	[Changed_Date] [smalldatetime] NULL ,
	[Changed_Name] [nvarchar] (10) NULL ,
	[Changed_Reason] [nvarchar] (30) NULL ,
	[Cnt_dim] [nvarchar] (100) NULL ,
	[Cnt_Meas] [decimal](18, 8) NULL ,
	[Cnt_Meas_Unit] [nvarchar] (10) NULL ,
	[Mtr_Amt_Per_Cnt] [decimal](18, 8) NULL ,
	[Mtr_Amt_Unit] [nvarchar] (10) NULL ,
	[Cnt_Net_Weight] [decimal](18, 8) NULL ,
	[Cnt_Gross_Weight] [decimal](18, 8) NULL ,
	[Quot_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2041] (
	[Rec_2041] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[Item_Name] [nvarchar] (50) NOT NULL ,
	[Item_Value] [nvarchar] (50) NULL ,
	[Item_Cal_Value] [nvarchar] (50) NULL ,
	[Ser_No] [int] NULL ,
	[Cal_No] [int] NULL ,
	[Is_Show] [bit] NOT NULL ,
	[Is_End] [bit] NOT NULL ,
	[Is_Edited] [bit] NOT NULL ,
	[Is_Numeric] [bit] NOT NULL ,
	[Scale_value] [int] NULL ,
	[Press_Name] [nvarchar] (50) NULL ,
	[Press_value] [nvarchar] (500) NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2042] (
	[Rec_2042] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[Parent_Rec_2042] [int] NULL ,
	[Level_No] [nvarchar] (21) NULL ,
	[Grade] [int] NULL ,
	[Ser_No] [int] NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Rec_611_0] [int] NOT NULL ,
	[Is_Rec_611] [bit] NOT NULL ,
	[MTR_NO] [nvarchar] (50) NULL ,
	[MTR_NAME] [nvarchar] (80) NULL ,
	[MTR_DIM] [nvarchar] (130) NULL ,
	[COLOR_NAME] [nvarchar] (50) NULL ,
	[UNIT_NAME] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Cal_Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Rate] [decimal](18, 6) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Prod_Mtr_Amt] [decimal](18, 9) NULL ,
	[Mtr_Prs] [decimal](18, 8) NULL ,
	[Mtr_Prs_Std] [decimal](18, 8) NULL ,
	[Mtr_Prs_New] [decimal](18, 8) NULL ,
	[Mtr_Prs_Avg] [decimal](18, 8) NULL ,
	[Quot_Unit_Name] [nvarchar] (10) NULL ,
	[Quot_Mtr_Prs] [decimal](18, 8) NULL ,
	[Quot_Unit_Press_Name] [nvarchar] (50) NULL ,
	[Quot_Mtr_Amt_Ratio] [decimal](18, 8) NULL ,
	[Is_Edit_Amt] [bit] NULL ,
	[Cal_No] [int] NULL ,
	[type] [nvarchar] (1) NOT NULL ,
	[Prop_Name] [nvarchar] (50) NULL ,
	[Prop_Value] [nvarchar] (100) NULL ,
	[Press_value] [nvarchar] (200) NULL ,
	[Mtr_Type_Name] [nvarchar] (80) NULL ,
	[Mtr_Field_Name] [nvarchar] (30) NULL ,
	[Value_List] [nvarchar] (100) NULL ,
	[Forbid_Edit] [bit] NULL ,
	[Must_Input_Loss] [bit] NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[Must_Input_Manu_Dim] [bit] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[Rec_50B1_Copy] [int] NULL ,
	[Rec_2042_Copy] [int] NULL ,
	[remark] [nvarchar] (200) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[next_po_name] [nvarchar] (50) NULL ,
	[cur_po_name] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2043] (
	[Rec_2043] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_2042] [int] NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[Part_No] [nvarchar] (8) NULL ,
	[Part_Name] [nvarchar] (30) NULL ,
	[Part_Dim] [nvarchar] (100) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Part_Amt] [decimal](18, 8) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Loss_amt] [decimal](18, 8) NULL ,
	[Part_Loss_Rate] [decimal](18, 8) NULL ,
	[Cut_Amt] [decimal](18, 8) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 8) NULL ,
	[Cal_mtr_amt] [decimal](18, 8) NULL ,
	[Part_Picture] [nvarchar] (200) NULL ,
	[Remark] [nvarchar] (50) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2044] (
	[Rec_2044] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[po_type_name] [nvarchar] (20) NULL ,
	[Ser_No] [int] NULL ,
	[Org_Ser] [nvarchar] (5) NULL ,
	[Po_No] [nvarchar] (14) NULL ,
	[po_name] [nvarchar] (50) NULL ,
	[Part_name] [nvarchar] (200) NULL ,
	[Last_PO] [bit] NULL ,
	[Imp_Po] [bit] NULL ,
	[Imp_Po_Name] [nvarchar] (50) NULL ,
	[Po_Time] [decimal](18, 8) NULL ,
	[Po_Amt] [decimal](18, 8) NULL ,
	[Po_Prs] [decimal](18, 8) NULL ,
	[PO_Out_Prs] [decimal](18, 8) NULL ,
	[PO_Pcs_Prs] [decimal](18, 8) NULL ,
	[Po_Note] [ntext] NULL ,
	[Remark] [ntext] NULL ,
	[Po_Photo] [nvarchar] (200) NULL ,
	[Next_Rec] [int] NULL ,
	[Lock] [nvarchar] (3) NULL ,
	[Upd_name] [nvarchar] (10) NOT NULL ,
	[Upd_date] [datetime] NOT NULL ,
	[Level_No] [nvarchar] (200) NULL ,
	[po_pcs] [decimal](18, 6) NULL ,
	[PO_PCS_Unit] [nvarchar] (20) NULL ,
	[No_Color] [bit] NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[User_Field0] [nvarchar] (50) NULL ,
	[User_Field1] [nvarchar] (50) NULL ,
	[User_Field2] [nvarchar] (50) NULL ,
	[User_Field3] [nvarchar] (50) NULL ,
	[User_Field4] [nvarchar] (50) NULL ,
	[User_Field5] [nvarchar] (50) NULL ,
	[User_Field6] [nvarchar] (50) NULL ,
	[User_Field7] [nvarchar] (50) NULL ,
	[User_Field8] [nvarchar] (50) NULL ,
	[User_Field9] [nvarchar] (50) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2045] (
	[Rec_2045] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[Ser_No] [int] NOT NULL ,
	[Item_Big_Type] [nvarchar] (50) NULL ,
	[Item_Small_Type] [nvarchar] (50) NOT NULL ,
	[Item_Desc] [nvarchar] (500) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst2046] (
	[Rec_2046] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_204] [int] NOT NULL ,
	[Container_Type] [nvarchar] (20) NOT NULL ,
	[Cnt_Amt_Per_Container] [decimal](18, 8) NULL ,
	[Container_Amt] [decimal](18, 8) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Cnt_Amt_Per_Container_Cal] [decimal](18, 8) NULL ,
	[Container_CBM] [decimal](18, 8) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst301] (
	[Rec_301] [int] IDENTITY (1, 1) NOT NULL ,
	[supl_No] [nvarchar] (10) NOT NULL ,
	[Cant_No] [nvarchar] (20) NULL ,
	[Area_No] [nvarchar] (20) NULL ,
	[supl_Cname] [nvarchar] (100) NULL ,
	[supl_Ename] [nvarchar] (100) NULL ,
	[supl_Name] [nvarchar] (20) NOT NULL ,
	[Supl_Tel] [nvarchar] (30) NULL ,
	[Supl_Fax] [nvarchar] (30) NULL ,
	[Attn] [nvarchar] (300) NULL ,
	[Attn_man] [nvarchar] (30) NULL ,
	[Supl_Caddr] [nvarchar] (100) NULL ,
	[Supl_Eaddr] [nvarchar] (100) NULL ,
	[Pay_Money_No] [nvarchar] (10) NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Close_Day] [nvarchar] (20) NULL ,
	[Meeting] [nvarchar] (2) NULL ,
	[Email_Addr] [nvarchar] (50) NULL ,
	[Http_Addr] [nvarchar] (50) NULL ,
	[Resp_Name] [nvarchar] (30) NULL ,
	[Supl_Prop] [nvarchar] (20) NULL ,
	[Tax_Ratio] [decimal](18, 4) NULL ,
	[Remark] [ntext] NULL ,
	[Build_Date] [smalldatetime] NULL ,
	[Supl_Bank] [nvarchar] (200) NULL ,
	[Invoice_Addr] [nvarchar] (200) NULL ,
	[First_Sale_Date] [smalldatetime] NULL ,
	[Last_Sale_Date] [smalldatetime] NULL ,
	[Last_Pay_Date] [smalldatetime] NULL ,
	[Check_Title] [nvarchar] (200) NULL ,
	[Quot_money_no] [nvarchar] (4) NULL ,
	[Purc_TypeNo] [nvarchar] (10) NULL ,
	[loc_id] [nvarchar] (4) NULL ,
	[flag] [nvarchar] (1) NULL ,
	[Sale_scope] [nvarchar] (200) NULL ,
	[Follow_Man] [nvarchar] (10) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3011] (
	[rec_301] [int] NULL ,
	[Mtr_Type] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst302] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_302] [int] IDENTITY (1, 1) NOT NULL ,
	[Req_No] [nvarchar] (20) NOT NULL ,
	[Req_Date] [smalldatetime] NOT NULL ,
	[Req_Type] [nvarchar] (20) NULL ,
	[Remark] [ntext] NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[Req_Man] [nvarchar] (10) NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3021] (
	[Rec_3021] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_302] [int] NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Photo] [ntext] NULL ,
	[Deliv_Date] [smalldatetime] NOT NULL ,
	[Used_To] [nvarchar] (200) NULL ,
	[Req_Man] [nvarchar] (10) NULL ,
	[Supl_No] [nvarchar] (20) NULL ,
	[Mtr_Prs] [decimal](18, 6) NULL ,
	[Mtr_Note] [nvarchar] (200) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Purced_Amt_Row] [decimal](18, 6) NULL ,
	[finish_purc] [bit] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst303] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_303] [int] IDENTITY (1, 1) NOT NULL ,
	[Purc_No] [nvarchar] (20) NOT NULL ,
	[Purc_Date] [smalldatetime] NOT NULL ,
	[Purc_Type] [nvarchar] (20) NULL ,
	[Supl_No] [nvarchar] (20) NOT NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[tax_Ratio] [decimal](18, 4) NULL ,
	[Deliv_Mode] [nvarchar] (100) NULL ,
	[Remark] [ntext] NULL ,
	[Purc_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Close_Man] [nvarchar] (10) NULL ,
	[Close_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3031] (
	[Rec_3031] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_303] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Prs_Supl] [decimal](18, 8) NULL ,
	[Mtr_Pay_Supl] [decimal](18, 2) NULL ,
	[Unit_Id_Supl] [nvarchar] (4) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Ass_Rate] [decimal](18, 6) NULL ,
	[Photo] [ntext] NULL ,
	[Supl_Mtr_No] [nvarchar] (80) NULL ,
	[Supl_Mtr_Name] [nvarchar] (100) NULL ,
	[Supl_Color] [nvarchar] (80) NULL ,
	[Deliv_Date] [smalldatetime] NULL ,
	[Mtr_Note] [nvarchar] (200) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Finish_Pay] [bit] NULL ,
	[Mtr_Amt_InBar_Supl] [decimal](18, 6) NULL ,
	[mtr_amt_inbar_local] [decimal](18, 6) NULL ,
	[Manu_Closed] [bit] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3032] (
	[Rec_3032] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_3031] [int] NOT NULL ,
	[Rec_303] [int] NOT NULL ,
	[From_Type] [nvarchar] (1) NOT NULL ,
	[From_Rec_No] [int] NULL ,
	[From_Inv_No] [nvarchar] (20) NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Mtr_Amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local_S] [decimal](18, 6) NULL ,
	[Mtr_Amt_InBar_Supl] [decimal](18, 6) NOT NULL ,
	[Mtr_Amt_InBar_Local] [decimal](18, 6) NOT NULL ,
	[Deliv_Date_S] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Manu_Closed] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst304] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_304] [int] IDENTITY (1, 1) NOT NULL ,
	[Quot_No] [nvarchar] (20) NOT NULL ,
	[Quot_Date] [smalldatetime] NOT NULL ,
	[Start_Date] [smalldatetime] NOT NULL ,
	[Quot_Type] [nvarchar] (20) NULL ,
	[Supl_No] [nvarchar] (20) NOT NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Money_No] [nvarchar] (10) NOT NULL ,
	[tax_Ratio] [decimal](18, 4) NULL ,
	[Deliv_Mode] [nvarchar] (100) NULL ,
	[Remark] [ntext] NULL ,
	[Quot_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3041] (
	[Rec_3041] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_304] [int] NOT NULL ,
	[Rec_611] [int] NULL ,
	[Mtr_Amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Prs_Supl] [decimal](18, 8) NOT NULL ,
	[Unit_Id_Supl] [nvarchar] (4) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Ass_Rate] [decimal](18, 6) NULL ,
	[Photo] [ntext] NULL ,
	[Supl_Mtr_No] [nvarchar] (80) NULL ,
	[Supl_Mtr_Name] [nvarchar] (100) NULL ,
	[Supl_Color] [nvarchar] (80) NULL ,
	[Mtr_Note] [nvarchar] (200) NULL ,
	[Remark] [ntext] NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst3042] (
	[Rec_3042] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_3041] [int] NOT NULL ,
	[Rec_304] [int] NOT NULL ,
	[Mtr_Amt_Supl] [decimal](18, 6) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 6) NULL ,
	[Mtr_Prs_Supl] [decimal](18, 6) NOT NULL ,
	[Is_Main] [bit] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst30A] (
	[Rec_30A] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (30) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Inv_Type] [nvarchar] (1) NOT NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [datetime] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Remark] [ntext] NULL ,
	[Cal_Date] [smalldatetime] NULL ,
	[Cal_Man] [nvarchar] (10) NULL ,
	[MRP_End_Date] [smalldatetime] NULL ,
	[mrp_mtr_filter] [ntext] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst30A1] (
	[Rec_30A1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Order_Mtr_Amt] [decimal](18, 6) NOT NULL ,
	[Order_Deliv_Date] [smalldatetime] NULL ,
	[Mtr_Deliv_Date] [smalldatetime] NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[rec_30a] [int] NULL ,
	[cust_mtr_no] [nvarchar] (80) NULL ,
	[cust_order] [nvarchar] (30) NULL ,
	[Cur_Po_Name] [nvarchar] (50) NULL ,
	[Mo_No] [nvarchar] (30) NULL ,
	[Rec_1031] [int] NULL ,
	[Rec_5031] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst30A2] (
	[Rec_30A2] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_30A] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Deliv_Date] [smalldatetime] NULL ,
	[Purc_Deliv_Date] [smalldatetime] NULL ,
	[Start_Amt] [decimal](18, 8) NULL ,
	[In_Amt] [decimal](18, 8) NULL ,
	[Out_Amt] [decimal](18, 8) NULL ,
	[Adv_Amt] [decimal](18, 6) NULL ,
	[Purc_Amt] [decimal](18, 6) NULL ,
	[Purced_Amt_Row] [decimal](18, 6) NULL ,
	[Finish_Purc] [bit] NULL ,
	[Is_Edited] [bit] NULL ,
	[form_man] [nvarchar] (10) NULL ,
	[form_date] [smalldatetime] NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Status] [nvarchar] (1) NULL ,
	[allow_delete] [bit] NULL ,
	[Supl_No] [nvarchar] (10) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst400] (
	[Form_Type] [nvarchar] (1) NOT NULL ,
	[Form_Type_Name] [nvarchar] (20) NOT NULL ,
	[Source_Table_Name] [nvarchar] (20) NULL ,
	[Inv_Type] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Inv_From_Obj] [nvarchar] (1) NULL ,
	[Must_Input_Proc_Man] [bit] NOT NULL ,
	[Must_Input_Bar_Man] [bit] NOT NULL ,
	[Must_Input_Purc_Man] [bit] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst401] (
	[Rec_401] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Supl_no] [nvarchar] (10) NOT NULL ,
	[Inv_type] [nvarchar] (1) NOT NULL ,
	[Supl_Inv] [nvarchar] (30) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Purc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4011] (
	[Rec_4011] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_401] [int] NOT NULL ,
	[Purc_No] [nvarchar] (20) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Unit_id_Supl] [nvarchar] (4) NOT NULL ,
	[Bar_no] [nvarchar] (20) NOT NULL ,
	[Payed] [bit] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Mtr_Prs_Supl] [decimal](18, 4) NULL ,
	[Mtr_Prs_Local] [decimal](18, 4) NULL ,
	[Money_Name] [nvarchar] (20) NULL ,
	[rec_3031] [int] NULL ,
	[Mtr_Pay] [decimal](18, 4) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst403] (
	[Rec_403] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[org_no] [nvarchar] (10) NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Mo_No] [nvarchar] (30) NOT NULL ,
	[Inv_type] [nvarchar] (1) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[inv_sub_type] [nvarchar] (1) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4031] (
	[Rec_4031] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_403] [int] NOT NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Mo_No] [nvarchar] (30) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_amt_Sent] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Unit_id_Sent] [nvarchar] (4) NOT NULL ,
	[Bar_no] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Sub_Stock_Mode] [nvarchar] (1) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst405] (
	[Rec_405] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[From_Bar_No] [nvarchar] (20) NULL ,
	[To_Bar_No] [nvarchar] (20) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4051] (
	[Rec_4051] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_405] [int] NOT NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[From_Bar_No] [nvarchar] (20) NOT NULL ,
	[To_Bar_no] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[sub_Stock_mode] [nvarchar] (1) NULL ,
	[unit_id_sent] [nvarchar] (4) NULL ,
	[mtr_amt_sent] [decimal](18, 8) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst406] (
	[Rec_406] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Bar_No] [nvarchar] (20) NULL ,
	[First_Stock] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4061] (
	[Rec_4061] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_406] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_amt_InBar] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Real] [decimal](18, 8) NOT NULL ,
	[Bar_no] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[mtr_prs_local] [decimal](18, 8) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst407] (
	[Rec_407] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[org_no] [nvarchar] (10) NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Mo_No] [nvarchar] (30) NULL ,
	[Inv_type] [nvarchar] (1) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4071] (
	[Rec_4071] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_407] [int] NOT NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Mo_No] [nvarchar] (30) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_amt_Sent] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Unit_id_Sent] [nvarchar] (4) NOT NULL ,
	[Bar_no] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Sub_Stock_Mode] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst409] (
	[Loc_id] [nvarchar] (4) NULL ,
	[Rec_409] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Order_Type] [nvarchar] (20) NULL ,
	[Inv_Type] [nvarchar] (1) NULL ,
	[Cust_No] [nvarchar] (20) NULL ,
	[Pay_Type] [nvarchar] (4) NULL ,
	[Money_No] [nvarchar] (10) NULL ,
	[Deliv_Mode] [nvarchar] (100) NULL ,
	[Same_Cust] [bit] NULL ,
	[Deliv_Cust_No] [nvarchar] (50) NULL ,
	[Deliv_Cust_Name] [nvarchar] (100) NULL ,
	[Deliv_Addr] [nvarchar] (100) NULL ,
	[Tax_Ratio] [decimal](18, 4) NULL ,
	[Remark] [ntext] NULL ,
	[Sale_Org_No] [nvarchar] (6) NULL ,
	[Sale_Man] [nvarchar] (20) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Bar_Man] [nvarchar] (20) NULL ,
	[Proc_Man] [nvarchar] (20) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Ship_Supl_No] [nvarchar] (10) NULL ,
	[Shipment_From] [nvarchar] (50) NULL ,
	[Shipment_To] [nvarchar] (50) NULL ,
	[Voyage_No] [nvarchar] (100) NULL ,
	[ETD] [smalldatetime] NULL ,
	[ETA] [smalldatetime] NULL ,
	[CNTR_Type] [nvarchar] (20) NULL ,
	[CNTR_no] [nvarchar] (20) NULL ,
	[CNTR_InTime] [smalldatetime] NULL ,
	[CNTR_OffTime] [smalldatetime] NULL ,
	[Seal_No] [nvarchar] (20) NULL ,
	[Trans_Supl_NO] [nvarchar] (10) NULL ,
	[Car_No] [nvarchar] (20) NULL ,
	[Driver_Name] [nvarchar] (20) NULL ,
	[Driver_Mobil_Code] [nvarchar] (20) NULL ,
	[SO_No] [nvarchar] (20) NULL ,
	[Invoice_No] [nvarchar] (20) NULL ,
	[Closing_Date] [smalldatetime] NULL ,
	[Duty_Addr] [nvarchar] (50) NULL ,
	[Export_No] [nvarchar] (100) NULL ,
	[Export_ContractNo] [nvarchar] (100) NULL ,
	[Co_Type] [nvarchar] (10) NULL ,
	[Co_No] [nvarchar] (20) NULL ,
	[Co_date] [smalldatetime] NULL ,
	[Total_Num] [nvarchar] (100) NULL ,
	[Total_Cnt_Amt] [decimal](18, 8) NULL ,
	[Total_N_Wei] [decimal](18, 8) NULL ,
	[Total_G_Wei] [decimal](18, 8) NULL ,
	[Total_Meas] [decimal](18, 8) NULL ,
	[Cnt_Unit] [nvarchar] (5) NULL ,
	[cntr_amt] [int] NULL ,
	[Invoice_Remark] [ntext] NULL ,
	[Packing_Remark] [ntext] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4091] (
	[Rec_4091] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_409] [int] NOT NULL ,
	[Ser_NO] [int] NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt_Cust] [decimal](18, 8) NULL ,
	[Mtr_Prs_Cust] [decimal](18, 8) NULL ,
	[Mtr_Pay_Cust] [decimal](18, 2) NULL ,
	[Unit_Id_Cust] [nvarchar] (4) NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NULL ,
	[Mtr_Prs_Local] [decimal](18, 8) NULL ,
	[Cust_Order] [nvarchar] (20) NULL ,
	[Cust_Mtr_No] [nvarchar] (80) NULL ,
	[Cust_Mtr_Name] [nvarchar] (100) NULL ,
	[Cust_Color] [nvarchar] (80) NULL ,
	[Finish_Pay] [bit] NULL ,
	[Remark] [ntext] NULL ,
	[Is_Material] [bit] NULL ,
	[Ass_Rate] [decimal](18, 8) NULL ,
	[Bar_No] [nvarchar] (20) NULL ,
	[Sub_Stock_Mode] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[User_Field5] [nvarchar] (100) NULL ,
	[User_Field6] [nvarchar] (100) NULL ,
	[User_Field7] [nvarchar] (100) NULL ,
	[User_Field8] [nvarchar] (100) NULL ,
	[User_Field9] [nvarchar] (100) NULL ,
	[User_Field10] [nvarchar] (100) NULL ,
	[User_Field11] [nvarchar] (100) NULL ,
	[Cnt_Low] [int] NULL ,
	[Cnt_High] [int] NULL ,
	[Cnt_Amt] [int] NULL ,
	[Mtr_Amt_Unit] [nvarchar] (5) NULL ,
	[G_Weight] [decimal](18, 8) NULL ,
	[N_Weight] [decimal](18, 8) NULL ,
	[Cnt_Meas] [decimal](18, 8) NULL ,
	[Cnt_Dim] [nvarchar] (50) NULL ,
	[Pack_Type] [nvarchar] (30) NULL ,
	[Packing_Desc] [nvarchar] (1000) NULL ,
	[Packing_Detail] [nvarchar] (1000) NULL ,
	[Mtr_desc] [nvarchar] (100) NULL ,
	[Invoice_No] [nvarchar] (20) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40B] (
	[Rec_40B] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40B1] (
	[Rec_40B1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_40B] [int] NOT NULL ,
	[From_Order_no] [nvarchar] (20) NULL ,
	[To_Order_No] [nvarchar] (30) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Bar_No] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40C] (
	[Rec_40C] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Supl_no] [nvarchar] (10) NULL ,
	[Inv_type] [nvarchar] (1) NULL ,
	[Form_type] [nvarchar] (1) NULL ,
	[Supl_Inv] [nvarchar] (30) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Purc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Inv_From_Obj] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40C1] (
	[Rec_40C1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_40C] [int] NOT NULL ,
	[Purc_No] [nvarchar] (20) NULL ,
	[Order_no] [nvarchar] (20) NULL ,
	[Mo_No] [nvarchar] (30) NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Unit_id_Supl] [nvarchar] (4) NOT NULL ,
	[Bar_no] [nvarchar] (20) NOT NULL ,
	[Payed] [bit] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Mtr_Prs_Supl] [decimal](18, 4) NULL ,
	[Mtr_Prs_Local] [decimal](18, 4) NULL ,
	[Money_Name] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40E] (
	[Rec_40E] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Org_no] [nvarchar] (10) NOT NULL ,
	[Mo_no] [nvarchar] (30) NOT NULL ,
	[Order_no] [nvarchar] (20) NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40E1] (
	[Rec_40E1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_40E] [int] NOT NULL ,
	[From_Mo_no] [nvarchar] (30) NOT NULL ,
	[To_Mo_no] [nvarchar] (30) NOT NULL ,
	[From_Order_no] [nvarchar] (20) NOT NULL ,
	[To_Order_No] [nvarchar] (20) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Mtr_Amt_Local] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Sent] [decimal](18, 8) NOT NULL ,
	[unit_id_sent] [nvarchar] (4) NOT NULL ,
	[sub_Stock_mode] [nvarchar] (1) NOT NULL ,
	[Bar_No] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40F] (
	[Rec_40F] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Bar_NO_From] [nvarchar] (20) NOT NULL ,
	[Bar_NO_To] [nvarchar] (20) NOT NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst40F1] (
	[Rec_40F1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_40F] [int] NOT NULL ,
	[Bar_NO_From] [nvarchar] (20) NOT NULL ,
	[Bar_NO_To] [nvarchar] (20) NOT NULL ,
	[Order_no] [nvarchar] (20) NOT NULL ,
	[Rec_611_From] [int] NOT NULL ,
	[Rec_611_To] [int] NOT NULL ,
	[Mtr_Amt_Local_From] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Local_To] [decimal](18, 8) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst481] (
	[Order_No] [nvarchar] (20) NULL ,
	[rec_611] [int] NOT NULL ,
	[remark] [nvarchar] (100) NULL ,
	[bar_no] [nvarchar] (20) NOT NULL ,
	[mtr_amt] [decimal](18, 8) NOT NULL ,
	[mtr_prs] [decimal](18, 8) NULL ,
	[upd_name] [nvarchar] (10) NOT NULL ,
	[upd_date] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst4811] (
	[rec_4811] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Type] [nvarchar] (30) NOT NULL ,
	[Inv_Date] [datetime] NOT NULL ,
	[Org_Name] [nvarchar] (50) NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[Mo_NO] [nvarchar] (30) NULL ,
	[rec_611] [int] NOT NULL ,
	[Bar_No] [nvarchar] (20) NOT NULL ,
	[Mtr_Amt] [decimal](18, 8) NOT NULL ,
	[Mtr_Prs] [decimal](18, 8) NULL ,
	[Remark] [nvarchar] (100) NULL ,
	[Upd_name] [nvarchar] (10) NOT NULL ,
	[Upd_date] [datetime] NOT NULL ,
	[To_Order_No] [nvarchar] (20) NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Bar_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Inv_Sub_Type] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst481_Pre] (
	[Rec_481_Pre] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Order_No] [nvarchar] (40) NULL ,
	[Pre_Date] [smalldatetime] NOT NULL ,
	[In_Amt] [decimal](18, 8) NULL ,
	[Out_Amt] [decimal](18, 8) NULL ,
	[Cur_Amt] [decimal](18, 8) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst500] (
	[Level_No] [nvarchar] (20) NOT NULL ,
	[Part_No] [nvarchar] (10) NULL ,
	[Part_Name] [nvarchar] (20) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Type_Type] [nvarchar] (1) NULL ,
	[Is_Print] [nvarchar] (1) NULL ,
	[ser_No] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501] (
	[Rec_501] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_Date] [smalldatetime] NULL ,
	[Rec_611_0] [int] NOT NULL ,
	[Parent_Rec_501] [int] NULL ,
	[Is_Rec_611] [bit] NOT NULL ,
	[Base_Amt] [decimal](18, 6) NULL ,
	[Start_Date] [smalldatetime] NOT NULL ,
	[end_date] [smalldatetime] NULL ,
	[Ver] [nvarchar] (20) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Remark] [nvarchar] (200) NULL ,
	[Rec_501_Copy] [int] NULL ,
	[From_Sample_Date] [smalldatetime] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[prod_name] [nvarchar] (50) NULL ,
	[bom_Error] [ntext] NULL ,
	[Need_ReCal] [bit] NULL ,
	[Changed_Date] [smalldatetime] NULL ,
	[Changed_Name] [nvarchar] (10) NULL ,
	[Changed_Reason] [nvarchar] (30) NULL ,
	[Ref_Mtr_No] [nvarchar] (50) NULL ,
	[Ref_S_Mtr_No] [nvarchar] (50) NULL ,
	[Ref_BOM_Ver] [nvarchar] (20) NULL ,
	[Ref_Changed] [bit] NULL ,
	[color_same_amt] [bit] NOT NULL ,
	[Cal_Date] [smalldatetime] NULL ,
	[Cal_Man] [nvarchar] (10) NULL ,
	[cur_po_name] [nvarchar] (50) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5012] (
	[Rec_5012] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_501] [int] NOT NULL ,
	[Ser_No] [int] NOT NULL ,
	[Item_Big_Type] [nvarchar] (50) NULL ,
	[Item_Small_Type] [nvarchar] (50) NOT NULL ,
	[Item_Desc] [ntext] NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501M] (
	[Rec_501M] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_501] [int] NOT NULL ,
	[Parent_Rec_501M] [int] NULL ,
	[Color_Rec_501] [int] NULL ,
	[Level_No] [nvarchar] (21) NULL ,
	[Grade] [int] NULL ,
	[Ser_No] [int] NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Rec_611_0] [int] NOT NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Rate] [decimal](18, 6) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Prod_Mtr_Amt] [decimal](18, 9) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Same_Amt] [bit] NULL ,
	[Same_Prod_Color] [bit] NULL ,
	[Is_Edit_Amt] [bit] NULL ,
	[Is_Rec_611] [bit] NOT NULL ,
	[Is_Type_Color] [bit] NOT NULL ,
	[Prod_Mtr_Color] [nvarchar] (1000) NULL ,
	[Rec_501M_Copy] [int] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[Cal_No] [int] NULL ,
	[type] [nvarchar] (1) NOT NULL ,
	[Prop_Name] [nvarchar] (50) NULL ,
	[Prop_Value] [nvarchar] (100) NULL ,
	[Press_value] [nvarchar] (200) NULL ,
	[Mtr_Type_Name] [nvarchar] (80) NULL ,
	[Mtr_Field_Name] [nvarchar] (30) NULL ,
	[Value_List] [nvarchar] (100) NULL ,
	[Rec_50B1_Copy] [int] NULL ,
	[Forbid_Edit] [bit] NULL ,
	[Must_Input_Loss] [bit] NULL ,
	[feature_type] [nvarchar] (1) NOT NULL ,
	[feature_group] [nvarchar] (50) NULL ,
	[feature_Cond] [nvarchar] (200) NULL ,
	[bom_ver] [nvarchar] (20) NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[Must_Input_Manu_Dim] [bit] NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Cal_Mtr_Amt] [decimal](18, 9) NULL ,
	[next_po_name] [nvarchar] (50) NULL ,
	[cur_po_name] [nvarchar] (50) NULL ,
	[is_last] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501MC] (
	[Rec_501MC] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_501] [int] NOT NULL ,
	[Rec_501M] [int] NOT NULL ,
	[Color_Rec_501] [int] NOT NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Loss_Rate] [decimal](18, 6) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Prod_Mtr_Amt] [decimal](18, 9) NULL ,
	[remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501M_Tmp] (
	[Rec_No] [int] NULL ,
	[Rec_611_P] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Rec_611_Parent] [int] NOT NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Total_Amt] [decimal](18, 9) NULL ,
	[Grade] [int] NOT NULL ,
	[Level_No] [nvarchar] (420) NOT NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[is_last] [bit] NULL ,
	[BOM] [bit] NULL ,
	[Color_Rec_501] [int] NULL ,
	[order_no] [nvarchar] (20) NULL ,
	[BOM_Rate] [decimal](18, 8) NULL ,
	[upd_name] [nvarchar] (10) NULL ,
	[upd_date] [smalldatetime] NULL ,
	[ver] [nvarchar] (20) NULL ,
	[start_date] [smalldatetime] NULL ,
	[feature_type] [nvarchar] (1) NOT NULL ,
	[feature_group] [nvarchar] (50) NULL ,
	[feature_Cond] [nvarchar] (200) NULL ,
	[Set_bom_ver] [nvarchar] (20) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501OrgReplace] (
	[Rec_501OrgReplace] [int] IDENTITY (1, 1) NOT NULL ,
	[Po_Name_New] [nvarchar] (50) NOT NULL ,
	[Po_Name_Old] [nvarchar] (50) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501P] (
	[Rec_501P] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_501] [int] NOT NULL ,
	[Rec_501M] [int] NULL ,
	[Part_No] [nvarchar] (10) NULL ,
	[Part_Name] [nvarchar] (30) NOT NULL ,
	[Part_Dim] [nvarchar] (50) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Part_Amt] [decimal](18, 6) NULL ,
	[Part_Loss_Rate] [decimal](18, 6) NULL ,
	[Cut_Amt] [decimal](18, 4) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 6) NULL ,
	[Cal_Mtr_Amt] [decimal](18, 6) NULL ,
	[Loss_Amt] [decimal](18, 6) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Same_Amt] [bit] NULL ,
	[Rec_501P_Copy] [int] NULL ,
	[remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst501PC] (
	[Rec_501PC] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_501] [int] NULL ,
	[Color_Rec_501] [int] NOT NULL ,
	[Rec_501P] [int] NOT NULL ,
	[Rec_501M] [int] NOT NULL ,
	[Part_Amt] [decimal](18, 6) NULL ,
	[Part_Loss_Rate] [decimal](18, 6) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst502] (
	[Rec_502] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[From_Inv] [nvarchar] (20) NULL ,
	[From_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Sale_Man] [nvarchar] (10) NULL ,
	[Proj_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5021] (
	[Rec_5021] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_502] [int] NOT NULL ,
	[Order_No] [nvarchar] (20) NULL ,
	[Rec_611_P] [int] NULL ,
	[Rec_611_old] [int] NULL ,
	[Rec_611_New] [int] NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt_PCS_Old] [decimal](18, 6) NULL ,
	[Loss_Amt_PCS_Old] [decimal](18, 6) NULL ,
	[Mtr_Amt_Pcs_New] [decimal](18, 6) NULL ,
	[Loss_Amt_PCS_New] [decimal](18, 6) NULL ,
	[update_BOM] [bit] NOT NULL ,
	[Update_Type] [nvarchar] (1) NOT NULL ,
	[update_reason] [nvarchar] (50) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst503] (
	[Rec_503] [int] IDENTITY (1, 1) NOT NULL ,
	[Mo_No] [nvarchar] (30) NOT NULL ,
	[Inv_Type] [nvarchar] (1) NOT NULL ,
	[order_No] [nvarchar] (30) NULL ,
	[Mo_Date] [smalldatetime] NOT NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[Order_Deliv_Date] [smalldatetime] NULL ,
	[Deliv_Date] [smalldatetime] NOT NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [datetime] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Remark] [ntext] NULL ,
	[IS_Sub_Mo] [bit] NULL ,
	[Close_Man] [nvarchar] (10) NULL ,
	[Close_Date] [smalldatetime] NULL ,
	[Order_Mat_Changed] [bit] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5031] (
	[Rec_5031] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_503] [int] NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Order_No] [nvarchar] (30) NOT NULL ,
	[Cust_Order] [nvarchar] (30) NULL ,
	[Cust_Mtr_No] [nvarchar] (80) NULL ,
	[Order_Deliv_Date] [smalldatetime] NULL ,
	[Deliv_Date] [smalldatetime] NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[Mtr_Amt] [decimal](18, 8) NOT NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[User_Field5] [nvarchar] (100) NULL ,
	[User_Field6] [nvarchar] (100) NULL ,
	[User_Field7] [nvarchar] (100) NULL ,
	[User_Field8] [nvarchar] (100) NULL ,
	[User_Field9] [nvarchar] (100) NULL ,
	[User_Field10] [nvarchar] (100) NULL ,
	[User_Field11] [nvarchar] (100) NULL ,
	[Parent_Mo_No] [nvarchar] (30) NULL ,
	[Exist_BOM] [bit] NULL ,
	[From_Type] [nvarchar] (1) NULL ,
	[rec_1031] [int] NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[cur_po_name] [nvarchar] (50) NULL ,
	[Only_Po] [bit] NULL ,
	[bom_ver] [nvarchar] (20) NULL ,
	[Grade] [int] NULL ,
	[Check_Mat_date] [smalldatetime] NULL ,
	[Check_Mat_Name] [nvarchar] (12) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5032] (
	[Rec_5032] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_503] [int] NOT NULL ,
	[Rec_5031] [int] NULL ,
	[Ser_No] [int] NOT NULL ,
	[Item_Big_Type] [nvarchar] (50) NULL ,
	[Item_Small_Type] [nvarchar] (50) NOT NULL ,
	[Item_Desc] [nvarchar] (500) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5033] (
	[Rec_5033] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_503] [int] NOT NULL ,
	[Rec_611_old] [int] NULL ,
	[Rec_611_New] [int] NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[Mtr_Source_old] [nvarchar] (1) NULL ,
	[Mtr_Source_new] [nvarchar] (1) NULL ,
	[Mtr_Amt_Old] [decimal](18, 6) NULL ,
	[Mtr_Amt_New] [decimal](18, 6) NULL ,
	[update_reason] [nvarchar] (50) NULL ,
	[Update_Type] [nvarchar] (1) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[IS_Auto_Prod_Amt] [bit] NOT NULL ,
	[IS_Full_Amt] [bit] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5034] (
	[Rec_5034] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_503] [int] NOT NULL ,
	[Rec_5033] [nvarchar] (20) NOT NULL ,
	[Rec_5031] [int] NOT NULL ,
	[IS_Full_Amt] [bit] NOT NULL ,
	[Update_Type] [nvarchar] (1) NOT NULL ,
	[Rec_611_Old] [int] NULL ,
	[Rec_611_New] [int] NULL ,
	[Mtr_Amt_Old] [decimal](18, 8) NULL ,
	[Mtr_Amt_New] [decimal](18, 8) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5035P] (
	[Rec_5031P] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_5031] [int] NOT NULL ,
	[Rec_503] [int] NOT NULL ,
	[Part_No] [nvarchar] (10) NULL ,
	[Part_Name] [nvarchar] (30) NOT NULL ,
	[Part_Dim] [nvarchar] (50) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Cut_Amt] [decimal](18, 4) NULL ,
	[Part_Amt] [decimal](18, 6) NULL ,
	[Part_Loss_Rate] [decimal](18, 6) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 6) NULL ,
	[Loss_Amt] [decimal](18, 6) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[total_part_amt] [decimal](18, 6) NULL ,
	[total_part_loss_amt] [decimal](18, 6) NULL ,
	[total_amt] [decimal](18, 6) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst504] (
	[Rec_504] [int] IDENTITY (1, 1) NOT NULL ,
	[Item_Name] [nvarchar] (30) NOT NULL ,
	[Item_Value] [nvarchar] (30) NULL ,
	[Remark] [nvarchar] (100) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Item_Type] [nvarchar] (30) NULL ,
	[ser_no] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst505] (
	[Rec_505] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[From_inv] [nvarchar] (20) NULL ,
	[From_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Sale_Man] [nvarchar] (10) NULL ,
	[Proj_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5051] (
	[Rec_5051] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_505] [int] NOT NULL ,
	[Rec_611_old] [int] NULL ,
	[Update_Type] [nvarchar] (1) NOT NULL ,
	[update_reason] [nvarchar] (50) NULL ,
	[Mtr_Source_Old] [nvarchar] (1) NULL ,
	[Mtr_Amt_PCS_Old] [decimal](18, 6) NULL ,
	[Loss_Rate_PCS_Old] [decimal](18, 6) NULL ,
	[upd_amt] [bit] NULL ,
	[Rec_611_New] [int] NULL ,
	[Mtr_Source_New] [nvarchar] (1) NULL ,
	[Mtr_Amt_Pcs_New] [decimal](18, 6) NULL ,
	[Loss_Rate_PCS_New] [decimal](18, 6) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[remark] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst5052] (
	[Rec_5052] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_5051] [int] NOT NULL ,
	[Rec_505] [int] NOT NULL ,
	[rec_611] [int] NOT NULL ,
	[ver] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50A] (
	[Rec_50A] [int] IDENTITY (1, 1) NOT NULL ,
	[Prod_Name] [nvarchar] (50) NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL ,
	[Mtr_Type] [nvarchar] (20) NULL ,
	[Ver] [nvarchar] (20) NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Status] [nvarchar] (1) NULL ,
	[mtr_dim] [nvarchar] (130) NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[Need_ReCal] [bit] NULL ,
	[Changed_Date] [smalldatetime] NULL ,
	[Changed_Name] [nvarchar] (10) NULL ,
	[Changed_Reason] [nvarchar] (30) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50A1] (
	[Rec_50A1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_50A] [int] NOT NULL ,
	[Ser_No] [int] NULL ,
	[Cal_No] [int] NULL ,
	[type] [nvarchar] (1) NOT NULL ,
	[Parent_Rec_50A1] [int] NULL ,
	[Prop_Name] [nvarchar] (50) NOT NULL ,
	[Default_Prop_Value] [nvarchar] (20) NULL ,
	[Test_Value] [nvarchar] (20) NULL ,
	[Press_value] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Mtr_Type_Name] [nvarchar] (80) NULL ,
	[Mtr_Field_Name] [nvarchar] (30) NULL ,
	[Value_List] [nvarchar] (100) NULL ,
	[Rec_50A1_Copy] [int] NULL ,
	[Level_No] [nvarchar] (21) NULL ,
	[Grade] [int] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[rec_611] [int] NULL ,
	[loss_rate] [decimal](18, 8) NULL ,
	[Forbid_Edit] [bit] NULL ,
	[Must_Input_Loss] [bit] NULL ,
	[feature_type] [nvarchar] (1) NOT NULL ,
	[feature_group] [nvarchar] (50) NULL ,
	[feature_Cond] [nvarchar] (200) NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[Must_Input_Manu_Dim] [bit] NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Is_Rec_611] [bit] NULL ,
	[MTR_NO] [nvarchar] (50) NULL ,
	[MTR_NAME] [nvarchar] (80) NULL ,
	[MTR_DIM] [nvarchar] (130) NULL ,
	[COLOR_NAME] [nvarchar] (50) NULL ,
	[UNIT_NAME] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Cal_Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Prod_Mtr_Amt] [decimal](18, 9) NULL ,
	[Is_Edit_Amt] [bit] NULL ,
	[next_po_name] [nvarchar] (50) NULL ,
	[cur_po_name] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50A2] (
	[Rec_50A2] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_50A1] [int] NOT NULL ,
	[Rec_50A] [int] NOT NULL ,
	[Part_No] [nvarchar] (8) NULL ,
	[Part_Name] [nvarchar] (30) NULL ,
	[Part_Dim] [nvarchar] (100) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Part_Amt] [decimal](18, 8) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Loss_amt] [decimal](18, 8) NULL ,
	[Part_Loss_Rate] [decimal](18, 8) NULL ,
	[Cut_Amt] [decimal](18, 8) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 8) NULL ,
	[Cal_mtr_amt] [decimal](18, 8) NULL ,
	[Part_Picture] [nvarchar] (200) NULL ,
	[Remark] [nvarchar] (50) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50B] (
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Rec_50B] [int] IDENTITY (1, 1) NOT NULL ,
	[Prod_Name] [nvarchar] (50) NULL ,
	[S_Mtr_No] [nvarchar] (50) NULL ,
	[Mtr_No] [nvarchar] (50) NULL ,
	[Mtr_Name] [nvarchar] (80) NULL ,
	[Mtr_Dim] [nvarchar] (130) NULL ,
	[Color_Name] [nvarchar] (30) NULL ,
	[Unit_Id] [nvarchar] (4) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Ver] [nvarchar] (20) NULL ,
	[Form_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NULL ,
	[Proc_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Status] [nvarchar] (1) NULL ,
	[Cust_mtr_No] [nvarchar] (30) NULL ,
	[cust_no] [nvarchar] (10) NULL ,
	[mtr_type] [nvarchar] (20) NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[Need_ReCal] [bit] NULL ,
	[Changed_Date] [smalldatetime] NULL ,
	[Changed_Name] [nvarchar] (10) NULL ,
	[Changed_Reason] [nvarchar] (30) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50B1] (
	[Rec_50B1] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_50B] [int] NOT NULL ,
	[Ser_No] [int] NULL ,
	[Cal_No] [int] NULL ,
	[type] [nvarchar] (1) NOT NULL ,
	[Parent_Rec_50B1] [int] NULL ,
	[Prop_Name] [nvarchar] (50) NOT NULL ,
	[Prop_Value] [nvarchar] (20) NULL ,
	[Press_value] [nvarchar] (200) NULL ,
	[Mtr_Type_Name] [nvarchar] (80) NULL ,
	[Mtr_Field_Name] [nvarchar] (30) NULL ,
	[Value_List] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Rec_611] [int] NULL ,
	[Rec_50A1_Copy] [int] NULL ,
	[Level_No] [nvarchar] (21) NULL ,
	[Grade] [int] NULL ,
	[Make_Org_No] [nvarchar] (6) NULL ,
	[Pick_Org_No] [nvarchar] (6) NULL ,
	[remark] [nvarchar] (200) NULL ,
	[loss_rate] [decimal](18, 8) NULL ,
	[Forbid_Edit] [bit] NULL ,
	[Must_Input_Loss] [bit] NULL ,
	[feature_type] [nvarchar] (1) NOT NULL ,
	[feature_group] [nvarchar] (50) NULL ,
	[feature_Cond] [nvarchar] (200) NULL ,
	[Supl_No] [nvarchar] (10) NULL ,
	[Manu_Dim] [nvarchar] (100) NULL ,
	[Must_Input_Manu_Dim] [bit] NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Is_Rec_611] [bit] NULL ,
	[MTR_NO] [nvarchar] (50) NULL ,
	[MTR_NAME] [nvarchar] (80) NULL ,
	[MTR_DIM] [nvarchar] (130) NULL ,
	[COLOR_NAME] [nvarchar] (50) NULL ,
	[UNIT_NAME] [nvarchar] (10) NULL ,
	[Mtr_Source] [nvarchar] (1) NULL ,
	[Mtr_Amt] [decimal](18, 9) NULL ,
	[Cal_Mtr_Amt] [decimal](18, 9) NULL ,
	[Loss_Amt] [decimal](18, 9) NULL ,
	[Prod_Mtr_Amt] [decimal](18, 9) NULL ,
	[Is_Edit_Amt] [bit] NULL ,
	[next_po_name] [nvarchar] (50) NULL ,
	[cur_po_name] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst50B2] (
	[Rec_50B2] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_50B1] [int] NOT NULL ,
	[Rec_50B] [int] NOT NULL ,
	[Part_No] [nvarchar] (8) NULL ,
	[Part_Name] [nvarchar] (30) NULL ,
	[Part_Dim] [nvarchar] (100) NULL ,
	[Part_Width] [nvarchar] (10) NULL ,
	[Part_Amt] [decimal](18, 8) NULL ,
	[Unit_Name] [nvarchar] (10) NULL ,
	[Loss_amt] [decimal](18, 8) NULL ,
	[Part_Loss_Rate] [decimal](18, 8) NULL ,
	[Cut_Amt] [decimal](18, 8) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Mtr_Amt] [decimal](18, 8) NULL ,
	[Cal_mtr_amt] [decimal](18, 8) NULL ,
	[Part_Picture] [nvarchar] (200) NULL ,
	[Remark] [nvarchar] (50) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [datetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst602] (
	[Unit_Id] [nvarchar] (4) NOT NULL ,
	[Unit_Name] [nvarchar] (10) NOT NULL ,
	[Unit_Ename] [nvarchar] (10) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6021] (
	[Rec_6021] [int] IDENTITY (1, 1) NOT NULL ,
	[Press_Name] [nvarchar] (50) NOT NULL ,
	[Press_Value] [nvarchar] (500) NULL ,
	[scale_value] [smallint] NOT NULL ,
	[main_unit_id] [nvarchar] (4) NOT NULL ,
	[acc_unit_id] [nvarchar] (4) NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst603] (
	[Rec_603] [int] IDENTITY (1, 1) NOT NULL ,
	[Mtr_Type] [nvarchar] (20) NOT NULL ,
	[Dis_No] [nvarchar] (30) NULL ,
	[Type_Name] [nvarchar] (80) NULL ,
	[Type_Kind] [nvarchar] (1) NULL ,
	[Code_Flag] [nvarchar] (20) NULL ,
	[Ser_Len] [varchar] (11) NULL ,
	[Prod_Name] [nvarchar] (80) NULL ,
	[Code_Rule] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[show_cut] [bit] NULL ,
	[TITLE_NAME] [nvarchar] (20) NULL ,
	[BOM_Precision] [decimal](18, 8) NULL ,
	[Purc_Precision] [decimal](18, 8) NULL ,
	[Need_QC] [nvarchar] (1) NULL ,
	[grad_no] [nvarchar] (100) NULL ,
	[HideBomMat] [bit] NULL ,
	[InBOMHideMe] [bit] NULL ,
	[BOM_Loss_Rate] [decimal](18, 8) NULL ,
	[Make_Precision] [tinyint] NULL ,
	[sub_Stock_mode] [nvarchar] (1) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst604] (
	[Type_No] [nvarchar] (4) NOT NULL ,
	[Color_Type] [nvarchar] (20) NOT NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Color_Type_NO] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst605] (
	[Type_No] [nvarchar] (4) NOT NULL ,
	[Color_No] [nvarchar] (10) NOT NULL ,
	[Color_Name] [nvarchar] (30) NULL ,
	[Color_Ename] [nvarchar] (50) NULL ,
	[Color_Picture] [nvarchar] (200) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6051] (
	[Color_No] [nvarchar] (10) NULL ,
	[Color_Ename] [nvarchar] (50) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [smalldatetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst606] (
	[Fee_No] [nvarchar] (4) NOT NULL ,
	[Fee_Name] [nvarchar] (30) NULL ,
	[Fee_Ammount] [decimal](18, 8) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst607] (
	[Unit_Id1] [nvarchar] (4) NOT NULL ,
	[Unit_Id2] [nvarchar] (4) NOT NULL ,
	[Trans_Val] [decimal](18, 10) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6071] (
	[Rec_6071] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_611] [int] NULL ,
	[Main_Unit_ID] [nvarchar] (4) NULL ,
	[Main_Value] [decimal](18, 10) NULL ,
	[Acc_Unit_ID] [nvarchar] (4) NULL ,
	[Acc_Value] [decimal](18, 10) NULL ,
	[Press_No] [nvarchar] (30) NULL ,
	[Press_Name] [nvarchar] (500) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst609] (
	[Po_Type] [nvarchar] (29) NOT NULL ,
	[Dis_No] [nvarchar] (10) NULL ,
	[Type_Name] [nvarchar] (50) NOT NULL ,
	[Type_Type] [nvarchar] (1) NULL ,
	[Code_Flag] [nvarchar] (20) NULL ,
	[Ser_Len] [nvarchar] (5) NULL ,
	[Code_Rule] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Lock] [nvarchar] (3) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6091] (
	[Rec_6091] [int] IDENTITY (1, 1) NOT NULL ,
	[Po_Type] [nvarchar] (20) NULL ,
	[Po_No] [nvarchar] (14) NOT NULL ,
	[Po_Name] [nvarchar] (50) NULL ,
	[Part_Name] [nvarchar] (200) NULL ,
	[Po_Prs] [decimal](18, 8) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Lock] [nvarchar] (3) NULL ,
	[po_unit_name] [nvarchar] (10) NULL ,
	[Po_Prs_Day] [decimal](18, 8) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6091_History] (
	[Rec_6091] [int] NULL ,
	[Po_Type] [nvarchar] (20) NULL ,
	[Po_No] [nvarchar] (14) NOT NULL ,
	[Po_Name] [nvarchar] (50) NULL ,
	[Part_Name] [nvarchar] (200) NULL ,
	[Po_Prs] [decimal](18, 8) NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Lock] [nvarchar] (3) NULL ,
	[PO_Unit_Name] [nvarchar] (10) NULL ,
	[Oper_Type] [nvarchar] (10) NULL ,
	[Oper_Date] [datetime] NULL ,
	[Oper_Name] [nvarchar] (12) NULL ,
	[Po_Prs_Day] [decimal](18, 8) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6092] (
	[Rec_6092] [int] IDENTITY (1, 1) NOT NULL ,
	[Org_no] [nvarchar] (6) NOT NULL ,
	[Po_type] [nvarchar] (29) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst611] (
	[Rec_611] [int] IDENTITY (1, 1) NOT NULL ,
	[Mtr_No] [nvarchar] (50) NOT NULL ,
	[S_Mtr_No] [nvarchar] (50) NULL ,
	[Old_Mtr_No] [nvarchar] (30) NULL ,
	[Mtr_Name] [nvarchar] (80) NULL ,
	[Mtr_Dim] [nvarchar] (130) NULL ,
	[Color_Name] [nvarchar] (30) NULL ,
	[Unit_Id] [nvarchar] (4) NOT NULL ,
	[Mtr_type] [nvarchar] (20) NULL ,
	[Type] [nvarchar] (1) NOT NULL ,
	[Mtr_Weight] [decimal](18, 8) NULL ,
	[Weight_Unit_Name] [nvarchar] (10) NULL ,
	[Remark] [ntext] NULL ,
	[Safe_Amt_Min] [decimal](18, 8) NULL ,
	[Safe_Amt_Max] [decimal](18, 8) NULL ,
	[Photo_Path] [ntext] NULL ,
	[Mtr_Len] [decimal](18, 8) NULL ,
	[Mtr_Wid] [decimal](18, 8) NULL ,
	[Mtr_Hei] [decimal](18, 8) NULL ,
	[Mtr_Status] [nvarchar] (1) NULL ,
	[Allow_Use] [bit] NULL ,
	[Check_Name] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Sub_Type] [nvarchar] (1) NULL ,
	[Bar_No] [nvarchar] (20) NULL ,
	[ABC_Type] [nvarchar] (1) NULL ,
	[Bar_Place] [nvarchar] (50) NULL ,
	[Ahead_Time] [int] NULL ,
	[PO_Prs_Max] [decimal](18, 4) NULL ,
	[Allow_MultiUnit] [bit] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Prod_Name] [nvarchar] (80) NULL ,
	[Supl_NO] [nvarchar] (10) NULL ,
	[Model_Mtr_No] [nvarchar] (80) NULL ,
	[sub_Stock_mode] [nvarchar] (1) NULL ,
	[cust_ORDER] [nvarchar] (30) NULL ,
	[cust_mtr_no] [nvarchar] (30) NULL ,
	[sample_order] [nvarchar] (30) NULL ,
	[sample_mtr] [nvarchar] (30) NULL ,
	[sample_date] [smalldatetime] NULL ,
	[allow_sale] [bit] NULL ,
	[allow_purc] [bit] NULL ,
	[allow_make] [bit] NULL ,
	[parent_mtr_no] [nvarchar] (50) NULL ,
	[left_mark] [ntext] NULL ,
	[top_mark] [ntext] NULL ,
	[front_mark] [ntext] NULL ,
	[Short_Amt_Rate] [decimal](18, 6) NULL ,
	[Over_Amt_Rate] [decimal](18, 6) NULL ,
	[Ass_Unit_Rate] [decimal](18, 6) NULL ,
	[Allow_Change_Unit_Rate] [bit] NULL ,
	[Use_Late_Pick_Mat] [bit] NULL ,
	[Ass_Unit_Id] [nvarchar] (4) NULL ,
	[Day_Output] [decimal](18, 6) NULL ,
	[Last_Supl_No] [nvarchar] (10) NULL ,
	[Last_Purc_Date] [smalldatetime] NULL ,
	[purc_amt_min] [decimal](18, 6) NULL ,
	[bar_code] [nvarchar] (50) NULL ,
	[bar_code_Type] [nvarchar] (50) NULL ,
	[mtr_prs] [decimal](18, 8) NULL ,
	[new_prs] [decimal](18, 8) NULL ,
	[avg_prs] [decimal](18, 8) NULL ,
	[Allow_BOM_Feature] [bit] NULL ,
	[Assign_BOM_Ver] [bit] NULL ,
	[BOM_Loss_Rate] [decimal](18, 8) NULL ,
	[rec_610_tmp] [int] NULL ,
	[Make_Precision] [tinyint] NULL ,
	[Purc_Pak_amt_Min] [decimal](18, 8) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6111] (
	[Rec_6111] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_611] [int] NULL ,
	[Ser_No] [int] NULL ,
	[Title_Name] [nvarchar] (20) NULL ,
	[Title_Note] [ntext] NULL ,
	[Note] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst6160] (
	[Rec_6160] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_611] [int] NOT NULL ,
	[Rec_611_4] [int] NULL ,
	[Cut_No] [nvarchar] (30) NULL ,
	[Part_Name] [nvarchar] (30) NULL ,
	[Bom_Dim] [nvarchar] (100) NULL ,
	[Cut_Amt] [int] NULL ,
	[Mtr_Width] [nvarchar] (50) NULL ,
	[Mtr_Time] [decimal](18, 8) NULL ,
	[Bom_Amt] [decimal](18, 8) NULL ,
	[Loss_Amt] [decimal](18, 8) NULL ,
	[Bing_Long] [decimal](18, 8) NULL ,
	[Bing_Amt] [decimal](18, 8) NULL ,
	[Press_No] [nvarchar] (10) NULL ,
	[Press_Name] [nvarchar] (200) NULL ,
	[Cut_Pic] [nvarchar] (200) NULL ,
	[Note] [nvarchar] (50) NULL ,
	[Upd_name] [nvarchar] (10) NULL ,
	[Upd_date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst617] (
	[Cant_No] [nvarchar] (20) NOT NULL ,
	[Cant_Name] [nvarchar] (20) NOT NULL ,
	[Flag] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst618] (
	[Area_No] [nvarchar] (20) NOT NULL ,
	[Area_Name] [nvarchar] (20) NULL ,
	[Area_Type] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst621] (
	[Money_No] [nvarchar] (10) NOT NULL ,
	[Money_Name] [nvarchar] (20) NULL ,
	[Money_Ename] [nvarchar] (20) NULL ,
	[Money_Main] [nvarchar] (1) NULL ,
	[Ratio] [decimal](18, 8) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst800] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[Org_No] [nvarchar] (6) NULL ,
	[User_Name] [nvarchar] (10) NULL ,
	[User_Ename] [nvarchar] (20) NULL ,
	[Sign_Picture] [ntext] NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst802] (
	[Pay_Type] [nvarchar] (4) NOT NULL ,
	[Pay_Script] [nvarchar] (100) NULL ,
	[Pay_Ename] [nvarchar] (100) NULL ,
	[Upd_Name] [nvarchar] (10) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst807] (
	[Rec_807] [int] IDENTITY (1, 1) NOT NULL ,
	[Report_ID] [nvarchar] (20) NOT NULL ,
	[Prog_Id] [nvarchar] (20) NOT NULL ,
	[Report_Name] [nvarchar] (50) NOT NULL ,
	[ISO_ID] [nvarchar] (50) NULL ,
	[Base_Report_Id] [nvarchar] (20) NULL ,
	[IS_Visible] [bit] NOT NULL ,
	[IS_System] [bit] NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Report_InnnerName] [nvarchar] (50) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst808] (
	[Rec_808] [int] IDENTITY (1, 1) NOT NULL ,
	[Container_Type] [nvarchar] (20) NOT NULL ,
	[Container_CName] [nvarchar] (80) NULL ,
	[Container_EName] [nvarchar] (80) NULL ,
	[Container_Dim] [nvarchar] (80) NULL ,
	[Container_CBM] [decimal](18, 8) NULL ,
	[Container_CUFT] [decimal](18, 8) NULL ,
	[Container_MAX_Gross_Weight] [decimal](18, 8) NULL ,
	[IS_Default] [bit] NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst813] (
	[Rec_813] [int] IDENTITY (1, 1) NOT NULL ,
	[Press_No] [nvarchar] (30) NOT NULL ,
	[Press_Value] [nvarchar] (200) NULL ,
	[Scale_Value] [smallint] NULL ,
	[Remark] [ntext] NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL ,
	[Press_Default] [nvarchar] (1) NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst901] (
	[user_id] [nvarchar] (10) NULL ,
	[User_No] [nvarchar] (4) NULL ,
	[user_name] [nvarchar] (10) NULL ,
	[Group_Id] [nvarchar] (4) NULL ,
	[password] [nvarchar] (50) NULL ,
	[user_right] [nvarchar] (100) NULL ,
	[photo] [nvarchar] (100) NULL ,
	[upd_name] [nvarchar] (10) NULL ,
	[upd_date] [datetime] NULL ,
	[g_note] [nvarchar] (1) NULL ,
	[Msg_Auto_Tell] [nvarchar] (1) NULL ,
	[Default_Erp_ID] [nvarchar] (20) NULL ,
	[Loc_Id] [nvarchar] (5) NULL ,
	[Tel] [nvarchar] (50) NULL ,
	[Fax] [nvarchar] (50) NULL ,
	[E_Mail] [nvarchar] (50) NULL ,
	[Remark] [nvarchar] (50) NULL ,
	[Font_Size] [int] NULL ,
	[Wait_Minute] [decimal](18, 2) NULL ,
	[org_no] [nvarchar] (20) NULL ,
	[bar_no] [nvarchar] (20) NULL ,
	[Use_Dog] [bit] NULL ,
	[Write_Dog] [bit] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst9012] (
	[user_id] [nvarchar] (10) NOT NULL ,
	[Bar_No] [nvarchar] (20) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst902] (
	[Group_Id] [nvarchar] (4) NULL ,
	[Group_Name] [nvarchar] (30) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst903] (
	[Bar_No] [nvarchar] (20) NOT NULL ,
	[Bar_Name] [nvarchar] (20) NULL ,
	[Type_Type] [nvarchar] (1) NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Upd_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst908] (
	[Rec_908] [int] IDENTITY (1, 1) NOT NULL ,
	[Form_Name] [nvarchar] (20) NOT NULL ,
	[Grid_Name] [nvarchar] (20) NOT NULL ,
	[Grid_Setting] [ntext] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmst909] (
	[Item_no] [nvarchar] (50) NULL ,
	[Item_value] [nvarchar] (50) NULL ,
	[Upd_name] [nvarchar] (10) NULL ,
	[Upd_date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstB02] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_B02] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Supl_No] [nvarchar] (20) NOT NULL ,
	[End_Date] [smalldatetime] NOT NULL ,
	[Remark] [ntext] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Close_Man] [nvarchar] (10) NULL ,
	[Close_Date] [smalldatetime] NULL ,
	[real_amount] [decimal](18, 2) NULL ,
	[Payed_Amount] [decimal](18, 2) NULL ,
	[Rest_Amount] [decimal](18, 2) NULL ,
	[Money_Name] [nvarchar] (20) NULL ,
	[Last_Pay_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstB021] (
	[Rec_B021] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_B02] [int] NOT NULL ,
	[Purc_No] [nvarchar] (20) NULL ,
	[Purc_Date] [smalldatetime] NULL ,
	[Rec_611] [int] NOT NULL ,
	[From_Inv_No] [nvarchar] (20) NULL ,
	[From_Inv_Type] [nvarchar] (4) NULL ,
	[From_Inv_Date] [smalldatetime] NULL ,
	[Mtr_No] [nvarchar] (50) NULL ,
	[Mtr_Name] [nvarchar] (80) NOT NULL ,
	[Mtr_Dim] [nvarchar] (200) NULL ,
	[Color_Name] [nvarchar] (50) NULL ,
	[Mtr_Amt_Supl] [decimal](18, 8) NOT NULL ,
	[Mtr_Amt_Inbar_Supl] [decimal](18, 8) NOT NULL ,
	[Req_Amt] [decimal](18, 8) NULL ,
	[Pay_Amt] [decimal](18, 8) NOT NULL ,
	[Unit_Name_Supl] [nvarchar] (20) NOT NULL ,
	[Mtr_Prs_Supl] [decimal](18, 8) NOT NULL ,
	[Req_Prs] [decimal](18, 8) NULL ,
	[Pay_Prs] [decimal](18, 8) NOT NULL ,
	[Pay_Amount] [decimal](18, 2) NOT NULL ,
	[Req_Amount] [decimal](18, 2) NULL ,
	[Rebate_Ratio] [decimal](18, 0) NULL ,
	[Rebate_Amount] [decimal](18, 2) NULL ,
	[Real_Amount] [decimal](18, 2) NOT NULL ,
	[Purc_Money_Name] [nvarchar] (20) NOT NULL ,
	[Check_Money_Name] [nvarchar] (20) NOT NULL ,
	[Payed_Amount] [decimal](18, 2) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Remark] [nvarchar] (100) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstB03] (
	[Loc_Id] [nvarchar] (4) NULL ,
	[Rec_B03] [int] IDENTITY (1, 1) NOT NULL ,
	[Inv_No] [nvarchar] (20) NOT NULL ,
	[Inv_Date] [smalldatetime] NOT NULL ,
	[Cash_Type] [nvarchar] (1) NOT NULL ,
	[Supl_No] [nvarchar] (20) NOT NULL ,
	[Payed_Amount] [decimal](18, 2) NULL ,
	[Money_Name] [nvarchar] (20) NOT NULL ,
	[Check_No] [nvarchar] (50) NULL ,
	[Check_Title] [nvarchar] (200) NULL ,
	[Check_Inv_Date] [smalldatetime] NULL ,
	[Check_Pick_Date] [smalldatetime] NULL ,
	[Check_Cash_Date] [smalldatetime] NULL ,
	[Invoice_Content] [nvarchar] (200) NULL ,
	[Credit_Summary] [nvarchar] (100) NULL ,
	[Credit_Subject1] [nvarchar] (100) NULL ,
	[Credit_Subject2] [nvarchar] (100) NULL ,
	[Debit_Summary] [nvarchar] (100) NULL ,
	[Debit_Subject1] [nvarchar] (100) NULL ,
	[Debit_Subject2] [nvarchar] (100) NULL ,
	[Remark] [ntext] NULL ,
	[Check_Man] [nvarchar] (10) NULL ,
	[Check_Date] [smalldatetime] NULL ,
	[Form_Man] [nvarchar] (10) NOT NULL ,
	[Form_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Status] [nvarchar] (1) NULL ,
	[User_Field0] [nvarchar] (100) NULL ,
	[User_Field1] [nvarchar] (100) NULL ,
	[User_Field2] [nvarchar] (100) NULL ,
	[User_Field3] [nvarchar] (100) NULL ,
	[User_Field4] [nvarchar] (100) NULL ,
	[Close_Man] [nvarchar] (10) NULL ,
	[Close_Date] [smalldatetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstB031] (
	[Rec_B031] [int] IDENTITY (1, 1) NOT NULL ,
	[Rec_B03] [int] NOT NULL ,
	[From_Inv_No] [nvarchar] (20) NULL ,
	[From_Inv_Date] [smalldatetime] NULL ,
	[From_Money_Name] [nvarchar] (20) NOT NULL ,
	[Rebate_Amount] [decimal](18, 2) NULL ,
	[Payed_Amount] [decimal](18, 2) NULL ,
	[Ratio_To_From] [decimal](18, 8) NULL ,
	[Upd_Date] [smalldatetime] NOT NULL ,
	[Upd_Name] [nvarchar] (10) NOT NULL ,
	[Remark] [nvarchar] (100) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc01] (
	[Erp_Order] [int] NOT NULL ,
	[Erp_Id] [nvarchar] (20) NOT NULL ,
	[Erp_Name] [nvarchar] (20) NOT NULL ,
	[Erp_Ename] [nvarchar] (30) NOT NULL ,
	[SER_NO] [tinyint] NULL ,
	[description] [nvarchar] (200) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc02] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[System_Id] [int] NOT NULL ,
	[Menu_Id] [nvarchar] (15) NOT NULL ,
	[Menu_Name] [nvarchar] (50) NULL ,
	[Prog_Id] [nvarchar] (20) NULL ,
	[Prog_Type] [nvarchar] (15) NULL ,
	[Menu_Ename] [nvarchar] (50) NULL ,
	[Help_Id] [int] NULL ,
	[Rpt_Name] [nvarchar] (50) NULL ,
	[DESCRIPTION] [nvarchar] (500) NULL ,
	[SER_NO] [nvarchar] (15) NULL ,
	[Show] [nvarchar] (1) NULL ,
	[Table_Name] [nvarchar] (20) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc03] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[System_Id] [int] NULL ,
	[User_id] [nvarchar] (10) NOT NULL ,
	[Menu_Id] [nvarchar] (15) NOT NULL ,
	[Rights] [nvarchar] (15) NULL ,
	[Mtr_Type_S] [ntext] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc05] (
	[Form_Id] [nvarchar] (50) NULL ,
	[Ser_No] [int] NULL ,
	[Inner_FieldName] [nvarchar] (50) NULL ,
	[Inner_ColName] [nvarchar] (50) NULL ,
	[Outer_ColName] [nvarchar] (50) NULL ,
	[Upd_Date] [smalldatetime] NULL ,
	[Upd_Name] [nvarchar] (12) NULL ,
	[Data_Type] [nvarchar] (10) NULL ,
	[Need_Save] [bit] NULL ,
	[Visible] [bit] NULL ,
	[fixed_value] [nvarchar] (200) NULL ,
	[Check_sql] [nvarchar] (2000) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc06] (
	[erp_id] [varchar] (10) NULL ,
	[table_id] [varchar] (30) NOT NULL ,
	[table_name] [nvarchar] (30) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc061] (
	[Table_Id] [nvarchar] (30) NULL ,
	[Col_Id] [nvarchar] (40) NULL ,
	[Col_Name] [nvarchar] (40) NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mmstc_Lock] (
	[Rec_No] [int] IDENTITY (1, 1) NOT NULL ,
	[lock_table] [nvarchar] (20) NULL ,
	[Lock_Condition] [nvarchar] (50) NULL ,
	[Lock_Date] [smalldatetime] NULL ,
	[Lock_Name] [nvarchar] (12) NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst609] WITH NOCHECK ADD 
	CONSTRAINT [PK_mmst609] PRIMARY KEY  CLUSTERED 
	(
		[Po_Type]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst621] WITH NOCHECK ADD 
	CONSTRAINT [PK_mmst621] PRIMARY KEY  CLUSTERED 
	(
		[Money_No]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst813] WITH NOCHECK ADD 
	CONSTRAINT [PK_mmst813] PRIMARY KEY  CLUSTERED 
	(
		[Press_No]
	)  ON [PRIMARY] 
GO

 CREATE  CLUSTERED  INDEX [mmst001_org_No] ON [dbo].[mmst001]([Org_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst103_Rec_103] ON [dbo].[mmst103]([Rec_103]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst1031_Rec_1031] ON [dbo].[mmst1031]([Rec_1031]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [IX_mmst103M] ON [dbo].[mmst103M]([Order_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [IX_mmst103MP] ON [dbo].[mmst103MP]([Order_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst301_supl_No] ON [dbo].[mmst301]([supl_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst303_Rec_303] ON [dbo].[mmst303]([Rec_303]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst481_Rec_611] ON [dbo].[mmst481]([rec_611]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p4811_Rec_611] ON [dbo].[mmst4811]([rec_611]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p501_Rec_501] ON [dbo].[mmst501]([Rec_501]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p501M_Rec_501] ON [dbo].[mmst501M]([Rec_501]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p501P_Rec_501] ON [dbo].[mmst501P]([Rec_501]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p503_Mo_No] ON [dbo].[mmst503]([Mo_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p603_Mtr_Type] ON [dbo].[mmst603]([Mtr_Type]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [p611_rec_611] ON [dbo].[mmst611]([Rec_611]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmst903_bar_no] ON [dbo].[mmst903]([Bar_No]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmstC02_menu_id] ON [dbo].[mmstc02]([Menu_Id]) ON [PRIMARY]
GO

 CREATE  CLUSTERED  INDEX [mmstc03_user_id] ON [dbo].[mmstc03]([User_id]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Rec_NO] ADD 
	CONSTRAINT [DF_Rec_NO_Flag] DEFAULT (0) FOR [Flag]
GO

 CREATE  INDEX [mmst001_org_name] ON [dbo].[mmst001]([Org_Name]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst100] ADD 
	CONSTRAINT [PK_mmst100] PRIMARY KEY  NONCLUSTERED 
	(
		[Loc_Id]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [mmst103_Order_No] ON [dbo].[mmst103]([Order_No]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst1031] ADD 
	CONSTRAINT [DF__mmst1031__Is_Aut__11165497] DEFAULT (1) FOR [Is_Auto_BOM],
	CONSTRAINT [DF__mmst1031__Mtr_So__6B10A740] DEFAULT ('1') FOR [Mtr_Source]
GO

ALTER TABLE [dbo].[mmst103M] ADD 
	CONSTRAINT [DF__mmst103M__featur__76625E5B] DEFAULT ('0') FOR [feature_type],
	CONSTRAINT [DF__mmst103m__rec_10__7B271378] DEFAULT (0) FOR [rec_1031],
	CONSTRAINT [DF__mmst103m__mat_us__01D41107] DEFAULT (1) FOR [mat_used]
GO

ALTER TABLE [dbo].[mmst103M_Feature] ADD 
	CONSTRAINT [DF__mmst103M___bom_v__4D2B3E9E] DEFAULT ('') FOR [bom_ver],
	CONSTRAINT [DF__mmst103M___Bom_V__4E1F62D7] DEFAULT ('') FOR [Bom_Ver_New]
GO

ALTER TABLE [dbo].[mmst201] ADD 
	CONSTRAINT [PK_mmst201] PRIMARY KEY  NONCLUSTERED 
	(
		[Title_No]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [mmst303_Purc_No] ON [dbo].[mmst303]([Purc_No]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst400] ADD 
	CONSTRAINT [DF__mmst400__Must_In__4DEA58AD] DEFAULT (0) FOR [Must_Input_Proc_Man],
	CONSTRAINT [DF__mmst400__Must_In__4EDE7CE6] DEFAULT (1) FOR [Must_Input_Bar_Man],
	CONSTRAINT [DF__mmst400__Must_In__4FD2A11F] DEFAULT (0) FOR [Must_Input_Purc_Man]
GO

ALTER TABLE [dbo].[mmst403] ADD 
	CONSTRAINT [DF__mmst403__inv_sub__60731D3C] DEFAULT ('0') FOR [inv_sub_type]
GO

 CREATE  INDEX [p4811_Inv_Date] ON [dbo].[mmst4811]([Inv_Date]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst501] ADD 
	CONSTRAINT [Start_Date_Default501] DEFAULT ('2000-01-01') FOR [Start_Date],
	CONSTRAINT [DF__mmst501__color_s__4CC12A4A] DEFAULT (0) FOR [color_same_amt]
GO

 CREATE  INDEX [p501_Rec_611_0] ON [dbo].[mmst501]([Rec_611_0]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst501M] ADD 
	CONSTRAINT [DF__mmst501m__type__67201ACB] DEFAULT ('1') FOR [type],
	CONSTRAINT [DF__mmst501M__featur__7385F1B0] DEFAULT ('0') FOR [feature_type],
	CONSTRAINT [DF__mmst501m__is_las__45AA1867] DEFAULT (0) FOR [is_last]
GO

 CREATE  INDEX [p501M_Rec_611_0] ON [dbo].[mmst501M]([Rec_611_0]) ON [PRIMARY]
GO

 CREATE  INDEX [p501P_Rec_501M] ON [dbo].[mmst501M]([Rec_501M]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst501M_Tmp] ADD 
	CONSTRAINT [DF__mmst501M___featu__77568294] DEFAULT ('0') FOR [feature_type]
GO

 CREATE  INDEX [p501P_Part_No] ON [dbo].[mmst501P]([Part_No]) ON [PRIMARY]
GO

 CREATE  INDEX [p501P_Rec_501P] ON [dbo].[mmst501P]([Rec_501P]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst5031] ADD 
	CONSTRAINT [DF__mmst5031__Only_P__758E35B3] DEFAULT (0) FOR [Only_Po]
GO

ALTER TABLE [dbo].[mmst5033] ADD 
	CONSTRAINT [DF__mmst5033__IS_Aut__3A3865BB] DEFAULT (1) FOR [IS_Auto_Prod_Amt],
	CONSTRAINT [DF__mmst5033__IS_Ful__3B2C89F4] DEFAULT (0) FOR [IS_Full_Amt]
GO

ALTER TABLE [dbo].[mmst5034] ADD 
	CONSTRAINT [DF__mmst5034__IS_Ful__3D14D266] DEFAULT (0) FOR [IS_Full_Amt]
GO

ALTER TABLE [dbo].[mmst50A1] ADD 
	CONSTRAINT [DF__mmst50A1__featur__747A15E9] DEFAULT ('0') FOR [feature_type],
	CONSTRAINT [DF__Mmst50A1__Is_Rec__4337C010] DEFAULT (1) FOR [Is_Rec_611]
GO

ALTER TABLE [dbo].[mmst50B1] ADD 
	CONSTRAINT [DF__mmst50B1__featur__756E3A22] DEFAULT ('0') FOR [feature_type],
	CONSTRAINT [DF__Mmst50B1__Is_Rec__45200882] DEFAULT (1) FOR [Is_Rec_611]
GO

ALTER TABLE [dbo].[mmst602] ADD 
	CONSTRAINT [PK_mmst602] PRIMARY KEY  NONCLUSTERED 
	(
		[Unit_Id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst603] ADD 
	CONSTRAINT [DF__mmst603__HideBom__5B0F49A1] DEFAULT (0) FOR [HideBomMat],
	CONSTRAINT [DF__mmst603__InBOMHi__5CF79213] DEFAULT (0) FOR [InBOMHideMe]
GO

 CREATE  INDEX [p603_Type_Name] ON [dbo].[mmst603]([Type_Name]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst604] ADD 
	CONSTRAINT [PK_mmst604] PRIMARY KEY  NONCLUSTERED 
	(
		[Color_Type]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst605] ADD 
	CONSTRAINT [PK_mmst605] PRIMARY KEY  NONCLUSTERED 
	(
		[Color_No]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst606] ADD 
	CONSTRAINT [PK_mmst211A] PRIMARY KEY  NONCLUSTERED 
	(
		[Fee_No]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst611] ADD 
	CONSTRAINT [DF__mmst611__Assign___42439BD7] DEFAULT (0) FOR [Assign_BOM_Ver]
GO

 CREATE  INDEX [p611_mtr_no] ON [dbo].[mmst611]([Mtr_No]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[mmst618] ADD 
	CONSTRAINT [PK_mmst018] PRIMARY KEY  NONCLUSTERED 
	(
		[Area_No]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst802] ADD 
	CONSTRAINT [PK_mmst802] PRIMARY KEY  NONCLUSTERED 
	(
		[Pay_Type]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_mmst802] UNIQUE  NONCLUSTERED 
	(
		[Pay_Type]
	)  ON [PRIMARY] ,
	CONSTRAINT [IX_mmst802_1] UNIQUE  NONCLUSTERED 
	(
		[Pay_Script]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmst901] ADD 
	CONSTRAINT [DF__Mmst901__Use_Dog__5185DF67] DEFAULT (0) FOR [Use_Dog],
	CONSTRAINT [DF__Mmst901__Write_D__527A03A0] DEFAULT (0) FOR [Write_Dog]
GO

ALTER TABLE [dbo].[mmstc01] ADD 
	CONSTRAINT [PK_mmstc01] PRIMARY KEY  NONCLUSTERED 
	(
		[Erp_Order]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mmstc02] ADD 
	CONSTRAINT [PK_mmstc02] PRIMARY KEY  NONCLUSTERED 
	(
		[Menu_Id]
	)  ON [PRIMARY] 
GO

 CREATE  INDEX [mmstC02_prog_id] ON [dbo].[mmstc02]([Prog_Id]) ON [PRIMARY]
GO

 CREATE  INDEX [mmstc03_menu_id] ON [dbo].[mmstc03]([Menu_Id]) ON [PRIMARY]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW dbo.VsCust
AS
SELECT supl_No as cust_no, supl_Name as cust_name, supl_Cname as cust_Cname,Cant_No
FROM dbo.mmst301
WHERE (flag = '1')



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW dbo.VsSupl
AS
SELECT supl_No, supl_Name, supl_Cname
FROM dbo.mmst301
WHERE (flag = '2')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst1035M AS
 SELECT mmst103.order_no,mmst103.cust_no,mmst1031.cust_order,mmst1031.deliv_date,mmst1031.cust_mtr_no,
 mmst1031.Rec_103,mmst1031.Rec_1031,mmst103m.rec_103m AS rec_1035, mmst103m.rec_103m, 
    mmst103M.Supl_No, mmst103M.Mtr_Source,mmst103m.rec_611_BOM, 
   mmst103m.Rec_611,mmst103m.rec_611_p,mmst103m.rec_611_parent, 
   mmst1031.Manu_Amt * mmst103M.Loss_Amt*mmst103m.BOM_Rate AS Total_Mtr_Loss_Amt, 
   mmst1031.Manu_Amt * mmst103M.Mtr_Amt*mmst103m.BOM_Rate AS Total_Mtr_Amt, 
   mmst1031.Manu_Amt * mmst103M.Total_Amt*mmst103m.BOM_Rate  AS total_amt,mmst103m.BOM_Rate,
   mmst103M.Mtr_Amt AS Pcs_Mtr_Amt,mmst103m.loss_amt as pcs_loss_amt, 
   mmst103m.loss_amt /nullif(mmst103M.Mtr_Amt,0)*100 AS pcs_loss_rate,mmst103m.level_no,mmst103m.grade,mmst103m.mat_used,mmst103M.Feature_Type,mmst103M.Feature_Group,
  mmst103m.manu_dim,MMST103M.cur_po_name,MMST103M.next_po_Name,mmst103M.remark,mmst103m.bom,mmst103m.ver,mmst103m.start_Date,mmst103m.IS_Max_Parent,mmst103m.Upd_Name,mmst103m.Upd_Date
 FROM mmst1031 INNER JOIN
   mmst103 ON mmst1031.rec_103 = mmst103.rec_103 INNER JOIN
   mmst103M ON mmst103M.mat_used='1' and mmst1031.rec_1031= mmst103m.rec_1031 and mmst1031.Rec_611 = mmst103M.rec_611_p AND 
   mmst103.Order_No = mmst103m.order_no 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW dbo.Vmmst1035MP
AS
SELECT mmst103.Order_No,mmst103.cust_no,mmst1031.Rec_1031,mmst1031.cust_order,mmst1031.cust_mtr_no,mmst1031.deliv_date, p.Rec_103M AS rec_1035, mmst1031.Rec_103, 
       mmst103M.Supl_No, mmst103M.Mtr_Source, mmst103m.rec_611_BOM,mmst103m.level_no,mmst103m.grade,
      mmst1031.Manu_Amt * p.Part_Amt AS total_part_amt, 
      mmst1031.Manu_Amt * p.Part_Loss_Rate / 100 AS Total_part_Loss_Amt, 
      mmst1031.Manu_Amt * (1 + ISNULL(p.Part_Loss_Rate, 0) / 100) 
      * p.Part_Amt AS Total_Amt, p.Rec_103MP, mmst103M.Rec_103M,mmst103m.BOM_Rate,
      mmst103M.Rec_611_P, p.Rec_611, mmst103M.Rec_611_Parent,p.Part_No, 
      p.Part_Name, p.Part_Dim, p.Part_Width, p.Unit_Name, p.Cut_Amt, p.Part_Amt, 
p.Part_Loss_Rate, p.Press_No, p.Press_Value, p.Mtr_Amt, p.Loss_Amt, p.Upd_Name, 
      p.Upd_Date,mmst103m.mat_used, mmst103M.cur_po_name,mmst103M.next_po_Name, p.remark
 FROM mmst1031 INNER JOIN
   mmst103 ON mmst1031.rec_103 = mmst103.rec_103 INNER JOIN
   mmst103M ON mmst103m.mat_used=1 and mmst1031.rec_1031= mmst103m.rec_1031 and mmst1031.Rec_611 = mmst103M.rec_611_p AND 
   mmst103.Order_No = mmst103m.order_no inner join  
   mmst103MP p ON mmst103M.Rec_103M = p.Rec_103M
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW dbo.Vmmst3031
AS
SELECT M2.Rec_3032, M2.Rec_3031, M2.Rec_303, M2.From_Type, M2.From_Rec_No, 
      M2.From_Inv_No, M2.Order_No, M1.Rec_611, M2.Mtr_Amt_Supl, M1.Unit_Id_Supl, 
      M1.Mtr_Prs_Supl, M1.Mtr_Prs_Supl * M2.Mtr_Amt_Supl AS mtr_pay_Supl, 
      M2.Mtr_Amt_Local, M2.Mtr_Amt_Local_S, M2.Mtr_Amt_InBar_Supl, 
      M2.Mtr_Amt_InBar_Local, M2.Deliv_Date_S, M1.Deliv_Date, M1.Ass_Rate, 
      M1.Supl_Mtr_No, M1.Supl_Mtr_Name, M1.Supl_Color, M1.Finish_Pay, M1.Mtr_Note, 
      M1.Remark, M1.Photo, M1.User_Field0, M1.User_Field1, M1.User_Field2, 
      M1.User_Field3, M1.User_Field4, M2.Upd_Name, M2.Upd_Date
FROM dbo.mmst3031 M1 LEFT OUTER JOIN
      dbo.mmst3032 M2 ON M1.Rec_3031 = M2.Rec_3031


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst4011 
 AS
 SELECT M2.Rec_4012, M2.Rec_4011, M2.Rec_401, M2.Rec_3032, M1.Purc_No, 
      M1.Rec_611, M2.Order_No, M2.Mtr_Amt_Supl, M1.Unit_id_Supl, M2.Mtr_Amt_Local, 
      M1.Bar_no, M1.Payed, M2.Upd_Name, M2.Upd_Date, M1.Mtr_Prs_Supl, 
      M1.Mtr_Prs_Local, M1.Money_Name, M1.Remark,M1.Mtr_Pay*M2.mtr_amt_Supl/nullif(M1.mtr_Amt_Supl,0) as mtr_pay 
FROM mmst4011 M1 INNER JOIN
      Mmst4012 M2 ON M1.Rec_4011 = M2.Rec_4011
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst5035M AS 
SELECT  Mmst503.Mo_No,mmst503.status,MMst5031.Order_No, MMst5031.rec_1031, MMst5031.Cust_Order, MMst5031.Deliv_Date, 
    MMst5031.Cust_Mtr_No,mmst5031.cur_po_name as cur_po_name_p, MMst5031.org_no as Make_Org_No_P,mmst5031.bom_ver as bom_ver_p, isnull(MMst5031.Manu_Dim,'')  as p_manu_dim, 
mmst103m.Rec_103M, mmst103m.Rec_103M AS rec_5035, MMst5031.Rec_503, MMst5031.Rec_5031,mmst5031.check_mat_date,mmst5031.check_mat_name,
    mmst103m.Supl_No, mmst103m.Mtr_Source,mmst103m.bom,mmst103m.rec_611_BOM,MMst5031.rec_611 as rec_611_parent,isnull(mmst5034.rec_611_new,mmst103m.Rec_611) as rec_611,case when mmst5034.old=0 then mmst5034.rec_611_old end rec_611_old,mmst611.Use_Late_Pick_Mat, 
 round(case mmst5034.old when 1 then MMst5031.Mtr_Amt*mmst103m.Total_Amt+mmst5034.mtr_amt_new when 0 then mmst5034.mtr_amt_new else MMst5031.Mtr_Amt*mmst103m.Total_Amt end*mmst103m.Loss_Amt/nullif(mmst103m.total_amt,0),isnull(mmst611.Make_Precision,4)) AS Total_Mtr_Loss_Amt, 
 round(case mmst5034.old when 1 then MMst5031.Mtr_Amt*mmst103m.Total_Amt+mmst5034.mtr_amt_new when 0 then mmst5034.mtr_amt_new else MMst5031.Mtr_Amt*mmst103m.Total_Amt end*mmst103m.Mtr_Amt/nullif(mmst103m.total_amt,0),isnull(mmst611.Make_Precision,4)) AS Total_Mtr_Amt, 
 round(case mmst5034.old when 1 then MMst5031.Mtr_Amt*mmst103m.Total_Amt+mmst5034.mtr_amt_new when 0 then mmst5034.mtr_amt_new else MMst5031.Mtr_Amt*mmst103m.Total_Amt end ,isnull(mmst611.Make_Precision,4)) AS total_amt, 
 case mmst5034.old when 1 then 0 when 0 then 1 end AS ECN_Flag, 
    mmst103m.Mtr_Amt AS Pcs_Mtr_Amt,mmst103m.Loss_Amt as pcs_loss_amt, 100.0 * mmst103m.Loss_Amt / NULLIF (mmst103m.Mtr_Amt, 0) AS pcs_loss_rate,  
    mmst103m.Upd_Name,mmst103m.Upd_Date, mmst103m.feature_type, mmst103m.feature_group, mmst103m.Manu_Dim,
    mmst103m.cur_po_name,mmst103m.next_po_name,mmst103m.level_no,mmst103m.grade,mmst103m.ver,mmst103m.remark
FROM  Mmst503 INNER JOIN
      MMst5031 ON Mmst503.Rec_503 = MMst5031.Rec_503 INNER JOIN
      mmst103m ON MMst5031.rec_1031 = mmst103m.rec_1031 AND 
          MMst5031.Rec_611 = mmst103m.Rec_611_Parent and mmst103m.mat_used = 1 and mmst103m.IS_Max_Parent=1  AND 
          isnull(MMst5031.Manu_Dim,'') = ISNULL(mmst103m.p_manu_dim,'')  and 
          isnull(MMst5031.Cur_po_name,'') = ISNULL(mmst103m.next_po_name,'') left join 
      (select rec_5034,1 as old, rec_5031,rec_611_old,rec_611_old as rec_611_new,-mtr_amt_old as mtr_amt_new,IS_Full_Amt from mmst5034 
       Union All 
       select rec_5034,0 as old,rec_5031,rec_611_old,rec_611_new,mtr_amt_new,IS_Full_Amt from mmst5034
       ) as mmst5034 on  mmst103m.rec_611=mmst5034.rec_611_old and MMst5031.rec_5031=mmst5034.rec_5031 left join 
      mmst611 on isnull(mmst5034.rec_611_new,mmst103m.Rec_611)=mmst611.rec_611 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst5035MP AS SELECT p.Rec_103M AS rec_5035, mmst5031.Rec_503, mmst5031.Rec_5031,    mmst503.Mo_No,mmst503.status, mmst5031.Order_No,mmst5031.cust_order,mmst5031.cust_mtr_no,mmst5031.deliv_date,mmst5031.cur_po_name as cur_po_name_p,MMst5031.org_no as Make_Org_No_P,mmst5031.bom_ver as bom_ver_p,mmst5031.check_mat_date,mmst5031.check_mat_name,isnull(MMst5031.Manu_Dim,'')  as p_manu_dim,mmst5031.order_deliv_date, mmst103M.Supl_No,    mmst103M.Mtr_Source,mmst103m.rec_611_BOM, mmst5031.Mtr_Amt * p.Part_Amt AS total_part_amt,    mmst5031.Mtr_Amt * p.Part_Loss_Rate / 100 AS Total_part_Loss_Amt,    mmst5031.Mtr_Amt * (1 + ISNULL(p.Part_Loss_Rate, 0) / 100)    * p.Part_Amt AS Total_Amt, p.Rec_103MP, p.Rec_103M,     p.Rec_611_P, p.Rec_611_Parent,  p.Rec_611,    p.Part_No, p.Part_Name, p.Part_Dim, p.Part_Width, p.Unit_Name, p.Cut_Amt,    p.Part_Amt, p.Part_Loss_Rate, p.Press_No, p.Press_Value, p.Mtr_Amt, p.Loss_Amt,    mmst103m.mat_used,p.Upd_Name, p.Upd_Date, mmst103m.feature_type, mmst103m.feature_group, mmst103m.Manu_Dim, mmst103m.cur_po_name, mmst103m.next_po_name,mmst103m.level_no,mmst103m.grade  FROM  Mmst503 INNER JOIN
       MMst5031 ON Mmst503.Rec_503 = MMst5031.Rec_503 INNER JOIN
      mmst103m ON mmst103m.mat_used = 1 and MMst5031.Rec_611 = mmst103m.Rec_611_Parent AND 
          MMst5031.rec_1031 = mmst103m.rec_1031 and mmst103m.IS_Max_Parent=1  AND 
          isnull(MMst5031.Manu_Dim,'') = ISNULL(mmst103m.p_manu_dim,'')  and 
          isnull(MMst5031.Cur_po_name,'') = ISNULL(mmst103m.next_po_name,'')  inner join 
      mmst103MP p ON mmst103M.Rec_103M = p.Rec_103M
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst5035M_ForPick AS 
SELECT  mmst503.Rec_503,mmst503.mo_no,mmst5031.order_no,MMst5031.org_no,mmst5031.deliv_date,mmst103m.mtr_source,isnull(mmst5034.rec_611_new,mmst103m.Rec_611) as rec_611,
round(case mmst5034.old when 1 then MMst5031.Mtr_Amt*mmst103m.Total_Amt+mmst5034.mtr_amt_new when 0 then mmst5034.mtr_amt_new else MMst5031.Mtr_Amt*mmst103m.Total_Amt end*mmst103m.Mtr_Amt/nullif(mmst103m.total_amt,0),isnull(mmst611.Make_Precision,4)) AS Mtr_Amt, 
round(case mmst5034.old when 1 then MMst5031.Mtr_Amt*mmst103m.Total_Amt+mmst5034.mtr_amt_new when 0 then mmst5034.mtr_amt_new else MMst5031.Mtr_Amt*mmst103m.Total_Amt end ,isnull(mmst611.Make_Precision,4)) AS total_amt, 
case when mmst5031.check_mat_date is null then '0' else '2' end as check_mat_status,mmst503.status,mmst103m.supl_no 
FROM mmst503 inner join MMst5031 on mmst503.rec_503=mmst5031.rec_503 INNER JOIN
      mmst103m ON mmst103m.mat_used = 1 and mmst103m.IS_Max_Parent=1 
         and MMst5031.rec_1031 = mmst103m.rec_1031 and MMst5031.Rec_611 = mmst103m.Rec_611_Parent  
         and isnull(MMst5031.Manu_Dim,'') = ISNULL(mmst103m.p_manu_dim,'') 
         and isnull(MMst5031.Cur_po_name,'') = ISNULL(mmst103m.next_po_name,'') left join 
      (select 1 as old, rec_5031,rec_611_old,rec_611_old as rec_611_new,-mtr_amt_old as mtr_amt_new from mmst5034 
       Union All 
       select 0 as old,rec_5031,rec_611_old,rec_611_new,mtr_amt_new from mmst5034
       ) as mmst5034 on  mmst103m.rec_611=mmst5034.rec_611_old and MMst5031.rec_5031=mmst5034.rec_5031 left join 
      mmst611 on isnull(mmst5034.rec_611_new,mmst103m.Rec_611)=mmst611.rec_611 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst5035M_Old AS 
SELECT  Mmst503.Mo_No,mmst503.status,MMst5031.Order_No, MMst5031.rec_1031, MMst5031.Cust_Order, MMst5031.Deliv_Date, 
    MMst5031.Cust_Mtr_No,mmst5031.cur_po_name as cur_po_name_p, MMst5031.org_no as Make_Org_No_P,mmst5031.bom_ver as bom_ver_p, isnull(MMst5031.Manu_Dim,'')  as p_manu_dim, 
mmst103m.Rec_103M, mmst103m.Rec_103M AS rec_5035, MMst5031.Rec_503, MMst5031.Rec_5031,mmst5031.check_mat_date,mmst5031.check_mat_name,
    mmst103m.Supl_No, mmst103m.Mtr_Source,mmst103m.bom,mmst103m.rec_611_BOM,MMst5031.rec_611 as rec_611_parent,mmst103m.Rec_611,mmst611.Use_Late_Pick_Mat, round(MMst5031.Mtr_Amt * mmst103m.Loss_Amt,isnull(mmst611.Make_Precision,4)) AS Total_Mtr_Loss_Amt, 
    round(MMst5031.Mtr_Amt * mmst103m.Mtr_Amt,isnull(mmst611.Make_Precision,4)) AS Total_Mtr_Amt, round(MMst5031.Mtr_Amt * mmst103m.Total_Amt,isnull(mmst611.Make_Precision,4)) AS total_amt, 
    mmst103m.Mtr_Amt AS Pcs_Mtr_Amt,mmst103m.Loss_Amt as pcs_loss_amt, 100.0 * mmst103m.Loss_Amt / NULLIF (mmst103m.Mtr_Amt, 0) AS pcs_loss_rate,  
    mmst103m.Upd_Name,mmst103m.Upd_Date, mmst103m.feature_type, mmst103m.feature_group, mmst103m.Manu_Dim,
    mmst103m.cur_po_name,mmst103m.next_po_name,mmst103m.level_no,mmst103m.grade,mmst103m.ver,mmst103m.remark
FROM  Mmst503 INNER JOIN
      MMst5031 ON Mmst503.Rec_503 = MMst5031.Rec_503 INNER JOIN
      mmst103m ON mmst103m.mat_used = 1 and MMst5031.Rec_611 = mmst103m.Rec_611_Parent AND 
          MMst5031.rec_1031 = mmst103m.rec_1031 and mmst103m.IS_Max_Parent=1  AND 
          isnull(MMst5031.Manu_Dim,'') = ISNULL(mmst103m.p_manu_dim,'')  and 
          isnull(MMst5031.Cur_po_name,'') = ISNULL(mmst103m.next_po_name,'') left join 
      mmst611 on mmst103m.Rec_611=mmst611.rec_611 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW Vmmst611 AS 
SELECT m.Rec_611, m.S_Mtr_No, m.parent_mtr_no, m.Old_Mtr_No, m.Mtr_No,m.bar_code,m.bar_code_Type,
      m.Mtr_Name, m.Mtr_Dim, ISNULL(m.Mtr_Dim, '') + ' ' + ISNULL(m.Color_Name, '') AS m_mtr_dim,
 ISNULL(m.Mtr_name, '') + ' '+ISNULL(m.Mtr_Dim, '') + ' ' + ISNULL(m.Color_Name, '') AS m_mtr_Name_dim,       m.Color_Name, m.Allow_MultiUnit,m.Allow_Change_Unit_Rate,m.Unit_Id, mmst602.Unit_Name, 
      mmst602.Unit_Ename,m.ass_unit_id,ass.unit_name as ass_unit_name,m.ass_unit_rate, mmst603.TITLE_NAME, m.Mtr_type, mmst603.Type_Name, 
      m.Type,mmst603.type_kind,m.Sub_Type, m.sub_Stock_mode, m.Bar_No, mmst903.Bar_Name, 
      m.Bar_Place, m.ABC_Type, m.Mtr_Weight, m.Weight_Unit_Name, m.Safe_Amt_Min, 
      m.Safe_Amt_Max,m.purc_amt_min,m.Purc_Pak_amt_Min,m.Ahead_Time,m.mtr_prs,m.new_prs,m.avg_prs,m.PO_Prs_Max,  m.Mtr_Len, m.Mtr_Wid, 
      m.Mtr_Hei, m.Mtr_Status, m.Check_Name, m.Check_Date, 
      CAST(ABS(CAST(m.Mtr_Len AS nvarchar(20))) AS nvarchar(20)) 
      + '*' + CAST(ABS(CAST(m.Mtr_Wid AS nvarchar(20))) AS nvarchar(20)) 
      + '*' + CAST(ABS(CAST(m.Mtr_Hei AS nvarchar(20))) AS nvarchar(20)) AS mtr_size, 
      m.Supl_NO, mmst301.supl_Name, m.Supl_NO AS cust_no, 
      mmst301.supl_Name AS cust_name, m.cust_ORDER, m.cust_mtr_no, m.sample_mtr, 
      m.sample_date, m.sample_order,m.Use_Late_Pick_Mat,m.Allow_Use, m.allow_purc, m.allow_make, 
      m.allow_sale,  m.Photo_Path, m.Remark,mmst603.HideBomMat,mmst603.InBOMHideMe,rec_611 as rec_611_0,m.Make_Precision,cast(1 as bit) as is_rec_611,m.Upd_Date, 
      m.Upd_Name
FROM mmst611 m LEFT OUTER JOIN
      mmst903 ON mmst903.Bar_No = m.Bar_No LEFT OUTER JOIN
      mmst602 ON mmst602.Unit_Id = m.Unit_Id LEFT OUTER JOIN
      mmst603 ON mmst603.Mtr_Type = m.Mtr_type LEFT OUTER JOIN
      mmst301 ON m.Supl_NO = mmst301.supl_No left join  Mmst602 ass ON m.ass_Unit_Id = ass.Unit_Id 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE VIEW vsOrg AS 
 SELECT supl_No , supl_Name,'1' as From_Obj
 FROM dbo.mmst301
 WHERE (flag = '2')
 UNION 
 SELECT supl_No AS supl_No, supl_Name AS supl_Name,'2' as From_Obj
 FROM dbo.mmst301
 WHERE (flag = '1')
 UNION 
 SELECT org_no AS supl_No, org_name AS supl_Name,'0' as From_Obj
 FROM mmst001
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

/*
程序功能:生成指定id号的成品成本阶次码
程序编写:鐘運周
编写日期:2009-03-17
*/
CREATE PROCEDURE [Set_204_Level_No] 
@Rec_204 int   		/*要处理的BOM记录号*/
AS
declare @Level_no varchar(30)
declare @level int
declare @i int
declare @Rec_2042 int
declare @is_type_color bit
set nocount on
select @level=1
declare   @tWrite     table   (Rec_2042 int, level_no nvarchar(30))  --当前已处理完的级
declare   @tRead    table   (Rec_2042 int, level_no nvarchar(30))  --当前正处理的级
update mmst2042 set level_no='',grade=0 where rec_204=@rec_204        
while @level<8 --结构最多七级
begin
	select @i=0
	if @level=1 --第一级
		declare C_mmst2042  cursor for  select m.Rec_2042,0 as IS_TYPE_COLOR,'' as level_no   from   mmst2042 m  
			 where   m.rec_204=@rec_204 and m.parent_Rec_2042 is null
			order by m.Rec_2042
	else            --大于第一级
		declare C_mmst2042  cursor for   select m.Rec_2042,0 as IS_TYPE_COLOR,p.level_no from   mmst2042 as m
			 inner join @tRead as p on  m.rec_204=@rec_204 and    m.parent_Rec_2042=p.Rec_2042 
			order by m.Rec_2042
	open C_mmst2042
	fetch next from C_mmst2042 into  @Rec_2042,@IS_TYPE_COLOR,@level_no	
	while (@@fetch_status=0 )
	 begin	
	        --成品色则等于其上级	
	        if @is_type_color=1	 select  @Level_No =@level_no
	        else select  @i=@i+1,@Level_No =@level_no+  replicate('0',3-len(@i))+cast(@i as varchar(3))
	
	       --插入到临时表,以便下级关联
	       insert @tWrite (Rec_2042,level_no) values(@Rec_2042,@level_no)
	       fetch next from C_mmst2042 into @Rec_2042,@is_type_color,@level_no
	end
	close C_mmst2042
	deallocate C_mmst2042	

	--保存数据到临时表中,因不保存删除数据后Cursor会读不到数据,所以不能直接用@tWrite
	delete @tRead
	insert @tRead(Rec_2042,level_no)  select  Rec_2042,level_no  from @tWrite
	--本级没有数据则不再继续往下找
             if (@@ROWCOUNT = 0) break;

	--更新数据库
	update mmst2042 set level_no=t.level_no,grade=case when 0=1 then @level-1 else @level end  from  mmst2042 inner join @tWrite as t on mmst2042.rec_204=@rec_204 and mmst2042.Rec_2042=t.Rec_2042

	--更新每产品用量,非第一阶则等于父阶用量乘自身用量
	if @level<3  --等级为1或2时
		update mmst2042 set prod_mtr_amt=isnull(mmst2042.mtr_amt,0)+isnull(mmst2042.loss_amt,0) 
		where mmst2042.rec_204=@rec_204 and grade=1
	if @level>1 
		update mmst2042c set prod_mtr_amt=(isnull(mmst2042c.mtr_amt,0)+isnull(mmst2042c.loss_amt,0))*isnull(p.prod_mtr_amt,0) from mmst2042 as mmst2042c
		inner join mmst2042 on mmst2042c.Rec_2042= mmst2042.Rec_2042
		inner join mmst2042 as p on mmst2042.parent_Rec_2042=p.Rec_2042 and mmst2042c.rec_204=p.rec_204
		inner join @tWrite as t on  mmst2042c.rec_204=@rec_204 and mmst2042c.Rec_2042=t.Rec_2042 and mmst2042.grade>1
	if @level<3  --等级为1或2时
		update mmst2042 set prod_mtr_amt=isnull(mmst2042.mtr_amt,0)+isnull(mmst2042.loss_amt,0) from mmst2042 
		where mmst2042.rec_204=@rec_204 and grade=1
	if @level>1 
	             update mmst2042 set prod_mtr_amt=(isnull(mmst2042.mtr_amt,0)+isnull(mmst2042.loss_amt,0))*p.prod_mtr_amt from mmst2042
		inner join mmst2042 as p on mmst2042.parent_Rec_2042=p.Rec_2042 
		inner join @tWrite as t on  mmst2042.rec_204=@rec_204 and mmst2042.Rec_2042=t.Rec_2042  and mmst2042.grade>1

	delete @tWrite --删除中间过程表	
             select @level=@level+1
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

/*
程序功能:生成指定id号的用料结构阶次码
程序编写:鐘運周
编写日期:2008-05-12
*/
CREATE PROCEDURE [Set_50A_Level_No] 
@Rec_50A int   		/*要处理的BOM记录号*/
AS
declare @Level_no varchar(30)
declare @level int
declare @i int
declare @rec_50A1 int
set nocount on
select @level=1
declare   @tWrite     table   (rec_50A1 int, level_no nvarchar(30))  --当前已处理完的级
declare   @tRead    table   (rec_50A1 int, level_no nvarchar(30))  --当前正处理的级
update mmst50A1 set level_no='',grade=0 where rec_50A=@rec_50A        
while @level<8 --结构最多七级
begin
	select @i=0
	if @level=1 --第一级
		declare C_mmst50A1  cursor for  select m.rec_50A1,'' as level_no   from   mmst50A1 m  
			 where   m.rec_50A=@rec_50A and m.parent_rec_50A1 is null
			order by m.rec_50A1
	else            --大于第一级
		declare C_mmst50A1  cursor for   select m.rec_50A1,p.level_no from   mmst50A1 as m
			 inner join @tRead as p on  m.rec_50A=@rec_50A and    m.parent_rec_50A1=p.rec_50A1 
			order by m.rec_50A1
	open C_mmst50A1
	fetch next from C_mmst50A1 into  @rec_50A1,@level_no	
	while (@@fetch_status=0 )
	 begin	
	       select  @i=@i+1,@Level_No =@level_no+  replicate('0',3-len(@i))+cast(@i as varchar(3))
	
	       --插入到临时表,以便下级关联
	       insert @tWrite (rec_50A1,level_no) values(@rec_50A1,@level_no)
	       fetch next from C_mmst50A1 into @rec_50A1,@level_no
	end
	close C_mmst50A1
	deallocate C_mmst50A1	

	--保存数据到临时表中,因不保存删除数据后Cursor会读不到数据,所以不能直接用@tWrite
	delete @tRead
	insert @tRead(rec_50A1,level_no)  select  rec_50A1,level_no  from @tWrite
	--本级没有数据则不再继续往下找
             if (@@ROWCOUNT = 0) break;

	--更新数据库
	update mmst50A1 set level_no=t.level_no,grade=@level  from  mmst50A1 inner join @tWrite as t on mmst50A1.rec_50A=@rec_50A and mmst50A1.rec_50A1=t.rec_50A1

	delete @tWrite --删除中间过程表	
             select @level=@level+1
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

/*
程序功能:生成指定id号的样品用料BOM阶次码
程序编写:鐘運周
编写日期:2008-05-12
*/
CREATE PROCEDURE [Set_50B_Level_No] 
@Rec_50B int   		/*要处理的BOM记录号*/
AS
declare @Level_no varchar(30)
declare @level int
declare @i int
declare @rec_50B1 int
set nocount on
select @level=1
declare   @tWrite     table   (rec_50B1 int, level_no nvarchar(30))  --当前已处理完的级
declare   @tRead    table   (rec_50B1 int, level_no nvarchar(30))  --当前正处理的级
update mmst50B1 set level_no='',grade=0 where rec_50B=@rec_50B        
while @level<8 --结构最多七级
begin
	select @i=0
	--连接物料表的原因是暂时备用
	if @level=1 --第一级
		declare C_mmst50B1  cursor for  select m.rec_50B1,'' as level_no   from   mmst50B1 m  
			left join mmst611 as m6 on m.rec_611=m6.rec_611 
			 where   m.rec_50B=@rec_50B and m.parent_rec_50B1 is null
			order by m.rec_50b1
	else            --大于第一级
		declare C_mmst50B1  cursor for   select m.rec_50B1,p.level_no from   mmst50B1 as m
			 inner join @tRead as p on  m.rec_50B=@rec_50B and    m.parent_rec_50B1=p.rec_50B1 
			left join mmst611 as m6 on m.rec_611=m6.rec_611 
			order by m.rec_50b1
	open C_mmst50B1
	fetch next from C_mmst50B1 into  @rec_50B1,@level_no	
	while (@@fetch_status=0 )
	 begin	
	       select  @i=@i+1,@Level_No =@level_no+  replicate('0',3-len(@i))+cast(@i as varchar(3))
	
	       --插入到临时表,以便下级关联
	       insert @tWrite (rec_50B1,level_no) values(@rec_50B1,@level_no)
	       fetch next from C_mmst50B1 into @rec_50B1,@level_no
	end
	close C_mmst50B1
	deallocate C_mmst50B1	

	--保存数据到临时表中,因不保存删除数据后Cursor会读不到数据,所以不能直接用@tWrite
	delete @tRead
	insert @tRead(rec_50B1,level_no)  select  rec_50B1,level_no  from @tWrite
	--本级没有数据则不再继续往下找
             if (@@ROWCOUNT = 0) break;

	--更新数据库
	update mmst50B1 set level_no=t.level_no,grade=@level  from  mmst50B1 inner join @tWrite as t on mmst50B1.rec_50B=@rec_50B and mmst50B1.rec_50B1=t.rec_50B1

	delete @tWrite --删除中间过程表	
             select @level=@level+1
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

/*
程序功能:生成指定id号的成品BOM阶次码
程序编写:鐘運周
编写日期:2008-05-09
*/
CREATE PROCEDURE [Set_Bom_Level_No] 
@Rec_501 int   		/*要处理的BOM记录号*/
AS
declare @Level_no varchar(30)
declare @level int
declare @i int
declare @rec_501m int
declare @is_type_color bit
set nocount on
select @level=1
declare   @tWrite     table   (rec_501m int, level_no nvarchar(30))  --当前已处理完的级
declare   @tRead    table   (rec_501m int, level_no nvarchar(30))  --当前正处理的级
update mmst501m set level_no='',grade=0 where rec_501=@rec_501        
while @level<8 --结构最多七级
begin
	select @i=0
	if @level=1 --第一级
		declare C_mmst501m  cursor for  select m.rec_501m,m.IS_TYPE_COLOR,'' as level_no   from   mmst501m m  
			 where   m.rec_501=@rec_501 and m.parent_rec_501m is null
			order by m.rec_501m
	else            --大于第一级
		declare C_mmst501m  cursor for   select m.rec_501m,m.IS_TYPE_COLOR,p.level_no from   mmst501m as m
			 inner join @tRead as p on  m.rec_501=@rec_501 and    m.parent_rec_501m=p.rec_501m 
			order by m.rec_501m
	open C_mmst501m
	fetch next from C_mmst501m into  @rec_501m,@IS_TYPE_COLOR,@level_no	
	while (@@fetch_status=0 )
	 begin	
	        --成品色则等于其上级	
	        if @is_type_color=1	 select  @Level_No =@level_no
	        else select  @i=@i+1,@Level_No =@level_no+  replicate('0',3-len(@i))+cast(@i as varchar(3))
	
	       --插入到临时表,以便下级关联
	       insert @tWrite (rec_501m,level_no) values(@rec_501m,@level_no)
	       fetch next from C_mmst501m into @rec_501m,@is_type_color,@level_no
	end
	close C_mmst501m
	deallocate C_mmst501m	

	--保存数据到临时表中,因不保存删除数据后Cursor会读不到数据,所以不能直接用@tWrite
	delete @tRead
	insert @tRead(rec_501m,level_no)  select  rec_501m,level_no  from @tWrite
	--本级没有数据则不再继续往下找
             if (@@ROWCOUNT = 0) break;

	--更新数据库
	update mmst501m set level_no=t.level_no,grade=case when mmst501m.IS_TYPE_COLOR=1 then @level-1 else @level end  from  mmst501m inner join @tWrite as t on mmst501m.rec_501=@rec_501 and mmst501m.rec_501m=t.rec_501m

	--更新每产品用量,非第一阶则等于父阶用量乘自身用量
	if @level<3  --等级为1或2时
		update mmst501mc set prod_mtr_amt=isnull(mmst501mc.mtr_amt,0)+isnull(mmst501mc.loss_amt,0) from mmst501mc 
		inner join mmst501m on mmst501mc.rec_501m=mmst501m.rec_501m
		where mmst501mc.rec_501=@rec_501 and grade=1
	if @level>1 
		update mmst501mc set prod_mtr_amt=(isnull(mmst501mc.mtr_amt,0)+isnull(mmst501mc.loss_amt,0))*isnull(p.prod_mtr_amt,0) from mmst501mc
		inner join mmst501m on mmst501mc.rec_501m= mmst501m.rec_501m
		inner join mmst501mc as p on mmst501m.parent_rec_501m=p.rec_501m and mmst501mc.color_rec_501=p.color_rec_501
		inner join @tWrite as t on  mmst501mc.rec_501=@rec_501 and mmst501mc.rec_501m=t.rec_501m and mmst501m.grade>1
	if @level<3  --等级为1或2时
		update mmst501m set prod_mtr_amt=isnull(mmst501m.mtr_amt,0)+isnull(mmst501m.loss_amt,0) from mmst501m 
		where mmst501m.rec_501=@rec_501 and grade=1
	if @level>1 
	             update mmst501m set prod_mtr_amt=(isnull(mmst501m.mtr_amt,0)+isnull(mmst501m.loss_amt,0))*p.prod_mtr_amt from mmst501m
		inner join mmst501m as p on mmst501m.parent_rec_501m=p.rec_501m 
		inner join @tWrite as t on  mmst501m.rec_501=@rec_501 and mmst501m.rec_501m=t.rec_501m  and mmst501m.grade>1

	delete @tWrite --删除中间过程表	
             select @level=@level+1
end
set nocount off
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

