七、K3 WISE 开发插件《Update字段级更新触发器 - BOS单审核后反写源单》

审核成功触发,是一个比较典型的场景。需要用到update触发器,跟踪到审核状态的变化。

引用的源码《采购检验单审核后反写收料通知单》,其中采购检验单是BOS自定义单据。

if (object_id('bobang_tgr_check_update', 'TR') is not null)
    drop trigger bobang_tgr_check_update
go
create trigger cl_tgr_check_update
on bobang_bos_check
after update
as 
declare @FID int
declare @FMultiCheckStatus  varchar(100)
declare @FAuxQtyPass float --合格数量
declare @FQtyPass float --基本单位合格数量
declare @FAuxNotPassQty float --不合格数量
declare @FNotPassQty float --基本单位不合格数量
declare @FAuxConPassQty float --让步接收数量
declare @FConPassQty float --基本单位让步接收数量
declare @FID_Src bigint --源单ID
declare @FEntryID_SRC bigint --源单FEntryID

select @FID=FID,@FMultiCheckStatus=FMultiCheckStatus
from inserted

--审核时
if update(FMultiCheckStatus) and @FMultiCheckStatus=16 
begin 
    declare mycursor cursor for 
    select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src 
    from bobang_bos_checkentry where FID=@FID
    open mycursor  
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    while (@@fetch_status=0) 
    begin 
        update t1 
        set t1.FAuxQtyPass=t1.FAuxQtyPass+isnull(@FAuxQtyPass,0),
        t1.FQtyPass=t1.FQtyPass+isnull(@FQtyPass,0),
        t1.FAuxNotPassQty=t1.FAuxNotPassQty+isnull(@FAuxNotPassQty,0),
        t1.FNotPassQty=t1.FNotPassQty+isnull(@FNotPassQty,0),
        t1.FAuxConPassQty=t1.FAuxConPassQty+isnull(@FAuxConPassQty,0),
        t1.FConPassQty=t1.FConPassQty+isnull(@FConPassQty,0)
        from POInStockEntry t1 
        left join POInStock t2 on t1.FInterID=t2.FInterID
        where t1.FInterID=@FID_Src and t1.FEntryID=@FEntryID_SRC
        and t2.FTranType=72
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    end 
    close mycursor 
    DEALLOCATE mycursor 
end 

--驳回前检查
declare @isTuiLiao int
declare @isRuKu int
if update(FMultiCheckStatus) and @FMultiCheckStatus=4 
begin 
    declare mycursor cursor for 
    select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src 
    from bobang_bos_checkentry where FID=@FID
    open mycursor  
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    while (@@fetch_status=0) 
    begin 
        select @isTuiLiao=COUNT(*) from POInStockEntry 
        where FSourceTrantype=72 and  FSourceInterId=@FID_Src and FSourceEntryID=@FEntryID_SRC
        if @isTuiLiao>0
        begin
            raiserror ('已下推退料通知单,不能反审核!',16,1)
            rollback tran    
        end
        
        select @isRuKu=COUNT(*) from ICStockBillEntry 
        where FSourceTrantype=72 and  FSourceInterId=@FID_Src and FSourceEntryID=@FEntryID_SRC
        if @isTuiLiao>0
        begin
            raiserror ('已下推外购入库单,不能反审核!',16,1)
            rollback tran    
        end
        
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    end 
    close mycursor 
    DEALLOCATE mycursor 
end

--驳回初始时
if update(FMultiCheckStatus) and @FMultiCheckStatus=2 
begin 
    declare mycursor cursor for 
    select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src 
    from bobang_bos_checkentry where FID=@FID
    open mycursor  
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    while (@@fetch_status=0) 
    begin 
        update t1 
        set t1.FAuxQtyPass=t1.FAuxQtyPass-isnull(@FAuxQtyPass,0),
        t1.FQtyPass=t1.FQtyPass-isnull(@FQtyPass,0),
        t1.FAuxNotPassQty=t1.FAuxNotPassQty-isnull(@FAuxNotPassQty,0),
        t1.FNotPassQty=t1.FNotPassQty-isnull(@FNotPassQty,0),
        t1.FAuxConPassQty=t1.FAuxConPassQty-isnull(@FAuxConPassQty,0),
        t1.FConPassQty=t1.FConPassQty-isnull(@FConPassQty,0)
        from POInStockEntry t1 
        left join POInStock t2 on t1.FInterID=t2.FInterID
        where t1.FInterID=@FID_Src and t1.FEntryID=@FEntryID_SRC
        and t2.FTranType=72
    fetch next from mycursor 
    into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC
    end 
    close mycursor 
    DEALLOCATE mycursor 
end 

 

转载于:https://www.cnblogs.com/star-studio/p/7483908.html

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值