Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified pyfiscalprinter/__init__.py
100644 → 100755
Empty file.
1 change: 0 additions & 1 deletion pyfiscalprinter/command_repository.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def getCmd(self, model):

dictionary = {
'epson_ext': self.CMD_EPSON_EXT,
'epson': self.CMD_EPSON
}


Expand Down
Empty file modified pyfiscalprinter/driver.py
100644 → 100755
Empty file.
Empty file modified pyfiscalprinter/epson.py
100644 → 100755
Empty file.
207 changes: 141 additions & 66 deletions pyfiscalprinter/epson_ext.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import string
import types
import unicodedata
import re

import driver
from epson_ext_driver import EpsonFiscalExtDriver
from generic import PrinterInterface, PrinterException
from math import ceil
from math import floor
from command_repository import CommandRepository
from lxml import etree

class FiscalPrinterError(Exception):
pass
Expand Down Expand Up @@ -57,6 +59,7 @@ class EpsonExtPrinter(PrinterInterface):

command_repository = CommandRepository()
commands = {}
i = 0

models = ["tickeadoras", "epsonlx300+", "tm-220-af"]

Expand Down Expand Up @@ -221,25 +224,15 @@ def addItem(self, description, quantity, price, iva, discount, discountDescripti
quantityStr = str(int(quantity * 10000))
ivaStr = str(int(iva * 100))
codigo_frente_iva = "7"
if self._currentDocumentType != 'A':
ivaStr = '0000'
codigo_frente_iva = "1"
# enviar con el iva incluido
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
# nota de crédito?
priceUnitStr = str(int(floor(price * 10000)))
else:
priceUnitStr = str(int(round(price * 10000, 0)))
net = price / ((100.0 + iva) / 100.0)
if round_up:
net = self.float_round_up(net, 2)
# enviar sin el iva (factura A)
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
# nota de crédito?
priceUnitStr = str(int(floor(net * 10000)))
else:
net = price / ((100.0 + iva) / 100.0)
if round_up:
net = self.float_round_up(net, 2)
# enviar sin el iva (factura A)
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
# nota de crédito?
priceUnitStr = str(int(floor(net * 10000)))
else:
priceUnitStr = str(int(round(net * 10000, 0)))
priceUnitStr = str(int(round(net * 10000, 0)))

parameters = [
"",
Expand Down Expand Up @@ -283,14 +276,14 @@ def addItem(self, description, quantity, price, iva, discount, discountDescripti
return reply

def addPayment(self, description, payment):
paymentStr = str(int(payment * 10000))
paymentStr = str(int(payment * 100))
parameters = [
formatText(description)[:20],
"",
"",
"",
"",
"1",
"8",
paymentStr
]
status = self._sendCommand(self.commands['CMD_ADD_PAYMENT'][self._getCommandIndex()], parameters)
Expand All @@ -310,21 +303,11 @@ def addAdditional(self, description, amount, iva, negative=False):

if negative:
command = self.commands['CMD_PRINT_DISCOUNT']

if self._currentDocumentType != 'A':
ivaStr = '0000'
codigo_frente_iva = "1"
# enviar con el iva incluido
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
priceUnitStr = str(int(ceil(priceUnit * 10000)))
else:
priceUnitStr = str(int(round(priceUnit * 10000, 0)))
# enviar sin el iva (factura A)
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
priceUnitStr = str(int(ceil((priceUnit / ((100.0 + iva) / 100)) * 10000)))
else:
# enviar sin el iva (factura A)
if self._currentDocument == self.commands['CURRENT_DOC_CREDIT_TICKET']:
priceUnitStr = str(int(ceil((priceUnit / ((100.0 + iva) / 100)) * 10000)))
else:
priceUnitStr = str(int(round((priceUnit / ((100.0 + iva) / 100)) * 10000, 0)))
priceUnitStr = str(int(round((priceUnit / ((100.0 + iva) / 100)) * 10000, 0)))

parameters = [
"",
Expand Down Expand Up @@ -384,58 +367,150 @@ def subtotal(self, print_text=True, display=False, text="Subtotal"):
def getStatus(self,status, printer):
reply = self._sendCommand('020A|0000', [])
response = [
reply[2],
reply[1],
reply[0],
"0",
"0",
"0",
"0",
]
return status(response, printer)

def dailyClose(self, type):
tique_a = self._sendCommand('080A|0000', ["82"])
tique = self._sendCommand('080A|0000', ["83"])
tique_b = self._sendCommand('080A|0000', ["81"])
nota_credito_a = self._sendCommand('080A|0000', ["112"])
nota_credito_b = self._sendCommand('080A|0000', ["113"])
nota_credito_c = self._sendCommand('080A|0000', ["114"])
if type == 'Z':
reply = self._sendCommand(self.commands['CMD_DAILY_CLOSE'], [])
if type == 'X':
reply = self._sendCommand(self.commands['CMD_TELLER_EXIT'], [])

def recursiveDict(self, element):
tag = element.tag
if element.tag == 'conjuntoComprobantesFiscales':
self.i = self.i + 1
tag = element.tag + str(self.i)

return tag, dict(map(self.recursiveDict,element)) or element.text

def changeKeyToDictForDocumentId(self, key, dictionary):
new_key = dictionary[key]['codigoTipoComprobante']
dictionary[new_key] = dictionary.pop(key)

return dictionary

def extractInfoToXml(self, xml):
self.i = 0
text = re.findall(r'(<cierreZ>(.*)</cierreZ>)', xml)
try:
receipt_number = reply[2]
root = etree.XML(bytes(text[0][0].encode('utf8')))
except Exception as e:
receipt_number = "null"
print('Create xml error', e)

return self.recursiveDict(root)[1]

if receipt_number == "null":
def getDailyCloseData(self, receipt_number):
self._sendCommand('0813|0000', [str(receipt_number), str(receipt_number)])
reply_xml = self._sendCommand('0814|0000', [])
try:
xml = reply_xml[2]
info_close_daily = self.extractInfoToXml(xml + '</arrayCierresZ></comprobanteAuditoria></arrayComprobantesAuditoria></tns:auditoria')
emission_date = re.findall(r'(<fechaHoraEmisionCierreZ>(.*)</fechaHoraEmisionCierreZ>)', xml + '</arrayCierresZ></comprobanteAuditoria></arrayComprobantesAuditoria></tns:auditoria')
emission_date = emission_date[0][1].replace('T', ' ')
except Exception as e:
xml = 'empty'
self._sendCommand('0815|0000', [])

if xml == 'empty':
response = []
else:
receipt_number = reply[2]
for x in range(1, 7):
if 'conjuntoComprobantesFiscales' + str(x) in info_close_daily['arrayConjuntosComprobantesFiscales']:
info_close_daily['arrayConjuntosComprobantesFiscales'] = self.changeKeyToDictForDocumentId('conjuntoComprobantesFiscales' + str(x), info_close_daily['arrayConjuntosComprobantesFiscales'])
canceled_qty = info_close_daily['cantidadComprobantesCancelados']
sales_documents_a = 0
sales_documents_b = 0
sales_last_a = '0000000'
sales_last_b = '0000000'
sales_total_a = 0
sales_total_b = 0
sales_tax_a = 0.00
sales_tax_b = 0.00
credit_last_a = '00000000'
credit_documents_a = 0
credit_total_a = 0.00
credit_tax_a = 0.00
credit_last_b = '00000000'
credit_documents_b = 0
credit_total_b = 0.00
credit_tax_b = 0.00
sales_first_a = '0000000'
sales_first_b = '0000000'
credit_first_a = '00000000'
credit_first_b = '00000000'

if '081' in info_close_daily['arrayConjuntosComprobantesFiscales']:
sales_documents_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['cantidadComprobantes']
sales_last_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['ultimoNumeroComprobante']
sales_first_a = info_close_daily['arrayConjuntosComprobantesFiscales']['081']['primerNumeroComprobante']
sales_total_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['081']['importeTotalComprobantes'])
sales_tax_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['081']['arraySubtotalesIVA']['subtotalIVA']['importe'])
if '082' in info_close_daily['arrayConjuntosComprobantesFiscales']:
sales_documents_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['cantidadComprobantes']
sales_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['ultimoNumeroComprobante']
sales_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['082']['primerNumeroComprobante']
sales_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['082']['importeTotalComprobantes'])
try:
sales_tax_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['082']['arraySubtotalesIVA']['subtotalIVA']['importe'])
except:
sales_tax_b = 0.00
if '112' in info_close_daily['arrayConjuntosComprobantesFiscales']:
credit_documents_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['cantidadComprobantes']
credit_last_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['ultimoNumeroComprobante']
credit_first_a = info_close_daily['arrayConjuntosComprobantesFiscales']['112']['primerNumeroComprobante']
credit_total_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['112']['importeTotalComprobantes'])
credit_tax_a = float(info_close_daily['arrayConjuntosComprobantesFiscales']['112']['arraySubtotalesIVA']['subtotalIVA']['importe'])
if '113' in info_close_daily['arrayConjuntosComprobantesFiscales']:
credit_documents_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['cantidadComprobantes']
credit_last_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['ultimoNumeroComprobante']
credit_first_b = info_close_daily['arrayConjuntosComprobantesFiscales']['113']['primerNumeroComprobante']
credit_total_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['113']['importeTotalComprobantes'])
try:
credit_tax_b = float(info_close_daily['arrayConjuntosComprobantesFiscales']['113']['arraySubtotalesIVA']['subtotalIVA']['importe'])
except:
credit_tax_b = 0.00

