clear
set century on
set date german
set exclusive off
set confirm oN
set console off
SET SAFETY OFF
set status bar off
set talk off
set deleted on
SET REPROCESS TO AUTOMATIC
SET OPTIMIZE ON
SET MULTILOCKS ON
SET ESCAPE OFF
SET BELL OFF


CLOSE DATABASES

PUBLIC sifraslike5

set sysmenu save
SET SYSMENU OFF
DEACTIVATE WINDOW "Standard"
putanja=CURDIR()
set default to &putanja

USE firma
mopcija=firma.opcioni
mglavni=firma.glavni
MPUTFIN=FIRMA.FINANS
MPUTPG=ALLTRIM(FIRMA.PROSLA)
sifraslike5=ALLTRIM(firma.slike)
sifraslikeo=ALLTRIM(firma.slikeo)
m.pravifak=ALLTRIM(firma.pravifak)
m.snimifak=ALLTRIM(firma.snimifak)
CLOSE databases
SET DEFAULT TO &mglavni
set path to &mopcija


set procedure to sve_proc.prg
USE parame
nazfir=ALLTRIM(parame.naziv)+" "+ALLTRIM(parame.naziv1)
CLOSE databases

MODIFY WINDOW SCREEN TITLE 'Robno poslovanje :'+nazfir icon file bluebug.ico

WITH _Screen
.WindowState = 2 
.MaxHeight=1000
.MaxWidth=1600
.MaxButton=.f.
.Closable=.f.
.AutoCenter=.t.
.backcolor=0
.movable=.T.
*.left=6
*.top=25
.fontbold=.t.
.fontsize=14
*.maxbutton=.f.
*.fontname="Tahoma"
*.picture=putanja+"\nsgeo.jpg"
ENDWITH


public m.sifkupdob, m.nazkupdob, m.adrkupdob, m.telkupdob, m.zirkupdob, m.meskupdob,M.MATKUPDOB, m.naz1kupdob, m.kuppdv, m.pttkupdob,m.pibkupdob
PUBLIC m.firma,m.firma1, m.adresa, M.MESTO, m.telefon, m.mobilni, m.fax,  m.kurs, m.email,m.trfir,m.sifban, m.maticni, m.ptt
PUBLIC oli, m.tarifa, sporocilo, KSTAJE, m.koef, fstaje, m.spor, m.matkupdob
PUBLIC m.magacin,m.magacinz, m.nazrob, m.sifrob, m.jm, m.brdok, helpkod,  m.stopa, m.nazmag
PUBLIC m.snvre, m.smar, m.spor, m.srab, m.spvre, mrb, m.ncena, m.pcena, mporez, mmarza
pUBLIC m.kolicina, m.maticni, m.registar, m.delatnost, m.ziro, m.brojdana, m.zadnce, m.magrad
PUBLIC merror, mess, mess1, mprog, mlineno, mkstaje, mfstaje,m.r1,m.slovima,m.rokpla
PUBLIC olir1,m.sdug,m.spot,m.uvecanje,m.ukupor,m.zavisni, mobrpor,m.nazban, m.suku, m.rab
PUBLIC mizjava, mdatizj, m.razduz, m.gotova, m.paragon, m.datod, m.datdo, m.malopor, m.malomar
PUBLIC m.nazgru, m.grupa, m.proizvod, m.nazpro, m.pib, m.pepdv, m.rabat, sifraslike, m.oddat, m.dodat
PUBLIC m.kljuc1,m.kljuc2,m.kljuc3,m.kljuc4,m.kljuc5,m.kljuc6,m.kljuc7,m.kljuc8,m.kljuc9,m.kljuc10
PUBLIC m.filsif, m.filnaz, sifraslike2, m.brpon, m.hjk, m.aktivan, m.brpar, m.mpcenadin, m.mpcenaeur
PUBLIC m.mpassword, masterpass, m.starakol, M.VOZAC, M.VOZILO, m.prefiks, M.AKTIVNOST, m.moze, m.euro, m.dolar
public m.istovar, m.prevoznik
******************************* napomena
PUBLIC m.sifnap, m.text1, m.text2, m.text3, m.text4, m.text5, m.text6, m.text7, m.text8
m.sifnap=SPACE(6)
m.text1=SPACE(100)
m.text2=SPACE(100)
m.text3=SPACE(100)
m.text4=SPACE(100)
m.text5=SPACE(100)
m.text6=SPACE(100)
m.text7=SPACE(100)
m.text8=SPACE(100)

*************** stampa kalkulacije **************************************************************
PUBLIC m.nabvre, m.pdvp8, m.pdvp18, m.pdvo8, m.pdvo18, m.ruc, m.provrem , m.vrstezav,m.zavopis, m.vrstekalk, m.vrstcarina
*************** stampa fakture **************************************************************
PUBLIC m.osn8,m.osn18, m.pdvp8, m.pdvp18, m.pro8, m.pro18, m.osnovica
********************nivelacija ************************
PUBLIC nstaje
********************** medjuskladisnica
PUBLIC m.ui, m.fiskal
m.ui=SPACE(1)
********************** kalo rastur reprezentacija
PUBLIC m.krr
*******************************************************
PUBLIC m.valuta, m.otprema, m.vrstarobe, m.teuro, m.tdolar, m.tipfak, mroba, mrobap5,mrobap8,mrobap18, mzavisni
*****************************************************
PUBLIC m.nazmag, m.nazmagz, m.datprom
************** mouse
PUBLIC mred, mkolona
mred=0
mkolona=0
************************* radnici
PUBLIC m.radnik, m.prio, m.sifrad, m.imerad, m.adrrad, m.mesrad, m.telrad, m.mobrad, m.lkrad, m.jmrad
**********************************


PUBLIC m.tabela, m.vrstadok
m.tabela=SPACE(10)
m.vrstadok=SPACE(3)
m.istovar=""
m.prevoznik=""
m.osnovica=0
m.datprom=DATE()
m.vrstezav=0
m.zavopis=SPACE(15)
m.vrstkalk=0
m.vrstcarina=0
m.tipfak=0
m.vrstarobe=0
masterpass=.f.
m.mpassword=SPACE(20)
nstaje=SPACE(1)
m.kuppdv=SPACE(1)
m.valuta=DATE()
m.otprema=SPACE(20)
m.mpcenadin=0
m.mpcenaeur=0
m.brpar=0
m.aktivan=.f.
m.hjk=SPACE(0)
m.brpon=SPACE(6)
m.filsif=.f.
m.filnaz=.f.
m.rabat=0
m.proizvod=SPACE(6)
m.nazpro=SPACE(30)
oli=SPACE(1)
sporocilo=SPACE(40)
m.sifkupdob=space(7)
m.kolicina=0
m.nazkupdob=space(30)
m.adrkupdob=SPACE(30)
m.telkupdob=SPACE(20)
m.zirkupdob=SPACE(25)
m.matkupdob=SPACE(15)
m.pibkupdob=SPACE(15)
m.radnick=SPACE(20)
m.sifrad=SPACE(4)
m.tarifa=SPACE(2)
m.prio=0
m.textpor=SPACE(2)
m.brdok=SPACE(9)
m.razduz="D"
m.gotova=.f.
m.snvre=0
m.smar=0
m.spor=0
m.srab=0
m.spvre=0
m.pcena=0
m.ncena=0
mrb=0
mizjava=SPACE(15)
mdatizj=DATE()
mobrpor=SPACE(1)
m.r1=SPACE(1)
m.sifrob=SPACE(13)
kstaje=SPACE(1)
fstaje=SPACE(1)
mktaje=SPACE(1)
mfstaje=SPACE(1)
mporez=0
mmarza=0
m.stopa=0
m.slovima=SPACE(1)
m.brojdana=0
m.rokpla=SPACE(3)
olir1=SPACE(2)
m.sdug=0
m.spot=0
m.radnik=SPACE(4)
m.uvecanje=0
m.ukupor=0
m.zavisni=0
m.paragon=0
m.datod=DATE()
m.datdo=DATE()
m.malopor=0
m.malomar=0
m.grupa=SPACE(4)
m.kljuc1=SPACE(20)
m.kljuc2=SPACE(20)
m.kljuc3=SPACE(20)
m.kljuc4=SPACE(20)
m.kljuc5=SPACE(20)
m.kljuc6=SPACE(20)
m.kljuc7=SPACE(20)
m.kljuc8=SPACE(20)
m.kljuc9=SPACE(20)
m.kljuc10=SPACE(20)
m.starakol=0
M.vozac=SPACE(50)
m.vozilo=SPACE(20)
m.prefiks=SPACE(4)
M.AKTIVNOST=.F.
m.magacin=SPACE(5)
m.magacinz=SPACE(5)
m.nazmag=SPACE(30)
m.fiskal=SPACE(6)
helpkod=SPACE(10)
m.nazmag=SPACE(20)
m.nazmagz=SPACE(20)
m.zadnce=0
m.magrad=SPACE(40)

	CLOSE databases
	DO krebaza
	CLOSE all
	DO otvaranje
	ON ERROR do greska with ;
	ERROR(),MESSAGE(),MESSAGE(1),PROGRAM(),LINENO()

DO FORM lozinka
read event
CLOSE DATABASES
return



procedure sve_proc

return
***************************************************

procedure otvaranje
OPEN DATABASE belcar SHARED
USE paragon EXCLUSIVE
zap
CLOSE ALL

MFINBAZ=ALLTRIM(MPUTFIN)+"\FIN"

OPEN DATABASE &MFINBAZ SHARED

USE ALLTRIM(MPUTFIN)+"\KONPLAN" ALIAS KONPLAN SHARED IN 0
USE ALLTRIM(MPUTFIN)+"\gknjiga" ALIAS gknjiga SHARED IN 0

MSTA="OPEN DATABASE "+MPUTPG+"BELCAR SHARED"
&MSTA
**OPEN DATABASE \\ceca\d\2019\robno\baze\belcar SHARED

MSTA="USE "+MPUTPG+"ZALIHE ALIAS Z2009 SHARED IN 0"
&MSTA
**USE \\ceca\d\2019\robno\baze\zalihe ALIAS z2009 SHARED IN 0

MSTA="USE "+MPUTPG+"ROBA ALIAS R2009 SHARED IN 0"
&MSTA
**USE \\ceca\d\2019\robno\baze\roba ALIAS r2009 SHARED IN 0

MSTA="USE "+MPUTPG+"KALKSTAV ALIAS K2009 SHARED IN 0"
&MSTA
*USE \\ceca\d\2019\robno\baze\kalkstav ALIAS k2009 SHARED IN 0


MSTA="USE "+MPUTPG+"FAKSTAV ALIAS F2009 SHARED IN 0"
&MSTA
*USE \\ceca\d\2019\robno\baze\FAkstav ALIAS f2009 SHARED IN 0

OPEN DATABASE belcar shared	

USE radnici  SHARED ORDER tag sifra ALIAS radnici IN 0
USE tarife  SHARED ORDER tag sifra ALIAS tarife IN 0
USE parame ALIAS parame SHARED IN 0
	m.kurs	 =parame.kurs
	m.firma	 =parame.naziv
	m.firma1 =parame.naziv1
	m.firma=ALLTRIM(m.firma)+" "+ALLTRIM(m.firma1)
	m.adresa =parame.adresa
	m.ptt=parame.ptt
	m.mesto  =parame.mesto
	m.telefon=parame.tel1
	m.mobilni=parame.mobilni
	m.fax	=parame.fax
	m.maticni=parame.maticni
	m.registar=parame.registar
	m.delatnost=parame.delatnost
	m.ziro   =parame.ziro
	m.malopor=parame.porez
	m.malomar=parame.marza
	m.pib	=parame.pib
	m.pepdv	=parame.pepdv
	m.email=parame.email
	m.mpassword=parame.mpassword
	m.maticni=parame.maticni
