业务系统在运算成本的时候,关键是在设计流程的时候,要确定那几个环节需要重新计算成本.例如:采购环节,退补价环节等等.运算新的成本公式应该是这样的:成本=结存金额+本期入库金额/结存数量+入库数量. 我给你发一个存储过程,是用来核算库存成本的你可以看一下 update spkfjc set spkfjc.kcshl=isnull(spkfjc.kcshl,0)+a.upshl, spkfjc.kcje=isnull(spkfjc.kcje,0)+a.upje, spkfjc.chbdj=case when (@djlx='JHA' or @djlx='CDB' or @djlx='CRK' or @djlx='ZRK') and (a.upshl>0 or a.upshl<0) and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then round((spkfjc.kcje+a.upje)/(spkfjc.kcshl+a.upshl),6) when @djlx='JHB' and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then round((spkfjc.kcje+a.upje)/(spkfjc.kcshl+a.upshl),6) when (@djlx='JHA' or @djlx='CDB' or @djlx='CRK' or @djlx='ZRK') and spkfjc.kcshl<0 and spkfjc.kcshl+a.upshl>0 then a.zgrkdj when @djlx='CBD' and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then round((spkfjc.kcje+a.upje)/(isnull(spkfjc.kcshl,0)+a.upshl),6) else spkfjc.chbdj end, spkfjc.zgjj=case when @djlx='JHA' and spkfjc.zgjj<a.zgrkdj then a.zgrkdj else spkfjc.zgjj end, spkfjc.zdjj=case when (@djlx='JHA' and spkfjc.zdjj>a.zdrkdj) or spkfjc.zdjj=0 then a.zdrkdj else spkfjc.zdjj end, spkfjc.zhjj=case when @djlx='JHA' then a.zgrkdj else zhjj end from #t_sp a where spkfjc.spid=a.spid 说明:jha,jhb等是相关业务的单据标识,kcshl 库存数量,kcje 库存金额,chbdj 成本单价,upshl 本次入库的数量,upje 本次入库的金额. 注意:在重新计算新成时,一定要有条件进行约束,不然会出现负成本
我给你发一个存储过程,是用来核算库存成本的你可以看一下
update spkfjc
set spkfjc.kcshl=isnull(spkfjc.kcshl,0)+a.upshl,
spkfjc.kcje=isnull(spkfjc.kcje,0)+a.upje,
spkfjc.chbdj=case
when
(@djlx='JHA' or @djlx='CDB' or @djlx='CRK' or @djlx='ZRK') and
(a.upshl>0 or a.upshl<0) and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then
round((spkfjc.kcje+a.upje)/(spkfjc.kcshl+a.upshl),6)
when
@djlx='JHB' and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then
round((spkfjc.kcje+a.upje)/(spkfjc.kcshl+a.upshl),6)
when
(@djlx='JHA' or @djlx='CDB' or @djlx='CRK' or @djlx='ZRK') and
spkfjc.kcshl<0 and
spkfjc.kcshl+a.upshl>0 then
a.zgrkdj
when @djlx='CBD' and (spkfjc.kcshl+a.upshl)<>0 and (spkfjc.kcje+a.upje)*(spkfjc.kcshl+a.upshl)>0 then
round((spkfjc.kcje+a.upje)/(isnull(spkfjc.kcshl,0)+a.upshl),6)
else spkfjc.chbdj end,
spkfjc.zgjj=case when @djlx='JHA' and spkfjc.zgjj<a.zgrkdj then a.zgrkdj else spkfjc.zgjj end,
spkfjc.zdjj=case when (@djlx='JHA' and spkfjc.zdjj>a.zdrkdj) or spkfjc.zdjj=0 then a.zdrkdj else spkfjc.zdjj end,
spkfjc.zhjj=case when @djlx='JHA' then a.zgrkdj else zhjj end
from #t_sp a
where spkfjc.spid=a.spid
说明:jha,jhb等是相关业务的单据标识,kcshl 库存数量,kcje 库存金额,chbdj 成本单价,upshl 本次入库的数量,upje 本次入库的金额.
注意:在重新计算新成时,一定要有条件进行约束,不然会出现负成本
你的用的是SPKFJC,我的用的是HWSP.你用的CCERP还是V7?
给你发了短消息了,注意查看