USE [master] 
GO 
IF EXISTS(SELECT 1 FROM sysdatabases WHERE NAME=N'kuedTempkued') 
BEGIN 
DROP DATABASE kuedTempkued  
END 
GO 
CREATE DATABASE kuedTempkued 
ON 
PRIMARY 
( 
NAME='kuedTempkued', 
FILENAME='C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\kuedTempkued.dbf', 
SIZE=5MB, 
MaxSize=60MB, 
FileGrowth=1MB 
) 
LOG ON 
( 
NAME='kuedTempkuedLog', 
FileName='C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\kuedTempkued.ldf', 
Size=2MB, 
MaxSize=30MB, 
FileGrowth=1MB 
) 
GO 
USE [kuedTempkued] 
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户预付]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户预付](
	[客户编号] [char](50) NULL,
	[预付金额] [numeric](18, 2) NULL,
	[日期] [datetime] NULL,
	[收款人] [char](10) NULL,
	[备注] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[发货状态]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[发货状态](
	[销售单编号] [char](20) NOT NULL,
	[配货人] [char](10) NULL,
	[配货时间] [datetime] NULL,
	[发货状态] [char](4) NULL,
	[物流单号] [char](20) NULL,
	[发货人] [char](10) NULL,
	[发货时间] [datetime] NULL,
 CONSTRAINT [PK_发货状态] PRIMARY KEY CLUSTERED 
(
	[销售单编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[付款流水]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[付款流水](
	[付款单号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[付款时间] [datetime] NULL,
	[付款方式] [nchar](10) NULL,
	[付款金额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
	[核对人] [nchar](10) NULL,
	[核对时间] [datetime] NULL,
 CONSTRAINT [PK_付款流水] PRIMARY KEY CLUSTERED 
(
	[付款单号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[用户仓库]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[用户仓库](
	[用户编号] [char](6) NULL,
	[仓库号] [char](6) NULL,
	[主管] [bit] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户跟踪表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户跟踪表](
	[编号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[地址] [nchar](10) NULL,
	[事项] [char](4) NULL,
	[备注] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[预售单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[预售单](
	[编号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[预售日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[保管员] [char](10) NULL,
	[总金额] [decimal](28, 6) NULL,
	[实收金额] [decimal](28, 6) NULL,
	[订单号] [char](20) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[状态] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[仓库] [nchar](10) NULL,
	[总利润] [decimal](28, 6) NULL,
	[总重量] [decimal](28, 6) NULL,
	[金额核对] [char](4) NULL,
	[核对人] [char](10) NULL,
	[日期] [datetime] NULL,
	[上级日期] [datetime] NULL,
 CONSTRAINT [PK__预售单__5C8CB268] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[分类表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[分类表](
	[序号] [nchar](10) NULL,
	[类别] [nchar](10) NULL,
	[时间] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[商品分类]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[商品分类](
	[分类序号] [nchar](10) NULL,
	[资料号] [nchar](14) NULL,
	[时间] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[系统设置]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[系统设置](
	[序号] [nchar](10) NOT NULL,
	[公司名] [nchar](10) NULL,
	[网址] [nchar](10) NULL,
	[远程使用] [bit] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[模板分配]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[模板分配](
	[ID] [int] NULL,
	[模板ID] [int] NULL,
	[用户ID] [nchar](10) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[打印模板]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[打印模板](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[数据] [image] NULL,
	[内部名] [nchar](50) NULL,
	[名称] [nchar](10) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[供货商清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[供货商清单](
	[供货商号] [char](50) NOT NULL,
	[拼音编码] [char](40) NULL,
	[简称] [varchar](80) NULL,
	[名称] [varchar](80) NULL,
	[地址] [varchar](80) NULL,
	[邮编] [char](6) NULL,
	[区号] [char](6) NULL,
	[地区] [varchar](12) NULL,
	[类型] [char](10) NULL,
	[电话] [varchar](20) NULL,
	[传真] [varchar](20) NULL,
	[手机] [varchar](20) NULL,
	[开户行] [varchar](40) NULL,
	[开户行邮编] [char](6) NULL,
	[银行帐号] [varchar](20) NULL,
	[税号] [varchar](20) NULL,
	[库房地址] [varchar](40) NULL,
	[库房电话] [varchar](20) NULL,
	[业务员] [char](10) NULL,
	[业务部门] [varchar](20) NULL,
	[QQ] [nchar](10) NULL,
	[价格等级] [nchar](10) NULL,
	[供货商来源] [nchar](10) NULL,
	[联系人] [nchar](10) NULL,
 CONSTRAINT [PK__供货商清单__3572E547] PRIMARY KEY CLUSTERED 
(
	[供货商号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[充值明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[充值明细](
	[序号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[充值时间] [datetime] NULL,
	[付款方式] [nchar](10) NULL,
	[付款金额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
	[审核] [char](4) NULL,
	[核对人] [nchar](10) NULL,
	[核对时间] [datetime] NULL,
	[交易单号] [char](20) NULL,
	[备注] [nvarchar](50) NULL,
	[付款日期] [datetime] NULL,
 CONSTRAINT [PK_充值明细] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[图片表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[图片表](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[资料号] [char](14) NULL,
	[小图] [image] NULL,
	[大图] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[欠款清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[欠款清单](
	[销售单号] [char](20) NULL,
	[客户编号] [char](50) NULL,
	[欠款时间] [datetime] NULL,
	[制单人] [nchar](10) NULL,
	[欠款金额] [numeric](18, 2) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户账户]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户账户](
	[客户编号] [char](50) NOT NULL,
	[余额] [numeric](18, 2) NULL,
	[最后变动时间] [datetime] NULL,
	[总付款] [numeric](18, 2) NULL,
	[进货总额] [numeric](18, 2) NULL,
	[退货总额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
 CONSTRAINT [PK_客户账户] PRIMARY KEY CLUSTERED 
(
	[客户编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[仓库清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[仓库清单](
	[仓库号] [char](14) NOT NULL,
	[仓库名] [varchar](30) NULL,
	[类别] [char](16) NULL,
	[备注] [varchar](40) NULL,
PRIMARY KEY CLUSTERED 
(
	[仓库号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[进价调整单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[进价调整单](
	[内部编号] [int] NOT NULL,
	[编号] [char](14) NOT NULL,
	[进货数量] [decimal](28, 6) NULL,
	[原进价] [decimal](28, 6) NOT NULL,
	[新进价] [decimal](28, 6) NOT NULL,
	[调整日期] [int] NOT NULL,
	[制单人] [char](10) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[内部编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[销售单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[销售单](
	[编号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[销售日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[保管员] [char](10) NULL,
	[总金额] [decimal](28, 6) NULL,
	[实收金额] [decimal](28, 6) NULL,
	[订单号] [char](20) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[仓库] [nchar](10) NULL,
	[总利润] [decimal](28, 6) NULL,
	[总重量] [decimal](28, 6) NULL,
	[金额核对] [char](4) NULL,
	[核对人] [char](10) NULL,
	[日期] [datetime] NULL,
	[上级日期] [datetime] NULL,
 CONSTRAINT [PK__销售单__5C8CB268] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[用户清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[用户清单](
	[用户编号] [char](20) NOT NULL,
	[部门] [char](20) NULL,
	[姓名] [char](10) NULL,
	[性别] [char](2) NULL,
	[password] [char](40) NULL,
	[密码] [char](40) NULL,
	[经营权] [char](61) NULL,
	[管理权] [char](61) NULL,
	[价格权] [char](61) NULL,
	[手机] [char](15) NULL,
	[QQ] [char](10) NULL,
	[地址] [char](50) NULL,
	[身份证] [char](20) NULL,
	[邮编] [char](10) NULL,
	[简称] [nchar](10) NULL,
	[拼音编码] [nchar](10) NULL,
	[等级] [nchar](10) NULL,
	[电话] [nchar](15) NULL,
	[用户来源] [nchar](10) NULL,
	[地区] [nchar](10) NULL,
	[公司] [nchar](30) NULL,
	[上浮] [float] NULL,
	[下浮] [float] NULL,
 CONSTRAINT [PK_用户清单] PRIMARY KEY CLUSTERED 
(
	[用户编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[赠卡]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[赠卡](
	[卡号] [int] NOT NULL,
	[密码] [int] NOT NULL,
	[面值] [int] NULL,
	[已兑] [bit] NULL,
	[开卡时间] [datetime] NOT NULL CONSTRAINT [DF_赠卡_开卡时间]  DEFAULT (getdate()),
	[兑换时间] [datetime] NULL,
	[有效期] [datetime] NULL,
	[会员] [nchar](20) NULL,
	[已打] [bit] NULL,
	[用户] [nchar](20) NULL,
	[id] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [pk_赠卡] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY],
 CONSTRAINT [IX_赠卡] UNIQUE NONCLUSTERED 
(
	[卡号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[品牌表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[品牌表](
	[序号] [nchar](10) NOT NULL,
	[品牌] [nchar](40) NULL,
 CONSTRAINT [PK_品牌表] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[商品清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[商品清单](
	[货号] [char](14) NOT NULL,
	[资料号] [char](14) NULL,
	[颜色] [char](10) NULL,
	[规格] [char](10) NULL,
	[条码] [char](14) NULL,
	[类别] [char](20) NULL,
	[重量] [numeric](18, 0) NULL,
	[日期] [datetime] NULL,
	[颜色配比] [int] NULL,
	[规格配比] [int] NULL,
	[进货价] [decimal](28, 6) NULL CONSTRAINT [DF_商品清单_进货价]  DEFAULT ((0)),
	[销售价1] [decimal](28, 6) NULL CONSTRAINT [DF_商品清单_销售价1]  DEFAULT ((0)),
	[销售价2] [decimal](28, 6) NULL CONSTRAINT [DF_商品清单_销售价2]  DEFAULT ((0)),
	[最低售价] [decimal](28, 6) NULL CONSTRAINT [DF_商品清单_最低售价]  DEFAULT ((0)),
	[品牌] [varchar](20) NULL,
 CONSTRAINT [PK__商品清单__2FBA0BF1] PRIMARY KEY CLUSTERED 
(
	[货号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[商品基本资料]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[商品基本资料](
	[资料号] [char](14) NOT NULL,
	[拼音编码] [char](40) NULL,
	[单位] [char](6) NULL,
	[品牌] [varchar](20) NULL,
	[颜色] [int] NULL,
	[规格] [int] NULL,
	[品名] [varchar](80) NULL,
	[进货价] [decimal](28, 6) NULL,
	[销售价1] [decimal](28, 6) NULL,
	[销售价2] [decimal](28, 6) NULL,
	[最低售价] [decimal](28, 6) NULL,
	[日期] [datetime] NULL,
	[类别] [nchar](10) NULL,
 CONSTRAINT [PK_商品基本资料] PRIMARY KEY CLUSTERED 
(
	[资料号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[调拨单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[调拨单](
	[编号] [char](20) NOT NULL,
	[源仓库] [varchar](20) NULL,
	[目的仓库] [varchar](20) NULL,
	[调拨日期] [datetime] NULL,
	[制单人] [char](10) NULL,
	[业务员] [char](10) NULL,
	[总金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[选中] [char](4) NULL,
 CONSTRAINT [PK__调拨单__67FE6514] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户等级表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户等级表](
	[客户编号] [char](50) NULL,
	[等级] [char](10) NULL,
	[积分] [float] NULL,
	[次数] [int] NULL,
	[三个月积分] [float] NULL,
	[三个月次数] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[支出单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[支出单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[支出单号] [char](20) NULL,
	[选择] [bit] NULL,
	[商品名称] [char](50) NULL,
	[采购数量] [decimal](28, 6) NULL,
	[采购价] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[购退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[类型号] [char](10) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_支出单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__支出单明细__5E74FADA] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[等级表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[等级表](
	[等级] [char](10) NULL,
	[积分] [float] NULL,
	[次数] [int] NULL,
	[三个月积分] [float] NULL,
	[三个月次数] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[用户名片]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[用户名片](
	[用户编号] [char](20) NOT NULL,
	[序号] [nchar](10) NULL,
	[职务] [char](20) NOT NULL,
	[姓名] [char](10) NULL,
	[手机] [char](15) NULL,
	[QQ] [char](10) NULL,
	[微信] [char](15) NULL,
	[地址] [char](50) NULL,
	[邮箱] [char](30) NULL,
	[邮编] [char](10) NULL,
	[电话] [nchar](15) NULL,
	[网站] [nchar](30) NULL,
	[公司] [nchar](30) NULL,
	[收款人] [char](20) NULL,
	[开户行] [char](30) NULL,
	[账户] [char](40) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[通知表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[通知表](
	[序号] [int] IDENTITY(1,1) NOT NULL,
	[通知] [text] NOT NULL,
	[日期] [datetime] NOT NULL CONSTRAINT [DF_通知表_日期]  DEFAULT (getdate()),
	[用户编号] [char](10) NULL,
 CONSTRAINT [PK_通知表] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[支出单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[支出单](
	[编号] [char](20) NOT NULL,
	[收款方] [char](50) NULL,
	[支出日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[保管员] [char](10) NULL,
	[总金额] [numeric](18, 2) NULL,
	[实付金额] [numeric](18, 2) NULL,
	[审核] [char](4) NULL,
	[购退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[仓库] [nchar](10) NULL,
	[金额核对] [char](4) NULL,
	[核对人] [char](10) NULL,
 CONSTRAINT [PK__支出单__5C8CB168] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[财务月报]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[财务月报](
	[日期] [datetime] NOT NULL,
	[月份] [int] NOT NULL,
	[类型号] [char](10) NULL,
	[金额] [decimal](28, 6) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[校验单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[校验单明细](
	[校验单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[数量] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[编号] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK__校验单明细__4D4A6ED8] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[收支类型]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[收支类型](
	[类型号] [nchar](10) NOT NULL,
	[名称] [nchar](40) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[货架转移]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[货架转移](
	[资料号] [nchar](10) NULL,
	[货架号] [nchar](10) NULL,
	[货号] [nchar](10) NULL,
	[日期] [datetime] NULL,
	[有效] [bit] NULL,
	[仓库] [nchar](10) NULL,
	[制单人] [nchar](10) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[快递单参数]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[快递单参数](
	[快递单名称] [nchar](10) NULL,
	[top1] [int] NULL,
	[left1] [int] NULL,
	[top2] [int] NULL,
	[left2] [int] NULL,
	[top3] [int] NULL,
	[left3] [int] NULL,
	[top4] [int] NULL,
	[left4] [int] NULL,
	[top5] [int] NULL,
	[left5] [int] NULL,
	[top6] [int] NULL,
	[left6] [int] NULL,
	[top9] [int] NULL,
	[top10] [int] NULL,
	[top11] [int] NULL,
	[top12] [int] NULL,
	[top13] [int] NULL,
	[top14] [int] NULL,
	[left9] [int] NULL,
	[left10] [int] NULL,
	[left11] [int] NULL,
	[left12] [int] NULL,
	[left13] [int] NULL,
	[left14] [int] NULL,
	[图片] [nchar](50) NULL,
	[paperWidth] [float] NULL,
	[PaperHeight] [float] NULL,
	[id] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户清单](
	[客户编号] [char](50) NOT NULL,
	[拼音编码] [char](40) NULL,
	[简称] [varchar](80) NULL,
	[名称] [varchar](80) NULL,
	[联系人] [varchar](30) NULL,
	[地址] [varchar](80) NULL,
	[邮编] [char](6) NULL,
	[区号] [char](6) NULL,
	[地区] [varchar](12) NULL,
	[电话] [varchar](20) NULL,
	[传真] [varchar](20) NULL,
	[电报] [varchar](20) NULL,
	[开户行] [varchar](40) NULL,
	[开户行邮编] [char](6) NULL,
	[银行帐号] [varchar](20) NULL,
	[税号] [varchar](20) NULL,
	[性质] [varchar](10) NULL,
	[业务员] [char](10) NULL,
	[业务部门] [varchar](20) NULL,
	[授信额度] [decimal](28, 6) NULL,
	[价格等级] [char](10) NULL,
	[QQ] [char](20) NULL,
	[客户来源] [char](20) NULL,
	[手机] [char](11) NULL,
	[公司] [varchar](30) NULL,
 CONSTRAINT [PK__客户清单__375B2DB9] PRIMARY KEY CLUSTERED 
(
	[客户编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[供货商地址]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[供货商地址](
	[供货商编号] [char](50) NOT NULL,
	[收货人] [varchar](30) NULL,
	[地址] [varchar](80) NULL,
	[邮编] [char](6) NULL,
	[区号] [char](6) NULL,
	[地区] [varchar](12) NULL,
	[电话] [varchar](20) NULL,
	[手机] [char](11) NULL,
	[公司] [varchar](30) NULL,
	[默认] [bit] NULL,
 CONSTRAINT [PK__供货商地址__375] PRIMARY KEY CLUSTERED 
(
	[供货商编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[规格表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[规格表](
	[序号] [nchar](10) NOT NULL,
	[规格] [nchar](10) NULL,
 CONSTRAINT [PK_规格表] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户地址]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户地址](
	[序号] [int] IDENTITY(1,1) NOT NULL,
	[客户编号] [char](50) NOT NULL,
	[收货人] [char](30) NULL,
	[地址] [char](100) NULL,
	[邮编] [char](6) NULL,
	[地区] [char](12) NULL,
	[电话] [char](20) NULL,
	[手机] [char](11) NULL,
	[公司] [char](30) NULL,
	[默认] [bit] NULL,
 CONSTRAINT [PK_客户地址] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[系统日志]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[系统日志](
	[bit] [bit] NULL,
	[时间] [datetime] NOT NULL CONSTRAINT [DF_系统日志_时间]  DEFAULT (getdate()),
	[单号] [char](50) NULL,
	[事件] [nvarchar](50) NULL,
	[操作员] [char](10) NULL,
 CONSTRAINT [PK_系统日志] PRIMARY KEY CLUSTERED 
(
	[时间] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[合并付款]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[合并付款](
	[付款单号] [nchar](10) NULL,
	[销售单号] [char](20) NULL,
	[付款时间] [datetime] NULL,
	[客户编号] [char](50) NULL,
	[制单人] [nchar](10) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[颜色表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[颜色表](
	[序号] [nchar](10) NOT NULL,
	[颜色] [nchar](10) NULL,
 CONSTRAINT [PK_颜色表] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[付款明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[付款明细](
	[序号] [char](20) NOT NULL,
	[供货商号] [char](50) NULL,
	[充值时间] [datetime] NULL,
	[付款方式] [nchar](10) NULL,
	[付款金额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
	[审核] [char](4) NULL,
	[核对人] [nchar](10) NULL,
	[核对时间] [datetime] NULL,
	[交易单号] [char](20) NULL,
	[备注] [nvarchar](50) NULL,
	[付款日期] [datetime] NULL,
 CONSTRAINT [PK_付款明细] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[单位表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[单位表](
	[序号] [nchar](10) NOT NULL,
	[单位] [nchar](20) NULL,
 CONSTRAINT [PK_单位表] PRIMARY KEY CLUSTERED 
(
	[序号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[供货商账户]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[供货商账户](
	[供货商号] [char](50) NOT NULL,
	[余额] [numeric](18, 2) NULL,
	[最后变动时间] [datetime] NULL,
	[总付款] [numeric](18, 2) NULL,
	[进货总额] [numeric](18, 2) NULL,
	[退货总额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
 CONSTRAINT [PK_供货商账户] PRIMARY KEY CLUSTERED 
(
	[供货商号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[每月结帐日期表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[每月结帐日期表](
	[月份] [int] NOT NULL,
	[全称] [char](4) NULL,
	[结帐日期] [int] NOT NULL DEFAULT ((25)),
PRIMARY KEY CLUSTERED 
(
	[月份] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[支付流水]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[支付流水](
	[付款单号] [char](20) NOT NULL,
	[供货商号] [char](50) NULL,
	[付款时间] [datetime] NULL,
	[付款方式] [nchar](10) NULL,
	[付款金额] [numeric](18, 2) NULL,
	[制单人] [nchar](10) NULL,
	[核对人] [nchar](10) NULL,
	[核对时间] [datetime] NULL,
 CONSTRAINT [PK_支付流水] PRIMARY KEY CLUSTERED 
(
	[付款单号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[校验单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[校验单](
	[编号] [char](20) NOT NULL,
	[日期] [datetime] NULL,
	[制单人] [char](10) NULL,
	[单号] [char](20) NULL,
	[审核] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
 CONSTRAINT [PK__校验单__5C8CB268] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[未付清单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[未付清单](
	[进货单号] [char](20) NULL,
	[供货商号] [char](50) NULL,
	[欠款时间] [datetime] NULL,
	[制单人] [nchar](10) NULL,
	[欠款金额] [numeric](18, 2) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[在线状态]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[在线状态](
	[用户编号] [char](6) NULL,
	[在线状态] [char](4) NULL,
	[版本号] [char](20) NULL,
	[日期] [datetime] NULL CONSTRAINT [DF_在线状态_日期]  DEFAULT (getdate())
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[临时销售单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[临时销售单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[临时销售单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[品名] [nchar](50) NULL,
	[颜色] [nchar](20) NULL,
	[规格] [nchar](10) NULL,
	[销售数量] [decimal](28, 6) NULL,
	[销售价] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[利润] [decimal](28, 6) NULL,
	[重量] [decimal](28, 6) NULL,
	[成本价] [decimal](28, 6) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_临时销售单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__临时销售单明细__5E74FADA] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[临时销售单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[临时销售单](
	[编号] [char](20) NOT NULL,
	[客户编号] [char](50) NULL,
	[客户名称] [char](50) NULL,
	[销售日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[保管员] [char](10) NULL,
	[总金额] [decimal](28, 6) NULL,
	[实收金额] [decimal](28, 6) NULL,
	[订单号] [char](20) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[仓库] [nchar](10) NULL,
	[总利润] [decimal](28, 6) NULL,
	[总重量] [decimal](28, 6) NULL,
	[金额核对] [char](4) NULL,
	[核对人] [char](10) NULL,
	[日期] [datetime] NULL CONSTRAINT [DF_临时销售单_日期]  DEFAULT (getdate()),
	[上级日期] [datetime] NULL,
 CONSTRAINT [PK__临时销售单__5C8CB268] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[盘点单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[盘点单](
	[编号] [char](20) NOT NULL,
	[仓库] [varchar](20) NULL,
	[制单人] [char](10) NULL,
	[业务员] [nchar](10) NULL,
	[盘点日期] [datetime] NULL,
	[审核] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[选中] [char](4) NULL,
	[盈亏金额] [decimal](28, 6) NULL,
	[盈亏] [decimal](28, 6) NULL,
 CONSTRAINT [PK__盘点单__095F58DF] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[销售日报]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[销售日报](
	[日期] [datetime] NULL,
	[制单人] [nchar](10) NULL,
	[现金] [numeric](18, 2) NULL,
	[刷卡] [numeric](18, 2) NULL,
	[转账] [numeric](18, 2) NULL,
	[合计] [numeric](18, 2) NULL,
	[应收款] [numeric](18, 2) NULL,
	[应退款] [numeric](18, 2) NULL,
	[客户欠款] [numeric](18, 2) NULL,
	[其他支出] [numeric](18, 2) NULL,
	[应付货款] [numeric](18, 2) NULL,
	[进货支付] [numeric](18, 2) NULL,
	[退货款] [numeric](18, 2) NULL,
	[欠款收回] [numeric](18, 2) NULL,
	[备用金] [numeric](18, 2) NULL,
	[上交现金] [numeric](18, 2) NULL,
	[审核] [char](4) NULL,
	[审核人] [nchar](10) NULL,
	[审核日期] [datetime] NULL,
	[核对] [char](4) NULL,
	[核对人] [nchar](10) NULL,
	[核对日期] [datetime] NULL,
	[备注] [varchar](max) NULL,
	[仓库] [nchar](10) NULL,
	[退货支出] [numeric](18, 2) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[结帐历史]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[结帐历史](
	[结帐编号] [char](14) NULL,
	[结帐日期] [char](10) NULL,
	[结帐年月] [int] NULL,
	[初次结帐] [char](2) NULL DEFAULT ('否'),
	[备注] [char](40) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[客户关系]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[客户关系](
	[用户编号] [char](6) NOT NULL,
	[客户编号] [char](50) NOT NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[采购订单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[采购订单](
	[编号] [char](14) NOT NULL,
	[供货商号] [char](50) NOT NULL,
	[订货日期] [datetime] NULL,
	[有效起日] [datetime] NULL,
	[有效止日] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[税价合计] [decimal](28, 6) NULL,
	[不含税价] [decimal](28, 6) NULL,
	[税额] [decimal](28, 6) NULL,
 CONSTRAINT [PK__采购订单__43C1049E] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[进货单]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[进货单](
	[编号] [char](20) NOT NULL,
	[供货商号] [char](50) NULL,
	[进货日期] [datetime] NULL,
	[业务员] [char](10) NULL,
	[制单人] [char](10) NULL,
	[验收员] [char](10) NULL,
	[保管员] [char](10) NULL,
	[总金额] [decimal](28, 6) NULL,
	[实付金额] [decimal](28, 6) NULL,
	[订单号] [char](20) NULL,
	[审核] [char](4) NULL,
	[进退货] [char](4) NULL,
	[仓库] [nchar](10) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[上级日期] [datetime] NULL,
	[日期] [datetime] NULL,
 CONSTRAINT [PK__进货单__4B622666] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[采购合同]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[采购合同](
	[供货商号] [char](50) NOT NULL,
	[货号] [char](14) NOT NULL,
	[进价] [decimal](28, 6) NULL CONSTRAINT [DF__采购合同__进价__3FF073BA]  DEFAULT ((0)),
	[付款方式] [varchar](20) NULL,
	[帐期] [int] NULL,
	[签定日期] [int] NULL,
	[合同期限] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[应付款]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[应付款](
	[编号] [char](14) NOT NULL,
	[发票号] [char](14) NULL,
	[填票日期] [datetime] NULL,
	[进货单号] [char](20) NULL,
	[货号] [char](14) NOT NULL,
	[供货商号] [char](50) NOT NULL,
	[数量] [decimal](28, 6) NOT NULL,
	[进货单价] [decimal](28, 6) NULL,
	[金额] [decimal](28, 6) NULL,
	[付款日期] [datetime] NULL,
	[详细说明] [varchar](100) NULL,
	[进货日期] [datetime] NULL,
	[状态] [char](6) NULL,
	[减预付] [char](2) NULL,
 CONSTRAINT [PK__应付款__727BF387] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[预收款]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[预收款](
	[供货商号] [char](50) NOT NULL,
	[预收款总额] [decimal](28, 6) NULL,
 CONSTRAINT [PK__预收款__74643BF9] PRIMARY KEY CLUSTERED 
(
	[供货商号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[预付款]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[预付款](
	[供货商号] [char](50) NOT NULL,
	[预付款总额] [decimal](28, 6) NULL,
 CONSTRAINT [PK__预付款__7093AB15] PRIMARY KEY CLUSTERED 
(
	[供货商号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[进货单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[进货单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[进货单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[进货数量] [decimal](28, 6) NULL,
	[进价] [decimal](28, 6) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[货物质量] [varchar](50) NULL,
	[审核] [char](4) NULL,
	[进退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_进货单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__进货单明细__4D4A6ED8] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[销售单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[销售单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[销售单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[销售数量] [decimal](28, 6) NULL,
	[销售价] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[利润] [decimal](28, 6) NULL,
	[重量] [decimal](28, 6) NULL,
	[成本价] [decimal](28, 6) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_销售单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__销售单明细__5E74FADA] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[调拨单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[调拨单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[调拨单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[数量] [decimal](28, 6) NULL,
	[单价] [decimal](28, 6) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[源仓库] [nchar](10) NULL,
	[目的仓库] [nchar](10) NULL,
	[选中] [char](4) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_调拨单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__调拨单明细__69E6AD86] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[预售单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[预售单明细](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[预售单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[预售数量] [decimal](28, 6) NULL,
	[预售价] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[利润] [decimal](28, 6) NULL,
	[重量] [decimal](28, 6) NULL,
	[成本价] [decimal](28, 6) NULL,
 CONSTRAINT [PK_预售单明细] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[反审单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[反审单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[反审单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[反审数量] [decimal](28, 6) NULL,
	[反审价] [decimal](28, 6) NULL,
	[仓库] [char](20) NULL,
	[目的仓库] [char](20) NULL,
	[合计金额] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[销退货] [char](4) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[利润] [decimal](28, 6) NULL,
	[重量] [decimal](28, 6) NULL,
	[成本价] [decimal](28, 6) NULL,
	[日期] [datetime] NULL CONSTRAINT [DF_反审单明细_日期]  DEFAULT (getdate()),
	[盘点数] [decimal](28, 6) NULL,
	[盈亏] [decimal](28, 6) NULL,
 CONSTRAINT [PK__反审单明细__5E74FADA] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[进销存汇总表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[进销存汇总表](
	[结帐编号] [char](14) NULL,
	[年月] [int] NULL,
	[货号] [char](14) NULL,
	[上期结帐数量] [decimal](28, 6) NULL DEFAULT ((0)),
	[上期结帐金额] [numeric](30, 2) NULL DEFAULT ((0)),
	[借方数量] [decimal](28, 6) NULL DEFAULT ((0)),
	[借方金额] [numeric](30, 2) NULL DEFAULT ((0)),
	[贷方数量] [decimal](28, 6) NULL DEFAULT ((0)),
	[贷方金额] [numeric](30, 2) NULL DEFAULT ((0)),
	[本期结存数量] [decimal](28, 6) NULL DEFAULT ((0)),
	[本期结存金额] [numeric](30, 2) NULL DEFAULT ((0)),
	[备注] [char](20) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[报损报溢]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[报损报溢](
	[编号] [char](14) NOT NULL,
	[货号] [char](14) NOT NULL,
	[仓库] [varchar](20) NOT NULL,
	[数量] [decimal](28, 6) NULL,
	[库存单价] [decimal](28, 6) NULL,
	[金额] [decimal](28, 6) NULL,
	[日期] [int] NULL,
	[责任人] [char](10) NULL,
	[制单人] [char](10) NULL,
PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[库存库]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[库存库](
	[货号] [char](14) NOT NULL,
	[仓库] [varchar](20) NULL,
	[库存数量] [decimal](28, 6) NULL,
	[库存金额] [decimal](28, 6) NULL,
	[库存单价] [decimal](28, 6) NULL,
	[最新进价] [decimal](28, 6) NULL,
	[日期] [datetime] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[上下限对照表]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[上下限对照表](
	[序号] [int] NOT NULL,
	[仓库号] [char](6) NOT NULL,
	[货号] [char](14) NOT NULL,
	[上限] [decimal](28, 6) NULL,
	[下限] [decimal](28, 6) NULL,
	[最佳存量] [decimal](28, 6) NULL,
	[备注] [varchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[采购订单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[采购订单明细](
	[编号] [char](14) NOT NULL,
	[订单号] [char](14) NOT NULL,
	[货号] [char](14) NOT NULL,
	[订货数量] [decimal](28, 6) NOT NULL,
	[进价] [decimal](28, 6) NULL,
	[税价合计] [decimal](28, 6) NULL,
	[扣率] [decimal](28, 6) NULL,
	[税率] [decimal](28, 6) NULL,
	[不含税价] [decimal](28, 6) NULL,
	[税额] [decimal](28, 6) NULL,
PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[盘点单明细]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[盘点单明细](
	[编号] [int] IDENTITY(1,1) NOT NULL,
	[盘点单号] [char](20) NULL,
	[货号] [char](14) NULL,
	[仓库] [varchar](20) NULL,
	[数量] [decimal](28, 6) NULL,
	[单价] [decimal](28, 6) NULL,
	[盘点数] [decimal](28, 6) NULL,
	[审核] [char](4) NULL,
	[盈亏] [decimal](28, 6) NULL,
	[盈亏金额] [decimal](28, 6) NULL,
	[选中] [char](4) NULL,
	[备注] [nvarchar](50) NULL,
	[时间] [datetime] NULL CONSTRAINT [DF_盘点单明细_时间]  DEFAULT (getdate()),
 CONSTRAINT [PK__盘点单明细__0B47A151] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[销售合同]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[销售合同](
	[客户编号] [char](50) NOT NULL,
	[货号] [char](14) NOT NULL,
	[售价] [decimal](28, 6) NULL CONSTRAINT [DF__销售合同__售价__41D8BC2C]  DEFAULT ((0)),
	[付款方式] [varchar](20) NULL,
	[帐期] [int] NULL,
	[签定日期] [int] NULL,
	[合同期限] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[调货申请]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[调货申请](
	[编号] [char](14) NOT NULL,
	[部门] [varchar](20) NULL,
	[组别] [varchar](20) NULL,
	[货号] [char](14) NOT NULL,
	[数量] [decimal](28, 6) NULL,
	[日期] [int] NULL,
	[申请人] [char](10) NULL,
	[申请说明] [varchar](100) NULL,
	[回复] [char](10) NULL,
PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[应收款]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[应收款](
	[编号] [char](14) NOT NULL,
	[发票号] [char](14) NULL,
	[填票日期] [datetime] NULL,
	[销售单号] [char](20) NULL,
	[货号] [char](14) NOT NULL,
	[客户编号] [char](50) NOT NULL,
	[数量] [decimal](28, 6) NOT NULL,
	[销售价] [decimal](28, 6) NULL,
	[金额] [decimal](28, 6) NULL,
	[收款日期] [datetime] NULL,
	[详细说明] [varchar](100) NULL,
	[销售日期] [datetime] NULL,
	[状态] [char](6) NULL,
	[减预收] [char](2) NULL,
 CONSTRAINT [PK__应收款__764C846B] PRIMARY KEY CLUSTERED 
(
	[编号] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[商品清单view]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[商品清单view] AS SELECT     a.货号, a.资料号, b.拼音编码, b.品名, a.颜色, a.规格, b.单位, b.进货价, b.销售价1, b.销售价2, b.最低售价, a.重量, b.品牌, b.日期, a.颜色配比, a.规格配比 FROM         dbo.商品清单 AS a LEFT OUTER JOIN                       dbo.商品基本资料 AS b ON a.资料号 = b.资料号
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[销售VIEW]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[销售VIEW] AS SELECT     TOP (100) PERCENT dbo.销售单.编号, dbo.客户清单.名称, dbo.销售单.销售日期, dbo.销售单.业务员, dbo.销售单.总金额, dbo.销售单.实收金额,                        dbo.付款流水.付款单号, dbo.付款流水.付款金额, dbo.付款流水.付款方式, dbo.欠款清单.欠款金额 FROM         dbo.销售单 INNER JOIN                       dbo.客户清单 ON dbo.销售单.客户编号 = dbo.客户清单.客户编号 LEFT OUTER JOIN                       dbo.欠款清单 ON dbo.销售单.编号 = dbo.欠款清单.销售单号 LEFT OUTER JOIN                       dbo.付款流水 ON dbo.销售单.编号 = dbo.付款流水.付款单号 ORDER BY dbo.销售单.编号
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetCustomersByPage]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'     CREATE PROCEDURE  [dbo].[GetCustomersByPage] @a VARCHAR(20)='''', @b VARCHAR(20)='''', @c VARCHAR(20)='''', @d VARCHAR(20)='''', @开始日期 char(40), @结束日期 char(40), @PageSize int, @PageNumber int,  @Pan int,  @e VARCHAR(20)='''', @f VARCHAR(20)='''', @g VARCHAR(20)='''' AS  Declare @RowStart int Declare @RowEnd int if @PageNumber > 0 Begin SET @PageNumber = @PageNumber -1 SET @RowStart = @PageSize * @PageNumber ; SET @RowEnd = @RowStart + @PageSize - 1; if @e ='''' begin if @pan = 1 begin With Cust AS      ( SELECT a.编号, a.进货单号,b.供货商号,c.名称 as 供货商名称,b.进货日期 as 退货日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.进货数量 as 退货数量,a.进价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   进货单明细 as a,进货单 as b,供货商清单 as c,商品清单view as d where     a.审核 = ''未审''  and a.进货单号 = b.编号 and a.货号 = d.货号 and b.供货商号= c.供货商号 and a.进退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 in (select  u.仓库名 from 仓库清单 as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.进货日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else With Cust AS      ( SELECT a.编号, a.进货单号,b.供货商号,c.名称 as 供货商名称,b.进货日期 as 退货日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.进货数量 as 退货数量,a.进价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   进货单明细 as a,进货单 as b,供货商清单 as c,商品清单view as d where    a.进货单号 = b.编号 and a.货号 = d.货号 and b.供货商号= c.供货商号 and a.进退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''      and a.仓库 in (select  u.仓库名 from 仓库清单view as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.进货日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else begin if @pan = 1 begin With Cust AS      ( SELECT a.编号, a.进货单号,b.供货商号,c.名称 as 供货商名称,b.进货日期 as 退货日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.进货数量 as 退货数量,a.进价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   进货单明细 as a,进货单 as b,供货商清单 as c,商品清单view as d where     a.审核 = ''未审''  and a.进货单号 = b.编号 and a.货号 = d.货号 and b.供货商号= c.供货商号 and a.进退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 = @e and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.进货日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else With Cust AS      ( SELECT a.编号, a.进货单号,b.供货商号,c.名称 as 供货商名称,b.进货日期 as 退货日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.进货数量 as 退货数量,a.进价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   进货单明细 as a,进货单 as b,供货商清单 as c,商品清单view as d where    a.进货单号 = b.编号 and a.货号 = d.货号 and b.供货商号= c.供货商号 and a.进退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 = @e and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.进货日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end  END      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aaaaaa]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'     CREATE PROCEDURE  [dbo].[aaaaaa] @a VARCHAR(20)='''', @b VARCHAR(20)='''', @c VARCHAR(20)='''', @d VARCHAR(20)='''', @开始日期 char(40), @结束日期 char(40), @PageSize int, @PageNumber int,  @Pan int,  @e VARCHAR(20)='''', @f VARCHAR(20)='''', @g VARCHAR(20)='''' AS  Declare @RowStart int Declare @RowEnd int if @PageNumber > 0 Begin SET @PageNumber = @PageNumber -1 SET @RowStart = @PageSize * @PageNumber ; SET @RowEnd = @RowStart + @PageSize - 1; if @e ='''' begin if @pan = 1 begin With Cust AS      ( SELECT a.编号, a.销售单号,b.客户编号,c.名称 as 客户名称,b.销售日期 as 日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.销售数量 as 数量,a.销售价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   销售单明细 as a,销售单 as b,客户清单 as c,商品清单view as d where     a.审核 = ''未审''  and a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and a.销退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 in (select  u.仓库名 from 仓库清单 as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.销售日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else With Cust AS      ( SELECT a.编号, a.销售单号,b.客户编号,c.名称 as 客户名称,b.销售日期 as 日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.销售数量 as 数量,a.销售价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   销售单明细 as a,销售单 as b,客户清单 as c,商品清单view as d where    a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and a.销退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''      and a.仓库 in (select  u.仓库名 from 仓库清单 as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.销售日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else begin if @pan = 1 begin With Cust AS      ( SELECT a.编号, a.销售单号,b.客户编号,c.名称 as 客户名称,b.销售日期 as 日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.销售数量 as 数量,a.销售价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   销售单明细 as a,销售单 as b,客户清单 as c,商品清单view as d where     a.审核 = ''未审''  and a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and a.销退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 = @e and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.销售日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end else With Cust AS      ( SELECT a.编号, a.销售单号,b.客户编号,c.名称 as 客户名称,b.销售日期 as 日期,b.业务员,a.货号,a.仓库,d.品名,d.颜色,d.规格,d.品牌,d.单位,a.审核,a.销售数量 as 数量,a.销售价,a.合计金额,b.备注 as 总备注,a.备注 as  明细备注,      ROW_NUMBER() OVER (order by a.货号) as RowNumber      FROM   销售单明细 as a,销售单 as b,客户清单 as c,商品清单view as d where    a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and a.销退货= @g and a.货号 like ''%'' +@a+ ''%'' and c.名称 like ''%'' +@b+ ''%''     and a.仓库 = @e and b.业务员 like ''%'' + @d + ''%'' and d.品名 like ''%'' + @c + ''%'' and b.销售日期 between @开始日期 and @结束日期)  select *  from Cust Where RowNumber Between @RowStart and @RowEnd end  END      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aaaaab]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'     CREATE PROCEDURE  [dbo].[aaaaab] @a VARCHAR(20)='''', @b VARCHAR(20)='''', @c VARCHAR(20)='''', @d VARCHAR(20)='''', @开始日期 char(40), @结束日期 char(40), @PageSize int, @PageNumber int,  @Pan int,  @e VARCHAR(20)='''', @f VARCHAR(20)='''', @g VARCHAR(20)='''' AS  Declare @RowStart int Declare @RowEnd int  if @e ='''' begin if @pan = 1 begin     SELECT  AAA =COUNT(a.编号)  FROM ( SELECT 编号,销售单号,货号 FROM  销售单明细  where  审核 = ''未审'' and 销退货= @g and 货号 like ''%'' +@a+ ''%''   and 仓库 in (select  u.仓库名 from 仓库清单 as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) )  as a,(SELECT 编号,客户编号 FROM 销售单 where  业务员 like ''%'' + @d + ''%'' and 销售日期 between @开始日期 and @结束日期) as b,客户清单 as c,商品清单view as d where  a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and c.名称 like ''%'' +@b+ ''%'' and d.品名 like ''%'' + @c + ''%''   end else     SELECT  AAA =COUNT(a.编号)  FROM ( SELECT 编号,销售单号,货号 FROM  销售单明细  where  销退货= @g and 货号 like ''%'' +@a+ ''%''   and 仓库 in (select  u.仓库名 from 仓库清单 as u ,用户仓库 as v ,用户清单 as w  where u.仓库号= v.仓库号 and v.用户编号 = w.用户编号 and  w.姓名 =@f ) )  as a,(SELECT 编号,客户编号 FROM 销售单 where  业务员 like ''%'' + @d + ''%'' and 销售日期 between @开始日期 and @结束日期) as b,客户清单 as c,商品清单view as d where  a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and c.名称 like ''%'' +@b+ ''%'' and d.品名 like ''%'' + @c + ''%''   end else begin if @pan = 1 begin    SELECT  AAA =COUNT(a.编号)  FROM ( SELECT 编号,销售单号,货号 FROM  销售单明细  where 审核 = ''未审'' and  销退货= @g and 货号 like ''%'' +@a+ ''%''   and   仓库 = @e  )  as a,(SELECT 编号,客户编号 FROM 销售单 where  业务员 like ''%'' + @d + ''%'' and 销售日期 between @开始日期 and @结束日期) as b,客户清单 as c,商品清单view as d where  a.销售单号 = b.编号 and a.货号 = d.货号 and b.客户编号= c.客户编号 and c.名称 like ''%'' +@b+ ''%'' and d.品名 like ''%'' + @c + ''%''    end else    SELECT  AAA =COUNT(a.编号)  FROM ( SELECT 编号,销售单号,货号 FROM  销售单明细  where  销退货= @g and patindex(''%'' + @a + ''%'',货号)>0   and   仓库 = @e  )  as a,(SELECT 编号,客户编号 FROM 销售单 where patindex(''%'' + @d + ''%'',业务员)>0  and 销售日期 between @开始日期 and @结束日期) as b,客户清单 as c ,(SELECT 货号,品名 FROM 商品清单view  ) as  d where patindex(''%'' + @b + ''%'',c.名称)>0   and c.客户编号= b.客户编号  and b.编号 = a.销售单号  and  a.货号 = d.货号  and d.品名 like ''%'' + @c + ''%''     end           
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[采购入库报表view]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[采购入库报表view] AS SELECT     a.进货单号, b.供货商号, c.名称 AS 供货商名称, b.进货日期, b.业务员, a.货号, a.仓库, d.品名, d.颜色, d.规格, d.品牌, d.单位, a.审核, a.进货数量, a.进价, a.合计金额,                        b.备注 AS 总备注, a.备注 AS 明细备注, d.资料号 FROM         dbo.进货单明细 AS a INNER JOIN                       dbo.进货单 AS b ON a.进货单号 = b.编号 INNER JOIN                       dbo.商品清单View AS d ON a.货号 = d.货号 INNER JOIN                       dbo.供货商清单 AS c ON b.供货商号 = c.供货商号 WHERE     (a.进退货 = ''进货'')
' 
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "a"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 125
               Right = 177
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "b"
            Begin Extent = 
               Top = 6
               Left = 215
               Bottom = 125
               Right = 354
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "d"
            Begin Extent = 
               Top = 126
               Left = 38
               Bottom = 245
               Right = 177
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "c"
            Begin Extent = 
               Top = 126
               Left = 215
               Bottom = 245
               Right = 364
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'采购入库报表view'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'采购入库报表view'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[采购退货报表view]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[采购退货报表view]
AS
SELECT     a.进货单号, b.供货商号, c.名称 AS 供货商名称, b.进货日期 AS 退货日期, b.业务员, a.货号, a.仓库, d.品名, d.颜色, d.规格, d.品牌, d.单位, a.审核, 
                      a.进货数量 AS 退货数量, a.进价, a.合计金额, b.备注 AS 总备注, a.备注 AS 明细备注, d.资料号
FROM         dbo.进货单明细 AS a INNER JOIN
                      dbo.进货单 AS b ON a.进货单号 = b.编号 INNER JOIN
                      dbo.商品清单view AS d ON a.货号 = d.货号 INNER JOIN
                      dbo.供货商清单 AS c ON b.供货商号 = c.供货商号
WHERE     (a.进退货 = ''退货'')
' 
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "a"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 125
               Right = 177
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "b"
            Begin Extent = 
               Top = 6
               Left = 215
               Bottom = 125
               Right = 354
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "d"
            Begin Extent = 
               Top = 126
               Left = 38
               Bottom = 245
               Right = 177
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "c"
            Begin Extent = 
               Top = 126
               Left = 215
               Bottom = 245
               Right = 364
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'采购退货报表view'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'采购退货报表view'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[商品来源View]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[商品来源View] AS SELECT DISTINCT                        TOP (100) PERCENT dbo.商品清单.货号, dbo.商品基本资料.资料号, dbo.供货商清单.名称, dbo.商品清单.颜色, dbo.商品清单.规格, dbo.商品基本资料.品名,                        dbo.商品清单.日期, dbo.进货单.供货商号 FROM         dbo.商品清单 INNER JOIN                       dbo.商品基本资料 ON dbo.商品清单.资料号 = dbo.商品基本资料.资料号 INNER JOIN                       dbo.进货单明细 ON dbo.商品清单.货号 = dbo.进货单明细.货号 INNER JOIN                       dbo.进货单 ON dbo.进货单明细.进货单号 = dbo.进货单.编号 INNER JOIN                       dbo.供货商清单 ON dbo.进货单.供货商号 = dbo.供货商清单.供货商号 ORDER BY dbo.商品清单.货号
' 

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[库存库View]'))
EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[库存库View]
AS
SELECT     TOP (100) PERCENT dbo.库存库.货号, dbo.商品清单view.品名, dbo.商品清单view.颜色, dbo.商品清单view.规格, dbo.商品清单view.单位, dbo.商品清单view.品牌, 
                      dbo.库存库.库存数量, dbo.库存库.库存金额, dbo.库存库.库存单价, dbo.库存库.仓库, dbo.商品清单view.销售价1, dbo.商品清单view.日期, 
                      dbo.商品清单view.资料号
FROM         dbo.库存库 INNER JOIN
                      dbo.商品清单view ON dbo.库存库.货号 = dbo.商品清单view.货号
WHERE     (dbo.库存库.库存数量 <> 0)
ORDER BY dbo.库存库.货号
' 
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "库存库"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 243
               Right = 177
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "商品清单view"
            Begin Extent = 
               Top = 6
               Left = 215
               Bottom = 328
               Right = 354
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'库存库View'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'VIEW', @level1name=N'库存库View'

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[销售退货报表view]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[销售退货报表view] AS SELECT     a.销售单号, b.客户编号, c.名称 AS 客户名称, b.销售日期, b.业务员, a.货号, a.仓库, d.品名, d.颜色, d.规格, d.品牌, d.单位, a.审核, a.销售数量, a.销售价, a.合计金额,                        b.备注 AS 总备注, a.备注 AS 明细备注, d.资料号, d.拼音编码 FROM         dbo.销售单明细 AS a LEFT OUTER JOIN                       dbo.销售单 AS b ON a.销售单号 = b.编号 LEFT OUTER JOIN                       dbo.商品清单view AS d ON a.货号 = d.货号 LEFT OUTER JOIN                       dbo.客户清单 AS c ON b.客户编号 = c.客户编号 WHERE     (a.销退货 = ''退货'')
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[销售出库报表view]'))
EXEC dbo.sp_executesql @statement = N' CREATE view [dbo].[销售出库报表view] AS SELECT     a.销售单号, b.客户编号, c.名称 AS 客户名称, b.销售日期, b.业务员, a.货号, a.仓库, d.品名, d.颜色, d.规格, d.品牌, d.单位, a.审核, a.销售数量, a.销售价, a.合计金额,                        b.备注 AS 总备注, a.备注 AS 明细备注, d.资料号, d.拼音编码 FROM         dbo.销售单明细 AS a LEFT OUTER JOIN                       dbo.销售单 AS b ON a.销售单号 = b.编号 LEFT OUTER JOIN                       dbo.商品清单view AS d ON a.货号 = d.货号 LEFT OUTER JOIN                       dbo.客户清单 AS c ON b.客户编号 = c.客户编号 WHERE     (a.销退货 = ''销售'')
' 
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_销退货反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'              CREATE PROCEDURE [dbo].[sf_销退货反审] AS SET   TRANSACTION   ISOLATION   LEVEL   REPEATABLE   READ  begin transaction   	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号  ) 			where j.审核=''已审'' and j.销退货=''退货'' and j.选中=''选中'' and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''已审'' and 销退货=''退货'' and 选中=''选中''  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 DELETE  [应收款] FROM   [应收款],[销售单] WHERE 应收款.销售单号 = 销售单.编号  and 销售单.审核=''已审'' and  销售单.销退货=''退货'' and 销售单.选中=''选中''     UPDATE 销售单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 销退货=''退货'' and 选中=''选中''  UPDATE 销售单 set 审核=''未审'' ,选中=''未选'',日期=getdate() where 审核=''已审'' and 销退货=''退货'' and 选中=''选中'' commit          
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_销退货]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'               CREATE PROCEDURE [dbo].[sf_销退货] AS begin transaction    	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号  ) 			where j.审核=''未审'' and j.销退货=''退货'' and j.选中=''选中'' and k.货号 is null 	  	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''未审'' and 销退货=''退货'' and 选中=''选中''  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应收款(编号, 销售单号, 货号, 客户编号, 数量, 销售价, 金额, 销售日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.客户编号,销售数量,销售价,a.合计金额,销售日期,''应付''  		FROM 销售单明细 as a, 销售单 as b 		where a.销售单号=b.编号 and a.审核=''未审'' and a.销退货=''退货'' and a.选中=''选中''   UPDATE 销售单明细 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 销退货=''退货'' and 选中=''选中''  UPDATE 销售单 set 审核=''已审'' ,选中=''未选'',日期=getdate() where 审核=''未审'' and 销退货=''退货'' and 选中=''选中''  commit                 
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_销售单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'                CREATE PROCEDURE [dbo].[sf_销售单反审] AS begin transaction  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  j.审核=''已审'' and j.销退货=''销售'' and j.选中=''选中''  and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''已审'' and 销退货=''销售'' and 选中=''选中''  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	  DELETE  [应收款] FROM   [应收款],[销售单] WHERE 应收款.销售单号 = 销售单.编号  and 销售单.审核=''已审'' and  销售单.销退货=''销售'' and 销售单.选中=''选中''     UPDATE 销售单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 销退货=''销售'' and 选中=''选中''  UPDATE 销售单 set 审核=''未审'' ,选中=''未选'' ,日期=getdate() where 审核=''已审'' and 销退货=''销售'' and 选中=''选中'' commit                         
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_销售单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'             CREATE PROCEDURE [dbo].[sf_销售单] AS begin transaction 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号   ) 			where j.审核=''未审'' and j.销退货=''销售'' and j.选中=''选中''  and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''未审'' and 销退货=''销售'' and 选中=''选中''  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应收款(编号, 销售单号, 货号, 客户编号, 数量, 销售价, 金额, 销售日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.客户编号,销售数量,销售价,a.合计金额,销售日期,''应收''  		FROM 销售单明细 as a, 销售单 as b 		where a.销售单号=b.编号 and a.审核=''未审'' and a.销退货=''销售'' and a.选中=''选中''   UPDATE 销售单明细 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 销退货=''销售'' and 选中=''选中''  UPDATE 销售单 set 审核=''已审'' ,选中=''未选'' ,日期=getdate() where 审核=''未审'' and 销退货=''销售'' and 选中=''选中''  commit                      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_销售单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[new_销售单反审] @单号 char(20) AS begin transaction  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  j.审核=''已审'' and j.销退货=''销售'' and j.销售单号=@单号  and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''已审'' and 销退货=''销售'' and 销售单号=@单号 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	  DELETE  [应收款] FROM   [应收款],[销售单] WHERE 应收款.销售单号 = 销售单.编号  and 销售单.审核=''已审'' and  销售单.销退货=''销售'' and 销售单.编号=@单号    UPDATE 销售单明细 set 审核=''未审'' where 审核=''已审'' and 销退货=''销售'' and 销售单号=@单号 UPDATE 销售单 set 审核=''未审'' ,日期=getdate() where 审核=''已审'' and 编号=@单号 commit                             
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_销退货]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'         CREATE PROCEDURE [dbo].[new_销退货] @单号 char(20) AS begin transaction    	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号  ) 			where j.审核=''未审'' and j.销退货=''退货'' and j.销售单号=@单号 and k.货号 is null 	  	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''未审'' and 销退货=''退货'' and 销售单号=@单号 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应收款(编号, 销售单号, 货号, 客户编号, 数量, 销售价, 金额, 销售日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.客户编号,销售数量,销售价,a.合计金额,销售日期,''应付''  		FROM 销售单明细 as a, 销售单 as b 		where a.销售单号=b.编号 and a.审核=''未审'' and a.销退货=''退货'' and a.销售单号=@单号  UPDATE 销售单明细 set 审核=''已审'' where 审核=''未审'' and 销退货=''退货'' and 销售单号=@单号 UPDATE 销售单 set 审核=''已审'' ,日期=getdate() where 审核=''未审'' and 销退货=''退货'' and 编号=@单号  commit                       
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_销退货反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'         CREATE PROCEDURE [dbo].[new_销退货反审] @单号 char(20) AS SET   TRANSACTION   ISOLATION   LEVEL   REPEATABLE   READ  begin transaction   	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号  ) 			where j.审核=''已审'' and j.销退货=''退货'' and j.销售单号=@单号 and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''已审'' and 销退货=''退货'' and 销售单号=@单号  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 DELETE  [应收款] FROM   [应收款],[销售单] WHERE 应收款.销售单号 = 销售单.编号  and 销售单.审核=''已审'' and  销售单.销退货=''退货'' and 销售单.编号=@单号    UPDATE 销售单明细 set 审核=''未审'' where 审核=''已审'' and 销退货=''退货'' and 销售单号=@单号 UPDATE 销售单 set 审核=''未审'' ,日期=getdate() where 审核=''已审'' and 销退货=''退货'' and 编号=@单号 commit               
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_销售单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'       CREATE PROCEDURE [dbo].[new_销售单] @单号 char(20) AS begin transaction 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.成本价,getdate() 			FROM 销售单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号   ) 			where j.审核=''未审'' and j.销退货=''销售'' and j.销售单号=@单号   and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(销售数量) FROM 销售单明细 where 审核=''未审'' and 销退货=''销售'' and 销售单号=@单号  		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应收款(编号, 销售单号, 货号, 客户编号, 数量, 销售价, 金额, 销售日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.客户编号,销售数量,销售价,a.合计金额,销售日期,''应收''  		FROM 销售单明细 as a, 销售单 as b 		where a.销售单号=b.编号 and a.审核=''未审'' and a.销退货=''销售'' and a.销售单号=@单号    UPDATE 销售单明细 set 审核=''已审'' where 审核=''未审'' and 销退货=''销售'' and 销售单号=@单号  UPDATE 销售单 set 审核=''已审'' ,日期=getdate() where 审核=''未审'' and 编号=@单号  commit                           
' 
END

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_调拨单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[new_调拨单] @单号 char(20) AS begin transaction  	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.源仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.源仓库=k.仓库 and j.货号=k.货号  ) 			where J.审核=''未审''and J.调拨单号=@单号  and  k.货号 is null  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.目的仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.目的仓库=k.仓库 and j.货号=k.货号 ) 			where J.审核=''未审''and J.调拨单号=@单号 and k.货号 is null  	 	UPDATE 库存库  set 库存数量=(库存数量-数量ALL), 库存单价=进价 , 库存金额=(库存金额-合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 源仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''未审'' and 调拨单号=@单号 GROUP BY 源仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.源仓库 AND 库存库.货号=LSj.货号 	 	UPDATE 库存库  set 库存数量=(库存数量+数量ALL), 库存单价=进价 , 库存金额=(库存金额+合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 目的仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''未审'' and 调拨单号=@单号 GROUP BY 目的仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.目的仓库 AND 库存库.货号=LSj.货号  	   UPDATE 调拨单明细 set 审核=''已审'' where 审核=''未审'' and 调拨单号=@单号 UPDATE 调拨单 set 审核=''已审'' where 审核=''未审'' and 编号=@单号   commit                             
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_调拨单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'            CREATE PROCEDURE [dbo].[new_调拨单反审] @单号 char(20) AS begin transaction 	  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.源仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.源仓库=k.仓库 and j.货号=k.货号  ) 			where J.审核=''已审''and J.调拨单号=@单号  and  k.货号 is null  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.目的仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.目的仓库=k.仓库 and j.货号=k.货号 ) 			where J.审核=''已审''and J.调拨单号=@单号 and k.货号 is null  	  	UPDATE 库存库  set 库存数量=(库存数量+数量ALL), 库存单价=进价 , 库存金额=(库存金额+合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 源仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''已审'' and 调拨单号=@单号 GROUP BY 源仓库,货号 ) AS LSJ 		WHERE  库存库.仓库=LSj.源仓库 AND 库存库.货号=LSj.货号 	 	UPDATE 库存库  set 库存数量=(库存数量-数量ALL), 库存单价=进价 , 库存金额=(库存金额-合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 目的仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''已审'' and 调拨单号=@单号 GROUP BY 目的仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.目的仓库 AND 库存库.货号=LSj.货号  	 UPDATE 调拨单明细 set 审核=''未审'' where 审核=''已审'' and 调拨单号=@单号 UPDATE 调拨单 set 审核=''未审'' where 审核=''已审''and 编号=@单号  commit                      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_调拨单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'          CREATE PROCEDURE [dbo].[sf_调拨单反审] AS begin transaction 	  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.源仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.源仓库=k.仓库 and j.货号=k.货号  ) 			where J.审核=''已审''and J.选中=''选中''  and  k.货号 is null  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.目的仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.目的仓库=k.仓库 and j.货号=k.货号 ) 			where J.审核=''已审''and J.选中=''选中'' and k.货号 is null  	  	UPDATE 库存库  set 库存数量=(库存数量+数量ALL), 库存单价=进价 , 库存金额=(库存金额+合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 源仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''已审'' and 选中=''选中''  GROUP BY 源仓库,货号 ) AS LSJ 		WHERE  库存库.仓库=LSj.源仓库 AND 库存库.货号=LSj.货号 	 	UPDATE 库存库  set 库存数量=(库存数量-数量ALL), 库存单价=进价 , 库存金额=(库存金额-合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 目的仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''已审'' and 选中=''选中''  GROUP BY 目的仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.目的仓库 AND 库存库.货号=LSj.货号  	 UPDATE 调拨单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 选中=''选中'' UPDATE 调拨单 set 审核=''未审'',选中=''未选'' where 审核=''已审''and 选中=''选中''  commit                   
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_调拨单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[sf_调拨单] AS begin transaction  	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.源仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.源仓库=k.仓库 and j.货号=k.货号  ) 			where J.审核=''未审''and J.选中=''选中''  and  k.货号 is null  	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.目的仓库, 0,0,k.库存单价,k.库存单价,getdate() 			FROM 调拨单明细 AS J left join 库存库 as k on ( j.目的仓库=k.仓库 and j.货号=k.货号 ) 			where J.审核=''未审''and J.选中=''选中'' and k.货号 is null  	  	UPDATE 库存库  set 库存数量=(库存数量-数量ALL), 库存单价=进价 , 库存金额=(库存金额-合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 源仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''未审'' and 选中=''选中'' GROUP BY 源仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.源仓库 AND 库存库.货号=LSj.货号 	 	UPDATE 库存库  set 库存数量=(库存数量+数量ALL), 库存单价=进价 , 库存金额=(库存金额+合计金额ALL) , 			最新进价=进价,日期=getdate()       FROM  		(SELECT 目的仓库,货号,''数量ALL''=sum(数量), ''进价'' = sum(合计金额)/sum(数量),  			''合计金额ALL''=sum(合计金额) FROM 调拨单明细 where 审核=''未审'' and 选中=''选中'' GROUP BY 目的仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.目的仓库 AND 库存库.货号=LSj.货号  	 UPDATE 调拨单明细 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 选中=''选中'' UPDATE 调拨单 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 选中=''选中''   commit                       
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_进退货反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'           CREATE PROCEDURE [dbo].[sf_进退货反审] AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''已审'' and j.进退货=''退货'' and j.选中=''选中'' and k.货号 is null    	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(进货数量) FROM 进货单明细 where 审核=''已审'' and 进退货=''退货'' and 选中=''选中'' 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 DELETE  [应付款] FROM   [应付款],[进货单] WHERE 应付款.进货单号 = 进货单.编号  and 进货单.审核=''已审'' and  进货单.进退货=''退货'' and 进货单.选中=''选中''      UPDATE 进货单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 进退货=''退货'' and 选中=''选中'' UPDATE 进货单 set 审核=''未审'',选中=''未选'' ,日期=getdate() where 审核=''已审'' and 进退货=''退货'' and 选中=''选中'' commit                    
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_进货单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'              CREATE PROCEDURE [dbo].[sf_进货单] AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,0,0,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  J.审核=''未审'' and J.进退货=''进货'' and J.选中=''选中'' and k.货号 is null   	 	UPDATE 库存库 SET 库存单价=case when 库存数量<=0 or (库存数量+数量ALL)<=0 then 进价 					else (库存金额+合计金额ALL)/(库存数量+数量ALL) end , 			库存数量=库存数量+数量ALL,日期=getdate(), 			库存金额=case when 库存数量<=0 or (库存数量+数量ALL)<=0  				then 进价*(库存数量+数量ALL) else (库存金额+合计金额ALL) end , 			最新进价=进价 		FROM  		(SELECT 仓库,货号,''数量ALL''=sum(进货数量), ''进价'' = sum(合计金额)/sum(进货数量),  			''合计金额ALL''=sum(合计金额) FROM 进货单明细 where 审核=''未审'' and 进退货=''进货'' and 选中=''选中'' GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 	INSERT INTO 应付款(编号, 进货单号, 货号, 供货商号, 数量, 进货单价, 金额, 进货日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.供货商号,进货数量,进价,a.合计金额,进货日期,''应付''  		FROM 进货单明细 as a, 进货单 as b 		where a.审核=''未审'' and a.进退货=''进货'' and a.进货单号=b.编号    UPDATE 进货单明细 set 审核=''已审'' ,选中=''未选'' where 审核=''未审'' and 进退货=''进货'' and 选中=''选中'' UPDATE 进货单 set 审核=''已审'',选中=''未选'',日期=getdate()  where 审核=''未审'' and 进退货=''进货'' and 选中=''选中'' commit        
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_进货单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'            CREATE PROCEDURE [dbo].[sf_进货单反审]  AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  J.审核=''已审'' and J.进退货=''进货'' and J.选中=''选中'' and k.货号 is null 	 UPDATE 库存库 SET 库存单价=case when 库存数量<=0 or (库存数量-数量ALL)<=0 then 进价 					else (库存金额-合计金额ALL)/(库存数量-数量ALL) end , 			库存数量=库存数量-数量ALL,日期=getdate(), 			库存金额=case when 库存数量<=0 or (库存数量-数量ALL)<=0  				then 进价*(库存数量-数量ALL) else (库存金额-合计金额ALL) end  			 		FROM  		(SELECT 仓库,货号,''数量ALL''=sum(进货数量), ''进价'' = sum(合计金额)/sum(进货数量),  			''合计金额ALL''=sum(合计金额) FROM 进货单明细 where 审核=''已审'' and 进退货=''进货'' and 选中=''选中'' GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 DELETE  [应付款] FROM   [应付款],[进货单] WHERE 应付款.进货单号 = 进货单.编号  and 进货单.审核=''已审'' and  进货单.进退货=''进货'' and 进货单.选中=''选中''    UPDATE 进货单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 进退货=''进货'' and 选中=''选中'' UPDATE 进货单 set 审核=''未审'' ,选中=''未选'' ,日期=getdate() where 审核=''已审'' and 进退货=''进货'' and 选中=''选中''  commit                        
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_进退货]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'            CREATE PROCEDURE [dbo].[sf_进退货] AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''未审'' and j.进退货=''退货'' and j.选中=''选中'' and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(进货数量) FROM 进货单明细 where 审核=''未审'' and 进退货=''退货'' and 选中=''选中'' 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应付款(编号, 进货单号, 货号, 供货商号, 数量, 进货单价, 金额, 进货日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.供货商号,进货数量,进价,a.合计金额,进货日期,''应收''  		FROM 进货单明细 as a, 进货单 as b 		where a.进货单号=b.编号 and a.审核=''未审'' and a.进退货=''退货'' and a.选中=''选中''  UPDATE 进货单明细 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 进退货=''退货'' and 选中=''选中'' UPDATE 进货单 set 审核=''已审'' ,选中=''未选'' ,日期=getdate() where 审核=''未审'' and 进退货=''退货'' and 选中=''选中'' commit                       
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_进退货反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'         CREATE PROCEDURE [dbo].[new_进退货反审] @单号 char(20) AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''已审'' and j.进退货=''退货'' and j.进货单号=@单号 and k.货号 is null    	 	UPDATE 库存库 SET 库存数量=库存数量+数量ALL, 库存金额=库存单价*(库存数量+数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(进货数量) FROM 进货单明细 where 审核=''已审'' and 进退货=''退货'' and 进货单号=@单号 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 DELETE  [应付款] FROM   [应付款],[进货单] WHERE 应付款.进货单号 = 进货单.编号  and 进货单.审核=''已审'' and  进货单.进退货=''退货'' and 进货单.编号 = @单号      UPDATE 进货单明细 set 审核=''未审'' where 审核=''已审'' and 进退货=''退货'' and 进货单号=@单号 UPDATE 进货单 set 审核=''未审'' ,日期=getdate() where 审核=''已审'' and 编号=@单号 commit                         
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_进货单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[new_进货单] @单号 char(20) AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,0,0,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  J.审核=''未审''  and J.进货单号=@单号 and k.货号 is null   	 	UPDATE 库存库 SET 库存单价=case when 库存数量<=0 or (库存数量+数量ALL)<=0 then 进价 					else (库存金额+合计金额ALL)/(库存数量+数量ALL) end , 			库存数量=库存数量+数量ALL,日期=getdate(), 			库存金额=case when 库存数量<=0 or (库存数量+数量ALL)<=0  				then 进价*(库存数量+数量ALL) else (库存金额+合计金额ALL) end , 			最新进价=进价 		FROM  		(SELECT 仓库,货号,''数量ALL''=sum(进货数量), ''进价'' = sum(合计金额)/sum(进货数量),  			''合计金额ALL''=sum(合计金额) FROM 进货单明细 where 审核=''未审'' and 进货单号 = @单号 GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 	INSERT INTO 应付款(编号, 进货单号, 货号, 供货商号, 数量, 进货单价, 金额, 进货日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.供货商号,进货数量,进价,a.合计金额,进货日期,''应付''  		FROM 进货单明细 as a, 进货单 as b 		where a.审核=''未审'' and   a.进货单号=b.编号    UPDATE 进货单明细 set 审核=''已审'' where 审核=''未审''  and 进货单号=@单号 UPDATE 进货单 set 审核=''已审'',日期=getdate()  where 审核=''未审'' and 编号=@单号 commit           
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_进货单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[new_进货单反审] @单号 char(20) AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,最新进价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where  J.审核=''已审'' and J.进货单号=@单号 and k.货号 is null 	 UPDATE 库存库 SET 库存单价=case when 库存数量<=0 or (库存数量-数量ALL)<=0 then 进价 					else (库存金额-合计金额ALL)/(库存数量-数量ALL) end , 			库存数量=库存数量-数量ALL,日期=getdate(), 			库存金额=case when 库存数量<=0 or (库存数量-数量ALL)<=0  				then 进价*(库存数量-数量ALL) else (库存金额-合计金额ALL) end  		FROM  		(SELECT 仓库,货号,''数量ALL''=sum(进货数量), ''进价'' = sum(合计金额)/sum(进货数量),  			''合计金额ALL''=sum(合计金额) FROM 进货单明细 where 审核=''已审'' and 进货单号=@单号 GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 DELETE  [应付款] FROM   [应付款],[进货单] WHERE 应付款.进货单号 = 进货单.编号  and 进货单.审核=''已审'' and 进货单号=@单号   UPDATE 进货单明细 set 审核=''未审''  where 审核=''已审'' and 进货单号=@单号 UPDATE 进货单 set 审核=''未审''   ,日期=getdate() where 审核=''已审'' and 编号=@单号  commit                             
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_进退货]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'              CREATE PROCEDURE [dbo].[new_进退货] @单号 char(20) AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.进价,getdate() 			FROM 进货单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''未审'' and j.进货单号=@单号 and k.货号 is null  	 	UPDATE 库存库 SET 库存数量=库存数量-数量ALL, 库存金额=库存单价*(库存数量-数量ALL),日期=getdate() 		FROM (SELECT 仓库,货号,''数量ALL''=sum(进货数量) FROM 进货单明细 where 审核=''未审'' and 进货单号=@单号 		GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号 	 	INSERT INTO 应付款(编号, 进货单号, 货号, 供货商号, 数量, 进货单价, 金额, 进货日期, 状态) 		SELECT 	a.编号,b.编号,a.货号,b.供货商号,进货数量,进价,a.合计金额,进货日期,''应收''  		FROM 进货单明细 as a, 进货单 as b 		where a.进货单号=b.编号 and a.审核=''未审'' and a.进货单号=@单号  UPDATE 进货单明细 set 审核=''已审'' where 审核=''未审'' and 进货单号=@单号 UPDATE 进货单 set 审核=''已审'' ,日期=getdate() where 审核=''未审'' and 编号=@单号 commit                          
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert1]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert1] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert2]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert2] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert3]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert3] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert4]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert4] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert5]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert5] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Ps_insert7]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[Ps_insert7] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_insert]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'      CREATE PROC [dbo].[sf_insert] @编号 char(20), @销售单号 char(20), @货号 char(14), @销售数量 decimal(28, 6), @销售价 decimal(28, 6), @合计金额 decimal(28, 6), @仓库 char(20), @审核 char(4), @销退货 char(4), @备注 nvarchar(50)  as  insert into   [销售单明细] ([编号],[销售单号],[货号],[销售数量],[销售价],[合计金额],[仓库],[审核],[销退货],[备注])  values(@编号 ,@销售单号 ,@货号 ,@销售数量 ,@销售价 ,@合计金额 ,@仓库 ,@审核 ,@销退货 ,@备注 )      
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_初始化]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'          CREATE PROCEDURE [dbo].[sf_初始化] AS begin transaction  	      delete from 应收款     delete from 应付款     delete from 库存库   commit       
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_盘点单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'            CREATE PROCEDURE [dbo].[sf_盘点单] AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.单价,getdate() 			FROM 盘点单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''未审'' and j.选中=''选中'' and k.货号 is null   	 	UPDATE 库存库 SET 库存数量=库存数量+盈亏ALL,库存金额=(库存数量+盈亏ALL)*库存单价,日期=getdate() 		FROM  		(SELECT 仓库,货号,''盈亏ALL''=sum(盈亏) 		FROM 盘点单明细 where 审核=''未审'' and 选中=''选中'' GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 UPDATE 盘点单明细 set 审核=''已审'',选中=''未选'' where 审核=''未审'' and 选中=''选中''  UPDATE 盘点单 set 审核=''已审'' ,选中=''未选'' where 审核=''未审'' and 选中=''选中''   commit                     
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_盘点单]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'        CREATE PROCEDURE [dbo].[new_盘点单] @单号 char(20) AS begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.单价,getdate() 			FROM 盘点单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''未审'' and j.盘点单号=@单号 and k.货号 is null   	 	UPDATE 库存库 SET 库存数量=库存数量+盈亏ALL,库存金额=(库存数量+盈亏ALL)*库存单价,日期=getdate() 		FROM  		(SELECT 仓库,货号,''盈亏ALL''=sum(盈亏) 		FROM 盘点单明细 where 审核=''未审'' and 盘点单号=@单号 GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 UPDATE 盘点单明细 set 审核=''已审'' where 审核=''未审'' and 盘点单号=@单号  UPDATE 盘点单 set 审核=''已审'' where 审核=''未审'' and 编号=@单号  commit                         
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[new_盘点单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'       CREATE PROCEDURE [dbo].[new_盘点单反审] @单号 char(20) AS  begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.单价,getdate() 			FROM 盘点单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''已审'' and j.盘点单号=@单号 and k.货号 is null   	 	UPDATE 库存库 SET 库存数量=库存数量-盈亏ALL,库存金额=(库存数量-盈亏ALL)*库存单价,日期=getdate() 		FROM  		(SELECT 仓库,货号,''盈亏ALL''=sum(盈亏) 		FROM 盘点单明细 where 审核=''已审'' and 盘点单号=@单号 GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 UPDATE 盘点单明细 set 审核=''未审'' where 审核=''已审'' and 盘点单号=@单号 UPDATE 盘点单 set 审核=''未审'' where 审核=''已审'' and 编号=@单号 commit                        
' 
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sf_盘点单反审]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'                   CREATE PROCEDURE [dbo].[sf_盘点单反审] AS  begin transaction 	 	INSERT INTO 库存库(货号,仓库,库存数量,库存金额,库存单价,日期) SELECT DISTINCT j.货号, j.仓库, 0,0,j.单价,getdate() 			FROM 盘点单明细 AS J left join 库存库 as k on ( j.仓库=k.仓库 and j.货号=k.货号 ) 			where j.审核=''已审'' and j.选中=''选中'' and k.货号 is null   	 	UPDATE 库存库 SET 库存数量=库存数量-盈亏ALL,库存金额=(库存数量-盈亏ALL)*库存单价,日期=getdate() 		FROM  		(SELECT 仓库,货号,''盈亏ALL''=sum(盈亏) 		FROM 盘点单明细 where 审核=''已审'' and 选中=''选中'' GROUP BY 仓库,货号) AS LSJ 		WHERE  库存库.仓库=LSj.仓库 AND 库存库.货号=LSj.货号  	 UPDATE 盘点单明细 set 审核=''未审'',选中=''未选'' where 审核=''已审'' and 选中=''选中''  UPDATE 盘点单 set 审核=''未审'',选中=''未选''  where 审核=''已审'' and 选中=''选中''  commit                    
' 
END

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[采购订单_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[采购订单]'))
ALTER TABLE [dbo].[采购订单]  WITH NOCHECK ADD  CONSTRAINT [采购订单_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[采购订单] CHECK CONSTRAINT [采购订单_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[进货单_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[进货单]'))
ALTER TABLE [dbo].[进货单]  WITH NOCHECK ADD  CONSTRAINT [进货单_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[进货单] CHECK CONSTRAINT [进货单_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[采购合同_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[采购合同]'))
ALTER TABLE [dbo].[采购合同]  WITH NOCHECK ADD  CONSTRAINT [采购合同_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[采购合同] CHECK CONSTRAINT [采购合同_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[采购合同_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[采购合同]'))
ALTER TABLE [dbo].[采购合同]  WITH NOCHECK ADD  CONSTRAINT [采购合同_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[采购合同] CHECK CONSTRAINT [采购合同_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[应付款_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[应付款]'))
ALTER TABLE [dbo].[应付款]  WITH NOCHECK ADD  CONSTRAINT [应付款_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[应付款] CHECK CONSTRAINT [应付款_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[应付款_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[应付款]'))
ALTER TABLE [dbo].[应付款]  WITH NOCHECK ADD  CONSTRAINT [应付款_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[应付款] CHECK CONSTRAINT [应付款_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[预收款_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[预收款]'))
ALTER TABLE [dbo].[预收款]  WITH NOCHECK ADD  CONSTRAINT [预收款_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[预收款] CHECK CONSTRAINT [预收款_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[预付款_供货商_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[预付款]'))
ALTER TABLE [dbo].[预付款]  WITH NOCHECK ADD  CONSTRAINT [预付款_供货商_fk] FOREIGN KEY([供货商号])
REFERENCES [dbo].[供货商清单] ([供货商号])
GO
ALTER TABLE [dbo].[预付款] CHECK CONSTRAINT [预付款_供货商_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_进货单明细_进货单]') AND parent_object_id = OBJECT_ID(N'[dbo].[进货单明细]'))
ALTER TABLE [dbo].[进货单明细]  WITH NOCHECK ADD  CONSTRAINT [FK_进货单明细_进货单] FOREIGN KEY([进货单号])
REFERENCES [dbo].[进货单] ([编号])
GO
ALTER TABLE [dbo].[进货单明细] CHECK CONSTRAINT [FK_进货单明细_进货单]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[进货单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[进货单明细]'))
ALTER TABLE [dbo].[进货单明细]  WITH NOCHECK ADD  CONSTRAINT [进货单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[进货单明细] CHECK CONSTRAINT [进货单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[销售单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[销售单明细]'))
ALTER TABLE [dbo].[销售单明细]  WITH NOCHECK ADD  CONSTRAINT [销售单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[销售单明细] CHECK CONSTRAINT [销售单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[调拨单历史_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[调拨单明细]'))
ALTER TABLE [dbo].[调拨单明细]  WITH NOCHECK ADD  CONSTRAINT [调拨单历史_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[调拨单明细] CHECK CONSTRAINT [调拨单历史_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[预售单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[预售单明细]'))
ALTER TABLE [dbo].[预售单明细]  WITH NOCHECK ADD  CONSTRAINT [预售单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[预售单明细] CHECK CONSTRAINT [预售单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[反审单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[反审单明细]'))
ALTER TABLE [dbo].[反审单明细]  WITH NOCHECK ADD  CONSTRAINT [反审单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[反审单明细] CHECK CONSTRAINT [反审单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[进销存汇总表_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[进销存汇总表]'))
ALTER TABLE [dbo].[进销存汇总表]  WITH NOCHECK ADD  CONSTRAINT [进销存汇总表_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[进销存汇总表] CHECK CONSTRAINT [进销存汇总表_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[报损报溢_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[报损报溢]'))
ALTER TABLE [dbo].[报损报溢]  WITH NOCHECK ADD  CONSTRAINT [报损报溢_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[报损报溢] CHECK CONSTRAINT [报损报溢_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[库存库_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[库存库]'))
ALTER TABLE [dbo].[库存库]  WITH NOCHECK ADD  CONSTRAINT [库存库_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[库存库] CHECK CONSTRAINT [库存库_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[上下限对照表_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[上下限对照表]'))
ALTER TABLE [dbo].[上下限对照表]  WITH NOCHECK ADD  CONSTRAINT [上下限对照表_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[上下限对照表] CHECK CONSTRAINT [上下限对照表_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_采购订单明细_采购订单]') AND parent_object_id = OBJECT_ID(N'[dbo].[采购订单明细]'))
ALTER TABLE [dbo].[采购订单明细]  WITH NOCHECK ADD  CONSTRAINT [FK_采购订单明细_采购订单] FOREIGN KEY([订单号])
REFERENCES [dbo].[采购订单] ([编号])
GO
ALTER TABLE [dbo].[采购订单明细] CHECK CONSTRAINT [FK_采购订单明细_采购订单]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[采购订单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[采购订单明细]'))
ALTER TABLE [dbo].[采购订单明细]  WITH NOCHECK ADD  CONSTRAINT [采购订单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[采购订单明细] CHECK CONSTRAINT [采购订单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[盘点单明细_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[盘点单明细]'))
ALTER TABLE [dbo].[盘点单明细]  WITH NOCHECK ADD  CONSTRAINT [盘点单明细_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[盘点单明细] CHECK CONSTRAINT [盘点单明细_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[销售合同_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[销售合同]'))
ALTER TABLE [dbo].[销售合同]  WITH NOCHECK ADD  CONSTRAINT [销售合同_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[销售合同] CHECK CONSTRAINT [销售合同_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[销售合同_客户编号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[销售合同]'))
ALTER TABLE [dbo].[销售合同]  WITH NOCHECK ADD  CONSTRAINT [销售合同_客户编号_fk] FOREIGN KEY([客户编号])
REFERENCES [dbo].[客户清单] ([客户编号])
GO
ALTER TABLE [dbo].[销售合同] CHECK CONSTRAINT [销售合同_客户编号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[调货申请_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[调货申请]'))
ALTER TABLE [dbo].[调货申请]  WITH NOCHECK ADD  CONSTRAINT [调货申请_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[调货申请] CHECK CONSTRAINT [调货申请_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[应收款_货号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[应收款]'))
ALTER TABLE [dbo].[应收款]  WITH NOCHECK ADD  CONSTRAINT [应收款_货号_fk] FOREIGN KEY([货号])
REFERENCES [dbo].[商品清单] ([货号])
GO
ALTER TABLE [dbo].[应收款] CHECK CONSTRAINT [应收款_货号_fk]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[应收款_客户编号_fk]') AND parent_object_id = OBJECT_ID(N'[dbo].[应收款]'))
ALTER TABLE [dbo].[应收款]  WITH NOCHECK ADD  CONSTRAINT [应收款_客户编号_fk] FOREIGN KEY([客户编号])
REFERENCES [dbo].[客户清单] ([客户编号])
GO
ALTER TABLE [dbo].[应收款] CHECK CONSTRAINT [应收款_客户编号_fk]

GO
INSERT INTO [dbo].[用户清单]
           ([用户编号]
           ,[部门]
           ,[姓名]
           ,[性别]
           ,[password]
           ,[经营权]
           ,[管理权]
           ,[价格权]
           ,[手机]
           ,[QQ]
           ,[地址]
           ,[身份证]
           ,[邮编]
           ,[简称]
           ,[拼音编码]
           ,[等级]
           ,[电话]
           ,[用户来源])
     VALUES
           ('1'
           ,''
           ,'kued'
           ,''
           ,'0c6d2fb7ce586f0583665e7bc99f0987'
           ,'J11111111111111111111111110111111111111111111'
           ,'G111111111111111111111111111111111111111111111111'                              
           ,'Q1111111111111111'                                            
           ,''
           ,''
           ,''
           ,''
           ,''
           ,''
           ,''
           ,''
           ,''
           ,'')
GO
INSERT INTO [dbo].[通知表]
           ([通知]
           ,[日期]
           ,[用户编号])
     VALUES
           ('欢迎使用本软件'
           ,getdate()
           ,'1')