📄 手机入库存储过程.sql
字号:
/***********************************************
手机入库存储过程
作者:陈银军
日期:2005.8.10
***********************************************/
CREATE PROCEDURE pSjrcDetail
@VAct int,--操作类型,1为insert,2为edit,3为del
@VModel char(5),--手机型号
@VColor char(4),--手机颜色
@VJbpz char(3),--基本配置
@VId char(12),--流水线号
@VNo char(16),--手机串号
@VMoney int,--手机价格
@VGl char(200),--手机功能
@VHyd char(4),--货源地
@VHylx char(2),--货源类型
@dat datetime,--日期型
@vbsid char(12),--报损表ID
@vcmon money,--补差价
@vomon money--手机价
--@lh int,--为1则删除领货记录
--@IDType char(2),--流水号ID
--@IDTypehrxx char(2),--手机串号入库详细流水号
--output --返回的内部单号
AS
begin
declare @Symbol nvarchar(2)
declare @ErrorMsg nvarchar(200)
declare @hrcid char(12)
declare @IDType char(2)
declare @numb int
declare @tempid char(12)
declare @OutNumber char(13)
declare @fno char(16)
declare @nobad int--判断是否损坏1为损坏,2为没损坏
declare @lx int --判断是换货机,还是重新入库机,1为换货机,2为重新入库机
declare @count int
Set NoCount On
Begin Tran
--设定延时
SET LOCK_TIMEOUT 5000
--得到厂家返回时的机子状况
if @vhylx='CF'
begin
/*
如果两者的串号相等的话,则表示前后的机子没有坏,而是误认为坏,被厂家返回
处理方式:
1:换货等待机子,标记换货等待表记录里面的fbad的值为'F',删除报损表单,不进行重新入库
2: 重新入库的机子,进行重新入库,删掉报损表单,备注栏里加上“本机报损失误而返回重新入库”
*/
set @fno=(select fno from thrxx where fid=(select fhrxx from tbs where fid=@vbsid))
if @fno=@VNo
set @nobad=1
else
set @nobad=2
set @count=(select count(*) from thhdd where fhrxx=(select fhrxx from tbs where fid=@vbsid))
if @count=1
set @lx=1--为换货类型
else
set @lx=2--为重新入库类型
end
set @numb=4
if @VAct=1 --添加记录
begin
if (@vhylx<>'CF')or((@vhylx='CF')and(@nobad=2))or((@vhylx='CF')and (@lx=2))
begin
--取手机定单入库的@HRcid
--设定手机订单入库的ID类别
set @IDType='SR'
exec pGetID @IDType,@numb,@OutNumber Output
if @@Error<>0
Goto Failed
set @hrcid=@OutNumber
--首先添加手机入库记录
insert into thrc(fid,fsjxh,fnum,fjbpz,fmon,fhylx,fdate,fmemo,fhyd) values(@OutNumber,@VModel,1,@VJbpz,@VMoney,@VHylx,@dat,@VGl,@VHyd)
if @@Error<>0
Goto Failed
--再次添加手机的详细串号入库
--设定手机串号入库的ID类别
set @IDType='SX'
exec pGetID @IDType,@numb,@OutNumber Output
if @@Error<>0
Goto Failed
set @tempid=@OutNumber
insert into thrxx(fid,fno,fcolor,fhrcid,fmon) values(@OutNumber,@VNo,@VColor,@hrcid,@VMoney)
if @@Error<>0
Goto Failed
end
if @vhylx='CF'
begin
if @nobad=2 --如果换了新机则填写报损返回表单
begin
set @IDType='BF'
exec pGetID @IDType,@numb,@OutNumber Output
if @@Error<>0
Goto Failed
--添加厂家返回记录
insert into tbsfh(fid,fbs,fhrxx,fdate,fmon,fomon)values(@OutNumber,@vbsid,@tempid,@dat,@vcmon,@vomon )
end
if @nobad=1 --没有损坏,则删除报损表单
begin
delete from tbs where tbs.fid=@vbsid
if @lx=1 --如果是换货等待的
update thhdd set fbad='F' where thhdd.fhrxx=(select fhrxx from tbs where fid=@vbsid)
end
end
END
if @VAct=2
begin
if @vhylx='CF'
update tbsfh set fdate=@dat,fmon=@vcmon where tbsfh.fhrxx=@VId
--更改此手机的价格,在串号入库中,当此时候更改的价格,只有等于原来的进货价的时候才能被更改,
--不等于时就发生了保价行为,所以此时应以保价来销售
update thrxx set fmon=@VMoney where fmon=(select fmon from thrc where fid in (select fhrcid from thrxx where fid=@Vid))
--修改手机订单入库
update thrc set fsjxh=@VModel,fjbpz=@VJbpz,fmemo=@VGl ,fmon=@VMoney,fdate=@dat where fid in(select fhrcid from thrxx where fid=@VId)
if @@Error<>0
Goto Failed
--修改手机串号入库
update thrxx set fno=@VNo,fcolor=@VColor where fid=@VId
if @@Error<>0
Goto Failed
end
if @VAct=3
begin
if @vhylx='CF'
delete from tbsfh where fhrxx=@VId
--删除领货记录
While (Select Count(*) from tgtlh where tgtlh.fhrxx=@VId)>0
delete from tgtlh where tgtlh.fhrxx=@VId
if @@Error<>0
Goto Failed
--删除手机订单入库
delete from thrc where fid in (select thrxx.fhrcid from thrxx where fid=@VId)
if @@Error<>0
Set @ErrorMsg='数据被锁定,请求超时!'
--删除手机串号入库记录
delete from thrxx where fid=@VId
if @@Error<>0
Goto Failed
end
Goto Succeed
Failed:
RaisError(@ErrorMsg,16,1)
Rollback Tran
Set NoCount Off
Return 1
Succeed:
Commit Tran
Set NoCount Off
Return 0
End
GO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -