产品入库更新生产任务单工时


CREATE TRIGGER [update_ICS_gongshi]		--自定义触发器的名称 
			ON [dbo].[ICStockBillEntry]		--出入库单据分录表 此处为表名,触发器的表名,意为在哪个表创建触发
FOR INSERT,UPDATE,DELETE		--触发类型:INSERT、UPDATE、DELETE;分别意为插入时、更新时、删除时触发,依据英文意思理解即可
AS   
    SET NOCOUNT ON  
DECLARE @FICMOInterID  int;		--声明变量:FInterID 生产任务单内码

select @FICMOInterID = MAX(FICMOInterID) --取当前插入或更新单据的生产任务单内码赋值给@FRoutingID
from (select FICMOInterID FROM inserted union all select FICMOInterID FROM deleted)a

BEGIN
    /*更新生产任务单工时*/
update ICMO			--更新生产任务单工时
set FHeadSelfJ01108 = FHeadSelfJ01107 * (FAuxQty - FAuxStockQty)
from ICMO
where FInterID = @FICMOInterID

END


drop trigger [update_ICS_gongshi]

select * from ICStockBill
where FTranType = 2		--单据类型2,产品入库单'139764'
and FCancellation != 0


FOrgBillInterID		--原单内码


select * from ICStockBillEntry
where FICMOBillNo = 'JT21897-3(WJW-14310-SJT7)'		--生产任务单号

and FFatherProductID = ''			--产品内码
and FICMOBillNo = ''		--生产任务单号
and FICMOInterID = ''		--任务单内码
and FInStockID = ''			--入库单内码
and FSCBillInterID = ''		--原单内码
and FSCBillNo = ''			--原单单号
and FSourceInterId = ''		--源单内码'87646'
and FSourceTranType = ''	--源单类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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、付费专栏及课程。

余额充值