diff --git a/intranet/modules/factures/main.py b/intranet/modules/factures/main.py index 8464a8e4..551779db 100755 --- a/intranet/modules/factures/main.py +++ b/intranet/modules/factures/main.py @@ -36,7 +36,8 @@ class main(ModuleBase): def icon(self): return "icon.png" - _club = True + _club = False + _adh = False diff --git a/intranet/modules/mesSous/main.py b/intranet/modules/mesSous/main.py new file mode 100755 index 00000000..9628f0bf --- /dev/null +++ b/intranet/modules/mesSous/main.py @@ -0,0 +1,248 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- +# ##################################################################################################### # +# Mes Sous +# ##################################################################################################### # +# Description: +# Affiche la liste des factures et l'historique de debits/credits de l'adherent. +# Fait aussi les rechargements Paypal +# Informations: +# +# Pages: +# index:liste des factures +# historique: historique des débits/crédits +# rechargementPaypal: Comme son nom l'indique +# +# ##################################################################################################### # +import cherrypy, sys, os, datetime + + +if (cherrypy.config.configMap["global"]["server.environment"] == "development"): + from ldap_crans_test import * +# print("monCompte : unsing test ldap : env=" + cherrypy.config.configMap["global"]["server.environment"]) +else: + from ldap_crans import * +# print("monCompte : unsing prod ldap : env=" + cherrypy.config.configMap["global"]["server.environment"]) + + +from ClassesIntranet.ModuleBase import ModuleBase + + +class main(ModuleBase): + def title(self): + return "Mon Solde" + def category(self): + return "Personnel" + def icon(self): + return "icon.png" + + _club = True + + + + def getCurrentAdministrativeYear(self): + ''' + premiere partie de l''annee scolaire en cours + ex : le 5 juin 2006 retourne 2005 + ''' + now = datetime.datetime.now() + currentYear = int(now.strftime("%Y")) + currentMonth = int(now.strftime("%m")) + if currentMonth > 8: + administrativeYear = currentYear + else: + administrativeYear = currentYear - 1 + return administrativeYear + + + def index(self, message = '', error = ''): + adh = cherrypy.session['LDAP'].getProprio(cherrypy.session['uid']) + t = {} + t['message'] = message + t['error'] = error + t['solde'] = adh.solde + + ############## liste des factures ############## + listeFactures = [] + for f in adh.factures(): + facture = {} + facture['no'] = f.numero() + facture['intitule'] = f.articles()[0]['designation'] + facture['details'] = [ + { + 'intitule':art['designation'], + 'quantite':art['nombre'], + 'prixUnitaire':art['pu'], + 'prixTotal':art['pu']*art['nombre'], + } for art in f.articles()] + facture['montant'] = f.total() + facture['paypal'] = f.urlPaypal(useSandbox = cherrypy.config.get("paypal.useSandbox", False), + businessMail = cherrypy.config.get("paypal.businessAdress", "paypal@crans.org"), + return_page = "https://intranet.crans.org/monCompte/paypalReturn", + cancel_return_page = "https://intranet.crans.org/monCompte/paypalCancel", + ) + + facture['payee'] = f.recuPaiement() + listeFactures.append(facture) + t['listeFactures'] = listeFactures + + return { + 'template' :'factures', + 'values' :t, + 'stylesheets' :['cransFactures.css'], + 'scripts' :[], + } + index.exposed = True + + def historique(self, page = 1, items_per_page = 20): + adh = cherrypy.session['LDAP'].getProprio(cherrypy.session['uid']) + + lst = [ x for x in adh.historique() if x.split(u' : ',1)[1].startswith(u'credit') or x.split(u' : ',1)[1].startswith(u'debit') ] + histLst = [] + for anItem in lst: + aLine = {} + aLine["date"] = anItem.split(u",")[0] + aLine["type"] = anItem.split(u' : ',2)[1].split(u' ')[0] + aLine["montant"] = anItem.split(u' : ',2)[1].split(u' ')[1] + try: + aLine["intitule"] = anItem.split(u'[')[1].split(u']')[0] + except Exception: + aLine["intitule"] = "" + histLst.append(aLine) + + histLst.reverse() + page = int(page) + items_per_page = int(items_per_page) + if page == 1: + prevPage = None + else: + prevPage = page - 1 + + if page * items_per_page >= histLst.__len__(): + nextPage = None + else: + nextPage = page + 1 + offset = items_per_page * ( page - 1) + + + return { + 'template' :'factures-historique', + 'values' :{ + 'liste':lst, + 'historic_items':histLst[offset:offset + items_per_page], + 'nextPage':nextPage, + 'prevPage':prevPage + }, + 'stylesheets' :['cransFactures.css'], + 'scripts' :[], + } + historique.exposed = True + + def delFacture(self, no): + try: + # trrouver la factures + fact = cherrypy.session['LDAP'].search('fid=' + no, 'w')['facture'][0] + #verifier qu'elle appartient bien a l'adherent + if not fact.proprietaire().mail() == cherrypy.session['uid']: + raise Exception, "Impossible de supprimer cette facture" + # la supprimer + fact.delete() + except Exception, e: + cherrypy.log(str(e), "FACTURES", 1) + return self.index() + delFacture.exposed = True + + + ########################## + # paypal + ########################## + # + # methode qui affiche successivement les + # templates du popup pour recharger son compte impression + # via paypal + # + def rechargerCompteImpression(self, etape = '1', combien = None): + adh = cherrypy.session['LDAP'].getProprio(cherrypy.session['uid']) + if (etape == "1"): # Introduction + return { + 'template' :'MonCompteRechargePaypal1', + 'standalone' :True, + 'values' :{}, + } + elif (etape == "2"): # choix montant + return { + 'template' :'MonCompteRechargePaypal2', + 'standalone' :True, + 'values' :{}, + } + elif (etape == "3"): # confirmer facture + # creer objet facture + f = Facture(adh) + # /!\ verifier que combien est un nombre + # et qu'il n'y a pas plus de 2 chiffres apres le point... + # (ce serait bien aussi si on pouvait mettre une virgue a la place du point) + try: + # remplacage des virgules + combien = combien.replace(u',', u'.') + # convertissage + combien = float(combien) + # arrondissage-tronquage : + combien = float(int(combien*100)/100.0) + # nombre positif + if combien < 0: + raise ValueError + except Exception: + return { + 'template' :'MonCompteRechargePaypal2', + 'standalone' :True, + 'values' :{'error':"Le montant doit être un nombre positif !", 'combien':combien}, + } + f.ajoute({'nombre': 1, 'code': 'SOLDE', 'designation': 'Credit du compte impression (intranet)', 'pu': combien}) + cherrypy.session['freshFacture'] = f + pageData = {} + pageData['details'] = [ + { + 'intitule':art['designation'], + 'quantite':art['nombre'], + 'prixUnitaire':art['pu'], + 'prixTotal':art['pu']*art['nombre'], + } for art in f.articles()] + pageData['total'] = f.total() + return { + 'template' :'MonCompteRechargePaypal3', + 'standalone' :True, + 'values' :pageData, + } + elif (etape == "4"):# payer maintenant ? + # sauver objet facture + f = cherrypy.session['freshFacture'] + f.save() + return { + 'template' :'MonCompteRechargePaypal4', + 'standalone' :True, + 'values' :{'lienPaypal' : f.urlPaypal(useSandbox = cherrypy.config.get("paypal.useSandbox", False), + businessMail = cherrypy.config.get("paypal.businessAdress", "paypal@crans.org"), + return_page = "https://intranet.crans.org/monCompte/paypalReturn", + cancel_return_page = "https://intranet.crans.org/monCompte/paypalCancel", + )}, + } + rechargerCompteImpression.exposed = True + + def paypalReturn(self, **kw): + _crans_cp.log("retour de paypal avec les infos : %s" % " ".join( [ "[%s: %s]" % (str(a), str(kw[a])) for a in kw] ) ) + return { + 'template' :'MonComptePaypalReturn', + 'standalone' :True, + 'values' :{}, + } + paypalReturn.exposed = True + + def paypalCancel(self, **kw): + _crans_cp.log("annulation de paypal avec les infos : %s" % " ".join( [ "[%s: %s]" % (str(a), str(kw[a])) for a in kw] ) ) + return { + 'template' :'MonComptePaypalCancel', + 'standalone' :True, + 'values' :{}, + } + paypalCancel.exposed = True + diff --git a/intranet/modules/mesSous/templates/MonComptePaypalCancel.tmpl b/intranet/modules/mesSous/templates/MonComptePaypalCancel.tmpl new file mode 100644 index 00000000..7bef45d6 --- /dev/null +++ b/intranet/modules/mesSous/templates/MonComptePaypalCancel.tmpl @@ -0,0 +1,22 @@ +#import cherrypy +#set bugMail = cherrypy.config.get("mail.bugreport", "nounous@crans.org") + + +#include "inc-paypal-head.tmpl" + + +
+