USE magacin ALIAS magacin SHARED IN 0
USE greska ALIAS greska SHARED IN 0	
USE textpor ALIAS textpor shared IN 0
USE TEXTpla ALIAS textpla SHARED IN 0
USE zagkalk ALIAS zagkalk shared IN 0
USE kalkstav ALIAS kalkstav SHARED IN 0
USE mszagkalk ALIAS mszagkalk SHARED IN 0
USE mskalkstav ALIAS mskalkstav SHARED IN 0
USE zagvrd ALIAS zagvrd SHARED IN 0
USE vrdstav ALIAS vrdstav SHARED IN 0
USE zagvrK ALIAS zagvrK SHARED IN 0
USE vrKstav ALIAS vrKstav SHARED IN 0
USE zagLOM ALIAS zagLOM SHARED IN 0
USE LOMstav ALIAS LOMstav SHARED IN 0
USE zagKALO ALIAS zagKALO SHARED IN 0
USE KALOstav ALIAS KALOstav SHARED IN 0
USE kupdob ALIAS kupdob SHARED IN 0
USE roba ALIAS roba SHARED IN 0
USE porkup ALIAS porkup SHARED IN 0
USE uplate alias uplate SHARED IN 0
USE zalihe ALIAS zalihe SHARED IN 0
USE zagfak ALIAS zagfak SHARED IN 0
USE zagofak ALIAS zagofak SHARED IN 0
USE fakstav ALIAS fakstav SHARED IN 0
USE fakstav ALIAS fakstava SHARED again IN 0
USE fakostav ALIAS fakostav SHARED IN 0
USE zagifak ALIAS zagifak SHARED IN 0
USE ifakstav ALIAS ifakstav SHARED IN 0
USE zagrev ALIAS zagrev SHARED IN 0
USE revstav ALIAS revstav SHARED IN 0
USE parstav ALIAS parstav SHARED IN 0
USE sklop ALIAS sklop SHARED IN 0
USE grupa ALIAS grupa SHARED IN 0
USE proizvod ALIAS proizvod SHARED IN 0
USE konkup ALIAS konkup shared IN 0
USE kroslist ALIAS kroslist shared IN 0
USE kljucne ALIAS kljucne SHARED IN 0
USE zagpon ALIAS zagpon SHARED IN 0
USE ponstav ALIAS ponstav SHARED IN 0
USE zagniv ALIAS zagniv SHARED IN 0
USE nivstav ALIAS nivstav SHARED IN 0
USE trazeno ALIAS trazeno SHARED IN 0
USE brojpar ALIAS brojpar SHARED IN 0
USE brojac	ALIAS brojac SHARED IN 0
USE pskup ALIAS pskup SHARED IN 0
USE kurs ALIAS kurs SHARED IN 0
*USE vrstezav ALIAS vrstezav SHARED IN 0
USE zavtros ALIAS zavtros SHARED IN 0
USE banke ALIAS banke SHARED IN 0
USE napomena ALIAS napomena SHARED IN 0

SELECT banke
SET ORDER TO tag glavni
GOTO top
SEEK 1
IF banke.glavni=1
	m.sifban=banke.banka
	m.trfir=banke.tr
	m.nazban=banke.opis
ELSE
	m.sifban=SPACE(4)
	m.trfir=SPACE(20)
	m.nazban=SPACE(30)
endif		

*USE uplaceno ALIAS uplaceno SHARED IN 0

USE firma  EXCLUSIVE ALIAS firma IN 0
USE pkalkstav EXCLUSIVE ALIAS pkalkstav IN 0
SELECT pkalkstav
INDEX on rb TAG rb OF pkalkstav additive
INDEX on naziv TAG naziv OF pkalkstav additive
INDEX on sifrob TAG sifrob OF pkalkstav additive

USE karkom EXCLUSIVE ALIAS karkom IN 0
SELECT KARKOM
INDEX ON DATUM TAG DATUM OF KARKOM ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF KARKOM ADDITIVE
INDEX ON NAZKOM  TAG NAZKOM OF KARKOM ADDITIVE
INDEX on iznos TAG iznos OF karkom DESCENDING additive
INDEX on dospelo TAG dospelo OF karkom DESCENDING additive

USE nekupci EXCLUSIVE ALIAS nekupci IN 0
SELECT nekupci
INDEX ON DATUM TAG DATUM OF nekupci ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF nekupci ADDITIVE
INDEX ON NAZKOM  TAG NAZKOM OF nekupci ADDITIVE
INDEX on iznos TAG iznos OF nekupci DESCENDING additive
INDEX on dospelo TAG dospelo OF nekupci DESCENDING additive

USE izfak EXCLUSIVE ALIAS izfak IN 0
SELECT izfak
INDEX ON DATUM TAG DATUM OF izfak ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF izfak ADDITIVE
INDEX ON NAZKOM  TAG NAZKOM OF izfak ADDITIVE
INDEX on iznos TAG iznos OF izfak DESCENDING additive
INDEX on dospelo TAG dospelo OF izfak DESCENDING additive

USE karsvi EXCLUSIVE ALIAS karsvi IN 0
SELECT KARsvi
INDEX ON DATUM TAG DATUM OF KARsvi ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF KARsvi ADDITIVE
INDEX ON NAZKOM  TAG NAZKOM OF KARsvi ADDITIVE
INDEX on iznos TAG iznos OF karsvi DESCENDING additive
INDEX on dospelo TAG dospelo OF karsvi DESCENDING additive

USE topkup EXCLUSIVE ALIAS topkup IN 0
SELECT topkup
INDEX ON DATUM TAG DATUM OF topkup ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF topkup ADDITIVE
INDEX ON NAZKOM  TAG NAZKOM OF topkup ADDITIVE
INDEX on iznos TAG iznos OF topkup DESCENDING additive
INDEX on dospelo TAG dospelo OF topkup DESCENDING additive

USE procenti EXCLUSIVE ALIAS procenti IN 0
SELECT procenti
FOR i=0 TO 20
a=STR(i*10,3,0)
APPEND BLANK
replace procenti.procenat WITH a
NEXT i

USE banka EXCLUSIVE ALIAS banka IN 0
USE direkt EXCLUSIVE ALIAS direkt IN 0

USE pfakstav EXCLUSIVE ALIAS pfakstav IN 0
SELECT pfakstav
INDEX ON rb TAG rb OF pfakstav ADDITIVE
INDEX ON naziv TAG naziv OF pfakstav ADDITIVE
INDEX ON sifrob TAG sifrob OF pfakstav ADDITIVE
INDEX ON datum TAG datum OF pfakstav ADDITIVE

USE pfakstavo EXCLUSIVE ALIAS pfakstavo IN 0
SELECT pfakstavo
INDEX ON rb TAG rb OF pfakstavo ADDITIVE
INDEX ON sifrob TAG sifrob OF pfakstavo ADDITIVE
INDEX ON datum TAG datum OF pfakstavo ADDITIVE

USE pponstav EXCLUSIVE ALIAS pponstav IN 0
SELECT pponstav
INDEX ON rb TAG rb OF pponstav ADDITIVE
INDEX ON naziv TAG naziv OF pponstav ADDITIVE
INDEX ON sifrob TAG sifrob OF pponstav ADDITIVE


USE llista EXCLUSIVE ALIAS llista IN 0
SELECT llista
INDEX ON rb TAG rb OF llista ADDITIVE
INDEX ON magacin TAG magacin OF llista ADDITIVE
INDEX ON sifrob TAG sifrob OF llista ADDITIVE
INDEX ON naziv TAG naziv OF llista ADDITIVE
INDEX on ikol TAG ikol OF llista DESCENDING additive

USE robkar EXCLUSIVE ALIAS robkar IN 0
SELECT robkar
INDEX on datum TAG datum OF robkar additive
INDEX on kupdob TAG kupdob OF robkar additive
INDEX on sifrob TAG sifrob OF robkar additive
INDEX on nazrob TAG nazrob OF robkar additive
INDEX on brdok TAG brdok OF robkar additive
INDEX on IKOLICINA TAG IKOLICINA OF robkar DESCENDING additive
INDEX on rb TAG rb OF robkar additive
INDEX on DTOS(datum)+pravdok+STR(staje) TAG kartica OF robkar additive

USE pnivel EXCLUSIVE ALIAS pnivel IN 0
SELECT pnivel
INDEX on datum TAG datum OF pnivel additive
INDEX on sifrob TAG sifrob OF pnivel additive
INDEX on rb TAG rb OF pnivel additive

USE prokol EXCLUSIVE ALIAS prokol IN 0
SELECT prokol
INDEX on datum TAG datum OF prokol additive
INDEX on kupdob TAG kupdob OF prokol additive
INDEX on sifrob TAG sifrob OF prokol additive
INDEX on nazrob TAG nazrob OF prokol additive
INDEX on brdok TAG brdok OF prokol additive
INDEX on IKOLICINA TAG IKOLICINA OF prokol DESCENDING additive

USE robizl EXCLUSIVE ALIAS robizl IN 0
SELECT robizl
INDEX on datum TAG datum OF robizl additive
INDEX on kupdob TAG kupdob OF robizl additive
INDEX on sifrob TAG sifrob OF robizl additive
INDEX on nazrob TAG nazrob OF robizl additive
INDEX on brdok TAG brdok OF robizl additive
INDEX on IKOLICINA TAG IKOLICINA OF robizl DESCENDING additive

USE toprob EXCLUSIVE ALIAS toprob IN 0
SELECT toprob
INDEX on datum TAG datum OF toprob additive
INDEX on kupdob TAG kupdob OF toprob additive
INDEX on sifrob TAG sifrob OF toprob additive
INDEX on nazrob TAG nazrob OF toprob additive
INDEX on brdok TAG brdok OF toprob additive
INDEX on IKOLICINA TAG IKOLICINA OF toprob DESCENDING additive

USE toprob1 EXCLUSIVE ALIAS toprob1 IN 0
SELECT toprob1
INDEX on datum TAG datum OF toprob1 additive
INDEX on kupdob TAG kupdob OF toprob1 additive
INDEX on sifrob TAG sifrob OF toprob1 additive
INDEX on nazrob TAG nazrob OF toprob1 additive
INDEX on brdok TAG brdok OF toprob1 additive
INDEX on IKOLICINA TAG IKOLICINA OF toprob1 DESCENDING additive

USE toprob2 EXCLUSIVE ALIAS toprob2 IN 0
SELECT toprob2
INDEX on sifrob TAG sifrob OF toprob2 additive
INDEX on nazrob TAG nazrob OF toprob2 additive
INDEX on vrednost TAG vrednost OF toprob2 DESCENDING additive
INDEX on KOLICINA TAG KOLICINA OF toprob2 DESCENDING additive

USE robizl2 EXCLUSIVE ALIAS robizl2 IN 0
SELECT robizl2
INDEX on datum TAG datum OF robizl2 additive
INDEX on kupdob TAG kupdob OF robizl2 additive
INDEX on sifrob TAG sifrob OF robizl2 additive
INDEX on nazrob TAG nazrob OF robizl2 additive
INDEX on brdok TAG brdok OF robizl2 additive
INDEX on IKOLICINA TAG IKOLICINA OF robizl2 DESCENDING additive

USE karrob EXCLUSIVE ALIAS karrob IN 0
SELECT KARrob
INDEX ON DATUM TAG DATUM OF KARrob ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF KARrob ADDITIVE
INDEX ON NAZrob  TAG NAZrob OF KARrob ADDITIVE
INDEX ON brdok  TAG brdok OF KARrob ADDITIVE
INDEX on sifrob TAG sifrob OF karrob additive
INDEX on ikolicina TAG ikolicina OF karrob DESCENDING additive

USE PORUCI EXCLUSIVE ALIAS PORUCI IN 0
SELECT PORUCI
INDEX ON DATUM TAG DATUM OF PORUCI ADDITIVE
INDEX ON KUPDOB  TAG KUPDOB OF PORUCI ADDITIVE
INDEX ON NAZrob  TAG NAZrob OF PORUCI ADDITIVE
INDEX ON brdok  TAG brdok OF PORUCI ADDITIVE
INDEX on sifrob TAG sifrob OF PORUCI additive
INDEX on ikolicina TAG ikolicina OF PORUCI DESCENDING additive

USE kuprob EXCLUSIVE ALIAS kuprob IN 0
SELECT Kuprob
INDEX ON DATUM TAG DATUM OF Kuprob ADDITIVE
INDEX ON kupdob TAG kupdob OF Kuprob ADDITIVE
INDEX ON nazdob TAG nazdob OF Kuprob ADDITIVE
INDEX ON sifrob TAG sifrob OF Kuprob ADDITIVE
INDEX ON nazrob TAG nazrob OF Kuprob ADDITIVE
INDEX ON brdok TAG brdok OF Kuprob ADDITIVE