response = [
str(receipt_number).zfill(8),
int(tique_a[9]) + int(tique[9]) + int(tique_b[9]) + int(nota_credito_a[9]) + int(
nota_credito_b[9]) + int(nota_credito_c[9]),
tique[8],
"0",
tique_a[8],
tique_b[8],
"0",
float(tique_a[10]) + float(tique_b[10]),
float(tique_a[11]) + float(tique_b[11]),
"0",
"0",
"0",
"0",
int(nota_credito_a[8]) + int(nota_credito_b[8]) + int(nota_credito_c[8]),
float(nota_credito_a[10]) + float(nota_credito_b[10]) + float(nota_credito_c[10]),
float(nota_credito_a[11]) + float(nota_credito_b[11]) + float(nota_credito_c[11]),
canceled_qty,
'0',
'0',
sales_documents_a,
sales_documents_b,
sales_last_b,
sales_total_a + sales_total_b,
sales_tax_a + sales_tax_b,
'0',
sales_last_a,
credit_last_a,
credit_last_b,
int(credit_documents_a) + int(credit_documents_b),
credit_total_a + credit_total_b,
credit_tax_a + credit_tax_b,
sales_first_a,
sales_first_b,
credit_first_a,
credit_first_b,
emission_date
]

return response

def dailyClose(self, type):
if type == 'Z':
reply = self._sendCommand(self.commands['CMD_DAILY_CLOSE'], [])
if type == 'X':
reply = self._sendCommand(self.commands['CMD_TELLER_EXIT'], [])

