From 3dc23f672021fed2090a80d63329f6d4d5705131 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 17 Jan 2011 20:53:48 +0000 Subject: [PATCH] Task 198 : add a button to change year in history of a card or account --- html/ajax_history.php | 152 +++++++++++++++++++++++++++---------- html/js/acc_ledger.js | 40 ++++++++++ html/popup.php | 8 +- include/class_exercice.php | 59 ++++++++++++++ 4 files changed, 220 insertions(+), 39 deletions(-) create mode 100644 include/class_exercice.php diff --git a/html/ajax_history.php b/html/ajax_history.php index 056dac545..96b013682 100644 --- a/html/ajax_history.php +++ b/html/ajax_history.php @@ -1,36 +1,37 @@ get_exercice(); if ( $year == 0 ) - { + { $html="erreur aucune période par défaut, allez dans préférence pour en choisir une"; - } + } else - { + { $per=new Periode($cn); $limit_periode=$per->get_limit($year); $array['from_periode']=$limit_periode[0]->first_day(); $array['to_periode']=$limit_periode[1]->last_day(); + if (isset($_GET['ex'])) + { + $limit_periode=$per->get_limit($_GET['ex']); + $array['from_periode']=$limit_periode[0]->first_day(); + } + + /* + * Add button to select another year + */ + if ($exercice->count() > 1 ) + { + $default=(isset($_GET['ex']))?$_GET['ex']:$year; + $dossier=dossier::id(); + if ( $div != 'popup') + { + $obj="{div:'$div',f_id:'".$_GET['f_id']."',gDossier:'$dossier',select:this}"; + $is=$exercice->select('p_exercice',$default,' onchange="update_history_card('.$obj.');"'); + $old="Autre exercice ".$is->input(); + } + else + { + $old='
'; + $is=$exercice->select('ex',$default,'onchange = "submit(this)"'); + $old.="Autre exercice ".$is->input(); + $old.=HtmlInput::hidden('div','popup'); + $old.=HtmlInput::hidden('act',$_GET['act']); + $old.=HtmlInput::hidden('f_id',$_GET['f_id']); + $old.=HtmlInput::hidden('ajax',$_GET['ajax']); + $old.=dossier::hidden(); + $old.='
'; + } + } ob_start(); require_once('template/history_top.php'); if ( $fiche->HtmlTable($array)==-1){ - echo h2info("Aucun opération pour l'exercice courant"); + echo h2info( $fiche->getName().'['.$fiche->strAttribut(ATTR_DEF_QUICKCODE).']'); + echo h2("Aucun opération pour l'exercice courant",'class="error"'); } + echo $old; + $html=ob_get_contents(); ob_clean(); - } -} + } + } /////////////////////////////////////////////////////////////////////////// // for an account /////////////////////////////////////////////////////////////////////////// if ( isset($_REQUEST['pcm_val'])) -{ + { $poste=new Acc_Account_Ledger($cn,$_REQUEST['pcm_val']); $year=$user->get_exercice(); if ( $year == 0 ) - { + { $html="erreur aucune période par défaut, allez dans préférence pour en choisir une"; - } + } else - { + { + $exercice=new Exercice($cn); + $old=''; $per=new Periode($cn); $limit_periode=$per->get_limit($year); $array['from_periode']=$limit_periode[0]->first_day(); $array['to_periode']=$limit_periode[1]->last_day(); + if (isset($_GET['ex'])) + { + $limit_periode=$per->get_limit($_GET['ex']); + $array['from_periode']=$limit_periode[0]->first_day(); + } + /* + * Add button to select another year + */ + if ($exercice->count() > 1 ) + { + $default=(isset($_GET['ex']))?$_GET['ex']:$year; + $dossier=dossier::id(); + if ( $div != 'popup') + { + $obj="{div:'$div',pcm_val:'".$_GET['pcm_val']."',gDossier:'$dossier',select:this}"; + $is=$exercice->select('p_exercice',$default,' onchange="update_history_account('.$obj.');"'); + $old="Autre exercice ".$is->input(); + } + else + { + $old='
'; + $is=$exercice->select('ex',$default,'onchange = "submit(this)"'); + $old.="Autre exercice ".$is->input(); + $old.=HtmlInput::hidden('div','popup'); + $old.=HtmlInput::hidden('act',$_GET['act']); + $old.=HtmlInput::hidden('pcm_val',$_GET['pcm_val']); + $old.=HtmlInput::hidden('ajax',$_GET['ajax']); + $old.=dossier::hidden(); + $old.='
'; + } + + } ob_start(); require_once('template/history_top.php'); + if ( $poste->HtmlTable($array) == -1) { - echo h2info("Aucun opération pour l'exercice courant"); + echo h2info($poste->id." ".$poste->name); + echo h2("Aucun opération pour l'exercice courant",'class="error"'); } + echo $old; + $html=ob_get_contents(); ob_clean(); - } -} + } + } $html=escape_xml($html); header('Content-type: text/xml; charset=UTF-8'); echo <<'.HtmlInput::print_window(); html_page_start($_SESSION['g_theme']); + if ( basename($_GET['ajax']) == 'ajax_history.php' ) { $href=dossier::get(); @@ -24,7 +25,12 @@ if ( basename($_GET['ajax']) == 'ajax_history.php' ) $from_periode='from_periode='.format_date($limit[0]->p_start); $to_periode='to_periode='.format_date($limit[1]->p_end); - + if (isset($_GET['ex'])) + { + $limit_periode=$periode->get_limit($_GET['ex']); + $from_periode='from_periode='.format_date($limit_periode[0]->p_start); + } + if (isset($_GET['pcm_val']) ) { $href_csv="poste_csv.php?".$href.'&poste_id='.$_GET['pcm_val'].'&ople=0&type=poste&'.$from_periode.'&'.$to_periode; diff --git a/include/class_exercice.php b/include/class_exercice.php new file mode 100644 index 000000000..b3f3d558d --- /dev/null +++ b/include/class_exercice.php @@ -0,0 +1,59 @@ +cn=$cn; + } + /** + *return the number of different exercices into a folder + *@param $cn is the database connexion object database + *@return the count of exercice + */ + function count() + { + $count=$this->cn->get_value('select count(distinct p_exercice) from parm_periode'); + return $count; + } + /** + *Show a ISelect with the different exercices + *@param $name of the iselect + *@param $selected the selected year (default = '') + *@param $js javascript (default = '') + *@return ISelect object + */ + function select($name,$selected='',$js='') + { + $iselect=new ISelect($name); + $iselect->value=$this->cn->make_array('select distinct p_exercice,p_exercice from parm_periode order by 1'); + $iselect->selected=$selected; + $iselect->javascript=$js; + return $iselect; + } +}