import de mesSous

darcs-hash:20071001104834-f46e9-0da6d95e696a074897ff9014ab5cf69d6e1b85d4.gz
This commit is contained in:
gdetrez 2007-10-01 12:48:34 +02:00
parent 66e1695d4f
commit 25920cebc4
11 changed files with 582 additions and 1 deletions

View file

@ -36,7 +36,8 @@ class main(ModuleBase):
def icon(self):
return "icon.png"
_club = True
_club = False
_adh = False

248
intranet/modules/mesSous/main.py Executable file
View file

@ -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 &ecirc;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

View file

@ -0,0 +1,22 @@
#import cherrypy
#set bugMail = cherrypy.config.get("mail.bugreport", "nounous@crans.org")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head>
<body>
<div id="popupInnerBody">
<h2>Paiement annul&eacute;</h2>
<p>Ton compte impressions sera crédité d&eacute;s que la facture sera réglée.</p>
<p>Tu peux régler la facture plus tard en allant dans <a href="/sous/">Mes Factures</a></p>
<p>En cas de probl&egrave;me, envoie un mail &agrave; <a href="mailto:$bugMail">$bugMail</a></p>
<div class="liens">
<a href="./">Retour</a>
</div>
</div>
</form>
</div>
</body></html>

View file

@ -0,0 +1,21 @@
#import cherrypy
#set bugMail = cherrypy.config.get("mail.bugreport", "nounous@crans.org")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head>
<body>
<div id="popupInnerBody">
<h2>Paiement termin&eacute;</h2>
<p>Ton compte impressions sera crédité dans quelques minutes.</p>
<p>N'h&eacute;site pas &agrave; nous envoyer tes remarques et/ou suggestions &agrave; <a href="mailto:$bugMail">$bugMail</a></p>
<div class="liens">
<a href="./">Retour</a>
</div>
</div>
</form>
</div>
</body></html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head>
<body>
<div id="popupInnerBody">
<h2>Recharger son compte impression</h2>
<p> Le cr@ns te permet de recharger ton compte pour les impressions via PayPal ou en allant voir un c&acirc;bleur.</p>
<p>La m&eacute;thode PayPal est plus rapide mais PayPal facture des frais de transaction.</p>
<div class="liens">
<a href="./">Annuler</a>
<a href="?etape=2">Continuer avec Paypal</a>
</div>
</div>
</form>
</div>
</body></html>

View file

@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head>
<body>
<div id="popupInnerBody">
<h2>&Eacute;tape 1 : Choisir le montant</h2>
#if $getVar('error',False)
<div class="errorMessage">$error</div>
#end if
<form method="post" action="rechargerCompteImpression" name="FormCombien">
<input type="hidden" name="etape" value="3" />
<label for="combien">Combien souhaites-tu mettre sur ton compte impression ?<br />
<input type="text" name="combien" value="$getVar('combien','')" /> &euro;
</label>
<p></p><!-- ici, calcul des frais de transaction -->
<div class="liens" id="liens">
<a href="./">Annuler</a>
<script type="text/JavaScript">
<!--
appendChildNodes("liens", A({'href':'#','onclick':"javascript:window.document.FormCombien.submit(); return false;"}, "Continuer"));
//-->
</script>
<noscript>
<input type="submit" value="Continuer"/>
</noscript>
</div>
</form>
</div>
</body></html>

View file

@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head><body>
<div id="popupInnerBody">
<h2>&Eacute;tape 2 : Confirmer la facture</h2>
<table cellspacing="0" border="0" class="factureDetails">
<tr>
<th width="80%">Description</th>
<th>Prix unitaire</th>
<th>Quantit&eacute;</th>
<th>total</th>
</tr>
#for unDetail in $details
<tr>
<td>$unDetail.intitule</td>
<td>$unDetail.prixUnitaire&nbsp;&euro;</td>
<td>$unDetail.quantite</td>
<td>$unDetail.prixTotal&nbsp;&euro;</td>
</tr>
#end for
<tr>
<td colspan="3" class="tdTotalDetailIntitule">
Total
</td>
<td class="tdTotalDetail">$total&nbsp;&euro;</td>
</table>
<div class="liens">
<a href="?etape=2">Pr&eacute;c&eacute;dent</a>
<a href="./">Annuler</a>
<a href="?etape=4">Confirmer</a>
</div>
</div>
</body></html>

View file

@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
#include "inc-paypal-head.tmpl"
</head><body>
<div id="popupInnerBody">
<h2>&Eacute;tape 3 : Fin</h2>
<p>Ton compte impressions sera credit&eacute; d&eacute;s que la facture
sera regl&eacute;e.</p>
<p>Tu peux régler la facture plus tard en allant dans <a
href="/mesSous/">Mon Soldes</a></p>
<div class="liens">
<a href="./">Payer plus tard</a>
<a href="$lienPaypal">Payer tout de suite</a>
</div>
</div>
</body></html>

View file