Paiement annulé

+

Ton compte impressions sera crédité dés que la facture sera réglée.

+

Tu peux régler la facture plus tard en allant dans Mes Factures

+

En cas de problème, envoie un mail à $bugMail

+
+ Retour +
+
+ + + + + + diff --git a/intranet/modules/mesSous/templates/MonComptePaypalReturn.tmpl b/intranet/modules/mesSous/templates/MonComptePaypalReturn.tmpl new file mode 100644 index 00000000..e96cd6c3 --- /dev/null +++ b/intranet/modules/mesSous/templates/MonComptePaypalReturn.tmpl @@ -0,0 +1,21 @@ +#import cherrypy +#set bugMail = cherrypy.config.get("mail.bugreport", "nounous@crans.org") + + +#include "inc-paypal-head.tmpl" + + +
+

Paiement terminé

+

Ton compte impressions sera crédité dans quelques minutes.

+

N'hésite pas à nous envoyer tes remarques et/ou suggestions à $bugMail

+
+ Retour +
+
+ + + + + + diff --git a/intranet/modules/mesSous/templates/MonCompteRechargePaypal1.tmpl b/intranet/modules/mesSous/templates/MonCompteRechargePaypal1.tmpl new file mode 100644 index 00000000..f8e76575 --- /dev/null +++ b/intranet/modules/mesSous/templates/MonCompteRechargePaypal1.tmpl @@ -0,0 +1,20 @@ + + +#include "inc-paypal-head.tmpl" + + +
+

