noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 195/219: Task #001381 : favori de filtre , aj


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 195/219: Task #001381 : favori de filtre , ajout des favoris de filtre dans les recherches.
Date: Mon, 18 Dec 2017 13:23:02 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 6152d092fbbd038aaecb9257edf68a8e54a7ad3c
Author: Dany De Bontridder <address@hidden>
Date:   Sun Dec 10 14:00:37 2017 +0100

    Task #001381 : favori de filtre , ajout des favoris de filtre dans les
    recherches.
---
 html/ajax_misc.php                                 |   18 +-
 html/js/acc_ledger.js                              |  156 +++
 html/recherche.php                                 |    7 +-
 html/test.php                                      |    2 +-
 include/ajax/ajax_search_filter.php                |  182 ++++
 .../ajax_search_operation.php}                     |   14 +-
 include/class/acc_ledger.class.php                 |  924 +----------------
 include/class/acc_ledger_search.class.php          | 1040 ++++++++++++++++++++
 include/database/user_filter_sql.class.php         |   92 ++
 include/history_operation.inc.php                  |   10 +-
 include/template/ledger_search.php                 |   13 +-
 ...test-iselect-button.php => select-box-test.php} |   15 +-
 12 files changed, 1522 insertions(+), 951 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index 0bc48cb..1eb27c9 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -196,7 +196,17 @@ $path = array(
     // Update, insert or delete accounting frmo CFGPCMN
     "accounting"=>"ajax_accounting",
     // Show detail of an ANC operation
-    "anc_detail_op"=>"ajax_anc_detail_operation"
+    "anc_detail_op"=>"ajax_anc_detail_operation",
+    // Display the list of filter saved
+    "display_search_filter"=>"ajax_search_filter",
+    // Save search filter 
+    "save_filter"=>"ajax_search_filter",
+    // Load a search filter
+    "load_filter"=>"ajax_search_filter",
+    // search operation to reconcile
+       'search_op'=>'ajax_search_operation',
+    // delete operation
+       'delete_search_operation'=>'ajax_search_filter'
 )    ;
 
 if (array_key_exists($op, $path)) {
@@ -406,9 +416,7 @@ EOF;
 EOF;
 
                break;
-       case 'search_op':
-               require_once NOALYSS_INCLUDE.'/search.inc.php';
-               break;
+
        case 'add_plugin':
                $me_code = new IText('me_code');
                $me_file = new IText('me_file');
@@ -451,5 +459,5 @@ EOF;
             break;
         
        default:
-               var_dump($_GET);
+               var_dump($_REQUEST);
 }
diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js
index 817dfd7..a2de0db 100644
--- a/html/js/acc_ledger.js
+++ b/html/js/acc_ledger.js
@@ -1215,3 +1215,159 @@ function document_remove(p_dossier,p_div,p_jrid)
         }
     });
 }
+/***
+ * @brief receive an object and display a list of filter + form to save one
+ * fill up the span (id : {div}search_filter_span) with the name of the 
selected filter
+ * Object = '{'div':'','type':'ALL','all_type':1,'dossier':'10104'}' 
+ * @see Acc_Ledger_Search
+ */
+function manage_search_filter(p_obj) {
+    waiting_box();
+    new Ajax.Request("ajax_misc.php", {
+       method:'get',
+       
parameters:{"op":"display_search_filter","gDossier":p_obj.dossier,"div":p_obj.div,"ledger_type":p_obj.ledger_type,"all_type":p_obj.all_type},
+       onSuccess:function(req) {
+            remove_waiting_box();
+            var x=posX;
+            var y=posY-20;
+            
create_div({'id':'boxfilter'+p_obj.div,'cssclass':'inner_box','html':req.responseText,'style':'top:'+y+'px;left:'+x+'px;position:absolute;width:400px'});
+            $('boxfilter'+p_obj.div).show();
+       }
+    });
+}
+
+/**
+ * Send data from the form and record a new filter , the ajax answer is a json 
object
+ * with the attribute filter_name,filter_id,status,message
+ * 
+ * @param p_div prefix id of all concerned DOM Element
+ * @param p_dossier 
+ * @see Acc_Ledger_Search
+ */
+function save_filter(p_div,p_dossier) {
+    var 
elt=['ledger_type','nb_jrn','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting'];
+    var eltValue={};
+    eltValue['gDossier']=p_dossier;
+    eltValue['op']="save_filter";
+    eltValue['div']=p_div;
+    eltValue['filter_name']=$(p_div+"filter_new").value;
+    // Get all elt from the form
+    for ( var i = 0 ; i < elt.length;i++) {
+        var idx=elt[i];
+        eltValue[idx]=$(p_div+elt[i]).value;
+   
+    }
+    //ledger's list r_jrn
+    if (eltValue['nb_jrn'] > 0) {
+        eltValue['r_jrn']=[];
+        for (i=0;i<eltValue['nb_jrn'];i++) {
+            var idx=p_div+'r_jrn['+i+']';
+            eltValue['r_jrn'+i]=$(idx).value
+   
+        }
+    }
+    //unpaid
+    eltValue['unpaid']=$(p_div+"unpaid").checked;
+    new Ajax.Request('ajax_misc.php', {
+        method:"POST",
+        parameters:eltValue,
+        onSuccess:function (req) {
+            try {
+                var answer=req.responseJSON;
+                if ( answer.status == 'OK') {
+                    var new_item=document.createElement('li');
+                    new_item.innerHTML=answer.filter_name;
+                    $(p_div+'button_list').appendChild(new_item);
+                    $(p_div+"filter_new").value="";
+                } else {
+                    throw answer.message;
+                }
+            } catch (e) {
+                smoke.alert(e.message);
+            }
+        }
+    });
+}
+/**
+ * Load a search filter  and fill up the form search
+ * @param p_div prefix id of all concerned DOM Element
+ * @param p_dossier 
+ * @param p_filter_id filter id (SQL user_filter.id)
+ * @see Acc_Ledger_Search
+ */
+function load_filter(p_div,p_dossier,p_filter_id) {
+    new Ajax.Request('ajax_misc.php',{
+       method:"get",
+       
parameters:{"gDossier":p_dossier,"div":p_div,"op":"load_filter","filter_id":p_filter_id},
+       onSuccess:function (req) {
+           try {
+                var answer=req.responseJSON;    
+                console.log(answer);
+                var 
elt=['ledger_type','date_start','date_end','date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting'];
+                for (var i=0;i<elt.length;i++) {
+                    var idx=elt[i];
+                    $(p_div+idx).value=answer[elt[i]]
+                }
+               // fillup the r_jrn array
+               var eltLedgerId=$("ledger_id"+p_div);
+               eltLedgerId.innerHTML="";
+               var eltHidden=document.createElement("input");
+               eltHidden.setAttribute("name",p_div+"nb_jrn");
+               eltHidden.setAttribute("type","hidden");
+               eltHidden.setAttribute("id",p_div+"nb_jrn");
+               eltHidden.setAttribute("value",answer.nb_jrn);
+               eltLedgerId.appendChild(eltHidden);  
+               
+               for ( var i=0;i < answer.nb_jrn;i++) {
+                   // create hidden element and add them into eltLedgerId
+                   var eltHidden=document.createElement("input");
+                   
+                   eltHidden.setAttribute("name",p_div+"r_jrn["+i+"]");
+                   eltHidden.setAttribute("type","hidden");
+                   eltHidden.setAttribute("id",p_div+"r_jrn["+i+"]");
+                   eltHidden.setAttribute("value",answer.r_jrn[i]);
+                   eltLedgerId.appendChild(eltHidden);
+               }
+               if ( answer.unpaid == 'false') {
+                   $(p_div+"unpaid").checked=false;
+               }
+               if ( answer.unpaid == 'true') {
+                   $(p_div+"unpaid").checked=true;
+               }
+
+               
+           } catch (e) {
+              smoke.alert(e.message);
+           }
+           
+       }
+    });
+}
+/**
+ * @brief delete a saved search filter  from the db, it is limited to the 
current
+ * user
+ * @parameter p_div
+identification des elements LI manageli{div}_{filter_id}
+identification element UL manage{div}
address@hidden p_filter_id SQL user_filter.id
+*/
+
+function delete_filter (p_div,p_dossier,p_filter_id) {
+    new Ajax.Request("ajax_misc",{
+        
parameters:{"gDossier":p_dossier,"div":p_div,"filter_id":p_filter_id,'op':"delete_search_operation"},
+        method:"POST",
+        onSuccess:function (req) {
+            try {
+            var answer=req.evalJSON;
+           
+            var child=$("manageli"+p_div+"_"+p_filter_id);
+                console.log(child)
+                if ( child )  {$("manage"+p_div).removeChild(child); }
+            }catch (e) {
+                console.log(e.message)
+            }
+            
+        }
+    })
+    
+}     
\ No newline at end of file
diff --git a/html/recherche.php b/html/recherche.php
index e56e16f..eb1ae08 100644
--- a/html/recherche.php
+++ b/html/recherche.php
@@ -20,10 +20,12 @@
 /*! \file
  * \brief Search module
  */
+define('ALLOWED',TRUE);
 require_once '../include/constant.php';
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 include_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
+require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
 
 html_page_start($_SESSION['g_theme']);
 
@@ -55,9 +57,8 @@ if ( $act=='X')
   }
 // display a search box
 
-$ledger=new Acc_Ledger($cn,0);
-$ledger->type='ALL';
-$search_box=$ledger->search_form('ALL',1);
+$ledger=new Acc_Ledger_Search('ALL');
+$search_box=$ledger->search_form();
 echo '<div class="content">';
 
 echo '<form method="GET">';
diff --git a/html/test.php b/html/test.php
index 41c0b0b..2d8265f 100644
--- a/html/test.php
+++ b/html/test.php
@@ -63,7 +63,7 @@ if (!file_exists('authorized_debug'))
     exit();
 }
 define('ALLOWED', 1);
