Creates csv for payments (Closes #1398).
authorStéphane Jacob <sj@m4x.org>
Wed, 2 Mar 2011 09:41:34 +0000 (10:41 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 2 Mar 2011 09:41:34 +0000 (10:41 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
modules/payment.php
templates/payment/xnet.tpl

index b262a4d..51a1b29 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ Bug/Wish:
         - #1399: Displays all similar entreprises only on demand           -JAC
         - #1403: Displays grade if any in medal validation process         -JAC
 
+    * Payments:
+        - #1398: Creates csv for payments                                  -JAC
+
     * Profile:
         - #1324,1352: Adds jobs to vcards                                  -JAC
         - #1380: Allows multiple entries for some medals                   -JAC
index f068aff..0005e13 100644 (file)
@@ -111,6 +111,7 @@ class PaymentModule extends PLModule
             'payment/paypal_return'        => $this->make_hook('paypal_return',    AUTH_PUBLIC, 'user', NO_HTTPS),
             '%grp/paiement'                => $this->make_hook('xnet_payment',     AUTH_MDP),
             '%grp/payment'                 => $this->make_hook('xnet_payment',     AUTH_MDP),
+            '%grp/payment/csv'             => $this->make_hook('payment_csv',      AUTH_MDP,    'groupadmin'),
             '%grp/payment/cyber_return'    => $this->make_hook('cyber_return',     AUTH_PUBLIC, 'user', NO_HTTPS),
             '%grp/payment/cyber2_return'   => $this->make_hook('cyber2_return',    AUTH_PUBLIC, 'user', NO_HTTPS),
             '%grp/payment/paypal_return'   => $this->make_hook('paypal_return',    AUTH_PUBLIC, 'user', NO_HTTPS),
@@ -589,6 +590,43 @@ class PaymentModule extends PLModule
         $page->assign('event', $event);
     }
 
+    function handler_payment_csv($page, $pid = null)
+    {
+        if (is_null($pid)) {
+            pl_redirect('payment');
+        }
+        if (substr($pid, -4) == '.vcf') {
+            $pid = substr($pid, 0, strlen($pid) - 4);
+        }
+
+        $res = XDB::fetchAllAssoc('SELECT  uid, IF(timestamp = \'0000-00-00\', 0, timestamp) AS date, comment, amount
+                                     FROM  payment_transactions
+                                    WHERE  ref = {?}
+                                 ORDER BY  timestamp',
+                                  $pid);
+        if (is_null($res)) {
+            pl_redirect('payment');
+        }
+
+        $users = User::getBulkUsersWithUIDs($res, 'uid', 'user');
+        $sum = 0;
+
+        pl_cached_content_headers('text/x-csv', 1);
+        $csv = fopen('php://output', 'w');
+        fputcsv($csv, array('Date', 'Nom', 'Prénom', 'Sexe', 'Promotion', 'Email', 'Commentaire', 'Montant'), ';');
+        foreach ($users as $item) {
+            $user = $item['user'];
+            $sum += strtr(substr($item['amount'], 0, strpos($item['amount'], 'EUR')), ',', '.');
+            fputcsv($csv, array(format_datetime($item['date'], '%d/%m/%y'), $user->lastName(), $user->firstName(),
+                                ($user->isFemale()) ? 'F' : 'M', $user->promo(), $user->ForlifeEmail(),
+                                $item['comment'], str_replace('EUR', '€', $item['amount'])), ';');
+        }
+        fputcsv($csv, array(date('d/m/y'), 'Total', '', '', '' , '', '', strtr($sum, '.', ',') . ' €'), ';');
+
+        fclose($csv);
+        exit;
+    }
+
     function handler_admin($page, $action = 'list', $id = null) {
         $page->setTitle('Administration - Paiements');
         $page->assign('title', 'Gestion des télépaiements');
index b50b959..89dddb1 100644 (file)
@@ -79,7 +79,10 @@ il suffit de cliquer sur le titre de la colonne concernée.
 {/if}
 
 {if $is_admin && $trans[$p.id]}
-<p>Liste des personnes ayant payé (pour les administrateurs uniquement)&nbsp;:</p>
+<p>
+  Liste des personnes ayant payé (pour les administrateurs uniquement)&nbsp;:<br />
+  <a href="{$platal->ns}payment/csv/{$p.id}.csv">{icon name=page_excel title="Fichier Excel"} Obtenir au format Excel</a>
+</p>
 <table cellpadding="0" cellspacing="0" id="list_{$p.id}" class='bicol'>
   <tr>
     <th>