CLOSE ALL

SET DELETED ON
SET CENTURY on
SET DATE german
USE c:\2006\baze\roba ALIAS roba IN 0
SELECT roba
zap
USE c:\2006\baze\kupdob ALIAS kupdob IN 0
SELECT kupdob
ZAP
USE c:\2006\baze\zagrac ALIAS zagrac IN 0
SELECT zagrac
ZAP
USE c:\2006\baze\zagkalk ALIAS zagkalk IN 0
SELECT zagkalk
zap
USE c:\2006\baze\zagniv ALIAS zagniv IN 0
SELECT zagniv
zap
USE c:\2006\baze\racstav ALIAS racstav IN 0
SELECT racstav
zap
USE c:\2006\baze\kalkstav ALIAS kalkstav IN 0
SELECT kalkstav
ZAP
USE c:\2006\baze\nivstav ALIAS nivstav IN 0
SELECT nivstav
ZAP
USE c:\2006\baze\prihod ALIAS prihod IN 0
SELECT prihod
ZAP

USE c:\2006\a\kupdob ALIAS skupdob IN 0
USE c:\2006\a\roba ALIAS sroba IN 0
USE c:\2006\a\dokument ALIAS sdokument IN 0
USE c:\2006\a\anarob ALIAS sanarob IN 0
USE c:\2006\a\izvod ALIAS sizvod IN 0

SELECT sroba
GOTO top
DO WHILE !EOF()
a=sroba.sifra
b=sroba.naziv
c=sroba.naziv2
d=sroba.jm
e=sroba.kolicina
f=sroba.ncena
g=sroba.pcena
h="18"
SELECT roba
	APPEND BLANK
	replace roba.sifrob	WITH a
	replace roba.naziv	WITH b
	replace roba.skrnaz	WITH c
	replace roba.jm		WITH d
	replace roba.kolicina WITH e
	replace roba.nabcen WITH f
	replace roba.procen	WITH g
	replace roba.tarifa WITH h
SELECT sroba
SKIP
ENDDO

SELECT skupdob
GOTO top
DO WHILE !EOF()
a=skupdob.sifra
b=skupdob.sif1
c=skupdob.naziv
d=skupdob.mesto
e=skupdob.adresa
f=skupdob.tel1
g=skupdob.ziro
	SELECT kupdob
	APPEND BLANK
	a=ALLTRIM(str(a))
	ml=LEN(A)
	a=REPLICATE("0",6-ml)+a
	replace kupdob.kupdob 	WITH a
	replace kupdob.sif1		WITH b
	replace kupdob.naziv	WITH c
	replace kupdob.mesto	WITH d
	replace kupdob.adresa	WITH e
	replace kupdob.tel1		WITH f
	replace kupdob.ziro		WITH g
SELECT skupdob
SKIP
ENDDO

SELECT sizvod
GOTO top
DO WHILE !EOF()
a=datum
b=pazar
c=gotovina
d=cekovi+eskont+virmani
SELECT prihod
	APPEND BLANK
	replace prihod.datum 	WITH a
	replace prihod.ukupno 	WITH b
	replace prihod.gotovina	WITH c
	replace prihod.virman	WITH d
	replace prihod.pdv18 	WITH b*18/118
	replace prihod.paz18 	WITH b*(1-18/118)
SELECT sizvod
SKIP
ENDDO

SELECT sdokument
GOTO top
DO WHILE !EOF()
a=sifdok
b=brdok
c=datum
c1=valuta
d=dokumenat
e=brdoki
f=kupdob
g=nvred
h=marza
i=porez
j=pvred
k=vreme

f=ALLTRIM(str(f))
ml=LEN(f)
f=REPLICATE("0",6-ml)+f

b=ALLTRIM(str(b))
ml=LEN(b)
b=REPLICATE("0",6-ml)+b

	IF a=1
		SELECT zagkalk
		APPEND BLANK
		replace brdok 		WITH b
		replace kupdob 		WITH f
		replace dokument	WITH d
		replace brdoki		WITH e
		replace datum 		WITH c
		replace valuta 		WITH c1
		replace nvred		WITH g
		replace pvred		WITH j
		replace porez		WITH i
		replace marza		WITH h
		replace vreme 		WITH k
		replace dobvre		WITH g
	ENDIF
	IF a=2
		SELECT zagniv
		APPEND BLANK
		replace brdok 		WITH b
