forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel_facturation.py
371 lines (331 loc) · 18.6 KB
/
panel_facturation.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
# -*- coding: utf-8 -*-
## This file is part of Gertrude.
##
## Gertrude is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Gertrude is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gertrude; if not, see <http://www.gnu.org/licenses/>.
import __builtin__
import os.path, sys
import string, datetime
import wx, wx.lib.scrolledpanel, wx.html
import xml.dom.minidom
from constants import *
from functions import *
from facture import *
from ooffice import *
from controls import *
from doc_facture_mensuelle import FactureModifications
from doc_export_compta import ExportComptaModifications
from doc_attestation_paiement import AttestationModifications
from doc_appel_cotisations import AppelCotisationsModifications
from sqlobjects import Creche, Site, Inscrit, Correction, NumeroFacture
class CorrectionsTab(AutoTab):
def __init__(self, parent):
AutoTab.__init__(self, parent)
self.sizer = wx.BoxSizer(wx.VERTICAL)
# la selection du mois et le numéro de facture
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.monthchoice = wx.Choice(self)
date = GetFirstMonday()
first_date = datetime.date(year=date.year, month=date.month, day=1)
while date < last_date:
string = '%s %d' % (months[date.month - 1], date.year)
self.monthchoice.Append(string, date)
date = GetNextMonthStart(date)
self.monthchoice.SetStringSelection('%s %d' % (months[today.month - 1], today.year))
self.Bind(wx.EVT_CHOICE, self.EvtMonthChoice, self.monthchoice)
sizer.Add(self.monthchoice, 1, wx.EXPAND, 5)
self.numfacture = AutoNumericCtrl(self, None, 'valeur', precision=0)
sizer.AddMany([(wx.StaticText(self, -1, u'Premier numéro de facture :'), 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10), (self.numfacture, 0, wx.ALIGN_CENTER_VERTICAL)])
self.sizer.Add(sizer, 0, wx.EXPAND|wx.ALL, 5)
self.corrections_sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.corrections_sizer, 0, wx.ALL, 5)
self.SetSizer(self.sizer)
self.UpdateContents()
self.Layout()
def EvtMonthChoice(self, evt=None):
while len(self.corrections_sizer.GetChildren()):
sizer = self.corrections_sizer.GetItem(0)
sizer.DeleteWindows()
self.corrections_sizer.Detach(0)
date = self.monthchoice.GetClientData(self.monthchoice.GetSelection())
if not date in creche.numeros_facture:
creche.numeros_facture[date] = NumeroFacture(date)
self.numfacture.SetInstance(creche.numeros_facture[date])
for inscrit in creche.inscrits:
if inscrit.HasFacture(date): # TODO and date not in inscrit.factures_cloturees:
if not date in inscrit.corrections:
inscrit.corrections[date] = Correction(inscrit, date)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(wx.StaticText(self, -1, GetPrenomNom(inscrit), size=(200, -1)), 0, wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 15)
sizer.AddMany([(wx.StaticText(self, -1, u'Libellé :'), 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10), AutoTextCtrl(self, inscrit.corrections[date], 'libelle')])
sizer.AddMany([(wx.StaticText(self, -1, 'Valeur :'), 0, wx.LEFT|wx.RIGHT|wx.ALIGN_CENTER_VERTICAL, 10), AutoNumericCtrl(self, inscrit.corrections[date], 'valeur', precision=2)])
self.corrections_sizer.Add(sizer)
AutoTab.UpdateContents(self)
self.sizer.FitInside(self)
def UpdateContents(self):
self.EvtMonthChoice()
class FacturationTab(AutoTab):
def __init__(self, parent):
AutoTab.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.inscrits_choice = {}
# Les appels de cotisations
box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Edition des appels de cotisation'), wx.HORIZONTAL)
self.appels_monthchoice = wx.Choice(self)
date = GetFirstMonday()
first_date = datetime.date(year=date.year, month=date.month, day=1)
while date < last_date:
string = '%s %d' % (months[date.month - 1], date.year)
self.appels_monthchoice.Append(string, date)
date = GetNextMonthStart(date)
self.appels_monthchoice.SetStringSelection('%s %d' % (months[today.month - 1], today.year))
button = wx.Button(self, -1, u'Génération')
self.Bind(wx.EVT_BUTTON, self.EvtGenerationAppelCotisations, button)
box_sizer.AddMany([(self.appels_monthchoice, 1, wx.ALL|wx.EXPAND, 5), (button, 0, wx.ALL, 5)])
sizer.Add(box_sizer, 0, wx.EXPAND|wx.BOTTOM, 10)
# Les factures
box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, u'Clôture et édition des factures'), wx.HORIZONTAL)
self.inscrits_choice["factures"] = wx.Choice(self)
self.factures_monthchoice = wx.Choice(self)
self.Bind(wx.EVT_CHOICE, self.EvtFacturesInscritChoice, self.inscrits_choice["factures"])
self.Bind(wx.EVT_CHOICE, self.EvtFacturesMonthChoice, self.factures_monthchoice)
self.cloture_button = wx.Button(self, -1, u'Clôture')
self.Bind(wx.EVT_BUTTON, self.EvtClotureFacture, self.cloture_button)
button2 = wx.Button(self, -1, u'Génération')
self.Bind(wx.EVT_BUTTON, self.EvtGenerationFacture, button2)
box_sizer.AddMany([(self.inscrits_choice["factures"], 1, wx.ALL|wx.EXPAND, 5), (self.factures_monthchoice, 1, wx.ALL|wx.EXPAND, 5), (self.cloture_button, 0, wx.ALL, 5), (button2, 0, wx.ALL, 5)])
if IsTemplateFile("Export compta.txt"):
exportButton = wx.Button(self, -1, u'Export compta')
self.Bind(wx.EVT_BUTTON, self.EvtExportCompta, exportButton)
box_sizer.Add(exportButton, 0, wx.ALL, 5)
if config.options & DECLOTURE:
self.decloture_button = wx.Button(self, -1, u'Dé-clôture')
self.Bind(wx.EVT_BUTTON, self.EvtDeclotureFacture, self.decloture_button)
box_sizer.Add(self.decloture_button, 0, wx.ALL, 5)
sizer.Add(box_sizer, 0, wx.EXPAND|wx.BOTTOM, 10)
# Les attestations de paiement
box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Edition des attestations de paiement'), wx.HORIZONTAL)
self.inscrits_choice["recus"] = wx.Choice(self)
self.recus_periodechoice = wx.Choice(self)
self.recus_endchoice = wx.Choice(self)
self.recus_endchoice.Disable()
self.Bind(wx.EVT_CHOICE, self.EvtRecusInscritChoice, self.inscrits_choice["recus"])
self.Bind(wx.EVT_CHOICE, self.EvtRecusPeriodeChoice, self.recus_periodechoice)
button = wx.Button(self, -1, u'Génération')
self.Bind(wx.EVT_BUTTON, self.EvtGenerationRecu, button)
box_sizer.AddMany([(self.inscrits_choice["recus"], 1, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5),
(self.recus_periodechoice, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5),
(wx.StaticText(self, -1, '-'), 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5),
(self.recus_endchoice, 0, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5),
(button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)])
sizer.Add(box_sizer, 0, wx.EXPAND|wx.BOTTOM, 10)
self.SetSizer(sizer)
self.UpdateContents()
self.Layout()
def EvtFacturesInscritChoice(self, evt):
selection = self.factures_monthchoice.GetStringSelection()
self.factures_monthchoice.Clear()
inscrit = self.inscrits_choice["factures"].GetClientData(self.inscrits_choice["factures"].GetSelection())
date = GetFirstMonday()
while date <= datetime.date.today():
if IsFacture(date) and (not isinstance(inscrit, Inscrit) or inscrit.HasFacture(date)):
self.factures_monthchoice.Append('%s %d' % (months[date.month - 1], date.year), date)
date = GetNextMonthStart(date)
self.factures_monthchoice.SetSelection(self.factures_monthchoice.GetCount()-1)
self.EvtFacturesMonthChoice()
def EvtFacturesMonthChoice(self, evt=None):
inscrits, periode = self.__GetFactureSelection()
for inscrit in inscrits:
if inscrit.HasFacture(periode) and periode not in inscrit.factures_cloturees:
self.cloture_button.Enable()
break
else:
self.cloture_button.Disable()
def EvtRecusInscritChoice(self, evt):
self.recus_periodechoice.Clear()
need_separator = False
inscrit = self.inscrits_choice["recus"].GetClientData(self.inscrits_choice["recus"].GetSelection())
if isinstance(inscrit, Inscrit):
for year in range(today.year-10, today.year):
if inscrit.GetInscriptions(datetime.date(year, 1, 1), datetime.date(year, 12, 31)):
need_separator = True
self.recus_periodechoice.Append(u"Année %d" % year, (datetime.date(year, 1, 1), datetime.date(year, 12, 31)))
if inscrit.GetInscriptions(datetime.date(today.year, 1, 1), GetMonthEnd(today)):
need_separator = True
debut = 1
while not inscrit.GetInscriptions(datetime.date(today.year, debut, 1), GetMonthEnd(datetime.date(today.year, debut, 1))) and debut < today.month:
debut += 1
if debut == today.month:
self.recus_periodechoice.Append("%s %d" % (months[debut-1], today.year), (datetime.date(today.year, debut, 1), GetMonthEnd(datetime.date(today.year, debut, 1))))
else:
self.recus_periodechoice.Append(u"%s - %s %d" % (months[debut-1], months[today.month-1], today.year), (datetime.date(today.year, debut, 1), datetime.date(today.year, today.month, 1)))
need_separator = True
else:
self.recus_periodechoice.Append(u"Année %d" % (today.year-1), (datetime.date(today.year-1, 1, 1), datetime.date(today.year-1, 12, 31)))
if today.month == 1:
self.recus_periodechoice.Append("Janvier %d" % today.year, (datetime.date(today.year, 1, 1), datetime.date(today.year, 1, 31)))
else:
self.recus_periodechoice.Append(u"Janvier - %s %d" % (months[today.month-1], today.year), (datetime.date(today.year, 1, 1), datetime.date(today.year, today.month, 1)))
date = GetFirstMonday()
while date < today:
if not isinstance(inscrit, Inscrit) or inscrit.GetInscriptions(datetime.date(date.year, date.month, 1), GetMonthEnd(date)):
if need_separator:
self.recus_periodechoice.Append(20 * "-", None)
need_separator = False
self.recus_periodechoice.Append('%s %d' % (months[date.month - 1], date.year), (datetime.date(date.year, date.month, 1), GetMonthEnd(date)))
date = GetNextMonthStart(date)
self.recus_periodechoice.SetSelection(0)
self.EvtRecusPeriodeChoice(evt)
def EvtRecusPeriodeChoice(self, evt):
inscrit = self.inscrits_choice["recus"].GetClientData(self.inscrits_choice["recus"].GetSelection())
periode = self.recus_periodechoice.GetClientData(self.recus_periodechoice.GetSelection())
self.recus_endchoice.Clear()
if periode:
debut, fin = periode
if debut.month == fin.month and debut < today:
date = debut
while date < today:
if not isinstance(inscrit, Inscrit) or inscrit.GetInscriptions(datetime.date(date.year, date.month, 1), GetMonthEnd(date)):
self.recus_endchoice.Append('%s %d' % (months[date.month - 1], date.year), (datetime.date(date.year, date.month, 1), GetMonthEnd(date)))
date = GetNextMonthStart(date)
self.recus_endchoice.Enable()
self.recus_endchoice.SetSelection(0)
else:
self.recus_endchoice.Disable()
else:
self.recus_periodechoice.SetSelection(0)
self.EvtRecusPeriodeChoice(evt)
def UpdateContents(self):
for choice in self.inscrits_choice.values():
choice.Clear()
choice.Append('Tous les enfants', creche)
if len(creche.sites) > 1:
for site in creche.sites:
choice.Append('Enfants du site ' + site.nom.strip(), site)
inscrits = { }
autres = { }
for inscrit in creche.inscrits:
if inscrit.GetInscription(datetime.date.today()) != None:
inscrits[GetPrenomNom(inscrit)] = inscrit
else:
autres[GetPrenomNom(inscrit)] = inscrit
keys = inscrits.keys()
keys.sort()
for key in keys:
for choice in self.inscrits_choice.values():
choice.Append(key, inscrits[key])
if len(inscrits) > 0 and len(autres) > 0:
for choice in self.inscrits_choice.values():
choice.Append(20 * '-', None)
keys = autres.keys()
keys.sort()
for key in keys:
for choice in self.inscrits_choice.values():
choice.Append(key, autres[key])
for choice in self.inscrits_choice.values():
choice.SetSelection(0)
self.cloture_button.Show(creche.cloture_factures)
self.EvtFacturesInscritChoice(None)
self.EvtRecusInscritChoice(None)
self.Layout()
def EvtGenerationAppelCotisations(self, evt):
periode = self.appels_monthchoice.GetClientData(self.appels_monthchoice.GetSelection())
DocumentDialog(self, AppelCotisationsModifications(periode, options=NO_NOM)).ShowModal()
def __GetSelection(self, periode, data):
if isinstance(data, Creche):
inscrits = [inscrit for inscrit in creche.inscrits if inscrit.HasFacture(periode)]
elif isinstance(data, Site):
inscrits = [inscrit for inscrit in GetInscrits(GetMonthStart(periode), GetMonthEnd(periode), site=data) if inscrit.HasFacture(periode)]
else:
inscrits = [data]
return inscrits, periode
def __GetFactureSelection(self):
periode = self.factures_monthchoice.GetClientData(self.factures_monthchoice.GetSelection())
data = self.inscrits_choice["factures"].GetClientData(self.inscrits_choice["factures"].GetSelection())
if isinstance(data, Creche):
inscrits = [inscrit for inscrit in creche.inscrits if inscrit.HasFacture(periode)]
elif isinstance(data, Site):
inscrits = [inscrit for inscrit in GetInscrits(GetMonthStart(periode), GetMonthEnd(periode), site=data) if inscrit.HasFacture(periode)]
else:
inscrits = [data]
return inscrits, periode
def EvtClotureFacture(self, evt):
inscrits, periode = self.__GetFactureSelection()
errors = {}
for inscrit in inscrits:
try:
facture = Facture(inscrit, periode.year, periode.month)
facture.Cloture()
except CotisationException, e:
errors["%s %s" % (inscrit.prenom, inscrit.nom)] = e.errors
continue
if errors:
message = u"Erreurs lors de la clôture :\n"
for label in errors.keys():
message += '\n' + label + ' :\n '
message += '\n '.join(errors[label])
wx.MessageDialog(self, message, 'Message', wx.OK|wx.ICON_WARNING).ShowModal()
self.EvtFacturesMonthChoice()
def EvtDeclotureFacture(self, evt):
inscrits, periode = self.__GetFactureSelection()
errors = {}
for inscrit in inscrits:
try:
date = datetime.date(periode.year, periode.month, 1)
if date in inscrit.factures_cloturees:
facture = inscrit.factures_cloturees[date]
facture.Decloture()
except CotisationException, e:
errors["%s %s" % (inscrit.prenom, inscrit.nom)] = e.errors
continue
if errors:
message = u"Erreurs lors de la de-clôture :\n"
for label in errors.keys():
message += '\n' + label + ' :\n '
message += '\n '.join(errors[label])
wx.MessageDialog(self, message, 'Message', wx.OK|wx.ICON_WARNING).ShowModal()
self.EvtFacturesMonthChoice()
def EvtGenerationFacture(self, evt):
inscrits, periode = self.__GetFactureSelection()
if len(inscrits) > 0:
DocumentDialog(self, FactureModifications(inscrits, periode)).ShowModal()
else:
wx.MessageDialog(self, u'Aucune facture pour cette période', 'Message', wx.OK|wx.ICON_WARNING).ShowModal()
def EvtGenerationRecu(self, evt):
inscrits = self.inscrits_choice["recus"].GetClientData(self.inscrits_choice["recus"].GetSelection())
debut, fin = self.recus_periodechoice.GetClientData(self.recus_periodechoice.GetSelection())
if self.recus_endchoice.IsEnabled():
fin = self.recus_endchoice.GetClientData(self.recus_endchoice.GetSelection())[1]
DocumentDialog(self, AttestationModifications(inscrits, debut, fin)).ShowModal()
def EvtExportCompta(self, evt):
inscrits, periode = self.__GetFactureSelection()
if len(inscrits) > 0:
DocumentDialog(self, ExportComptaModifications(inscrits, periode)).ShowModal()
class FacturationNotebook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, style=wx.LB_DEFAULT)
self.AddPage(FacturationTab(self), "Edition")
self.AddPage(CorrectionsTab(self), u"Corrections")
def UpdateContents(self):
for page in range(self.GetPageCount()):
self.GetPage(page).UpdateContents()
class FacturationPanel(GPanel):
name = "Facturation"
bitmap = GetBitmapFile("facturation.png")
profil = PROFIL_TRESORIER
def __init__(self, parent):
GPanel.__init__(self, parent, u'Facturation')
self.notebook = FacturationNotebook(self)
self.sizer.Add(self.notebook, 1, wx.EXPAND)
def UpdateContents(self):
self.notebook.UpdateContents()