noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 07/10: Saved search for accountancy replace f


From: dwm
Subject: [Noalyss-commit] [noalyss] 07/10: Saved search for accountancy replace filter by "Saved search"
Date: Sun, 25 Feb 2024 13:17:51 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit 4496e09703f7956c1a425950b185f47aae30cd6e
Author: Dany wm <danydb@noalyss.eu>
AuthorDate: Tue Feb 20 20:55:09 2024 +0100

    Saved search for accountancy replace filter by "Saved search"
---
 html/ajax_misc.php                                 |   2 +
 html/js/acc_ledger.js                              |  22 +++++
 include/ajax/ajax_search_filter.php                |  29 ++++--
 include/class/acc_ledger_search.class.php          |  52 ++++++++++-
 include/history_operation.inc.php                  |  47 +++++-----
 .../acc_ledger_search-display_list_filter.php      | 103 +++++++++++++++++++++
 include/template/follow_up_filter-display_list.php |   4 +-
 7 files changed, 225 insertions(+), 34 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 5e1261b5b..e79e3b0f8 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -266,6 +266,8 @@ $path = array(
     "save_filter"=>"ajax_search_filter",
     // Load a search filter
     "load_filter"=>"ajax_search_filter",
+    // display a list of filter (alias saved search)
+    "display_list_filter"=>"ajax_search_filter",
     // display tag for filter
     'display_filter_tag'=>'ajax_search_filter',
     // search operation to reconcile
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index 6298d53ad..7ca3b0422 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -1672,6 +1672,28 @@ function reset_filter(p_div) {
     // By default , unpaid is uncked
     $(p_div + "operation_filter").value = "all";
 }
+function display_list_filter(p_dossier,access_code,ledger_type)
+{
+    new Ajax.Request("ajax_misc.php",{
+        parameters:{"gDossier":p_dossier
+            ,"op":"display_list_filter"
+            ,"ac":access_code
+            ,'ledger_type':ledger_type
+        },
+        method:'GET',
+        onSuccess: function (responseHtml) {
+            try {
+                var posy=calcy(250)
+                var div = create_div({"id":"display_list_filter_div",
+                    'cssclass': "inner_box", 'style': 
'width:90%,right:5%;top:'+posy+"px"});
+                div.update(responseHtml.responseText);
+                div.show();
+            }catch (e) {
+                console.error(e.message);
+            }
+        }
+    })
+}
 
 /**
  * propose to duplicate an operation
diff --git a/include/ajax/ajax_search_filter.php 
b/include/ajax/ajax_search_filter.php
index 7301c4ba3..e895707ad 100644
--- a/include/ajax/ajax_search_filter.php
+++ b/include/ajax/ajax_search_filter.php
@@ -111,13 +111,7 @@ if ($op=="load_filter")
     $answer['filter_id']=0;
     $answer['message']="";
     $filter=new User_filter_SQL($cn, $filter_id);
-    $record=$filter->to_array();
-
-    $record['desc']=$record['description'];
-    $record['r_jrn']=explode(",", $record['r_jrn']??"");
-    $record['tag']=explode(",",$record['uf_tag']??"");
-    $record['tag_option']=$record["uf_tag_option"];
-    $record['p_currency_code']=$record['uf_currency_code'];
+    $record=Acc_Ledger_Search::build_array($filter);
     $result=array_merge($answer, $record);
 
 
@@ -227,4 +221,25 @@ if ($op=='display_filter_tag')
             $tag_operation->update_search_cell($div);
         }
     }
+    return;
+}
+//---------------------------------------------------------------------------------------------------------------
+// display_list_filter : display a list of saved search alias filter
+//----------------------------------------------------------------------------------------------------------------
+if ($op=='display_list_filter')
+{
+    echo \HtmlInput::title_box("Recherches sauvées",'display_list_filter_div');
+
+    $ledger_search=new Acc_Ledger_Search($http->request("ledger_type"));
+    $ledger_search->display_list_filter();
+?>
+
+
+    <ul class="aligned-block">
+        <li>
+            <?=\HtmlInput::button_close("display_list_filter_div")?>
+        </li>
+    </ul>
+<?php
+    return;
 }
\ No newline at end of file
diff --git a/include/class/acc_ledger_search.class.php 
b/include/class/acc_ledger_search.class.php
index 786c12914..f070b1248 100644
--- a/include/class/acc_ledger_search.class.php
+++ b/include/class/acc_ledger_search.class.php
@@ -42,7 +42,7 @@ class Acc_Ledger_Search
     /**
      * @brief return a HTML string with the form for the search
      * @param  $p_type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN: uppercase !
-     * @param  $all_type_ledger 
+     * @param  $all_type_ledger
      *       values :
      *         - 1 means all the ledger of this type
      *         - 0 No have the "Tous les journaux" availables
@@ -50,6 +50,8 @@ class Acc_Ledger_Search
      * @param type $p_type
      * @param type $p_all
      * @param type $p_div
+     *
+     * @todo the parameter $all_type_ledger is useless : ALL means all the 
ledgers, VEN all the ledger of sales...
      */
 
     function __construct($p_type, $p_all=1, $p_div="")
@@ -279,7 +281,7 @@ class Acc_Ledger_Search
     function build_name_filter()
     {
         $name=new IText($this->div."filter_new");
-        $name->placeholder=_("Nom du filtre");
+        $name->placeholder=_("Nom de la recherche");
         $r=$name->input();
         $bt=new IButton($this->div."save_ok",_("Ajout"));
         
$bt->javascript=sprintf("save_filter('%s','%s')",$this->div,Dossier::id());
@@ -724,7 +726,7 @@ class Acc_Ledger_Search
         
         $r.=HtmlInput::submit('search', _('Rechercher'));
         
-        $button_search=new IButton("{$this->div}button", _('Filtre'));
+        $button_search=new IButton("{$this->div}button", _('Recherches 
sauvées'));
         $button_search->javascript=$this->build_search_filter();
         $r.=$button_search->input();
         
@@ -1313,4 +1315,48 @@ class Acc_Ledger_Search
         return $ret;
     }
 
+    /**
+     * @brief use a user_filter row and turns it into an array for
+     * javascript purpose
+     * @param User_Filter_SQL $user_filter_sql
+     * @return array
+     */
+    static function build_array(User_Filter_SQL $user_filter_sql)
+    {
+        $record=$user_filter_sql->to_array();
+
+        $record['desc']=$record['description'];
+        $record['r_jrn']=explode(",", $record['r_jrn']??"");
+        $record['tag']=explode(",",$record['uf_tag']??"");
+        $record['tag_option']=$record["uf_tag_option"];
+        $record['p_currency_code']=$record['uf_currency_code'];
+        return $record;
+    }
+
+    /**
+     * @brief build an HTML string with a button to show the list of
+     * saved search
+     * @return string HTML button
+     * @throws Exception if $_REQUEST['ac'] is not set
+     */
+    public  function button_propose_filter()
+    {
+        $http=new HttpInput();
+        $button=HtmlInput::button_action("Recherches sauvées",
+            sprintf("display_list_filter('%s','%s','%s')"
+                ,Dossier::id()
+                , $http->request("ac")
+                ,$this->type
+                ),uniqid(),'smallbutton');
+        return $button;
+    }
+
+    /**
+     * @brief display a list of saved search
+     */
+    public function display_list_filter()
+    {
+       require_once 
NOALYSS_TEMPLATE."/acc_ledger_search-display_list_filter.php";
+
+    }
 }
diff --git a/include/history_operation.inc.php 
b/include/history_operation.inc.php
index 56b8ab3c2..a983cd50a 100644
--- a/include/history_operation.inc.php
+++ b/include/history_operation.inc.php
@@ -32,31 +32,33 @@ global $g_user,$cn,$http;
 $p_array = $_GET;
 $ledger_type=$http->get("ledger_type","string", 'ALL');
 
-$Ledger=new Acc_Ledger_Search($ledger_type,0,'search_op');
 switch($ledger_type)
 {
-        case 'ACH':
-                $ask_pay=1;
-                $p_array['ledger_type']='ACH';
-                break;
-        case 'ODS':
-                $ask_pay=0;
-                $p_array['ledger_type']='ODS';
-                break;
-        case 'ALL':
-                $ask_pay=0;
-                $p_array['ledger_type']='ALL';
-                break;
-        case 'VEN':
-                $ask_pay=1;
-                $p_array['ledger_type']='VEN';
-                break;
-        case 'FIN':
-                $ask_pay=0;
-                $p_array['ledger_type']='FIN';
-                break;
+    case 'ACH':
+            $ask_pay=1;
+            $p_array['ledger_type']='ACH';
+            break;
+    case 'ODS':
+            $ask_pay=0;
+            $p_array['ledger_type']='ODS';
+            break;
+    case 'ALL':
+            $ask_pay=0;
+            $p_array['ledger_type']='ALL';
+            break;
+    case 'VEN':
+            $ask_pay=1;
+            $p_array['ledger_type']='VEN';
+            break;
+    case 'FIN':
+            $ask_pay=0;
+            $p_array['ledger_type']='FIN';
+            break;
+    default:
+        throw new \Exception("HO58 : ledger_type unknown");
 
 }
+$Ledger=new Acc_Ledger_Search($p_array['ledger_type'],0,'search_op');
 echo '<div class="content">';
 // Check privilege
 $p_jrn=$http->request("p_jrn", "string",-1);
@@ -113,8 +115,9 @@ $offset=(isNumber($offset)==0)?0:$offset;
 $bar = navigation_bar($offset, $max_line, $step, $page);
 
 echo $msg;
-echo $Ledger->display_search_form();
+echo $Ledger->button_propose_filter();
 echo HtmlInput::filter_table('history_operation_t', '0,1,2,3,4,5,6,7', 1);
+echo $Ledger->display_search_form();
 echo $bar;
 echo '<form method="GET" id="fpaida" class="print">';
 echo HtmlInput::hidden("ac", $http->request('ac'));
diff --git a/include/template/acc_ledger_search-display_list_filter.php 
b/include/template/acc_ledger_search-display_list_filter.php
new file mode 100644
index 000000000..879b3589d
--- /dev/null
+++ b/include/template/acc_ledger_search-display_list_filter.php
@@ -0,0 +1,103 @@
+<?php
+/*
+*   This file is part of NOALYSS.
+*
+*   NOALYSS is free software; you can redistribute it and/or modify
+*   it under the terms of the GNU General Public License as published by
+*   the Free Software Foundation; either version 2 of the License, or
+*   (at your option) any later version.
+*
+*   NOALYSS is distributed in the hope that it will be useful,
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*   GNU General Public License for more details.
+*
+*   You should have received a copy of the GNU General Public License
+*   along with NOALYSS; if not, write to the Free Software
+*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder danydb@noalyss.eu
+
+/*!
+* \file
+* \brief display a list of saved search for accountancy (alias filter)
+*/
+global $g_user;
+$array=$this->cn->get_array("select id,filter_name,description,ledger_type
+from public.user_filter where login=$1 and ledger_type=$2",
+[$g_user->getLogin(),$this->type]);
+$nb_array=count($array);
+$http=new HttpInput();
+$div="search_op";
+?>
+<p>
+    Cliquez sur un lien pour affiche le résultat de la recherche
+</p>
+
+<?php
+echo \HtmlInput::filter_list("filter_list_acc_ul");
+
+?>
+<ul  id="filter_list_acc_ul" class="list-group m-2" >
+
+<?php
+for ($i=0;$i<$nb_array;$i++):
+?>
+<li class="list-group-item-action" style="background-color: transparent">
+    <?php
+    $user_filter=new \User_filter_SQL($this->cn,$array[$i]["id"]);
+
+    $a_param=array();
+    $a_param["search_opnb_jrn"] = $user_filter->getp("nb_jrn");
+    if ($a_param["search_opnb_jrn"] > 0 ) {
+        $a_param['search_opr_jrn']=explode(",",$user_filter->getp("r_jrn"));
+    }
+    $a_param    ["date_start"] =  $user_filter->getp("date_start");
+    $a_param    ["date_paid_start"] =  $user_filter->getp("date_paid_start");
+    $a_param    ["date_paid_end"] =  $user_filter->getp("date_paid_end");
+    /*[search_opdate_start_hidden] => 01.01.2023
+    [search_opdate_end_hidden] => 31.12.2023*/
+    $a_param["desc"] =$user_filter->getp("description");
+    $a_param["amount_min"] = $user_filter->getp("amount_min");
+    $a_param["amount_max"] = $user_filter->getp("amount_max");
+    $a_param["search_opqcode"] =$user_filter->getp("qcode");
+    $a_param["accounting"] = $user_filter->getp("accounting");
+    $a_param["tva_id_search"] = $user_filter->getp("tva_id_search");
+    $a_param["operation_filter"] = $user_filter->getp("operation_filter");
+    $a_param["p_currency_code"] = $user_filter->getp("uf_currency_code");
+    $a_param["search_optag_option"] =$user_filter->getp("uf_tag_option");
+    if ( $user_filter->getp("uf_tag") != "") {
+        $a_param["search_optag"]=explode(",",$user_filter->getp("uf_tag"));
+    }
+    $a_param['search_opqcode']=$user_filter->getp('qcode');
+    $a_param['ledger_type']=$array[$i]['ledger_type'];
+
+    $a_param['ac']=$http->request("ac");
+    $a_param['gDossier']=$http->request("gDossier","number");
+    $url="do.php?".http_build_query($a_param);
+    ?>
+    <a class="line" href="<?=$url?>">
+    <span class="search-content">
+    <?=$array[$i]['filter_name']?>  <?=h($array[$i]['description'])?>
+
+    </span>
+    </a>
+</li>
+<?php
+endfor;
+?>
+</ul>
+    <ul  class="list-group m-2" >
+    <li class="list-group-item-action" style="background-color: transparent">
+    <?php
+    $a_param=array();
+    $a_param['ac']=$http->request("ac");
+    $a_param['gDossier']=$http->request("gDossier","number");
+    $url="do.php?".http_build_query($a_param);
+    ?>
+    <a class="line" href="<?=$url?>">
+       Aucun filtre
+    </a>
+    </li>
+
+</ul>
diff --git a/include/template/follow_up_filter-display_list.php 
b/include/template/follow_up_filter-display_list.php
index 01fe4f112..56abaafdd 100644
--- a/include/template/follow_up_filter-display_list.php
+++ b/include/template/follow_up_filter-display_list.php
@@ -35,7 +35,7 @@ from action_gestion_filter
 where af_user=$1 
 order by lower(af_name)", [$login]);
 if (count($a_list) == 0) {
-    echo_warning("Aucun filtre");
+    echo_warning("Aucune recherche sauvée");
     echo \HtmlInput::button_close($div);
     return;
 }
@@ -43,7 +43,7 @@ if (count($a_list) == 0) {
 
 ?>
 <p>
-    Cliquer sur un filtre pour chercher
+    Cliquez sur un lien pour affiche le résultat de la recherche
 </p>
 <?php
 echo \HtmlInput::filter_list("filter_list_ul");



reply via email to

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