USE promkup EXCLUSIVE ALIAS promkup IN 0
SELECT promkup
INDEX ON DATUM TAG DATUM OF promkup ADDITIVE
INDEX ON kupdob TAG kupdob OF promkup ADDITIVE
INDEX ON nazdob TAG nazdob OF promkup ADDITIVE
INDEX ON sifrob TAG sifrob OF promkup ADDITIVE
INDEX ON nazrob TAG nazrob OF promkup ADDITIVE
INDEX ON brdok TAG brdok OF promkup ADDITIVE

USE ropokup ALIAS ropokup EXCLUSIVE IN 0
SELECT ropokup
INDEX on sifra	TAG sifra OF ropokup additive
INDEX on naziv	TAG naziv OF ropokup additive
INDEX on sifra1	TAG sifra1 OF ropokup additive
INDEX on naziv1	TAG naziv1 OF ropokup additive

USE upolag ALIAS upolag exclusive IN 0
SELECT upolag
INDEX on sifra TAG sifra OF upolag additive
INDEX on naziv TAG naziv OF upolag additive

USE paragon ALIAS paragon  exclusive IN 0

USE psklop ALIAS psklop EXCLUSIVE IN 0
SELECT psklop
INDEX on sklop TAG sklop OF psklop additive
INDEX on element TAG element OF pssklop additive

USE topgrup ALIAS topgrup EXCLUSIVE IN 0
SELECT topgrup
INDEX on kolicina1 TAG kolicina1 OF topgrup DESCENDING additive
INDEX on kolicina2 TAG kolicina2 OF topgrup DESCENDING additive
INDEX on kolicina3 TAG kolicina3 OF topgrup DESCENDING additive
INDEX on sifra TAG sifra OF topgrup  additive
INDEX on naziv TAG naziv OF topgrup  additive
INDEX on proc1 TAG proc1 OF topgrup DESCENDING additive
INDEX on proc2 TAG proc2 OF topgrup DESCENDING additive
INDEX on proc3 TAG proc3 OF topgrup DESCENDING additive
INDEX on razl1 TAG razl1 OF topgrup DESCENDING additive
INDEX on razl2 TAG razl2 OF topgrup DESCENDING additive
INDEX on procr1 TAG procr1 OF topgrup DESCENDING additive
INDEX on procr2 TAG procr2 OF topgrup DESCENDING additive

USE topgrup1 ALIAS topgrup1 EXCLUSIVE IN 0
SELECT topgrup1
INDEX on kolicina1 TAG kolicina1 OF topgrup1 DESCENDING additive
INDEX on kolicina2 TAG kolicina2 OF topgrup1 DESCENDING additive
INDEX on kolicina3 TAG kolicina3 OF topgrup1 DESCENDING additive
INDEX on kupdob TAG kupdob OF topgrup1  additive
INDEX on naziv TAG naziv OF topgrup1  additive
INDEX on razl1 TAG razl1 OF topgrup1 DESCENDING additive
INDEX on razl2 TAG razl2 OF topgrup1 DESCENDING additive
INDEX on proc1 TAG proc1 OF topgrup1 DESCENDING additive
INDEX on proc2 TAG proc2 OF topgrup1 DESCENDING additive
INDEX on proc3 TAG proc3 OF topgrup1 DESCENDING additive
INDEX on procr1 TAG procr1 OF topgrup1 DESCENDING additive
INDEX on procr2 TAG procr2 OF topgrup1 DESCENDING additive

USE topgrupe ALIAS topgrupe EXCLUSIVE IN 0
SELECT topgrupe
INDEX on grupa TAG grupa OF topgrupe additive
INDEX on naziv TAG naziv OF topgrupe additive
INDEX on kolicina1 TAG kolicina1 OF topgrupe DESCENDING additive
INDEX on kolicina2 TAG kolicina2 OF topgrupe DESCENDING additive
INDEX on kolicina3 TAG kolicina3 OF topgrupe DESCENDING additive
INDEX on vred1 TAG vred1 OF topgrupe DESCENDING additive
INDEX on vred2 TAG vred2 OF topgrupe DESCENDING additive
INDEX on vred3 TAG vred3 OF topgrupe DESCENDING additive
INDEX on proc1 TAG proc1 OF topgrupe DESCENDING additive
INDEX on proc2 TAG proc2 OF topgrupe DESCENDING additive
INDEX on proc3 TAG proc3 OF topgrupe DESCENDING additive
INDEX on kolicina21 TAG kolicina21 OF topgrupe DESCENDING additive
INDEX on kolicina32 TAG kolicina32 OF topgrupe DESCENDING additive
INDEX on vred21 TAG vred21 OF topgrupe DESCENDING additive
INDEX on vred32 TAG vred32 OF topgrupe DESCENDING additive
INDEX on proc21 TAG proc21 OF topgrupe DESCENDING additive
INDEX on proc32 TAG proc32 OF topgrupe DESCENDING additive

USE topgrupek ALIAS topgrupek EXCLUSIVE IN 0
SELECT topgrupek
INDEX on grupa TAG grupa OF topgrupek additive
INDEX on naziv TAG naziv OF topgrupek additive
INDEX on kolicina1 TAG kolicina1 OF topgrupek DESCENDING additive
INDEX on kolicina2 TAG kolicina2 OF topgrupek DESCENDING additive
INDEX on kolicina3 TAG kolicina3 OF topgrupek DESCENDING additive
INDEX on vred1 TAG vred1 OF topgrupek DESCENDING additive
INDEX on vred2 TAG vred2 OF topgrupek DESCENDING additive
INDEX on vred3 TAG vred3 OF topgrupek DESCENDING additive
INDEX on proc1 TAG proc1 OF topgrupek DESCENDING additive
INDEX on proc2 TAG proc2 OF topgrupek DESCENDING additive
INDEX on proc3 TAG proc3 OF topgrupek DESCENDING additive
INDEX on kolicina21 TAG kolicina21 OF topgrupek DESCENDING additive
INDEX on kolicina32 TAG kolicina32 OF topgrupek DESCENDING additive
INDEX on vred21 TAG vred21 OF topgrupek DESCENDING additive
INDEX on vred32 TAG vred32 OF topgrupek DESCENDING additive
INDEX on proc21 TAG proc21 OF topgrupek DESCENDING additive
INDEX on proc32 TAG proc32 OF topgrupek DESCENDING additive

USE ponudarg ALIAS ponudarg EXCLUSIVE IN 0
SELECT ponudarg
INDEX on sifrob TAG sifrob OF ponudarg additive
INDEX on naziv TAG naziv OF ponudarg additive
INDEX on kupio TAG kupio OF ponudarg DESCENDING additive
INDEX on prodato tAG prodato OF ponudarg DESCENDING additive
INDEX on NCENA TAG ncena OF ponudarg DESCENDING additive
INDEX on pcena TAG pcena OF ponudarg DESCENDING additive
INDEX on cena TAG cena OF ponudarg DESCENDING additive
INDEX on mpcena TAG mpcena OF ponudarg DESCENDING additive

USE pkros ALIAS pkros EXCLUSIVE IN 0
SELECT pkros
INDEX on proizvod TAG proizvod OF pkros additive

USE dani ALIAS dani EXCLUSIVE IN 0
SELECT dani
INDEX on ned 		TAG ned OF dani additive
INDEX on pon 		TAG pon OF dani additive
INDEX on uto 		TAG uto OF dani additive
INDEX on sre 		TAG sre OF dani additive
INDEX on cet 		TAG cet OF dani additive
INDEX on pet		TAG pet OF dani additive
INDEX on sub 		TAG sub OF dani additive
index on neduk		TAG neduk OF dani additive
INDEX on nedproc 	TAG nedproc OF dani additive

USE ptrazeno ALIAS ptrazeno EXCLUSIVE IN 0
SELECT ptrazeno
INDEX on sifrob 	TAG sifrob OF ptrazeno additive
INDEX on kupdob		TAG kupdob OF ptrazeno additive
INDEX on kolicina	TAG kolicina OF ptrazeno descending additive
INDEX on datum 		TAG datum OF ptrazeno additive


USE dani1 ALIAS dani1 EXCLUSIVE IN 0
SELECT dani1
INDEX on ned 		TAG ned OF dani1 additive
INDEX on pon 		TAG pon OF dani1 additive
INDEX on uto 		TAG uto OF dani1 additive
INDEX on sre 		TAG sre OF dani1 additive
INDEX on cet 		TAG cet OF dani1 additive
INDEX on pet		TAG pet OF dani1 additive
INDEX on sub 		TAG sub OF dani1 additive
index on neduk		TAG neduk OF dani1 additive
INDEX on nedproc 	TAG nedproc OF dani1 additive

USE kasa ALIAS kasa EXCLUSIVE IN 0
SELECT kasa
INDEX on kupdob TAG kupdob OF kasa additive
INDEX on naziv TAG naziv OF kasa additive
INDEX on kolicina TAG kolicina OF kasa additive
INDEX on pvrednost TAG pvrednost OF kasa additive
INDEX on cenasapor TAG cenasapor OF kasa additive
INDEX on kupdob+sifrob TAG kasaapa OF kasa additive

USE kepu ALIAS kepu EXCLUSIVE IN 0
SELECT kepu
INDEX on datum TAG datum OF kepu additive

USE pregled ALIAS pregled EXCLUSIVE IN 0
SELECT pregled
INDEX on brdok TAG brdok OF pregled additive
INDEX on datum TAG datum OF pregled additive
INDEX on nazkom TAG nazkom OF pregled additive

USE prosecna ALIAS prosecna EXCLUSIVE IN 0
SELECT prosecna
INDEX on datum TAG datum OF prosecna additive

USE pnivstav alias pnivstav exclusive IN 0
SELECT pnivstav
INDEX on datum TAG datum OF pnivstav additive

USE PKONKUP ALIAS PKONKUP EXCLUSIVE IN 0
USE Ptraznja ALIAS Ptraznja EXCLUSIVE IN 0
USE Ptraznja1 ALIAS Ptraznja1 EXCLUSIVE IN 0
USE proba ALIAS proba EXCLUSIVE IN 0
USE graph ALIAS graph EXCLUSIVE IN 0
USE istinaz ALIAS istinaz EXCLUSIVE IN 0
USE abc ALIAS abc EXCLUSIVE IN 0
USE komanda ALIAS komanda EXCLUSIVE IN 0
USE koverat ALIAS koverat EXCLUSIVE IN 0
USE efakture ALIAS efakture EXCLUSIVE IN 0

RETURN




******************************************************************
PROCEDURE krebaza

ERASE banka.dbf
CREATE TABLE banka ;
	(datum		D(8),;
	zadok		c(9),;
	iznos		n(15,2))
	
ERASE direkt.dbf
CREATE TABLE direkt ;
	(datum		D(8),;
	zadok		c(9),;
	iznos		n(15,2))
	
ERASE ptrazeno.dbf
CREATE TABLE ptrazeno ;
	(datum		D(8),;
	vreme		c(8),;
	kupdob		c(6),;
	sifrob		c(13),;
	naziv		c(60),;
	napomena	c(80),;
	kolicina	n(15,2),;
	nazkom		c(30),;
	radnik		c(4),;
	nazrad		c(15),;
	oem			c(20))
	
ERASE ptraznja.dbf
CREATE TABLE ptraznja ;
	(datum		D(8),;
	vreme		c(8),;
	kupdob		c(6),;
	sifrob		c(13),;
	nazrob		c(30),;
	kolicina	n(15,3),;
	cena		n(12,2),;
	rabat		n(6,2),;
	staje		n(1),;
	zvao		c(10))
	
ERASE ptraznja1.dbf
CREATE TABLE ptraznja1 ;
	(datum		D(8),;
	vreme		c(8),;
	kupdob		c(6),;
	sifrob		c(13),;
	nazrob		c(30),;
	kolicina	n(15,3),;
	cena		n(12,2),;
	rabat		n(6,2),;
	staje		n(1),;
	zvao		c(10))
	

ERASE pkros.dbf
ERASE pkros.cdx
CREATE TABLE pkros;
	(proizvod	c(30),;
	oem			c(20),;
	cargo		c(13),;
	napomena	c(30))
	
	
