Revision 2f2a7de9
Added by Mikaël Ates almost 12 years ago
calebasse/facturation/invoice_header.py | ||
---|---|---|
13 | 13 |
from invoice_template import InvoiceTemplate |
14 | 14 |
from ..pdftk import PdfTk |
15 | 15 |
from batches import build_batches |
16 |
from calebasse.utils import get_nir_control_key |
|
16 | 17 |
|
17 | 18 |
class Counter(object): |
18 | 19 |
def __init__(self, initial_value=0): |
... | ... | |
159 | 160 |
ctx['TOTAL'] = total1+total2 |
160 | 161 |
return [tpl.generate(ctx)] |
161 | 162 |
|
163 |
def render_not_cmpp_header(invoicing, counter): |
|
164 |
header_template='facturation/bordereau_not_cmpp_header.html' |
|
165 |
management_codes = dict() |
|
166 |
total_acts = 0 |
|
167 |
for invoice in invoicing.invoice_set.all(): |
|
168 |
total_acts += invoice.acts.count() |
|
169 |
if invoice.policy_holder_management_code: |
|
170 |
management_codes.setdefault(invoice.policy_holder_management_code, []).append(invoice) |
|
171 |
list_management_codes = list() |
|
172 |
for mc, invoices in management_codes.iteritems(): |
|
173 |
dic = dict() |
|
174 |
dic['code'] = mc |
|
175 |
dic['title'] = invoices[0].policy_holder_management_code_name |
|
176 |
dic['nb_files'] = len(invoices) |
|
177 |
nb_acts = 0 |
|
178 |
for invoice in invoices: |
|
179 |
nb_acts += invoice.acts.count() |
|
180 |
dic['nb_acts'] = nb_acts |
|
181 |
list_management_codes.append(dic) |
|
182 |
list_management_codes.sort(key=lambda dic: dic['code']) |
|
183 |
ctx = { |
|
184 |
'now': datetime.datetime.now(), |
|
185 |
'service': invoicing.service, |
|
186 |
'start_date': invoicing.start_date, |
|
187 |
'end_date': invoicing.end_date, |
|
188 |
'counter': counter, |
|
189 |
'list_management_codes': list_management_codes, |
|
190 |
'total_files': invoicing.invoice_set.count(), |
|
191 |
'total_acts': total_acts |
|
192 |
} |
|
193 |
prefix = '%s-invoicing-header-%s' % ( |
|
194 |
invoicing.service.slug, invoicing.id) |
|
195 |
return render_to_pdf_file( |
|
196 |
(header_template, ), ctx, prefix=prefix, delete=True) |
|
197 |
|
|
198 |
def render_not_cmpp_content(invoicing, counter): |
|
199 |
header_template='facturation/bordereau_not_cmpp_content.html' |
|
200 |
total_acts = 0 |
|
201 |
list_patients = list() |
|
202 |
for invoice in invoicing.invoice_set.all(): |
|
203 |
total_acts += invoice.acts.count() |
|
204 |
policy_holder = '' |
|
205 |
if invoice.policy_holder_last_name and invoice.policy_holder_first_name: |
|
206 |
policy_holder = invoice.policy_holder_last_name.upper() + ' ' + invoice.policy_holder_first_name |
|
207 |
nir = None |
|
208 |
if invoice.policy_holder_social_security_id: |
|
209 |
nir = invoice.policy_holder_social_security_id + ' ' + str(get_nir_control_key(invoice.policy_holder_social_security_id)) |
|
210 |
health_center = '' |
|
211 |
tp = '' |
|
212 |
cai = '' |
|
213 |
if invoice.policy_holder_healthcenter: |
|
214 |
health_center = invoice.policy_holder_healthcenter.name |
|
215 |
if invoice.policy_holder_healthcenter.large_regime: |
|
216 |
tp = invoice.policy_holder_healthcenter.large_regime.code |
|
217 |
cai = invoice.policy_holder_healthcenter.health_fund |
|
218 |
name = '' |
|
219 |
if invoice.patient_last_name and invoice.patient_first_name: |
|
220 |
name = invoice.patient_last_name.upper() + ' ' + invoice.patient_first_name |
|
221 |
list_patients.append({\ |
|
222 |
'code' : invoice.policy_holder_management_code, |
|
223 |
'policy_holder': policy_holder, |
|
224 |
'nir': nir, |
|
225 |
'health_center': health_center, |
|
226 |
'tp': tp, |
|
227 |
'cai': cai, |
|
228 |
'cen': invoice.policy_holder_other_health_center, |
|
229 |
'number': invoice.patient_id, |
|
230 |
'name': name, |
|
231 |
'birth_date': invoice.patient_birthdate, |
|
232 |
'inscription_date': invoice.patient_entry_date, |
|
233 |
'sortie_date': invoice.patient_exit_date, |
|
234 |
'nb_actes': invoice.acts.count()}) |
|
235 |
list_patients.sort(key=lambda dic: dic['code']) |
|
236 |
ctx = { |
|
237 |
'now': datetime.datetime.now(), |
|
238 |
'service': invoicing.service, |
|
239 |
'start_date': invoicing.start_date, |
|
240 |
'end_date': invoicing.end_date, |
|
241 |
'counter': counter, |
|
242 |
'total_files': invoicing.invoice_set.count(), |
|
243 |
'total_acts': total_acts, |
|
244 |
'patients': list_patients |
|
245 |
} |
|
246 |
prefix = '%s-invoicing-content-%s' % ( |
|
247 |
invoicing.service.slug, invoicing.id) |
|
248 |
return render_to_pdf_file( |
|
249 |
(header_template, ), ctx, prefix=prefix, delete=True) |
|
250 |
|
|
162 | 251 |
|
163 | 252 |
def render_invoicing(invoicing, delete=False, headers=True, invoices=True): |
164 | 253 |
service = invoicing.service |
165 | 254 |
now = datetime.datetime.now() |
166 |
batches_by_health_center = build_batches(invoicing) |
|
167 |
centers = sorted(batches_by_health_center.keys()) |
|
168 |
all_files = [] |
|
169 | 255 |
output_file = None |
170 |
counter = Counter(1)
|
|
256 |
all_files = []
|
|
171 | 257 |
try: |
172 |
for center in centers: |
|
173 |
if headers is not True and headers is not False and headers != center: |
|
174 |
continue |
|
175 |
for batch in batches_by_health_center[center]: |
|
176 |
files = batches_files(service, invoicing, center, |
|
177 |
[batch], delete=delete, |
|
178 |
headers=headers, invoices=invoices, counter=counter) |
|
179 |
all_files.extend(files) |
|
258 |
if service.name == 'CMPP': |
|
259 |
batches_by_health_center = build_batches(invoicing) |
|
260 |
centers = sorted(batches_by_health_center.keys()) |
|
261 |
counter = Counter(1) |
|
262 |
for center in centers: |
|
263 |
if headers is not True and headers is not False and headers != center: |
|
264 |
continue |
|
265 |
for batch in batches_by_health_center[center]: |
|
266 |
files = batches_files(service, invoicing, center, |
|
267 |
[batch], delete=delete, |
|
268 |
headers=headers, invoices=invoices, counter=counter) |
|
269 |
all_files.extend(files) |
|
270 |
else: |
|
271 |
counter = Counter(1) |
|
272 |
header = render_not_cmpp_header(invoicing, counter) |
|
273 |
all_files.append(header) |
|
274 |
content = render_not_cmpp_content(invoicing, counter) |
|
275 |
all_files.append(content) |
|
180 | 276 |
output_file = tempfile.NamedTemporaryFile(prefix='%s-invoicing-%s-' % |
181 | 277 |
(service.slug, invoicing.id), suffix='-%s.pdf' % now, delete=False) |
182 | 278 |
pdftk = PdfTk() |
... | ... | |
199 | 295 |
pass |
200 | 296 |
|
201 | 297 |
|
202 |
|
|
203 | 298 |
def batches_files(service, invoicing, health_center, batches, delete=False, |
204 | 299 |
headers=True, invoices=True, counter=None): |
205 | 300 |
files = [] |
calebasse/facturation/templates/facturation/bordereau_not_cmpp_content.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html> |
|
3 |
<head> |
|
4 |
<style> |
|
5 |
@page then { |
|
6 |
@frame { |
|
7 |
margin: 2cm 1cm; |
|
8 |
} |
|
9 |
@frame footer { |
|
10 |
-pdf-frame-content: footer; |
|
11 |
bottom: 0cm; |
|
12 |
height: 0.5cm; |
|
13 |
} |
|
14 |
} |
|
15 |
#content td { |
|
16 |
text-align: center; |
|
17 |
} |
|
18 |
</style> |
|
19 |
</head> |
|
20 |
<body> |
|
21 |
<div id="title">Bordereau des actes par patient</div> |
|
22 |
<div id="date"> |
|
23 |
<div> |
|
24 |
Édité le {{ now|date:"d/m/Y" }} à {{ now|time:"H:i:s" }} |
|
25 |
</div> |
|
26 |
</div> |
|
27 |
<div id="header-box"> |
|
28 |
<div id="payee-header"> |
|
29 |
<table style="padding: 3px; border: 0.5px solid black; height: 5cm;"> |
|
30 |
<tr style="padding-top: 3px; padding-bottom: 2px; line-height: 50%; background-color: #EEEEEE; margin-bottom: 3cm"><td> Établissement</td></tr> |
|
31 |
<tr><td style="height: 5cm; display: block;"> |
|
32 |
{% block payee %} |
|
33 |
{{ service.name }} de SAINT-ETIENNE</br> |
|
34 |
66/68, RUE MARENGO</br> |
|
35 |
42000 SAINT-ETIENNE</br> |
|
36 |
Tél.: 04 77 92 05 70</br> |
|
37 |
</br> |
|
38 |
Période du {{ start_date|date:"d/m/Y" }} au {{ end_date|date:"d/m/Y" }}</br> |
|
39 |
</br> |
|
40 |
Nombre de dossiers : {{ total_files }}</br> |
|
41 |
Nombre d'actes : {{ total_acts }}</br> |
|
42 |
</br> |
|
43 |
</br> |
|
44 |
</br> |
|
45 |
{% endblock %} |
|
46 |
</td></tr> |
|
47 |
</table> |
|
48 |
</div> |
|
49 |
<div id="content"> |
|
50 |
<div style="border: 0.5px solid black; padding-top: 2px; padding-bottom: 3px; line-height: 50%;"> |
|
51 |
<pdf:nexttemplate name="then"/> |
|
52 |
<table> |
|
53 |
<thead style="border: none;"> |
|
54 |
<tr class="batch-columns-header" style="background-color: #EEEEEE;"> |
|
55 |
<td>Code gestion</td> |
|
56 |
<td>Assuré</td> |
|
57 |
<td>NIR + Clé</td> |
|
58 |
<td>Nom caisse</td> |
|
59 |
<td>TP</td> |
|
60 |
<td>Num caisse</td> |
|
61 |
<td>Centre</td> |
|
62 |
<td>Numéro</td> |
|
63 |
<td>Enfant</td> |
|
64 |
<td>Naissance</td> |
|
65 |
<td>Inscription</td> |
|
66 |
<td>Sortie</td> |
|
67 |
<td>Actes</td> |
|
68 |
</tr> |
|
69 |
</thead> |
|
70 |
<tbody class="batch-content" style="border: none;"> |
|
71 |
{% for patient in patients %} |
|
72 |
<tr> |
|
73 |
<td>{% if patient.code %}{{ patient.code }}{% endif %}</td> |
|
74 |
<td>{% if patient.policy_holder %}{{ patient.policy_holder }}{% endif %}</td> |
|
75 |
<td>{% if patient.nir %}{{ patient.nir }}{% endif %}</td> |
|
76 |
<td>{% if patient.health_center %}{{ patient.health_center }}{% endif %}</td> |
|
77 |
<td>{% if patient.tp %}{{ patient.tp }}{% endif %}</td> |
|
78 |
<td>{% if patient.cai %}{{ patient.cai }}{% endif %}</td> |
|
79 |
<td>{% if patient.cen %}{{ patient.cen }}{% endif %}</td> |
|
80 |
<td>{% if patient.number %}{{ patient.number }}{% endif %}</td> |
|
81 |
<td>{% if patient.name %}{{ patient.name }}{% endif %}</td> |
|
82 |
<td>{% if patient.birth_date %}{{ patient.birth_date }}{% endif %}</td> |
|
83 |
<td>{% if patient.inscription_date %}{{ patient.inscription_date }}{% endif %}</td> |
|
84 |
<td>{% if patient.sortie_date %}{{ patient.sortie_date }}{% endif %}</td> |
|
85 |
<td>{% if patient.nb_actes %}{{ patient.nb_actes }}{% endif %}</td> |
|
86 |
</tr> |
|
87 |
{% endfor %} |
|
88 |
</tbody> |
|
89 |
</table> |
|
90 |
<div id="footer"> |
|
91 |
{% if counter %}{{ counter.increment }}.{% endif %}<pdf:pagenumber/> |
|
92 |
</div> |
|
93 |
</body> |
|
94 |
</html> |
calebasse/facturation/templates/facturation/bordereau_not_cmpp_header.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html> |
|
3 |
<head> |
|
4 |
<style> |
|
5 |
@page then { |
|
6 |
@frame { |
|
7 |
margin: 2cm 1cm; |
|
8 |
} |
|
9 |
@frame footer { |
|
10 |
-pdf-frame-content: footer; |
|
11 |
bottom: 0cm; |
|
12 |
height: 0.5cm; |
|
13 |
} |
|
14 |
} |
|
15 |
#content td { |
|
16 |
text-align: center; |
|
17 |
} |
|
18 |
</style> |
|
19 |
</head> |
|
20 |
<body> |
|
21 |
<div id="title">Bordereau des actes par code de gestion</div> |
|
22 |
<div id="date"> |
|
23 |
<div> |
|
24 |
Édité le {{ now|date:"d/m/Y" }} à {{ now|time:"H:i:s" }} |
|
25 |
</div> |
|
26 |
</div> |
|
27 |
<div id="header-box"> |
|
28 |
<div id="payee-header"> |
|
29 |
<table style="padding: 3px; border: 0.5px solid black; height: 5cm;"> |
|
30 |
<tr style="padding-top: 3px; padding-bottom: 2px; line-height: 50%; background-color: #EEEEEE; margin-bottom: 3cm"><td> Établissement</td></tr> |
|
31 |
<tr><td style="height: 5cm; display: block;"> |
|
32 |
{% block payee %} |
|
33 |
{{ service.name }} de SAINT-ETIENNE</br> |
|
34 |
66/68, RUE MARENGO</br> |
|
35 |
42000 SAINT-ETIENNE</br> |
|
36 |
Tél.: 04 77 92 05 70</br> |
|
37 |
</br> |
|
38 |
Période du {{ start_date|date:"d/m/Y" }} au {{ end_date|date:"d/m/Y" }}</br> |
|
39 |
</br> |
|
40 |
Nombre de dossiers : {{ total_files }}</br> |
|
41 |
Nombre d'actes : {{ total_acts }}</br> |
|
42 |
</br> |
|
43 |
</br> |
|
44 |
</br> |
|
45 |
{% endblock %} |
|
46 |
</td></tr> |
|
47 |
</table> |
|
48 |
</div> |
|
49 |
<div id="content"> |
|
50 |
<div style="border: 0.5px solid black; padding-top: 2px; padding-bottom: 3px; line-height: 50%;"> |
|
51 |
<pdf:nexttemplate name="then"/> |
|
52 |
<table> |
|
53 |
<thead style="border: none;"> |
|
54 |
<tr class="batch-columns-header" style="background-color: #EEEEEE;"> |
|
55 |
<td>Code gestion</td> |
|
56 |
<td>Libellé</td> |
|
57 |
<td>Nombre d'actes</td> |
|
58 |
<td>Nombre de dossiers</td> |
|
59 |
</tr> |
|
60 |
</thead> |
|
61 |
<tbody class="batch-content" style="border: none;"> |
|
62 |
{% for mc in list_management_codes %} |
|
63 |
<tr> |
|
64 |
<td>{{ mc.code }}</td> |
|
65 |
<td>{{ mc.title }}</td> |
|
66 |
<td>{{ mc.nb_acts }}</td> |
|
67 |
<td>{{ mc.nb_files }}</td> |
|
68 |
</tr> |
|
69 |
{% endfor %} |
|
70 |
</tbody> |
|
71 |
</table> |
|
72 |
<div id="footer"> |
|
73 |
{% if counter %}{{ counter.increment }}.{% endif %}<pdf:pagenumber/> |
|
74 |
</div> |
|
75 |
</body> |
|
76 |
</html> |
Also available in: Unified diff
facturation: Add rendering functions for not CMPP services.