From: Pierre Habouzit (MadCoder Date: Mon, 13 Dec 2004 00:30:28 +0000 (+0000) Subject: refactor trezo/gere_operations X-Git-Tag: xorg/old~673 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=6ec9a7e445d4bcb38bf39d24df207bb996d5091d;p=platal.git refactor trezo/gere_operations git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-75 --- diff --git a/htdocs/trezo/gere_operations.php b/htdocs/trezo/gere_operations.php index 8160241..325794b 100644 --- a/htdocs/trezo/gere_operations.php +++ b/htdocs/trezo/gere_operations.php @@ -23,88 +23,69 @@ require_once('xorg.inc.php'); require_once("money/trezo.inc.php"); new_admin_page('trezo/gere_operations.tpl'); -//Table operations : -//+--------+---------------+------+-----+------------+----------------+ -//| Field | Type | Null | Key | Default | Extra | -//+--------+---------------+------+-----+------------+----------------+ -//| id | int(11) | | PRI | NULL | auto_increment | -//| date | date | | | 0000-00-00 | | -//| label | varchar(80) | | | | | -//| credit | decimal(10,2) | | | 0.00 | | -//| debit | decimal(10,2) | | | 0.00 | | -//+--------+---------------+------+-----+------------+----------------+ - -$action = clean_request('action'); -$operation_id = clean_request('operation_id'); -$operation_date = clean_request('operation_date'); -$operation_label = clean_request('operation_label'); -$operation_credit = clean_request('operation_credit'); -$operation_debit = clean_request('operation_debit'); +$action = clean_request('action'); +$op_id = clean_request('op_id'); +$op_date = clean_request('op_date'); +$op_label = clean_request('op_label'); +$op_credit = clean_request('op_credit'); +$op_debit = clean_request('op_debit'); $annee_sel = isset($_REQUEST['annee']) ? $_REQUEST['annee'] : date("Y"); $mois_sel = isset($_REQUEST['mois']) ? $_REQUEST['mois'] : sprintf("%02u", date('m')); -$from_date = "$annee_sel-$mois_sel-01"; -$to_date = "$annee_sel-$mois_sel-31"; -$mon_sel = $trim_fr[$mois_sel]." $annee_sel"; +$from_date = "$annee_sel-$mois_sel-01"; +$to_date = "$annee_sel-$mois_sel-31"; +$mon_sel = $trim_fr[$mois_sel]." $annee_sel"; switch($action) { case "edit": - if ($operation_id) { - $res=$globals->db->query("select date,label,credit,debit from money_trezo where id='$operation_id'"); - list($operation_date,$operation_label,$operation_credit,$operation_debit)=mysql_fetch_row($res); + if ($op_id) { + $res=$globals->db->query("select date,label,credit,debit from money_trezo where id='$op_id'"); + list($op_date,$op_label,$op_credit,$op_debit)=mysql_fetch_row($res); } - break; + break; + case "update": - $operation_date = clean_request('operation_date'); - $operation_label = clean_request('operation_label'); - $operation_credit = clean_request('operation_credit'); - $operation_debit = clean_request('operation_debit'); - $sql_add = ""; + if (isDate($op_date)){ + $mydatefr = explode("/",$op_date); + $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0]; + } else { + $mydate = date("Y-m-d"); + } - if ($operation_credit) - $sql_add = ',credit='.$operation_credit; - if ($operation_debit) - $sql_add = $sql_add.",debit=".$operation_debit; + $sql = "replace into money_trezo set date='$mydate',label='$op_label'"; - if (isDate($operation_date)){ - $mydatefr = explode("/",$operation_date); - $mydate = $mydatefr[2]."-".$mydatefr[1]."-".$mydatefr[0]; - }else{ - $mydate = date("Y-m-d"); - } + if ($op_credit) { $sql .= ',credit='.$op_credit; } + if ($op_debit) { $sql .= ",debit=".$op_debit; } + if ($op_id) { $sql .= ",id='$op_id'"; } + + $globals->db->query($sql); + break; - if ($operation_id) { - $sql = "update money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add." where id='".$operation_id."'"; - } else { - $sql = "insert into money_trezo set date='".$mydate."',label='".$operation_label."'".$sql_add; - } - break; case "del": - if ($operation_id) { - $globals->db->query("delete from money_trezo where id='".$operation_id."'"); + if ($op_id) { + $globals->db->query("delete from money_trezo where id='".$op_id."'"); } - break; - -} // $action + break; +} -$page->assign('operation_id', $operation_id); +$page->assign('op_id', $op_id); $page->assign('annee_sel', $annee_sel); -$page->assign('mois_sel', $mois_sel); -$page->assign('operation_date', $operation_date); -$page->assign('operation_label', $operation_label); -$page->assign('operation_debit', $operation_debit); -$page->assign('operation_credit', $operation_credit); -$page->assign('mon_sel', $mon_sel); +$page->assign('mois_sel', $mois_sel); +$page->assign('op_date', $op_date); +$page->assign('op_label', $op_label); +$page->assign('op_debit', $op_debit); +$page->assign('op_credit', $op_credit); +$page->assign('mon_sel', $mon_sel); $page->assign('from_solde', solde_until($from_date)); -$page->assign('to_solde', solde_until($to_date)); +$page->assign('to_solde', solde_until($to_date)); $page->assign_by_ref('month_arr', $mois_fr); -$sql = "SELECT id,date,label,credit,debit - FROM money_trezo - WHERE date >= '$from_date' AND date <= '$to_date' - ORDER BY date"; +$sql = "SELECT id,date,label,credit,debit + FROM money_trezo + WHERE date >= '$from_date' AND date <= '$to_date' + ORDER BY date"; $page->mysql_assign($sql, 'ops'); $page->run(); diff --git a/templates/trezo/gere_operations.tpl b/templates/trezo/gere_operations.tpl index e9c1676..3067add 100644 --- a/templates/trezo/gere_operations.tpl +++ b/templates/trezo/gere_operations.tpl @@ -30,7 +30,7 @@ - + - + - + - +
- {if $operation_id} + {if $op_id} Modifier une opération {else} Ajouter une opération @@ -39,24 +39,24 @@
Date (DD/MM/YYYY)
Description libre
Débit
Crédit
- + @@ -67,7 +67,7 @@ retour -{elseif $smarty.request.action eq "update" && $operation_id} +{elseif $smarty.request.action eq "update" && $op_id} modification de l'opération {elseif $smarty.request.action eq "update"} ajout de l'opération @@ -109,7 +109,7 @@
- + @@ -128,7 +128,7 @@
- +