-html_page_start();
+html_page_start("Classic 692");
 
 /*
  * Loading of all scenario
diff --git a/include/ajax/ajax_search_filter.php 
b/include/ajax/ajax_search_filter.php
new file mode 100644
index 0000000..c742a25
--- /dev/null
+++ b/include/ajax/ajax_search_filter.php
@@ -0,0 +1,182 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta 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.
+ *
+ *   PhpCompta 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 PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2016) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+require NOALYSS_INCLUDE.'/database/user_filter_sql.class.php';
+$cn=Dossier::connect();
+$dossier_id=Dossier::id();
+global $g_user;
+/**
+ * @file
+ * @brief Managed the search filter
+ */
+$http=new HttpInput();
+//---------------------------------------------------------------------------
+// Record the the search filter
+//---------------------------------------------------------------------------
+$op=$http->request("op");
+if ($op=='save_filter')
+{
+    $answer=[];
+    $answer['filter_name']="";
+    $answer['status']='NOK';
+    $answer['filter_id']=0;
+    $answer['message']="";
+    try
+    {
+        $new=new User_filter_SQL($cn, -1);
+        $new->setp("login", $g_user->login);
+        $new->setp("nb_jrn", $http->post("nb_jrn", 'number'));
+        $new->setp("date_start", $http->post("date_start", 'string', NULL));
+        $new->setp("date_end", $http->post("date_end", 'string', NULL));
+        $new->setp("description", $http->post("desc", 'string', NULL));
+        $new->setp("amount_min", $http->post("amount_min", 'number', NULL));
+        $new->setp("amount_max", $http->post("amount_max", 'number', NULL));
+        $new->setp("qcode", $http->post("qcode", 'string', NULL));
+        $new->setp("accounting", $http->post("accounting", 'string', NULL));
+        $new->setp("date_paid_start",
+                $http->post("date_paid_start", 'string', NULL));
+        $new->setp("date_paid_end", $http->post("date_paid_end", 'string', 
NULL));
+        $new->setp("ledger_type", $http->post("ledger_type", 'string'));
+        $new->setp("unpaid", $http->post("unpaid", 'string', NULL));
+        $new->setp("filter_name", h($http->post("filter_name", 'string')));
+        $aJrn=[];
+        $max=$http->post("nb_jrn");
+        for ($i=0; $i<$max; $i++)
+        {
+            $aJrn[]=$http->post("r_jrn".$i, "number");
+        }
+        $new->setp("r_jrn", join(',', $aJrn));
+        if (strlen($new->getp("filter_name"))==0)
+        {
+            throw new Exception(_("Nom ne peut être vide"));
+        }
+        $new->save();
+        $answer['filter_name']=sprintf("<a 
onclick=\"load_filter('%s','%s','%s')\">%s</a>",
+                trim($http->post('div')), $dossier_id, $new->getp('id'),
+                $new->getp("filter_name"));
+        $answer['filter_id']=$new->getp("id");
+        $answer['status']='OK';
+    }
+    catch (Exception $ex)
+    {
+        $answer['status']='NOK';
+        $answer['message']=$ex->getMessage();
+    }
+    header('Content-Type: application/json;charset=utf-8');
+    echo json_encode($answer);
+    return;
+}
+//------------------------------------------------------------------------------
+// Load a filter
+//------------------------------------------------------------------------------
+if ($op=="load_filter")
+{
+    $filter_id=$http->get("filter_id", "number");
+    $div=$http->get("div");
+    $answer=[];
+    $answer['status']='OK';
+    $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']);
+
+    $result=array_merge($answer, $record);
+
+
+    header('Content-Type: application/json;charset=utf-8');
+    echo json_encode($result);
+    return;
+}
+//-----------------------------------------------------------------------------
+// Display all the existing search filters and allow to load or delete them
+// id of the box is "boxfilter"+{p_div}
+//------------------------------------------------------------------------------
+if ($op=="display_search_filter")
+{
+    $p_div=$http->get("div");
+    $ledger_type=$http->get("ledger_type");
+
+    echo HtmlInput::title_box(_("Filtre"), "boxfilter".$p_div);
+    // Make a list of all search filters with the same ledger_type of the 
current
+    // user
+    $result=$cn->get_array("
+        select id, filter_name,ledger_type 
+        from user_filter 
+        where
+        login = $1 
+        and ledger_type=$2
+        order by 2 asc
+", [$g_user->login, $ledger_type]);
+    $nb_result=count($result);
+    printf('<ul class="select_table" id="manage%s">', $p_div);
+    for ($i=0; $i<$nb_result; $i++)
+    {
+        printf(' <li id="manageli%s_%d">', $p_div, $result[$i]["id"]);
+        $rmAction=sprintf("delete_filter('%s','%s','%s')", $p_div, $dossier_id,
+                $result[$i]['id']);
+        printf('<a class="tinybutton" style="display:inline" id="" 
onclick="'.$rmAction.'">'.SMALLX.'</a>'
+        );
+        printf("<a style=\"display:inline\" 
onclick=\"load_filter('%s','%s','%s')\">",
+                $p_div, $dossier_id, $result[$i]["id"]);
+        echo $result[$i]["filter_name"];
+        echo '</a>';
+
+        printf("</li>");
+    }
+    return;
+}
+//-----------------------------------------------------------------------------
+// Delete a filter_id 
+// Check if this filter belong to current user
+//------------------------------------------------------------------------------
+if ($op=="delete_search_operation")
+{
+    $answer=[];
+    $answer['filter_name']="";
+    $answer['status']='NOK';
+    $answer['filter_id']=0;
+    $answer['message']="";
+    try
+    {
+        $p_div=$http->post("div");
+        $filter_id=$http->post("filter_id", "number");
+
+        $answer['div']=$p_div;
+
+        $cn->exec_sql("delete from user_filter where id=$1 and 
login=$2",[$filter_id,$g_user->login]);
+        
+        $answer['filter_id']=$filter_id;
+        $answer['status']="OK";
+    }
+    catch (Exception $ex)
+    {
+        $answer['message']=$ex->getMessage();
+    }
+    header('Content-Type: application/json;charset=utf-8');
+    echo json_encode($answer);
+    return;
+}
\ No newline at end of file
diff --git a/include/search.inc.php b/include/ajax/ajax_search_operation.php
similarity index 92%
rename from include/search.inc.php
rename to include/ajax/ajax_search_operation.php
index b59d2e6..b183d48 100644
--- a/include/search.inc.php
+++ b/include/ajax/ajax_search_operation.php
@@ -23,7 +23,7 @@
 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
 require_once NOALYSS_INCLUDE.'/class/dossier.class.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
-require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
+require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
 
 global $ĥttp;
 $gDossier=dossier::id();
@@ -38,17 +38,15 @@ require_once  NOALYSS_INCLUDE.'/class/user.class.php';
 
 $base=basename($_SERVER['SCRIPT_NAME']);
 $inside=false;
-$ledger=new Acc_Ledger($cn,0);
-$ledger->type='ALL';
 if (isset($_GET['amount_id']))
 {
        put_global(array(
-                               
array("key"=>'amount_min','value'=>$_GET['amount_id']),
-                               
array("key"=>'amount_max','value'=>$_GET['amount_id'])
-                               ));
+                        array("key"=>'amount_min','value'=>$_GET['amount_id']),
+                        array("key"=>'amount_max','value'=>$_GET['amount_id'])
+                        ));
 }
 
-$search_box=$ledger->search_form('ALL',1,'search_op');
+$ledger=new Acc_Ledger_Search('ALL',1,'search_op');
 
 if ($base == 'recherche.php' || $base == 'do.php')
        {
@@ -66,7 +64,7 @@ if ($base == 'recherche.php' || $base == 'do.php')
                $inside=true;
        }
 
-echo $search_box;
+echo $ledger->search_form();
 echo HtmlInput::submit("viewsearch",_("Recherche"));
 echo HtmlInput::button_close('search_op');
 echo '</form>';
diff --git a/include/class/acc_ledger.class.php 
b/include/class/acc_ledger.class.php
index a2fda93..a146403 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -617,459 +617,9 @@ class Acc_Ledger extends jrn_def_sql
         return $pj_pref.$pj_seq;
     }
 
