-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInforme.py
More file actions
161 lines (143 loc) · 4.76 KB
/
Informe.py
File metadata and controls
161 lines (143 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
import os
import sqlite3
import locale
"""
# Accion que carga y registra las fuentes que va a usar los informes una vez generados
"""
pdfmetrics.registerFont(TTFont('MontserratTH', 'Montserrat-Thin.ttf'))
pdfmetrics.registerFont(TTFont('Montserrat', 'Montserrat-Regular.ttf'))
pdfmetrics.registerFont(TTFont('MontserratBL', 'Montserrat-Bold.ttf'))
pdfmetrics.registerFont(TTFont('MontserratAlt', 'MontserratAlternates-Regular.ttf'))
"""
# Accion que conecta con la BBDD nada mas abrir el programa
"""
try:
bbdd = 'dataBaseRestaurante'
conexion = sqlite3.connect(bbdd)
cur = conexion.cursor()
print('BASE DE DATOS CONECTADA')
except sqlite3.OperationalError as e:
print(e)
def cerrarConexion():
"""
# Accion que cierra la bbdd una vez cierra el programa
"""
try:
conexion.commit()
conexion.close()
print('cerrando base de datos')
except sqlite3.OperationalError as e:
print(e)
def cabecera(cser):
"""
# Accion dibuja la parte superior del informe
"""
try:
cser.setTitle('Informes')
cser.setAuthor('Alfonso Fernández Álvarez')
cser.setFont('Montserrat', 24)
cser.line(50, 820, 525, 820)
cser.line(50, 745, 525, 745)
cser.line(50, 700, 525, 700)
textnom = 'RealFooters Restaurant'
textdir = 'Calle Maxwell S/N- Vigo'
texttlfo = '555 55 55 55'
cser.drawCentredString(297.5, 795, textnom)
cser.setFont('MontserratTH', 11)
cser.drawCentredString(297.5, 775, textdir)
cser.drawCentredString(297.5, 755, texttlfo)
except:
print ('error cabecera')
def pie(cser):
"""
# Accion que dibuja la parte del pie de informe
"""
try:
cser.line(50, 100, 525, 100)
textgracias = "Gracias por su visita"
cser.drawCentredString(297.5, 50, textgracias)
except:
print('error pie')
def cliente(cser,dni):
"""
# Accion que dibuja la parte del cliente del informe
"""
Ayuda = ["DNI: ", "Apellidos: ", "Nombre: ", "Direccion: ", "Provincia: ", "Municipio: "]
cser.setFont('MontserratAlt', 11)
try:
cur.execute(
'select * from cliente where dni=?', (dni,))
listado = cur.fetchall()
conexion.commit()
x = 50
y = 590
for registro in listado:
for i in range(6):
y = y + 15
cser.drawString(x, y, Ayuda[i] +" "+ str(registro[i]))
except:
print('error cliente')
def factura(idfactura,dni):
"""
# Accion que dibuja las comandas de esa mesa así como su importe y su importe total
"""
try:
cser = canvas.Canvas( str(idfactura) + '.pdf', pagesize=A4)
cabecera(cser)
pie(cser)
cliente(cser,dni)
cur.execute('select c.idventa, s.servicio, c.cantidad, s.preciounidad from LineaFactura as c inner join servicio as s on s.IdServicio = c.IdServicio where c.idfactura = ?', (idfactura,))
listado = cur.fetchall()
conexion.commit()
cser.setFont('MontserratBL', 11)
textlistado = 'Factura'
textcliente = 'Cliente'
cser.drawString(255, 590, textlistado)
cser.drawString(255, 710, textcliente)
cser.line(50, 580, 525, 580)
cser.setFont('Montserrat', 11)
x = 50
y = 540
total = 0
for registro in listado:
for i in range(4):
if i <= 1:
cser.drawString(x, y, str(registro[i]))
x = x + 40
else:
x = x + 120
cser.drawString(x, y, str(registro[i]))
var1 = int(registro[2])
var2 = registro[3]
var2 = var2
var2 = round(float(var2), 2)
subtotal = var1*var2
total = total + subtotal
subtotal = locale.currency(subtotal)
x = x + 120
cser.drawString(x, y, str(subtotal))
y = y - 20
x = 50
y = y -20
cser.line(50, y, 525, y)
y = y -20
x = 400
cser.setFont('MontserratBL', 11)
cser.drawString(x, y, 'Total: ')
cser.setFont('Montserrat', 11)
x = 485
total = round(float(total), 2)
total = locale.currency(total)
cser.drawString(x,y,str(total))
cser.showPage()
cser.save()
dir = os.getcwd()
os.system('/usr/bin/xdg-open ' + dir + '/' + str(idfactura) + '.pdf')
except sqlite3.OperationalError as e:
print(e)
conexion.rollback()
print('error en factura')