Kingdee 供应链出入库老单删除触发器1(随笔记录)

 1 IF  EXISTS (select name from sysobjects where name='tr_XX')
 2 DROP TRIGGER tr_XX
 3 GO
 4 CREATE TRIGGER tr_XX
 5 ON dbo.ICStockBillEntry
 6 FOR DELETE
 7 as
 8 BEGIN  
 9     DECLARE @FInterID        AS INT,
10     @FTranType            AS INT,
11     @FBillNo                AS NVARCHAR(50),
12     @FEntryID                AS INT 
13     
14     declare @table0 table
15         (FInterID   INT,
16         FEntryID    INT)
17         
18         insert into @table0
19         (FInterID,FEntryID)
20         SELECT FInterID,FEntryID FROM DELETED    
21     
22     WHILE EXISTS(SELECT 1 FROM @table0)
23         BEGIN
24             SET ROWCOUNT 1
25             SELECT @FInterID=FInterID,@FEntryID=FEntryID FROM DELETED
26             IF @FInterID > 0 
27                 BEGIN
28                     SELECT @FTranType=FTranType,@FBillNo=FBillNo FROM dbo.ICStockBill WHERE FInterID=@FInterID
29                     IF @FTranType > 0 
30                         IF @FTranType=1 OR @FTranType=2 OR @FTranType=5 OR @FTranType=10 OR @FTranType=21 OR @FTranType=24 OR @FTranType=28 OR @FTranType=29 OR @FTranType=41
31                                 -- 业务逻辑处理
32                             END    
33                 END
34             DELETE FROM @table0 WHERE FInterID=@FInterID AND FEntryID=@FEntryID
35             SET ROWCOUNT 0
36         END    
37 END
38 GO

  该触发器 主要是想 针对K3供应链出入库老单删除单据或单据中一行或多行物料 时 触发追加的业务逻辑处理 。 经过测试 发现该触发器 在sql server 查询分析器上执行删除事务该触发器的业务逻辑可以执行,但是在K3客户端进行单据删除操作,触发器的业务逻辑没有被执行。后跟踪K3删除单据sql脚本,发现K3单据删除有两种情况:

  1、整张单据删除:K3是先执行“delete from ICStockBill where FInterID=XXXX”,接着执行“delete from ICStockBillEntry whereFInterID=XXXX”;

  2、单据删除部分,由于K3是操作是进去K3选中一行 点击菜单栏删除按钮进行删除 然后保存.sql执行顺序是:"DELETE ICStockBill WHERE FInterID=xxxx  ----> INSERT INTO StockBillEntry ........   ----> INSERT INTO ICStockBill...... ----->UPDATE ICStockBill .......".  

  由跟踪出来的信息可知K3单据删除都是先删除 单据头表:ICStockBill ,由于该触发器是单据体表(ICStockBillEntry)的触发器,并且在该触发器中 需要查询单据头表的单据类型(FTranType)等信息 作为下步判断逻辑处理等,但是在此处 单据头该单据信息已被删除,查出来为空。进而不能下步的处理,所以该触发器处理失效.   由于对K3单据删除时 K3是怎么处理 不清楚,上面分析都是本人自己跟踪测试 个人分析出来的。所以在K3中如果需要需要处理这样的业务逻辑,该怎么处理?

PS:在此处记录下来,以后如果有很好的解决办法再来解答...

转载于:https://www.cnblogs.com/424445716zb/archive/2012/05/25/2517914.html

CREATE trigger icstockbill_check --实现对物料单据管控 on Icstockbill for insert as Declare @Ftrantype int --单据类别定义/生产领料单24/调拔单41/销售出库单21 Select @Ftrantype=Ftrantype from inserted --控制领料单的领料日期不能小于生产任务单的计划开工日期 倒扣物料只能车间仓库发料 if (@Ftrantype=24) begin declare @icmo varchar(20) declare @message varchar(200) declare @message0 varchar(200) declare @message00 varchar(200) declare @message000 varchar(200) declare @finterid240 int set @message='错误!领料日期不能小于生产任务单计划开工日期,请与生管人员联系!错误单号:' set @message0='生产领料单发料仓库不正确,倒扣物料不能从 原料仓/半成品仓/成品仓 发料' set @message00='已完工生产任务单不能跨月领料.请检查领料日期!' set @message000='生产领料单必需关联源生产任务单号,请重新录入单据!' if exists ( select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid where t2.ficmointerid=0 ) begin RAISERROR(@message000,18,18) ROLLBACK end if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdateCast(year(max(t4.fdate)) as int(10))*100+Cast(month(max(t4.fdate)) as int(5)) ) begin RAISERROR(@message00,18,18) ROLLBACK end --更新领料单上的销售订单号 select @finterid240=finterid from inserted update t2 set t2.fentryselfb0445=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=24 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid240 return end --控制委外加工生产任务单领料日期不对小于计划开工日期 if (@Ftrantype=28) begin declare @icmo3 varchar(20) declare @message3 varchar(200) set @message3='错误!委外加工发出日期不能小于对应委外加工生产任务单计划开工日期,请与采购人员联系变更!错误单号:' if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdate0 and t1.fdate0 and t1.fdate<t3.FPlanCommitDate set @message4=@message4+@icmo4 RAISERROR(@message4,18,18) ROLLBACK end ; --更新产品入库单上的销售订单号 select @finterid20=finterid from inserted update t2 set t2.fentryselfa0236=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=2 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid20 return end ---更新委外加工入单销售订单号 if (@Ftrantype=5) begin update t2 set t2.fentryselfa0548=t4.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid inner join seorder as t4 on t4.finterid=t3.forderinterid return end ---控制出全部出货的销售订单所对应的采购订单不能退料(红字外购入库单) /*if (@Ftrantype=1) begin declare @message500 varchar(200) set @message500='已全部出货的销售订单所对应的采购订单不能退料!请检查您所退料的采购订单号码是否正确!' if exists (select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join seorder as t3 on t3.fbillno=t2.fentryselfa0152 where t2.fqty<0 and t3.fclosed=1 ) begin RAISERROR(@message500,18,18) ROLLBACK end return end */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值