forked from studio1247/gertrude
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacture.py
More file actions
563 lines (513 loc) · 36.2 KB
/
facture.py
File metadata and controls
563 lines (513 loc) · 36.2 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
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
# -*- 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 datetime
from constants import *
from cotisation import *
class FactureFinMois(object):
def CalculeDeduction(self, cotisation, heures):
deduction = cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees) - cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees-heures)
cotisation.heures_mois_ajustees -= heures
self.deduction += deduction
if cotisation.montant_heure_garde:
self.formule_deduction.append("%s * %.2f" % (GetHeureString(heures), cotisation.montant_heure_garde))
else:
self.formule_deduction.append("%s = %.2f" % (GetHeureString(heures), deduction))
def CalculeSupplement(self, cotisation, heures):
supplement = cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees+heures) - cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees)
cotisation.heures_mois_ajustees += heures
self.supplement += supplement
if cotisation.montant_heure_garde is not None:
self.formule_supplement.append(u"%s * %.2f" % (GetHeureString(heures), cotisation.montant_heure_garde))
else:
self.formule_supplement.append(u"%s = %.2f" % (GetHeureString(heures), supplement))
def __init__(self, inscrit, annee, mois, options=0):
self.inscrit = inscrit
self.site = None
self.annee = annee
self.mois = mois
self.debut_recap = datetime.date(annee, mois, 1)
self.fin_recap = GetMonthEnd(self.debut_recap)
self.date = self.fin_recap
try:
first_numero = int(creche.numeros_facture[self.debut_recap].valeur)
except:
first_numero = 0
self.numero = first_numero + creche.inscrits.index(inscrit)
self.options = options
self.cotisation_mensuelle = 0.0
self.report_cotisation_mensuelle = 0.0
self.heures_contrat = 0.0 # heures réellement contractualisées, tient compte des prorata
self.heures_maladie = 0.0
self.heures_facturees_par_mode = [0.0] * (MODE_MAX+1)
self.heures_contractualisees = 0.0
self.heures_contractualisees_realisees = 0.0
self.heures_realisees = 0.0
self.heures_realisees_non_facturees = 0.0
self.heures_facturees_non_realisees = 0.0
self.heures_previsionnelles = 0.0
self.total_contractualise = 0.0
self.total_realise = 0.0
self.total_realise_non_facture = 0.0
self.taux_effort = 0.0
self.supplement = 0.0
self.deduction = 0.0
self.formule_supplement = []
self.formule_deduction = []
self.jours_presence_non_facturee = {}
self.jours_presence_selon_contrat = {}
self.jours_supplementaires = {}
self.jours_absence_non_prevenue = {}
self.heures_supplementaires = 0.0
self.jours_maladie = []
self.jours_maladie_deduits = []
self.jours_vacances = []
self.jours_conges_non_factures = []
self.raison_deduction = set()
self.supplement_activites = 0.0
self.previsionnel = False
self.cloture = False
self.montant_heure_garde = 0.0
self.correction = 0.0
self.libelle_correction = ""
self.regularisation = 0.0
if self.debut_recap in inscrit.corrections:
try:
if inscrit.corrections[self.debut_recap].valeur:
self.correction = float(inscrit.corrections[self.debut_recap].valeur)
self.libelle_correction = inscrit.corrections[self.debut_recap].libelle
except:
print "Warning", GetPrenomNom(inscrit), ": correction invalide", inscrit.corrections[self.debut_recap].valeur
jours_ouvres = 0
cotisations_mensuelles = []
heures_hebdomadaires = {}
last_cotisation = None
if options & TRACES:
print '\nFacture de', inscrit.prenom, inscrit.nom, 'pour', months[mois-1], annee
if inscrit.HasFacture(self.debut_recap) and creche.cloture_factures and today > self.fin_recap:
fin = self.debut_recap - datetime.timedelta(1)
debut = GetMonthStart(fin)
if inscrit.GetInscriptions(debut, fin) and debut not in inscrit.factures_cloturees and IsFacture(debut) and self.debut_recap >= first_date:
error = u"La facture du mois " + GetDeMoisStr(debut.month-1) + " " + str(debut.year) + u" n'est pas clôturée"
raise CotisationException([error])
date = self.debut_recap
while date.month == mois:
if not date in creche.jours_fermeture and (creche.conges_inscription != GESTION_CONGES_INSCRIPTION_SIMPLE or not date in inscrit.jours_conges):
jours_ouvres += 1
inscription = inscrit.GetInscription(date)
if inscription:
self.site = inscription.site
inscritState = inscrit.GetState(date)
# print date, str(inscritState)
state, heures_reference, heures_realisees, heures_facturees = inscritState.state, inscritState.heures_contractualisees, inscritState.heures_realisees, inscritState.heures_facturees
heures_facturees_non_realisees = 0.0
heures_realisees_non_facturees = inscrit.GetTotalActivitesPresenceNonFacturee(date)
heures_supplementaires_facturees = (heures_facturees - heures_reference)
if heures_realisees_non_facturees > heures_reference:
heures_supplementaires_facturees -= heures_realisees_non_facturees - heures_reference
if last_cotisation and last_cotisation.Include(date):
cotisation = last_cotisation
cotisation.jours_ouvres += 1
cotisation.heures_reference += heures_reference
else:
cotisation = Cotisation(inscrit, date, options=NO_ADDRESS|self.options)
cotisation.jours_ouvres = 1
cotisation.heures_mois_ajustees = cotisation.heures_mois
cotisation.heures_reference = heures_reference
cotisation.heures_realisees = 0.0
cotisation.heures_realisees_non_facturees = 0.0
cotisation.heures_facturees_non_realisees = 0.0
cotisation.nombre_jours_maladie_deduits = 0
cotisation.heures_maladie = 0.0
cotisation.heures_contractualisees = 0.0
cotisation.heures_supplementaires = 0.0
cotisations_mensuelles.append(cotisation)
last_cotisation = cotisation
self.taux_effort = cotisation.taux_effort
self.montant_heure_garde = cotisation.montant_heure_garde
if options & TRACES: print u" cotisation mensuelle à partir de %s" % date, cotisation.cotisation_mensuelle
if (cotisation.mode_inscription, cotisation.heures_semaine) in heures_hebdomadaires:
heures_hebdomadaires[(cotisation.mode_inscription, cotisation.heures_semaine)] += 1
else:
heures_hebdomadaires[(cotisation.mode_inscription, cotisation.heures_semaine)] = 1
if state == HOPITAL:
if options & TRACES:
print "jour maladie hospitalisation", date
if heures_reference > 0:
self.jours_maladie.append(date)
self.jours_maladie_deduits.append(date)
cotisation.nombre_jours_maladie_deduits += 1
cotisation.heures_maladie += heures_reference
self.heures_facturees_par_mode[cotisation.mode_garde] -= heures_reference
if creche.mode_facturation == FACTURATION_FORFAIT_10H:
self.CalculeDeduction(cotisation, 10)
elif inscription.mode != MODE_FORFAIT_HORAIRE:
self.CalculeDeduction(cotisation, heures_reference)
self.raison_deduction.add('hospitalisation')
elif state == MALADE or state == MALADE_SANS_JUSTIFICATIF:
if options & TRACES:
print "jour maladie", date
if heures_reference > 0:
self.jours_maladie.append(date)
if state == MALADE and (creche.mode_facturation != FACTURATION_HORAIRES_REELS or inscription.mode == MODE_FORFAIT_HORAIRE):
# recherche du premier et du dernier jour
premier_jour_maladie = tmp = date
nombre_jours_ouvres_maladie = 0
while tmp > inscrit.inscriptions[0].debut:
tmp -= datetime.timedelta(1)
state = inscrit.GetState(tmp).state
if state == MALADE:
premier_jour_maladie = tmp
if not tmp in creche.jours_fermeture:
nombre_jours_ouvres_maladie += 1
elif state != ABSENT:
break
if creche.traitement_maladie == DEDUCTION_MALADIE_AVEC_CARENCE_JOURS_OUVRES:
nb_jours_maladie = nombre_jours_ouvres_maladie + 1
elif creche.traitement_maladie == DEDUCTION_MALADIE_AVEC_CARENCE_JOURS_CALENDAIRES:
nb_jours_maladie = (date - premier_jour_maladie).days + 1
else:
dernier_jour_maladie = tmp = date
while not inscrit.inscriptions[-1].fin or tmp < inscrit.inscriptions[-1].fin:
tmp += datetime.timedelta(1)
state = inscrit.GetState(tmp).state
if state == MALADE:
dernier_jour_maladie = tmp
else:
break
nb_jours_maladie = (dernier_jour_maladie - premier_jour_maladie).days + 1
if options & TRACES: print "nombre de jours : %d (minimum=%d)" % (nb_jours_maladie, creche.minimum_maladie)
if nb_jours_maladie > creche.minimum_maladie:
self.jours_maladie_deduits.append(date)
cotisation.nombre_jours_maladie_deduits += 1
cotisation.heures_maladie += heures_reference
if creche.mode_facturation == FACTURATION_FORFAIT_10H:
self.CalculeDeduction(cotisation, 10)
elif inscription.mode != MODE_FORFAIT_HORAIRE:
self.CalculeDeduction(cotisation, heures_reference)
self.raison_deduction.add(u"maladie > %dj consécutifs" % creche.minimum_maladie)
elif state == VACANCES:
if heures_reference > 0:
self.jours_vacances.append(date)
if creche.repartition==REPARTITION_SANS_MENSUALISATION and not inscription.IsNombreSemainesCongesAtteint(date):
self.jours_conges_non_factures.append(date)
self.heures_facturees_par_mode[cotisation.mode_garde] -= heures_reference
self.CalculeDeduction(cotisation, heures_reference)
self.raison_deduction.add(u"absence prévenue")
elif state == ABSENCE_NON_PREVENUE or state == ABSENCE_CONGE_SANS_PREAVIS:
heures_facturees_non_realisees = heures_reference
self.jours_absence_non_prevenue[date] = heures_reference
elif state > 0:
if state & PREVISIONNEL:
self.previsionnel = True
if heures_supplementaires_facturees > 0:
self.jours_supplementaires[date] = heures_realisees
else:
self.jours_presence_selon_contrat[date] = heures_realisees
if heures_supplementaires_facturees > 0:
if creche.mode_facturation == FACTURATION_FORFAIT_10H:
self.CalculeSupplement(cotisation, 10)
elif cotisation.inscription.mode != MODE_FORFAIT_HORAIRE:
cotisation.heures_supplementaires += heures_supplementaires_facturees
self.heures_supplementaires += heures_supplementaires_facturees
if creche.mode_facturation != FACTURATION_HORAIRES_REELS and (creche.facturation_periode_adaptation == PERIODE_ADAPTATION_FACTUREE_NORMALEMENT or not cotisation.inscription.IsInPeriodeAdaptation(date)):
self.CalculeSupplement(cotisation, heures_supplementaires_facturees)
if creche.tarification_activites == ACTIVITES_FACTUREES_JOURNEE or (creche.tarification_activites == ACTIVITES_FACTUREES_JOURNEE_PERIODE_ADAPTATION and inscription.IsInPeriodeAdaptation(date)):
activites = inscrit.GetExtraActivites(date)
for value in activites:
if value in creche.activites:
activite = creche.activites[value]
self.supplement_activites += activite.tarif
if heures_realisees_non_facturees > 0 and heures_realisees == heures_realisees_non_facturees:
self.jours_presence_non_facturee[date] = heures_realisees_non_facturees
self.total_realise_non_facture += cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees+heures_realisees_non_facturees) - cotisation.CalculeFraisGarde(cotisation.heures_mois_ajustees)
self.heures_realisees += heures_realisees
self.heures_realisees_non_facturees += heures_realisees_non_facturees
self.heures_facturees_non_realisees += heures_facturees_non_realisees
cotisation.heures_realisees += heures_realisees
cotisation.heures_realisees_non_facturees += heures_realisees_non_facturees
cotisation.heures_facturees_non_realisees += heures_facturees_non_realisees
if cotisation.inscription.mode != MODE_FORFAIT_HORAIRE:
cotisation.heures_contractualisees += heures_reference
self.heures_contractualisees += heures_reference
self.heures_contractualisees_realisees += min(heures_realisees, heures_reference)
if creche.mode_facturation == FACTURATION_HORAIRES_REELS or (creche.facturation_periode_adaptation == PERIODE_ADAPTATION_HORAIRES_REELS and inscription.IsInPeriodeAdaptation(date)) or (creche.mode_facturation == FACTURATION_PSU and cotisation.mode_garde == MODE_HALTE_GARDERIE):
self.heures_facturees_par_mode[cotisation.mode_garde] += heures_realisees - heures_realisees_non_facturees + heures_facturees_non_realisees
self.total_contractualise += cotisation.CalculeFraisGarde(heures_reference)
else:
self.heures_facturees_par_mode[cotisation.mode_garde] += heures_facturees - heures_realisees_non_facturees
self.total_realise += cotisation.CalculeFraisGarde(heures_realisees - heures_realisees_non_facturees)
date += datetime.timedelta(1)
if inscrit.HasFacture(self.debut_recap):
for cotisation in cotisations_mensuelles:
inscription = cotisation.inscription
self.heures_maladie += cotisation.heures_maladie
if creche.repartition == REPARTITION_SANS_MENSUALISATION:
self.cotisation_mensuelle += cotisation.heures_contractualisees * cotisation.montant_heure_garde
self.total_contractualise += cotisation.heures_contractualisees * cotisation.montant_heure_garde
elif creche.facturation_periode_adaptation == PERIODE_ADAPTATION_HORAIRES_REELS and inscription.IsInPeriodeAdaptation(cotisation.debut):
if inscription.mode == MODE_FORFAIT_HORAIRE:
self.heures_facturees_par_mode[cotisation.mode_garde] += cotisation.heures_realisees - cotisation.heures_realisees_non_facturees
report = cotisation.CalculeFraisGarde(cotisation.heures_realisees)
self.report_cotisation_mensuelle += report
cotisation.prorata_effectue = True
if options & TRACES:
print " cotisation periode adaptation :", report
elif inscription.mode == MODE_FORFAIT_HORAIRE:
self.cotisation_mensuelle += cotisation.cotisation_mensuelle * cotisation.jours_ouvres / jours_ouvres
cotisation.heures_contractualisees = inscription.forfait_heures_presence * cotisation.jours_ouvres / jours_ouvres
self.heures_contractualisees += cotisation.heures_contractualisees
self.total_contractualise += cotisation.heures_contractualisees * cotisation.montant_heure_garde
if cotisation.nombre_jours_maladie_deduits > 0:
# retire parce que "montant" non defini ... self.deduction += montant * cotisation.nombre_jours_maladie_deduits / cotisation.jours_ouvres
heures_contractualisees = cotisation.heures_contractualisees * (cotisation.jours_ouvres - cotisation.nombre_jours_maladie_deduits) / cotisation.jours_ouvres
else:
heures_contractualisees = cotisation.heures_contractualisees
if cotisation.heures_realisees - cotisation.heures_realisees_non_facturees > heures_contractualisees:
cotisation.heures_supplementaires = cotisation.heures_realisees - cotisation.heures_realisees_non_facturees - heures_contractualisees
self.heures_facturees_par_mode[cotisation.mode_garde] += cotisation.heures_realisees - cotisation.heures_realisees_non_facturees
self.heures_supplementaires += cotisation.heures_supplementaires
self.CalculeSupplement(cotisation, cotisation.heures_supplementaires)
else:
self.heures_facturees_par_mode[cotisation.mode_garde] += heures_contractualisees
elif creche.mode_facturation == FACTURATION_HORAIRES_REELS:
self.cotisation_mensuelle += cotisation.heures_contractualisees * cotisation.montant_heure_garde
self.report_cotisation_mensuelle += (cotisation.heures_realisees - cotisation.heures_realisees_non_facturees - cotisation.heures_contractualisees) * cotisation.montant_heure_garde
elif creche.mode_facturation == FACTURATION_PSU and cotisation.mode_garde == MODE_HALTE_GARDERIE:
if self.heures_contractualisees:
# On ne met dans la cotisation mensuelle que les heures realisees des heures du contrat
self.cotisation_mensuelle += (cotisation.heures_realisees - cotisation.heures_realisees_non_facturees + cotisation.heures_facturees_non_realisees - cotisation.heures_supplementaires) * cotisation.montant_heure_garde
# print '(', cotisation.heures_realisees, '-', cotisation.heures_realisees_non_facturees, '+', cotisation.heures_facturees_non_realisees, '-', cotisation.heures_supplementaires, ') *', cotisation.montant_heure_garde, '=', self.cotisation_mensuelle
elif creche.mode_facturation == FACTURATION_PSU and self.heures_contractualisees:
prorata_heures = cotisation.heures_mois * cotisation.jours_ouvres / jours_ouvres
if not cotisation.prorata_effectue:
prorata = cotisation.cotisation_mensuelle * cotisation.jours_ouvres / jours_ouvres
else:
prorata = cotisation.cotisation_mensuelle
self.cotisation_mensuelle += prorata
self.total_contractualise += prorata
self.heures_contrat += prorata_heures
else:
if self.heures_contractualisees:
if cotisation.heures_reference != self.heures_contractualisees:
prorata = cotisation.cotisation_mensuelle * cotisation.heures_reference / self.heures_contractualisees
prorata_heures = cotisation.heures_mois * cotisation.heures_reference / self.heures_contractualisees
cotisation.prorata_effectue = True
if options & TRACES:
print " prorata : %f * %f / %f = %f" % (cotisation.cotisation_mensuelle, cotisation.heures_reference, self.heures_contractualisees, prorata)
else:
prorata = cotisation.cotisation_mensuelle
prorata_heures = cotisation.heures_mois
else:
prorata = cotisation.cotisation_mensuelle
prorata_heures = cotisation.heures_mois
# ajoute FACTURATION_PSU bloc plus haut pour eviter 2 * la regle de 3
# avant il y avait ce commentaire: ne marche pas pour saint julien, mais c'est redemande (2 octobre 2012), normal pour le premier mois pour un enfant qui arrive mi-septembre
# avec le test suivant on devrait etre bon, parce que sinon on effectue la regle de 3 dans la cotisation + ici
if not cotisation.prorata_effectue:
prorata = (prorata * cotisation.jours_ouvres) / jours_ouvres
if (options & TRACES):
print " prorata : %f" % prorata
self.cotisation_mensuelle += prorata
self.total_contractualise += prorata
self.heures_contrat += prorata_heures
if creche.regularisation_fin_contrat:
if creche.gestion_depart_anticipe and inscription.depart and cotisation.Include(inscription.depart):
date = cotisation.debut
while date <= inscription.depart:
cotisation_regularisee = Cotisation(inscrit, date, options=NO_ADDRESS|self.options|DEPART_ANTICIPE)
regularisation_cotisation = cotisation_regularisee.cotisation_mensuelle - cotisation.cotisation_mensuelle
if (options & TRACES):
print u" régularisation cotisation : %f - %f = %f" % (cotisation_regularisee.cotisation_mensuelle, cotisation.cotisation_mensuelle, regularisation_cotisation)
self.regularisation += regularisation_cotisation
date = GetNextMonthStart(date)
jours_presence = inscription.GetNombreJoursPresenceSemaine()
if jours_presence and inscription.semaines_conges:
if (inscription.fin and inscription.fin >= self.debut_recap and inscription.fin <= self.fin_recap) or (creche.gestion_depart_anticipe and inscription.depart and inscription.depart >= self.debut_recap and inscription.depart <= self.fin_recap):
semaines_conges_non_pris = inscription.semaines_conges - float(inscription.GetNombreJoursCongesPoses()) / jours_presence
heures = cotisation.heures_semaine * semaines_conges_non_pris
regularisation_conges_non_pris = heures * cotisation.montant_heure_garde
if (options & TRACES):
print u" régularisation congés non pris : %dh * %f = %f" % (heures, cotisation.montant_heure_garde, regularisation_conges_non_pris)
self.regularisation += regularisation_conges_non_pris
if self.regularisation != 0:
self.deduction -= self.regularisation
self.raison_deduction.add(u"régularisation")
self.heures_facture = self.heures_contrat + self.heures_supplementaires - self.heures_maladie
self.heures_facturees = sum(self.heures_facturees_par_mode)
if creche.temps_facturation == FACTURATION_FIN_MOIS:
self.cotisation_mensuelle += self.report_cotisation_mensuelle
self.report_cotisation_mensuelle = 0.0
# print self.total_realise_non_facture
# self.cotisation_mensuelle -= self.total_realise_non_facture
# arrondi de tous les champs en euros
if IsContratFacture(self.debut_recap):
self.cotisation_mensuelle = round(self.cotisation_mensuelle, 2)
else:
self.cotisation_mensuelle = 0.0
if not self.montant_heure_garde:
self.heures_cotisation_mensuelle = 0
else:
self.heures_cotisation_mensuelle = self.cotisation_mensuelle / self.montant_heure_garde
self.report_cotisation_mensuelle = round(self.report_cotisation_mensuelle, 2)
self.supplement = round(self.supplement, 2)
self.formule_supplement = ' + '.join(self.formule_supplement)
self.supplement_activites = round(self.supplement_activites, 2)
self.deduction = round(self.deduction, 2)
self.formule_deduction = ' + '.join(self.formule_deduction)
if self.raison_deduction:
self.raison_deduction = "(" + ", ".join(self.raison_deduction) + ")"
else:
self.raison_deduction = ""
self.total_contractualise = round(self.total_contractualise, 2)
self.total_realise = round(self.total_realise, 2)
self.majoration_mensuelle = 0.0
for tarif in creche.tarifs_speciaux:
if tarif.unite == TARIF_SPECIAL_UNITE_EUROS and self.inscrit.tarifs & (1<<tarif.idx):
if tarif.type == TARIF_SPECIAL_REDUCTION:
self.majoration_mensuelle -= tarif.valeur
elif tarif.type == TARIF_SPECIAL_MAJORATION:
self.majoration_mensuelle += tarif.valeur
else:
self.cotisation_mensuelle = tarif.valeur
self.frais_inscription = 0.0
self.frais_inscription_reservataire = 0.0
for inscription in self.inscrit.inscriptions:
if inscription.frais_inscription and inscription.debut and inscription.debut >= self.debut_recap and inscription.debut <= self.fin_recap:
if inscription.reservataire:
self.frais_inscription_reservataire += inscription.frais_inscription
else:
self.frais_inscription += inscription.frais_inscription
self.total = self.cotisation_mensuelle + self.frais_inscription + self.supplement + self.supplement_activites - self.deduction + self.correction
self.total_facture = self.total + self.report_cotisation_mensuelle
if options & TRACES:
for var in ["heures_contractualisees", "heures_facturees", "heures_supplementaires", "heures_contractualisees_realisees", "heures_realisees_non_facturees", "cotisation_mensuelle", "supplement", "deduction", "total"]:
print "", var, ':', eval("self.%s" % var)
def Cloture(self, date=None):
if not self.cloture:
if date is None:
date = datetime.date(self.annee, self.mois, 1)
self.cloture = True
self.inscrit.factures_cloturees[date] = self
if sql_connection:
sql_connection.execute('INSERT INTO FACTURES (idx, inscrit, date, cotisation_mensuelle, total_contractualise, total_realise, total_facture, supplement_activites, supplement, deduction) VALUES (NULL,?,?,?,?,?,?,?,?,?)', (self.inscrit.idx, date, self.cotisation_mensuelle, self.total_contractualise, self.total_realise, self.total_facture, self.supplement_activites, self.supplement, self.deduction))
history.append(None)
def Restore(self):
return self
class FactureDebutMois(FactureFinMois):
def __init__(self, inscrit, annee, mois, options=0):
FactureFinMois.__init__(self, inscrit, annee, mois, options)
self.heures_previsionnelles = self.heures_realisees
if mois == 1:
self.facture_precedente = FactureFinMois(inscrit, annee-1, 12, options)
else:
self.facture_precedente = FactureFinMois(inscrit, annee, mois-1, options)
self.debut_recap = self.facture_precedente.debut_recap
self.fin_recap = self.facture_precedente.fin_recap
self.date = datetime.date(annee, mois, 1)
self.jours_presence_selon_contrat = self.facture_precedente.jours_presence_selon_contrat
self.jours_supplementaires = self.facture_precedente.jours_supplementaires
self.heures_supplementaires = self.facture_precedente.heures_supplementaires
self.jours_maladie = self.facture_precedente.jours_maladie
self.jours_maladie_deduits = self.facture_precedente.jours_maladie_deduits
self.jours_conges_non_factures = self.facture_precedente.jours_conges_non_factures
self.jours_vacances = self.facture_precedente.jours_vacances
self.raison_deduction = self.facture_precedente.raison_deduction
self.previsionnel |= self.facture_precedente.previsionnel
class FactureDebutMoisContrat(FactureDebutMois):
def __init__(self, inscrit, annee, mois, options=0):
FactureDebutMois.__init__(self, inscrit, annee, mois, options)
self.cotisation_mensuelle += self.facture_precedente.report_cotisation_mensuelle
self.supplement = self.facture_precedente.supplement
self.deduction = self.facture_precedente.deduction
self.supplement_activites = self.facture_precedente.supplement_activites
self.total = self.cotisation_mensuelle + self.frais_inscription + self.supplement + self.supplement_activites - self.deduction + self.correction
class FactureDebutMoisPrevisionnel(FactureDebutMois):
def __init__(self, inscrit, annee, mois, options=0):
FactureDebutMois.__init__(self, inscrit, annee, mois, options)
if today > self.fin_recap:
if inscrit.GetInscriptions(self.facture_precedente.debut_recap, self.facture_precedente.fin_recap):
if self.facture_precedente.fin_recap not in inscrit.factures_cloturees:
error = u"La facture du mois " + GetDeMoisStr(self.facture_precedente.fin_recap.month-1) + " " + str(self.facture_precedente.fin_recap.year) + u" n'est pas clôturée"
raise CotisationException([error])
facture_cloturee = inscrit.factures_cloturees[self.facture_precedente.fin_recap].Restore()
self.cotisation_mensuelle += self.facture_precedente.cotisation_mensuelle - facture_cloturee.cotisation_mensuelle
self.supplement += self.facture_precedente.supplement - facture_cloturee.supplement
self.deduction += self.facture_precedente.deduction - facture_cloturee.deduction
self.supplement_activites += self.facture_precedente.supplement_activites - facture_cloturee.supplement_activites
self.cotisation_mensuelle += self.report_cotisation_mensuelle
self.total = self.cotisation_mensuelle + self.frais_inscription + self.supplement + self.supplement_activites - self.deduction + self.correction
def Cloture(self, date=None):
if not self.cloture:
facture_previsionnelle = FactureFinMois(self.inscrit, self.annee, self.mois)
facture_previsionnelle.Cloture(facture_previsionnelle.fin_recap)
date = self.date
while date.month == self.mois:
if date in self.inscrit.journees:
journee = self.inscrit.journees[date]
journee.CloturePrevisionnel()
elif not (date in creche.jours_fermeture or date in self.inscrit.jours_conges):
journee = self.inscrit.GetJourneeReferenceCopy(date)
if journee:
self.inscrit.journees[date] = journee
journee.CloturePrevisionnel()
journee.Save()
date += datetime.timedelta(1)
FactureFinMois.Cloture(self)
def CreateFacture(inscrit, annee, mois, options=0):
if creche.temps_facturation == FACTURATION_FIN_MOIS:
return FactureFinMois(inscrit, annee, mois, options)
elif creche.temps_facturation == FACTURATION_DEBUT_MOIS_CONTRAT:
return FactureDebutMoisContrat(inscrit, annee, mois, options)
else:
return FactureDebutMoisPrevisionnel(inscrit, annee, mois, options)
class FactureCloturee:
def __init__(self, inscrit, date, cotisation_mensuelle, total_contractualise, total_realise, total_facture, supplement_activites, supplement, deduction):
self.inscrit = inscrit
self.date = date
self.cotisation_mensuelle = cotisation_mensuelle
self.total_contractualise = total_contractualise
self.total_realise = total_realise
self.total_facture = total_facture
self.supplement_activites = supplement_activites
self.supplement = supplement
self.deduction = deduction
self.facture = None
def Restore(self):
if not self.facture:
self.facture = CreateFacture(self.inscrit, self.date.year, self.date.month)
self.facture.cotisation_mensuelle = self.cotisation_mensuelle
self.facture.total_contractualise = self.total_contractualise
self.facture.total_realise = self.total_realise
self.facture.total_facture = self.total_facture
self.facture.supplement_activites = self.supplement_activites
self.facture.supplement = self.supplement
self.facture.deduction = self.deduction
self.facture.total = self.cotisation_mensuelle + self.supplement + self.supplement_activites - self.deduction + self.facture.correction
return self.facture
def Decloture(self):
self.cloture = True
del self.inscrit.factures_cloturees[self.date]
if sql_connection:
print u'Suppression clôture', self.inscrit.idx, self.date
sql_connection.execute('DELETE FROM FACTURES where inscrit=? AND date=?', (self.inscrit.idx, self.date))
# print "sql_connection.execute('DELETE FROM FACTURES where inscrit=%d AND date=%r)'" % (self.inscrit.idx, self.date)
history.append(None)
def Facture(inscrit, annee, mois, options=0):
date = datetime.date(annee, mois, 1)
if date in inscrit.factures_cloturees:
return inscrit.factures_cloturees[date].Restore()
else:
return CreateFacture(inscrit, annee, mois, options)