CLOSE ALL
SET NEAR OFF

USE d:\2009\robno\baze\zagfak ALIAS zagfak exclusive IN 0
USE d:\2009\robno\baze\fakstav ALIAS fakstav exclusive IN 0

USE d:\2009\pod\novembar\fdir ALIAS szf IN 0
USE d:\2009\pod\novembar\fakstav ALIAS ssf IN 0
USE d:\2009\pod\august\KUPDOB ALIAS sKUP IN 0

SELECT zagfak
ZAP
SELECT fakstav
ZAP

SELECT szf
GOTO top
DO WHILE !EOF()
IF val(szf.preduzece)<>1
	SKIP
	LOOP
ENDIF

*!*	IF ALLTRIM(szf.magid)<>"1"
*!*		SKIP
*!*		LOOP
*!*	ENDIF
	
if szf.datum<ctod("01.01.2009")
	skip
	loop
endif
	
mid	 =szf.fdirid
mtip =szf.tipid
mbrd =szf.dokument
mdat =szf.datum
mkup1=szf.ppid
mval =szf.valuta
mmag =ALLTRIM(szf.magid)

SELECT skup
SET ORDER TO tag ppid
GOTO top
SEEK mkup1
mkup =skup.kupdob
mpvre=0

SELECT ssf
SET ORDER TO tag fdirid
GOTO top
SEEK mid	
DO WHILE !EOF()
IF ssf.fdirid<>mid
	EXIT
ENDIF
msif=ssf.sifrob
mkol=ssf.kolicina
mpce=ssf.pcena
msto=ssf.stopa*100
mrab=ssf.rabat*100

mpvre=mpvre+mkol*mpce*(1-mrab/100)

SELECT fakstav
APPEND BLANK
replace fakstav.brdok	WITH mbrd
replace fakstav.datum	WITH mdat
replace fakstav.sifrob	WITH msif
replace fakstav.magacin	WITH mmag
replace fakstav.kupdob	WITH mkup
replace fakstav.kolicina	WITH mkol
replace fakstav.stopa	WITH msto
replace fakstav.pcena	WITH mpce
replace fakstav.rabat	WITH mrab

SELECT ssf
SKIP
ENDDO

SELECT zagfak
APPEND BLANK
replace zagfak.brdok	WITH mbrd
replace zagfak.magacin	WITH mmag
replace zagfak.datum	WITH mdat
replace zagfak.valuta	WITH mval
replace zagfak.kupdob	WITH mkup
replace zagfak.pvred	WITH mpvre

SELECT szf
SKIP
ENDDO
RETURN


