金蝶K3采购报价单审核后自动写入采购价格管理来控制采购订单价格(二)

之前金蝶K3采购报价单审核后自动写入采购价格管理来控制采购订单价格 在使用过程中发现,金蝶自带的采购报价单有问题:供应商能选择禁用的供应商。 一查bos才知道原来是取自供应商档案的。而禁用供应商,供应商档案又不会自动禁用的

 要解决这问题。只有不用不用采购报价单自带的供应商,自己定义一个供应商,取自基础数据的供应商。

1、通过跟踪查到自定义的供应商在数据库中字段名为FBase , 把原来数据的供应商ID的值更新到自定义的供应商字段上

 update   ICSMQuotation   set FBase= FVendorID  ;

2、重建视图v_ICSMQuotation,让视图有FBase字段

drop view v_ICSMQuotation;
 go
 create view v_ICSMQuotation
  as select m.*,e.FItemID,FAuxTaxPrice from  ICSMQuotationEntry e  left join  ICSMQuotation m on  m.FID=e.FID  and  m.FClassTypeID=1007311 ;
 go

3、修改触发器ICSMQuotationEntry_insert,参数@FVendorID的取自

ALTER trigger [dbo].[ICSMQuotationEntry_insert]
  on [dbo].[ICSMQuotationEntry]
  after insert
 as
  declare @FVendorID varchar(50),
   @FItemID varchar(50),@FID varchar(50), @count int,@FItemName varchar(500), @msg  varchar(1000)
  
   select  @FItemID=FItemID from inserted;
   select @FVendorID=FBase  from ICSMQuotation where FID  in(select FID from inserted)
   select  @FID=FID from inserted;
    select @count= COUNT(1) FROM v_ICSMQuotation  WHERE FVendorID=@FVendorID and FItemID=@FItemID    
 if @count>1
begin
 select @FItemName=  fname from t_ICItem  where FItemID=@FItemID;
   set @msg='物料【'+@FItemName+'】'+'报价已经存在,不能再增加,只能执行修改数据'
  --  RAISERROR( @FID   ,1,1)
    RAISERROR(@msg,1,1)
	ROLLBACK TRANSACTION
end 
else
	begin
		 update ICSMQuotationEntry set FNOTE2=
		    (select  top 1 '在时间'+CONVERT(varchar(20),fstartdate,120) +'定价'  +CAST(   fprice  as varchar(50))   from t_SupplyHis  
		    where  fsupid=@FVendorID  and fitemid=@FItemID  order by fdeldate desc )
		  where FID=@FID and fitemid=@FItemID
	end
	

4、修改试图ICSMQuotationEntry_update参数@FVendorID的取自

 -----4、创建触发器 修改报价单的价格要取历史数据信息写入到表中--------------

	ALTER TRIGGER [dbo].[ICSMQuotationEntry_update]
   ON  [dbo].[ICSMQuotationEntry]
   after UPDATE 
 as
 if update (FAuxTaxPrice)
 begin
  declare @FVendorID varchar(50),
   @FItemID varchar(50),@FID varchar(50), @count int,@FItemName varchar(500), @msg  varchar(1000)
  
   select  @FItemID=FItemID from inserted;
   select @FVendorID=FBase  from ICSMQuotation where FID  in(select FID from inserted)
   select  @FID=FID from inserted;
  update ICSMQuotationEntry set FNOTE2=
		    (select  top 1 '在时间'+CONVERT(varchar(20),fstartdate,120) +'定价'  +CAST(  fprice  as varchar(50))   from t_SupplyHis  
		    where  fsupid=@FVendorID  and fitemid=@FItemID  order by fdeldate desc )
		  where FID=@FID and fitemid=@FItemID

 end

5、修改触发器inserted.FVendorID改为 inserted.FBase

-------5 触发器处理  审核报价单,把价写入到采购价格管理   反审价格单,把采购价格管理数据删除        -----
ALTER TRIGGER [dbo].[ICSMQuotation_update]
   ON  [dbo].[ICSMQuotation]
   after UPDATE
