diff --git a/Brie/brie/controllers/stats.py b/Brie/brie/controllers/stats.py index 7ead8e5..b3bc636 100644 --- a/Brie/brie/controllers/stats.py +++ b/Brie/brie/controllers/stats.py @@ -21,7 +21,13 @@ class StatsController(AuthenticatedBaseController): residences = [] rooms_stats = dict() members_stats = dict() + total_earned = dict() + average_cotisation = dict() + global_average_cotisation = 0 + global_total_earned = 0 + global_current_members = 0 residences_ldap = Residences.get_residences(self.user) + year = CotisationComputes.current_year() for residence_ldap in residences_ldap: residence_dn = residence_ldap.uniqueMember.first() residence_name = residence_ldap.cn.first() @@ -38,6 +44,23 @@ class StatsController(AuthenticatedBaseController): for room in Room.get_rooms(self.user, residence_dn): if not room.has("x-memberIn"): rooms_stats[residence_name]['empty_rooms'].append(room) + # FIXME : Vérifier si on compte les "extras" (vente de câbles). Il ne faudrait pas les compter. + all_payments = Cotisation.get_all_payment_by_year(self.user, residence_dn, year) + total_earned[residence_name] = 0 + for onepayment in all_payments: + total_earned[residence_name] += float(onepayment.get('x-amountPaid').first()) + #end for + if(members_stats[residence_name]['number_of_current_members'] != 0): + average_cotisation[residence_name] = float(total_earned[residence_name])/float(members_stats[residence_name]['number_of_current_members']) + else: + average_cotisation[residence_name] = 0 + global_total_earned += total_earned[residence_name] + global_current_members += members_stats[residence_name]['number_of_current_members'] + + if(global_current_members != 0): + global_average_cotisation = global_total_earned/global_current_members + else: + global_average_cotisation = 0 residence = None if self.user is not None: @@ -49,7 +72,12 @@ class StatsController(AuthenticatedBaseController): "residence" : residence, "residences" : residences, "rooms_stats" : rooms_stats, - "members_stats" : members_stats + "members_stats" : members_stats, + "total_earned" : total_earned, + "average_cotisation" : average_cotisation, + "global_total_earned" : global_total_earned, + "global_current_members" : global_current_members, + "global_average_cotisation" : global_average_cotisation } #end def #end class diff --git a/Brie/brie/templates/stats/index.html b/Brie/brie/templates/stats/index.html index 65df8e2..30c8985 100644 --- a/Brie/brie/templates/stats/index.html +++ b/Brie/brie/templates/stats/index.html @@ -6,6 +6,23 @@