--V1.7.4所作升级
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>='2007-07-18'
    Return
end

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FWFeeB]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
  CREATE TABLE [dbo].[FWFeeB] (
  [FormNo] [char] (14) NOT NULL ,
  [FeeCode] [char] (6) NOT NULL ,
  [FeeName] [char] (20) NULL ,
  [Total] [money] NULL ,
  [ProMemo] [char] (255) NULL ,
  [TimeMark] [int] IDENTITY (1, 1) NOT NULL 
  ) ON [PRIMARY]
  ALTER TABLE [dbo].[FWFEEB] WITH NOCHECK ADD 
   PRIMARY KEY  CLUSTERED 
  (
    [FormNo],
    [FeeCode]
  )  ON [PRIMARY] 
  ALTER TABLE [dbo].[FWFEEB] WITH NOCHECK ADD 
  CONSTRAINT [DF_FWFEEB_Total] DEFAULT (0) FOR [Total]
end
 

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FWFeeH]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
  CREATE TABLE [dbo].[FWFeeH] (
  [FormNo] [char] (14) NOT NULL ,
  [FormDate] [char] (10) NULL ,
  [WriteDate] [char] (10) 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 ,
  [CustCode] [char] (10) NULL ,
  [FKType] [char] (1) NULL ,
  [PayDate] [char] (10) NULL ,
  [Total] [money] NULL ,
  [PayTotal] [money] null,
  [DscTotal] [money] null,
  [ProMemo] [varchar] (255) NULL ,
  [Tag] [char] (1) NULL ,
  [PrnTimes] [int] NULL ,
  [RZUser] [char] (6) NULL ,
  [RZUserName] [char] (10) NULL ,
  [timemark] [timestamp] NULL
  
  ) ON [PRIMARY]
  
  ALTER TABLE [dbo].[FWFeeH] WITH NOCHECK ADD 
   PRIMARY KEY  CLUSTERED 
  (
    [FormNo]
  )  ON [PRIMARY] 
  ALTER TABLE [dbo].[FWFeeH] WITH NOCHECK ADD 
  CONSTRAINT [DF_FWFeeH_Total] DEFAULT (0) FOR [Total],
  CONSTRAINT [DF_FWFeeH_PayTotal] DEFAULT (0) FOR [PayTotal],
  CONSTRAINT [DF_FWFeeH_DscTotal] DEFAULT (0) FOR [DscTotal]
end
 

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tWFeeSet]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
  CREATE TABLE [dbo].[tWFeeSet] (
  [FeeCode] [char] (6) NOT NULL ,
  [FeeName] [char] (20) NULL ,
  [DefMoney] [money] NULL ,
  [FeeMemo] [varchar] (50) NULL 
  ) ON [PRIMARY]
  ALTER TABLE [dbo].[tWFeeSet] WITH NOCHECK ADD 
  CONSTRAINT [PK_tWFeeSet] PRIMARY KEY  CLUSTERED 
  (
    [FeeCode]
  )  ON [PRIMARY] 
 

  ALTER TABLE [dbo].[tWFeeSet] WITH NOCHECK ADD 
  CONSTRAINT [DF_tWFeeSet_DefMoney] DEFAULT (0) FOR [DefMoney]
end

if not Exists(Select * from SysColumns where Id=Object_ID('FWJSH') and name='FeeTotal' )
begin
  alter table FWJSH add FeeTotal money null   
  
  ALTER TABLE [dbo].[FWJSH] WITH NOCHECK ADD 	
	CONSTRAINT [DF_FWJSH_FeeTotal] DEFAULT (0) FOR [FeeTotal]
	Exec ('update FWJSH set FeeTotal=0')	
end

Declare @i int
Select @i=IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0501'
insert into tSysFunc 
Values('K0507','客户费用编码','0501',1,1,1,1,1,1,1,1,0,0,1,'tfrmWFeeCode',0,@i,'供应商结算/K0507')

Select @i=IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0501'
insert into tSysFunc 
Values('K0508','客户费用单','0501',1,1,1,1,1,1,1,1,1,1,1,'tfrmProWFee',0,@i,'供应商结算/K0508')

Select @i=IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0502'
insert into tSysFunc 
Values('K0509','客户费用单查询','0502',1,0,0,0,1,1,1,1,0,0,1,'tfrmQProWFee',0,@i,'供应商结算/K0509')

--预收款
if not Exists(Select * from tSysFunc where FuncCode='K0608' and iNodeCode='0501')
begin
  Update tSysFunc set iNodeCode='0501'
  ,SerialNo=(Select IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0501') 
  where FuncCode='K0608'
end
--结算单
if not Exists(Select * from tSysFunc where FuncCode='K0616' and iNodeCode='0501')
begin
  Update tSysFunc set iNodeCode='0501'
  ,SerialNo=(Select IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0501') 
  where FuncCode='K0616'
end
--结算单查询
if not Exists(Select * from tSysFunc where FuncCode='K0612' and iNodeCode='0502')
begin
  Update tSysFunc set iNodeCode='0502'
  ,SerialNo=(Select IsNull(Max(SerialNo),0)+1 from tSysFunc where iNodeCode='0502') 
  where FuncCode='K0612'
end

update tNodeTree Set tNodeName='结算管理' where tNodeCode='05'