noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 164/323: Periode : change with exercice


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 164/323: Periode : change with exercice
Date: Wed, 14 Mar 2018 17:38:43 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit a73bac90844d86c39dec15acf472a0def01bba84
Author: Dany De Bontridder <address@hidden>
Date:   Fri Feb 9 21:27:33 2018 +0100

    Periode : change with exercice
---
 html/ajax_misc.php      | 41 +++++++++++++++++++++++++++++++++++++++++
 html/js/scripts.js      | 20 +++++++++++++++++++-
 include/balance.inc.php | 13 +++++++++++--
 3 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 1432864..2d995b4 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -245,6 +245,47 @@ if (array_key_exists($op, $path)) {
 }
 switch ($op)
 {
+    case "periode_change":
+        $field=$http->get("field");
+        $type=$http->get("type");
+        $exercice=$http->get("exercice","number");
+        $last=$http->get("last","number");
+        
+        // if last == 1 then show first and last periode of the 
+        // exercice
+        $periode_start=0;
+        $periode_end=0;
+        if ( $last==1) {
+            $t_periode=new Periode($cn);
+            list($per_max,$per_min)=$t_periode->get_limit($exercice);
+            $periode_start=$per_max->p_id;
+            $periode_end=$per_min->p_id;
+        }
+        
+        $iperiod = new IPeriod($field);
+        $iperiod->id=$field;
+        $iperiod->user = $g_user;
+        $iperiod->cn = $cn;
+        $iperiod->filter_year = true;
+        $iperiod->exercice=$exercice;
+        if ( $type=="from")
+        {
+            $iperiod->show_end_date=FALSE;
+            $iperiod->value=$periode_start;
+        } elseif ($type=="to"){
+            $iperiod->show_start_date=FALSE;
+            $iperiod->value=$periode_end;
+            
+        } else {
+            throw new Exception(_("Invalide type"));
+        }
+        
+        $iperiod->type = ALL;
+        echo $iperiod->input();
+        
+        return;
+        
+        break;
     case "pref_exercice":
         $iperiod = new IPeriod("period");
         $iperiod->id="setting_period";
diff --git a/html/js/scripts.js b/html/js/scripts.js
index f232c19..e278eb8 100644
--- a/html/js/scripts.js
+++ b/html/js/scripts.js
@@ -3485,6 +3485,24 @@ function progress_bar_check(p_idx, p_taskid)
  */
 function updatePeriodePreference(p_dossier)
 {
+    waiting_box();
     var exercice=$('exercice_setting').value;
     new 
Ajax.Updater('setting_period',"ajax_misc.php",{method:"get",parameters:{ 
"op":"pref_exercice","gDossier":p_dossier,"exercice":exercice}});  
-}
\ No newline at end of file
+    remove_waiting_box();
+}
+/**
+ * Update the from and to periode list when changing the exercice
+ * @param {int} p_dossier
+ * @param {string} p_exercice id of the exercice
+ * @param {type} p_periode_from id of the starting periode
+ * @param {type} p_periode_to id of the ending periode
+ * @param {type} p_last possible value = 1 to show last periode or 0 the first
+ */
+function updatePeriode(p_dossier,p_exercice,p_periode_from,p_periode_to,p_last)
+{
+    waiting_box();
+    var exercice=$(p_exercice).value;
+    new 
Ajax.Updater(p_periode_from,"ajax_misc.php",{method:"get",parameters:{op:"periode_change","gDossier":p_dossier,"exercice":exercice,field:p_periode_from,"type":"from","last":p_last}});
+    new 
Ajax.Updater(p_periode_to,"ajax_misc.php",{method:"get",parameters:{op:"periode_change","gDossier":p_dossier,"exercice":exercice,field:p_periode_to,"type":"to","last":p_last}});
+    remove_waiting_box();
+}
diff --git a/include/balance.inc.php b/include/balance.inc.php
index 92db13b..dfab085 100644
--- a/include/balance.inc.php
+++ b/include/balance.inc.php
@@ -35,7 +35,13 @@ require_once NOALYSS_INCLUDE.'/class/periode.class.php';
 require_once NOALYSS_INCLUDE.'/class/exercice.class.php';
 global $g_user, $http;
 $gDossier=dossier::id();
-$exercice=(isset($_GET['exercice']))?$_GET['exercice']:$g_user->get_exercice();
+
+// Get the exercice
+$exercice=$http->get("exercice","number",0);
+if ($exercice == 0 ){
+    $exercice=$g_user->get_exercice();
+}
+
 bcscale(2);
 
 echo '<div class="content">';
@@ -46,7 +52,8 @@ echo '<fieldset  
class="noprint"><legend>'._('Exercice').'</legend>';;
 echo '<form method="GET">';
 echo _('Choisissez un autre exercice')." : ";
 $ex=new Exercice($cn);
-$wex=$ex->select('exercice',$exercice,' onchange="submit(this)"');
+$js=sprintf("updatePeriode(%d,'%s','%s','%s',1)",Dossier::id(),'exercice','from_periode','to_periode');
+$wex=$ex->select('exercice',$exercice,' onchange="'.$js.'"');
 echo $wex->input();
 echo dossier::hidden();
 echo HtmlInput::get_to_hidden(array('ac','type'));
@@ -66,6 +73,7 @@ echo dossier::hidden();
 // filter on the current year
 $from=$http->get("from_periode", "number",0);
 $input_from=new IPeriod("from_periode",$from,$exercice);
+$input_from->id="from_periode";
 $input_from->show_end_date=false;
 $input_from->type=ALL;
 $input_from->cn=$cn;
@@ -83,6 +91,7 @@ if( $to == 0) {
      $to=$per_min->p_id;
 }
 $input_to=new IPeriod("to_periode",$to,$exercice);
+$input_to->id="to_periode";
 $input_to->show_start_date=false;
 $input_to->filter_year=true;
 $input_to->type=ALL;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]