*!*	DEFINE CLASS absolutereader as custom
PROCEDURE ar_ini
m.pokracuj=.t.
DECLARE LONG ARSetDebug  IN (m.gcini_path+"absoluteread.dll ") String @filename
DECLARE LONG ARDeviceOpen  IN (m.gcini_path+"absoluteread.dll ")
DECLARE LONG ARDeviceClose IN (m.gcini_path+"absoluteread.dll ")
DECLARE LONG ARDeviceGetStatus IN (m.gcini_path+"absoluteread.dll ")
DECLARE LONG ARDeviceGetSC IN (m.gcini_path+"absoluteread.dll ") Long typ, String @data, Long size
DECLARE LONG ARDeviceGetInt IN (m.gcini_path+"absoluteread.dll ") Long typ, Long @data
DECLARE LONG ARDocumentClear IN (m.gcini_path+"absoluteread.dll ")
DECLARE LONG ARDocumentDone IN (m.gcini_path+"absoluteread.dll ")
DECLARE LONG ARDocumentGetCodeCount IN (m.gcini_path+"absoluteread.dll ") Long @num
DECLARE LONG ARDocumentSet IN (m.gcini_path+"absoluteread.dll ") Long typ, String data
DECLARE LONG ARDocumentSetInt IN (m.gcini_path+"absoluteread.dll ") Long typ, Long data
DECLARE LONG ARDocumentSetDouble IN (m.gcini_path+"absoluteread.dll ")  Long typ, Double data
DECLARE LONG ARDocumentSetDate IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long year , Long month, Long day
DECLARE LONG ARDocumentSetInvoicee IN (m.gcini_path+"absoluteread.dll ")  Long typ, String data
DECLARE LONG ARDocumentSetInvoiceeInt IN (m.gcini_path+"absoluteread.dll ")  Long typ,Long data 
DECLARE LONG ARDocumentSetCustomer IN (m.gcini_path+"absoluteread.dll ")  Long typ, String data
DECLARE LONG ARDocumentSetCustomerInt IN (m.gcini_path+"absoluteread.dll ")  Long typ,Long data 
DECLARE LONG ARDocumentAddItem IN (m.gcini_path+"absoluteread.dll ") 
DECLARE LONG ARDocumentSetItemIndex IN (m.gcini_path+"absoluteread.dll ") Long riadok_c
DECLARE LONG ARDocumentGetItemCount IN (m.gcini_path+"absoluteread.dll ") Long @count
DECLARE LONG ARDocumentSetItem IN (m.gcini_path+"absoluteread.dll ")  Long typ, String data
DECLARE LONG ARDocumentSetItemInt IN (m.gcini_path+"absoluteread.dll ")  Long typ,Long data 
DECLARE LONG ARDocumentSetItemDouble IN (m.gcini_path+"absoluteread.dll ")  Long typ, Double data
DECLARE LONG ARDocumentSetItemDate IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long year, Long month, Long day 
DECLARE LONG ARDocumentPrepare IN (m.gcini_path+"absoluteread.dll ") 
DECLARE LONG ARDocumentSaveCode IN (m.gcini_path+"absoluteread.dll ") Long index, String filename, Long filetype
DECLARE LONG ARDocumentScan IN (m.gcini_path+"absoluteread.dll ")

DECLARE LONG ARDocumentGetSC IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data, Long size 
DECLARE LONG ARDocumentGetInt IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long @data
DECLARE LONG ARDocumentGetInvoiceeSC IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data, Long size 
DECLARE LONG ARDocumentGetInvoiceeInt IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long @data
DECLARE LONG ARDocumentGetCustomer IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data
DECLARE LONG ARDocumentGetCustomerSC IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data, Long size 

DECLARE LONG ARDocumentGetItem IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data
DECLARE LONG ARDocumentGetItemSC IN (m.gcini_path+"absoluteread.dll ")  Long typ, String @data, Long size 
DECLARE LONG ARDocumentGetItemInt IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long @data
DECLARE LONG ARDocumentGetItemDouble IN (m.gcini_path+"absoluteread.dll ")  Long typ, Double @data
*!*	DECLARE LONG ARDocumentGetItemDate IN (m.gcini_path+"absoluteread.dll ")  Long typ, Long @rok, Long @mesiac, long @den

DECLARE LONG ARDeviceGet IN (m.gcini_path+"absoluteread.dll ") Long typ, String @data

FUNCTION GetDevice
PARAMETERS id 
PRIVATE m.s
m.s=SPACE(128)
m.data=SPACE(128)
=ARDeviceGetSC(id, @s, 128)
RETURN ALLTRIM(STRTRAN(m.s,CHR(0),""))

FUNCTION GetDeviceInt
PARAMETERS id
PRIVATE m.i
m.i=0
m.data=0
=ARDeviceGetInt(id, @i)
RETURN m.i



