1
|
# -*- coding: utf-8 -*-
|
2
|
|
3
|
from datetime import date
|
4
|
|
5
|
from django.http import HttpResponseRedirect
|
6
|
|
7
|
from calebasse.cbv import TemplateView, UpdateView
|
8
|
|
9
|
from models import Invoicing
|
10
|
|
11
|
|
12
|
class FacturationHomepageView(TemplateView):
|
13
|
|
14
|
template_name = 'facturation/index.html'
|
15
|
|
16
|
def get_context_data(self, **kwargs):
|
17
|
context = super(FacturationHomepageView, self).get_context_data(**kwargs)
|
18
|
current = Invoicing.objects.current_for_service(self.service)
|
19
|
last = Invoicing.objects.last_for_service(self.service)
|
20
|
context['current'] = current
|
21
|
context['last'] = last
|
22
|
return context
|
23
|
|
24
|
|
25
|
class FacturationDetailView(UpdateView):
|
26
|
|
27
|
context_object_name = "invoicing"
|
28
|
model = Invoicing
|
29
|
template_name = 'facturation/detail.html'
|
30
|
|
31
|
def post(self, request, *args, **kwargs):
|
32
|
return HttpResponseRedirect('/')
|
33
|
|
34
|
def get_context_data(self, **kwargs):
|
35
|
context = super(FacturationDetailView, self).get_context_data(**kwargs)
|
36
|
if self.service.name == 'CMPP':
|
37
|
(len_patients, len_invoices, len_invoices_hors_pause,
|
38
|
len_acts_invoiced, len_acts_invoiced_hors_pause,
|
39
|
len_patient_invoiced, len_patient_invoiced_hors_pause,
|
40
|
len_acts_lost, len_patient_with_lost_acts,
|
41
|
patients_stats, days_not_locked) = \
|
42
|
context['invoicing'].get_stats_or_validate()
|
43
|
context['len_patients'] = len_patients
|
44
|
context['len_invoices'] = len_invoices
|
45
|
context['len_invoices_hors_pause'] = len_invoices_hors_pause
|
46
|
context['len_invoices_pause'] = len_invoices - len_invoices_hors_pause
|
47
|
context['len_acts_invoiced'] = len_acts_invoiced
|
48
|
context['len_acts_invoiced_hors_pause'] = len_acts_invoiced_hors_pause
|
49
|
context['len_acts_invoiced_pause'] = len_acts_invoiced - len_acts_invoiced_hors_pause
|
50
|
context['len_patient_invoiced'] = len_patient_invoiced
|
51
|
context['len_patient_invoiced_hors_pause'] = len_patient_invoiced_hors_pause
|
52
|
context['len_patient_invoiced_pause'] = len_patient_invoiced - len_patient_invoiced_hors_pause
|
53
|
context['len_acts_lost'] = len_acts_lost
|
54
|
context['len_patient_with_lost_acts'] = len_patient_with_lost_acts
|
55
|
context['patients_stats'] = patients_stats
|
56
|
context['days_not_locked'] = days_not_locked
|
57
|
elif self.service.name == 'CAMSP':
|
58
|
context['invoicing'].get_stats_or_validate()
|
59
|
elif 'SESSAD' in self.service.name:
|
60
|
context['invoicing'].get_stats_or_validate()
|
61
|
return context
|
62
|
|
63
|
#TODO: Invoicing summary
|
64
|
# Missing function to generate bill from acts grouped
|
65
|
# Prepare stats
|
66
|
|
67
|
#TODO: Validate facturation
|
68
|
# generate bills
|
69
|
|
70
|
#TODO: Display the invoicing display
|
71
|
|
72
|
#TODO: Summary tab on module index
|
73
|
|
74
|
class CloseFacturationView(UpdateView):
|
75
|
|
76
|
context_object_name = "invoicing"
|
77
|
model = Invoicing
|
78
|
template_name = 'facturation/close.html'
|
79
|
|
80
|
def post(self, request, *args, **kwargs):
|
81
|
pk = self.kwargs.get('pk', None)
|
82
|
#TODO: grab the date
|
83
|
invoicing = None
|
84
|
if pk is not None:
|
85
|
invoicing = Invoicing.objects.get(pk=pk, service=self.service)
|
86
|
if not invoicing or self.service.name != 'CMPP' or \
|
87
|
invoicing.status != Invoicing.STATUS.open:
|
88
|
return HttpResponseRedirect('..')
|
89
|
#TODO: give the closing date
|
90
|
invoicing.close()
|
91
|
return HttpResponseRedirect('..')
|
92
|
|
93
|
def get_context_data(self, **kwargs):
|
94
|
context = super(CloseFacturationView, self).get_context_data(**kwargs)
|
95
|
today = date.today()
|
96
|
context['date'] = date(day=today.day, month=today.month, year=today.year)
|
97
|
return context
|
98
|
|
99
|
class ValidationFacturationView(UpdateView):
|
100
|
|
101
|
context_object_name = "invoicing"
|
102
|
model = Invoicing
|
103
|
template_name = 'facturation/validation.html'
|
104
|
|
105
|
def post(self, request, *args, **kwargs):
|
106
|
pk = self.kwargs.get('pk', None)
|
107
|
invoicing = None
|
108
|
if pk is not None:
|
109
|
invoicing = Invoicing.objects.get(pk=pk, service=self.service)
|
110
|
if not invoicing or self.service.name != 'CMPP' or \
|
111
|
invoicing.status != Invoicing.STATUS.closed:
|
112
|
return HttpResponseRedirect('..')
|
113
|
invoicing.get_stats_or_validate(commit=True)
|
114
|
return HttpResponseRedirect('..')
|
115
|
|
116
|
def get_context_data(self, **kwargs):
|
117
|
context = super(CloseFacturationView, self).get_context_data(**kwargs)
|
118
|
return context
|