1、ERP数据字典
链接:https://pan.baidu.com/s/1p1cs3G2MwrpSj0guHRacfg
提取码:9ae3
2、原料库存日单价SQL注释说明
create or replace procedure pro_aikcdj is
begindeclare--jzbz varchar2(180); --上月是否结账标志cbjs varchar2(20000); --财务未结账取成本计算单价qcje varchar2(20000);vqs1 varchar2(20000);zvqsl varchar2(20000);zerosl varchar2(20000); --库存为0的更新单价rq varchar2(20);csrq varchar2(20); --初始日期sy varchar2(50);endy varchar2(50);rj varchar2(20); --上月期间xtzh varchar2(20000);xtck varchar2(20000);qtrk varchar2(20000);cgroup varchar2(80);corg varchar2(80);cjcsl varchar2(80);cwlzj varchar2(80);cwlbm varchar2(80);cwlmc varchar2(80);ccby varchar2(80);csnabmny varchar2(80);cnabmny varchar2(80);czero varchar2(10);cdr varchar2(10);crkhj varchar2(80);cckhj varchar2(80);yearend varchar2(10);yearstart varchar2(10);zerojg varchar2(20000);csprice varchar2(20000);mprice varchar2(20000);xzprice varchar2(20000);dbrk varchar2(20000);xsck varchar2(20000);dbck varchar2(20000);ccprk varchar2(20000);yykj varchar2(20000);cgth varchar2(20000);jxcw varchar2(180);cgcpdb varchar2(20000); --采购订单成品调拨CURSOR cur_kc ISselect sum(ic_onhandnum.nonhandnum) jcsl,ic_onhanddim.pk_group,ic_onhanddim.pk_org,cmaterialoid,bd_material_v.code wlbm,bd_material_v.name wlmc,org_financeorg.pk_costregion pk_costregionfrom (select *from ic_onhanddimwhere nvl(ic_onhanddim.dr, 0) = 0and ic_onhanddim.pk_org in(select distinct org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), 'yyyy-mm'))) ic_onhanddimleft join bd_material_von ic_onhanddim.cmaterialoid = bd_material_v.pk_sourceleft join ic_onhandnumon ic_onhanddim.pk_onhanddim = ic_onhandnum.pk_onhanddimleft join org_stockorgon ic_onhanddim.pk_org = org_stockorg.pk_stockorgleft join org_financeorgon org_stockorg.pk_financeorg = org_financeorg.pk_financeorgwhere 1 = 1and bd_material_v.code like '1%'or bd_material_v.code like 'S01%'group by ic_onhanddim.pk_group,ic_onhanddim.pk_org,cmaterialoid,bd_material_v.code,bd_material_v.name,org_financeorg.pk_costregion; --已结账算法CURSOR cur_csh ISselect pk_group,pk_org,cinventoryid,wlmc,kcdj * nvl(kcsl, 0) nabmny,wlbm,pk_costregionfrom (select *from def_rcbdjwhere 1 = 1and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), 'yyyy-mm')and def_rcbdj.pk_org = org_costregion.pk_org)and ddate = to_char(sysdate - 10, 'yyyy-mm-dd')and nvl(def_rcbdj.dr, 0) = 0) def_rcbdj; --未结账算法 取10天内库存单价加权平均月初改单太多导致数据异常 begincsrq := to_char(sysdate, 'dd');rq := to_char(sysdate, 'yyyy-mm-dd');rj := to_char(add_months(sysdate, -1), 'yyyy-mm');sy := to_char(last_day(add_months(sysdate, -1)) + 1,'yyyy-mm-dd'); --月初endy := to_char(last_day(sysdate) + 1, 'yyyy-mm-dd'); --月底czero := 0.0000;cdr := 0;yearend := to_char(sysdate, 'mm'); --二月底yearstart := to_char(sysdate, 'yyyy') || '-01'; --年初if csrq >= 01 thenopen cur_kc;loopfetch cur_kcinto cjcsl, cgroup, corg, cwlzj, cwlbm, cwlmc, ccby;exit when cur_kc%notfound;select nvl(sum(ia_monthnab.nabmny), 0)into cnabmnyfrom ia_monthnabwhere ia_monthnab.caccountperiod = rjAND ia_monthnab.cinventoryid = cwlzjand ia_monthnab.pk_org = ccbyand ia_monthnab.nabmny <> 0and nvl(ia_monthnab.dr, 0) = 0; --判断期初表里头没有的物料select sum(xa.nassistnum * xc.vbdef10)into crkhjfrom ic_purchasein_b xa,po_arriveorder_b xb,po_order_b xc,ic_purchasein_h xdwhere xa.csourcebillbid = xb.pk_arriveorder_band xb.csourcebid = xc.pk_order_band xa.dr = 0and xb.dr = 0and xc.dr = 0and xd.dr = 0and xd.cgeneralhid = xa.cgeneralhidand xd.freplenishflag <> 'Y' --采购退货参照采购订单金额冲减20190628and dbizdate betweento_char(trunc(sysdate - 1, 'mm'), 'yyyy-mm-dd') andto_char(sysdate + 1, 'yyyy-mm-dd')and regexp_like(xc.vbdef10, '[[:digit:]]')and xa.cmaterialvid = cwlzjand xa.pk_org = corg;--and xd.ccostdomainid = ccby;双成本域select sum(nnum)into cckhjfrom ic_material_b a, ic_material_h bwhere a.dr = 0and b.dr = 0and a.cgeneralhid = b.cgeneralhidand a.cgeneralhid = b.cgeneralhidand a.cmaterialvid = cwlzjand a.pk_org = corg--and b.ccostdomainoid = ccby--双成本域and dbizdate betweento_char(trunc(sysdate - 1, 'mm'), 'yyyy-mm-dd') andto_char(sysdate + 1, 'yyyy-mm-dd');--if nvl(cnabmny,0)=0 and nvl(cjcsl,0)>0 theninsert into def_rcbdj(id,pk_group,pk_org,pk_costregion,cinventoryid,wlbm,wlmc,dbizdate,kcdj,nabmny,kcsl,rkhj,cksl,ddate,dr,jzzt)values(seq_ycl_rcbdj.nextval,cgroup,corg,ccby,cwlzj,cwlbm,cwlmc,to_char(sysdate - 1, 'yyyy-mm-dd'),czero,czero,cjcsl,crkhj,cckhj,to_char(sysdate, 'yyyy-mm-dd'),cdr,'财务已结账');end loop;commit;close cur_kc;vqs1 := 'update def_rcbdj set kcsl=(select sum(ic_onhandnum.nonhandnum) xcl from ic_onhanddim
left join ic_onhandnum
on ic_onhanddim.pk_onhanddim=ic_onhandnum.pk_onhanddim
left join bd_material
on ic_onhanddim.cmaterialvid=bd_material.pk_material
left join bd_stordocon ic_onhanddim.cwarehouseid=bd_stordoc.pk_stordoc
where nvl(ic_onhandnum.dr,0)=0 and bd_material.code=def_rcbdj.wlbm and ic_onhanddim.pk_org=def_rcbdj.pk_organd bd_stordoc.name not like ''%零成本%''
group by ic_onhanddim.pk_org,ic_onhanddim.cmaterialvid,bd_material.code) where substr(def_rcbdj.TS,0,10)=''' || rq ||''' ';execute immediate vqs1; --更新库存数量20190910去掉零成本仓库的影响commit;if yearend = 02 thenqcje := ' update def_rcbdj set nabmny=(selectsum(nvl(ia_monthnab.nabmny, 0))from ia_monthnableft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourceleft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhereia_monthnab.caccountperiod =''' || yearstart || '''and nvl(ia_monthnab.dr, 0) = 0 AND bd_material_v.code=def_rcbdj.wlbmand org_costregion.pk_org=def_rcbdj.pk_org) where substr(def_rcbdj.TS,0,10)=''' || rq || ''' '; --更新期初execute immediate qcje;commit;ccprk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl(( select sum(ia_monthnab.nabprice * ic_finprodin_b.nnum)from ic_finprodin_binner join org_stockorgon ic_finprodin_b.pk_org = org_stockorg.pk_stockorginner join org_financeorgon org_stockorg.pk_financeorg = org_financeorg.pk_financeorginner join ia_monthnabon ia_monthnab.pk_org = org_financeorg.pk_costregionand ia_monthnab.cinventoryid = ic_finprodin_b.cmaterialvidleft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourcewhere ic_finprodin_b.dbizdate between''' || sy || ''' and''' || endy || '''and ia_monthnab.caccountperiod=''' || yearstart || '''and nvl(ic_finprodin_b.dr,0)=0and ic_finprodin_b.pk_org=def_rcbdj.pk_organd bd_material_v.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate ccprk; --增加产成品入库的金额每年二月份更新逻辑commit;elseqcje := ' update def_rcbdj set nabmny=(selectsum(nvl(ia_monthnab.nabmny, 0))from ia_monthnableft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourceleft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhereia_monthnab.caccountperiod =''' || rj || '''and nvl(ia_monthnab.dr, 0) = 0 AND bd_material_v.code=def_rcbdj.wlbmand org_costregion.pk_org=def_rcbdj.pk_org) where substr(def_rcbdj.TS,0,10)=''' || rq || ''' '; --更新期初execute immediate qcje;commit;ccprk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl(( select sum(ia_monthnab.nabprice * ic_finprodin_b.nnum)from ic_finprodin_binner join org_stockorgon ic_finprodin_b.pk_org = org_stockorg.pk_stockorginner join org_financeorgon org_stockorg.pk_financeorg = org_financeorg.pk_financeorginner join ia_monthnabon ia_monthnab.pk_org = org_financeorg.pk_costregionand ia_monthnab.cinventoryid = ic_finprodin_b.cmaterialvidleft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourcewhere ic_finprodin_b.dbizdate between''' || sy || ''' and''' || endy || '''and ia_monthnab.caccountperiod=''' || rj || '''and nvl(ic_finprodin_b.dr,0)=0and ic_finprodin_b.pk_org=def_rcbdj.pk_organd bd_material_v.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate ccprk; --增加产成品入库的金额commit;end if;xtzh := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select sum(nvl(ncostmny,0))from ic_generalin_bleft join bd_materialon ic_generalin_b.cmaterialvid= bd_material.pk_materialwhere cbodytranstypecode = ''4A-06''and dbizdate between''' || sy || ''' and''' || endy || '''and ic_generalin_b.dr = 0and ic_generalin_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xtzh; --增加形态转换的金额commit;qtrk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select
sum(nvl(qtck.nnum * kcdj.nabprice, 0))from (select avg(nabprice) nabprice ,pk_org,cinventoryid,KCRNfrom (select cinventoryid,org_costregion.pk_org,nvl(nabprice, 0) nabprice,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_org order by ia_monthnab.caccountperiod desc) KCRNfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhere nvl(ia_monthnab.dr, 0) = 0)where KCRN = 1group by pk_org,cinventoryid,KCRN) kcdjright join (select ic_generalin_b.pk_org,ic_generalin_b.cmaterialvid,bd_material.code wlbm,nvl(sum(nnum), 0) nnumfrom ic_generalin_bleft join bd_materialon ic_generalin_b.cmaterialvid = bd_material.pk_materialwhere ic_generalin_b.dr = 0and cbodytranstypecode <> ''4A-06''and cbodytranstypecode <> ''4A-02''and dbizdate between to_char(last_day(add_months(sysdate,-1)) + 1,''yyyy-mm-dd'') andto_char(last_day(sysdate) + 1,''yyyy-mm-dd'')group by ic_generalin_b.pk_org,ic_generalin_b.cmaterialvid,bd_material.code) qtckon kcdj.cinventoryid = qtck.cmaterialvidand kcdj.pk_org = qtck.pk_orgwhere 1=1and qtck.pk_org=def_rcbdj.pk_organd qtck.wlbm=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate qtrk; --增加其他入库的金额commit;xtck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl((select sum(nnum)from ic_generalout_bleft join bd_materialon ic_generalout_b.cmaterialvid = bd_material.pk_materialwhere ic_generalout_b.dr =0and cbodytranstypecode<>''4I-02''and dbizdate between''' || sy || ''' and''' || endy || '''and ic_generalout_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xtck; --增加形态出库和其他出库的数量commit;xsck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl(( select sum(nnum)from ic_saleout_bleft join bd_materialon ic_saleout_b.cmaterialvid = bd_material.pk_materialwhere ic_saleout_b.dr =0and ic_saleout_b.dbizdate between''' || sy || ''' and''' || endy || '''and ic_saleout_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xsck; --增加销售出库的数量0709commit;cgcpdb := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select sum(ic_purchasein_b.nassistnum*po_order_b.vbdef10)from ic_purchasein_bleft join po_order_bon ic_purchasein_b.csourcebillbid=po_order_b.pk_order_bleft join bd_materialon ic_purchasein_b.cmaterialvid= bd_material.pk_materialwhere nvl(ic_purchasein_b.dr,0)=0and nvl(po_order_b.dr,0)=0and dbizdate between''' || sy || ''' and''' || endy || '''and regexp_like(po_order_b.vbdef10,''[[:digit:]]'')and bd_material.code=def_rcbdj.wlbmand ic_purchasein_b.pk_org =def_rcbdj.pk_organd ic_purchasein_b.nassistnum>0),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate cgcpdb; --增加成品调拨的金额03-09新增逻辑commit;cgth := 'update def_rcbdj set cksl=nvl(cksl,0)-nvl((select sum(nnum)from ic_purchasein_binner join ic_purchasein_hon ic_purchasein_h.cgeneralhid = ic_purchasein_b.cgeneralhidleft join bd_materialon ic_purchasein_b.cmaterialvid = bd_material.pk_materialwhere nvl(ic_purchasein_b.dr,0)=0and ic_purchasein_h.freplenishflag=''Y''and nnum<0and dbizdate between''' || sy || ''' and''' || endy || '''and ic_purchasein_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate cgth; --增加采购退货的数量2019.02.25更新commit; --去掉采购退货造成的多次数量冲减问题,李亚婷反馈2019-06-27dbrk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((selectsum(to_bill_b.norigtaxnetprice*ic_transin_b.nnum)from to_bill_b
inner join ic_transin_bon to_bill_b.cbill_bid = ic_transin_b.cfirstbillbidleft join bd_materialon ic_transin_b.cmaterialvid=bd_material.pk_material
where nvl(to_bill_b.dr,0)=0 and nvl(ic_transin_b.dr,0)=0
and dbizdate between''' || sy || ''' and''' || endy || '''
and ic_transin_b.pk_org=def_rcbdj.pk_org
and bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate dbrk; --增加调拨入库的金额commit;dbck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl((selectsum(ic_transout_b.nnum)from ic_transout_bleft join bd_materialon ic_transout_b.cmaterialvid=bd_material.pk_material
where nvl(ic_transout_b.dr,0)=0
and dbizdate between''' || sy || ''' and''' || endy || '''
and ic_transout_b.pk_org=def_rcbdj.pk_org
and bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate dbck; --增加调拨出库的数量commit;zvqsl := 'update def_rcbdj set kcdj=( (nvl(nabmny,0)+nvl(rkhj,0))-((nvl(nabmny,0)+nvl(rkhj,0))/(nvl(cksl,0)+kcsl))*nvl(cksl,0) )/kcsl where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and kcsl>0 and cksl+kcsl>0 ';execute immediate zvqsl;commit;zerosl := 'update def_rcbdj set kcdj=0 where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and kcsl<=0 and wlbm not like ''119%'''; --没库存时库存单价设置为0,2019.01.19更新execute immediate zerosl;commit;jxcw := 'update def_rcbdj set kcdj=0.535 where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and wlbm=''12000000000077'' and pk_org=''0001B110000000001IX1'''; --益肠宝赋值execute immediate jxcw;commit;yykj := 'update def_rcbdj set kcdj=nvl( (select avg(nabprice) nabpricefrom(select * from (select cinventoryid,org_costregion.pk_org,nvl(nabprice, 0) nabprice,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_book order by ia_monthnab.caccountperiod desc) KCRNfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhere nvl(ia_monthnab.dr, 0) = 0 and nvl(org_costregion.dr,0)=0) ia_monthnabwhere KCRN =1) ia_monthnabwhere ia_monthnab.pk_org=def_rcbdj.pk_organd ia_monthnab.cinventoryid=def_rcbdj.cinventoryid),0 )
where def_rcbdj.pk_org=''0001B110000000001IGO'' and ddate=''' || rq ||''' ';execute immediate yykj; --岳阳科技更新库存单价取月初的期初单价2019/02/20日更新commit;open cur_csh;loopfetch cur_cshinto cgroup, corg, cwlzj, cwlmc, csnabmny, cwlbm, ccby;exit when cur_csh%notfound;beginselect sum(xa.nassistnum * xc.vbdef10)into crkhjfrom ic_purchasein_b xa,po_arriveorder_b xb,po_order_b xc,ic_purchasein_h xdwhere xa.csourcebillbid = xb.pk_arriveorder_band xb.csourcebid = xc.pk_order_band xa.dr = 0and xb.dr = 0and xc.dr = 0and xd.dr = 0and xd.cgeneralhid = xa.cgeneralhidand xd.freplenishflag <> 'Y' --采购退货参照采购订单金额冲减20190628and xd.creationtime betweento_char(sysdate - 10, 'yyyy-mm-dd') andto_char(sysdate + 1, 'yyyy-mm-dd')and regexp_like(xc.vbdef10, '[[:digit:]]')and xa.cmaterialvid = cwlzjand xa.pk_org = corg;--and xd.ccostdomainid = ccby;双成本域select sum(nnum)into cckhjfrom ic_material_b a, ic_material_h bwhere a.dr = 0and b.dr = 0and a.cgeneralhid = b.cgeneralhidand a.cgeneralhid = b.cgeneralhidand a.cmaterialvid = cwlzjand a.pk_org = corg--and b.ccostdomainoid = ccby--双成本域and b.creationtime between to_char(sysdate - 10, 'yyyy-mm-dd') andto_char(sysdate + 1, 'yyyy-mm-dd');insert into def_rcbdj(id,pk_group,pk_org,pk_costregion,cinventoryid,wlbm,wlmc,dbizdate,kcdj,nabmny,kcsl,rkhj,cksl,ddate,dr,jzzt)values(seq_ycl_rcbdj.nextval,cgroup,corg,ccby,cwlzj,cwlbm,cwlmc,to_char(sysdate - 1, 'yyyy-mm-dd'),czero,csnabmny,czero,crkhj,cckhj,to_char(sysdate, 'yyyy-mm-dd'),cdr,'财务未结账');end;end loop;commit;close cur_csh;vqs1 := 'update def_rcbdj set kcsl=(select sum(ic_onhandnum.nonhandnum) xcl from ic_onhanddim
left join ic_onhandnum
on ic_onhanddim.pk_onhanddim=ic_onhandnum.pk_onhanddim
left join bd_material
on ic_onhanddim.cmaterialvid=bd_material.pk_material
left join bd_stordocon ic_onhanddim.cwarehouseid=bd_stordoc.pk_stordoc
where nvl(ic_onhandnum.dr,0)=0 and bd_material.code=def_rcbdj.wlbm and ic_onhanddim.pk_org=def_rcbdj.pk_organd bd_stordoc.name not like ''%零成本%''
group by ic_onhanddim.pk_org,ic_onhanddim.cmaterialvid,bd_material.code) where substr(def_rcbdj.TS,0,10)=''' || rq ||''' ';execute immediate vqs1; --更新库存数量20190910去掉零成本仓库带来的影响commit;xtzh := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select sum(nvl(ncostmny,0))from ic_generalin_bleft join bd_materialon ic_generalin_b.cmaterialvid= bd_material.pk_materialwhere cbodytranstypecode = ''4A-06''and dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and ic_generalin_b.dr = 0and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_generalin_b.pk_org= org_costregion.pk_org)and ic_generalin_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xtzh; --增加形态转换的金额commit;qtrk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select
sum(nvl(qtck.nnum * kcdj.nabprice, 0))from (select avg(nabprice) nabprice ,pk_org,cinventoryid,KCRNfrom (select cinventoryid,org_costregion.pk_org,nvl(nabprice, 0) nabprice,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_org order by ia_monthnab.caccountperiod desc) KCRNfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhere nvl(ia_monthnab.dr, 0) = 0)where KCRN = 1 group by pk_org,cinventoryid,KCRN ) kcdjright join (select ic_generalin_b.pk_org,ic_generalin_b.cmaterialvid,bd_material.code wlbm,nvl(sum(nnum), 0) nnumfrom ic_generalin_bleft join bd_materialon ic_generalin_b.cmaterialvid = bd_material.pk_materialwhere ic_generalin_b.dr = 0and cbodytranstypecode <> ''4A-06''and cbodytranstypecode <> ''4A-02''and dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')group by ic_generalin_b.pk_org,ic_generalin_b.cmaterialvid,bd_material.code) qtckon kcdj.cinventoryid = qtck.cmaterialvidand kcdj.pk_org = qtck.pk_orgwhere 1=1and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and qtck.pk_org= org_costregion.pk_org)and qtck.pk_org=def_rcbdj.pk_organd qtck.wlbm=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate qtrk; --增加其他入库的金额commit;xtck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl((select sum(nnum)from ic_generalout_bleft join bd_materialon ic_generalout_b.cmaterialvid = bd_material.pk_materialwhere ic_generalout_b.dr =0and cbodytranstypecode<>''4I-02''and dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_generalout_b.pk_org= org_costregion.pk_org)and ic_generalout_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xtck; --增加其他出库的数量commit;cgcpdb := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((select sum(ic_purchasein_b.nassistnum*po_order_b.vbdef10) from ic_purchasein_bleft join po_order_b on ic_purchasein_b.csourcebillbid=po_order_b.pk_order_bleft join bd_materialon ic_purchasein_b.cmaterialvid= bd_material.pk_materialwhere nvl(ic_purchasein_b.dr,0)=0 and nvl(po_order_b.dr,0)=0and dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and regexp_like(po_order_b.vbdef10,''[[:digit:]]'')and bd_material.code=def_rcbdj.wlbmand NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_purchasein_b.pk_org= org_costregion.pk_org)and ic_purchasein_b.pk_org =def_rcbdj.pk_organd ic_purchasein_b.nassistnum>0),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate cgcpdb; --增加成品调拨的金额03-09新增逻辑commit;cgth := 'update def_rcbdj set cksl=nvl(cksl,0)-nvl((select sum(nnum)from ic_purchasein_binner join ic_purchasein_hon ic_purchasein_h.cgeneralhid = ic_purchasein_b.cgeneralhidleft join bd_materialon ic_purchasein_b.cmaterialvid = bd_material.pk_materialwhere nvl(ic_purchasein_b.dr,0)=0and ic_purchasein_h.freplenishflag=''Y'' and nnum<0and dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_purchasein_b.pk_org= org_costregion.pk_org)and ic_purchasein_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate cgth; ----增加采购退货的数量2019.02.25更新commit; --去掉采购退货造成的多次数量冲减问题,李亚婷反馈2019-06-27dbrk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl((selectsum(to_bill_b.norigtaxnetprice*ic_transin_b.nnum)from to_bill_b
inner join ic_transin_bon to_bill_b.cbill_bid = ic_transin_b.cfirstbillbidleft join bd_materialon ic_transin_b.cmaterialvid=bd_material.pk_material
where nvl(to_bill_b.dr,0)=0 and nvl(ic_transin_b.dr,0)=0
and dbizdate between
to_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_transin_b.pk_org= org_costregion.pk_org)
and ic_transin_b.pk_org=def_rcbdj.pk_org
and bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate dbrk; --增加调拨入库的金额commit;if yearend = 02 thenccprk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl(( select sum(ia_monthnab.nabprice * ic_finprodin_b.nnum)from ic_finprodin_binner join org_stockorgon ic_finprodin_b.pk_org = org_stockorg.pk_stockorginner join org_financeorgon org_stockorg.pk_financeorg = org_financeorg.pk_financeorginner join ia_monthnabon ia_monthnab.pk_org = org_financeorg.pk_costregionand ia_monthnab.cinventoryid = ic_finprodin_b.cmaterialvidleft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourcewhere ic_finprodin_b.dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and ia_monthnab.caccountperiod=''' || yearstart || '''and nvl(ic_finprodin_b.dr,0)=0and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_finprodin_b.pk_org= org_costregion.pk_org)and ic_finprodin_b.pk_org=def_rcbdj.pk_organd bd_material_v.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate ccprk; --增加产成品入库的金额commit;elseccprk := 'update def_rcbdj set rkhj=nvl(rkhj,0)+nvl(( select sum(ia_monthnab.nabprice * ic_finprodin_b.nnum)from ic_finprodin_binner join org_stockorgon ic_finprodin_b.pk_org = org_stockorg.pk_stockorginner join org_financeorgon org_stockorg.pk_financeorg = org_financeorg.pk_financeorginner join ia_monthnabon ia_monthnab.pk_org = org_financeorg.pk_costregionand ia_monthnab.cinventoryid = ic_finprodin_b.cmaterialvidleft join bd_material_von ia_monthnab.cinventoryid = bd_material_v.pk_sourcewhere ic_finprodin_b.dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and ia_monthnab.caccountperiod=''' || rj || '''and nvl(ic_finprodin_b.dr,0)=0and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_finprodin_b.pk_org= org_costregion.pk_org)and ic_finprodin_b.pk_org=def_rcbdj.pk_organd bd_material_v.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate ccprk; --增加产成品入库的金额commit;end if;dbck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl((selectsum(ic_transout_b.nnum)from ic_transout_bleft join bd_materialon ic_transout_b.cmaterialvid=bd_material.pk_material
where nvl(ic_transout_b.dr,0)=0
and dbizdate between
to_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_transout_b.pk_org= org_costregion.pk_org)
and ic_transout_b.pk_org=def_rcbdj.pk_org
and bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate dbck; --增加调拨出库的数量commit;xsck := 'update def_rcbdj set cksl=nvl(cksl,0)+nvl(( select sum(nnum)from ic_saleout_bleft join bd_materialon ic_saleout_b.cmaterialvid = bd_material.pk_materialwhere ic_saleout_b.dr =0and ic_saleout_b.dbizdate betweento_char(sysdate-10,''yyyy-mm-dd'')and to_char(sysdate+1, ''yyyy-mm-dd'')and NOT exists(select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ic_saleout_b.pk_org= org_costregion.pk_org)and ic_saleout_b.pk_org=def_rcbdj.pk_organd bd_material.code=def_rcbdj.wlbm),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate xsck; --增加销售出库的数量0709commit;zvqsl := 'update def_rcbdj set kcdj=( (nvl(nabmny,0)+nvl(rkhj,0))-((nvl(nabmny,0)+nvl(rkhj,0))/(nvl(cksl,0)+kcsl))*nvl(cksl,0) )/kcsl where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and kcsl>0 and kcsl+cksl>0 ';execute immediate zvqsl;commit;cbjs := 'update def_rcbdj set kcdj=nvl((select(case when sum(nnum)=0 then 0 else sum(nnum*nprice)/sum(nnum) end) djfrom ia_detailledgerleft join bd_materialon ia_detailledger.cinventoryvid = bd_material.pk_materialleft join org_stockorgon ia_detailledger.cstockorgid=org_stockorg.pk_stockorg where caccountperiod =to_char(add_months(sysdate,-1),''yyyy-mm'') and nvl(ia_detailledger.dr,0) = 0and ia_detailledger.cbilltypecode not in (''IG'', ''IF'', ''IE'')and (ia_detailledger.fintransitflag in (-1, 0))and ia_detailledger.fdispatchflag = 1and ia_detailledger.iauditsequence >= 0and nvl(nprice, 0) > 0and NOT exists (select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ia_detailledger.cstockorgid= org_costregion.pk_org) and ia_detailledger.cinventoryvid=def_rcbdj.cinventoryidand ia_detailledger.cstockorgid=def_rcbdj.pk_org),0),TS=to_char(sysdate,''yyyy-mm-dd hh24:mi:ss'')where substr(def_rcbdj.TS,0,10)=to_char(sysdate,''yyyy-mm-dd'')and concat(def_rcbdj.cinventoryid,def_rcbdj.pk_org) in (select concat(ia_detailledger.cinventoryvid,ia_detailledger.cstockorgid) from ia_detailledgerleft join bd_materialon ia_detailledger.cinventoryvid = bd_material.pk_materialleft join org_stockorgon ia_detailledger.cstockorgid=org_stockorg.pk_stockorg where caccountperiod =to_char(add_months(sysdate,-1),''yyyy-mm'') and nvl(ia_detailledger.dr,0) = 0and ia_detailledger.cbilltypecode not in (''IG'', ''IF'', ''IE'')and (ia_detailledger.fintransitflag in (-1, 0))and ia_detailledger.fdispatchflag = 1and ia_detailledger.iauditsequence >= 0and nvl(nprice,0) > 0and NOT exists (select org_costregion.pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionwhere caccountperiod =to_char(add_months(sysdate, -1), ''yyyy-mm'')and ia_detailledger.cstockorgid= org_costregion.pk_org) )';execute immediate cbjs;commit; --2019.11.14增加未结账单价取财务成本计算的单价 zerosl := 'update def_rcbdj set kcdj=0 where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and kcsl<=0 and wlbm not like ''119%'''; --没库存时库存单价设置为0,2019.01.19更新execute immediate zerosl;commit;jxcw := 'update def_rcbdj set kcdj=0.535 where substr(def_rcbdj.TS,0,10)=''' || rq ||''' and wlbm=''12000000000077'' and pk_org=''0001B110000000001IX1'''; --益肠宝赋值execute immediate jxcw;commit;yykj := 'update def_rcbdj set kcdj=nvl( (select avg(nabprice) nabpricefrom(select * from (select cinventoryid,org_costregion.pk_org,nvl(nabprice, 0) nabprice,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_book order by ia_monthnab.caccountperiod desc) KCRNfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org = org_costregion.pk_costregionwhere nvl(ia_monthnab.dr, 0) = 0 and nvl(org_costregion.dr,0)=0) ia_monthnabwhere KCRN =1) ia_monthnab where ia_monthnab.pk_org=def_rcbdj.pk_org and ia_monthnab.cinventoryid=def_rcbdj.cinventoryid ),0 )
where def_rcbdj.pk_org=''0001B110000000001IGO'' and ddate=''' || rq ||''' ';execute immediate yykj;commit;zerojg := 'update def_rcbdj set kcdj=nvl(( select avg(nvl(nabprice, 0)) from (select ia_monthnab.nabprice,ia_monthnab.cinventoryid,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_book order by ia_monthnab.caccountperiod desc) KCRN,org_costregion.pk_org pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionleft join bd_materialon ia_monthnab.cinventoryid =bd_material.pk_materialwhere nvl(ia_monthnab.dr, 0) = 0and nvl(ia_monthnab.nabprice,0)>0and bd_material.code like ''1%'') ia_monthnabwhere KCRN = 1and ia_monthnab.pk_org=def_rcbdj.pk_org and ia_monthnab.cinventoryid=def_rcbdj.cinventoryid),0)where ddate=to_char(sysdate,''yyyy-mm-dd'')and nvl(kcsl,0)=0 and nvl(dr,0)=0and pk_org<>''0001A91000000000B6GB'' and pk_org<>''0001B110000000001IGO'' ';/*zerojg := 'update def_rcbdj set kcdj=(select nvl(sum(kcdj),0)from (select pk_org,cinventoryid,row_number() over(partition by pk_org, cinventoryid order by ddate desc) rn,kcdj,ddatefrom def_rcbdjwhere 1 = 1and nvl(dr, 0) = 0and ddate > to_char(last_day(add_months(sysdate, -1)), ''yyyy-mm-dd'')and kcdj<>0and kcdj<>10000000) zxdjwhere rn = 1and zxdj.pk_org=def_rcbdj.pk_organd zxdj.cinventoryid=def_rcbdj.cinventoryid) where ddate=to_char(sysdate,''yyyy-mm-dd'')and nvl(kcsl,0)=0 and nvl(dr,0)=0and pk_org<>''0001A91000000000B6GB'' and pk_org<>''0001B110000000001IGO'' ';*/execute immediate zerojg;commit; --库存数量为0的价格修正逻辑2019.08.21 csprice := 'update def_rcbdj set cskcdj=kcdj where nvl(dr,0)=0 and ddate=to_char(sysdate,''yyyy-mm-dd'')';execute immediate csprice;commit; --将初始计算的价格保留2019.08.28mprice := 'update def_rcbdj set monthprice=nvl(( select avg(nvl(nabprice, 0)) from (select ia_monthnab.nabprice,ia_monthnab.cinventoryid,row_number() over(partition by ia_monthnab.cinventoryid, ia_monthnab.pk_book order by ia_monthnab.caccountperiod desc) KCRN,org_costregion.pk_org pk_orgfrom ia_monthnableft join org_costregionon ia_monthnab.pk_org =org_costregion.pk_costregionleft join bd_materialon ia_monthnab.cinventoryid =bd_material.pk_materialwhere nvl(ia_monthnab.dr, 0) = 0and nvl(ia_monthnab.nabprice,0)>0and bd_material.code like ''1%'') ia_monthnabwhere KCRN = 1and ia_monthnab.pk_org=def_rcbdj.pk_org and ia_monthnab.cinventoryid=def_rcbdj.cinventoryid),0)where substr(def_rcbdj.TS,0,10)=''' || rq || ''' ';execute immediate mprice;commit; --记录最新月初单价xzprice := ' update def_rcbdj set kcdj=monthpricewhere 1=1and ddate= to_char(sysdate,''yyyy-mm-dd'')and(casewhen to_number(cskcdj, ''9999999999.9999'') > 0 and nvl(monthprice,0)<>0 then(to_number(cskcdj, ''9999999999.9999'') -to_number(monthprice, ''9999999999.9999'')) /to_number(cskcdj, ''9999999999.9999'')else0end)>0.2or (casewhen to_number(cskcdj, ''9999999999.9999'') > 0 and nvl(monthprice,0)<>0 then(to_number(cskcdj, ''9999999999.9999'') -to_number(monthprice, ''9999999999.9999'')) /to_number(cskcdj, ''9999999999.9999'')else0end)<-0.2 ';execute immediate xzprice; --当误差为上下浮动二十个百分点的时候修正单价commit;end if; --已经结账公司算法end;
end pro_aikcdj;
|