-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreporte.py
More file actions
39 lines (30 loc) · 1.13 KB
/
Copy pathreporte.py
File metadata and controls
39 lines (30 loc) · 1.13 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
import openpyxl
libro = openpyxl.load_workbook("ventas.xlsx")
hoja = libro.active
total_ventas = 0
mayor_venta = 0
mejor_cliente = ""
print("===========================")
print(" REPORTE DE VENTAS ")
print("===========================")
for fila in hoja.iter_rows(min_row=2, values_only=True):
nombre = fila[0]
producto = fila[1]
cantidad = fila[2]
precio = fila[3]
subtotal = cantidad * precio
total_ventas += subtotal
if subtotal > mayor_venta:
mayor_venta = subtotal
mejor_cliente = nombre
print(nombre + " | " + producto + " | $" + str(subtotal))
print("===========================")
print("Total ventas: $" + str(total_ventas))
print("Mejor cliente: " + mejor_cliente + " ($" + str(mayor_venta) + ")")
with open("reporte.txt", "w") as archivo:
archivo.write("===========================\n")
archivo.write(" REPORTE DE VENTAS \n")
archivo.write("===========================\n")
archivo.write("Total ventas: $" + str(total_ventas) + "\n")
archivo.write("Mejor cliente: " + mejor_cliente + " ($" + str(mayor_venta) + ")\n")
print("\nReporte guardado en reporte.txt")