--售飯與靈活消費的公用表結構
IF OBJECT_ID('dbo.XF_SysParam') IS NULL
CREATE TABLE dbo.XF_SysParam (
       Param_ID             int IDENTITY,
       Param_Code           varchar(20) NOT NULL,
       Param_Name           varchar(40) NOT NULL,
       Param_Value          varchar(100) NOT NULL,
       PRIMARY KEY (Param_ID ASC)
)
go

IF OBJECT_ID('dbo.XF_Collect') IS NULL
CREATE TABLE dbo.XF_Collect (
       ID_KEY               int IDENTITY,
       IP_Addr              varchar(15) NULL,
       Com_Port             int NULL,
       Chg_Status           tinyint NULL,
       PRIMARY KEY (ID_KEY ASC)
)
go

IF OBJECT_ID('dbo.XF_Section') IS NULL
CREATE TABLE dbo.XF_Section (
       Sect_No              varchar(4) NOT NULL,
       Sect_Name            varchar(20) NOT NULL,
       Remark               varchar(20) NULL,
       PRIMARY KEY (Sect_No ASC)
)
go

IF OBJECT_ID('dbo.XF_Area') IS NULL
CREATE TABLE dbo.XF_Area (
       Area_No              varchar(12) NOT NULL,
       Sect_No              varchar(4)  NOT NULL,
       Area_Name            varchar(30) NOT NULL,
       Remark               varchar(20) NULL,
       PRIMARY KEY (Area_No ASC), 
       FOREIGN KEY (Sect_No)
                             REFERENCES dbo.XF_Section  (Sect_No)
                             ON DELETE NO ACTION
                             ON UPDATE NO ACTION
)
go

IF OBJECT_ID('dbo.XF_KeyType') IS NULL
CREATE TABLE XF_KeyType (
       Key_Type             int NOT NULL,
       Key_Value            int NOT NULL,
       Key_TypeName         varchar(20) NOT NULL,
       Key_Fund             money NOT NULL DEFAULT 0.00,
       Remark               varchar(20) NULL,
       PRIMARY KEY (Key_Type ASC, Key_Value ASC)
)
go

IF OBJECT_ID('dbo.XF_WareInfo') IS NULL
CREATE TABLE dbo.XF_WareInfo (
       Ware_ID              int NOT NULL,
       System_No            varchar(10) NOT NULL,
       Ware_No              varchar(20) NOT NULL,
       Ware_Name            varchar(50) NOT NULL,
       Ware_Price           money NOT NULL,
       Ware_Discount        tinyint NOT NULL DEFAULT 100,
       Ware_Unit            varchar(8) NULL,
       Remark               varchar(30) NULL,
       PRIMARY KEY (Ware_ID ASC, System_No ASC)
)
go

IF OBJECT_ID('XF_ConsumeCleanup') IS NULL
CREATE TABLE [dbo].[XF_ConsumeCleanup] (
	[ID_KEY] [bigint] IDENTITY (1, 1) NOT NULL ,
	[Person_ID] [int] NOT NULL ,
	[System_No] [varchar] (10) NOT NULL ,
	[Consume_Mode] [int] NOT NULL ,
	[Consume_Time] [datetime] NOT NULL ,
	[Before_Fund] [money] NULL ,
	[Consume_Fund] [money] NOT NULL ,
	[Consume_Copy] [int] NULL ,
	[Consume_TimeLen] [float] NULL ,
	[Consume_Capacity] [float] NULL ,
	[Repast_No] [varchar] (3) NULL ,
	[Ware_ID] [int] NULL ,
	[MOC_No] [varchar] (6) NOT NULL ,
	[COM_No] [varchar] (6) NULL ,
	[Card_Balance] [money] NOT NULL ,
	[DB_Balance] [money] NULL ,
	[Card_SmallAccount] [money] NULL ,
	[Data_Type] [tinyint] NOT NULL ,
	[Remark] [varchar] (20) NULL ,
	[SalesPerson] [varchar] (20) NULL ,
	[Download_Time] [datetime] NULL,
    PRIMARY KEY (ID_KEY ASC) 
)
GO

IF OBJECT_ID('XF_CollectLog') IS NULL
 CREATE TABLE XF_CollectLog(Id_Key int IDENTITY(1,1),Log_DateTime DateTime,Log_Msg varchar(255),PRIMARY KEY (ID_KEY ASC))  
GO

--售飯消費的餐別表
IF OBJECT_ID('dbo.SF_Repast') IS NULL
CREATE TABLE dbo.SF_Repast (
       Repast_No            varchar(3) NOT NULL,
       Repast_Name          varchar(20) NOT NULL,
       Bgn_Time             varchar(5) NOT NULL,
       End_Time             varchar(5) NOT NULL,
       Price                money NOT NULL DEFAULT 0,
       Remark               varchar(20) NULL,
       PRIMARY KEY (Repast_No ASC)
)
go

