Hello, days ago, i made a code that makes an analysis based on the inputs of units, Income, operating expenses, Selling and administrative expenses, debtors, and finally makes an output of utilities, income per unit, etc. And print them in a word doc.
import PySimpleGUI as Ps
from docxtpl import DocxTemplate
from pathlib import Path
Document_path = Path(__file__).parent / "Análisis_DelPeriodo_Template.docx"
DOC = DocxTemplate(Document_path)
layout = [
[Ps.Text("Intervalo de tiempo"), Ps.Input(key="TIEMPO")],
[Ps.Text("Unidades/Servicios vendidos"), Ps.Input(key="UNIDADES")],
[Ps.Text("Cuentas Por Cobrar"), Ps.Input(key= "PORCOBRAR")],
[Ps.Text("Ingresos"), Ps.Input(key= "INGRESOS")],
[Ps.Text("Gastos Operativos"), Ps.Input (key= "GASTOSOP")],
[Ps.Text("Gastos de Admin/Ventas"), Ps.Input(key= "GASTOSAV")],
[Ps.Button("Crear Análisis"),Ps.Exit()],
]
def Operaciones():
Ingresos = float(values["INGRESOS"])
Gastos_Op = float(values["GASTOSOP"])
Gastos_AV = float(values["GASTOSAV"])
Unidades = float(values["UNIDADES"])
GASTOS_TOTALES = round(Gastos_Op + Gastos_AV, 2)
UTILIDAD_OPERACIONES = round(Ingresos - Gastos_Op, 2)
UTILIDAD_TOTAL = round(Ingresos - GASTOS_TOTALES, 2)
MARGEN = round(UTILIDAD_TOTAL / Ingresos * 100, 2)
INGRESOS_XUNIDAD = round(Ingresos / Unidades, 2)
GASTOS_XUNIDAD = round(GASTOS_TOTALES / Unidades, 2)
UTILIDAD_XUNIDAD = round(UTILIDAD_TOTAL / Unidades)
values["GASTOS_TOTALES"] = GASTOS_TOTALES
values["UTILIDAD_OPERACIONES"] = UTILIDAD_OPERACIONES
values["UTILIDAD_TOTAL"] = UTILIDAD_TOTAL
values["MARGEN"] = MARGEN
values["INGRESOS_XUNIDAD"] = INGRESOS_XUNIDAD
values["GASTOS_XUNIDAD"] = GASTOS_XUNIDAD
values["UTILIDAD_XUNIDAD"] = UTILIDAD_XUNIDAD
window = Ps.Window("Análisis de Periodo", layout, element_justification= "right")
while True:
event, values = window.read()
if event == "Exit" or event == Ps.WIN_CLOSED:
break
if event == "Crear Análisis":
Operaciones()
DOC.render(values)
output_path = Path(__file__).parent / f"{values['TIEMPO']}-Análisis.docx"
DOC.save(output_path)
Ps.popup("Archivo Guardado", f"Tú archivo ha sido guardado aquí: {output_path}")
window.close()
Sorry parts of the code are in Spanish because, soy de México, And also i have like a month and a half since i started to learn python, so any recommendation i well receive, thanks for your time.