try:
return [
str(reply[2]).zfill(8)
]
except:
return []

def auditByDate(self, date_from, date_to, type):
reply = self._sendCommand(self.commands.CMD_AUDIT_BY_DATE, [date_from, date_to, type])
return reply[2:]
Expand Down
14 changes: 7 additions & 7 deletions pyfiscalprinter/epson_ext_driver.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def __init__(self, deviceFile, speed=9600):

def _parseReply( self, reply, skipStatusErrors ):
fields = reply.split('|')
printerStatus = fields[2]
fiscalStatus = fields[1]
if not skipStatusErrors:
self._parsePrinterStatus( printerStatus )
self._parseFiscalStatus( fiscalStatus )
printerStatus = fields[1]
fiscalStatus = fields[2]
#if not skipStatusErrors:
#self._parsePrinterStatus( printerStatus )
#self._parseFiscalStatus( fiscalStatus )
return fields[1:]

def sendCommand( self, commandNumber, fields, skipStatusErrors = False ):
Expand All @@ -33,7 +33,7 @@ def sendCommand( self, commandNumber, fields, skipStatusErrors = False ):

url = 'http://localhost:3000'
headers = {'Content-Type': 'text/plain'}

print('Comando: ', message)
ret = ''
while ret == '':
try:
Expand All @@ -44,6 +44,6 @@ def sendCommand( self, commandNumber, fields, skipStatusErrors = False ):
time.sleep(5)
print("Was a nice sleep, now let me continue...")
continue

print('Respuesta: ', ret.content)
return self._parseReply( ret.content, skipStatusErrors )

Empty file modified pyfiscalprinter/fiscal.ini
100644 → 100755
Empty file.
Empty file modified pyfiscalprinter/generic.py
100644 → 100755
Empty file.
Empty file modified pyfiscalprinter/hasar.py
100644 → 100755
Empty file.
Empty file modified pyfiscalprinter/service.py
100644 → 100755
Empty file.
Empty file modified pyfiscalprinter/test.py
100644 → 100755
Empty file.