Rapport Remunération
[auf_rh_dae.git] / project / rh / views.py
index 882ed6d..fde04ad 100644 (file)
@@ -10,6 +10,7 @@ from datamaster_modeles import models as ref
 from project.lib import get_employe_from_id
 
 from rh import models as rh
+from rh.lib import calc_remun
 
 # homes
 @login_required
@@ -134,3 +135,62 @@ def rapports_contrat(request):
     }
 
     return render_to_response('rh/rapports/contrats.html', c, RequestContext(request))
+
+
+def rapports_remuneration(request):
+
+    lookup_params = dict(request.GET.items())
+
+    for key, value in lookup_params.items():
+        if not isinstance(key, str):
+            # 'key' will be used as a keyword argument later, so Python
+            # requires it to be a string.
+            del lookup_params[key]
+            lookup_params[smart_str(key)] = value
+
+    employes = rh.Employe.objects.all()
+    employes = employes.filter(**lookup_params)
+
+    output = []
+
+    for employe in employes:
+        line = {}
+        output.append(line)
+
+        dossiers = employe.dossiers.all()
+
+        remun = {}
+        remun_sum_euro = 0
+
+        for dossier in dossiers:
+            this_remun, this_remun_sum, this_remun_sum_euro = calc_remun(dossier)
+
+            for item in this_remun:
+                if item not in remun:
+                    remun[item] = this_remun[item]
+                else:
+                    remun[item][0] += this_remun[item][0]
+                    remun[item][1] += this_remun[item][1]
+
+            remun_sum_euro += this_remun_sum_euro
+
+        line['remun_sum_euro'] = remun_sum_euro
+
+        for r in remun:
+            if r == u'Indemnité':
+                print r
+                line['Indemnite'] = remun[r][1]
+            else:
+                line[r] = remun[r][1]
+
+        line['id'] = employe.id
+        line['nom'] = employe.nom
+        line['prenom'] = employe.prenom
+
+
+    c = {
+        'title': 'Rapport de remuneration',
+        'employes': output,
+    }
+
+    return render_to_response('rh/rapports/remuneration.html', c, RequestContext(request))