ERASE karkom.dbf
ERASE karkom.cdx
CREATE TABLE karkom ;
	(datum		d(8),;
	kupdob		c(6),;
	nazkom		c(30),;
	tel1		c(20),;
	tel2		c(20),;
	dokument	c(10),;
	brdok		c(9),;
	magacin		c(5),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	vrsta		c(2),;
	valuTa		d(8),;
	iznos		n(15,2),;
	dospelo		n(15,2))


ERASE kaSA.dbf
CREATE TABLE kaSA ;
	(brdok		c(9),;
	rb			n(3),;
	naziv		c(30),;
	sifrar		c(13),;
	sifrob		c(13),;
	nazrob		c(30),;
	magacin		c(5),;
	datum		d(8),;
	kupdob		c(6),;
	adresa		c(30),;
	mesto		c(30),;
	pib			c(9),;
	kolicina	n(15,3),;
	ncena		n(15,5),;
	tarifa		c(2),;
	marza		n(7,2),;
	rabat		n(6,2),;
	npcena		n(15,5),;
	pcena		n(15,5),;
	stopa		n(6,2),;
	porez		n(15,2),;
	euro		n(15,2),;
	obrpor		n(1),;
	zavtros		n(15,2),;
	jm			c(3),;
	cenasapor	n(15,5),;
	pvrednost	n(15,2),;
	razduz		c(1),;
	mesec		n(2),;
	godina		n(4),;
	kod			c(1))

ERASE nekupci.dbf
ERASE nekupci.cdx
CREATE TABLE nekupci ;
	(datum		d(8),;
	kupdob		c(6),;
	nazkom		c(30),;
	tel1		c(20),;
	tel2		c(20),;
	dokument	c(10),;
	brdok		c(9),;
	magacin		c(5),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	vrsta		c(2),;
	valuTa		d(8),;
	iznos		n(15,2),;
	dospelo		n(15,2))

	
ERASE izfak.dbf
ERASE izfak.cdx
CREATE TABLE izfak ;
	(datum		d(8),;
	kupdob		c(6),;
	nazkom		c(30),;
	tel1		c(20),;
	tel2		c(20),;
	dokument	c(10),;
	brdok		c(9),;
	magacin		c(5),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	vrsta		c(2),;
	valuTa		d(8),;
	iznos		n(15,2),;
	dospelo		n(15,2))

ERASE karsvi.dbf
ERASE karsvi.cdx
CREATE TABLE karsvi ;
	(datum		d(8),;
	kupdob		c(6),;
	nazkom		c(30),;
	tel1		c(20),;
	tel2		c(20),;
	dokument	c(10),;
	brdok		c(9),;
	magacin		c(5),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	vrsta		c(2),;
	valuTa		d(8),;
	iznos		n(15,2),;
	dospelo		n(15,2))

ERASE topkup.dbf
ERASE topkup.cdx
CREATE TABLE topkup ;
	(datum		d(8),;
	kupdob		c(6),;
	nazkom		c(30),;
	tel1		c(20),;
	tel2		c(20),;
	dokument	c(10),;
	brdok		c(9),;
	magacin		c(5),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	vrsta		c(2),;
	valuTa		d(8),;
	iznos		n(15,2),;
	dospelo		n(15,2))

ERASE karrob.dbf
ERASE karrob.cdx
CREATE TABLE karrob;
	(datum		d(8),;
	sifrob		c(13),;
	kupdob		c(6),;
	nazdob		c(30),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(12,3),;
	ikolicina	n(12,3),;
	kolicina	n(12,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3))
	
ERASE PORUCI.dbf
ERASE PORUCI.cdx
CREATE TABLE PORUCI;
	(datum		d(8),;
	sifrob		c(13),;
	kupdob		c(6),;
	nazdob		c(30),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(12,3),;
	ikolicina	n(12,3),;
	kolicina	n(12,3),;
	ncena		n(15,2),;
	pcena		n(15,2),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,2),;
	stanje		n(15,3))

ERASE kuprob.dbf
ERASE kuprob.cdx
CREATE TABLE kuprob;
	(datum		d(8),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(12,3),;
	ikolicina	n(12,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(12,3))

ERASE promkup.dbf
ERASE promkup.cdx
CREATE TABLE promkup;
	(datum		d(8),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(12,3),;
	ikolicina	n(12,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(12,3))

ERASE llista.dbf
ERASE llista.cdx
CREATE TABLE llista;
	(rb			n(5),;
	magacin		c(5),;
	sifrob		c(13),;
	naziv		c(100),;
	jm			c(3),;
	kolicina	n(12,3),;
	ikol		n(12,3),;
	pcen		n(15,5),;
	ncen		n(15,5),;
	dpcen		n(15,5),;
	dncen		n(15,5),;
	lokacija	c(50),;
	mpmarza		n(8,2),;
	stanje		c(1),;
	kod			n(1),;
	KATBROJ		C(15),;
	mpcenaeur	n(15,5),;
	mpcenadin	n(15,5),;
	cenovnik	c(1),;
	tarifa		c(2),;
	grupa		c(4),;
	nazgru		c(30))
	
ERASE paragon.dbf
CREATE TABLE paragon;
	(datum		d(8),;
	brdok		n(5),;
	sifra		c(13),;
	naziv		c(30),;
	cena		n(15,5),;
	kolicina	n(15,3),;
	rb			n(4),;
	jm			c(3))
	
ERASE pfakstav.dbf
ERASE pfakstav.cdx
CREATE TABLE pfakstav;
	(brdok		c(9),;
	rb			n(3),;
	naziv		c(100),;
	sifrar		c(13),;
	sifrob		c(13),;
	magacin		c(5),;
	datum		d(8),;
	datprom		d(8),;
	kupdob		c(6),;
	kolicina	n(15,3),;
	ncena		n(15,6),;
	tarifa		c(2),;
	marza		n(7,2),;
	rabat		n(6,2),;
	npcena		n(15,6),;
	pcena		n(15,6),;
	stopa		n(6,2),;
	porez		n(15,2),;
	euro		n(15,2),;
	obrpor		c(1),;
	zavtros		n(15,6),;
	jm			c(3),;
	cenasapor	n(15,6),;
	pvrednost	n(15,6),;
	razduz		c(1),;
	kod			c(1),;
	NAZROB		M)


ERASE pfakstavo.dbf
ERASE pfakstavo.cdx
CREATE TABLE pfakstavo;
	(brdok		c(9),;
	rb			n(3),;
	opis		c(80),;
	sifrob		c(13),;
	magacin		c(5),;
	datum		d(8),;
	kupdob		c(6),;
	kolicina	n(15,3),;
	ncena		n(15,6),;
	tarifa		c(2),;
	marza		n(7,2),;
	rabat		n(6,2),;
	npcena		n(15,6),;
	pcena		n(15,6),;
	stopa		n(6,2),;
	porez		n(15,2),;
	euro		n(15,2),;
	obrpor		c(1),;
	zavtros		n(15,6),;
	jm			c(3),;
	cenasapor	n(15,6),;
	pvrednost	n(15,6),;
	razduz		c(1),;
	kod			c(1),;
	stavka		m)

ERASE pponstav.dbf
ERASE pponstav.cdx
CREATE TABLE pponstav;
	(brdok		c(9),;
	rb			n(3),;
	naziv		c(100),;
	sifrar		c(13),;
	sifrob		c(13),;
	magacin		c(5),;
	datum		d(8),;
	kupdob		c(6),;
	kolicina	n(15,3),;
	ncena		n(15,6),;
	tarifa		c(2),;
	marza		n(7,2),;
	rabat		n(6,2),;
	npcena		n(15,6),;
	pcena		n(15,6),;
	stopa		n(6,2),;
	porez		n(15,6),;
	euro		n(15,2),;
	obrpor		c(1),;
	zavtros		n(15,2),;
	jm			c(3),;
	cenasapor	n(15,6),;
	pvrednost	n(15,6),;
	razduz		c(1),;
	lokacija	c(50),;
	kod			c(1))


ERASE pkalkstav.dbf
ERASE pkalkstav.cdx
CREATE TABLE pkalkstav;
	(brdok		c(9),;
	rb			n(4),;
	naziv		c(100),;
	sifrar		c(13),;
	sifrob		c(13),;
	magacin		c(5),;
	magacinz	c(5),;
	datum		d(8),;
	kupdob		c(6),;
	kolicina	n(15,3),;
	ncena		n(15,5),;
	tarifa		c(2),;
	marza		n(7,2),;
	dobcen		n(15,5),;
	rabat		n(6,2),;
	npcena		n(15,5),;
	pcena		n(15,5),;
	stopa		n(6,2),;
	porez		n(15,2),;
	euro		n(15,4),;
	dolar		n(15,4),;
	obrpor		c(1),;
	zavtros		n(15,2),;
	jm			c(3),;
	cenasapor	n(15,5),;
	pvrednost	n(15,4),;
	ceneur		n(15,5),;
	akciza		c(1),;
	razduz		c(1),;
	starac		n(15,2),;
	kod			c(1),;
	nazrob		m)


ERASE procenti.dbf
CREATE TABLE procenti;
	(procenat	c(3),;
	iznos		n(15,2))



ERASE robkar.dbf
ERASE robkar.cdx
CREATE TABLE robkar;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,6),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3),;
	duguje		n(15,2),;
	potrazuje	n(15,2),;
	saldo		n(15,2),;
	staje		n(1),;
	rb			n(5),;
	pravdok		c(9))

ERASE pnivel.dbf
ERASE pnivel.cdx
CREATE TABLE pnivel;
	(datum		d(8),;
	sifrob		c(13),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	pcena		n(15,5),;
	duguje		n(15,2),;
	saldo		n(15,2),;
	rb			n(5),;
	staje		n(1),;
	stvacen		n(15,2),;
	pravdok		c(9),;
	ncena		n(12,2),;
	scena		n(12,2))


ERASE robizl.dbf
ERASE robizl.cdx
CREATE TABLE robizl;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3))

ERASE robizl2.dbf
ERASE robizl2.cdx
CREATE TABLE robizl2;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3))

ERASE toprob.dbf
ERASE toprob.cdx
CREATE TABLE toprob;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(40),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,2))

ERASE toprob1.dbf
ERASE toprob1.cdx
CREATE TABLE toprob1;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3))

ERASE prokol.dbf
ERASE prokol.cdx
CREATE TABLE prokol;
	(datum		d(8),;
	oznaka		c(1),;
	kupdob		c(6),;
	nazdob		c(30),;
	sifrob		c(13),;
	nazrob		c(30),;
	dokument	c(10),;
	brdok		c(9),;
	ukolicina	n(15,3),;
	ikolicina	n(15,3),;
	ncena		n(15,5),;
	pcena		n(15,5),;
	rabat		n(6,2),;
	marza		n(15,2),;
	stvacen		n(15,5),;
	stanje		n(15,3),;
	nap1		c(60),;
	nap2		c(60),;
	nap3		c(60))


ERASE ropokup.dbf
ERASE ropokup.cdx
CREATE TABLE ropokup;
	(sifra		c(13),;
	naziv		c(30),;
	jm			c(3),;
	kolicina	n(15,3),;
	kolicina1	n(15,3),;
	sifra1		c(13),;
	naziv1		c(30),;
	jm1			c(3),;
	pcena		n(15,5),;
	ncena		n(15,5),;
	marza		n(6,2),;
	oznaka		c(1))

ERASE toprob2.dbf
ERASE toprob2.cdx
CREATE TABLE toprob2;
	(sifrob		c(13),;
	nazrob		c(30),;
	jm			c(3),;
	kolicina	n(15,3),;
	vrednost	n(15,5),;
	ncena		n(15,6),;
	okolicina	n(15,3),;
	ovrednost	n(15,5))

ERASE upolag.dbf
ERASE upolag.cdx
CREATE 	table upolag;
	(sifra		c(13),;
	scg			n(1),;
	bih			n(1),;
	cro			n(1),;
	naziv		c(100),;
	jm			c(3),;
	kolscg		n(12,3),;
	kolbih		n(12,3),;
	kolcro		n(12,3),;
	proscg		n(12,3),;
	probih		n(12,3),;
	procro		n(12,3))