*		replace dokument	WITH d
		replace brdoki		WITH e
		replace datum 		WITH c
		replace svred		WITH g
		replace nvred		WITH j
		replace pdv			WITH i
		replace marza		WITH h
		replace vreme 		WITH k
	ENDIF
	IF a=3
		SELECT zagrac
		APPEND BLANK
		replace brdok 		WITH b
		replace kupdob 		WITH f
		replace datum 		WITH c
		replace nvred		WITH g
		replace pvred		WITH j
		replace porez		WITH i
		replace marza		WITH h
		replace vreme 		WITH k
	endif				

	IF A=1
		SELECT sanarob
		GOTO top
		LOCATE FOR sanarob.brdok=VAL(b) .and. sanarob.sifdok=1
		DO WHILE !EOF()
		IF sanarob.sifdok<>1
			CONTINUE
			LOOP
		endif	
		IF sanarob.brdok<>VAL(b)
			EXIT
		ENDIF
		mdat=sanarob.datum
		mkup=f
		msif=sanarob.sifra
		mkol=sanarob.kolicina
		mnce=sanarob.ncena
		mpce=sanarob.pcena
		mvre=sanarob.vreme
		SELECT kalkstav
		APPEND BLANK
		replace kalkstav.datum WITH mdat
		replace kalkstav.brdok WITH b
		replace kalkstav.kupdob WITH f
		replace kalkstav.sifrob WITH msif
		replace kalkstav.kolicina WITH mkol
		replace kalkstav.dobcen WITH mnce
		replace kalkstav.ncena WITH mnce
		replace kalkstav.pcena WITH mpce
		replace kalkstav.vreme WITH mvre
		replace kalkstav.tarifa WITH "18"
		replace kalkstav.stopa WITH 18
		SELECT sanarob
		CONTINUE
		ENDDO
	ENDIF
	IF A=2
		SELECT sanarob
		GOTO top
		LOCATE FOR sanarob.brdok=VAL(b) .and. sanarob.sifdok=2
		DO WHILE !EOF()
		IF sanarob.sifdok<>2
			CONTINUE
			LOOP
		endif	
		IF sanarob.brdok<>VAL(b)
			EXIT
		ENDIF
		mdat=sanarob.datum
		mkup=f
		msif=sanarob.sifra
		mkol=sanarob.kolicina
		mnce=sanarob.ncena
		mpce=sanarob.pcena
		mvre=sanarob.vreme
		SELECT nivstav
		APPEND BLANK
		replace nivstav.datum WITH mdat
		replace nivstav.brdok WITH b
*		replace nivstav.kupdob WITH f
		replace nivstav.sifrob WITH msif
		replace nivstav.kolicina WITH mkol
*		replace nivstav.dobcen WITH mnce
		replace nivstav.scena WITH mnce
		replace nivstav.ncena WITH mpce
		replace nivstav.vreme WITH mvre
		replace nivstav.tarifa WITH "18"
*		replace nivstav.stopa WITH 18
		SELECT sanarob
		CONTINUE
		ENDDO
	ENDIF
	IF A=3
		SELECT sanarob
		GOTO top
		LOCATE FOR sanarob.brdok=VAL(b) .and. sanarob.sifdok=3
		DO WHILE !EOF()
		IF sanarob.sifdok<>3
			CONTINUE
			LOOP
		endif	
		IF sanarob.brdok<>VAL(b) 
			EXIT
		ENDIF
		mdat=sanarob.datum
		mkup=f
		msif=sanarob.sifra
		mkol=sanarob.kolicina
		mnce=sanarob.ncena
		mpce=sanarob.pcena
		mvre=sanarob.vreme
		SELECT racstav
		APPEND BLANK
		replace racstav.datum WITH mdat
		replace racstav.brdok WITH b
		replace racstav.kupdob WITH f
		replace racstav.sifrob WITH msif
		replace racstav.kolicina WITH mkol
*		replace racstav.dobcen WITH mnce
		replace racstav.ncena WITH mnce
		replace racstav.pcena WITH mpce
		replace racstav.vreme WITH mvre
		replace racstav.tarifa WITH "18"
*		replace racstav.stopa WITH 18
		SELECT sanarob
		CONTINUE
		ENDDO
	ENDIF
SELECT sdokument
SKIP
ENDDO
	
CLOSE ALL
