noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_search_filter.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
25$cn=Dossier::connect();
26$dossier_id=Dossier::id();
27global $g_user;
28/**
29 * @file
30 * @brief Managed the search filter
31 */
33//---------------------------------------------------------------------------
34// Record the the search filter
35//---------------------------------------------------------------------------
36$op=$http->request("op");
37if ($op=='save_filter')
38{
39 $answer=[];
40 $answer['filter_name']="";
41 $answer['status']='NOK';
42 $answer['filter_id']=0;
43 $answer['message']="";
44 try
45 {
46 $new=new User_filter_SQL($cn, -1);
47 $new->setp("login", $g_user->login);
48 $new->setp("nb_jrn", $http->post("nb_jrn", 'number'));
49 $new->setp("date_start", $http->post("date_start", 'string', NULL));
50 $new->setp("date_end", $http->post("date_end", 'string', NULL));
51 $new->setp("description", $http->post("desc", 'string', NULL));
52 $new->setp("amount_min", $http->post("amount_min", 'number', NULL));
53 $new->setp("amount_max", $http->post("amount_max", 'number', NULL));
54 $new->setp("qcode", $http->post("qcode", 'string', NULL));
55 $new->setp("accounting", $http->post("accounting", 'string', NULL));
56 $new->setp("uf_tag_option",$http->post("tag_option","string",null));
57 $new->setp("date_paid_start",
58 $http->post("date_paid_start", 'string', NULL));
59 $new->setp("date_paid_end", $http->post("date_paid_end", 'string', NULL));
60 $new->setp("ledger_type", $http->post("ledger_type", 'string'));
61 $new->setp("operation_filter", $http->post("operation_filter", 'string', NULL));
62 $new->setp("filter_name", h($http->post("filter_name", 'string')));
63 $new->setp("uf_currency_code", h($http->post("p_currency_code", 'number',-1)));
64 $acc_tva=Acc_Tva::build($cn, $http->post("tva_id_search", 'string',-1));
65 $tva_id=($acc_tva->tva_id===-1)?null:$acc_tva->tva_id;
66 $new->setp("tva_id_search",$tva_id);
67 $tag=$http->post("tag","string",'');
68
69 if (is_array($tag) )
70 $new->setp("uf_tag",join(',',$tag));
71 else
72 $new->setp("uf_tag",null);
73 $aJrn=[];
74 $max=$http->post("nb_jrn");
75 for ($i=0; $i<$max; $i++)
76 {
77 $aJrn[]=$http->post("r_jrn".$i, "number");
78 }
79 $new->setp("r_jrn", join(',', $aJrn));
80 if (strlen($new->getp("filter_name"))==0)
81 {
82 throw new Exception(_("Nom ne peut être vide"));
83 }
84 $new->save();
85 $rmAction=sprintf("delete_filter('%s','%s','%s')", trim($http->post('div')), $dossier_id,
86 $new->getp('id'));
87 $answer['filter_name']="";
88 $answer['filter_name'].=sprintf("<a class=\"line\" style=\"display:inline;text-decoration:underline\" onclick=\"load_filter('%s','%s','%s')\">%s</a>",
89 trim($http->post('div')), $dossier_id, $new->getp('id'),
90 $new->getp("filter_name"));
91 $answer['filter_name'].='<span id="'.uniqid().'" onclick="'.$rmAction.'" class="icon" style="display:inline;margin-left:2em">&#xe80f;</span>';;
92 $answer['filter_id']=$new->getp("id");
93 $answer['status']='OK';
94 }
95 catch (Exception $ex)
96 {
97 $answer['status']='NOK';
98 $answer['message']=$ex->getMessage();
99 }
100 header('Content-Type: application/json;charset=utf-8');
101 echo json_encode($answer);
102 return;
103}
104//------------------------------------------------------------------------------
105// Load a filter
106//------------------------------------------------------------------------------
107if ($op=="load_filter")
108{
109 $filter_id=$http->get("filter_id", "number");
110 $div=$http->get("div");
111 $answer=[];
112 $answer['status']='OK';
113 $answer['filter_id']=0;
114 $answer['message']="";
115 $filter=new User_filter_SQL($cn, $filter_id);
117 $result=array_merge($answer, $record);
118
119
120 header('Content-Type: application/json;charset=utf-8');
121 echo json_encode($result);
122 return;
123}
124//-----------------------------------------------------------------------------
125// Display all the existing search filters and allow to load or delete them
126// id of the box is "boxfilter"+{p_div}
127//------------------------------------------------------------------------------
128if ($op=="display_search_filter")
129{
130 $p_div=$http->get("div");
131 $ledger_type=$http->get("ledger_type");
132
133 echo HtmlInput::title_box(_("Filtre"), "boxfilter".$p_div);
134
135
136
137 // Make a list of all search filters with the same ledger_type of the current
138 // user
139 $result=$cn->get_array("
140 select id, filter_name,ledger_type
141 from user_filter
142 where
143 login = $1
144 and ledger_type=$2
145 order by 2 asc
146", [$g_user->login, $ledger_type]);
147 $nb_result=count($result);
148 printf('<ul class="select_table" id="manage%s">', $p_div);
149 $search_filter=new Acc_Ledger_Search($ledger_type,1,$p_div);
150 // Button add filter
151 echo "<li>";
152 echo $search_filter->build_name_filter();
153 echo "</li>";
154
155 echo "<li>";
156 echo HtmlInput::anchor(_("Remise à zéro"), "", "style=\"text-decoration:underline\" onclick=\"reset_filter('$p_div');removeDiv('boxfilter{$p_div}')\"");
157 echo "</li>";
158
159 // Link reset
160 for ($i=0; $i<$nb_result; $i++)
161 {
162 printf(' <li id="manageli%s_%d">', $p_div, $result[$i]["id"]);
163 $rmAction=sprintf("delete_filter('%s','%s','%s')", $p_div, $dossier_id,
164 $result[$i]['id']);
165 printf("<a href=\"javascript:void(0)\" style=\"display:inline;text-decoration:underline\" onclick=\"load_filter('%s','%s','%s');removeDiv('boxfilter%s')\">",
166 $p_div, $dossier_id, $result[$i]["id"],$p_div);
167 echo $result[$i]["filter_name"];
168 echo '</a>';
169 echo '<span id="'.uniqid().'" onclick="'.$rmAction.'" class="icon" style="display:inline;margin-left:2em">&#xe80f;</span>';
170
171 printf("</li>");
172 }
173 echo '</ul>';
174 echo HtmlInput::button_close("boxfilter".$p_div);
175 return;
176}
177//-----------------------------------------------------------------------------
178// Delete a filter_id
179// Check if this filter belong to current user
180//------------------------------------------------------------------------------
181if ($op=="delete_search_operation")
182{
183 $answer=[];
184 $answer['filter_name']="";
185 $answer['status']='NOK';
186 $answer['filter_id']=0;
187 $answer['message']="";
188 try
189 {
190 $p_div=$http->post("div");
191 $filter_id=$http->post("filter_id", "number");
192
193 $answer['div']=$p_div;
194
195 $cn->exec_sql("delete from user_filter where id=$1 and login=$2",[$filter_id,$g_user->login]);
196
197 $answer['filter_id']=$filter_id;
198 $answer['status']="OK";
199 }
200 catch (Exception $ex)
201 {
202 $answer['message']=$ex->getMessage();
203 }
204 header('Content-Type: application/json;charset=utf-8');
205 echo json_encode($answer);
206 return;
207}
208//---------------------------------------------------------------------------------------------------------------
209// display_filter_tag : transform uf_tag into a list of tag , and display those tags in cells
210//----------------------------------------------------------------------------------------------------------------
211if ($op=='display_filter_tag')
212{
213 $tag=$http->request("uf_tag");
214 if ( trim($tag)=="") {return;}
215 $div=$http->request("div");
216 $aTag=explode(',', $tag);
217 if (is_array($aTag))
218 {
219 $nb_tag=count($aTag);
220 for ($j=0; $j<$nb_tag; $j++)
221 {
223 $tag_operation->update_search_cell($div);
224 }
225 }
226 return;
227}
228//---------------------------------------------------------------------------------------------------------------
229// display_list_filter : display a list of saved search alias filter
230//----------------------------------------------------------------------------------------------------------------
231if ($op=='display_list_filter')
232{
233 echo \HtmlInput::title_box("Recherches sauvées",'display_list_filter_div');
234
235 $ledger_search=new Acc_Ledger_Search($http->request("ledger_type"));
236 $ledger_search->display_list_filter();
237?>
238
239
240 <ul class="aligned-block">
241 <li>
242 <?=\HtmlInput::button_close("display_list_filter_div")?>
243 </li>
244 </ul>
245<?php
246 return;
247}
global $g_user
if no group available , then stop
$dossier_id
$op
h( $row[ 'oa_description'])
$answer
$filter
_("actif, passif,charge,...")
$ex
static build_array(User_Filter_SQL $user_filter_sql)
use a user_filter row and turns it into an array for javascript purpose
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static anchor($p_text, $p_url="", $p_js="", $p_style=' class="line" ', $p_title="click", array $p_attribute=[])
Return a simple LINK with a url or a javascript if $p_js is not null then p_url will be javascript:vo...
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n', $raw="")
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
manage the http input (get , post, request) and extract from an array
concerns the tags linked to an accountancy writing
ORM abstract of the table public.user_filter.