七、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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM