Stok miktar kontrolü için SQL komutu

Depolarda görünen kayıtlı stok miktarları ile belgelerden hesaplanan stok miktarlarını karşılaştırıp farklı olanları görmek için aşağıdaki kodu kullanın.

execute block
returns
(
	xkonum_k type of k,
	xstok_k type of k,
	xgiris type of miktar,
	xcikis type of miktar,
	xhesaplanangiris type of miktar,
	xhesaplanancikis type of miktar
)
as
begin
	for select k from konum where ustk > 1 into :xkonum_k do 
	begin
		for select s.k, sm.giris, sm.cikis from stok s join stokmiktar sm on s.k=sm.stok_k and sm.konum_k=:xkonum_k into :xstok_k, :xgiris, :xcikis do
		begin
			xhesaplanangiris=0;
			xhesaplanancikis=0;
			
			select 
			sum(case when bt.stokgiris=1 then bd.birimmiktar else 0 end), 
			sum(case when bt.stokcikis=1 then bd.birimmiktar else 0 end)
			from belge b 
			join belgetur bt on b.belgetur_k=bt.k and b.konum_k=:xkonum_k
			join belgedetay bd on bd.belge_k=b.k and b.belgedurum_k=2 and bd.iptal=0 and coalesce(b.etkisiz,0)=0 and coalesce(b.irsaliyedenhazirlanmis,0)=0
			join stokbirimbarkod sbb on sbb.barkod=bd.barkod
			join stokbirim sb on sb.k=sbb.stokbirim_k and sb.stok_k=:xstok_k
			into :xhesaplanangiris, :xhesaplanancikis;

			if (xgiris <> xhesaplanangiris or xcikis <> xhesaplanancikis) then
			begin
				suspend;
			end
		end	
	end
end

Bu kod nasıl aktif edilir

Sistem menüsünden SQL komut menüsüne 7193sql şifresi ile giriş yapın ve kodu yapıştırın. F9 tuşuna basarak komutu çalıştırabilirsiniz.

1 Beğeni