Provjerava razlike TKM i Lager

Ares procedura, poziva se na dokumentu nivelacije.

Kreirajte novi ispis na trenutni datum i na carobnjak pozovite proceduru.

 

Dobijete pregled gresaka ne slaganja TKM i Lagera po artiklima

-------

 

declare @acWarehouse char (30),
@cKey char (13),
@adDate datetime

set @cKey = '#acKey#'
set @acWarehouse = (select acReceiver from tHE_Move where acKey = @cKey)
set @adDate = (select adDate from tHE_Move where acKey = @cKey)

if object_id('tempdb..#sif') is not null
drop table #sif

select z.acIdent, z.anStock*case when c.anSalePrice is null then m.anSalePrice else c.anSalePrice end as Total
into #sif
from tHE_Stock z
inner join tHE_SetItem m on z.acIdent = m.acIdent
left join tHE_SetItemPriceForWrh c on m.acIdent = c.acIdent and c.acWarehouse = @acWarehouse
where z.acWarehouse = @acWarehouse

if object_id('tempdb..#tkm') is not null
drop table #tkm

select p.acIdent,
sum(case
when d.acType = 'P' then p.anQty * p.anSalePrice
when d.acType = 'I' then p.anQty * (-1) * p.anSalePrice
when d.acType = 'C' and g.acVerifyStatus <> 'N' then p.anRebate * p.anPrice
when d.acType = 'C' and g.acVerifyStatus = 'N' then 0
when d.acType = 'E' and g.acReceiver = @acWarehouse and g.acIssuer <> @acWarehouse then p.anQty * p.anInSalePrice
when d.acType = 'E' and g.acReceiver <> @acWarehouse and g.acIssuer = @acWarehouse then p.anQty * (-1) * p.anSalePrice
when d.acType = 'M' then (round(p.anQty *(-1) * (p.anRTPrice-p.anRTPrice*p.anRebate/100),2) )-(round(p.anQty *(-1) * (p.anRTPrice-p.anRTPrice*p.anRebate/100),2) - round(p.anQty *(-1) * p.anSalePrice,2))
end) as anTotal
into #tkm
from tHE_Move g
inner join tHE_MoveItem p on g.acKey = p.acKey
inner join tHE_SetItem m on p.acIdent = m.acIdent and m.acSetOfItem <> 'USL'
inner join tPA_SetDocType d on g.acDocType = d.acDocType
where (g.acReceiver = @acWarehouse or g.acIssuer = @acWarehouse)
and g.adDate <= @adDate and d.acType <> 'N'
group by p.acIdent

if object_id('tempdb..#repErr') is not null
drop table #repErr

select g.acIdent, g.Total, t.anTotal
into #repErr
from #sif g
left join #tkm t on g.acIdent = t.acIdent
where abs(abs(g.Total) - abs(t.anTotal)) > 0.1