ERASE psklop.dbf
ERASE psklop.cdx
CREATE TABLE psklop;
	(sklop		c(13),;
	element		c(13),;
	naziv		c(30),;
	kolicina	n(12,3))

ERASE PKONKUP.DBF
CREATE TABLE PKONKUP;
	(KUPDOB		C(6),;
	DATUM		D(8),;
	VREME		C(8),;
	NAPOMENA	C(100),;
	ZVAO		C(10),;
	staje		n(1))
	
ERASE topgrup.DBF
CREATE TABLE topgrup;
	(sifra		C(13),;
	naziv		c(40),;
	jm			C(3),;
	kolicina1	n(12,3),;
	proc1		n(7,2),;
	razl1		n(12,3),;
	procr1		n(7,2),;
	kolicina2	n(12,3),;
	proc2		n(7,2),;
	razl2		n(12,3),;
	procr2		n(7,2),;
	kolicina3	n(12,3),;
	proc3		n(7,2))
	
ERASE topgrup1.DBF
CREATE TABLE topgrup1;
	(kupdob		C(6),;
	naziv		c(30),;
	kolicina1	n(12,3),;
	razl1		n(12,3),;
	proc1		n(8,2),;
	procr1		n(8,2),;
	kolicina2	n(12,3),;
	razl2		n(12,3),;
	proc2		n(8,2),;
	procr2		n(8,2),;
	kolicina3	n(12,3),;
	proc3		n(8,2))

ERASE topgrupe.DBF
CREATE TABLE topgrupe;
	(grupa		C(4),;
	naziv		c(30),;
	kolicina1	n(12,3),;
	vred1		n(12,2),;
	proc1		n(8,2),;
	kolicina21  n(12,3),;
	vred21		n(12,2),;
	proc21		n(8,2),;
	kolicina2	n(12,3),;
	vred2		n(12,2),;
	proc2		n(8,2),;
	kolicina32  n(12,3),;
	vred32		n(12,2),;
	proc32		n(8,2),;
	kolicina3	n(12,3),;
	vred3		n(12,2),;
	proc3		n(8,2))

ERASE topgrupek.DBF
CREATE TABLE topgrupek;
	(grupa		C(13),;
	naziv		c(30),;
	kolicina1	n(12,3),;
	vred1		n(12,2),;
	proc1		n(8,2),;
	kolicina21  n(12,3),;
	vred21		n(12,2),;
	proc21		n(8,2),;
	kolicina2	n(12,3),;
	vred2		n(12,2),;
	proc2		n(8,2),;
	kolicina32  n(12,3),;
	vred32		n(12,2),;
	proc32		n(8,2),;
	kolicina3	n(12,3),;
	vred3		n(12,2),;
	proc3		n(8,2))

ERASE ponudarg.DBF
CREATE TABLE ponudarg;
	(sifrob		C(13),;
	naziv		c(30),;
	kupio		n(15,3),;
	prodato		n(15,3),;
	ncena		n(15,5),;
	pcena	    n(15,5),;
	rabat		n(6,2),;
	pruc		n(6,2),;
	cena		n(15,5),;
	mpcena		n(15,5),;
	oznaka		c(1))


ERASE proba.DBF
CREATE TABLE proba;
	(prvo		C(30),;
	drugo		n(15,3))


ERASE dani.dbf
CREATE TABLE dani;
	(ned		n(2),;
	pon			n(15,2),;
	uto			n(15,2),;
	sre			n(15,2),;
	cet			n(15,2),;
	pet			n(15,2),;
	sub			n(15,2),;
	neduk		n(15,2),;
	nedproc		n(8,2),;
	dat1		d(8),;
	dat2		d(8))
	
ERASE dani1.dbf
CREATE TABLE dani1;
	(ned		n(2),;
	pon			n(15,2),;
	uto			n(15,2),;
	sre			n(15,2),;
	cet			n(15,2),;
	pet			n(15,2),;
	sub			n(15,2),;
	neduk		n(15,2),;
	nedproc		n(8,2),;
	dat1		d(8),;
	dat2		d(8))

ERASE pnivstav.dbf
CREATE TABLE pnivstav;
	(rb			n(6),;
	datum		d(8),;
	brdok		c(9),;
	sifrob		c(13),;
	naziv		c(30),;
	kolicina	n(15,3),;
	stacena		n(15,7),;
	novcena		n(15,7),;
	marza		n(15,6),;
	tarifa		c(2),;
	stopa		n(5,2),;
	jm			c(3))
	
ERASE kepu.dbf
CREATE TABLE kepu;
	(rb			n(6),;
	datum		d(8),;
	opis		c(60),;
	zaduzenje	n(15,2),;
	razduzenje	n(15,2),;
	datupl		d(8),;
	uplata		n(15,2))


ERASE pcur.dbf
CREATE TABLE pcur;
	(brdok		c(6),;
	magacin		c(5),;
	datum		d(8),;
	kupdob		c(8),;
	duguje		n(15,2),;
	datupl		d(8),;
	uplata		n(15,2))

ERASE pregled.dbf
CREATE TABLE pregled;
	(brdok	c(9),;
	magacin	c(5),;
	datum	d(8),;
	valuta	d(8),;
	kupdob	c(6),;
	nazkom  c(30),;
	pvred	n(15,2),;
	fiskal	c(5),;
	stfis	n(1),;
	zakljucan n(1),;
	knjizen	n(1),;
	efak	n(1),;
	brdoki	c(15))	

ERASE istinaz.dbf
CREATE TABLE istinaz;
	(sifra	c(13),;
	naziv	c(50))


ERASE abc.dbf
CREATE TABLE abc;
	(art_id		c(20),;
	 tax_id		c(1),;
	 plu_naziv	c(40),;
	 cena		n(10,2),;
	 kolicina	n(12,3))

ERASE komanda.dbf
ERASE komanda.ntx
CREATE TABLE komanda;
	(komanda	c(3),;
	 tekst		c(40))


ERASE prosecna.dbf
ERASE prosecna.cdx
CREATE TABLE prosecna;
	(datum		d(8),;
	 pstanje	n(12,3),;
	 ukol		n(12,3),;
	 ucen		n(12,2),;
	 ikol		n(12,3),;
	 icen		n(12,2),;
	 stanjep	n(12,3),;
	 prosecna	n(12,2))

ERASE koverat.dbf
ERASE koverat.cdx
CREATE TABLE koverat;
	(naziv		c(30),;
	 naziv1		c(30),;
	 adresa		c(30),;
	 ptt		c(5),;
	 mesto		c(30))


ERASE efakture.dbf
CREATE TABLE efakture;
	(CRF 		C(3),;
	 BRDOK  	c(20),;
	 DATIZD     c(10),;
	 DATVAL 	c(10),; 
	 OZNDOK		c(3),;
	 VALUTA	    c(3),;
     DATOBRP	c(3),;
     BRNAR      c(15),;
     BRUG		c(15),;
     BRSPO		c(15),;
     PIBFIRME   c(250),; 
     PIBKUP     c(250),;
     JBKJS      c(6),;
     DATPROM    c(10),;
     PAYANSCO   c(2),;
     MODNUM     c(5),;
     POZIVNABRO c(11),;
     TEKUCI     c(20),;
     NAPOMENA   c(200),;
     SIFROB     c(13),;
     JM         c(3),;
     KOLICINA   c(15),;
     NAZIV      c(240),;
     CENA       c(15),;
     OZNPOR     c(2),;
	 stopa		c(5),;
     RABAT      c(6),;
     osnovica   c(15),;
     rabatiz	c(15),;
     prodajna	c(15))

FUNCTION okom(mmkupdob)
SELECT kupdob
SET ORDER TO tag kupdob
GOTO top
SEEK mmkupdob
IF !FOUND()
*	=MESSAGEBOX("Zao mi je ali takav kupac ne postoji","Upozorenje",48)
ELSE
	m.sifkupdob=kupdob.kupdob
	m.nazkupdob=kupdob.naziv
	m.adrkupdob=kupdob.adresa
	m.meskupdob=kupdob.mesto
	m.kuppdv=kupdob.pdv
	m.matkupdob=kupdob.maticni
	m.pibkupdob=kupdob.pib
	m.pttkupdob=kupdob.ptt
ENDIF

RETURN
****************************************

FUNCTION okom1(mmkupdob)
SELECT kupdob
SET ORDER TO tag kupdob
GOTO top
SEEK mmkupdob
IF !FOUND()
**	=MESSAGEBOX("Zao mi je ali takav kupac ne postoji","Upozorenje",48)
ELSE
	m.sifkupdob=kupdob.kupdob
	m.nazkupdob=kupdob.naziv
	m.adrkupdob=kupdob.adresa
	m.meskupdob=kupdob.mesto
	m.kuppdv=kupdob.pdv
	m.matkupdob=kupdob.maticni
	m.pibkupdob=kupdob.pib
	m.pttkupdob=kupdob.ptt	
ENDIF

RETURN
****************************************

FUNCTION orob(mmsifrob)
SELECT roba
SET ORDER TO tag sifrob
GOTO top
SEEK mmsifrob
IF !FOUND()
	=MESSAGEBOX("Zao mi je ali takva roba ne postoji","Upozorenje",48)
ELSE
	m.sifrob	=roba.sifrob
	m.nazrob	=roba.naziv
	m.jm		=roba.jm
ENDIF

RETURN
****************************************
FUNCTION omag(mmmag)
SELECT magacin
SET ORDER TO tag magacin
GOTO top
SEEK mmmag
IF !FOUND()
	=MESSAGEBOX("Zao mi je ali takav magacin ne postoji","Upozorenje",48)
	return("")
ELSE
	return(magacin.naziv)
ENDIF
return

****************************************


FUNCTION poruka(porukica)
=MESSAGEBOX(porukica,"Poruka!!!!",48)
RETURN



***********************************************************************
FUNCTION nadjikom(mmkupdob)

SELECT kupdob
SET ORDER TO tag kupdob
GOTO top
SEEK mmkupdob
IF !FOUND()
	*=PORUKA("Zao mi je ali takav kupac ne postoji")
ELSE
	m.sifkupdob=kupdob.kupdob
	m.nazkupdob=kupdob.naziv
	m.adrkupdob=kupdob.adresa
	m.meskupdob=kupdob.mesto
	m.kuppdv=kupdob.pdv
	m.matkupdob=kupdob.maticni
	m.pibkupdob=kupdob.pib
ENDIF

RETURN



*************************************************************************
PROCEDURE fenix
CLOSE ALL
DO FORM indexiraj
CLOSE ALL
open database belcar shared	
DO otvaranje
RETURN

*************************************************************
FUNCTION rolock()
DO WHILE !RLOCK()
=MESSAGEBOX("Neko je zakljucao slog","Poruka!",0,1)
ENDDO
RETURN

************************************************************
FUNCTION robica()
PARAMETERS mrobica
SELECT zalihe
SET ORDER to tag zalihe
GOTO top
SEEK m.magacin+mrobica
m.ncena=zalihe.nabcen
m.pcena=zalihe.procen
m.mpcenadin=zalihe.mpcenadin
m.mpcenaeur=zalihe.mpcenaeur
Rkolicina=zalihe.ukol-zalihe.ikol
*BROWSE
SELECT kalkstav
SET ORDER TO tag sifrob1
GOTO top
SEEK mrobica
DO WHILE !EOF()
IF kalkstav.sifrob<>mrobica
	EXIT
endif	
*IF kalkstav.kolicina<>0
	m.zadnce=kalkstav.ncena
	EXIT
*ENDIF
SKIP
ENDDO
m.ncena=m.zadnce
RETURN (Rkolicina)
************************************************************

PROCEDURE greska
PARAMETER gr1,gr2,gr3,gr4,gr5
merror=gr1
mess=gr2
mess1=gr3
mprog=gr4
mlineno=gr5
SELECT greska
APPEND BLANK
replace datum WITH DATE()
replace vreme WITH TIME()
replace greska WITH gr1
replace por		WITH gr2
replace por1	WITH gr3
replace pro		WITH gr4
replace lini	WITH gr5
deaktiviraj()
DO FORM greska
RETURN

*********************************************************************

