看这版有点冷,扔把火烧烧,动静动静。二次开发这类的,我不知道发到哪里,就先发补丁这版区了。
采购入库分解触发器:
作用:自动分解入库结果
代码:
ALTER trigger [dbo].[t_cgrkdentry_zby_insert] on [dbo].[t_cgrkdentry]
for insert
AS
--select * from t_cgrkd
--select * from t_cgrkdentry
--select * from t_cgrkdmxcl
declare @Fid int,@Findex int,@Fqty decimal(20,2),@i int,@maxi int,@Foperid int
declare @Fitemid int,@Funitid int,@p int,@maxp int,@Fsupid int
select @Fid=Fid,@Findex=Findex from inserted
select @Fsupid=Fsupply from t_cgrkd where Fid=@Fid
create table #bomdata(Fitemid int,Funitid int,Fqty decimal(20,2),Fbatchno varchar(50),Fauxpropid int,
Fcustid int,Fpp int,Fother int,Fprice decimal(20,6),Famount decimal(20,2),Ftaxprice decimal(20,6),Ftaxamount decimal(20,2),
Ftaxrate decimal(20,2),Fstockid int,Fspid int,Fnote varchar(250),Fqinhao varchar(50),
Fid_src int,Fentryid_src int,Fbillno_src varchar(50),Fclassid_src int)
create table #bomdata2(Findex int not null identity,Fitemid int,Funitid int,Fqty decimal(20,2),Fbatchno varchar(50),Fauxpropid int,
Fcustid int,Fpp int,Fother int,Fprice decimal(20,6),Famount decimal(20,2),Ftaxprice decimal(20,6),Ftaxamount decimal(20,2),
Ftaxrate decimal(20,2),Fstockid int,Fspid int,Fnote varchar(250),Fqinhao varchar(50),
Fid_src int,Fentryid_src int,Fbillno_src varchar(50),Fclassid_src int)
--select @maxi=max(Fentryid) from t_routingoper where Finterid=@Froutingid
select @i=1,@p=1
delete from t_cgrkdmxcl where Fid=@Fid and Fitemid=0
--插入临时表1
select @maxp=max(Findex) from t_cgrkdentry where Fid=@Fid
select @p=1
delete from t_cgrkdmxcl where Fid=@Fid
while @p<=@maxp
begin
select @Fitemid=Fitemid from t_cgrkdentry where Fid=@Fid and Findex=@p
if exists(select 1 from icbom where Fitemid=@Fitemid)
insert into #bomdata
select t3.Fitemid,t3.Funitid,t1.Fqty*t3.Fauxqty as Fqty,t1.Fbatchno,t1.Fauxpropid,
t1.Fcustid,t1.Fpp,t1.Fother,0,0,0,0,
17,t1.Fstockid,t1.Fspid,t1.Fnote,t1.Fqinhao,
t1.Fid_src,t1.Fentryid_src,t1.Fbillno_src,t1.Fclassid_src
from t_cgrkdentry t1,icbom t2,icbomchild t3,t_icitem t4
where t1.Fid=@Fid and t1.Findex=@p and t1.Fitemid=t2.Fitemid and t2.Finterid=t3.Finterid
and t3.Fitemid=t4.Fitemid
else
insert into #bomdata
select Fitemid,Funitid,Fqty,Fbatchno,Fauxpropid,
Fcustid,Fpp,Fother,Fprice,Famount,Ftaxprice,Ftaxamount,
Ftaxrate,Fstockid,Fspid,Fnote,Fqinhao,
Fid_src,Fentryid_src,Fbillno_src,Fclassid_src
From t_cgrkdentry where Fid=@Fid and Findex=@p
--select * from icbom
--select * from t_cgrkdentry
select @p=@p+1
if @p>@maxp
break
else
continue
end
--更新辅助属性
update t1 set t1.Fauxpropid=13234
from #bomdata t1,t_icitem t2 where t1.Fitemid=t2.Fitemid and t2.FAuxClassID=3009 and t1.Fauxpropid=0
--更新忘记写的批次
update t1 set t1.Fbatchno='-'
from #bomdata t1,t_icitem t2 where t1.Fitemid=t2.Fitemid and t2.Fbatchmanager=1 and isnull(t1.Fbatchno,'')=''
--更新价格为0部分物料的价格和金额?
update t1 set t1.Ftaxprice=t2.Fprice,t1.Fprice=t2.Fprice/(1+t3.Fvalueaddrate/100),
t1.Ftaxamount=round(t2.Fprice*t1.Fqty,2),t1.Famount=round(t2.Fprice/(1+t3.Fvalueaddrate/100)*t1.Fqty,2)
from #bomdata t1,t_supplyentry t2,t_supplier t3 where t1.Fitemid=t2.Fitemid and t2.Fsupid=@Fsupid and t2.Fsupid=t3.Fitemid
and t2.Fused=1
--select * from t_supplyentry
--select Fvalueaddrate,* from t_supplier
--插入临时表2
insert into #bomdata2
select Fitemid,Funitid,Fqty,Fbatchno,Fauxpropid,
Fcustid,Fpp,Fother,Fprice,Famount,Ftaxprice,Ftaxamount,
Ftaxrate,Fstockid,Fspid,Fnote,Fqinhao,
Fid_src,Fentryid_src,Fbillno_src,Fclassid_src
From #bomdata --order by Fnumber
--group by Fitemid,Funitid,FoperID,Fdefaultloc,Fitemid2,FSCbillno
--插入投料信息分录表
INSERT INTO t_cgrkdmxcl
(FID,Findex,Fitemid,Funitid,Fqty,Fbatchno,Fauxpropid,
Fcustid,Fpp,Fother,Fprice,Famount,Ftaxprice,Ftaxamount,
Ftaxrate,Fstockid,Fspid,Fnote,Fqinhao,
Fid_src,Fentryid_src,Fbillno_src,Fclassid_src)
select @FID,Findex,Fitemid,Funitid,Fqty,Fbatchno,Fauxpropid,
Fcustid,Fpp,Fother,Fprice,Famount,Ftaxprice,Ftaxamount,
Ftaxrate,Fstockid,Fspid,Fnote,Fqinhao,
Fid_src,Fentryid_src,Fbillno_src,Fclassid_src From #bomdata2
drop table #bomdata2,#bomdata
|