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
|
|
|
] |
44
|
|
|
], |
45
|
|
|
pad=0 |
46
|
|
|
), |
47
|
|
|
sg.VSeparator(), |
48
|
|
|
sg.Column( |
49
|
|
|
[ |
50
|
|
|
[ |
51
|
|
|
sg.CalendarButton("FechaPago:", format='%Y-%m-%d', title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING), |
52
|
|
|
sg.Input("", size=(12, 1), key="fecha_pago", change_submits=True), |
53
|
|
|
sg.Text("FormaPago:", pad=TEXT_PADDING), |
54
|
|
|
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)) |
55
|
|
|
], |
56
|
|
|
[ |
57
|
|
|
sg.Button("Comprobante Pago", key="prepare_pago"), |
58
|
|
|
] |
59
|
|
|
], |
60
|
|
|
pad=0 |
61
|
|
|
) |
62
|
|
|
] |
63
|
|
|
|
64
|
|
|
button_column_third = [ |
65
|
|
|
sg.Button("Preparar Correos", key="prepare_correos"), |
66
|
|
|
sg.Button("Facturas Pendientes", key="facturas_pendientes"), |
67
|
|
|
sg.Checkbox("Ver Detallado", default=False, key="detallado"), |
68
|
|
|
sg.VSeparator(), |
69
|
|
|
sg.Button("Ajuste Anual", key="preparar_ajuste_anual"), |
70
|
|
|
sg.Text("Año-Mes:", pad=TEXT_PADDING), |
71
|
|
|
sg.Input((date.today() + timedelta(days=31)).strftime('%Y-%m'), size=(8, 1), key="anio_mes_ajuste"), |
72
|
|
|
sg.Text("Ajuste:", pad=TEXT_PADDING), |
73
|
|
|
sg.Input("", size=(6, 1), key="ajuste_porcentaje"), |
74
|
|
|
sg.Text("%", pad=RTEXT_PADDING), |
75
|
|
|
sg.VSeparator(), |
76
|
|
|
sg.Text("Recuperar:", pad=TEXT_PADDING), |
77
|
|
|
sg.Button("Emitidas", key="recuperar_emitidas"), |
78
|
|
|
sg.Button("Recibidas", key="recuperar_recibidas"), |
79
|
|
|
sg.Text("Dias:", pad=TEXT_PADDING), |
80
|
|
|
sg.Input("40", size=(4, 1), key="recuperar_dias"), |
81
|
|
|
] |
82
|
|
|
|
83
|
|
|
button_column_low = [ |
84
|
|
|
sg.Button("Validar Clientes", key="validate_clientes"), |
85
|
|
|
sg.Button("Crear Facturas", disabled=True, key="crear_facturas"), |
86
|
|
|
sg.Button("Enviar Correos", disabled=True, key="enviar_correos"), |
87
|
|
|
sg.Button("Confirmar Pago", disabled=True, key="confirm_pago_button"), |
88
|
|
|
|
89
|
|
|
] |
90
|
|
|
|
91
|
|
|
# ----- Full layout ----- |
92
|
|
|
return [ |
93
|
|
|
button_column, |
94
|
|
|
[sg.HSeparator()], |
95
|
|
|
c_second, |
96
|
|
|
[sg.HSeparator()], |
97
|
|
|
button_column_third, |
98
|
|
|
[sg.Output(expand_x=True, expand_y=True, key="console")], |
99
|
|
|
button_column_low |
100
|
|
|
] |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
class InvoiceButtonManager: |
104
|
|
|
def __init__(self, button, detallado): |
105
|
|
|
self._cfdis = [] |
106
|
|
|
self.button = button |
107
|
|
|
self.detallado = detallado |
108
|
|
|
|
109
|
|
|
def set_invoices(self, invoices): |
110
|
|
|
self._cfdis = invoices |
111
|
|
|
for i, cfdi in enumerate(self._cfdis, start=1): |
112
|
|
|
log_item(f"FACTURA NUMERO: {i}") |
113
|
|
|
log_cfdi(cfdi, detailed=self.detallado.get()) |
114
|
|
|
|
115
|
|
|
self.style_button() |
116
|
|
|
|
117
|
|
|
def clear(self): |
118
|
|
|
cfdis = self._cfdis |
119
|
|
|
self._cfdis = [] |
120
|
|
|
self.style_button() |
121
|
|
|
return cfdis |
122
|
|
|
|
123
|
|
|
def style_button(self): |
124
|
|
|
self.button.update( |
125
|
|
|
disabled=len(self._cfdis) == 0 |
126
|
|
|
) |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
class EmailButtonManager: |
130
|
|
|
def __init__(self, button): |
131
|
|
|
self._emails = {} |
132
|
|
|
self.button = button |
133
|
|
|
|
134
|
|
|
def set_invoices(self, invoices): |
135
|
|
|
self._emails = invoices |
136
|
|
|
|
137
|
|
|
for i, (receptor, notify_invoices, facturas_pendientes) in enumerate(invoices, start=1): |
138
|
|
|
log_item(f"CORREO NUMERO: {i}") |
139
|
|
|
log_email(receptor, notify_invoices, facturas_pendientes) |
140
|
|
|
|
141
|
|
|
self.style_button() |
142
|
|
|
|
143
|
|
|
def clear(self): |
144
|
|
|
emails = self._emails |
145
|
|
|
self._emails = {} |
146
|
|
|
self.style_button() |
147
|
|
|
return emails |
148
|
|
|
|
149
|
|
|
def style_button(self): |
150
|
|
|
self.button.update( |
151
|
|
|
disabled=len(self._emails) == 0 |
152
|
|
|
) |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
class ConfirmPagoButtonManager: |
156
|
|
|
def __init__(self, button, detallado): |
157
|
|
|
self._cfdi = None |
158
|
|
|
self._status = None |
159
|
|
|
|
160
|
|
|
self.button = button |
161
|
|
|
self.detallado = detallado |
162
|
|
|
|
163
|
|
|
def set_confirm_pago(self, cfdi, status): |
164
|
|
|
self._cfdi = cfdi |
165
|
|
|
self._status = status |
166
|
|
|
|
167
|
|
|
if self._cfdi["MetodoPago"] != "PUE": |
168
|
|
|
log_item(f"PAGO PUE") |
169
|
|
|
log_cfdi(self._cfdi, detailed=self.detallado.get()) |
170
|
|
|
if status: |
171
|
|
|
logger.info("Factura Pagada") |
172
|
|
|
else: |
173
|
|
|
logger.info("Factura Pendiente de Pago") |
174
|
|
|
|
175
|
|
|
if self._cfdi["MetodoPago"] != "PPD": |
176
|
|
|
log_item(f"IGNORAR PPD") |
177
|
|
|
log_cfdi(self._cfdi, detailed=self.detallado.get()) |
178
|
|
|
if status: |
179
|
|
|
logger.info("Factura Ignorada") |
180
|
|
|
else: |
181
|
|
|
logger.info("Factura No Ignorada") |
182
|
|
|
|
183
|
|
|
self.style_button() |
184
|
|
|
|
185
|
|
|
def clear(self): |
186
|
|
|
confirm_pago = self._cfdi |
187
|
|
|
pagada = self._status |
188
|
|
|
self._cfdi = None |
189
|
|
|
self._status = None |
190
|
|
|
self.style_button() |
191
|
|
|
return confirm_pago, pagada |
192
|
|
|
|
193
|
|
|
def style_button(self): |
194
|
|
|
if self._cfdi: |
195
|
|
|
if self._cfdi["MetodoPago"] != "PUE": |
196
|
|
|
self.button.update( |
197
|
|
|
text="Cancelar Pago" if self._status else "Confirmar Pago", |
198
|
|
|
disabled=False |
199
|
|
|
) |
200
|
|
|
if self._cfdi["MetodoPago"] != "PPD": |
201
|
|
|
self.button.update( |
202
|
|
|
text="No Ignorar" if self._status else "Ignorar", |
203
|
|
|
disabled=False |
204
|
|
|
) |
205
|
|
|
|
206
|
|
|
self.button.update( |
207
|
|
|
disabled=True |
208
|
|
|
) |
209
|
|
|
|