-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
557 lines (420 loc) · 18.2 KB
/
main.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
"""
Sales Outlet - using Tkinter for GUI
Punto de Venta - usando TKinter para la Interfaz Gráfica
Abraham Magaña Hernández & Gerardo Gabriel Mercado Guerra
This is the first time i've been working with GUI and i really wanted to use a database but i don't have too much time to learn that
im pretty new to this and i make this work using only code and large lists.
La primera vez que trabajo usando interfaces gráficas, realmente queria utilizar una base de datos para este programa, tal vez lo haga
en un futuro, pero por ahora funciona usando listas de los productos.
Abraham Magaña Hernández ©
"""
# Libraries (As i said I only use tkinter and datetime to put the function about the current hour and date to the .txt files output)
# Librerias (Como dije, use Tkinter y pues la libreria datime esta ahí para incluir la función de dar la hora y el día gactuales)
from tkinter import *
from tkinter import ttk
import datetime
import random
# Delete Variable it's so important, you need to put this on every function to clear labels and change it's value if the windows closes, super important!
# La Variable "Delete", esta variable es super importante ya que limpia o limita cada cuando se debe limpiar el programa, la encontrarás seguido
delete=bool(False)
gain=int(0)
# This Function clears any Labels
# Esta función limpia algunas Labels, o etiquetas, como le digas, usando la variable delete
def clear(function):
global delete
function.destroy()
delete=False
# This Function it's the login one, you need to log in before using the programa obviously
# Esta es la función de logeo, ingreso, como quieras decirle, necesitas logearte para entrar en el programa
def login():
global loginVerify, delete, today, user, gain
user=textBoxlogin.get()
password=textBoxpassword.get()
if user in ["Abraham","Thorns"] and password in ["123"]:
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
hour=date.strftime("%H")
file=open("ganancias.txt","w")
file.write(f"------------------------------------------------------\n")
file.write(f"Cafe DiFiore - Administracion de Facturaciones Reales\n")
file.write(f"------------------------------------------------------\n")
file=open("logs.txt","w")
file.write(f"-----------------------------------------\n")
file.write(f"Cafe DiFiore - Administracion de Usuarios \n")
file.write(f"-----------------------------------------\n")
if hour in ["8","9","10","11","12","13","14","15","16","17","18","19","20"]:
file=open("logs.txt","a")
file.write(f"{today} - {user} se ha logeado!\n")
if delete==False:
pass
else:
clear(loginVerify)
loginSuccess="¡Bienvenido de vuelta "+user+"!"
loginVerify=Label(window,text=loginSuccess,font=("Calibri",10),fg="green3")
loginVerify.pack()
delete=True
mainWindow()
else:
if delete==False:
pass
else:
clear(loginVerify)
loginSuccess=f"¡Ingreso Fuera de Hora de Servicio!"
loginVerify=Label(window,text=loginSuccess,font=("Calibri",10),fg="red")
loginVerify.pack()
delete=True
else:
if user in [""] and password in [""]:
if delete==False:
pass
else:
clear(loginVerify)
error="¡Necesita ingresar un usuario y contraseña!"
delete=True
elif user!="" and password!="":
if delete==False:
pass
else:
clear(loginVerify)
error="Usuario o Contraseña Incorrectos!"
delete=True
else:
if delete==False:
pass
else:
clear(loginVerify)
error="¡Falta ingresar algún tipo de dato!"
delete=True
loginVerify=Label(window,text=error,font=("Calibri",10),fg="red")
loginVerify.pack()
# This Function "Registers" the Product Input
# Esta función registra el producto que entre al programa
def register():
global mainWindow,IDTextBox,delete,productAdd,productTable,productPrice,gain
productType=IDTextBox.get()
productType=productType.lower()
productType=productType.title()
if productType in ["Roles","Capuchino","Moka","Flat White","Latte","Chai","Dirty Chai","Chocolate","Golden Milk", "Taro",
"Cajeta","Cacao","Ice Latte","Panque","Brownie","Americano G","Soda Italiana S"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=35
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Frape Chocolate","Frape Café","Frape Cafe","Frape Cajeta","Frape Vainilla","Frape Oreo","Frape Taro","Frape Mazapan",
"Frape Moka","Cold Brew","Soda Italiana","Tisana","Dirty Chai G"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=40
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Doble","Cortado","Cortado Doble","Refrescos","Leche Santa Clara","Galletas Chispas","Lungo"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=20
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Malteada Chocolate","Malteada Vainilla","Malteada Fresa","Brownie Con Nieve","Brownie Nieve"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=55
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Espreso","Galletas Ketto"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=15
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Americano","Lungo G"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=25
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Té Snapple","Te Snapple","Mini Panque"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=18
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Panini Jamon","Panini Jamón","Panini Jamón Pavo","Panini Jamon Pavo","Café 1/4","Cafe 1/4"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=65
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Panini Selva Negra"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=85
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Te Frio","Té Frio","Té","Te","Capuchino M","Moka M","Flat White M","Latte M","Chai M","Chocolate M"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=30
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Adiccion","Chocoqueso","Pastel Zanahoria","Muss Guayaba","Muss Frutos",
"Muss limon","Strudell","Corazon De Leon","Corazón De León","Gansito Ketto","Pinguino Ketto","Chescake Brownie",
"Chescake Fresa","Beso De Chocolate","Crunch De Menta","Domo Mazapan","Domo Mazapán","Trufa","Tarta De Frutas"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=60
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Golden Milk G","Frape Especial"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=45
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in ["Café 1kg","Cafe 1kg"]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" Agregado!',font=("Calibri",10),fg="green3")
productAdd.pack()
productPrice=265
gain=gain+productPrice
productTable.insert("",0,text=productType,values=(f"${productPrice}"))
date=datetime.datetime.now()
today=date.strftime("%d/%m/%Y %H:%M:%S")
file=open("logs.txt","a")
file.write(f"{today} - {user} ha facturado un {productType} a ${productPrice}\n")
delete=True
elif productType in [""]:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Ingrese algún producto!',font=("Calibri",10),fg="red2")
productAdd.pack()
delete=True
else:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡Producto "{productType}" NO EXISTE!',font=("Calibri",10),fg="red2")
productAdd.pack()
delete=True
# This function it's for the checkout window, tells the purchase value and confirms or declines it
# Esta funcion es para confirmar y rechazar la compra
def checkout():
global gain, mainWindow,checkout,delete,productAdd
if gain<=0:
if delete==False:
pass
else:
clear(productAdd)
productAdd=Label(mainWindow,text=f'¡NO HAY PRODUCTOS REGISTRADOS!',font=("Calibri",10),fg="red2")
productAdd.pack()
delete=True
else:
checkout=Tk()
checkout.resizable(0,0)
checkout.iconbitmap("titleIcon.ico")
checkout.geometry("295x215")
checkout.title("Café DiFiore - Recibo")
finalLabel=Label(checkout,text="Registro de Ingresos",font=("Helvetica",20,"bold"))
finalLabel.pack(pady=2)
finalLabel2=Label(checkout,text="Total a Pagar :",font=("Calibri",15))
finalLabel2.pack(pady=2)
checkoutLabel=Label(checkout,text=f"${gain}",font=("Calibri",20,"bold"),fg="green3")
checkoutLabel.pack(pady=8)
endButton=Button(checkout,text="Registrar",command=final)
endButton.pack(pady=2)
endButton2=Button(checkout,text="Cancelar",command=restart)
endButton2.pack(pady=2)
# This Function it's my main window, not the root one, that's called "window"
# Esta función es para la ventana pricipal donde se registran los productos.
def mainWindow():
global mainWindow,imageLogo,IDTextBox,delete,productTable
delete=False
window.destroy()
mainWindow=Tk()
mainWindow.resizable(0,0)
mainWindow.iconbitmap("titleIcon.ico")
mainWindow.geometry("430x520")
mainWindow.title("Café DiFiore - Administrador")
imageLogo=PhotoImage(file="images/logoImage.gif")
topLabel=Label(image=imageLogo)
topLabel.pack()
productTable=ttk.Treeview(mainWindow,columns=("#1",))
productTable.heading("#0",text=" Nombre",anchor=W)
productTable.heading("#1",text="Precio",anchor=W)
productTable.pack()
titleLabel=Label(mainWindow, text="Ingrese el Tipo de Producto :", font=("Calibri",15))
titleLabel.pack()
IDTextBox=Entry(mainWindow,font=("Calibri",12))
IDTextBox.pack(pady=2)
checkButton=Button(mainWindow,text="Aceptar",font=("Calibri",10),command=register)
checkButton.pack(pady=4)
checkOutButton=Button(mainWindow,text="Finalizar",font=("Calibri",10),command=checkout)
checkOutButton.pack(pady=4)
# This function write on a txt file when a purchase is successful
# Cuando una compra es confirmada, esta función lo registra en un archivo de texto
def final():
global checkout, gain
file=open("ganancias.txt","a")
file.write(f"{today} - {user} ha realizado una venta de ${gain}!\n")
gain=0
for i in productTable.get_children():
productTable.delete(i)
if delete==False:
pass
else:
clear(productAdd)
checkout.destroy()
# This function write on a txt file when a purchase is not successful
# Cuando una compra es rechazada o invalidada, esta función lo registra en un archivo de texto
def restart():
global checkout,gain
file=open("ganancias.txt","a")
file.write(f"{today} - {user} ha cancelado una venta de ${gain}!\n")
gain=0
for i in productTable.get_children():
productTable.delete(i)
if delete==False:
pass
else:
clear(productAdd)
checkout.destroy()
# Root Window - Before Login Function
# Ventana Raiz - Esto viene antes de la función de logeo.
window=Tk()
window.resizable(0,0)
window.iconbitmap("titleIcon.ico")
window.geometry("400x320")
window.title("Login - Café DiFiore")
emptyLabel=Label(window, text="\n",font=("Calibri",5))
emptyLabel.pack()
imageLogin=PhotoImage(file="images/loginImage.gif")
imageLabel=Label(window,image=imageLogin)
imageLabel.pack()
loginLabel=Label(window, text="Usuario :",font=(None, 15))
loginLabel.pack()
textBoxlogin=Entry(window,font=("Helvetica",12))
textBoxlogin.focus()
textBoxlogin.pack()
passwordLabel=Label(window, text="Contraseña :",font=(None, 15))
passwordLabel.pack()
textBoxpassword=Entry(window,show="*",font=("Helvetica",12))
textBoxpassword.pack()
emptyLabel2=Label(window, text="\n",font=("Calibri",2))
emptyLabel2.pack()
bottom1=Button(window, text="Login", command=login)
bottom1.pack()
# Exec
window.mainloop()