delete from smspec where doctype = 'WO' and docid = 'РНПЮ0000000008'
insert into smspec(doctype, docid, specitem, displayitem, article, quantity,
itemprice,
totalprice,
itempricenotax,
totalpricenotax, itempricecur, totalpricecur, causetype, causeid, causespecitem)
select 'WO', 'РНПЮ0000000008', rownum, rownum, article, abs(diff),
nvl(supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
nvl(abs(diff) * supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
null, null,
nvl(supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
nvl(abs(diff) * supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
null,null, null
from (
select r2.article, r1.quantity, r2.quantity, nvl(r2.quantity, 0) - nvl(r1.quantity, 0) diff
from smgoods r1,
smgoods@DBNOHT18 r2
where r1.article(+) = r2.article
and r1.storeloc (+) = 46
and r2.storeloc = 46
and nvl(r1.quantity, 0) != nvl(r2.quantity, 0)
)
where diff < 0
delete from smspec where doctype = 'WI' and docid = 'ПНЮГ02810'
insert into smspec(doctype, docid, specitem, displayitem, article, quantity,
itemprice,
totalprice,
itempricenotax,
totalpricenotax, itempricecur, totalpricecur, causetype, causeid, causespecitem)
select 'WI', 'ПНЮГ02810', rownum, rownum, article, abs(diff),
nvl(supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
nvl(abs(diff) * supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
null, null,
nvl(supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
nvl(abs(diff) * supermag.SMGETPRICEONDATERL(article, 43, 46, to_date('25.04.2016', 'dd.mm.yyyy')), 0.01),
null,null, null
from (
select r2.article, r1.quantity, r2.quantity, nvl(r2.quantity, 0) - nvl(r1.quantity, 0) diff
from smgoods r1,
smgoods@DBNOHT18 r2
where r1.article(+) = r2.article
and r1.storeloc (+) = 46
and r2.storeloc = 46
and nvl(r1.quantity, 0) != nvl(r2.quantity, 0)
)
where diff > 0
update smdocuments set
totalsum = (select sum(totalprice) from smspec where docid = 'ПНЮГ02810' and doctype = 'WI'),
totalsumcur = (select sum(totalprice) from smspec where docid = 'ПНЮГ02810' and doctype = 'WI')
where id = 'ПНЮГ02810' and doctype = 'WI'
update smdocuments set
totalsum = (select sum(totalprice) from smspec where docid = 'РНПЮ0000000008' and doctype = 'WO'),
totalsumcur = (select sum(totalprice) from smspec where docid = 'РНПЮ0000000008' and doctype = 'WO')
where id = 'РНПЮ0000000008' and doctype = 'WO'