From b1cb14405c9c6ecd46aa3502c8ef9271dc367fc9 Mon Sep 17 00:00:00 2001 From: Roven Gabriel Date: Wed, 11 Sep 2013 19:17:19 +0200 Subject: [PATCH] =?UTF-8?q?implementation=20tr=C3=A9sorie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Brie/brie/controllers/root.py | 2 + Brie/brie/controllers/treasury.py | 97 ++++++++++++++++++++++++ Brie/brie/model/ldap.py | 11 ++- Brie/brie/public/css/form-signin.css | 6 +- Brie/brie/templates/navbar.html | 2 + Brie/brie/templates/treasury/__init__.py | 0 Brie/brie/templates/treasury/index.html | 30 ++++++++ 7 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 Brie/brie/controllers/treasury.py create mode 100644 Brie/brie/templates/treasury/__init__.py create mode 100644 Brie/brie/templates/treasury/index.html diff --git a/Brie/brie/controllers/root.py b/Brie/brie/controllers/root.py index 99a04de..ee49d56 100644 --- a/Brie/brie/controllers/root.py +++ b/Brie/brie/controllers/root.py @@ -21,6 +21,7 @@ from brie.controllers.edit import EditController from brie.controllers.administration import AdministrationController from brie.controllers.error import ErrorController from brie.controllers.registration import RegistrationController +from brie.controllers.treasury import TreasuryController __all__ = ['RootController'] @@ -51,6 +52,7 @@ class RootController(BaseController): error = ErrorController() search = SearchController() registration = RegistrationController(edit) + treasury = TreasuryController() @expose('brie.templates.index') def index(self): diff --git a/Brie/brie/controllers/treasury.py b/Brie/brie/controllers/treasury.py new file mode 100644 index 0000000..6e5f6c6 --- /dev/null +++ b/Brie/brie/controllers/treasury.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- + +from tg import session +from tg.controllers import redirect +from tg.decorators import expose, validate +from brie.config import ldap_config +from brie.config import groups_enum +from brie.lib.ldap_helper import * +from brie.lib.aurore_helper import * +from brie.lib.plugins import * +from brie.model.ldap import * + +from brie.controllers import auth +from brie.controllers.auth import AuthenticatedBaseController, AuthenticatedRestController +from brie.controllers.members import MembersController + +from operator import itemgetter + +""" Controller de recherche """ +class TreasuryController(AuthenticatedBaseController): + require_group = groups_enum.tresorier + + validate = None + + def __init__(self): + self.validate = ValidatePaymentController() + #end if + + """ Affiche les résultats """ + @expose("brie.templates.treasury.index") + def index(self): + residence_dn = self.user.residence_dn + residence = Residences.get_name_by_dn(self.user, self.user.residence_dn) + + year = CotisationComputes.current_year() + pending_payments = Cotisation.get_all_pending_payments(self.user, residence_dn, year) + + admin_totals = dict() + admin_payments_received = dict() + for pending_payment in pending_payments: + admin_member = Member.get_by_dn(self.user, pending_payment.get("x-action-user").first()) + admin_name = pending_payment.get("x-action-user-info").first() + if admin_member is not None: + admin_name = admin_member.cn.first() + + + dn_prefix = "cn=" + pending_payment.cn.first() + ",cn=" + str(year) + ",cn=cotisations," + + print dn_prefix + member_dn = pending_payment.dn[len(dn_prefix):] + print member_dn + member = Member.get_by_dn(self.user, member_dn) + + amount_paid = int(pending_payment.get("x-amountPaid").first()) + + if admin_name in admin_totals: + admin_totals[admin_name] += amount_paid + else: + admin_totals[admin_name] = amount_paid + #end if + + if admin_name in admin_payments_received: + admin_payments_received[admin_name].append((member, pending_payment)) + else: + admin_payments_received[admin_name] = [(member, pending_payment)] + #end if + #end for + + admin_payments_received_ordered = sorted(admin_payments_received.iteritems(), key=lambda t:t[0]) + + return { + "residence" : residence, + "user" : self.user, + "admin_totals" : admin_totals, + "admin_payments_received" : admin_payments_received_ordered + } + #end def + +#end class + + +class ValidatePaymentController(AuthenticatedRestController): + + @expose() + def post(self, residence, member_uid, payment_cn, year): + residence_dn = Residences.get_dn_by_name(self.user, residence) + member = Member.get_by_uid(self.user, residence_dn, member_uid) + + cotisation_dn = "cn=" + payment_cn + ",cn=" + str(year) + ",cn=cotisations," + member.dn + cashed_attr = Cotisation.cashed_payment_attr() + cotisation = self.user.ldap_bind.search_dn(cotisation_dn) + cotisation.add("x-paymentCashed", "TRUE") + self.user.ldap_bind.save(cotisation) + + redirect("/treasury/") + #end def +#end class diff --git a/Brie/brie/model/ldap.py b/Brie/brie/model/ldap.py index 408cb05..b285e2a 100644 --- a/Brie/brie/model/ldap.py +++ b/Brie/brie/model/ldap.py @@ -347,6 +347,13 @@ class Cotisation: } #end def + @staticmethod + def cashed_payment_attr(): + return { + "x-paymentCashed" : "TRUE" + } + #end def + @staticmethod def prix_annee(user_session, residence_dn): dn = ldap_config.cotisation_annee_base_dn + residence_dn @@ -390,13 +397,13 @@ class Cotisation: @staticmethod def get_all_pending_payments(user_session, residence_dn, year): dn = ldap_config.username_base_dn + residence_dn - return user_session.ldap_bind.search(dn, "(&(&(objectClass=aurorePayment)(x-year=" + str(year) + "))(!(x-paymentCashed=True)))") + return user_session.ldap_bind.search(dn, "(&(&(objectClass=aurorePayment)(x-year=" + str(year) + "))(!(x-paymentCashed=TRUE)))") #end def @staticmethod def get_pending_payments_of_admin(user_session, residence_dn, user_dn, year): dn = ldap_config.username_base_dn + residence_dn - return user_session.ldap_bind.search(dn, "(&(&(&(objectClass=aurorePayment)(x-year=" + str(year) + "))(!(x-paymentCashed=True)))(x-action-user=" + user_dn + "))") + return user_session.ldap_bind.search(dn, "(&(&(&(objectClass=aurorePayment)(x-year=" + str(year) + "))(!(x-paymentCashed=TRUE)))(x-action-user=" + user_dn + "))") #end def diff --git a/Brie/brie/public/css/form-signin.css b/Brie/brie/public/css/form-signin.css index 85711db..aa257c0 100644 --- a/Brie/brie/public/css/form-signin.css +++ b/Brie/brie/public/css/form-signin.css @@ -18,8 +18,12 @@ .form-signin input[type="text"], .form-signin input[type="password"] { font-size: 16px; - height: auto; margin-bottom: 15px; padding: 7px 9px; } + +input[type="text"],input[type="password"] +{ + height: 28px; +} diff --git a/Brie/brie/templates/navbar.html b/Brie/brie/templates/navbar.html index e72318e..63421a0 100644 --- a/Brie/brie/templates/navbar.html +++ b/Brie/brie/templates/navbar.html @@ -13,7 +13,9 @@
  • CHAMBRES
  • MEMBRES
  • INSCRIPTION
  • +
  • TRESORIE
  • ADMINISTRATION
  • + diff --git a/Brie/brie/templates/treasury/__init__.py b/Brie/brie/templates/treasury/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Brie/brie/templates/treasury/index.html b/Brie/brie/templates/treasury/index.html new file mode 100644 index 0000000..bd0ee45 --- /dev/null +++ b/Brie/brie/templates/treasury/index.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    + PAIEMENTS EN ATTENTE
    +
    +
    + ${admin_name} ${admin_totals[admin_name]} € +
    + ${payment.description.first()} + ${member.cn.first()} - ${payment.get("x-amountPaid").first()} € - ${payment.get("x-time").first()} +
    + + + + + +
    +
    +
    + +