--V1.3版本 所作的升级
if exists( Select OptValue from tSysOpt where OptName='DBEdition')
begin
  Declare @DBVer varchar(10)
  Select @DBVer=OptValue from tSysOpt where OptName='DBEdition'
  Set @DBVer=Substring(@DBVer,1,4)+'-'+Substring(@DBVer,6,2)+'-'+Substring(@DBVer,9,2)
  if @DBVer>='2006-11-20'
    Return
end
--2006-11-08 添加业务员提成率字段
if not Exists(Select * from SysColumns where Id=Object_ID('tUser') and name='TiCheng' )
  alter table tUser add TiCheng money null default 0
--2006-11-14 添加批发订货仓库字段  
if not Exists(Select * from SysColumns where Id=Object_ID('FWDHH') and name='StoreCode' )
  alter table FWDHH add StoreCode Char(2) null  
--2006-11-16 增加订货历史数据表
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FWDHB_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[FWDHB_History] (
	[FormNo] [char] (14) NOT NULL ,
	[ProdCode] [char] (18) NOT NULL ,
	[ProdName] [char] (40) NULL ,
	[BarCode] [char] (18) NOT NULL ,
	[DepCode] [char] (12) NULL ,
	[Spec] [char] (20) NULL ,
	[ProdAdr] [char] (10) NULL ,
	[PUnit] [char] (20) NULL ,
	[PUnitAmt] [money] NULL ,
	[RUnit] [char] (20) NULL ,
	[CountP] [money] NULL ,
	[Unit] [char] (20) NULL ,
	[CountM] [money] NULL ,
	[CountN] [money] NULL ,
	[OPrice] [decimal](19, 10) NULL ,
	[OutOPrice] [decimal](19, 10) NULL ,
	[Price] [money] NULL ,
	[Cost] [money] NULL ,
	[OutCost] [money] NULL ,
	[Total] [money] NULL ,
	[ProPrice] [money] NOT NULL ,
	[ProTotal] [money] NULL ,
	[ProMemo] [char] (255) NULL ,
	[timeMark] [int] IDENTITY (1, 1) NOT NULL ,
	[WBoxPrice] [money] NULL ,
	[DscTotal] [money] NULL ,
	[ProdType] [char] (1) NULL ,
	[IsPresent] [char] (10) NOT NULL ,
	[LinkCode] [char] (30) NULL ,
	[STax] [tinyint] NULL 
) ON [PRIMARY]

ALTER TABLE [dbo].[FWDHB_History] WITH NOCHECK ADD 
	CONSTRAINT [DF_FWDHB_History_PUnitAmt] DEFAULT (0) FOR [PUnitAmt],
	CONSTRAINT [DF_FWDHB_History_CountP] DEFAULT (0) FOR [CountP],
	CONSTRAINT [DF_FWDHB_History_CountM] DEFAULT (0) FOR [CountM],
	CONSTRAINT [DF_FWDHB_History_CountN] DEFAULT (0) FOR [CountN],
	CONSTRAINT [DF_FWDHB_History_OPrice] DEFAULT (0) FOR [OPrice],
	CONSTRAINT [DF_FWDHB_History_OutOPrice] DEFAULT (0) FOR [OutOPrice],
	CONSTRAINT [DF_FWDHB_History_Price] DEFAULT (0) FOR [Price],
	CONSTRAINT [DF_FWDHB_History_Cost] DEFAULT (0) FOR [Cost],
	CONSTRAINT [DF_FWDHB_History_OutCost] DEFAULT (0) FOR [OutCost],
	CONSTRAINT [DF_FWDHB_History_Total] DEFAULT (0) FOR [Total],
	CONSTRAINT [DF_FWDHB_History_ProPrice] DEFAULT (0) FOR [ProPrice],
	CONSTRAINT [DF_FWDHB_History_ProTotal] DEFAULT (0) FOR [ProTotal],
	CONSTRAINT [DF_FWDHB_History_DscTotal] DEFAULT (0) FOR [DscTotal],
	CONSTRAINT [DF_FWDHB_History_IsPresent] DEFAULT ('0') FOR [IsPresent],
	CONSTRAINT [PK_FWDHB_History] PRIMARY KEY  CLUSTERED 
	(
		[FormNo],
		[ProdCode],
		[BarCode],
		[IsPresent]
	)  ON [PRIMARY] 

end

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FWDHH_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
CREATE TABLE [dbo].[FWDHH_History] (
	[FormNo] [char] (14) NOT NULL ,
	[FormDate] [char] (10) NULL ,
	[ReferNo] [char] (14) NULL ,
	[WriteDate] [char] (10) NULL ,
	[OverDate] [char] (10) NULL ,
	[YWCode] [char] (6) NULL ,
	[FormMaker] [char] (10) NULL ,
	[UserCode] [char] (6) NULL ,
	[UserName] [char] (10) NULL ,
	[CheckCode] [char] (6) NULL ,
	[CheckName] [char] (10) NULL ,
	[CheckType] [char] (1) NULL ,
	[DepCode] [char] (12) NULL ,
	[CustCode] [char] (10) NULL ,
	[PayMode] [char] (1) NULL ,
	[PayDate] [char] (10) NULL ,
	[CountN] [money] NULL ,
	[ProTotal] [money] NULL ,
	[Cost] [money] NULL ,
	[OutCost] [money] NULL ,
	[Total] [money] NULL ,
	[ProMemo] [varchar] (255) NULL ,
	[Tag] [char] (1) NULL ,
	[SchemeCode] [char] (2) NULL ,
	[PrnTimes] [int] NULL ,
	[RZUser] [char] (6) NULL ,
	[RZUserName] [char] (10) NULL ,
	[timemark] [timestamp] NULL ,
	[DscTotal] [money] NULL ,
	[Subscription] [money] NULL ,
	[StationName] [char] (30) NULL ,
	[VldDate] [char] (10) NULL ,
	[StoreCode] [char] (2) NULL 
) ON [PRIMARY]


ALTER TABLE [dbo].[FWDHH_History] WITH NOCHECK ADD 
	CONSTRAINT [DF_FWDHH_History_CheckType] DEFAULT (0) FOR [CheckType],
	CONSTRAINT [DF_FWDHH_History_PayMode] DEFAULT (0) FOR [PayMode],
	CONSTRAINT [DF_FWDHH_History_CountN] DEFAULT (0) FOR [CountN],
	CONSTRAINT [DF_FWDHH_History_ProTotal] DEFAULT (0) FOR [ProTotal],
	CONSTRAINT [DF_FWDHH_History_Cost] DEFAULT (0) FOR [Cost],
	CONSTRAINT [DF_FWDHH_History_OutCost] DEFAULT (0) FOR [OutCost],
	CONSTRAINT [DF_FWDHH_History_Total] DEFAULT (0) FOR [Total],
	CONSTRAINT [DF_FWDHH_History_PrnTimes] DEFAULT (0) FOR [PrnTimes],
	CONSTRAINT [DF_FWDHH_History_DscTotal] DEFAULT (0) FOR [DscTotal],
	CONSTRAINT [DF_FWDHH_History_StationName] DEFAULT ('') FOR [StationName],
	CONSTRAINT [PK_FWDHH_History] PRIMARY KEY  CLUSTERED 
	(
		[FormNo]
	)  ON [PRIMARY] 

end