-    /**
-     * @brief Show all the operation
-     * @param$sql is the sql stmt, normally created by build_search_sql
-     * @param$offset the offset
-     * @param$p_paid if we want to see info about payment
-      @code
-      // Example
-      // Build the sql
-      list($sql,$where)=$Ledger->build_search_sql($_GET);
-      // Count nb of line
-      $max_line=$this->db->count_sql($sql);
-
-      $step=$_SESSION['g_pagesize'];
-      $page=(isset($_GET['offset']))?$_GET['page']:1;
-      $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-      // create the nav. bar
-      $bar=navigation_bar($offset,$max_line,$step,$page);
-      // show a part
-      list($count,$html)= $Ledger->list_operation($sql,$offset,0);
-      echo $html;
-      // show nav bar
-      echo $bar;
-
-      @endcode
-     * @see build_search_sql
-     * @see display_search_form
-     * @see search_form
-
-     * @return HTML string
-     */
-    public function list_operation_to_reconcile($sql, $p_target)
-    {
-        global $g_parameter, $g_user;
-        $gDossier=dossier::id();
-        $limit=" LIMIT ".MAX_RECONCILE;
-        // Sort
-        // Count
-        $count=$this->db->count_sql($sql);
-        // Add the limit
-        $sql.=" order by jr_date asc ".$limit;
-
-        // Execute SQL stmt
-        $Res=$this->db->exec_sql($sql);
-
-        //starting from here we can refactor, so that instead of returning the 
generated HTML,
-        //this function returns a tree structure.
-
-        $r="";
-
-
-        $Max=Database::num_row($Res);
-
-        if ($Max==0)
-            return array(0, _("Aucun enregistrement trouvé"));
-        $r.=HtmlInput::hidden("target", $p_target);
-        $r.='<table class="result">';
-
-
-        $r.="<tr >";
-        $r.="<th>"._("Selection")."</th>";
-        $r.="<th>"._("Internal")."</th>";
-
-        if ($this->type=='ALL')
-        {
-            $r.=th(_('Journal'));
-        }
-
-        $r.='<th>'._("Date").'</th>';
-        $r.='<th>'._("Pièce").'</td>';
-        $r.=th(_('tiers'));
-        $r.='<th>'._("Description").'</th>';
-        $r.=th(_('Notes'), ' ');
-        $r.='<th>'._("Montant").'</th>';
-        $r.="<th>"._('Concerne')."</th>";
-        $r.="</tr>";
-        // Total Amount
-        $tot=0.0;
-        $gDossier=dossier::id();
-        $str_dossier=Dossier::id();
-        for ($i=0; $i<$Max; $i++)
-        {
-
-
-            $row=Database::fetch_array($Res, $i);
-
-            if ($i%2==0)
-                $tr='<TR class="odd">';
-            else
-                $tr='<TR class="even">';
-            $r.=$tr;
-            // Radiobox
-            //
-
-                       $r.='<td><INPUT TYPE="CHECKBOX" 
name="jr_concerned'.$row['jr_id'].'" ID="jr_concerned'.$row['jr_id'].'" 
value="'.$row['quick_code'].'"> </td>';
-            //internal code
-            // button  modify
-            $r.="<TD>";
-            // If url contains
-            //
-
-            $href=basename($_SERVER['PHP_SELF']);
-
-
-            $r.=sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
-                    $row['jr_id'], $gDossier, $row['jr_internal']);
-            $r.="</TD>";
-            if ($this->type=='ALL')
-                $r.=td($row['jrn_def_name']);
-            // date
-            $r.="<TD>";
-            $r.=$row['str_jr_date'];
-            $r.="</TD>";
-
-            // pj
-            $r.="<TD>";
-            $r.=$row['jr_pj_number'];
-            $r.="</TD>";
-
-            // Tiers
-            $other=($row['quick_code']!='')?'['.$row['quick_code'].'] 
'.$row['name'].' '.$row['first_name']:'';
-            $r.=td($other);
-            // comment
-            $r.="<TD>";
-            $tmp_jr_comment=h($row['jr_comment']);
-            $r.=$tmp_jr_comment;
-            $r.="</TD>";
-            $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
-            // Amount
-            // If the ledger is financial :
-            // the credit must be negative and written in red
-            $positive=0;
-
-            // Check ledger type :
-            if ($row['jrn_def_type']=='FIN')
-            {
-                $positive=$this->db->get_value("select qf_amount from 
quant_fin where jr_id=$1",
-                        array($row['jr_id']));
-                if ($this->db->count()!=0)
-                    $positive=($positive<0)?1:0;
-            }
-            $r.="<TD align=\"right\">";
-
-            $r.=( $positive!=0 )?"<font color=\"red\">  - 
".nbm($row['jr_montant'])."</font>":nbm($row['jr_montant']);
-            $r.="</TD>";
-
-
-
-            // Rapprochement
-            $rec=new Acc_Reconciliation($this->db);
-            $rec->set_jr_id($row['jr_id']);
-            $a=$rec->get();
-            $r.="<TD>";
-            if ($a!=null)
-            {
-
-                foreach ($a as $key=> $element)
-                {
-                    $operation=new Acc_Operation($this->db);
-                    $operation->jr_id=$element;
-                    $l_amount=$this->db->get_value("select jr_montant from jrn 
".
-                            " where jr_id=$1", array($element));
-                    $r.="<A class=\"detail\" 
HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > 
".$operation->get_internal()."[".nbm($l_amount)."]</A>";
-                }//for
-            }// if ( $a != null ) {
-            $r.="</TD>";
-
-            if ($row['jr_valid']=='f')
-            {
-                $r.="<TD>"._("Opération annulée")."</TD>";
-            }
-            // end row
-            $r.="</tr>";
-        }
-        $r.='</table>';
-        return array($count, $r);
-    }
-
-    /**
-     * @brief Show all the operation
-     * @param$sql is the sql stmt, normally created by build_search_sql
-     * @param$offset the offset
-     * @param$p_paid if we want to see info about payment
-      \code
-      // Example
-      // Build the sql
-      list($sql,$where)=$Ledger->build_search_sql($_GET);
-      // Count nb of line
-      $max_line=$cn->count_sql($sql);
-
-      $step=$_SESSION['g_pagesize'];
-      $page=(isset($_GET['offset']))?$_GET['page']:1;
-      $offset=(isset($_GET['offset']))?$_GET['offset']:0;
-      // create the nav. bar
-      $bar=navigation_bar($offset,$max_line,$step,$page);
-      // show a part
-      list($count,$html)= $Ledger->list_operation($sql,$offset,0);
-      echo $html;
-      // show nav bar
-      echo $bar;
-
-      \endcode
-     * \see build_search_sql
-     * \see display_search_form
-     * \see search_form
-
-     * \return HTML string
-     */
-    public function list_operation($sql, $offset, $p_paid=0)
-    {
-        global $g_parameter, $g_user;
-        bcscale(2);
-        $table=new Sort_Table();
-        $gDossier=dossier::id();
-        $amount_paid=0.0;
-        $amount_unpaid=0.0;
-        $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT 
".$_SESSION['g_pagesize']:"";
-        $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET 
".Database::escape_string($offset):"";
-        $order="  order by jr_date_order asc,jr_internal asc";
-        // Sort
-        $url="?".CleanUrl();
-        $str_dossier=dossier::get();
-        $table->add(_("Date"), $url,
-                'order by jr_date 
asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
-                'order by  jr_date 
desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
-                "da", "dd");
-        $table->add(_('Echeance'), $url, " order by  jr_ech asc",
-                " order by  jr_ech desc", 'ea', 'ed');
-        $table->add(_('Paiement'), $url, " order by  jr_date_paid asc",
-                " order by  jr_date_paid desc", 'eap', 'edp');
-        $table->add(_('Pièce'), $url,
-                ' order by  substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
-                ' order by  substring(jr_pj_number,\'[0-9]+$\')::numeric desc 
',
-                "pja", "pjd");
-        $table->add(_('Tiers'), $url, " order by  name asc",
-                " order by  name desc", 'na', 'nd');
-        $table->add(_('Montant'), $url, " order by jr_montant asc",
-                " order by jr_montant desc", "ma", "md");
-        $table->add(_("Description"), $url, "order by jr_comment asc",
-                "order by jr_comment desc", "ca", "cd");
-
-        $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
-        $order=$table->get_sql_order($ord);
-
-        // Count
-        $count=$this->db->count_sql($sql);
-        // Add the limit
-        $sql.=$order.$limit.$offset;
-        // Execute SQL stmt
-        $Res=$this->db->exec_sql($sql);
-
-        //starting from here we can refactor, so that instead of returning the 
generated HTML,
-        //this function returns a tree structure.
-
-        $r="";
-
-
-        $Max=Database::num_row($Res);
-
-        if ($Max==0)
-            return array(0, _("Aucun enregistrement trouvé"));
-
-        $r.='<table class="result">';
-
-
-        $r.="<tr >";
-        $r.="<th>"._("n° interne")."</th>";
-        if ($this->type=='ALL')
-        {
-            $r.=th('Journal');
-        }
-        $r.='<th>'.$table->get_header(0).'</th>';
-        if ($p_paid!=0)
-            $r.='<th>'.$table->get_header(1).'</td>';
-        if ($p_paid!=0)
-            $r.='<th>'.$table->get_header(2).'</th>';
-        $r.='<th>'.$table->get_header(3).'</th>';
-        $r.='<th>'.$table->get_header(4).'</th>';
-        $r.='<th>'.$table->get_header(6).'</th>';
-        $r.=th('Notes', ' style="width:15%"');
-        $r.='<th>'.$table->get_header(5).'</th>';
-        // if $p_paid is not equal to 0 then we have a paid column
-        if ($p_paid!=0)
-        {
-            $r.="<th> "._('Payé')."</th>";
-        }
-        $r.="<th>"._('Concerne')."</th>";
-        $r.="<th>"._('Document')."</th>";
-        $r.="</tr>";
-        // Total Amount
-        $tot=0.0;
-        $gDossier=dossier::id();
-        for ($i=0; $i<$Max; $i++)
-        {
-
-
-            $row=Database::fetch_array($Res, $i);
-
-            if ($i%2==0)
-                $tr='<TR class="odd">';
-            else
-                $tr='<TR class="even">';
-            $r.=$tr;
-            //internal code
-            // button  modify
-            $r.="<TD>";
-            // If url contains
-            //
-
-            $href=basename($_SERVER['PHP_SELF']);
-
-
-            $r.=sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
-                    $row['jr_id'], $gDossier, $row['jr_internal']);
-            $r.="</TD>";
-            if ($this->type=='ALL')
-                $r.=td($row['jrn_def_name']);
-            // date
-            $r.="<TD>";
-            $r.=$row['str_jr_date'];
-            $r.="</TD>";
-            // echeance
-            if ($p_paid!=0)
-            {
-                $r.="<TD>";
-                $r.=$row['str_jr_ech'];
-                $r.="</TD>";
-                $r.="<TD>";
-                $r.=$row['str_jr_date_paid'];
-                $r.="</TD>";
-            }
-
-            // pj
-            $r.="<TD>";
-            $r.=$row['jr_pj_number'];
-            $r.="</TD>";
-
-            // Tiers
-            $other=($row['quick_code']!='')?'['.$row['quick_code'].'] 
'.$row['name'].' '.$row['first_name']:'';
-            $r.=td($other);
-            // comment
-            $r.="<TD>";
-            $tmp_jr_comment=h($row['jr_comment']);
-            $r.=$tmp_jr_comment;
-            $r.="</TD>";
-            $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
-            // Amount
-            // If the ledger is financial :
-            // the credit must be negative and written in red
-            $positive=0;
-
-            // Check ledger type :
-            if ($row['jrn_def_type']=='FIN')
-            {
-                $positive=$this->db->get_value("select qf_amount from 
quant_fin where jr_id=$1",
-                        array($row['jr_id']));
-                if ($this->db->count()!=0)
-                    $positive=($positive<0)?1:0;
-            }
-            $r.="<TD align=\"right\">";
-            $t_amount=$row['jr_montant'];
-            if 
($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
-                $t_amount=$row['total_invoice'];
-            $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
-            //STAN $positive always == 0
-            if ($row ['jrn_def_type']=='FIN')
-            {
-                $r.=( $positive!=0 )?"<font color=\"red\">  - 
".nbm($t_amount)."</font>":nbm($t_amount);
-            }
-            else
-            {
-                $r.=( $t_amount<0 )?"<font color=\"red\">  
".nbm($t_amount)."</font>":nbm($t_amount);
-            }
-            $r.="</TD>";
-
-
-            // Show the paid column if p_paid is not null
-            if ($p_paid!=0)
-            {
-                $w=new ICheckBox();
-                $w->name="rd_paid".$row['jr_id'];
-                $w->selected=($row['jr_rapt']=='paid')?true:false;
-                // if p_paid == 2 then readonly
-                $w->readonly=( $p_paid==2)?true:false;
-                $h=new IHidden();
-                $h->name="set_jr_id".$row['jr_id'];
-                $r.='<TD>'.$w->input().$h->input().'</TD>';
-                if ($row['jr_rapt']=='paid')
-                    $amount_paid=bcadd($amount_paid, $t_amount);
-                else
-                    $amount_unpaid=bcadd($amount_unpaid, $t_amount);
-            }
-
-            // Rapprochement
-            $rec=new Acc_Reconciliation($this->db);
-            $rec->set_jr_id($row['jr_id']);
-            $a=$rec->get();
-            $r.="<TD>";
-            if ($a!=null)
-            {
-
-                foreach ($a as $key=> $element)
-                {
-                    $operation=new Acc_Operation($this->db);
-                    $operation->jr_id=$element;
-                    $l_amount=$this->db->get_value("select jr_montant from jrn 
".
-                            " where jr_id=$1", array($element));
-                    $r.="<A class=\"detail\" 
HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > 
".$operation->get_internal()."[".nbm($l_amount)."]</A>";
-                }//for
-            }// if ( $a != null ) {
-            $r.="</TD>";
-
-            if ($row['jr_valid']=='f')
-            {
-                $r.="<TD>"._("Opération annulée")."</TD>";
-            }
-            else
-            {
-                
-            } // else
-            //document
-            if ($row['jr_pj_name']!="")
-            {
-                
$r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
-            }
-            else
-                $r.="<TD></TD>";
-
-            // end row
-            $r.="</tr>";
-        }
-        $amount_paid=round($amount_paid, 4);
-        $amount_unpaid=round($amount_unpaid, 4);
-        $tot=round($tot, 4);
-        $r.="<TR>";
-        $r.='<TD COLSPAN="5">Total</TD>';
-        $r.='<TD ALIGN="RIGHT">'.nbm($tot)."</TD>";
-        $r.="</tr>";
-        if ($p_paid!=0)
-        {
-            $r.="<TR>";
-            $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
-            $r.='<TD ALIGN="RIGHT">'.nbm($amount_paid)."</TD>";
-            $r.="</tr>";
-            $r.="<TR>";
-            $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
-            $r.='<TD ALIGN="RIGHT">'.nbm($amount_unpaid)."</TD>";
-            $r.="</tr>";
-        }
-        $r.="</table>";
-
-        return array($count, $r);
-    }
+    
 