function SLOVIMA( broj )
DECLARE imebr[9]
  local _trojka,;
  tric,;
  cs,;
  cd,;
  cj,;
  sl1

  imebr[1]="jedan"
  imebr[2]="dva"
  imebr[3]="tri"
  imebr[4]="četiri"
  imebr[5]="pet"
  imebr[6]="šest"
  imebr[7]="sedam"
  imebr[8]="osam"
  imebr[9]="devet"

  rez   = " "
  celi  = int( broj )
  dec   = ( broj - celi ) * 100
  cbroj = str( celi, 15 )
  i     = 1

  if broj == 0 
           return "nula" 
  endif

    DO while ( i < 15 )
      tric    = substr( cbroj, i, 3 )
      _trojka = val( tric )
      if tric # "   " .and. ( tric # "000" .or. i = 4 )
        cs = val( substr( tric, 1, 1 ) )
        cd = val( substr( tric, 2, 1 ) )
        cj = val( substr( tric, 3, 1 ) )
        do case
          case cs = 1
            rez = rez+ "sto"
          case cs = 2
            rez = rez+ "dve"
          case cs > 2
            rez = rez+ imebr[cs]
        endcase
        do case
          case cs > 4
            rez = rez+ "stotina"
          case cs > 1
            rez =rez+ "stotine"
        endcase
        sl1 = iif( cj = 0, "", imebr[cj] )
        do case
          case cd =4
            rez =rez+ "četr"
          case cd = 5
            rez =rez+ "pe"
          case cd = 6
            rez =rez+ "šez"
          case cd = 9
            rez =rez+ "deve"
          case cd > 1
            rez =rez+ imebr[cd]
          case cd = 1
            sl1 = ""
            do case
              case cj = 0
                rez =rez+ "deset"
              case cj = 1
                rez =rez+ "jeda"
              case cj = 4
                rez =rez+ "četr"
              otherwise
                rez =rez+ imebr[cj]
            endcase
            if cj > 0 
            	 rez =rez+ "naest" 
          	endif
          endcase
          if cd > 1 
          	 rez =rez+ "deset" 
          endif
            do case
              case cj = 1 .and. ( i == 4 .or. i == 10 ) .and. cd # 1
                sl1 = "jedna"
              case cj = 2 .and. ( i == 4 .or. i == 10 ) .and. cd # 1
                sl1 = "dve"
            endcase
            rez =rez+ sl1
            do case
              case i = 1 .or. i == 10
                rez =rez+ "hiljad"
                do case
                  case ( _trojka % 100 > 11 .and. _trojka % 100 < 19 ) .or. cj == 1
                    rez =rez+ "a"
                  case _trojka = 1
                    rez =rez+ "u"
                  case cj > 4 .or. cj = 0
                    rez =rez+ "a"
                  case cj > 1
                    rez =rez+ "e"
                endcase
              case i = 4
                rez =rez+ "milijard"
                do case
                  case ( _trojka % 100 > 11 .and. _trojka % 100 < 19 )
                    rez =rez+ "i"
                  case cj = 1
                    rez =rez+ "a"
                  case cj > 4 .or. cj = 0
                    rez =rez+ "i"
                  case cj > 1
                    rez =rez+ "e"
                endcase
              case i = 7
                rez =rez+ "milion"
                if cj # 1 .or. ( _trojka % 100 > 11 .and. _trojka % 100 < 19 )
                  rez =rez+ "a"
                endif
            endcase
          endif
          i =i+ 3
        enddo
        return( rez + " i " + transform( dec, "@L 99" ) + "/100" )
        **********************************************************************



FUNCTION fgrupa(msifra)
SELECT grupa 
SET ORDER TO tag grupa
GOTO top
SEEK msifra
IF FOUND()
	m.nazgru=grupa.naziv
ELSE
	m.nazgru=SPACE(30)	
endif
RETURN .t.


FUNCTION fproizvod(msifra)
SELECT proizvod 
SET ORDER TO tag sifra
GOTO top
SEEK msifra
IF FOUND()
	m.nazpro=proizvod.naziv
ELSE
	m.nazpro=SPACE(30)	
endif
RETURN .t.

FUNCTION aktiviraj()
m.aktivan=.t.
DO FORM aktivan
RETURN .t.

FUNCTION deaktiviraj()
m.aktivan=.f.
RETURN .t.


***************** priprema za upis *********************
FUNCTION pripremi(mfile)
=CURSORSETPROP("Buffering",5,mfile)
*DO WHILE !RLOCK()
*	WAIT "Sacekajte zakljucan je slog" TIMEOUT 2
*ENDDO
return(0)

***************** priprema za brisanje *********************
FUNCTION pripremib(mfile)
=CURSORSETPROP("Buffering",3,mfile)
*DO WHILE !RLOCK()
*	WAIT "Sacekajte zakljucan je slog" TIMEOUT 2
*ENDDO
return(0)

****************** upis u tabelu **********************
FUNCTION upisi()
BEGIN TRANSACTION 
	=TABLEUPDATE(.t.)
END TRANSACTION 
UNLOCK all
return(0)
*****************************************************
************** formatiranje vodecih nula kod automatskog sifriranja **********
FUNCTION formsif(mvarijabla,mduzina)
mvar1=ALLTRIM(STR(VAL(mvarijabla)+1))
ml=LEN(mvar1)
mvarijabla=REPLICATE("0",mduzina-ml)+mvar1
RETURN(mvarijabla)

**********************************************************************
************** formatiranje krajnjih blankova da bi nasao dokumente u gk **********
FUNCTION formdok(mvarijabla,mduzina)
mvar1=ALLTRIM(mvarijabla)
ml=LEN(mvar1)
mvarijabla=mvar1+REPLICATE(" ",mduzina-ml)
RETURN(mvarijabla)

**********************************************************************

*************** skidanje sa zaliha izlaz **********************
FUNCTION zizlaz(fmag,fsif,fkol,fnce,fpce)
SELECT zalihe
SET ORDER TO tag sifra
GOTO top
SEEK fsif
IF FOUND()
	pripremi("zalihe")
	replace zalihe.ikol 		WITH zalihe.ikol+fkol
	replace zalihe.ivrednost 	WITH zalihe.ivrednost+fkol*fpce
	upisi()
ENDIF
return(0)
**************************************************************	
*************** vracanje stanja na zalihe izlaz **********************
FUNCTION zizlazb(fmag,fsif,fkol,fnce,fpce)
SELECT zalihe
SET ORDER TO tag sifra
GOTO top
SEEK fsif
IF FOUND()
	pripremi("zalihe")
	replace zalihe.ikol 		WITH zalihe.ikol-fkol
	replace zalihe.ivrednost 	WITH zalihe.ivrednost-fkol*fpce
	upisi()
ENDIF
return(0)
**************************************************************	
*************** prosecna nabavna cena **********************
FUNCTION prosnab(fsif,fmag,fdatum)
mprosecna=0
SELECT prosecna
ZAP

SELECT kalkstav
SET ORDER TO tag magsifrob
GOTO top
SEEK fmag+fsif
DO WHILE !EOF()
IF kalkstav.datum>fdatum .or. kalkstav.magacin<>fmag .or. kalkstav.sifrob<>fsif
	EXIT
endif	
mdat=kalkstav.datum
mkol=kalkstav.kolicina
mcen=kalkstav.ncena
SELECT prosecna
APPEND BLANK
replace prosecna.datum 	WITH mdat
replace prosecna.ukol	WITH mkol
replace prosecna.ucen	WITH mcen
SELECT kalkstav
SKIP
ENDDO

SELECT fakstava
SET ORDER TO tag magsifrob
GOTO top
SEEK fmag+fsif
DO WHILE !EOF()
IF fakstava.datum>fdatum .or. fakstava.magacin<>fmag .or. fakstava.sifrob<>fsif
	EXIT
endif	
mdat=fakstava.datum
mkol=fakstava.kolicina
mcen=fakstava.pcena
SELECT prosecna
APPEND BLANK
replace prosecna.datum 	WITH mdat
replace prosecna.ikol	WITH mkol
replace prosecna.icen	WITH mcen
SELECT fakstava
SKIP
ENDDO

mkol=0
SELECT prosecna
GOTO top
DO WHILE !EOF()
replace prosecna.pstanje 	WITH mkol
mkol=prosecna.pstanje+prosecna.ukol-prosecna.ikol
replace prosecna.stanjep	WITH mkol
mprosecna=(prosecna.ukol*prosecna.ikol+prosecna.pstanje*prosecna.prosecna)/(prosecna.pstanje+prosecna.ukol)
replace prosecna.prosecna 	WITH mprosecna
SKIP
ENDDO

return(mprosecna)


********************************* presek stanja ******************************
PROCEDURE preseksta
SELECT komanda
ZAP
APPEND BLANK
replace komanda.komanda WITH "80"
COPY TO \\fiskalni\c\metaline\exch\lnk\to_fp\CMD_080.dbf FOXPLUS
RETURN

*****************************************************************************
********************************* datum kontra ******************************
function lindat(mmdatum)
datuml=DTOS(mmdatum)
datuml=SUBSTR(datuml,1,4)+"-"+SUBSTR(datuml,5,2)+"-"+SUBSTR(datuml,7,2)
RETURN(datuml)

*****************************************************************************


***************************** dnevni fiskalni ******************************
PROCEDURE dnevnifis	
SELECT komanda
ZAP
APPEND BLANK
replace komanda.komanda WITH "90"
COPY TO \\fiskalni\c\metaline\exch\lnk\to_fp\CMD_090.dbf FOXPLUS
return
*****************************************************************************

*************************** brisanje stavki********************************
PROCEDURE bristavki
SELECT komanda
ZAP
APPEND BLANK
replace komanda.komanda WITH "140"
COPY TO c:\metaline\exch\lnk\to_fp\CMD_140.dbf FOXPLUS
RETURN
******************************************************************************

*************** otkljucaj/zakljucaj dokumente ******************************
FUNCTION zakotk(tabela)
SELECT pregled
IF pregled.zakljucan=0 
	replace pregled.zakljucan WITH 1
else
	masterpass=.f.
	DO FORM unoslozinke
	IF masterpass=.t.
		replace pregled.zakljucan WITH 0
	endif	
ENDIF
m.brdok=pregled.brdok
SELECT &tabela
SET ORDER TO tag brdok
GOTO top
SEEK m.brdok
IF FOUND()
	pripremi(tabela)
	replace zakljucan WITH pregled.zakljucan
	upisi()
ENDIF
return(0)
****************************************************************
*************** knjizi dokumente u gk******************************
FUNCTION knjizi(m.fbrdok,m.fmagacin,m.fvrstadok)
SELECT pregled
IF pregled.zakljucan<>1
*	=MESSAGEBOX("Postovani morate prvo zakljucati dokument",0,"Obratite paznju!")
*	return(0)
ENDIF
IF pregled.knjizen=1
	oli=MESSAGEBOX("Nalog je vec proknjizen da li zelite da ga ponovo proknjizim?",4,"Molim Vas da obratite paznju")
	IF oli=6 
		=MESSAGEBOX("Knjizim ponovo u GK",0,"Poruka",1000)
	endif
	IF oli=7
		return(0)
	endif	
ELSE
	=MESSAGEBOX("Knjizim GK",0,"Poruka",1000)
ENDIF
replace pregled.knjizen WITH 1
***************** kalkulacija - domaca
IF m.fvrstadok="KAD"
	*=MESSAGEBOX(m.fbrdok+m.fmagacin+m.fvrstadok,0)
	sELECT zagkalk
	SET ORDER TO tag magbrdok
	GOTO top
	SEEK m.fmagacin+m.fbrdok
	IF FOUND()
		pripremi("zagkalk")
		replace knjizen WITH 1
		upisi()
		mdob=zagkalk.kupdob
		mizndob=zagkalk.zo0+zagkalk.zo5+zagkalk.zo8+zagkalk.zo18
		mpdvdob=zagkalk.zp5+zagkalk.zp8+zagkalk.zp18
		miznzav=zagkalk.zto0+zagkalk.zto18
		mpdvzav=zagkalk.ztp18
		m.nalog=formdok("KAD-"+ALLTRIM(m.fbrdok),10)
		m.dokument=formdok("MAG-"+m.fmagacin,10)
		m.datum=zagkalk.datum
		m.valuta=zagkalk.valuta
		m.opis=zagkalk.brdoki		
		m.nab=mizndob+miznzav
		m.pro=0
		m.ruc=0
		SELECT kalkstav
		SET ORDER TO tag magbrdok
		GOTO top
		SEEK m.fmagacin+m.fbrdok
		DO WHILE !EOF()
		IF kalkstav.brdok<>m.fbrdok
			EXIT
		ENDIF
		IF kalkstav.magacin<>m.fmagacin
			EXIT
		ENDIF
		m.pro=m.pro+kalkstav.pcena*kalkstav.kolicina
		SKIP 
		ENDDO
		m.ruc=m.pro-(mizndob+miznzav)
		
		SELECT gknjiga
		SET ORDER TO tag nalog
		GOTO top
		SEEK m.nalog+m.dokument
	
		DO WHILE !EOF()
