2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class TrezoModule
extends PLModule
27 'trezo' => $this->make_hook('default', AUTH_COOKIE
),
28 'trezo/ops' => $this->make_hook('operation', AUTH_COOKIE
),
32 function handler_default(&$page)
36 $page->changeTpl('trezo/index.tpl');
38 require_once 'money/trezo.inc.php';
41 //+--------+---------------+------+-----+------------+----------------+
42 //| field | type | null | key | default | extra |
43 //+--------+---------------+------+-----+------------+----------------+
44 //| id | int(11) | | pri | null | auto_increment |
45 //| date | date | | | 0000-00-00 | |
46 //| label | varchar(80) | | | | |
47 //| credit | decimal(10,2) | | | 0.00 | |
48 //| debit | decimal(10,2) | | | 0.00 | |
49 //+--------+---------------+------+-----+------------+----------------+
51 $annee_sel = Env
::get('annee', date('y'));
52 $mois_sel = Env
::get('mois', sprintf('%02u', date('m') - (intval(date('m') - 1) %
3)));
54 $mois_sel_fin = sprintf('%02u',$mois_sel +
2);
55 $from_date = "$annee_sel-$mois_sel-01";
56 $to_date = "$annee_sel-$mois_sel_fin-31";
57 $mon_sel = $trim_fr[$mois_sel]." $annee_sel";
59 $page->assign('from_solde', solde_until($from_date));
60 $page->assign('to_solde', solde_until($to_date));
61 $page->assign('annee_sel', $annee_sel);
62 $page->assign('mois_sel', $mois_sel);
63 $page->assign('mon_sel', $mon_sel);
64 $page->assign_by_ref('month_arr', $trim_fr);
66 $page->assign('ops', XDB
::iterator(
67 "SELECT date, label, credit, debit
68 FROM money_trezo WHERE date >= {?} and date <= {?} order by date",
69 $from_date, $to_date));
72 function handler_operation(&$page)
76 $page->changeTpl('trezo/gere_operations.tpl');
78 require_once 'money/trezo.inc.php';
80 $page->assign('xorg_title','Polytechnique.org - Administration - Trezo : gestion');
82 $action = clean_request('action');
83 $op_id = clean_request('op_id');
84 $op_date = clean_request('op_date');
85 $op_label = clean_request('op_label');
86 $op_credit = clean_request('op_credit');
87 $op_debit = clean_request('op_debit');
89 $annee_sel = isset($_REQUEST['annee']) ?
$_REQUEST['annee'] : date("Y");
90 $mois_sel = isset($_REQUEST['mois']) ?
$_REQUEST['mois'] : sprintf("%02u", date('m'));
92 $from_date = "$annee_sel-$mois_sel-01";
93 $to_date = "$annee_sel-$mois_sel-31";
94 $mon_sel = $trim_fr[$mois_sel]." $annee_sel";
99 $res = XDB
::query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id);
100 list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow();
105 if (isDate($op_date)){
106 $mydatefr = explode("/",$op_date);
107 $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
109 $mydate = date("Y-m-d");
112 $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'";
114 if ($op_credit) { $sql .= ',credit='.$op_credit; }
115 if ($op_debit) { $sql .= ',debit='.$op_debit; }
116 if ($op_id) { $sql .= ",id='$op_id'"; }
123 XDB
::execute("DELETE FROM money_trezo WHERE id={?}", $op_id);
128 $page->assign('op_id', $op_id);
129 $page->assign('annee_sel', $annee_sel);
130 $page->assign('mois_sel', $mois_sel);
131 $page->assign('op_date', $op_date);
132 $page->assign('op_label', $op_label);
133 $page->assign('op_debit', $op_debit);
134 $page->assign('op_credit', $op_credit);
135 $page->assign('mon_sel', $mon_sel);
137 $page->assign('from_solde', solde_until($from_date));
138 $page->assign('to_solde', solde_until($to_date));
139 $page->assign('month_arr', $mois_fr);
140 $page->assign('ops', XDB
::iterator(
141 "SELECT id, date, label, credit, debit FROM money_trezo
142 WHERE date >= {?} and date <= {?} ORDER BY date",
143 $from_date, $to_date));