Recharger son compte impression

+

Le cr@ns te permet de recharger ton compte pour les impressions via PayPal ou en allant voir un câbleur.

+

La méthode PayPal est plus rapide mais PayPal facture des frais de transaction.

+
+ Annuler + Continuer avec Paypal +
+
+ + + + + + \ No newline at end of file diff --git a/intranet/modules/mesSous/templates/MonCompteRechargePaypal2.tmpl b/intranet/modules/mesSous/templates/MonCompteRechargePaypal2.tmpl new file mode 100644 index 00000000..e8a4e9ff --- /dev/null +++ b/intranet/modules/mesSous/templates/MonCompteRechargePaypal2.tmpl @@ -0,0 +1,33 @@ + + +#include "inc-paypal-head.tmpl" + + +
+

Étape 1 : Choisir le montant

+#if $getVar('error',False) +
$error
+#end if +
+ + +

+
+ Annuler + + +
+ + +
+
+ + diff --git a/intranet/modules/mesSous/templates/MonCompteRechargePaypal3.tmpl b/intranet/modules/mesSous/templates/MonCompteRechargePaypal3.tmpl new file mode 100644 index 00000000..3ce6045b --- /dev/null +++ b/intranet/modules/mesSous/templates/MonCompteRechargePaypal3.tmpl @@ -0,0 +1,35 @@ + + +#include "inc-paypal-head.tmpl" + +
+