*		=MESSAGEBOX(gknjiga.nalog+m.nalog+gknjiga.dokument+m.dokument,0)
		IF ALLTRIM(gknjiga.NALOG)<>ALLTRIM(M.NALOG) .or. ALLTRIM(gknjiga.dokument)<>ALLTRIM(m.dokument)
			EXIT
		endif	
		IF ALLTRIM(gknjiga.nalog)=ALLTRIM(m.nalog) .and. ALLTRIM(gknjiga.dokument)=ALLTRIM(m.dokument) .and. ALLTRIM(gknjiga.automatika)="BG"
			pripremi("gknjiga")
			DELETE
			upisi()
		ENDIF
		SKIP
		ENDDO
	****************************** 4330 *****************************
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "4330"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizndob+mpdvdob
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()						
	****************************** 270 *****************************
		IF zagkalk.zp18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "270"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH zagkalk.zp18
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif					
	****************************** 271 *****************************
		IF zagkalk.zp8<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "271"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH zagkalk.zp8
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	****************************** 270 zavisni *****************************
		IF zagkalk.ztp18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "270"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH zagkalk.ztp8
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	****************************** 1329 ruc *****************************
		IF m.ruc<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "1329"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH m.ruc
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()						
		ENDIF
	****************************** 1320 prod cena *****************************
		IF m.pro<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "132"+ALLTRIM(m.magacin)
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Kalkulacija:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH m.pro
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
		
				
	ENDIF
endif		
****************************************
***************** kalkulacija - ino
IF m.fvrstadok="KAU"
	sELECT zagkalk
	SET ORDER TO tag magbrdok
	GOTO top
	SEEK m.fmagacin+m.fbrdok
	IF FOUND()
	**	browse
		pripremi("zagkalk")
		replace knjizen WITH 1
		upisi()
		mdob=zagkalk.kupdob
		mizndob=zagkalk.io0+zagkalk.io5+zagkalk.io8+zagkalk.io18
		mpdvdob=zagkalk.ip5+zagkalk.ip8+zagkalk.ip18
		miznzav=zagkalk.ito0+zagkalk.ito18
		mpdvzav=zagkalk.itp18
		m.nalog=formdok("KAU-"+ALLTRIM(m.fbrdok),10)
		m.dokument=formdok("MAG-"+m.fmagacin,10)
		m.datum=zagkalk.datum
		m.valuta=zagkalk.valuta
		m.opis=zagkalk.brdoki		
		m.nab=mizndob+miznzav
		m.pro=0
		m.ruc=0
		SELECT kalkstav
		SET ORDER TO tag magbrdok
		GOTO top
		SEEK m.fmagacin+m.fbrdok
		DO WHILE !EOF()
		IF kalkstav.brdok<>m.fbrdok
			EXIT
		ENDIF
		IF kalkstav.magacin<>m.fmagacin
			EXIT
		ENDIF
		m.pro=m.pro+kalkstav.pcena*kalkstav.kolicina
		SKIP 
		ENDDO
		m.ruc=m.pro-(mizndob+miznzav)
		SELECT gknjiga
		SET ORDER TO tag nalog
		GOTO top
		SEEK m.nalog+m.dokument
	
		DO WHILE !EOF()
*		=MESSAGEBOX(gknjiga.nalog+m.nalog+gknjiga.dokument+m.dokument,0)
		IF ALLTRIM(gknjiga.NALOG)<>ALLTRIM(M.NALOG) .or. ALLTRIM(gknjiga.dokument)<>ALLTRIM(m.dokument)
			EXIT
		endif	
		IF ALLTRIM(gknjiga.nalog)=ALLTRIM(m.nalog) .and. ALLTRIM(gknjiga.dokument)=ALLTRIM(m.dokument) .and. ALLTRIM(gknjiga.automatika)="BG"
			pripremi("gknjiga")
			DELETE
			upisi()
		ENDIF
		SKIP
		ENDDO
	****************************** 4340 *****************************
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "4340"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Uvozna kalk.:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizndob		&&+mpdvdob ne ide za ino
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()						
	****************************** 274 *****************************
		IF zagkalk.ip18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "274"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Uvozna kalk.:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH zagkalk.ip18
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif					
	****************************** 270 zavisni *****************************
		IF zagkalk.itp18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "270"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Uvozna kalk.:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH zagkalk.itp18
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	****************************** 1329 ruc *****************************
		IF m.ruc<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "1329"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Uvozna kalk.:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH m.ruc
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()						
		ENDIF
	****************************** 1320 prod cena *****************************
		IF m.pro<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "132"+ALLTRIM(m.magacin)
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Uvozna kalk.:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH m.pro
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF

	ENDIF
endif		
****************************************
***************** fakture za robu
IF m.vrstadok="FAR"
	sELECT zagfak
	SET ORDER TO tag magbrdok
	GOTO top
	SEEK m.fmagacin+m.fbrdok
	IF FOUND()
		pripremi("zagfak")
		replace knjizen WITH 1
		upisi()

		m.nalog=formdok("FAR-"+ALLTRIM(m.fbrdok),10)
		m.dokument=formdok("MAG-"+m.fmagacin,10)
		m.datum=zagfak.datum
		m.valuta=zagfak.valuta		

		mdob=zagfak.kupdob
		
		SELECT kupdob
		SET ORDER TO tag kupdob
		GOTO top
		SEEK mdob
		mstranac=kupdob.stranac
		mpdv8=0
		mpdv18=0
		mizn=0
		mruc=0
		mpnv=0
		SELECT fakstav
		SET ORDER TO tag magbrdok
		GOTO top
		SEEK m.fmagacin+m.fbrdok
		DO WHILE !EOF()
		IF fakstav.magacin<>m.fmagacin .or. fakstav.brdok<>m.fbrdok
			EXIT
		endif	
		msif=fakstav.sifrob
		*mpros=prosnab(msif,fakstav.magacin,fakstav.datum)
		
		SELECT fakstav
		mizn=mizn+fakstav.kolicina*fakstav.pcena*(1-fakstav.rabat/100)
		IF fakstav.stopa=8
			mpdv8=mpdv8+fakstav.kolicina*fakstav.pcena*(1-fakstav.rabat/100)*fakstav.stopa/100
		ENDIF
		IF fakstav.stopa=20
			mpdv18=mpdv18+fakstav.kolicina*fakstav.pcena*(1-fakstav.rabat/100)*fakstav.stopa/100
		endif
		*mpnv=mpnv+fakstav.kolicina*mpros
		SKIP
		ENDDO
		mruc=mizn-mpnv
		mizn=ROUND(mizn,2)
		mpdv8=ROUND(mpdv8,2)
		mpdv18=ROUND(mpdv18,2)
		SELECT gknjiga
		SET ORDER TO tag nalog
		GOTO top
		SEEK m.nalog+m.dokument
	
		DO WHILE !EOF()
*		=MESSAGEBOX(gknjiga.nalog+m.nalog+gknjiga.dokument+m.dokument,0)
		IF ALLTRIM(gknjiga.NALOG)<>ALLTRIM(M.NALOG) .or. ALLTRIM(gknjiga.dokument)<>ALLTRIM(m.dokument)
			EXIT
		endif	
		IF ALLTRIM(gknjiga.nalog)=ALLTRIM(m.nalog) .and. ALLTRIM(gknjiga.dokument)=ALLTRIM(m.dokument) .and. ALLTRIM(gknjiga.automatika)="BG"
			pripremi("gknjiga")
			DELETE
			upisi()
		ENDIF
		SKIP
		ENDDO
		*=MESSAGEBOX(mizn,0)
	****************************** 2020-2030 *****************************
		IF mstranac=1
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "2050"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH mizn+mpdv8+mpdv18
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif						

		IF mstranac=2
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "2040"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH mizn+mpdv8+mpdv18
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif						

	****************************** 471 *****************************
		IF mpdv8<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "471"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mpdv8
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif					
	****************************** 470 *****************************
		IF mpdv18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "470"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mpdv18
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	****************************** 6021-603 *****************************
		IF mstranac=3
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "6021"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizn		&&  mpnv ovo treba kako treba od januara
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
		
		IF mstranac<>3
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "603"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizn		&&  mpnv ovo treba kako treba od januara
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		endif
	****************************** 1329 ruc *****************************
*!*			IF mruc<>0
*!*			SELECT gknjiga
*!*			pripremi("gknjiga")
*!*			APPEND BLANK
*!*			replace gknjiga.datum 		WITH m.datum
*!*			replace gknjiga.datknji		WITH m.datum
*!*			replace gknjiga.dpo			WITH m.datum
*!*			replace gknjiga.nalog		WITH m.nalog
*!*			replace gknjiga.dokument	WITH m.dokument
*!*			replace gknjiga.konto		WITH "1329"
*!*			replace gknjiga.analitika	WITH ""
*!*			replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
*!*			replace gknjiga.duguje		WITH mruc
*!*			replace gknjiga.valuta		WITH m.valuta
*!*			replace gknjiga.automatika	WITH "BG"
*!*			upisi()						
*!*			ENDIF
	****************************** 132  lager  *****************************
		IF mizn<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "132"+ALLTRIM(m.magacin)
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizn
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF

	****************************** 5011  prosecna nabavna vrednost prodate robe  *****************************
	*	IF mpnv<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "5011"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH mizn
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
	*	ENDIF

	endif
endif		
****************************************
***************** fakture za usluge
IF m.vrstadok="FAU"
	sELECT zagofak
	SET ORDER TO tag magbrdok
	GOTO top
	SEEK m.fmagacin+m.fbrdok
	IF FOUND()
		pripremi("zagofak")
		replace knjizen WITH 1
		upisi()

		m.nalog=formdok("FAU-"+ALLTRIM(m.fbrdok),10)
		m.dokument=formdok("MAG-"+m.fmagacin,10)
		m.datum=zagofak.datum
		m.valuta=zagofak.valuta		

		mdob=zagofak.kupdob
		
		SELECT kupdob
		SET ORDER TO tag kupdob
		GOTO top
		SEEK mdob
		mstranac=kupdob.stranac
		mpdv8=0
		mpdv18=0
		mizn=0
		mruc=0
		mpnv=0
		SELECT fakostav
		SET ORDER TO tag magbrdok
		GOTO top
		SEEK m.fmagacin+m.fbrdok
		DO WHILE !EOF()
		IF fakostav.magacin<>m.fmagacin .or. fakostav.brdok<>m.fbrdok
			EXIT
		endif	
		msif=fakostav.sifrob
		
		SELECT fakostav
		mizn=mizn+fakostav.kolicina*fakostav.pcena
		IF fakostav.stopa=8
			mpdv8=mpdv8+fakostav.kolicina*fakostav.pcena*fakostav.stopa/100
		ENDIF
		IF fakostav.stopa=20
			mpdv18=mpdv18+fakostav.kolicina*fakostav.pcena*fakostav.stopa/100
		endif
		SKIP
		ENDDO
		
		mpnv=mizn-(mpdv8+mpdv18)		
		SELECT gknjiga
		SET ORDER TO tag nalog
		GOTO top
		SEEK m.nalog+m.dokument
	
		DO WHILE !EOF()
