CLOSE ALL
SET DATE GERMAN
SET CENTURY on
SET DELETED ON

mdat=CTOD("25.12.2022")
OPEN DATABASE  str 
USE roba ALIAS roba EXCLUSIVE IN 0
USE kalkstavc ALIAS kalkstavc EXCLUSIVE IN 0
USE kalkstav ALIAS kalkstav EXCLUSIVE IN 0
USE inventar ALIAS inventar EXCLUSIVE IN 0

SELECT kalkstavc
GOTO top
DO WHILE !EOF()
IF ALLTRIM(kalkstavc.brdok)=="NUL" OR ALLTRIM(kalkstavc.brdok)=="POP"
	DELETE
ENDIF
SKIP
ENDDO
	
SELECT roba
goto top
DO WHILE !EOF()
IF roba.kolicina<>0 AND roba.usluga<>"D"
	a1=roba.sifrob
	a2=roba.nabcen
	a3=roba.procen
	a4=roba.tarifa
	a5=roba.kolicina
	SELECT kalkstavc
	APPEND BLANK
	replace kalkstavc.brdok WITH "NUL"
	replace kalkstavc.datum WITH mdat
	replace kalkstavc.sifrob WITH a1
	replace kalkstavc.ncena WITH a2
	replace kalkstavc.pcena WITH a3
	replace kalkstavc.kolicina WITH -a5
	replace kalkstavc.dobcen WITH a2
	replace kalkstavc.tarifa WITH a4
	replace kalkstavc.stopa WITH VAL(a4)
ENDIF
SELECT roba
SKIP
ENDDO

SELECT inventar
GOTO top
DO WHILE !EOF()
IF kolicina>0
	a1=inventar.sifrob		
	a2=inventar.kolicina
	SELECT roba
	SET ORDER TO tag sifrob
	GOTO top
	SEEK a1
	a3=roba.tarifa
	a4=roba.nabcen
	a5=roba.procen
	SELECT kalkstavc
	APPEND BLANK
	replace kalkstavc.brdok WITH "POP"
	replace kalkstavc.datum WITH mdat+1
	replace kalkstavc.sifrob WITH a1
	replace kalkstavc.ncena WITH a4
	replace kalkstavc.pcena WITH a5
	replace kalkstavc.kolicina WITH a2
	replace kalkstavc.dobcen WITH a4
	replace kalkstavc.tarifa WITH a3
	replace kalkstavc.stopa WITH VAL(a3)
ENDIF
SELECT inventar
SKIP
ENDDO
RETURN
	
	
	