SET DELETED ON
SET DATE GERMAN
SET CENTURY ON
OPEN DATABASE c:\2014\baze\str SHARED

USE roba ALIAS roba SHARED IN 0
USE nivstav ALIAS nivstav EXCLUSIVE IN 0
USE zagniv ALIAS zagniv IN 0

SELECT nivstav
**ZAP

select roba
GOTO top
DO while !EOF()
IF roba.tarifa="08" OR roba.tarifa="8 "
	replace roba.tarifa WITH "10"
ENDIF
SKIP
ENDDO

msnv=0
mssv=0
msma=0
mspo=0	
SELECT roba
GOTO top
DO WHILE !EOF()
IF roba.tarifa<>"10"
	SKIP
	LOOP
ENDIF
IF roba.kolicina<=0
	SKIP
	LOOP
endif		
a1=roba.sifrob
a2=roba.procen
a3=roba.kolicina
a4=roba.procen/1.08
a4=ROUND(a4*1.1,0)

	SELECT nivstav
	APPEND BLANK
	replace nivstav.brdok	WITH "000002"
	replace nivstav.sifrob WITH a1
	replace nivstav.kolicina WITH a3
	replace nivstav.scena WITH a2
	replace nivstav.ncena WITH a4 
	replace nivstav.marza WITH (nivstav.ncena-nivstav.scena)*(1-10/110)
	replace nivstav.datum WITH CTOD("04.01.2014")
	REPLACE NIVSTAV.VREME WITH "14:10:00"
	replace nivstav.pdv WITH (nivstav.ncena-nivstav.scena)*(10/110)
	REPLACE NIVSTAV.tarifa WITH "10"
	replace nivstav.stopa WITH 10
	replace nivstav.naziv WITH roba.naziv
	replace nivstav.jm WITH roba.jm
	msnv=msnv+a3*a4
	mssv=mssv+a3*a2
	msma=msma+a3*nivstav.marza
	mspo=mspo+a3*nivstav.pdv

SELECT roba
SKIP
ENDDO


SELECT zagniv
APPEND BLANK
replace zagniv.datum	WITH CTOD("04.01.2014")
replace zagniv.brdok	WITH "000002"
replace zagniv.svred	WITH mssv
replace zagniv.nvred	WITH msnv
replace zagniv.marza	WITH msma
replace zagniv.pdv		WITH mspo
replace zagniv.vreme	WITH "14:10:00"

RETURN
	