offline
- srdjos
- Zaslužni građanin
- Pridružio: 27 Sep 2005
- Poruke: 678
|
hm, nisi jedini, sad sam i ja u takvoj situaciji,
queriji moraju da nam rade na svim tim bazama
koje si ti pomenuo plus Interbase i Sybase
i onda testiranje pun gas, da odlepis,
mora da se radi onaj cisti sql standard SQL-92
uglavnom, najvise nas Interbase zajebava
ovo je kod jos dok sam bio u NS-u
main bazica je bila MS SQL 2000 ,
u pitanju je cursor koji na MS SQL-u
kazu da se ne preteruje u koriscenju istog
(nije PL baza)
ovo je knjizenje nama famoznog PDV-a u glavnu knjigu
to bilo pre vise od godinu dana
ne moze cak ni da se formatira ovde
bolje da sam ga stavio u neki txt fajl
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_PDVShemaProknjizi]
(
@sh_SifKnjiz INT,
@sh_VaziOd smalldatetime,
@sh_Magacin NVARCHAR(5),
@sh_VrDok NVARCHAR(3),
@sh_NalFin NVARCHAR(2),
@sh_DatOd SMALLDATETIME,
@sh_DatDo SMALLDATETIME
)
AS
BEGIN TRAN roba_fina
-- DugPot 0-potrazuje 1-duguje
-- Znak 1 pozitiva, -1 negativa
-- Vrednost
-- 0 - nabavna vrednost
-- 1 - prodajna vrednost bez PDV-a
-- 2 - iznosPDV-a
-- 3 - prodajna vrednost sa PDV-om
-- 4 - rabat
-- 5 - Maloprodajna vrednost
-- Tip partnera
-- 0 - domaci
-- 1 - inostrani
-- 2 - Crna Gora
-- 3 - poljoprivrednik
-- 4 - licne potrebe preduzeca
DECLARE @magacin NVARCHAR(5), @oznaka NVARCHAR(3), @broj INT, @pdvdane BIT,
@tippartnera SMALLINT, @datum SMALLDATETIME, @dokument NVARCHAR(100),
@partner INT, @valutaR INT, @nabvred NUMERIC(18,4), @ProdVredbezPDV NUMERIC(18,4),
@ProdVredPDV NUMERIC(18,4), @rabat NUMERIC(18,4), @mpVred NUMERIC (18,4),
@porez NUMERIC (18,4), @marza NUMERIC(18,2),
-- deklaracija pomocnih promenjivih, pratim fakturu po fakturu
@pommag NVARCHAR(5), @pomozn NVARCHAR(3), @pombr INT,
@part_dane bit, @polje VARCHAR(20), @sql VARCHAR(4000),
@vpmp_magacin BIT,
-- deklaracije za drugi kursor
@konto NVARCHAR(8), @dugpot BIT, @znak SMALLINT,
@vrednost TINYINT, @tarifa INTEGER, @PDVOvbveznik BIT,
@tippartnera_s SMALLINT,
-- promenjive za fin. nalog i promene
@f_unet BIT, @f_broj INT, @f_rbr INT,
@f_tipanal TINYINT, @f_anal INT,
@f_dokument NVARCHAR(20), @f_opis NVARCHAR(20),
@f_dugpot NUMERIC(18, 2),
@f_duguje NUMERIC(18,2), @f_potrazuje NUMERIC(18,2),
@f_mestros INT,
-- promenjiva za gresku
@greska INT,
-- promenjiva za obracunavanje rabata
@obrRabata INT
SET @greska=0
SET @part_dane=(SELECT ISNULL(Part, 0) FROM _VPVrDok WHERE Oznaka=@sh_VrDok)
-------- neke od provera
IF @part_dane=1
BEGIN
IF EXISTS(SELECT TipPartnera
FROM _Partneri
WHERE Sifra IN (SELECT Partner FROM _VPDok
WHERE Magacin=@sh_Magacin
AND Oznaka=@sh_VrDok)
AND (TipPartnera<0 OR TipPartnera IS NULL))
BEGIN
SET @dokument=(SELECT TOP 1 Naziv
FROM _Partneri
WHERE Sifra IN (SELECT Partner FROM _VPDok
WHERE Magacin=@sh_Magacin
AND Oznaka=@sh_VrDok)
AND (TipPartnera<0 OR TipPartnera IS NULL))
RAISERROR('Tip partnera ne odgovara : %s , podaci neae biti upisani', 16, 1, @dokument)
GOTO kraj
END
END
IF NOT EXISTS(SELECT rd.Magacin, rd.Oznaka, rd.Broj, rd.PDVDaNe, part.TipPartnera,
rd.Datum, ISNULL(rd.Dokument,'') AS Dokument, rd.Partner, rd.ValutaR
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
LEFT JOIN _Partneri part
ON rd.Partner=part.Sifra
WHERE rd.Magacin=@sh_Magacin
AND rd.Oznaka=@sh_VrDok
AND Knjizeno IS NULL
AND rd.Datum BETWEEN @sh_DatOd AND @sh_DatDo
GROUP BY rd.Magacin, rd.Oznaka, rd.Broj, rd.Datum, rd.Dokument,
rd.Partner, rd.ValutaR, part.TipPartnera, rd.PDVDaNe)
BEGIN
RAISERROR('Bez podataka za knjiženje u finansijsko',16,1)
GOTO kraj
END
---------- kraj provera
-- uzimam nacin obracuna rabata
SET @obrRabata=(SELECT ISNULL(ObrRabata, 1) FROM _regi WHERE Sifra=1)
DECLARE RobFin_kursor CURSOR FOR
SELECT rd.Magacin, rd.Oznaka, rd.Broj, ISNULL(rd.PDVDaNe, 1) ASPDVDaNe, ISNULL(part.TipPartnera,0) AS TipPartnera,
rd.Datum, ISNULL(rd.Dokument,'') AS Dokument, rd.Partner, rd.ValutaR
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
LEFT JOIN _Partneri part
ON rd.Partner=part.Sifra
WHERE rd.Magacin=@sh_Magacin
AND rd.Oznaka=@sh_VrDok
AND Knjizeno IS NULL
AND rd.Datum BETWEEN @sh_DatOd AND @sh_DatDo
GROUP BY rd.Magacin, rd.Oznaka, rd.Broj, rd.Datum, rd.Dokument,
rd.Partner, rd.ValutaR, part.TipPartnera, rd.PDVDaNe
ORDER BY rd.Magacin, rd.Oznaka, rd.Broj
OPEN RobFin_kursor
FETCH NEXT FROM RobFin_kursor
INTO @magacin, @oznaka, @broj, @pdvdane, @tippartnera, @datum, @dokument, @partner, @valutaR
WHILE @@fetch_status=0
BEGIN
SET @pommag=@magacin SET @pomozn=@oznaka SET @pombr=@broj
DECLARE Shema_kursor CURSOR FOR
SELECT Konto, DugPot, Znak, Vrednost, Tarifa, PDVObveznik, TipPartnera
FROM _ShemaKnjiz
WHERE SifKnjiz=@sh_SifKnjiz
AND VaziOd<=(SELECT MAX(VaziOd)
FROM _ShemaKnjiz
WHERE SifKnjiz=@sh_SifKnjiz
AND VaziOd<=@sh_VaziOd)
AND PDVObveznik=@pdvdane
AND TipPartnera=@tippartnera
-- AND Tarifa IN (SELECT Tarifa
-- FROM _VPDokStavke
-- WHERE Magacin=@magacin
-- AND Oznaka=@oznaka
-- AND Broj=@broj)
ORDER BY RBr
-- setujem unos naloga fin knjigovodstva kao da nije unet
SET @f_unet=0
OPEN Shema_kursor
FETCH NEXT FROM Shema_kursor
INTO @konto, @dugpot, @znak, @vrednost, @tarifa,
@PDVOvbveznik, @tippartnera_s
WHILE (@pommag=@magacin) AND
(@pomozn=@oznaka) AND
(@pombr=@broj) AND
(@@fetch_status=0)
BEGIN
-- unos naloga finansijskog knjigovodstva
IF @f_unet=0
BEGIN
SET @f_broj=(SELECT ISNULL(MAX(Broj)+1,1) FROM _FNal WHERE Oznaka=@sh_NalFin)
INSERT INTO _FNal (Oznaka, Broj, Datum, StatusNal)
VALUES (@sh_NalFin, @f_broj, @datum, 0)
SET @greska=@greska+@@ERROR
-- nalog unet
SET @f_unet=1
END
-- ne pitaj zastoooooooooooooo je moralooooooooo ovakoooooooooooo,
-- ako ima tarifu, razbija po tarifama, u suprotnom, sumira sve zajedno
-- @vpmp_magacin=1 -- veleprodaja, razlika je u racunanju poreza ovde se racuna, kod maloprodaje se porez izbija
IF @sh_VrDok<>'MK'
BEGIN
IF @tarifa IS NULL
BEGIN
SELECT @nabvred=(SUM(rds.Kolicina*rds.NabCena)),
@ProdVredBezPDV=(SUM(rds.Kolicina*rds.ProdCena)),
@ProdVredPDV=(SUM(rds.Kolicina*(rds.ProdCena*(1+(rds.ProcPor/100))))),--(SUM(rds.Kolicina*(ROUND(rds.ProdCena*(1+(rds.ProcPor/100)), 2)))),
@Rabat=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.ProdCena*((rd.Rabat+rds.Rabat)/100)) )
WHEN 1 THEN SUM( (rds.Kolicina*rds.ProdCena) - (rds.Kolicina*(rds.ProdCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100)))) )
END,
@porez=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.ProdCena*(1-((rds.Rabat+rd.Rabat)/100)))*(rds.ProcPor/100) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.ProdCena*(1-(rds.Rabat/100)) * (1-(rd.Rabat/100)))*(rds.ProcPor/100) )
END,
@mpVred=
CASE @obrrabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*(1-((rds.Rabat+rd.Rabat)/100))) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100))) )
END
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
WHERE rd.Magacin=@magacin
AND rd.Oznaka=@oznaka
AND rd.Broj=@broj
END
ELSE
BEGIN
SELECT @nabvred=(SUM(rds.Kolicina*rds.NabCena)),
@ProdVredBezPDV=(SUM(rds.Kolicina*rds.ProdCena)),
@ProdVredPDV=(SUM(rds.Kolicina*(rds.ProdCena*(1+(rds.ProcPor/100))))),--(SUM(rds.Kolicina*(ROUND(rds.ProdCena*(1+(rds.ProcPor/100)), 2)))),
@Rabat=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.ProdCena*((rd.Rabat+rds.Rabat)/100)) )
WHEN 1 THEN SUM( (rds.Kolicina*rds.ProdCena) - (rds.Kolicina*(rds.ProdCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100)))) )
END,
@porez=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.ProdCena*(1-((rds.Rabat+rd.Rabat)/100)))*(rds.ProcPor/100) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.ProdCena*(1-(rds.Rabat/100)) * (1-(rd.Rabat/100)))*(rds.ProcPor/100) )
END,
@mpVred=
CASE @obrrabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*(1-((rds.Rabat+rd.Rabat)/100))) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100))) )
END
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
WHERE rd.Magacin=@magacin
AND rd.Oznaka=@oznaka
AND rd.Broj=@broj
AND rds.Tarifa=@tarifa
END
END
ELSE -- samo maloprodajne kalkulacije
BEGIN
IF @tarifa IS NULL
BEGIN
SELECT @nabvred=(SUM(rds.Kolicina*rds.NabCena)),
@ProdVredBezPDV=SUM(rds.Kolicina*rds.ProdCena),
@ProdVredPDV=(SUM(rds.Kolicina*(rds.ProdCena*(1+(rds.ProcPor/100))))),
@Rabat=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*((rd.Rabat+rds.Rabat)/100)) )
WHEN 1 THEN SUM( (rds.Kolicina*rds.MPCena) - (rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100)))) )
END,
@porez=
CASE @obrrabata
WHEN 0 THEN SUM( ((rds.Kolicina*rds.MPCena)*(1-((rds.Rabat+rd.Rabat)/100)) )*(rds.ProcPor/(100+rds.ProcPor)) )
WHEN 1 THEN SUM( ((rds.Kolicina*rds.MPCena)*(1-(rds.Rabat/100)) * (1-(rd.Rabat/100)) )*(rds.ProcPor/(100+rds.ProcPor)) )
END,
@mpVred=
CASE @obrrabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*(1-((rds.Rabat+rd.Rabat)/100))) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100))) )
END
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
WHERE rd.Magacin=@magacin
AND rd.Oznaka=@oznaka
AND rd.Broj=@broj
END
ELSE
BEGIN
SELECT @nabvred=(SUM(rds.Kolicina*rds.NabCena)),
@ProdVredBezPDV=SUM(rds.Kolicina*rds.ProdCena),
@ProdVredPDV=(SUM(rds.Kolicina*(rds.ProdCena*(1+(rds.ProcPor/100))))),
@Rabat=
CASE @obrRabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*((rd.Rabat+rds.Rabat)/100)) )
WHEN 1 THEN SUM( (rds.Kolicina*rds.MPCena) - (rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100)))) )
END,
@porez=
CASE @obrrabata
WHEN 0 THEN SUM( ((rds.Kolicina*rds.MPCena)*(1-((rds.Rabat+rd.Rabat)/100)) )*(rds.ProcPor/(100+rds.ProcPor)) )
WHEN 1 THEN SUM( ((rds.Kolicina*rds.MPCena)*(1-(rds.Rabat/100)) * (1-(rd.Rabat/100)) )*(rds.ProcPor/(100+rds.ProcPor)) )
END,
@mpVred=
CASE @obrrabata
WHEN 0 THEN SUM(rds.Kolicina*(rds.MPCena*(1-((rds.Rabat+rd.Rabat)/100))) )
WHEN 1 THEN SUM(rds.Kolicina*(rds.MPCena*(1-(rds.Rabat/100))*(1-(rd.Rabat/100))) )
END
FROM _VPDokStavke rds
INNER JOIN _VPDok rd
ON rds.Magacin=rd.Magacin
AND rds.Oznaka=rd.Oznaka
AND rds.Broj=rd.Broj
WHERE rd.Magacin=@magacin
AND rd.Oznaka=@oznaka
AND rd.Broj=@broj
AND rds.Tarifa=@tarifa
END
END
SET @greska=@greska+@@ERROR
-- unos promena naloga
SET @f_dugpot=(SELECT CASE @tippartnera
WHEN 0 THEN-- domaci
(SELECT CASE @pdvdane
WHEN 1 THEN -- obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
WHEN 0 THEN -- nije obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
END)
WHEN 1 THEN -- INOSTRANI
(SELECT CASE @pdvdane
WHEN 1 THEN -- obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
WHEN 0 THEN -- nije obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
END)
WHEN 2 THEN -- CRNA GORA
(SELECT CASE @pdvdane
WHEN 1 THEN -- obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
WHEN 0 THEN -- nije obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
END)
WHEN 4 THEN -- LICNE POTREBE PREDUZECA
(SELECT CASE @pdvdane
WHEN 1 THEN -- obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
WHEN 0 THEN -- nije obveznik
(SELECT CASE @vrednost
WHEN 0 THEN @nabvred
WHEN 1 THEN @ProdVredbezPDV
WHEN 2 THEN @porez
WHEN 3 THEN @ProdVredbezPDV-@rabat+@porez
WHEN 4 THEN @rabat
WHEN 5 THEN @mpVred
END)
END)
END)
-- odavle
IF @dugpot=1
BEGIN
SET @f_duguje=(@znak*@f_dugpot)
SET @f_potrazuje=0.00
END
ELSE
BEGIN
SET @f_duguje=0.00
SET @F_potrazuje=(@znak*@f_dugpot)
END
IF (SELECT ISNULL(Analitika,0) FROM _FKon WHERE Konto=@konto)=1
BEGIN
SET @f_tipAnal=(SELECT TipAnal FROM _FKon WHERE Konto=@konto)
SET @f_anal=@partner
END
ELSE
BEGIN
SET @f_tipAnal=NULL
SET @f_anal=NULL
END
-- IF (SELECT ISNULL(TrMesto,0) FROM _FKon WHERE Konto=@konto)=1
-- SET @f_mestros=(SELECT MestoTroska FROM _VPMagacin WHERE Oznaka=@sh_Magacin)
-- ELSE
SET @f_mestros=null
SET @f_dokument=UPPER(@magacin+'/'+@oznaka+'/'+CAST(@broj AS NVARCHAR(8)))
SET @f_opis=LEFT(@dokument,20)
SET @f_rbr=(SELECT ISNULL(MAX(Id)+1, 1)
FROM _FPromene
WHERE Oznaka=@sh_NalFin
AND Broj=@f_broj)
BEGIN TRAN UnosStavke
IF (@f_duguje<>0 OR @f_potrazuje<>0)
BEGIN
INSERT INTO _FPromene (Oznaka,Broj,Id,DPO,Konto,Opis,Dokument,Valuta,
Duguje,Potrazuje, Mesto, TipAnalitike, Analitika)
VALUES (@sh_NalFin, @f_broj, @f_rbr, @datum, @konto, @f_opis, @f_dokument,
@valutaR, @f_duguje, @f_potrazuje, @f_mestros, @f_tipanal, @f_anal)
SET @greska=@greska+@@ERROR
END
COMMIT TRAN UnosStavke
SELECT @sql =
CASE @f_tipanal
WHEN 1 THEN 'UPDATE _FPromene SET Kupac='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 2 THEN 'UPDATE _FPromene SET Dobavljac='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 3 THEN 'UPDATE _FPromene SET Pogon='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 4 THEN 'UPDATE _FPromene SET Zaposlen='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 5 THEN 'UPDATE _FPromene SET Kredit='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 6 THEN 'UPDATE _FPromene SET PrivLice='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
WHEN 7 THEN 'UPDATE _FPromene SET PosAnal='+CAST(@f_anal AS VARCHAR(20)) +' WHERE Oznaka='''+CAST(@sh_NalFin AS VARCHAR(2))+''' AND Broj='+CAST(@f_broj AS VARCHAR(20))+' AND Id='+CAST(@f_rbr AS VARCHAR(20))
ELSE NULL
END
IF @sql IS NOT NULL
EXEC(@sql)
SET @greska=@greska+@@ERROR
FETCH NEXT FROM Shema_kursor
INTO @konto, @dugpot, @znak, @vrednost, @tarifa,
@PDVOvbveznik, @tippartnera_s
END
CLOSE Shema_kursor
DEALLOCATE Shema_kursor
BEGIN TRAN UpdateDokumenta
UPDATE _VPDok
SET Knjizeno=@sh_NalFin+'/'+CAST(@f_broj AS NVARCHAR(10))
WHERE Magacin=@magacin
AND Oznaka=@oznaka
AND Broj=@Broj
SET @greska=@greska+@@error
COMMIT TRAN UpdateDokumenta
FETCH NEXT FROM RobFin_kursor
INTO @magacin, @oznaka, @broj, @pdvdane, @tippartnera, @datum, @dokument, @partner, @valutaR
END
CLOSE RobFin_kursor
DEALLOCATE RobFin_kursor
SET @greska=@greska+@@error
IF @greska <> 0
GOTO kraj
ELSE
COMMIT TRAN roba_fina
kraj:
ROLLBACK TRAN roba_fina
RETURN @greska
|