AS 
   declare @FVendorID varchar(50),@FID varchar(50);
 declare @FItemIDtable table (FVendorID varchar(50), FItemID varchar(50))    
   if update (FCheckerID)
   begin
     
      if exists (SELECT 1 FROM inserted  WHERE FCheckerID <> 0)                                                                             
      ---审核
       BEGIN 
       
          if exists (SELECT 1 FROM t_Supply   inner  join ICSMQuotationEntry on ICSMQuotationEntry.FItemID=t_Supply.FItemID
              inner join inserted on    t_Supply.FSupID =inserted.FBase  and   inserted.fid=ICSMQuotationEntry.fid        
              where t_Supply.FPType=1)
             begin  --如果存在就更新  
		  --更新最高价格		
			update t_Supply set FPOHighPrice=ICSMQuotationEntry.FAuxTaxPrice,FcheckDate= GETDATE() from t_Supply 
				   inner  join ICSMQuotationEntry on ICSMQuotationEntry.FItemID=t_Supply.FItemID
				   inner join inserted on    t_Supply.FSupID =inserted.FBase  and   inserted.fid=ICSMQuotationEntry.fid        
				   where t_Supply.FPType=1
			 --更新报价      
			update t_SupplyEntry 
					 set FPrice=ICSMQuotationEntry.FAuxTaxPrice ,
					   FUsed=1,
					  FCheckerID=inserted.FCheckerID,
					   FCheckDate=GETDATE(),
					   FQuoteTime=GETDATE(),
					   FDisableDate='2100-01-01 00:00:00.000',
					   FLastModifiedBy =inserted.FCheckerID,
					   FLastModifiedDate=GETDATE(),
					   FRemark=inserted.FBillNo+'报价单自动更新'
					 from t_SupplyEntry 
				   inner  join ICSMQuotationEntry on ICSMQuotationEntry.FItemID=t_SupplyEntry.FItemID
				   inner join inserted on    t_SupplyEntry.FSupID =inserted.FBase  and   inserted.fid=ICSMQuotationEntry.fid     
				   where t_SupplyEntry.FPType=1
	  end
	     else
		   begin-- 插入
			  DECLARE @FInterID INT;
			   exec GetICMaxNumOld 't_Supply', @FInterID output  
			 
		 
		 
		  INSERT INTO t_SupplyEntry	([FBrNo],[FSupID],[FItemID] ,[FEntryID],[FUnitID] ,[FStartQty],[FEndQty] ,[FPrice] ,[FCyID],[FDiscount],[FLeadTime],[FQuoteTime],[FUsed],[FDisableDate],[FRemark]
			   ,[FPType] ,[FLastModifiedDate],[FLastModifiedBy],[FCheckerID],[FCheckDate])
		  select 0,b.FBase,a.FItemID ,@FInterID,a.FUnitID,0,0, a.FAuxTaxPrice,b.FCurrencyID,0,0,GETDATE(),1,'2100-01-01 00:00:00.000',b.FBillNo+'报价单自动更新',
		  1,GETDATE(),b.FBiller, b.FCheckerID,GETDATE()
		   from ICSMQuotationEntry a   join inserted b on a.FID= b.FID
		 
		  
		  
		     INSERT INTO t_Supply (FBrNo,FItemID,FSupID,FCurrencyID,FPOHighPrice,FPType,FcheckDate) 
		     select 0,a.FItemID, b.FBase,b.FCurrencyID ,a.FAuxTaxPrice*1.05,1, GETDATE() from ICSMQuotationEntry a   join inserted b on a.FID= b.FID
		     
		        
		  end
       end   
       
       else
       --反审
          begin          
           select  @FVendorID=FBase from inserted;   
           select  @FID=FID from inserted; 
         
         delete @FItemIDtable;
          insert  into @FItemIDtable (FVendorID,FItemID)
           select v.FBase,v.FItemID from v_ICSMQuotation v where FClassTypeID='1007311' and  v.FBase=@FVendorID  and  v.FID=@FID
  
  delete       t_SupplyEntry   where  FPType=1 and FSupID   in (select  FVendorID  from  @FItemIDtable) and FItemID  in (select  FItemID  from  @FItemIDtable)
   delete     t_Supply where FPType=1 and FSupID   in (select  FVendorID  from  @FItemIDtable) and FItemID  in (select  FItemID  from  @FItemIDtable)
     
      
          end
       
   end

6、修改触发器POOrder_insert

  --- 采购订单触发器
   ALTER trigger [dbo].[POOrder_insert]
  on [dbo].[POOrder]
  after insert
 as
  declare @FVendorID varchar(50),@FInterID varchar(50),
   @count int,@FItemName varchar(500), @msg  varchar(1000),@FValue varchar(50)
   declare @FItemIDtable table (FVendorID varchar(50), FItemID varchar(50),FName varchar(500))    
  
  select @FValue=FValue  from t_SystemProfile where FCategory='IC' and  FKey='meiyoubaojiabunengbaocun'  
  if @FValue=1
   begin
		   select  @FVendorID=FSupplyID from inserted;
		   select  @FInterID=FInterID  from  inserted;	
		   insert  into @FItemIDtable (FVendorID,FItemID,FName)
		      select @FVendorID,FItemID,(select top 1 fname from t_ICItem  where FItemID=pe.FItemID)as FName from  POOrderEntry pe where  FInterID =@FInterID
		      and FItemID not  in (select FItemID from  ICSMQuotationEntry e  where  FID  in(select FID from  ICSMQuotation  where FBase=@FVendorID and fcheckdate  is not  null) )
             select @count= COUNT(1) FROM @FItemIDtable   
		 if @count>0
		begin
		 select @msg=   ( stuff((select ',' + FName from @FItemIDtable   for xml path('')), 1, 1, '') ) from   @FItemIDtable 
		   set @msg=@msg+ '    如上物料没有报价,请先创建报价单或审核报价单后,再操作'
			RAISERROR(@msg,18,18)
			ROLLBACK TRANSACTION
		end 
end

完整执行语句如附件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
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 */
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值