CLOSE ALL

USE d:\2009\pod\august\zagkalk ALIAS zag1 IN 0
USE d:\2009\pod\august\kalkstav ALIAS kal1 IN 0
SELECT kal1
SET ORDER TO tag brdok
GOTO top

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

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

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

SELECT zagkalk
APPEND BLANK
replace zagkalk.brdok	WITH mbrd
replace zagkalk.datum	WITH mdat
replace zagkalk.kupdob	WITH mkup
replace zagkalk.brdoki	WITH mbrdi
replace zagkalk.magacin	WITH "001"
*replace zagkalk.nvred	WITH nvre
*replace zagkalk.porez	WITH mpor

nvre=0
mpdv18=0
mpdv8=0
SELECT kal1
GOTO top
SEEK mbrkal
DO WHILE !EOF()
IF kal1.brdok<>mbrkal
	exit	
ENDIF
mkol=kal1.kolicina
mzav=kal1.zavtros+kal1.carina
mnab=kal1.nabcen
mpro=kal1.procen
mrab=kal1.rabat
msto=kal1.stopa
msif=kal1.sifrob
nvre=nvre+kal1.nabvre
IF ustopa=0.18
	mpdv18=mpdv18+mnab*mkol*ustopa
ENDIF
IF ustopa=0.08
	mpdv8 =mpdv8 +mnab*mkol*ustopa
endif	
	
SELECT kalkstav
APPEND BLANK
replace kalkstav.brdok WITH mbrd
replace kalkstav.datum	WITH mdat
replace kalkstav.kupdob	WITH mkup
replace kalkstav.ncena	WITH mnab
replace kalkstav.pcena	WITH mpro
replace kalkstav.rabat	WITH mrab*100
replace kalkstav.zavtros WITH mzav
replace kalkstav.stopa WITH msto*100
replace kalkstav.magacin	WITH "001"
replace kalkstav.kolicina WITH mkol
replace kalkstav.sifrob	WITH msif
replace kalkstav.dobcen WITH mnab
replace kalkstav.kupdob	WITH mkup

SELECT kal1
SKIP
ENDDO

SELECT zagkalk
replace zagkalk.nvred	WITH nvre
replace zagkalk.porez	WITH mpdv18+mpdv8


SELECT zag1
SKIP
ENDDO


RETURN

