金蝶ERP实现产品入库冲减生产现场虚仓毛坯数,销售成品代码前一位数对应毛坯件的唯一代码,一一对应,其中增加委外加工时的半成品冲减功能。在此语句具体操作中出现虚仓入库单不能保存,提示不能删除己审核的单据的提示,现修改如下(文中修改以红字显示),具体语句如下:
if exists(select 1 from sysobjects where ">name = 'icstockbill_jade01') drop trigger icstockbill_jade01gocreate trigger icstockbill_jade01 on icstockbillfor insert,update,deleteasdeclare @frob int,@finterid int,@ftrantype int,@fstatus intselect @frob = frob,@finterid = finterid,@ftrantype = ftrantype,@fstatus = fstatusfrom inserted--from icstockbill where finterid = 26864declare @fstatus1 smallint,@fstatus2 smallint,@fbillno varchar(40)select @fbillno = fbillno,@fstatus1 = fstatus from inserted--from icstockbill where finterid = 26864select @fstatus2 = fstatus from deleted--select @fstatus2 = 0
--更新蓝字,未审核状态的 '销售出库单','领料单','委外出库单','其他出库单'的单价和金额
--更新步骤:供应商供货信息,以前月份的期末单价,以前月份的发出单价
--供应商供货信息只取RMB的平均单价
if @frob = 1 and @fstatus = 0 and (@ftrantype = 21 or @ftrantype = 24 or @ftrantype = 28 or @ftrantype = 29) begin
--更新供应商供货信息平均单价
update a set fprice = isnull(b.fprice,0),famount = isnull(b.fprice,0) * fqty,fauxprice = isnull(b.fprice,0) from icstockbillentry a ,(select fitemid,convert(decimal(18,2),avg(fprice)) as fprice from t_supplyentry where fcyid = 1 group by fitemid) bwhere a.fitemid = b.fitemid and a.finterid = @finteridif @ftrantype = 24
--更新以前月的平均单价
update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice from icstockbillentry x, (select fstockid,fitemid,fyear * 100 + fperiod as fperiods, convert(decimal(18,2),avg(case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end)) as fprice from icinvbal where fsend <> 0 or fendqty <> 0 group by fstockid,fitemid,fyear * 100 + fperiod) y, (select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal where fsend <> 0 or fendqty <> 0 group by fstockid,fitemid) z where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods and x.fscstockid = y.fstockid and x.fitemid = y.fitemid and x.finterid = @finteridelse
--更新以前月的平均单价
update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice from icstockbillentry x, (select fstockid,fitemid,fyear * 100 + fperiod as fperiods, convert(decimal(18,2),avg(case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end)) as fprice from icinvbal where fsend <> 0 or fendqty <> 0 group by fstockid,fitemid,fyear * 100 + fperiod) y, (select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal where fsend <> 0 or fendqty <> 0 group by fstockid,fitemid) z where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods and x.fdcstockid = y.fstockid and x.fitemid = y.fitemid and x.finterid = @finterid endif @ftrantype = 2 and ((isnull(@fstatus1,0) = 1 and isnull(@fstatus2,0) = 0) or (isnull(@fstatus1,0) = 0 and isnull(@fstatus2,0) = 1)) begindeclare @finterid_zp intdeclare @fitemid_mp int,@fstockid_mp as int,@fqty_mp decimal(18,2)
--虚仓入库单最大内码
select @finterid_zp = isnull(max(finterid),0) + 1 from zpstockbill
--产品入库单第一行产品对应的毛坯
select @fitemid_mp = c.fitemid from icstockbillentry a,t_icitem b,t_icitem cwhere a.fitemid = b.fitemid and finterid = @finteridand c.fnumber = case left(b.fnumber,3) when '11.' then '15.001' when '12.' then '15.001' when '13.' then '15.002' when '14.' then '15.003' when '20.' then '15.002' endand fentryid = 1if isnull(@fitemid_mp,0) = 0 goto ext