CLOSE ALL

USE d:\2009\pod\robno\zagniv ALIAS zn1 IN 0
USE d:\2009\pod\robno\nivstav ALIAS sn1 IN 0
SELECT sn1
SET ORDER TO tag nivid
GOTO top

USE d:\2009\robno\baze\zagniv ALIAS zagniv IN 0
SELECT zagniv
ZAP

USE d:\2009\robno\baze\nivstav ALIAS nivstav IN 0
SELECT nivstav
zap



SELECT zn1
GOTO top
DO WHILE !EOF()
IF ALLTRIM(preduzece)<>"1"
	SKIP
	LOOP
ENDIF
IF ALLTRIM(magacin)<>"1"
	SKIP
	LOOP
ENDIF
mbrd=brdok
mdat=datum
mbrniv=nivid
*mkup=kupdob
*mbrdi=brdoki
*mbrkal=idkalkd

SELECT zagniv
APPEND BLANK
replace zagniv.brdok	WITH mbrd
replace zagniv.datum	WITH mdat
replace zagniv.tip		WITH 1
replace zagniv.magacin	WITH "001"

svre=0
nvre=0
sruc=0
SELECT sn1
GOTO top
SEEK mbrniv
DO WHILE !EOF()
IF sn1.nivid<>mbrniv
	exit	
ENDIF
msif=sn1.sifrob
mkol=sn1.kolicina
msce=sn1.staracena
mnce=sn1.novacena
mstopa=sn1.stopa*100
	
SELECT nivstav
APPEND BLANK
replace nivstav.brdok WITH mbrd
replace nivstav.datum	WITH mdat
replace nivstav.kolicina	WITH mkol
replace nivstav.sifrob	WITH msif
replace nivstav.scena	WITH msce
replace nivstav.ncena	WITH mnce
replace nivstav.marza	WITH mnce-msce
replace nivstav.stopa WITH mstopa
replace nivstav.magacin WITH "001"
replace nivstav.tip		WITH 1
svre=svre+mkol*msce
nvre=nvre+mkol*mnce
sruc=sruc+svre-nvre

SELECT sn1
SKIP
ENDDO

SELECT zagniv
replace zagniv.svred	WITH svre
replace zagniv.nvred	WITH nvre
replace zagniv.marza	WITH svre-nvre

SELECT zn1
SKIP
enddo


RETURN