+    
     /**
      * @brief get_detail gives the detail of row
      * this array must contains at least the field
@@ -2575,475 +2125,7 @@ class Acc_Ledger extends jrn_def_sql
         $this->db->exec_sql($sql);
     }
 
-    /**
-     * @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
-     * @param  $all_type_ledger
-     *       values :
-     *         - 1 means all the ledger of this type
-     *         - 0 No have the "Tous les journaux" availables
-     * @param  $div is the div (for reconciliation)
-     * @return a HTML String without the tag FORM or DIV
-     *
-     * @see build_search_sql
-     * @see display_search_form
-     * @see list_operation
-     */
-    function search_form($p_type, $all_type_ledger=1, $div="")
-    {
-        global $g_user;
-        $r="";
-        $bledger_param=json_encode(array(
-            'dossier'=>$_REQUEST['gDossier'],
-            'type'=>$p_type,
-            'all_type'=>$all_type_ledger,
-            'div'=>$div
-        ));
-
-        $bledger_param=str_replace('"', "'", $bledger_param);
-        $bledger=new ISmallButton('l');
-        $bledger->label=_("choix des journaux");
-        $bledger->javascript=" show_ledger_choice($bledger_param)";
-        $f_ledger=$bledger->input();
-        $hid_jrn="";
-        if (isset($_REQUEST[$div.'nb_jrn']))
-        {
-            for ($i=0; $i<$_REQUEST[$div.'nb_jrn']; $i++)
-            {
-                if (isset($_REQUEST[$div."r_jrn"][$i]))
-                    $hid_jrn.=HtmlInput::hidden($div.'r_jrn['.$i.']',
-                                    $_REQUEST[$div."r_jrn"][$i]);
-            }
-            $hid_jrn.=HtmlInput::hidden($div.'nb_jrn', 
$_REQUEST[$div.'nb_jrn']);
-        } else
-        {
-            $hid_jrn=HtmlInput::hidden($div.'nb_jrn', 0);
-        }
-        /* Compute date for exercice */
-        $period=$g_user->get_periode();
-        $per=new Periode($this->db, $period);
-        $exercice=$per->get_exercice();
-        list($per_start, $per_end)=$per->get_limit($exercice);
-        $date_end=$per_end->last_day();
-        $date_start=$per_start->first_day();
-
-        /* widget for date_start */
-        $f_date_start=new IDate('date_start');
-        /* all periode or only the selected one */
-        if (isset($_REQUEST['date_start']))
-        {
-            $f_date_start->value=$_REQUEST['date_start'];
-        }
-        else
-        {
-            $f_date_start->value=$date_start;
-        }
-
-        /* widget for date_end */
-        $f_date_end=new IDate('date_end');
-        /* all date or only the selected one */
-        if (isset($_REQUEST['date_end']))
-        {
-            $f_date_end->value=$_REQUEST['date_end'];
-        }
-        else
-        {
-            $f_date_end->value=$date_end;
-        }
-        /* widget for date term */
-        $f_date_paid_start=new IDate('date_paid_start');
-        $f_date_paid_end=new IDate('date_paid_end');
-
-        
$f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
-        
$f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
-
-        /* widget for desc */
-        $f_descript=new IText('desc');
-        $f_descript->size=40;
-        if (isset($_REQUEST['desc']))
-        {
-            $f_descript->value=$_REQUEST['desc'];
-        }
-
-        /* widget for amount */
-        $f_amount_min=new INum('amount_min');
-        
$f_amount_min->value=(isset($_REQUEST['amount_min']))?abs($_REQUEST['amount_min']):0;
-        $f_amount_max=new INum('amount_max');
-        
$f_amount_max->value=(isset($_REQUEST['amount_max']))?abs($_REQUEST['amount_max']):0;
-
-        /* input quick code */
-        $f_qcode=new ICard('qcode'.$div);
-
-        $f_qcode->set_attribute('typecard', 'all');
-        /*        $f_qcode->set_attribute('p_jrn','0');
-
-          $f_qcode->set_callback('filter_card');
-         */
-        $f_qcode->set_dblclick("fill_ipopcard(this);");
-        // Add the callback function to filter the card on the jrn
-        //$f_qcode->set_callback('filter_card');
-        $f_qcode->set_function('fill_data');
-        $f_qcode->javascript=sprintf(' onchange="fill_data_onchange(%s);" ',
-                $f_qcode->name);
-        
$f_qcode->value=(isset($_REQUEST['qcode'.$div]))?$_REQUEST['qcode'.$div]:'';
-
-        /*        $f_txt_qcode=new IText('qcode');
-          
$f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
-         */
-
-        /* input poste comptable */
-        $f_accounting=new IPoste('accounting');
-        
$f_accounting->value=(isset($_REQUEST['accounting']))?$_REQUEST['accounting']:'';
-        if ($this->id==-1)
-            $jrn=0;
-        else
-            $jrn=$this->id;
-        $f_accounting->set_attribute('jrn', $jrn);
-        $f_accounting->set_attribute('ipopup', 'ipop_account');
-        $f_accounting->set_attribute('label', 'ld');
-        $f_accounting->set_attribute('account', 'accounting');
-        $info=HtmlInput::infobulle(13);
-
-        $f_paid=new ICheckbox('unpaid');
-        $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
-
-        $r.=dossier::hidden();
-        $r.=HtmlInput::hidden('ledger_type', $this->type);
-        $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
-        ob_start();
-        require_once NOALYSS_TEMPLATE.'/ledger_search.php';
-        $r.=ob_get_contents();
-        ob_end_clean();
-        return $r;
-    }
-
-    /**
-     * @brief this function will create a sql stmt to use to create the list 
for
-     * the ledger,
-     * @param  $p_array is usually the $_GET,
-     * @param  $p_order the order of the row
-     * @param  $p_where is the sql condition if not null then the $p_array 
will not be used
-     * \note the p_action will be used to filter the ledger but gl means ALL
-     * struct array $p_array
-      \verbatim
-      (
-      [gDossier] => 13
-      [p_jrn] => -1
-      [date_start] =>
-      [date_end] =>
-      [amount_min] => 0
-      [amount_max] => 0
-      [desc] =>
-      [search] => Rechercher
-      [p_action] => ven
-      [sa] => l
-      )
-      \endverbatim
-     * \return an array with a valid sql statement, an the where clause => 
array[sql] array[where]
-     * \see list_operation
-     * \see display_search_form
-     * \see search_form
-     */
-    public function build_search_sql($p_array, $p_order="", $p_where="")
-    {
-        $sql="select jr_id     ,
-             jr_montant,
-             substr(jr_comment,1,60) as jr_comment,
-             to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
-             to_char(jr_date,'DD.MM.YY') as str_jr_date,
-             jr_date as jr_date_order,
-             jr_grpt_id,
-             jr_rapt,
-             jr_internal,
-             jrn_def_id,
-             jrn_def_name,
-             jrn_def_ech,
-             jrn_def_type,
-             jr_valid,
-             jr_tech_per,
-             jr_pj_name,
-             p_closed,
-             jr_pj_number,
-             n_text,
-            case
-            when jrn_def_type='VEN' then
-                (select ad_value from fiche_detail where ad_id=1
-                and f_id=(select max(qs_client) from quant_sold join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then
-               (select ad_value from fiche_detail where ad_id=1
-               and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then
-               (select ad_value from fiche_detail where ad_id=1
-               and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as name,
-          case
-            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as first_name,
-           case
-            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
-           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
-           end as quick_code,
-           case
-            when jrn_def_type='VEN' then
-                    (select sum(qs_price)+sum(vat) from
-                               (select qs_internal,qs_price,case when 
qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where 
qs_internal=X.jr_internal) as ven_invoice
-                         )
-           when jrn_def_type = 'ACH' then
-                       (
-                               select 
sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
-                               from
-                                (select 
qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from 
quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
-                       )
-               else null
-               end as total_invoice,
-            jr_date_paid,
-            to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
-             from
-             jrn as X left join jrn_note using(jr_id)
-             join jrn_def on jrn_def_id=jr_def_id
-             join parm_periode on p_id=jr_tech_per";
-
-        if (!empty($p_array))
-            extract($p_array, EXTR_SKIP);
-
-        if (isset($op))
-            $r_jrn=(isset(${$op."r_jrn"}))?${$op."r_jrn"}:-1;
-        else
-        {
-            $r_jrn=(isset($r_jrn))?$r_jrn:-1;
-        }
-
-        /* if no variable are set then give them a default
-         * value */
-        if ($p_array==null||empty($p_array)||!isset($amount_min))
-        {
-            $amount_min=0;
-            $amount_max=0;
-
-            $desc='';
-            $qcode=(isset($qcode))?$qcode:"";
-            if (isset($qcodesearch_op))
-                $qcode=$qcodesearch_op;
-            $accounting=(isset($accounting))?$accounting:"";
-            $periode=new Periode($this->db);
-            $g_user=new User($this->db);
-            $p_id=$g_user->get_periode();
-            if ($p_id!=null)
-            {
-                list($date_start, $date_end)=$periode->get_date_limit($p_id);
-            }
-        }
-
-        /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
-         *  type otherwise only one ledger */
-        $fil_ledger='';
-        $fil_amount='';
-        $fil_date='';
-        $fil_desc='';
-        $fil_sec='';
-        $fil_qcode='';
-        $fil_account='';
-        $fil_paid='';
-        $fil_date_paid='';
-
-        $and='';
-        $g_user=new User($this->db);
-        $p_action=$ledger_type;
-        if ($p_action=='')
-            $p_action='ALL';
-        if ($r_jrn==-1)
-        {
-
-            /* from compta.php the p_action is quick_writing instead of ODS  */
-            if ($p_action=='quick_writing')
-                $p_action='ODS';
-
-
-            $fil_ledger=$g_user->get_ledger_sql($p_action, 3);
-            $and=' and ';
-        }
-        else
-        {
-
-            if ($p_action=='quick_writing')
-                $p_action='ODS';
-
-            $aLedger=$g_user->get_ledger($p_action, 3);
-            $fil_ledger='';
-            $sp='';
-            for ($i=0; $i<count($r_jrn); $i++)
-            {
-                if (isset($r_jrn[$i]))
-                {
-                    $a=$r_jrn[$i];
-                    $fil_ledger.=$sp.$a;
-                    $sp=',';
-                }
-            }
-            $fil_ledger=' jrn_def_id in ('.$fil_ledger.')';
-            $and=' and ';
-
-            /* no ledger selected */
-            if ($sp=='')
-            {
-                $fil_ledger='';
-                $and='';
-            }
-        }
-
-        /* format the number */
-        $amount_min=abs(toNumber($amount_min));
-        $amount_max=abs(toNumber($amount_max));
-        if ($amount_min>0&&isNumber($amount_min))
-        {
-            $fil_amount=$and.' jr_montant >='.$amount_min;
-            $and=' and ';
-        }
-        if ($amount_max>0&&isNumber($amount_max))
-        {
-            $fil_amount.=$and.' jr_montant <='.$amount_max;
-            $and=' and ';
-        }
-        /* 
-------------------------------------------------------------------------- *
-         * if both amount are the same then we need to search into the detail
-         * and we reset the fil_amount
-         * 
-------------------------------------------------------------------------- */
-        if (isNumber($amount_min)&&
-                isNumber($amount_max)&&
-                $amount_min>0&&
-                bccomp($amount_min, $amount_max, 2)==0)
-        {
-            $fil_amount=$and.' ( ';
-
-            // Look in detail
-            $fil_amount.='jr_grpt_id in ( select distinct j_grpt from jrnx 
where j_montant = '.$amount_min.') ';
-
-            //and the total operation
-            $fil_amount.=' or ';
-            $fil_amount.=' jr_montant = '.$amount_min;
-
-            $fil_amount.=')';
-            $and=" and ";
-        }
-        // date
-        if (isset($date_start)&&isDate($date_start)!=null)
-        {
-            $fil_date=$and." jr_date >= 
to_date('".$date_start."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if (isset($date_end)&&isDate($date_end)!=null)
-        {
-            $fil_date.=$and." jr_date <= 
to_date('".$date_end."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        // date paiement
-        if (isset($date_paid_start)&&isDate($date_paid_start)!=null)
-        {
-            $fil_date_paid=$and." jr_date_paid >= 
to_date('".$date_paid_start."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        if (isset($date_paid_end)&&isDate($date_paid_end)!=null)
-        {
-            $fil_date_paid.=$and." jr_date_paid <= 
to_date('".$date_paid_end."','DD.MM.YYYY')";
-            $and=" and ";
-        }
-        // comment
-        if (isset($desc)&&$desc!=null)
-        {
-            $desc=sql_string($desc);
-            $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or 
upper(jr_pj_number) like upper('%".$desc."%') ".
-                    " or upper(jr_internal)  like upper('%".$desc."%')
-                          or jr_grpt_id in (select j_grpt from jrnx where 
j_text ~* '".$desc."')
-                          or jr_id in (select jr_id from jrn_info where 
ji_value is not null and ji_value ~* '$desc')
-                          )";
-            $and=" and ";
-        }
-        //    Poste
-        if (isset($accounting)&&$accounting!=null)
-        {
-            $fil_account=$and."  jr_grpt_id in (select j_grpt
-                         from jrnx where j_poste::text like 
'".sql_string($accounting)."%' )  ";
-            $and=" and ";
-        }
-        // Quick Code
-        if (isset($qcodesearch_op))
-            $qcode=$qcodesearch_op;
-        if (isset($qcode)&&$qcode!=null)
-        {
-            $fil_qcode=$and."  jr_grpt_id in ( select j_grpt from
-                       jrnx where trim(j_qcode) = 
upper(trim('".sql_string($qcode)."')))";
-            $and=" and ";
-        }
-
-        // Only the unpaid
-        if (isset($unpaid))
-        {
-            $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
-            $and=" and ";
-        }
-        $repo=new Database();
-        $g_user=new User($repo);
-        $g_user->Check();
-        $g_user->check_dossier(dossier::id());
-
-        if ($g_user->admin==0&&$g_user->is_local_admin()==0)
-        {
-            $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
-                    " from user_sec_jrn where ".
-                    " uj_login='".sql_string($_SESSION['g_user'])."'".
-                    " and uj_priv in ('R','W'))";
-        }
-        
$where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.$fil_qcode.$fil_paid.$fil_account.$fil_date_paid;
-        $sql.=" where ".$where;
-        return array($sql, $where);
-    }
-
-    /**
-     * @brief return a html string with the search_form
-     * \return a HTML string with the FORM
-     * \see build_search_sql
-     * \see search_form
-     * \see list_operation
-     */
-    function display_search_form()
-    {
-        $r='';
-        $type=$this->type;
-
-        if ($type=="")
-            $type='ALL';
-        $r.='<div id="search_form" style="display:none">';
-        $r.=HtmlInput::anchor_hide('&#10761;',
-                        '$(\'search_form\').style.display=\'none\';');
-        $r.=h2('Recherche', 'class="title"');
-        $r.='<FORM METHOD="GET">';
-        $r.=$this->search_form($type);
-        $r.=HtmlInput::submit('search', _('Rechercher'));
-        $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
-
-        /*  when called from commercial.php some hidden values are needed */
-        if (isset($_REQUEST['sa']))
-            $r.=HtmlInput::hidden("sa", $_REQUEST['sa']);
-        if (isset($_REQUEST['sb']))
-            $r.=HtmlInput::hidden("sb", $_REQUEST['sb']);
-        if (isset($_REQUEST['sc']))
-            $r.=HtmlInput::hidden("sc", $_REQUEST['sc']);
-        if (isset($_REQUEST['f_id']))
-            $r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
-
-        $r.='</FORM>';
-
-        $r.='</div>';
-        $button=new IButton('tfs');
-        $button->label=_("Filtrer");
-        $button->javascript="toggleHideShow('search_form','tfs');";
-
-        $r.=$button->input();
-        return $r;
-    }
+  
 
     /**
      * @brief return the last p_limit operation into an array
diff --git a/include/class/acc_ledger_search.class.php 
b/include/class/acc_ledger_search.class.php
new file mode 100644
index 0000000..d786a56
--- /dev/null
+++ b/include/class/acc_ledger_search.class.php
@@ -0,0 +1,1040 @@
+<?php
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta 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.
+ *
+ *   PhpCompta 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 PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2016) Author Dany De Bontridder <address@hidden>
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+/**
+ * @file
+ * @brief 
+ * @param type $name Descriptionara
+ */
+class Acc_Ledger_Search
+{
+
+    private $cn; //!< Database Connection
+    private $type; //!< type of ledger : FIN,ODS,VEN,ACH
+    private $all; //!< Flag to indicate if all ledgers must searched (1 for 
yes)
+    private $div; //! prefix for id of DOM id
+
+    /**
+     * @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
+     * @param  $all_type_ledger
+     *       values :
+     *         - 1 means all the ledger of this type
+     *         - 0 No have the "Tous les journaux" availables
+     * @param  $div is the div (for reconciliation)
+     * @param type $p_type
+     * @param type $p_all
+     * @param type $p_div
+     */
+
+    function __construct($p_type, $p_all=1, $p_div="")
+    {
+        $this->cn=Dossier::connect();
+        $this->type=$p_type;
+        $this->all=$p_all;
+        $this->div=$p_div;
+    }
+
+    public function get_type()
+    {
+        return $this->type;
+    }
+
+    public function get_all()
+    {
+        return $this->all;
+    }
+
+    public function get_div()
+    {
+        return $this->div;
+    }
+
+    public function set_type($type)
+    {
+        $this->type=$type;
+    }
+
+    public function set_all($all)
+    {
+        $this->all=$all;
+    }
+
+    public function set_div($div)
+    {
+        $this->div=$div;
+    }
+
+    /**
+     * @brief return a HTML string with the form for the search
+     * @return a HTML String without the tag FORM or DIV
+     *
+     * @see build_search_sql
+     * @see display_search_form
+     * @see list_operation
+     * @example search_acc_operation.php
+     */
+    function search_form()
+    {
+        global $g_user;
+        $r="";
+        $bledger_param=json_encode(array(
+            'dossier'=>Dossier::id(),
+            'type'=>$this->type,
+            'all_type'=>$this->all,
+            'div'=>$this->div
+        ));
+
+        $bledger_param=str_replace('"', "'", $bledger_param);
+        $bledger=new ISmallButton('l');
+        $bledger->label=_("choix des journaux");
+        $bledger->javascript=" show_ledger_choice($bledger_param)";
+        $f_ledger=$bledger->input();
+        $hid_jrn="";
+        if (isset($_REQUEST[$this->div.'nb_jrn']))
+        {
+            for ($i=0; $i<$_REQUEST[$this->div.'nb_jrn']; $i++)
+            {
+                if (isset($_REQUEST[$this->div."r_jrn"][$i]))
+                    $hid_jrn.=HtmlInput::hidden($this->div.'r_jrn['.$i.']',
+                                    $_REQUEST[$this->div."r_jrn"][$i]);
+            }
+            $hid_jrn.=HtmlInput::hidden($this->div.'nb_jrn',
+                            $_REQUEST[$this->div.'nb_jrn']);
+        } else
+        {
+            $hid_jrn=HtmlInput::hidden($this->div.'nb_jrn', 0);
+        }
+        /* Compute date for exercice */
+        $period=$g_user->get_periode();
+        $per=new Periode($this->cn, $period);
+        $exercice=$per->get_exercice();
+        list($per_start, $per_end)=$per->get_limit($exercice);
+        $date_end=$per_end->last_day();
+        $date_start=$per_start->first_day();
+
+        /* widget for date_start */
+        $f_date_start=new IDate('date_start', '', $this->div."date_start");
+        /* all periode or only the selected one */
+        if (isset($_REQUEST['date_start']))
+        {
+            $f_date_start->value=$_REQUEST['date_start'];
+        }
+        else
+        {
+            $f_date_start->value=$date_start;
+        }
+
+        /* widget for date_end */
+        $f_date_end=new IDate('date_end', '', $this->div."date_end");
+        /* all date or only the selected one */
+        if (isset($_REQUEST['date_end']))
+        {
+            $f_date_end->value=$_REQUEST['date_end'];
+        }
+        else
+        {
+            $f_date_end->value=$date_end;
+        }
+        /* widget for date term */
+        $f_date_paid_start=new IDate('date_paid_start', '',
+                $this->div."date_paid_start");
+        $f_date_paid_end=new IDate('date_paid_end', '',
+                $this->div."date_paid_end");
+
+        
$f_date_paid_start->value=(isset($_REQUEST['date_paid_start']))?$_REQUEST['date_paid_start']:'';
+        
$f_date_paid_end->value=(isset($_REQUEST['date_paid_end']))?$_REQUEST['date_paid_end']:'';
+
+        /* widget for desc */
+        $f_descript=new IText('desc', "", $this->div."desc");
+        $f_descript->size=40;
+        if (isset($_REQUEST['desc']))
+        {
+            $f_descript->value=$_REQUEST['desc'];
+        }
+
+        /* widget for amount */
+        $f_amount_min=new INum('amount_min', '0', $this->div."amount_min");
+        
$f_amount_min->value=(isset($_REQUEST['amount_min']))?abs($_REQUEST['amount_min']):0;
+        $f_amount_max=new INum('amount_max', '0', $this->div."amount_max");
+        
$f_amount_max->value=(isset($_REQUEST['amount_max']))?abs($_REQUEST['amount_max']):0;
+
+        /* input quick code */
+        $f_qcode=new ICard($this->div.'qcode');
+
+        $f_qcode->set_attribute('typecard', 'all');
+        /*        $f_qcode->set_attribute('p_jrn','0');
+
+          $f_qcode->set_callback('filter_card');
+         */
+        $f_qcode->set_dblclick("fill_ipopcard(this);");
+        // Add the callback function to filter the card on the jrn
+        //$f_qcode->set_callback('filter_card');
+        $f_qcode->set_function('fill_data');
+        $f_qcode->javascript=sprintf(' onchange="fill_data_onchange(%s);" ',
+                $f_qcode->name);
+        
$f_qcode->value=(isset($_REQUEST[$this->div.'qcode']))?$_REQUEST[$this->div.'qcode']:'';
+
+        /*        $f_txt_qcode=new IText('qcode');
+          
$f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
+         */
+
+        /* input poste comptable */
+        $f_accounting=new IPoste('accounting', "", $this->div."accounting");
+        
$f_accounting->value=(isset($_REQUEST['accounting']))?$_REQUEST['accounting']:'';
+        /*
+         * utile ??? Filtre les postes comptables en fonction du journal 
+         * if ($this->id==-1)
+          $jrn=0;
+          else
+          $jrn=$this->id; */
+        $f_accounting->set_attribute('jrn', 0);
+        $f_accounting->set_attribute('ipopup', 'ipop_account');
+        $f_accounting->set_attribute('label', 'ld');
+        $f_accounting->set_attribute('account', $this->div.'accounting');
+        $info=HtmlInput::infobulle(13);
+
+        $f_paid=new ICheckbox('unpaid', null, $this->div.'unpaid');
+        $f_paid->selected=(isset($_REQUEST['unpaid']))?true:false;
+
+        $r.=dossier::hidden();
+        $r.=HtmlInput::hidden('ledger_type', $this->type,
+                        $this->div."ledger_type");
+        $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+        ob_start();
+        $search_filter=$this->build_search_filter();
+        $save_filter=$this->build_name_filter();
+        require_once NOALYSS_TEMPLATE.'/ledger_search.php';
+        $r.=ob_get_contents();
+        ob_end_clean();
+        return $r;
+    }
+
+    /**
+     * Build the button for managing the filter for search
+     * @param type $p_div id prefix of the div, button, table ..
+     * @param  $this->type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN
+     * @param  $all_type_ledger
+     *       values :
+     *         - 1 means all the ledger of this type
+     *         - 0 No have the "Tous les journaux" availables
+     */
+    private function build_search_filter()
+    {
+        $json=json_encode(["div"=>$this->div, "ledger_type"=>$this->type, 
"all_type"=>$this->all,
+            "dossier"=>Dossier::id()]);
+        $json=str_replace('"', "'", $json);
+        $r=sprintf('manage_search_filter(%s)', $json);
+        return $r;
+    }
+
+    /**
+     * Build the button for saving the filter for search
+     */
+    private function build_name_filter()
+    {
+        $name=new IText($this->div."filter_new");
+        $name->placeholder=_("Nom du filtre");
+        
$name->javascript=sprintf("save_filter('%s','%s')",$this->div,Dossier::id());
+        return $name;
+    }
+
+    /**
+     * @brief this function will create a sql stmt to use to create the list 
for
+     * the ledger,
+     * @param  $p_array is usually the $_GET,
+     * @param  $p_order the order of the row
+     * @param  $p_where is the sql condition if not null then the $p_array 
will not be used
+     * \note the p_action will be used to filter the ledger but gl means ALL
+     * struct array $p_array
+      \verbatim
+      (
+      [gDossier] => 13
+      [p_jrn] => -1
+      [date_start] =>
+      [date_end] =>
+      [amount_min] => 0
+      [amount_max] => 0
+      [desc] =>
+      [search] => Rechercher
+      [p_action] => ven
+      [sa] => l
+      )
+      \endverbatim
+     * \return an array with a valid sql statement, an the where clause => 
array[sql] array[where]
+     * \see list_operation
+     * \see display_search_form
+     * \see search_form
+     */
+    public function build_search_sql($p_array, $p_order="", $p_where="")
+    {
+        $sql="select jr_id     ,
+             jr_montant,
+             substr(jr_comment,1,60) as jr_comment,
+             to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
+             to_char(jr_date,'DD.MM.YY') as str_jr_date,
+             jr_date as jr_date_order,
+             jr_grpt_id,
+             jr_rapt,
+             jr_internal,
+             jrn_def_id,
+             jrn_def_name,
+             jrn_def_ech,
+             jrn_def_type,
+             jr_valid,
+             jr_tech_per,
+             jr_pj_name,
+             p_closed,
+             jr_pj_number,
+             n_text,
+            case
+            when jrn_def_type='VEN' then
+                (select ad_value from fiche_detail where ad_id=1
+                and f_id=(select max(qs_client) from quant_sold join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then
+               (select ad_value from fiche_detail where ad_id=1
+               and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then
+               (select ad_value from fiche_detail where ad_id=1
+               and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as name,
+          case
+            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=32 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as first_name,
+           case
+            when jrn_def_type='VEN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qs_client) from quant_sold join jrnx using 
(j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'ACH' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select max(qp_supplier) from quant_purchase join jrnx 
using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
+           when jrn_def_type = 'FIN' then (select ad_value from fiche_detail 
where ad_id=23 and f_id=(select qf_other from quant_fin where 
quant_fin.jr_id=x.jr_id))
+           end as quick_code,
+           case
+            when jrn_def_type='VEN' then
+                    (select sum(qs_price)+sum(vat) from
+                               (select qs_internal,qs_price,case when 
qs_vat_sided<>0 then 0 else qs_vat end as vat from quant_sold where 
qs_internal=X.jr_internal) as ven_invoice
+                         )
+           when jrn_def_type = 'ACH' then
+                       (
+                               select 
sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
+                               from
+                                (select 
qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat from 
quant_purchase where qp_internal=X.jr_internal) as invoice_purchase
+                       )
+               else null
+               end as total_invoice,
+            jr_date_paid,
+            to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid
+             from
+             jrn as X left join jrn_note using(jr_id)
+             join jrn_def on jrn_def_id=jr_def_id
+             join parm_periode on p_id=jr_tech_per";
+
+        if (!empty($p_array))
+            extract($p_array, EXTR_SKIP);
+
+        if (isset($op))
+            $r_jrn=(isset(${$op."r_jrn"}))?${$op."r_jrn"}:-1;
+        else
+        {
+            $r_jrn=(isset($r_jrn))?$r_jrn:-1;
+        }
+
+        /* if no variable are set then give them a default
+         * value */
+        if ($p_array==null||empty($p_array)||!isset($amount_min))
+        {
+            $amount_min=0;
+            $amount_max=0;
+
+            $desc='';
+            $qcode=(isset($qcode))?$qcode:"";
+            if (isset($qcodesearch_op))
+                $qcode=$qcodesearch_op;
+            $accounting=(isset($accounting))?$accounting:"";
+            $periode=new Periode($this->cn);
+            $g_user=new User($this->cn);
+            $p_id=$g_user->get_periode();
+            if ($p_id!=null)
+            {
+                list($date_start, $date_end)=$periode->get_date_limit($p_id);
+            }
+        }
+
+        /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
+         *  type otherwise only one ledger */
+        $fil_ledger='';
+        $fil_amount='';
+        $fil_date='';
+        $fil_desc='';
+        $fil_sec='';
+        $fil_qcode='';
+        $fil_account='';
+        $fil_paid='';
+        $fil_date_paid='';
+
+        $and='';
+        $g_user=new User($this->cn);
+        $p_action=$ledger_type;
+        if ($p_action=='')
+            $p_action='ALL';
+        if ($r_jrn==-1)
+        {
+
+            /* from compta.php the p_action is quick_writing instead of ODS  */
+            if ($p_action=='quick_writing')
+                $p_action='ODS';
+
+
+            $fil_ledger=$g_user->get_ledger_sql($p_action, 3);
+            $and=' and ';
+        }
+        else
+        {
+
+            if ($p_action=='quick_writing')
+                $p_action='ODS';
+
+            $aLedger=$g_user->get_ledger($p_action, 3);
+            $fil_ledger='';
+            $sp='';
+            for ($i=0; $i<count($r_jrn); $i++)
+            {
+                if (isset($r_jrn[$i]))
+                {
+                    $a=$r_jrn[$i];
+                    $fil_ledger.=$sp.$a;
+                    $sp=',';
+                }
+            }
+            $fil_ledger=' jrn_def_id in ('.$fil_ledger.')';
+            $and=' and ';
+
+            /* no ledger selected */
+            if ($sp=='')
+            {
+                $fil_ledger='';
+                $and='';
+            }
+        }
+
+        /* format the number */
+        $amount_min=abs(toNumber($amount_min));
+        $amount_max=abs(toNumber($amount_max));
+        if ($amount_min>0&&isNumber($amount_min))
+        {
+            $fil_amount=$and.' jr_montant >='.$amount_min;
+            $and=' and ';
+        }
+        if ($amount_max>0&&isNumber($amount_max))
+        {
+            $fil_amount.=$and.' jr_montant <='.$amount_max;
+            $and=' and ';
+        }
+        /* 
-------------------------------------------------------------------------- *
+         * if both amount are the same then we need to search into the detail
+         * and we reset the fil_amount
+         * 
-------------------------------------------------------------------------- */
+        if (isNumber($amount_min)&&
+                isNumber($amount_max)&&
+                $amount_min>0&&
+                bccomp($amount_min, $amount_max, 2)==0)
+        {
+            $fil_amount=$and.' ( ';
+
+            // Look in detail
+            $fil_amount.='jr_grpt_id in ( select distinct j_grpt from jrnx 
where j_montant = '.$amount_min.') ';
+
+            //and the total operation
+            $fil_amount.=' or ';
+            $fil_amount.=' jr_montant = '.$amount_min;
+
+            $fil_amount.=')';
+            $and=" and ";
+        }
+        // date
+        if (isset($date_start)&&isDate($date_start)!=null)
+        {
+            $fil_date=$and." jr_date >= 
to_date('".$date_start."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if (isset($date_end)&&isDate($date_end)!=null)
+        {
+            $fil_date.=$and." jr_date <= 
to_date('".$date_end."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        // date paiement
+        if (isset($date_paid_start)&&isDate($date_paid_start)!=null)
+        {
+            $fil_date_paid=$and." jr_date_paid >= 
to_date('".$date_paid_start."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        if (isset($date_paid_end)&&isDate($date_paid_end)!=null)
+        {
+            $fil_date_paid.=$and." jr_date_paid <= 
to_date('".$date_paid_end."','DD.MM.YYYY')";
+            $and=" and ";
+        }
+        // comment
+        if (isset($desc)&&$desc!=null)
+        {
+            $desc=sql_string($desc);
+            $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or 
upper(jr_pj_number) like upper('%".$desc."%') ".
+                    " or upper(jr_internal)  like upper('%".$desc."%')
+                          or jr_grpt_id in (select j_grpt from jrnx where 
j_text ~* '".$desc."')
+                          or jr_id in (select jr_id from jrn_info where 
ji_value is not null and ji_value ~* '$desc')
+                          )";
+            $and=" and ";
+        }
+        //    Poste
+        if (isset($accounting)&&$accounting!=null)
+        {
+            $fil_account=$and."  jr_grpt_id in (select j_grpt
+                         from jrnx where j_poste::text like 
'".sql_string($accounting)."%' )  ";
+            $and=" and ";
+        }
+        // Quick Code
+        if (isset($qcodesearch_op))
+            $qcode=$qcodesearch_op;
+        if (isset($qcode)&&$qcode!=null)
+        {
+            $fil_qcode=$and."  jr_grpt_id in ( select j_grpt from
+                       jrnx where trim(j_qcode) = 
upper(trim('".sql_string($qcode)."')))";
+            $and=" and ";
+        }
+
+        // Only the unpaid
+        if (isset($unpaid))
+        {
+            $fil_paid=$and.SQL_LIST_UNPAID_INVOICE;
+            $and=" and ";
+        }
+        $repo=new Database();
+        $g_user=new User($repo);
+        $g_user->Check();
+        $g_user->check_dossier(dossier::id());
+
+        if ($g_user->admin==0&&$g_user->is_local_admin()==0)
+        {
+            $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
+                    " from user_sec_jrn where ".
+                    " uj_login='".sql_string($_SESSION['g_user'])."'".
+                    " and uj_priv in ('R','W'))";
+        }
+        
$where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.$fil_qcode.$fil_paid.$fil_account.$fil_date_paid;
+        $sql.=" where ".$where;
+        return array($sql, $where);
+    }
+
+    /**
+     * @brief return a html string with the search_form
+     * \return a HTML string with the FORM
+     * \see build_search_sql
+     * \see search_form
+     * \see list_operation
+     */
+    function display_search_form()
+    {
+        $r='';
+        $r.='<div id="search_form" style="display:none">';
+        $r.=HtmlInput::anchor_hide('&#10761;',
+                        '$(\'search_form\').style.display=\'none\';');
+        $r.=h2('Recherche', 'class="title"');
+        $r.='<FORM METHOD="GET">';
+        $r.=$this->search_form();
+        $r.=HtmlInput::submit('search', _('Rechercher'));
+        $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+
+        /*  when called from commercial.php some hidden values are needed */
+        if (isset($_REQUEST['sa']))
+            $r.=HtmlInput::hidden("sa", $_REQUEST['sa']);
+        if (isset($_REQUEST['sb']))
+            $r.=HtmlInput::hidden("sb", $_REQUEST['sb']);
+        if (isset($_REQUEST['sc']))
+            $r.=HtmlInput::hidden("sc", $_REQUEST['sc']);
+        if (isset($_REQUEST['f_id']))
+            $r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
+
+        $r.='</FORM>';
+
+        $r.='</div>';
+        $button=new IButton('tfs');
+        $button->label=_("Filtrer");
+        $button->javascript="toggleHideShow('search_form','tfs');";
+
+        $r.=$button->input();
+        return $r;
+    }
+
+    /**
+     * @brief Show all the operation
+     * @param$sql is the sql stmt, normally created by build_search_sql
+     * @param$offset the offset
+     * @param$p_paid if we want to see info about payment
+      \code
+      // Example
+      // Build the sql
+      list($sql,$where)=$Ledger->build_search_sql($_GET);
+      // Count nb of line
+      $max_line=$cn->count_sql($sql);
+
+      $step=$_SESSION['g_pagesize'];
+      $page=(isset($_GET['offset']))?$_GET['page']:1;
+      $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+      // create the nav. bar
+      $bar=navigation_bar($offset,$max_line,$step,$page);
+      // show a part
+      list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+      echo $html;
+      // show nav bar
+      echo $bar;
+
+      \endcode
+     * \see build_search_sql
+     * \see display_search_form
+     * \see search_form
+
+     * \return HTML string
+     */
+    public function list_operation($sql, $offset, $p_paid=0)
+    {
+        global $g_parameter, $g_user;
+        bcscale(2);
+        $table=new Sort_Table();
+        $gDossier=dossier::id();
+        $amount_paid=0.0;
+        $amount_unpaid=0.0;
+        $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT 
".$_SESSION['g_pagesize']:"";
+        $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET 
".Database::escape_string($offset):"";
+        $order="  order by jr_date_order asc,jr_internal asc";
+        // Sort
+        $url="?".CleanUrl();
+        $str_dossier=dossier::get();
+        $table->add(_("Date"), $url,
+                'order by jr_date 
asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
+                'order by  jr_date 
desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
+                "da", "dd");
+        $table->add(_('Echeance'), $url, " order by  jr_ech asc",
+                " order by  jr_ech desc", 'ea', 'ed');
+        $table->add(_('Paiement'), $url, " order by  jr_date_paid asc",
+                " order by  jr_date_paid desc", 'eap', 'edp');
+        $table->add(_('Pièce'), $url,
+                ' order by  substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
+                ' order by  substring(jr_pj_number,\'[0-9]+$\')::numeric desc 
',
+                "pja", "pjd");
+        $table->add(_('Tiers'), $url, " order by  name asc",
+                " order by  name desc", 'na', 'nd');
+        $table->add(_('Montant'), $url, " order by jr_montant asc",
+                " order by jr_montant desc", "ma", "md");
+        $table->add(_("Description"), $url, "order by jr_comment asc",
+                "order by jr_comment desc", "ca", "cd");
+
+        $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
+        $order=$table->get_sql_order($ord);
+
+        // Count
+        $count=$this->cn->count_sql($sql);
+        // Add the limit
+        $sql.=$order.$limit.$offset;
+        // Execute SQL stmt
+        $Res=$this->cn->exec_sql($sql);
+
+        //starting from here we can refactor, so that instead of returning the 
generated HTML,
+        //this function returns a tree structure.
+
+        $r="";
+
+
+        $Max=Database::num_row($Res);
+
+        if ($Max==0)
+            return array(0, _("Aucun enregistrement trouvé"));
+
+        $r.='<table class="result">';
+
+
+        $r.="<tr >";
+        $r.="<th>"._("n° interne")."</th>";
+        if ($this->type=='ALL')
+        {
+            $r.=th('Journal');
+        }
+        $r.='<th>'.$table->get_header(0).'</th>';
+        if ($p_paid!=0)
+            $r.='<th>'.$table->get_header(1).'</td>';
+        if ($p_paid!=0)
+            $r.='<th>'.$table->get_header(2).'</th>';
+        $r.='<th>'.$table->get_header(3).'</th>';
+        $r.='<th>'.$table->get_header(4).'</th>';
+        $r.='<th>'.$table->get_header(6).'</th>';
+        $r.=th('Notes', ' style="width:15%"');
+        $r.='<th>'.$table->get_header(5).'</th>';
+        // if $p_paid is not equal to 0 then we have a paid column
+        if ($p_paid!=0)
+        {
+            $r.="<th> "._('Payé')."</th>";
+        }
+        $r.="<th>"._('Concerne')."</th>";
+        $r.="<th>"._('Document')."</th>";
+        $r.="</tr>";
+        // Total Amount
+        $tot=0.0;
+        $gDossier=dossier::id();
+        for ($i=0; $i<$Max; $i++)
+        {
+
+
+            $row=Database::fetch_array($Res, $i);
+
+            if ($i%2==0)
+                $tr='<TR class="odd">';
+            else
+                $tr='<TR class="even">';
+            $r.=$tr;
+            //internal code
+            // button  modify
+            $r.="<TD>";
+            // If url contains
+            //
+
+            $href=basename($_SERVER['PHP_SELF']);
+
+
+            $r.=sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
+                    $row['jr_id'], $gDossier, $row['jr_internal']);
+            $r.="</TD>";
+            if ($this->type=='ALL')
+                $r.=td($row['jrn_def_name']);
+            // date
+            $r.="<TD>";
+            $r.=$row['str_jr_date'];
+            $r.="</TD>";
+            // echeance
+            if ($p_paid!=0)
+            {
+                $r.="<TD>";
+                $r.=$row['str_jr_ech'];
+                $r.="</TD>";
+                $r.="<TD>";
+                $r.=$row['str_jr_date_paid'];
+                $r.="</TD>";
+            }
+
+            // pj
+            $r.="<TD>";
+            $r.=$row['jr_pj_number'];
+            $r.="</TD>";
+
+            // Tiers
+            $other=($row['quick_code']!='')?'['.$row['quick_code'].'] 
'.$row['name'].' '.$row['first_name']:'';
+            $r.=td($other);
+            // comment
+            $r.="<TD>";
+            $tmp_jr_comment=h($row['jr_comment']);
+            $r.=$tmp_jr_comment;
+            $r.="</TD>";
+            $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
+            // Amount
+            // If the ledger is financial :
+            // the credit must be negative and written in red
+            $positive=0;
+
+            // Check ledger type :
+            if ($row['jrn_def_type']=='FIN')
+            {
+                $positive=$this->cn->get_value("select qf_amount from 
quant_fin where jr_id=$1",
+                        array($row['jr_id']));
+                if ($this->cn->count()!=0)
+                    $positive=($positive<0)?1:0;
+            }
+            $r.="<TD align=\"right\">";
+            $t_amount=$row['jr_montant'];
+            if 
($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
+                $t_amount=$row['total_invoice'];
+            $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
+            //STAN $positive always == 0
+            if ($row ['jrn_def_type']=='FIN')
+            {
+                $r.=( $positive!=0 )?"<font color=\"red\">  - 
".nbm($t_amount)."</font>":nbm($t_amount);
+            }
+            else
+            {
+                $r.=( $t_amount<0 )?"<font color=\"red\">  
".nbm($t_amount)."</font>":nbm($t_amount);
+            }
+            $r.="</TD>";
+
+
+            // Show the paid column if p_paid is not null
+            if ($p_paid!=0)
+            {
+                $w=new ICheckBox();
+                $w->name="rd_paid".$row['jr_id'];
+                $w->selected=($row['jr_rapt']=='paid')?true:false;
+                // if p_paid == 2 then readonly
+                $w->readonly=( $p_paid==2)?true:false;
+                $h=new IHidden();
+                $h->name="set_jr_id".$row['jr_id'];
+                $r.='<TD>'.$w->input().$h->input().'</TD>';
+                if ($row['jr_rapt']=='paid')
+                    $amount_paid=bcadd($amount_paid, $t_amount);
+                else
+                    $amount_unpaid=bcadd($amount_unpaid, $t_amount);
+            }
+
+            // Rapprochement
+            $rec=new Acc_Reconciliation($this->cn);
+            $rec->set_jr_id($row['jr_id']);
+            $a=$rec->get();
+            $r.="<TD>";
+            if ($a!=null)
+            {
+
+                foreach ($a as $key=> $element)
+                {
+                    $operation=new Acc_Operation($this->cn);
+                    $operation->jr_id=$element;
+                    $l_amount=$this->cn->get_value("select jr_montant from jrn 
".
+                            " where jr_id=$1", array($element));
+                    $r.="<A class=\"detail\" 
HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > 
".$operation->get_internal()."[".nbm($l_amount)."]</A>";
+                }//for
+            }// if ( $a != null ) {
+            $r.="</TD>";
+
+            if ($row['jr_valid']=='f')
+            {
+                $r.="<TD>"._("Opération annulée")."</TD>";
+            }
+            else
+            {
+                
+            } // else
+            //document
+            if ($row['jr_pj_name']!="")
+            {
+                
$r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
+            }
+            else
+                $r.="<TD></TD>";
+
+            // end row
+            $r.="</tr>";
+        }
+        $amount_paid=round($amount_paid, 4);
+        $amount_unpaid=round($amount_unpaid, 4);
+        $tot=round($tot, 4);
+        $r.="<TR>";
+        $r.='<TD COLSPAN="5">Total</TD>';
+        $r.='<TD ALIGN="RIGHT">'.nbm($tot)."</TD>";
+        $r.="</tr>";
+        if ($p_paid!=0)
+        {
+            $r.="<TR>";
+            $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
+            $r.='<TD ALIGN="RIGHT">'.nbm($amount_paid)."</TD>";
+            $r.="</tr>";
+            $r.="<TR>";
+            $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
+            $r.='<TD ALIGN="RIGHT">'.nbm($amount_unpaid)."</TD>";
+            $r.="</tr>";
+        }
+        $r.="</table>";
+
+        return array($count, $r);
+    }
+
+    /**
+     * @brief Show all the operation
+     * @param$sql is the sql stmt, normally created by build_search_sql
+     * @param$offset the offset
+     * @param$p_paid if we want to see info about payment
+      @code
+      // Example
+      // Build the sql
+      list($sql,$where)=$Ledger->build_search_sql($_GET);
+      // Count nb of line
+      $max_line=$this->cn->count_sql($sql);
+
+      $step=$_SESSION['g_pagesize'];
+      $page=(isset($_GET['offset']))?$_GET['page']:1;
+      $offset=(isset($_GET['offset']))?$_GET['offset']:0;
+      // create the nav. bar
+      $bar=navigation_bar($offset,$max_line,$step,$page);
+      // show a part
+      list($count,$html)= $Ledger->list_operation($sql,$offset,0);
+      echo $html;
+      // show nav bar
+      echo $bar;
+
+      @endcode
+     * @see build_search_sql
+     * @see display_search_form
+     * @see search_form
+
+     * @return HTML string
+     */
+    public function list_operation_to_reconcile($sql, $p_target)
+    {
+        global $g_parameter, $g_user;
+        $gDossier=dossier::id();
+        $limit=" LIMIT ".MAX_RECONCILE;
+        // Sort
+        // Count
+        $count=$this->cn->count_sql($sql);
+        // Add the limit
+        $sql.=" order by jr_date asc ".$limit;
+
+        // Execute SQL stmt
+        $Res=$this->cn->exec_sql($sql);
+
+        //starting from here we can refactor, so that instead of returning the 
generated HTML,
+        //this function returns a tree structure.
+
+        $r="";
+
+
+        $Max=Database::num_row($Res);
+
+        if ($Max==0)
+            return array(0, _("Aucun enregistrement trouvé"));
+        $r.=HtmlInput::hidden("target", $p_target);
+        $r.='<table class="result">';
+
+
+        $r.="<tr >";
+        $r.="<th>"._("Selection")."</th>";
+        $r.="<th>"._("Internal")."</th>";
+
+        if ($this->type=='ALL')
+        {
+            $r.=th(_('Journal'));
+        }
+
+        $r.='<th>'._("Date").'</th>';
+        $r.='<th>'._("Pièce").'</td>';
+        $r.=th(_('tiers'));
+        $r.='<th>'._("Description").'</th>';
+        $r.=th(_('Notes'), ' ');
+        $r.='<th>'._("Montant").'</th>';
+        $r.="<th>"._('Concerne')."</th>";
+        $r.="</tr>";
+        // Total Amount
+        $tot=0.0;
+        $gDossier=dossier::id();
+        $str_dossier=Dossier::id();
+        for ($i=0; $i<$Max; $i++)
+        {
+
+
+            $row=Database::fetch_array($Res, $i);
+
+            if ($i%2==0)
+                $tr='<TR class="odd">';
+            else
+                $tr='<TR class="even">';
+            $r.=$tr;
+            // Radiobox
+            //
+
+                       $r.='<td><INPUT TYPE="CHECKBOX" 
name="jr_concerned'.$row['jr_id'].'" ID="jr_concerned'.$row['jr_id'].'" 
value="'.$row['quick_code'].'"> </td>';
+            //internal code
+            // button  modify
+            $r.="<TD>";
+            // If url contains
+            //
+
+            $href=basename($_SERVER['PHP_SELF']);
+
+
+            $r.=sprintf('<A class="detail" style="text-decoration:underline" 
HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
+                    $row['jr_id'], $gDossier, $row['jr_internal']);
+            $r.="</TD>";
+            if ($this->type=='ALL')
+                $r.=td($row['jrn_def_name']);
+            // date
+            $r.="<TD>";
+            $r.=$row['str_jr_date'];
+            $r.="</TD>";
+
+            // pj
+            $r.="<TD>";
+            $r.=$row['jr_pj_number'];
+            $r.="</TD>";
+
+            // Tiers
+            $other=($row['quick_code']!='')?'['.$row['quick_code'].'] 
'.$row['name'].' '.$row['first_name']:'';
+            $r.=td($other);
+            // comment
+            $r.="<TD>";
+            $tmp_jr_comment=h($row['jr_comment']);
+            $r.=$tmp_jr_comment;
+            $r.="</TD>";
+            $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
+            // Amount
+            // If the ledger is financial :
+            // the credit must be negative and written in red
+            $positive=0;
+
+            // Check ledger type :
+            if ($row['jrn_def_type']=='FIN')
+            {
+                $positive=$this->cn->get_value("select qf_amount from 
quant_fin where jr_id=$1",
+                        array($row['jr_id']));
+                if ($this->cn->count()!=0)
+                    $positive=($positive<0)?1:0;
+            }
+            $r.="<TD align=\"right\">";
+
+            $r.=( $positive!=0 )?"<font color=\"red\">  - 
".nbm($row['jr_montant'])."</font>":nbm($row['jr_montant']);
+            $r.="</TD>";
+
+
+
+            // Rapprochement
+            $rec=new Acc_Reconciliation($this->cn);
+            $rec->set_jr_id($row['jr_id']);
+            $a=$rec->get();
+            $r.="<TD>";
+            if ($a!=null)
+            {
+
+                foreach ($a as $key=> $element)
+                {
+                    $operation=new Acc_Operation($this->cn);
+                    $operation->jr_id=$element;
+                    $l_amount=$this->cn->get_value("select jr_montant from jrn 
".
+                            " where jr_id=$1", array($element));
+                    $r.="<A class=\"detail\" 
HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > 
".$operation->get_internal()."[".nbm($l_amount)."]</A>";
+                }//for
+            }// if ( $a != null ) {
+            $r.="</TD>";
+
+            if ($row['jr_valid']=='f')
+            {
+                $r.="<TD>"._("Opération annulée")."</TD>";
+            }
+            // end row
+            $r.="</tr>";
+        }
+        $r.='</table>';
+        return array($count, $r);
+    }
+
+}
diff --git a/include/database/user_filter_sql.class.php 
b/include/database/user_filter_sql.class.php
new file mode 100644
index 0000000..084c632
--- /dev/null
+++ b/include/database/user_filter_sql.class.php
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * Autogenerated file 
+ *   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
+ * author : Dec 2017 , Dany De Bontridder (address@hidden)
+ */
+require_once NOALYSS_INCLUDE.'/lib/noalyss_sql.class.php';
+require_once NOALYSS_INCLUDE.'/lib/database.class.php';
+
+/**
+ * class_user_filter_sql.php
+ *
+ * @file
+ * @brief abstract of the table public.user_filter 
+ */
+class User_filter_SQL extends Noalyss_SQL
+{
+
+    function __construct(Database $p_cn, $p_id=-1)
+    {
+        $this->table="public.user_filter";
+        $this->primary_key="id";
+        /*
+         * List of columns
+         */
+        $this->name=array(
+            "id"=>"id"
+            , "login"=>"login"
+            , "nb_jrn"=>"nb_jrn"
+            , "date_start"=>"date_start"
+            , "date_end"=>"date_end"
+            , "description"=>"description"
+            , "amount_min"=>"amount_min"
+            , "amount_max"=>"amount_max"
+            , "qcode"=>"qcode"
+            , "accounting"=>"accounting"
+            , "r_jrn"=>"r_jrn"
+            , "date_paid_start"=>"date_paid_start"
+            , "date_paid_end"=>"date_paid_end"
+            , "ledger_type"=>"ledger_type"
+            , "all_ledger"=>"all_ledger"
+            ,"unpaid"=>"unpaid"
+            ,'filter_name'=>"filter_name"
+        );
+        /*
+         * Type of columns
+         */
+        $this->type=array(
+            "id"=>"numeric"
+            , "login"=>"text"
+            , "nb_jrn"=>"numeric"
+            , "date_start"=>"text"
+            , "date_end"=>"text"
+            , "description"=>"text"
+            , "amount_min"=>"numeric"
+            , "amount_max"=>"numeric"
+            , "qcode"=>"text"
+            , "accounting"=>"text"
+            , "r_jrn"=>"text"
+            , "date_paid_start"=>"text"
+            , "date_paid_end"=>"text"
+            , "ledger_type"=>"text"
+            , "all_ledger"=>"numeric"
+            ,"unpaid"=>"text"
+            ,"filter_name"=>"text"
+        );
+
+
+        $this->default=array(
+            "id"=>"auto"
+        );
+
+        $this->date_format="DD.MM.YYYY";
+        parent::__construct($p_cn, $p_id);
+    }
+
+}
diff --git a/include/history_operation.inc.php 
b/include/history_operation.inc.php
index 8564a11..cdba89b 100644
--- a/include/history_operation.inc.php
+++ b/include/history_operation.inc.php
@@ -32,33 +32,29 @@ require_once 
NOALYSS_INCLUDE.'/class/acc_ledger_purchase.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger_fin.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger_sold.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger.class.php';
+require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
 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':
-                $Ledger = new Acc_Ledger_Purchase($cn, 0);
                 $ask_pay=1;
                 break;
         case 'ODS':
-                $Ledger=new Acc_Ledger($cn,0);
                 $ask_pay=0;
                 $p_array['ledger_type']='ODS';
-                $Ledger->type='ODS';
                 break;
         case 'ALL':
-                $Ledger=new Acc_Ledger($cn,0);
                 $ask_pay=0;
                 $p_array['ledger_type']='ALL';
-                $Ledger->type='ALL';
                 break;
         case 'VEN':
-                $Ledger=new Acc_Ledger_Sold($cn,0);
                 $ask_pay=1;
                 break;
         case 'FIN':
-                $Ledger=new Acc_Ledger_Fin($cn,0);
                 $ask_pay=0;
                 break;
 
diff --git a/include/template/ledger_search.php 
b/include/template/ledger_search.php
index d0e4180..ccd65e3 100644
--- a/include/template/ledger_search.php
+++ b/include/template/ledger_search.php
@@ -1,15 +1,17 @@
 <?php
 //This file is part of NOALYSS and is under GPL 
 //see licence.txt
+require_once NOALYSS_INCLUDE.'/lib/select_box.class.php';
 ?>
-<table>
+<table id="<?=$this->div?>table_search">
+    
 <tr>
 <td style="text-align:right;width:30em">
 <?php echo _('Dans le journal')?>
 </td>
 <td>
    <?php echo $f_ledger; ?>
-    <span id="ledger_id<?php echo $div;?>">
+    <span id="ledger_id<?php echo $this->div;?>">
         <?php
         echo $hid_jrn;
         ?>
@@ -80,4 +82,9 @@
 </tr>
 
 </table>
-
+<?php
+$box=new Select_Box("{$this->div}button","Filtre");
+$box->add_input(_('Ajout'), $save_filter);
+$box->add_javascript(_('Gestion Filtre'), $search_filter);
+echo $box->input();
+?>
diff --git a/scenario/test-iselect-button.php b/scenario/select-box-test.php
similarity index 77%
rename from scenario/test-iselect-button.php
rename to scenario/select-box-test.php
index ae37bed..991c6fc 100644
--- a/scenario/test-iselect-button.php
+++ b/scenario/select-box-test.php
@@ -8,23 +8,24 @@
       background:white;
       width:455px;
       max-width:250px;
-      position:relative;
-      z-index:3;
       padding:3px;
       margin:0px;
       display:none;
       top:-17px;
+      position:absolute;
       }
      div.select_box ul {
        list-style:none;
        padding:2px;
        margin:1px;
        width:100%;
+       top:10px;
+
      }
 div.select_box ul li {
     padding-top:2px;
     padding-bottom:2px;
-  margin:2px;
+    margin:2px;
 }
 div.select_box a {
     text-decoration:none;
@@ -38,6 +39,12 @@ div.select_box a:hover,div.select_box ul li:hover {
 
 </head>
 <body>
+    <div>
+        <p>
+            Le CSS est important , surtout la position, il faut qu'il soit 
dans 
+            un élément positionné en absolu.
+        </p>
+        <p style="position: absolute">
   <?php
      require NOALYSS_INCLUDE.'/lib/select_box.class.php';
      $a=new Select_Box("test","click me !");
@@ -50,4 +57,6 @@ div.select_box a:hover,div.select_box ul li:hover {
      echo $a->input();
      
      ?>
+        </p>
+        </div>
 </body>



reply via email to

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