*		=MESSAGEBOX(gknjiga.nalog+m.nalog+gknjiga.dokument+m.dokument,0)
		IF ALLTRIM(gknjiga.NALOG)<>ALLTRIM(M.NALOG) .or. ALLTRIM(gknjiga.dokument)<>ALLTRIM(m.dokument)
			EXIT
		endif	
		IF ALLTRIM(gknjiga.nalog)=ALLTRIM(m.nalog) .and. ALLTRIM(gknjiga.dokument)=ALLTRIM(m.dokument) .and. ALLTRIM(gknjiga.automatika)="BG"
			pripremi("gknjiga")
			DELETE
			upisi()
		ENDIF
		SKIP
		ENDDO
	****************************** 2020-2030 *****************************
		IF mstranac=1
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "2050"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH mizn+mpdv8+mpdv18
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif						

		IF mstranac=2
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "2040"
		replace gknjiga.analitika	WITH mdob
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.duguje		WITH mizn+mpdv8+mpdv18
		replace gknjiga.valuta		WITH m.valuta
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif						

	****************************** 471 *****************************
		IF mpdv8<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "471"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mpdv8
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()
		endif					
	****************************** 470 *****************************
		IF mpdv18<>0
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "470"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mpdv18
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	****************************** 6021-603 *****************************
		IF mstranac=3
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "6122"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizn
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
		
		IF mstranac<>3
		SELECT gknjiga
		pripremi("gknjiga")
		APPEND BLANK
		replace gknjiga.datum 		WITH m.datum
		replace gknjiga.datknji		WITH m.datum
		replace gknjiga.dpo			WITH m.datum
		replace gknjiga.nalog		WITH m.nalog
		replace gknjiga.dokument	WITH m.dokument
		replace gknjiga.konto		WITH "6132"
		replace gknjiga.analitika	WITH ""
		replace gknjiga.opis		WITH "Faktura:"+ALLTRIM(m.fbrdok)+"/"+ALLTRIM(m.fmagacin)
		replace gknjiga.potrazuje	WITH mizn
		replace gknjiga.valuta		WITH m.valuta	
		replace gknjiga.automatika	WITH "BG"
		upisi()					
		ENDIF
	endif	
endif		
****************************************************************
***************** medjuskladisnica
IF m.vrstadok="MS"
	SELECT &tabela
	SET ORDER TO tag magbrdok
	GOTO top
	SEEK m.magacin+m.brdok
	IF FOUND()
		pripremi(tabela)
		replace knjizen WITH 1
		upisi()
	ENDIF
endif		
return(0)
****************************************************************




*************** prosecna nabavna cena **********************
FUNCTION prosCEN(fsif,fmag,fdatum)
mprosecna=0

SELECT robkar
zap
SET ORDER TO tag datum
GOTO top
M.ODDAT=CTOD("01.01.2010")
m.dodat=FDATUM
msukol=0
msikol=0
mstanje=0
msaldo=0
*IF thisform.optiongroup1.Value=1 .or. thisform.optiongroup1.Value=3
SELECT kalkstav
SET ORDER TO tag magsifrob
GOTO top
SEEK FMAG+FSIF
DO WHILE  !EOF()
IF kalkstav.sifrob<>FSIF .or. kalkstav.magacin<>FMAG
	EXIT
endif	
IF kalkstav.datum<M.ODDAT .or. kalkstav.datum>M.DODAT
	skip
	loop
ENDIF
mdat	=kalkstav.datum
mskom	=kalkstav.kupdob
mbrdok	=kalkstav.brdok
mukol	=kalkstav.kolicina
mpce	=kalkstav.pcena
mnce	=kalkstav.ncena
msukol=msukol+mukol
m.nazkupdob=SPACE(30)
nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "Kalkulacija"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ukolicina WITH mukol
	replace robkar.pcena 	WITH mpce
	replace robkar.duguje	WITH mukol*mpce
	replace robkar.saldo 	WITH msaldo
	replace robkar.ncena	WITH mnce
	replace robkar.staje	WITH 3
	replace robkar.pravdok WITH mbrdok
SELECT kalkstav
SKIP
ENDDO

SELECT nivstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF nivstav.sifrob<>FSIF
	EXIT
endif	
IF nivstav.datum<M.ODDAT .or. nivstav.datum>M.DODAT
	skip
	loop
ENDIF
mdat	=nivstav.datum
mbrdok	=nivstav.brdok
mukol	=nivstav.kolicina
mpce	=nivstav.marza
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.dokument WITH "Nivelacija"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ukolicina WITH mukol
	replace robkar.pcena 	WITH mpce
	replace robkar.staje	WITH 2
	replace robkar.pravdok WITH SUBSTR(mbrdok,3,7)

SELECT nivstav
SKIP
enddo

SELECT MSkalkstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF MSkalkstav.sifrob<>FSIF 
	EXIT
endif	
IF MSkalkstav.datum<M.ODDAT .or. MSkalkstav.datum>M.DODAT
	skip
	loop
ENDIF
IF mskalkstav.magacin<>FMAG .and. mskalkstav.magacinz<>FMAG
	SKIP
	LOOP
endif	
mdat	=MSkalkstav.datum
mskom	=MSkalkstav.kupdob
mbrdok	=MSkalkstav.brdok
mukol	=MSkalkstav.kolicina
mpce	=MSkalkstav.pcena
nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH SPACE(30)
	replace robkar.dokument WITH "Medjuskladisnica"
	replace robkar.brdok 	WITH mbrdok
	IF mskalkstav.magacinz=FMAG
		replace robkar.ukolicina WITH mukol
		msukol=msukol+mukol
	ENDIF
	IF mskalkstav.magacin=FMAG
		replace robkar.ikolicina WITH mukol
		msukol=msukol-mukol	
	endif		
	replace robkar.pcena 	WITH mpce

SELECT mskalkstav
SKIP
ENDDO


SELECT vrdstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF vrdstav.sifrob<>FSIF
	EXIT
endif	
IF vrdstav.datum<M.ODDAT .or. vrdstav.datum>M.DODAT
	skip
	loop
ENDIF
mdat	=vrdstav.datum
mskom	=vrdstav.kupdob
mbrdok	=vrdstav.brdok
mukol	=vrdstav.kolicina
mpce	=vrdstav.pcena
msukol=msukol+mukol
m.nazkupdob=SPACE(30)
nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "VRD"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ukolicina WITH mukol
	replace robkar.pcena 	WITH mpce

SELECT vrdstav
SKIP
ENDDO

SELECT LOMstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF LOMstav.sifrob<>FSIF
	EXIT
endif	
IF LOMstav.datum<M.ODDAT .or. LOMstav.datum>M.DODAT
	skip
	loop
ENDIF
mdat	=LOMstav.datum
mskom	=LOMstav.kupdob
mbrdok	=LOMstav.brdok
mukol	=LOMstav.kolicina
mpce	=LOMstav.pcena
msukol=msukol+mukol
m.nazkupdob=SPACE(30)
nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "LOM"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ukolicina WITH mukol
	replace robkar.pcena 	WITH mpce
SELECT LOMstav
SKIP
ENDDO

**ENDIF
**
**IF thisform.optiongroup1.Value=2 .or. thisform.optiongroup1.Value=3
SELECT fakstava
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF fakstava.sifrob<>FSIF
	EXIT
endif	
IF fakstava.datum<M.ODDAT .or. fakstava.datum>M.DODAT
	SKIP
	loop
ENDIF
IF FAKSTAVa.RAZDUZ<>"D"
**	SKIP
**	LOOP
ENDIF	
mdat	=fakstava.datum
mskom	=fakstava.kupdob
mbrdok	=fakstava.brdok
mukol	=fakstava.kolicina
mpce	=fakstava.pcena
msikol=msikol+mukol
m.nazkupdob=SPACE(30)

nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "Faktura"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ikolicina WITH mukol
	replace robkar.pcena 	WITH mpce
	replace robkar.potrazuje WITH mukol*mpce
	replace robkar.staje	WITH 4
	replace robkar.pravdok WITH mbrdok
SELECT fakstava
SKIP
ENDDO

SELECT Ifakstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF Ifakstav.sifrob<>FSIF
	EXIT
endif	
IF Ifakstav.datum<M.ODDAT .or. Ifakstav.datum>M.DODAT
	SKIP
	loop
ENDIF
IF IFAKSTAV.RAZDUZ<>"D"
**	SKIP
**	LOOP
ENDIF	
mdat	=Ifakstav.datum
mskom	=Ifakstav.kupdob
mbrdok	=Ifakstav.brdok
mukol	=Ifakstav.kolicina
mpce	=Ifakstav.pcena
msikol=msikol+mukol
m.nazkupdob=SPACE(30)

nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "Int.otpre."
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ikolicina WITH mukol
	replace robkar.pcena 	WITH mpce

SELECT Ifakstav
SKIP
ENDDO



SELECT revstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF revstav.sifrob<>FSIF
	EXIT
endif	
IF revstav.datum<M.ODDAT .or. revstav.datum>M.DODAT
	SKIP
	loop
ENDIF
IF revSTAV.RAZDUZ<>"D"
*	SKIP
*	LOOP
ENDIF	
mdat	=revstav.datum
mskom	=revstav.kupdob
mbrdok	=revstav.brdok
mukol	=revstav.kolicina
mpce	=revstav.pcena
msikol=msikol+mukol
m.nazkupdob=SPACE(30)

nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "Int.otprre."
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ikolicina WITH mukol
	replace robkar.pcena 	WITH mpce

SELECT revstav
SKIP
ENDDO

SELECT vrkstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF vrkstav.sifrob<>FSIF
	EXIT
endif	
IF vrkstav.datum<M.ODDAT .or. vrkstav.datum>M.DODAT
	SKIP
	loop
ENDIF
IF vrkSTAV.RAZDUZ<>"D"
**	SKIP
**	LOOP
ENDIF	
mdat	=vrkstav.datum
mskom	=vrkstav.kupdob
mbrdok	=vrkstav.brdok
mukol	=vrkstav.kolicina
mpce	=vrkstav.pcena
msikol=msikol+mukol
m.nazkupdob=SPACE(30)

nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "VRK"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ikolicina WITH mukol
	replace robkar.pcena 	WITH mpce

SELECT vrkstav
SKIP
ENDDO

SELECT KALOstav
SET ORDER TO tag sifrob
GOTO top
SEEK FSIF
DO WHILE  !EOF()
IF KALOstav.sifrob<>FSIF
	EXIT
endif	
IF KALOstav.datum<M.ODDAT .or. KALOstav.datum>M.DODAT
	SKIP
	loop
ENDIF
IF KALOSTAV.RAZDUZ<>"D"
**	SKIP
**	LOOP
ENDIF	
mdat	=KALOstav.datum
mskom	=KALOstav.kupdob
mbrdok	=KALOstav.brdok
mukol	=KALOstav.kolicina
mpce	=KALOstav.pcena
msikol=msikol+mukol
m.nazkupdob=SPACE(30)

nadjikom(mskom)
SELECT robkar
	APPEND BLANK
	replace robkar.datum 	WITH mdat
	replace robkar.nazdob 	WITH m.nazkupdob
	replace robkar.dokument WITH "KALO"
	replace robkar.brdok 	WITH mbrdok
	replace robkar.ikolicina WITH mukol
	replace robkar.pcena 	WITH mpce

SELECT KALOstav
SKIP
ENDDO

**ENDIF

SELECT robkar
SET ORDER TO tag kartica

mdug=0
mpot=0
m.srecen=0
m.stanje=0
m.zpcen=0
GOTO top
DO WHILE !EOF()
IF robkar.staje<>2
	mstanje=mstanje+robkar.ukolicina-robkar.ikolicina
ELSE
	replace robkar.ukolicina WITH mstanje
**	replace robkar.pcena WITH mstanje*robkar.stvacen
	replace robkar.duguje WITH mstanje*robkar.pcena
endif	
	msaldo=msaldo+robkar.duguje-robkar.potrazuje
	mdug=mdug+robkar.duguje
	mpot=mpot+robkar.potrazuje

IF m.stanje+robkar.ukolicina>0
	m.srecen=(m.srecen*m.stanje+robkar.ncena*robkar.ukolicina)/(m.stanje+robkar.ukolicina)
	m.stanje=mstanje
else
	m.srecen=0
	m.stanje=0
endif
replace robkar.stanje 	WITH mstanje
replace robkar.saldo	WITH msaldo
replace robkar.stvacen  WITH m.srecen
IF robkar.pcena>0
	m.zpcen=robkar.pcena
endif	
SKIP
ENDDO
*!*	IF FSIF="010010"
*!*		BROWSE
*!*	ENDIF	
RETURN(M.SRECEN)