@ -0,0 +1,58 @@
<div id="messagePlaceHolder"></div>
<div id="globalDiv" onclick="setMessage();">
<ul id="actionMenu">
<li><a href="index">Mes factures PayPal</a></li>
<li><a href="historique">Historique des transactions</a></li>
</ul>
<div id="mainPanel">
<div id="factureListDiv">
<h1>Historique</h1>
<div style="overflow:auto;">
<div>
#if $prevPage
<a href="historique?page=$prevPage">&lt;&lt; moins vieux</a>
#else
<span class="off">&lt;&lt; moins vieux</span>
#end if
&nbsp;|&nbsp;
#if $nextPage
<a href="historique?page=$nextPage">plus vieux &gt;&gt;</a>
#else
<span class="off">plus vieux &gt;&gt;</span>
#end if
</div>
<table id="historique_sous" cellspacing="0">
<tr>
<th>Date</th>
<th>Intitul&eacute;</th>
<th>D&eacute;bit</th>
<th>Cr&eacute;dit</th>
</tr>
#for anItem in $historic_items
<tr>
<td>$anItem.date</td>
<td>$anItem.intitule</td>
#if $anItem.type=="debit"
<td>$anItem.montant</td>
#else
<td>&nbsp;<!-- evite que opera fasse des trucs bizarres... --></td>
#end if
#if $anItem.type=="credit"
<td>$anItem.montant</td>
#else
<td>&nbsp;<!-- evite que opera fasse des trucs bizarres... --></td>
#end if
</tr>
#end for
#if $historic_items == []
<tr><td colspan="4" style="color:gray;">
AUCUNE TRANSACTION ENREGISTR&Eacute;E
</td></tr>
#end if
</table>
</div>
</div><!-- fin de #mainPanel -->
</div>
</div>

View file

@ -0,0 +1,115 @@
<div id="messagePlaceHolder"></div>
#if $message != ''
<script type="text/javascript">setMessage('$message.replace("\'","\\\'")')</script>
#end if
#if $error != ''
<script type="text/javascript">setMessage('$error.replace("\'","\\\'")', 'errorMessage')</script>
#end if
<script type="text/javascript">
function showDetail(id){
slideDown(id, {duration:0.4});
var element = document.getElementById("togglelink" + id);
element.onclick=null;
element.style.backgroundPosition='bottom left';
setTimeout("var element = document.getElementById(\'togglelink" + id + "\');element.onclick=function () {hideDetail(\'" + id + "\'); return false;};",450);
return false;
}
function hideDetail(id){
slideUp(id, {duration:0.4});
var element = document.getElementById("togglelink" + id);
element.onclick=null;
element.style.backgroundPosition="top left";
setTimeout("var element = document.getElementById(\'togglelink" + id + "\');element.onclick=function () {showDetail(\'" + id + "\'); return false;};",450);
return false;
}
</script>
<div id="globalDiv">
<ul id="actionMenu">
<li><a href="rechargerCompteImpression">Nouveau Rechargement</a></li>
<li><a href="index">Mes factures PayPal</a></li>
<li><a href="historique">Historique des transactions</a></li>
</ul>
<div id="mainPanel">
<div id="soldeCourant">
<h1>Solde</h1>
<div class="solde">$getVar('solde', "n/a")&nbsp;&euro;
<span class="actions"><a href="rechargerCompteImpression">Rechargez avec PayPal</a></span>
</div>
</div>
<div id="factureListDiv">
<h1>Mes factures PayPal</h1>
#for f in $listeFactures
#if $f.payee
<div class="factureRow facturePayee">
#else
<div class="factureRow factureNonPayee">
#end if
<div class="factureSummary">
<span class="intitule">
#if $f.details.__len__() > 1
<a href="#" class="linkToggle" id="togglelinkfacture$f.no" onclick="showDetail('facture$f.no'); return false;"></a>
#end if
$f.intitule
#if not $f.payee
(non pay&eacute;e)
#end if
</span>
<span class="montant">
$f.montant&nbsp;&euro;
</span>
<span class="note" style="float:left;clear: left;">Cr&eacute;e le -</span>
#if not $f.payee
<span class="actions">
<a href="delFacture?no=$f.no">Annuler</a>
<a href="$f.paypal">Payer avec PayPal</a>
</span>
#else
<span class="note" style="float:right;clear:right;">Pay&eacute;e</span>
#end if
</div>
#if $f.details.__len__() > 1
<div id="facture$f.no" style="display:none;">
<table cellspacing="0" border="0" class="factureDetails">
<tr>
<th style="width:80%">Description</th>
<th>Prix unitaire</th>
<th>Quantit&eacute;</th>
<th>total</th>
</tr>
#for unDetail in $f.details
<tr>
<td>$unDetail.intitule</td>
<td>$unDetail.prixUnitaire&nbsp;&euro;</td>
<td>$unDetail.quantite</td>
<td>$unDetail.prixTotal&nbsp;&euro;</td>
</tr>
#end for
<tr>
<td colspan="3" class="tdTotalDetailIntitule">
Total
</td>
<td class="tdTotalDetail">$f.montant&nbsp;&euro;</td>
</tr>
</table>
</div>
</div>
#end if
#end for
#if $listeFactures == []
<div class="factureRow tdNoFactures">
AUCUNE TRANSACTION PAYPAL ENREGISTR&Eacute;E
</div>
#end if
</div>
</div><!-- fine de #mainPanel -->
</div>

View file

@ -0,0 +1,11 @@
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Cr@nsIntranet</title>
<!-- ++++++++++++++++++++++++++ stylesheets +++++++++++++++++++++++++++ -->
<link rel="stylesheet" type="text/css" href="$static('monCompte.css')" />
<!-- ++++++++++++++++++++++++++++ scripts +++++++++++++++++++++++++++++ -->
<script src="/static/MochiKit/MochiKit.js" type="text/javascript"></script>
<script src="/static/MochiKit/New.js" type="text/javascript"></script>