七K3开发插件《审核成功反写触发器》

Posted 林枫山(新手培训教程)

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了七K3开发插件《审核成功反写触发器》相关的知识,希望对你有一定的参考价值。

审核成功触发,是一个比较典型的场景。需要用到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 

 

以上是关于七K3开发插件《审核成功反写触发器》的主要内容,如果未能解决你的问题,请参考以下文章

k3 wise 序时簿二次开发2

K3 cloud 老版本 建立单据关联关系

在金蝶 k3 的工业单据中的事件 m_BillTransfer_HookInvoke

K3开发文档《K3 WISE常用数据表整理》

金蝶k3销售出库单不能审核,出现“审核单据时出错,”原因,由于数据移动,不能以NOLOCK方式扫描

金蝶k3销售出库单不能审核,出现“审核单据时出错,”原因,由于数据移动,不能以NOLOCK方式扫描