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)
34 $page->changeTpl('trezo/index.tpl');
36 require_once 'money/trezo.inc.php';
39 //+--------+---------------+------+-----+------------+----------------+
40 //| field | type | null | key | default | extra |
41 //+--------+---------------+------+-----+------------+----------------+
42 //| id | int(11) | | pri | null | auto_increment |
43 //| date | date | | | 0000-00-00 | |
44 //| label | varchar(80) | | | | |
45 //| credit | decimal(10,2) | | | 0.00 | |
46 //| debit | decimal(10,2) | | | 0.00 | |
47 //+--------+---------------+------+-----+------------+----------------+
49 $annee_sel = Env
::v('annee', date('y'));
50 $mois_sel = Env
::v('mois', sprintf('%02u', date('m') - (intval(date('m') - 1) %
3)));
52 $mois_sel_fin = sprintf('%02u',$mois_sel +
2);
53 $from_date = "$annee_sel-$mois_sel-01";
54 $to_date = "$annee_sel-$mois_sel_fin-31";
55 $mon_sel = $trim_fr[$mois_sel]." $annee_sel";
57 $page->assign('from_solde', solde_until($from_date));
58 $page->assign('to_solde', solde_until($to_date));
59 $page->assign('annee_sel', $annee_sel);
60 $page->assign('mois_sel', $mois_sel);
61 $page->assign('mon_sel', $mon_sel);
62 $page->assign_by_ref('month_arr', $trim_fr);
64 $page->assign('ops', XDB
::iterator(
65 "SELECT date, label, credit, debit
66 FROM money_trezo WHERE date >= {?} and date <= {?} order by date",
67 $from_date, $to_date));
70 function handler_operation(&$page)
72 $page->changeTpl('trezo/gere_operations.tpl');
74 require_once 'money/trezo.inc.php';
76 $page->assign('xorg_title','Polytechnique.org - Administration - Trezo : gestion');
78 $action = clean_request('action');
79 $op_id = clean_request('op_id');
80 $op_date = clean_request('op_date');
81 $op_label = clean_request('op_label');
82 $op_credit = clean_request('op_credit');
83 $op_debit = clean_request('op_debit');
85 $annee_sel = isset($_REQUEST['annee']) ?
$_REQUEST['annee'] : date("Y");
86 $mois_sel = isset($_REQUEST['mois']) ?
$_REQUEST['mois'] : sprintf("%02u", date('m'));
88 $from_date = "$annee_sel-$mois_sel-01";
89 $to_date = "$annee_sel-$mois_sel-31";
90 $mon_sel = $trim_fr[$mois_sel]." $annee_sel";
95 $res = XDB
::query("SELECT date,label,credit,debit FROM money_trezo WHERE id={?}", $op_id);
96 list($op_date,$op_label,$op_credit,$op_debit) = $res->fetchOneRow();
101 if (isDate($op_date)){
102 $mydatefr = explode("/",$op_date);
103 $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0];
105 $mydate = date("Y-m-d");
108 $sql = "replace into money_trezo set date='$mydate',label='".addslashes($op_label)."'";
110 if ($op_credit) { $sql .= ',credit='.$op_credit; }
111 if ($op_debit) { $sql .= ',debit='.$op_debit; }
112 if ($op_id) { $sql .= ",id='$op_id'"; }
119 XDB
::execute("DELETE FROM money_trezo WHERE id={?}", $op_id);
124 $page->assign('op_id', $op_id);
125 $page->assign('annee_sel', $annee_sel);
126 $page->assign('mois_sel', $mois_sel);
127 $page->assign('op_date', $op_date);
128 $page->assign('op_label', $op_label);
129 $page->assign('op_debit', $op_debit);
130 $page->assign('op_credit', $op_credit);
131 $page->assign('mon_sel', $mon_sel);
133 $page->assign('from_solde', solde_until($from_date));
134 $page->assign('to_solde', solde_until($to_date));
135 $page->assign('month_arr', $mois_fr);
136 $page->assign('ops', XDB
::iterator(
137 "SELECT id, date, label, credit, debit FROM money_trezo
138 WHERE date >= {?} and date <= {?} ORDER BY date",
139 $from_date, $to_date));