SET DEFAULT TO d:\2016\baze
CLOSE ALL
SET DATE GERMAN
SET CENTURY ON	
mdat=CTOD("13.12.2015")
USE kalkstav ALIAS kalkstav
SELECT kalkstav
DELETE ALL FOR kalkstav.datum<MDAT
PACK

USE nivstav ALIAS nivstav 
SELECT nivstav
DELETE ALL FOR nivstav.datum<MDAT
PACK

USE povstav ALIAS povstav 
SELECT povstav
DELETE ALL FOR povstav.datum<MDAT
PACK
	
USE prihod ALIAS prihod 
SELECT prihod
ZAP

USE kalostav ALIAS kalostav 
SELECT kalostav
DELETE ALL FOR kalostav.datum<MDAT
PACK

USE racstav ALIAS racstav 
SELECT racstav
DELETE ALL FOR racstav.datum<MDAT
PACK

USE rpovstav ALIAS rpovstav 
SELECT rpovstav
DELETE ALL FOR rpovstav.datum<MDAT
PACK

USE rzagpov ALIAS rzagpov 
SELECT rzagpov
DELETE ALL FOR rzagpov.datum<MDAT
PACK

USE zagkalk ALIAS zagkalk 
SELECT zagkalk
DELETE ALL FOR zagkalk.datum<MDAT
PACK

USE zagkalo ALIAS zagkalo 
SELECT zagkalo
DELETE ALL FOR zagkalo.datum<MDAT
PACK

USE zagniv ALIAS zagniv 
SELECT zagniv
DELETE ALL FOR zagniv.datum<MDAT
PACK

USE zagpov ALIAS zagpov 
SELECT zagpov
DELETE ALL FOR zagpov.datum<MDAT
PACK

USE zagrac ALIAS zagrac 
SELECT zagrac
DELETE ALL FOR zagrac.datum<MDAT
PACK

USE zagracp ALIAS zagracp 
SELECT zagracp
DELETE ALL FOR zagracp.datum<MDAT
PACK

USE inventar ALIAS inventar IN 0
USE kalkstav ALIAS kalkstav IN 0
USE zagkalk ALIAS zagkalk IN 0
USE roba ALIAS roba IN 0
SELECT roba
PACK

SELECT inventar
GOTO top
DO WHILE !EOF()
a1=inventar.kolicina
IF a1<=0
	SKIP
	LOOP
ENDIF
a2=inventar.nabcen
a3=inventar.procen
a4=inventar.kolicina
a5=inventar.sifrob
SELECT kalkstav
APPEND BLANK
replace kalkstav.brdok 		WITH "PS"
replace kalkstav.datum 		WITH mdat
replace kalkstav.sifrob 	WITH a5
replace kalkstav.kolicina 	WITH a4
replace kalkstav.dobcen 	WITH a2
replace kalkstav.ncena 		WITH a2
replace kalkstav.pcena 		WITH a3
SELECT roba
SET ORDER TO tag sifrob
GOTO top
SEEK a5
SELECT kalkstav	
replace kalkstav.tarifa 	WITH roba.tarifa
IF kalkstav.tarifa="10"
	replace kalkstav.stopa 		WITH 10
ELSE
	replace kalkstav.stopa		WITH 20
ENDIF
SELECT inventar
SKIP
ENDDO

SELECT zagkalk
APPEND BLANK
replace zagkalk.brdok WITH "PS"
replace zagkalk.datum WITH mdat
RETURN
	