PROCEDURE  SetDocument(hodnota , id )
=ARDocumentSet(id, m.hodnota)


FUNCTION GetDocument(id)
PRIVATE s
m.s=SPACE(250)
=ARDocumentGetSC(id, @s, 250)
RETURN ALLTRIM(STRTRAN(m.s,CHR(0),""))

FUNCTION SetDocumentInt(hodnota, id)
=ARDocumentSetInt(id, m.hodnota)
RETURN .t.

FUNCTION SetDocumentDouble(hodnota, id)
=ARDocumentSetDouble(id, m.hodnota)
RETURN .t.

FUNCTION GetDocumentInt(id)
PRIVATE m.i
m.i=000000000 
=ARDocumentGetInt(id,@i)
RETURN m.i

FUNCTION GetDocumentDouble(id)
PRIVATE m.d
m.d=0000000.0000
=ARDocumentGetInt(id, @d)
RETURN m.d

FUNCTION SetDocumentDate(hodnota, id)
PRIVATE rok, mesiac, den
m.rok = year(m.hodnota)
m.mesiac = month(m.hodnota)
m.den = day(m.hodnota)
= ARDocumentSetDate(id, m.rok, m.mesiac, m.den)
RETURN .t.


FUNCTION SetDocumentInvoicee(hodnota, id)
=ARDocumentSetInvoicee(id, m.hodnota)
RETURN .t.

FUNCTION GetDocumentInvoicee(id)
PRIVATE m.s
s=SPACE(250)
=ARDocumentGetInvoiceeSC(id, @s, 250)
RETURN ALLTRIM(STRTRAN(m.s,CHR(0),""))

FUNCTION SetDocumentInvoiceeInt(hodnota, id)
=ARDocumentSetInvoiceeInt(id, m.hodnota)
RETURN .t.


FUNCTION GetDocumentInvoiceeInt(id)
PRIVATE m.i
m.i=0000000000
=ARDocumentGetInvoiceeInt(id, @i)
RETURN m.i

FUNCTION SetDocumentCustomer(hodnota, id)
=ARDocumentSetCustomer(id, m.hodnota)
RETURN .t.


FUNCTION GetDocumentCustomer(id)
PRIVATE m.s
m.s=SPACE(250)
=ARDocumentGetCustomerSC(id, @s, 250)
RETURN ALLTRIM(STRTRAN(m.s,CHR(0),""))

FUNCTION SetDocumentItem(hodnota, id)
=ARDocumentSetItem(id, m.hodnota)
RETURN .t.


FUNCTION  GetDocumentItem(id)
PRIVATE m.s
m.s=SPACE(250)
=ARDocumentGetItemSC(id, @s, 250)
RETURN ALLTRIM(STRTRAN(m.s,CHR(0),""))

FUNCTION SetDocumentItemInt(hodnota, id)
=ARDocumentSetItemInt(id, m.hodnota)
RETURN .t.

FUNCTION GetDocumentItemInt(id)
PRIVATE m.i
m.i=00000000
=ARDocumentGetItemInt(id, @i)
RETURN m.i

*!*	FUNCTION GetDocumentItemDate(name, id)
*!*	PRIVATE m.rok, m.mesiac, m.den
*!*	m.rok=1
*!*	m.den=1
*!*	m.mesiac=1
*!*	=ARDocumentGetItemDate(id, @rok, @mesiac, @den)
*!*	RETURN CTOD(ALLTRIM(STR(m.den,2,0))+"."+ALLTRIM(STR(m.mesiac,2,0))+"."+ALLTRIM(STR(m.rok,4,0)))

FUNCTION SetDocumentItemDate(datum, id)
PRIVATE m.ret
m.ret=ARDocumentSetItemInt(id, YEAR(datum), MONTH(datum), DAY(datum))
RETURN m.ret

FUNCTION GetDocumentItemDouble(id)
PRIVATE m.d
m.d=0000000.0000
=ARDocumentGetItemDouble(id, @d)
RETURN m.d 

FUNCTION SetDocumentItemDouble(hodnota, id)
=ARDocumentSetItemDouble(id, m.hodnota)
RETURN .t.


FUNCTION GetItem(y) 
PRIVATE getitemx
TRY 
	=ARDocumentSetItemIndex(y)
	m.fdidEAN= GetDocumentItem(didEAN)
	m.fdidName= GetDocumentItem(didName)
	m.fdidLevel= GetDocumentItemInt(didLevel)
	m.fdidPrice= GetDocumentItemDouble(didPrice)
	m.fdidAmount=GetDocumentItemDouble(didAmount)
	m.fdidPacking=GetDocumentItemDouble(didPacking)
	m.fdidUnit=GetDocumentItemInt(didUnit)
	m.fdidWeight=GetDocumentItemDouble(didWeight)
	m.fdidVAT=GetDocumentItemDouble(didVAT)
	m.fdidDiscount=GetDocumentItemDouble(didDiscount)
	m.fdidSuperDiscount=GetDocumentItemDouble(didSuperDiscount)
