SQl存储过程:销售出库更新生产周计划单出货数量和产品入库自动生成领料单


---销售出库更新生产周计划单出货数量和产品入库自动生成领料单
ALTER trigger [GF_UpdateFOUTQty] on [dbo].[ICStockBill]
for update
as

declare @FinterID int,@FStatus int,@FOldStatus int,@FTranType int

select @FinterID = FinterID,@FStatus = FStatus,@FTranType = FTranType from inserted 
select @FOldStatus = FStatus from deleted 

--销售出库单审核
    if update(FStatus) and @FStatus = 1 and @FOldStatus = 0 and @FTranType = 21
Begin
    update t2 set  t2.FOUTQty = t2.FOUTQty+b.FQty  from icstockbill a
    inner join icstockbillentry b on a.FinterID = b.FinterID
    inner join seorderentry s2 on b.FSourceInterID = s2.FinterID and b.FSourceEntryID = s2.FEntryID
    inner join t_bossczjhdentry t2 on s2.FinterID = t2.FID_SRC and s2.FEntryID = t2.FEntryID_SRC
    where a.FTranType = '21' and a.FinterID = @FinterID
END

--产品入库单审核
    if update(FStatus) and @FStatus = 1 and @FOldStatus = 0 and @FTranType = 2
Begin
--循环产品入库单每一行
        declare @i int,@j int  
        set @i=1
        select @j = max(FEntryID) from 
            (select DENSE_RANK()over(order by b.FEntryID) as FEntryID,b.FinterID from icstockbill a
            inner join icstockbillentry b on a.FinterID = b.FinterID
            where a.FinterID = @FinterID) a
        group by FinterID
        while @i<=@j
        begin
--循环产品入库关联的生产投料单每一行
                declare @FBillNO varchar(255),@FName varchar(255),@FQty decimal(28, 10),@FEntryID int

                select @FBillNO = s2.FBillNo,@FName = t1.FName,@FQty = b.FQty,@FEntryID = s1.FEntryID from icstockbill a
                inner join icstockbillentry b on a.FinterID = b.FinterID
                inner join t_icitem t1 on b.FItemID = t1.FItemID
                inner join icmo m1 on b.FSourceInterID = m1.FInterID
                inner join seorderentry s1 on m1.FOrderInterID = s1.FInterID and m1.FSourceEntryID = s1.FEntryID
                inner join seorder s2 on s1.FInterID = s2.FInterID
                where a.FInterID = @FinterID and b.FEntryID = @i

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值