|
本帖最后由 WZZ123000 于 2021-2-1 11:59 编辑
以下是触发器代码
想增加一行代码
以上界中委外加工商库存(供应商历史库存)=委外加工商即时库存+如果以上“仓库调拨序时薄”中审核标志<>"Y",且物料代码相同,调入仓库相同时对数量加总-如果以上“仓库调拨序时薄”中审核标志<>"Y",且物料代码相同,调出仓库相同时对数量加总
alter TRIGGER [dbo].[cst_委外加工单审核后生成已审核的调拨单]
ON [dbo].[ICOutMO]
FOR update
AS
--当供应商是%车间时,更新仓库为相同名字的仓库
--已经和工厂确认1个物料只能在一个仓库里存在,否则不允许生成调拨单
--批号管理和有效期管理的物料会自动跳过,不处理
declare @fsupid int
declare @fcheckdate datetime
declare @fcheckerid int
declare @fbillno varchar(200)
declare @多单信息 varchar(200)
declare @产品默认仓库id int
--后来决定调拨单不要自动审核了
if update(fcheckerid) and exists(select 1 from inserted where FCheckerID>0) and exists(select 1 from deleted where isnull(FCheckerID,0)=0)
begin
select @fsupid=FWWSupplyID,@fcheckdate=FCheckDate,@fcheckerid=FCheckerID,@产品默认仓库id=t.FDefaultLoc
from inserted a
inner join t_ICItem t on a.FItemID=t.FItemID
inner join t_Stock s on t.FDefaultLoc=s.FItemID
where s.FName in ('线材成品仓','模组成品仓') --只考虑产品的默认仓库是这两个仓库的
if exists(--不允许在生成调拨单时存在1个物料在多个仓库存在的情况,这个和客户进行了明确的
select 1
from (
select x.FItemID,x.FStockID,t.FNumber,t.FName,fqty=sum(FQty)
from ICInventory x (nolock)
inner join t_Stock y on x.FStockID=y.FItemID
inner join t_ICItem t on x.FItemID=t.FItemID
where t.FBatchManager=0 and t.FKFPeriod=0
and x.FQty<>0 and y.FName in ('线材原材料仓','模组原材料仓','辅材仓','A类仓(贵重)')
group by x.FItemID,x.FStockID,t.FNumber,t.FName
) aa
group by FItemID,FNumber,FName
having count(1)>1)
begin
declare @sql as varchar(2000)
select @sql='金蝶提示:物料'+FNumber+'的库存在(线材原材料仓,模组原材料仓,辅材仓,A类仓(贵重))这几个仓库中同时存在,请先调整后再来审核!'
from (
select x.FItemID,x.FStockID,t.FNumber,t.FName,fqty=sum(FQty)
from ICInventory x (nolock)
inner join t_Stock y on x.FStockID=y.FItemID
inner join t_ICItem t on x.FItemID=t.FItemID
where t.FBatchManager=0 and t.FKFPeriod=0
and x.FQty<>0 and y.FName in ('线材原材料仓','模组原材料仓','辅材仓','A类仓(贵重)')
group by x.FItemID,x.FStockID,t.FNumber,t.FName
) aa
group by FItemID,FNumber,FName
having count(1)>1
ROLLBACK tran
RAISERROR(@sql,18,18)
return
end
select
a.FInterID,b.FEntryID,a.FBillerID,
委外加工单号=a.FBillNo,日期=a.FDate,a.FWWSupplyID,加工商=sup.FName,fstockid=s.FItemID,
t.FItemID,t.FUnitID,t.FQtyDecimal,物料代码=t.FNumber,委外加工单数量=a.FQty,父件物料代码=tp.FNumber,计划用量=b.FPlanQty,
单位用量=round(b.FPlanQty/a.FQty,t.FQtyDecimal),
fid=ROW_NUMBER()over(PARTITION by a.FWWSupplyID,b.fitemid order by a.FWWSupplyID,b.fitemid,a.fdate,a.fbillno),--这个决定分配的结果
未发数量=round(b.FPlanQty-b.FDiscountQty,t.FQtyDecimal),
加工商库存=cast(0 as decimal(18,10)),累计缺料数量=cast(0 as decimal(18,10)),缺料数量=cast(0 as decimal(18,10)),
公司库存=cast(0 as decimal(18,10)),
调出仓库id=cast(0 as decimal(18,10)),
累计调拨数量=cast(0 as decimal(18,10)),调拨数量=cast(0 as decimal(18,10))
into #cst_未发料的委外加工单
from ICOutMO a
inner join ICOutMOEntry b on a.FInterID=b.FInterID
inner join t_ICItem t on b.FItemID=t.FItemID
inner join t_ICItem tp on a.FItemID=tp.FItemID
inner join t_Supplier sup on a.FWWSupplyID=sup.FItemID
inner join t_Stock s on sup.FName=s.FName
inner join t_ICItem t1 on a.FItemID=t1.FItemID
inner join t_Stock s1 on t1.FDefaultLoc=s1.FItemID
where sup.FName like '%车间'
and s1.FItemID=@产品默认仓库id --只考虑和审核的委外加工单产品默认仓库一致的委外加工单
and a.FDate>cast('2020-01-01' as datetime)
and a.FCancellation=0 and a.FStatus=1 --0未审核和3已关闭,都不考虑
and t.FBatchManager=0 and t.FKFPeriod=0 --不考虑批次管理的和保质期管理的物料
and b.FPlanQty>b.FDiscountQty
and a.FWWSupplyID=@fsupid --相同的供应商
and a.FDate<=@fcheckdate --单据日期<=当前审核日期
......
详细代码在附件,谢谢各位大神!
|
|