日期:2014-05-17 浏览次数:20439 次
if exists(select name from sysobjects where name='NonSaleOut'and type='p')
drop procedure NonSaleOut
go
create procedure NonSaleOut
@danh varchar(50)--单号
as
begin
declare @goods_count int--配送出库产品种类(总行数)
declare @goodsid varchar(50)--商品条码
declare @goodsname varchar(50)--商品名称
declare @kucun_count float --库存数量
declare @ps_count float --配送单某条码的数量
declare @ps_number int --配送明细单序号
declare @check int --检验数量
declare @kdbm varchar(50)--开单部门
declare @bmbm varchar(50)--开单部门代码
declare @shck varchar(50)--收货仓库
declare @ckbm varchar(50)--收货仓库代码
declare @kdsj varchar(50)--开单时间
declare @id varchar(50) --退货单id号
declare @jbr varchar(50) --经办人
declare @jine float--商品销售价
declare @remark varchar(50)--备注
declare @errno int
set @errno=0
set @check=0
set @ps_number=0--配送明细单序号,初始为0
select @goods_count=count(*) from NONSALEOUTDETAIL where danh=@danh--获取配送单商品种类数量
select @kdbm=kdbm,@bmbm=bmbm,@shck=shck,@ckbm=ckbm,@kdsj=kdsj,@jbr=jbr from NONSALEOUTDOC where danh=@danh
SELECT IDENTITY(int, 1,1) AS id,convert(int,gid)as gid,danh,goodsname,goodsid,shul,jine,remark into #nonsaleout from NONSALEOUTDETAIL where danh=@danh
Begin TransAction --事务开始
while (@ps_number<@goods_count)
begin
set @ps_number=@ps_number+1--配送明细单序号自增一
select @goodsname=goodsname,@goodsid=goodsid,@ps_count=shul,@jine=jine,@id=gid,@remark=remark from #nonsaleout where id=@ps_number--获取某条细单的商品名称,商品条码,数量
select @kucun_count=count(*) from QL_SSTORE_GOODS where goodsid=@goodsid
if (@kucun_count>0)
begin
update GOODS set stock=convert(numeric(18,2),(stock-@ps_count)) where goodsid=@goodsid
set @errno=@errno+@@error
insert into CHANGES(gsdh,goodsname,goodsid,shul,jine,kdsj,kdry,remark) select danh,goodsname,goodsid,-shul,jine,convert(varchar(20),getdate(),120),@jbr,'aa' from NONSALEOUTDETAIL where danh=@danh and goodsid=@goodsid and gid=@id