1
|
|
|
from datetime import date, timedelta |
2
|
|
|
|
3
|
|
|
import PySimpleGUI as sg |
4
|
|
|
# noinspection PyUnresolvedReferences |
5
|
|
|
from satcfdi.transform.catalog import CATALOGS |
6
|
|
|
|
7
|
|
|
from .log_tools import * |
8
|
|
|
|
9
|
|
|
logging.basicConfig(level=logging.DEBUG) |
10
|
|
|
logger = LogAdapter(logging.getLogger()) |
11
|
|
|
|
12
|
|
|
FORMA_PAGO = CATALOGS['{http://www.sat.gob.mx/sitio_internet/cfd/catalogos}c_FormaPago'] |
13
|
|
|
TEXT_PADDING = ((5, 0), 3) |
14
|
|
|
RTEXT_PADDING = ((0, 0), 3) |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
def make_layout(): |
18
|
|
|
# LAYOUT |
19
|
|
|
button_column = [ |
20
|
|
|
sg.Button("Preparar Facturas", key="prepare_facturas"), |
21
|
|
|
sg.Text("Año-Mes:", pad=TEXT_PADDING), |
22
|
|
|
sg.Input(date.today().strftime('%Y-%m'), size=(8, 1), key="periodo", change_submits=True), |
23
|
|
|
sg.Text("De La:", pad=TEXT_PADDING), |
24
|
|
|
sg.Input("1", key="inicio", size=(4, 1), change_submits=True), |
25
|
|
|
sg.Text("Hasta:", pad=TEXT_PADDING), |
26
|
|
|
sg.Input("", key="final", size=(4, 1), change_submits=True), |
27
|
|
|
sg.Text(" ", pad=TEXT_PADDING), |
28
|
|
|
sg.Button("Exportar Excel", key="exportar_facturas"), |
29
|
|
|
] |
30
|
|
|
|
31
|
|
|
c_second = [ |
32
|
|
|
sg.Column( |
33
|
|
|
[ |
34
|
|
|
[ |
35
|
|
|
sg.Text("Factura:", pad=TEXT_PADDING), |
36
|
|
|
sg.Input("", size=(30, 1), key="factura_pagar", change_submits=True), |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
sg.Button("Status SAT", key="status_sat"), |
40
|
|
|
sg.Button("Descarga", key="descarga"), |
41
|
|
|
sg.Button("Pago PUE", key="pago_pue"), |
42
|
|
|
sg.Button("Ignorar PPD", key="ignorar_ppd"), |
43
|
|
|
sg.Button("Email Notificada", key="email_notificada"), |
44
|
|
|
] |
45
|
|
|
], |
46
|
|
|
pad=0 |
47
|
|
|
), |
48
|
|
|
sg.VSeparator(), |
49
|
|
|
sg.Column( |
50
|
|
|
[ |
51
|
|
|
[ |
52
|
|
|
sg.CalendarButton("FechaPago:", format='%Y-%m-%d', title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING), |
53
|
|
|
sg.Input("", size=(12, 1), key="fecha_pago", change_submits=True), |
54
|
|
|
sg.Text("FormaPago:", pad=TEXT_PADDING), |
55
|
|
|
sg.Combo([Code(k, v) for k, v in FORMA_PAGO.items()], default_value=Code("03", FORMA_PAGO["03"]), key="forma_pago", change_submits=True, size=(34, 1)) |
56
|
|
|
], |
57
|
|
|
[ |
58
|
|
|
sg.Button("Comprobante Pago", key="prepare_pago"), |
59
|
|
|
] |
60
|
|
|
], |
61
|
|
|
pad=0 |
62
|
|
|
) |
63
|
|
|
] |
64
|
|
|
|
65
|
|
|
button_column_third = [ |
66
|
|
|
sg.Button("Preparar Correos", key="prepare_correos"), |
67
|
|
|
sg.Button("Facturas Pendientes", key="facturas_pendientes"), |
68
|
|
|
sg.Checkbox("Ver Detallado", default=False, key="detallado"), |
69
|
|
|
sg.VSeparator(), |
70
|
|
|
sg.Button("Ajuste Anual", key="preparar_ajuste_anual"), |
71
|
|
|
sg.Text("Año-Mes:", pad=TEXT_PADDING), |
72
|
|
|
sg.Input((date.today() + timedelta(days=31)).strftime('%Y-%m'), size=(8, 1), key="anio_mes_ajuste"), |
73
|
|
|
sg.Text("Ajuste:", pad=TEXT_PADDING), |
74
|
|
|
sg.Input("", size=(6, 1), key="ajuste_porcentaje"), |
75
|
|
|
sg.Text("%", pad=RTEXT_PADDING), |
76
|
|
|
sg.VSeparator(), |
77
|
|
|
sg.Text("Recuperar:", pad=TEXT_PADDING), |
78
|
|
|
sg.Button("Emitidas", key="recuperar_emitidas"), |
79
|
|
|
sg.Button("Recibidas", key="recuperar_recibidas"), |
80
|
|
|
sg.Text("Dias:", pad=TEXT_PADDING), |
81
|
|
|
sg.Input("40", size=(4, 1), key="recuperar_dias"), |
82
|
|
|
] |
83
|
|
|
|
84
|
|
|
button_column_low = [ |
85
|
|
|
sg.Button("Validar Clientes", key="validate_clientes"), |
86
|
|
|
sg.Button("Crear Facturas", disabled=True, key="crear_facturas"), |
87
|
|
|
sg.Button("Enviar Correos", disabled=True, key="enviar_correos"), |
88
|
|
|
] |
89
|
|
|
|
90
|
|
|
# ----- Full layout ----- |
91
|
|
|
return [ |
92
|
|
|
button_column, |
93
|
|
|
[sg.HSeparator()], |
94
|
|
|
c_second, |
95
|
|
|
[sg.HSeparator()], |
96
|
|
|
button_column_third, |
97
|
|
|
[sg.Output(expand_x=True, expand_y=True, key="console")], |
98
|
|
|
button_column_low |
99
|
|
|
] |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
class InvoiceButtonManager: |
103
|
|
|
def __init__(self, button, detallado): |
104
|
|
|
self._cfdis = [] |
105
|
|
|
self.button = button |
106
|
|
|
self.detallado = detallado |
107
|
|
|
|
108
|
|
|
def set_invoices(self, invoices): |
109
|
|
|
self._cfdis = invoices |
110
|
|
|
for i, cfdi in enumerate(self._cfdis, start=1): |
111
|
|
|
log_item(f"FACTURA NUMERO: {i}") |
112
|
|
|
log_cfdi(cfdi, detailed=self.detallado.get()) |
113
|
|
|
|
114
|
|
|
self.style_button() |
115
|
|
|
|
116
|
|
|
def clear(self): |
117
|
|
|
cfdis = self._cfdis |
118
|
|
|
self._cfdis = [] |
119
|
|
|
self.style_button() |
120
|
|
|
return cfdis |
121
|
|
|
|
122
|
|
|
def style_button(self): |
123
|
|
|
self.button.update( |
124
|
|
|
disabled=len(self._cfdis) == 0 |
125
|
|
|
) |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
class EmailButtonManager: |
129
|
|
|
def __init__(self, button): |
130
|
|
|
self._emails = {} |
131
|
|
|
self.button = button |
132
|
|
|
|
133
|
|
|
def set_invoices(self, invoices): |
134
|
|
|
self._emails = invoices |
135
|
|
|
|
136
|
|
|
for i, (receptor, notify_invoices, facturas_pendientes) in enumerate(invoices, start=1): |
137
|
|
|
log_item(f"CORREO NUMERO: {i}") |
138
|
|
|
log_email(receptor, notify_invoices, facturas_pendientes) |
139
|
|
|
|
140
|
|
|
self.style_button() |
141
|
|
|
|
142
|
|
|
def clear(self): |
143
|
|
|
emails = self._emails |
144
|
|
|
self._emails = {} |
145
|
|
|
self.style_button() |
146
|
|
|
return emails |
147
|
|
|
|
148
|
|
|
def style_button(self): |
149
|
|
|
self.button.update( |
150
|
|
|
disabled=len(self._emails) == 0 |
151
|
|
|
) |
152
|
|
|
|
153
|
|
|
|