Project

General

Profile

Download (6.44 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / facturation / views.py @ 26c60057

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, len_patient_acts_paused,
42
                len_acts_paused) = \
43
            context['invoicing'].get_stats_or_validate()
44
            context['len_patients'] = len_patients
45
            context['len_invoices'] = len_invoices
46
            context['len_invoices_hors_pause'] = len_invoices_hors_pause
47
            context['len_invoices_pause'] = len_invoices - len_invoices_hors_pause
48
            context['len_acts_invoiced'] = len_acts_invoiced
49
            context['len_acts_invoiced_hors_pause'] = len_acts_invoiced_hors_pause
50
            context['len_acts_invoiced_pause'] = len_acts_invoiced - len_acts_invoiced_hors_pause
51
            context['len_patient_invoiced'] = len_patient_invoiced
52
            context['len_patient_invoiced_hors_pause'] = len_patient_invoiced_hors_pause
53
            context['len_patient_invoiced_pause'] = len_patient_invoiced - len_patient_invoiced_hors_pause
54
            context['len_acts_lost'] = len_acts_lost
55
            context['len_patient_with_lost_acts'] = len_patient_with_lost_acts
56
            context['patients_stats'] = patients_stats
57
            context['days_not_locked'] = days_not_locked
58
            context['len_patient_acts_paused'] = len_patient_acts_paused
59
            context['len_acts_paused'] = len_acts_paused
60
        elif self.service.name == 'CAMSP':
61
            (len_patient_pause, len_patient_hors_pause,
62
                len_acts_pause, len_acts_hors_pause, patients_stats,
63
                days_not_locked, len_patient_acts_paused,
64
                len_acts_paused) = context['invoicing'].get_stats_or_validate()
65
            if context['invoicing'].status == Invoicing.STATUS.closed and \
66
                    date.today() > context['invoicing'].end_date:
67
                context['show_validation_btn'] = True
68
            context['len_patient_pause'] = len_patient_pause
69
            context['len_patient_hors_pause'] = len_patient_hors_pause
70
            context['len_acts_pause'] = len_acts_pause
71
            context['len_acts_hors_pause'] = len_acts_hors_pause
72
            context['patients_stats'] = patients_stats
73
            context['days_not_locked'] = days_not_locked
74
            context['len_patient_acts_paused'] = len_patient_acts_paused
75
            context['len_acts_paused'] = len_acts_paused
76
        elif 'SESSAD' in self.service.name:
77
            (len_patient_pause, len_patient_hors_pause,
78
                len_acts_pause, len_acts_hors_pause,
79
                len_patient_missing_notif, len_acts_missing_notif,
80
                patients_stats, days_not_locked,
81
                len_patient_acts_paused, len_acts_paused) = \
82
                    context['invoicing'].get_stats_or_validate()
83
            if context['invoicing'].status == Invoicing.STATUS.closed and \
84
                    date.today() > context['invoicing'].end_date:
85
                context['show_validation_btn'] = True
86
            #XXX: Supressimer ligne suivante
87
            context['show_validation_btn'] = True
88
            context['len_patient_pause'] = len_patient_pause
89
            context['len_patient_hors_pause'] = len_patient_hors_pause
90
            context['len_acts_pause'] = len_acts_pause
91
            context['len_acts_hors_pause'] = len_acts_hors_pause
92
            context['len_patient_missing_notif'] = len_patient_missing_notif
93
            context['len_acts_missing_notif'] = len_acts_missing_notif
94
            context['patients_stats'] = patients_stats
95
            context['days_not_locked'] = days_not_locked
96
            context['len_patient_acts_paused'] = len_patient_acts_paused
97
            context['len_acts_paused'] = len_acts_paused
98
        return context
99

    
100

    
101
class CloseFacturationView(UpdateView):
102

    
103
    context_object_name = "invoicing"
104
    model = Invoicing
105
    template_name = 'facturation/close.html'
106

    
107
    def post(self, request, *args, **kwargs):
108
        pk = self.kwargs.get('pk', None)
109
        #TODO: grab the date
110
        invoicing = None
111
        if pk is not None:
112
            invoicing = Invoicing.objects.get(pk=pk, service=self.service)
113
        if not invoicing or self.service.name != 'CMPP' or \
114
                invoicing.status != Invoicing.STATUS.open:
115
            return HttpResponseRedirect('..')
116
        #TODO: give the closing date
117
        invoicing.close()
118
        return HttpResponseRedirect('..')
119

    
120
    def get_context_data(self, **kwargs):
121
        context = super(CloseFacturationView, self).get_context_data(**kwargs)
122
        today = date.today()
123
        context['date'] = date(day=today.day, month=today.month, year=today.year)
124
        return context
125

    
126
class ValidationFacturationView(UpdateView):
127

    
128
    context_object_name = "invoicing"
129
    model = Invoicing
130
    template_name = 'facturation/validation.html'
131

    
132
    def post(self, request, *args, **kwargs):
133
        pk = self.kwargs.get('pk', None)
134
        invoicing = None
135
        if pk is not None:
136
            invoicing = Invoicing.objects.get(pk=pk, service=self.service)
137
        if not invoicing or \
138
                invoicing.status != Invoicing.STATUS.closed:
139
            return HttpResponseRedirect('..')
140
        invoicing.get_stats_or_validate(commit=True)
141
        return HttpResponseRedirect('..')
142

    
143
    def get_context_data(self, **kwargs):
144
        context = super(ValidationFacturationView, self).get_context_data(**kwargs)
145
        return context
(8-8/8)