触发器:出货调整单

alter trigger GF_出货调整单 on t_AdjustBill
for update 
as 


declare @FID int,@FStatus int,@FOldStatus int


select @FID = FID,@FStatus = FMultiCheckStatus from inserted 
select @FOldStatus = FMultiCheckStatus from deleted 

declare @FID_1 int 
select @FID_1 = max(FID) from icchange 

--declare @error_mes varchar(1000)
--set @error_mes='验货日:'+CONVERT(varchar(100), @FDateyh, 23)+'超出数量,请调整'


--订单通知单启动审核
if update(FMultiCheckStatus) and @FStatus = 4 and @FOldStatus = 2 

begin


---满足条件插入

        insert into icchange(FID,FClassTypeID,FTranType,FBillNo,FDate,FBillerID,FEmpID,FStatus,FDeptID,FExchangeRateType,FPrintCount)
        select CAST(@FID_1+b.Findex as int),'1007001','1',a.FBillNo+'*'+cast(b.Findex as nvarchar(50)) ,a.FDate,a.FBiller,a.FEmpID,'0',a.FDeptID,a.FExchangeRateType,'0' 
        from t_AdjustBill a
        inner join t_AdjustBillentry b on a.FID =b.FID
        where a.FID = @FID    

        insert into icchangeentry(FID,Findex,FMtrlType,FitemID,FAuxPropID,FUnitID,FQty,FBaseQty,FSecQty,FSecCoefficient,FKFPeriod,FPeriodDate,FBatchNo,FStockID,FSPID,FCostPercentage,FPlanMode,FStockQty,FSRCID,FSRCEntryID) 
        select CAST(@FID_1+b.Findex as int),'1','0',b.FitemID,'0',b.FUnitID,b.FQty,b.FQty,'0','0','0','1900-01-01',b.FForecastNo,'120074','0','0','14036','0',b.FID,b.FEntryID 
        from t_AdjustBill a
        inner join  t_AdjustBillentry b on a.FID =b.FID
        where a.FID = @FID

        insert into icchangeentry(FID,Findex,FMtrlType,FitemID,FAuxPropID,FUnitID,FQty,FBaseQty,FSecQty,FSecCoefficient,FKFPeriod,FPeriodDate,FBatchNo,FStockID,FSPID,FCostPercentage,FPlanMode,FStockQty,FSRCID,FSRCEntryID)
        select CAST(@FID_1+b.Findex as int),'2','1',b.FitemID,'0',b.FUnitID,b.FQty,b.FQty,'0','0','0','1900-01-01',a.FbillNo,'120074','0','0','14036','0',b.FID,b.FEntryID 
        from t_AdjustBill a
        inner join  t_AdjustBillentry b on a.FID =b.FID
        where a.FID = @FID    

--        update c2 set c2.FBatchNo = t2.FGMPBatchNo from seorder  a
--        inner join seorderentry b on a.finterid = b.finterid
--        inner join icchangeentry c2 on c2.FSRCID = b.FinterID and c2.FSRCEntryID = b.FEntryID
--        left join  seorder t1  on b.FEntrySelfS0177 = t1.FBillNo 
--        inner join  icmo t2  on t1.FinterID = t2.ForderInterID and b.FitemID = t2.FitemID
--        inner join seorderentry s1 on t2.ForderInterID = s1.FinterID and t2.FSourceEntryID = s1.FEntryID
--        inner join t_bosddtzdentry d1 on b.FSourceInterID = d1.FID and b.FSourceEntryID = d1.Findex
--        inner join t_bosddtzdentry d2 on s1.FSourceInterID = d2.FID and s1.FSourceEntryID = d2.Findex and d1.ForderNo = d2.ForderNo
--        where a.FinterID = @FinterID and t2.FCancellation = '0' and c2.FMtrlType = 0 

end

猜你喜欢

转载自blog.csdn.net/qq_41969460/article/details/87880090