*!*		m.fdidManufactureDate=GetDocumentItemDate(didManufactureDate)
*!*		m.fdidExpirationDate=GetDocumentItemDate(didExpirationDate)
	m.fdidComment=GetDocumentItem(didComment)
	GetItemx =.t.
CATCH 
	getitemx=.f.
ENDTRY 
RETURN getitemx


PROCEDURE Status
DO ar_ini 
IF ARDeviceOpen() <> 0 
	MESSAGEBOX("Neviem nájsť scanner.",16,"AR scanner status")
	RETURN 
ENDIF 
PRIVATE status
PRIVATE ddID, ddVATID, ddSSD, ddSED
ddID=0
ddVATID=1
ddSSD=2
ddSED=3
Status = ARDeviceGetStatus()
m.fddid=GetDevice(ddID )
m.fddvatid=GetDevice(ddVATID)
m.fddssd=GetDeviceInt(ddSSD) 
m.fddsed=GetDeviceInt(ddSED)
=ardeviceclose()
Function SetItem(y)
PRIVATE setitemx
TRY 
	=ARDocumentAddItem()
	=SetDocumentItem(doklad.serial_no, m.didean)
	=SetDocumentItem(doklad.nazev, m.didName)
	=SetDocumentItemDouble(MTON(doklad.cena), m.didPrice)
	=SetDocumentItemDouble(MTON(doklad.mnozstvi), m.didAmount)
	=SetDocumentItemDouble(1.0, m.didPacking)
	=SetDocumentItemDouble(0.0, m.didVAT)
	=SetDocumentItemDouble(0.0, m.didDiscount)
	=SetDocumentItemDouble(0.0, m.didSuperDiscount)
	=SetDocumentItem("", m.didComment)
	SetItemx = .t.
CATCH 
	SetItemx = .f.
ENDTRY
RETURN m.setitemx



FUNCTION CreateCode(meno)
=ARDocumentClear()
*!*	=ARSetDebug("m:\ardebug.txt")
=SetDocumentInt(4, ddType)
=SetDocument(m.fddnumber, ddNumber)
SELECT doklad
SUM mnozstvi*cena TO m.fddamount
GO TOP 
=SetDocumentDouble(MTON(m.fddamount), ddAmount)
=SetDocumentDate(IIF(EMPTY(m.fdddocumentdate),DATE(),m.fdddocumentdate), ddDocumentDate)
=SetDocumentDate(IIF(EMPTY(m.fddservicedate),DATE(),m.fddservicedate), ddServiceDate)
=SetDocumentDate(IIF(EMPTY(m.fddpaymentdue),DATE(),m.fddpaymentdue), ddPaymentDue)
=SetDocument(m.fddreference, ddReference)
=SetDocument(m.fddinvoicereference, ddInvoiceReference)
=SetDocument(m.fddcomment, ddComment)
=SetDocumentInvoicee(IIF(EMPTY(m.fdcdname),"dodavatel",m.fdcdname), dcdName)
=SetDocumentInvoicee(m.fdcdstreet, dcdStreet)
=SetDocumentInvoicee(m.fdcdcity, dcdcity)
=SetDocumentInvoicee(m.fdcdfax, DcdFax)
=SetDocumentInvoicee(m.fdcdemail, dcdEMail)
=SetDocumentInvoicee(m.fdcdbusinessid, dcdBusinessId)
=SetDocumentInvoicee(IIF(EMPTY(m.fdcdvatid),"ic dph dodavatela",m.fdcdvatid), dcdVatId)
=SetDocumentCustomer(m.hotel_name, dcdName)
=SetDocumentCustomer(m.hotel_naz1, dcdStreet)
=SetDocumentCustomer(m.hotel_ico, dcdBusinessId)
=SetDocumentCustomer(IIF(EMPTY(m.hot_icdph),"hotelove ic dph",m.hot_icdph), dcdVATId)
PRIVATE m.a
a = 0
SELECT doklad
SCAN ALL 
	=SetItem(a)
	a = a + 1
ENDSCAN 
=ARDocumentPrepare()
PRIVATE m.codenum
m.codenum=0
=ARDocumentGetCodeCount(@codenum)
=ARDocumentSaveCode(0, m.meno+".bmp", 2)
If codenum > 1 
	=ARDocumentSaveCode(1, m.meno+"2.bmp", 2)
Else
ENDIF 
=ARDocumentDone()
RETURN .t.





