文件名称:K3触发器实现对物料单据管控 .txt
文件大小:11KB
文件格式:TXT
更新时间:2012-11-25 05:11:11
K3触发器实现对物料单据管控 .txt
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.fdate