Étape 2 : Confirmer la facture

+ + + + + + + + #for unDetail in $details + + + + + + + #end for + + + +
DescriptionPrix unitaireQuantitétotal
$unDetail.intitule$unDetail.prixUnitaire €$unDetail.quantite$unDetail.prixTotal €
+ Total + $total €
+
+ Précédent + Annuler + Confirmer +
+
+ + \ No newline at end of file diff --git a/intranet/modules/mesSous/templates/MonCompteRechargePaypal4.tmpl b/intranet/modules/mesSous/templates/MonCompteRechargePaypal4.tmpl new file mode 100644 index 00000000..5820a310 --- /dev/null +++ b/intranet/modules/mesSous/templates/MonCompteRechargePaypal4.tmpl @@ -0,0 +1,17 @@ + + +#include "inc-paypal-head.tmpl" + +
+

Étape 3 : Fin

+

Ton compte impressions sera credité dés que la facture +sera reglée.

+

Tu peux régler la facture plus tard en allant dans Mon Soldes

+
+ Payer plus tard + Payer tout de suite +
+
+ + \ No newline at end of file diff --git a/intranet/modules/mesSous/templates/factures-historique.tmpl b/intranet/modules/mesSous/templates/factures-historique.tmpl new file mode 100644 index 00000000..7c772622 --- /dev/null +++ b/intranet/modules/mesSous/templates/factures-historique.tmpl @@ -0,0 +1,58 @@ +
+ +
+ + +
+
+

Historique

+
+
+ #if $prevPage + << moins vieux + #else + << moins vieux + #end if +  |  + #if $nextPage + plus vieux >> + #else + plus vieux >> + #end if +
+ + + + + + + + #for anItem in $historic_items + + + + #if $anItem.type=="debit" + + #else + + #end if + #if $anItem.type=="credit" + + #else + + #end if + + #end for + #if $historic_items == [] + + #end if +
DateIntituléDébitCrédit
$anItem.date$anItem.intitule$anItem.montant $anItem.montant 
+ AUCUNE TRANSACTION ENREGISTRÉE +
+
+
+
+
diff --git a/intranet/modules/mesSous/templates/factures.tmpl b/intranet/modules/mesSous/templates/factures.tmpl new file mode 100644 index 00000000..0f3d5f19 --- /dev/null +++ b/intranet/modules/mesSous/templates/factures.tmpl @@ -0,0 +1,115 @@ +
+ +#if $message != '' + +#end if + +#if $error != '' + +#end if + + + + +
+ + +
+
+

Solde

+
$getVar('solde', "n/a") € + Rechargez avec PayPal +
+
+ +
+

Mes factures PayPal

+ #for f in $listeFactures + #if $f.payee +
+ #else +
+ #end if +
+ + #if $f.details.__len__() > 1 + + #end if + $f.intitule + #if not $f.payee + (non payée) + #end if + + + + $f.montant € + + Crée le - + #if not $f.payee + + Annuler + Payer avec PayPal + + #else + Payée + #end if + +
+ #if $f.details.__len__() > 1 + +
+ #end if + #end for + + #if $listeFactures == [] +
+ AUCUNE TRANSACTION PAYPAL ENREGISTRÉE +
+ #end if +
+
+
diff --git a/intranet/modules/mesSous/templates/inc-paypal-head.tmpl b/intranet/modules/mesSous/templates/inc-paypal-head.tmpl new file mode 100644 index 00000000..907ec0c7 --- /dev/null +++ b/intranet/modules/mesSous/templates/inc-paypal-head.tmpl @@ -0,0 +1,11 @@ + + + Cr@nsIntranet + + + + + + + +