noalyss Version-9
acc_ledger_search.class.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
22// if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
23
24
25/**
26 * @file
27 * @brief search in ledger
28 */
29/**
30 * @class Acc_Ledger_Search
31 * @brief search in ledger
32 */
34{
35
36 protected $cn; //!< Database Connection
37 private $type; //!< type of ledger : FIN,ODS,VEN,ACH
38 private $all; //!< Flag to indicate if all ledgers must searched (1 for yes)
39 private $div; //! prefix for id of DOM id
40 //! id of the ledger
41 var $id ;
42 /**
43 * @brief return a HTML string with the form for the search
44 * @param $p_type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN: uppercase !
45 * @param $all_type_ledger
46 * values :
47 * - 1 means all the ledger of this type
48 * - 0 No have the "Tous les journaux" availables
49 * @param $div is the div (for reconciliation)
50 * @param type $p_type
51 * @param type $p_all
52 * @param type $p_div
53 *
54 * @todo the parameter $all_type_ledger is useless : ALL means all the ledgers, VEN all the ledger of sales...
55 */
56
57 function __construct($p_type, $p_all=1, $p_div="")
58 {
59 $this->cn=Dossier::connect();
60 $this->set_type($p_type);
61 $this->all=$p_all;
62 $this->div=$p_div;
63 }
64
65 public function get_type()
66 {
67 return $this->type;
68 }
69
70 public function get_all()
71 {
72 return $this->all;
73 }
74
75 public function get_div()
76 {
77 return $this->div;
78 }
79
80 public function set_type($type)
81 {
82 if (! in_array($type, ["ALL","VEN","ACH","ODS","FIN"]))
83 {
84 throw new Exception ("ALS02 : type invalide $type",EXC_PARAM_VALUE);
85 }
86 $this->type=$type;
87 }
88
89 public function set_all($all)
90 {
91 $this->all=$all;
92 }
93
94 public function set_div($div)
95 {
96 $this->div=$div;
97 }
98
99 /**
100 * @brief return a HTML string with the form for the search
101 * @return a HTML String without the tag FORM or DIV
102 *
103 * @see build_search_sql
104 * @see display_search_form
105 * @see list_operation
106 * @example search_acc_operation.php
107 */
108 function search_form()
109 {
110 global $g_user,$g_parameter;
112 $http=new HttpInput();
113 $r="";
114 $bledger_param=json_encode(array(
115 'dossier'=>Dossier::id(),
116 'type'=>$this->type,
117 'all_type'=>$this->all,
118 'div'=>$this->div
119 ));
120
121 $bledger_param=noalyss_str_replace('"', "'", $bledger_param);
122 $bledger=new ISmallButton('l');
123 $bledger->label=_("choix des journaux");
124 $bledger->javascript=" show_ledger_choice($bledger_param)";
125 $f_ledger=$bledger->input();
126 $hid_jrn="";
127 if (isset($_REQUEST[$this->div.'nb_jrn']))
128 {
129 for ($i=0; $i<$_REQUEST[$this->div.'nb_jrn']; $i++)
130 {
131 if (isset($_REQUEST[$this->div."r_jrn"][$i]))
132 $hid_jrn.=HtmlInput::hidden($this->div.'r_jrn['.$i.']',
133 $_REQUEST[$this->div."r_jrn"][$i]);
134 }
135 $hid_jrn.=HtmlInput::hidden($this->div.'nb_jrn',
136 $_REQUEST[$this->div.'nb_jrn']);
137 } else
138 {
139 $hid_jrn=HtmlInput::hidden($this->div.'nb_jrn', 0);
140 }
141 /* Compute default date for exercice */
142 $period=$g_user->get_periode();
143 $per=new Periode($this->cn, $period);
144 $exercice=$per->get_exercice();
145 list($per_start, $per_end)=$per->get_limit($exercice);
146 $date_end=$per_end->last_day();
147 $date_start=$per_start->first_day();
148
149 $date_start_hidden=HtmlInput::hidden("{$this->div}date_start_hidden", $date_start);
150 $date_end_hidden=HtmlInput::hidden("{$this->div}date_end_hidden", $date_end);
151 /* widget for date_start */
152 $f_date_start=new IDate('date_start', '', $this->div."date_start");
153
154 /* all periode or only the selected one */
155 $f_date_start->value=$http->request("date_start","string",$date_start);
156
157 /* widget for date_end */
158 $f_date_end=new IDate('date_end', '', $this->div."date_end");
159
160 /* all date or only the selected one */
161 $f_date_end->value=$http->request("date_end","string",$date_end);
162
163 /* widget for date term */
164 $f_date_paid_start=new IDate('date_paid_start', '',
165 $this->div."date_paid_start");
166 $f_date_paid_end=new IDate('date_paid_end', '',
167 $this->div."date_paid_end");
168
169 $f_date_paid_start->value=$http->request("date_paid_start","string","");
170 $f_date_paid_end->value=$http->request("date_paid_end","string","");
171
172 /* widget for desc */
173 $f_descript=new IText('desc', "", $this->div."desc");
174 $f_descript->size=40;
175 $f_descript->value=$http->request('desc',"string","");
176
177 /* widget for amount */
178 $f_amount_min=new INum('amount_min', '0', $this->div."amount_min");
179 $f_amount_min->value=$http->request("amount_min","string",0);
180 $f_amount_max=new INum('amount_max', '0', $this->div."amount_max");
181 $f_amount_max->value=$http->request("amount_max","string",0);
182
183
184 /* input quick code */
185 $f_qcode=new ICard($this->div.'qcode');
186
187 $f_qcode->set_attribute('typecard', 'all');
188 /* $f_qcode->set_attribute('p_jrn','0');
189
190 $f_qcode->set_callback('filter_card');
191 */
192 $f_qcode->set_dblclick("fill_ipopcard(this);");
193 // Add the callback function to filter the card on the jrn
194 //$f_qcode->set_callback('filter_card');
195 $f_qcode->set_function('fill_data');
196 $f_qcode->javascript=sprintf(' onchange="fill_data_onchange(%s);" ',
197 $f_qcode->name);
198 $f_qcode->value=$http->request($this->div.'qcode',"string","");
199
200 /* $f_txt_qcode=new IText('qcode');
201 $f_txt_qcode->value=(isset($_REQUEST['qcode']))?$_REQUEST['qcode']:'';
202 */
203
204 /* input poste comptable */
205 $f_accounting=new IPoste('accounting', "", $this->div."accounting");
206 $f_accounting->value=$http->request('accounting',"string","");
207 /*
208 * utile ??? Filtre les postes comptables en fonction du journal
209 * if ($this->id==-1)
210 $jrn=0;
211 else
212 $jrn=$this->id; */
213 $f_accounting->set_attribute('jrn', 0);
214 $f_accounting->set_attribute('ipopup', 'ipop_account');
215 $f_accounting->set_attribute('label', 'ld');
216 $f_accounting->set_attribute('account', $this->div.'accounting');
217 $info=Icon_Action::infobulle(13);
218
219 // Status of the operation : paid, unpaid or all
220 $f_paid=new ISelect('operation_filter', null, $this->div.'operation_filter');
221 $f_paid->value=array(["value"=>'all',"label"=>_("Toutes")],
222 ["value"=>'unpaid',"label"=>_("Non payées")],
223 ["value"=>'paid',"label"=>_("Payées")]
224 );
225 $f_paid->selected=$http->request("operation_filter","string","all");
226
227 $r.=dossier::hidden();
228 $r.=HtmlInput::hidden('ledger_type', $this->type,
229 $this->div."ledger_type");
230 $r.=HtmlInput::hidden('ac', $http->request('ac'));
231
232 // to avoid to find a given operation
233 if (isset($_REQUEST['hide_operation']))
234 $r.=HtmlInput::hidden("hide_operation", $http->request('hide_operation'));
235
236 if (isset($_REQUEST['single_operation']))
237 $r.=HtmlInput::hidden("single_operation", $http->request('single_operation'));
238
239 //------
240 // Devise
241 ///-------
242 $currency_id=$http->request("p_currency_code","string",-1);
243 $acc_currency=new Acc_Currency($this->cn);
244
245 $sCurrency=$acc_currency->select_currency();
246 $sCurrency->id=$this->div."p_currency_code";
247 $sCurrency->value[]=array("label"=>_("Toutes"),"value"=>-1);
248 $sCurrency->selected=$currency_id;
249 $tva_id_search=new ITva_Popup("tva_id_search",
250 $http->request("tva_id_search","string",null),
251 $this->div."tva_id_search");
252 ob_start();
253 $search_filter=$this->build_search_filter();
254 require_once NOALYSS_TEMPLATE.'/ledger_search.php';
255 $r.=ob_get_contents();
256 ob_end_clean();
257 return $r;
258 }
259
260 /**
261 * Build the button for managing the filter for search
262 * @param type $p_div id prefix of the div, button, table ..
263 * @param $this->type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN
264 * @param $all_type_ledger
265 * values :
266 * - 1 means all the ledger of this type
267 * - 0 No have the "Tous les journaux" availables
268 */
270 {
271 $json=json_encode(["div"=>$this->div, "ledger_type"=>$this->type, "all_type"=>$this->all,
272 "dossier"=>Dossier::id()]);
273 $json=noalyss_str_replace('"', "'", $json);
274 $r=sprintf('manage_search_filter(%s)', $json);
275 return $r;
276 }
277
278 /**
279 * Build the button for saving the filter for search
280 */
282 {
283 $name=new IText($this->div."filter_new");
284 $name->placeholder=_("Nom de la recherche");
285 $r=$name->input();
286 $bt=new IButton($this->div."save_ok",_("Ajout"));
287 $bt->javascript=sprintf("save_filter('%s','%s')",$this->div,Dossier::id());
288 $r.=$bt->input();
289 return $r;
290 }
291
292 /**
293 * @brief this function will create a sql stmt to use to create the list for
294 * the ledger,
295 * @param $p_array is usually the $_GET,
296 * @param $p_order the order of the row --> not used
297 * @param $p_where is the sql condition if not null then the $p_array will not be used
298 * \note the p_action will be used to filter the ledger but gl means ALL
299 * struct array $p_array
300 \verbatim
301 (
302 [gDossier] => 13
303 [p_jrn] => -1
304 [date_start] =>
305 [date_end] =>
306 [amount_min] => 0
307 [amount_max] => 0
308 [desc] =>
309 [search] => Rechercher
310 [p_action] => ven
311 [sa] => l
312 )
313 \endverbatim
314 * \return an array with a valid sql statement, an the where clause => array[sql] array[where]
315 * \see list_operation
316 * \see display_search_form
317 * \see search_form
318 */
319 public function build_search_sql($p_array, $p_order="", $p_where="")
320 {
321 $sql="with cas as (
322 select distinct jr_id
323 from jrn
324 join jrnx on (jr_grpt_id=j_grpt)
325 where
326 exists(select 1 from operation_analytique where j_id=jrnx.j_id) )
327 select jr_id ,
328 jr_montant,
329 substr(jr_comment,1,60) as jr_comment,
330 to_char(jr_ech,'DD.MM.YY') as str_jr_ech,
331 to_char(jr_date,'DD.MM.YY') as str_jr_date,
332 jr_date as jr_date_order,
333 jr_grpt_id,
334 jr_rapt,
335 jr_internal,
336 jrn_def_id,
337 jrn_def_name,
338 jrn_def_ech,
339 jrn_def_type,
340 jr_valid,
341 jr_tech_per,
342 jr_pj_name,
343 p_closed,
344 jr_pj_number,
345 n_text,
346 (select string_agg(a,' ')
347 from (select '<span style=\"font-size:80%\" class=\"tagcell tagcell-color'||t.t_color::text||'\">'||t_tag||'</span>' a
348 from operation_tag ot join tags t on(ot.tag_id=t.t_id)
349 where ot.jrn_id=X.jr_id
350 ) as tag_ml)
351 as tag_operation
352 ,
353 case
354 when jrn_def_type='VEN' then
355 (select ad_value from fiche_detail where ad_id=1
356 and f_id=(select max(qs_client) from quant_sold join jrnx
357 using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt)
358 where e.jr_id=x.jr_id))
359 when jrn_def_type = 'ACH' then
360 (select ad_value
361 from fiche_detail
362 where ad_id=1
363 and f_id=(select max(qp_supplier) from quant_purchase
364 join jrnx using (j_id) join jrn as e on (e.jr_grpt_id=j_grpt) where e.jr_id=x.jr_id))
365 when jrn_def_type = 'FIN' then
366 (select ad_value from fiche_detail where ad_id=1
367 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
368 end as name,
369 case
370 when jrn_def_type='VEN' then
371 (select ad_value from fiche_detail
372 where ad_id=32
373 and f_id=(select max(qs_client)
374 from quant_sold
375 join jrnx using (j_id)
376 join jrn as e on (e.jr_grpt_id=j_grpt)
377 where e.jr_id=x.jr_id))
378 when jrn_def_type = 'ACH' then (select ad_value
379 from fiche_detail
380 where ad_id=32
381 and f_id=(select max(qp_supplier)
382 from quant_purchase
383 join jrnx using (j_id)
384 join jrn as e on (e.jr_grpt_id=j_grpt)
385 where e.jr_id=x.jr_id))
386 when jrn_def_type = 'FIN' then (select ad_value
387 from fiche_detail
388 where ad_id=32
389 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
390 end as first_name,
391 case
392 when jrn_def_type='VEN' then
393 (select ad_value
394 from fiche_detail
395 where ad_id=23
396 and f_id=(select max(qs_client)
397 from quant_sold
398 join jrnx using (j_id)
399 join jrn as e on (e.jr_grpt_id=j_grpt)
400 where e.jr_id=x.jr_id))
401 when jrn_def_type = 'ACH' then (select ad_value
402 from fiche_detail
403 where ad_id=23
404 and f_id=(select max(qp_supplier)
405 from quant_purchase
406 join jrnx using (j_id)
407 join jrn as e on (e.jr_grpt_id=j_grpt)
408 where e.jr_id=x.jr_id))
409 when jrn_def_type = 'FIN' then (select ad_value
410 from fiche_detail
411 where ad_id=23
412 and f_id=(select qf_other from quant_fin where quant_fin.jr_id=x.jr_id))
413 end as quick_code,
414 ( case
415 when jrn_def_type='VEN' then
416 (select sum(qs_price)+sum(vat) from
417 (select qs_internal,qs_price,case when qs_vat_sided<>0 then 0
418 else qs_vat end as vat
419 from quant_sold
420 where qs_internal=X.jr_internal) as ven_invoice
421 )
422 when jrn_def_type = 'ACH' then
423 (select sum(qp_price)+sum(vat)+sum(qp_nd_tva)+sum(qp_nd_tva_recup)
424 from
425 (select qp_internal,qp_price,qp_nd_tva,qp_nd_tva_recup,qp_vat-qp_vat_sided as vat
426 from quant_purchase
427 where qp_internal=X.jr_internal) as invoice_purchase
428 )
429 else jr_montant
430 end +
431 coalesce( case when jrn_def_type='VEN' then
432 (select sum(case when j102.j_debit is true then 0-j102.J_montant else j102.j_montant end)
433 from jrnx j102 join jrn_tax using(j_id) where j102.j_grpt =X.jr_grpt_id)
434 when jrn_def_type='ACH' then
435 (select sum(case when j103.j_debit is false then 0-j103.J_montant else j103.j_montant end)
436 from jrnx j103 join jrn_tax using(j_id) where j103.j_grpt =X.jr_grpt_id)
437 else
438 0 end ,0) ) as total_invoice,
439 jr_date_paid,
440 to_char(jr_date_paid,'DD.MM.YY') as str_jr_date_paid,
441 cas.jr_id as analytic_op,
442 x.currency_id,
443 (select cr_code_iso from currency c where c.id=x.currency_id) cr_code_iso,
444 x.currency_rate
445 from
446 jrn as X
447 left join jrn_note using(jr_id)
448 left join cas using( jr_id)
449 join jrn_def on jrn_def_id=jr_def_id
450 join parm_periode on p_id=jr_tech_per
451 ";
452
453 if (!empty($p_array))
454 extract($p_array, EXTR_SKIP);
455
457 if (isset($p_array[$op."r_jrn"]))
458 {
459 $r_jrn=$p_array[$op."r_jrn"];
460 }
461 else
462 {
463 $r_jrn=(isset($r_jrn))?$r_jrn:-1;
464 }
465
466 /* if no variable are set then give them a default
467 * value */
468 if ($p_array==null||empty($p_array)||!isset($amount_min))
469 {
470 $amount_min=0;
471 $amount_max=0;
472
473 $desc='';
474 $qcode=(isset($p_array[$this->div."qcode"]))?$p_array[$this->div."qcode"]:"";
476 $periode=new Periode($this->cn);
477 $g_user=new Noalyss_user($this->cn);
478 $p_id=$g_user->get_periode();
479 if ($p_id!=null)
480 {
481 list($date_start, $date_end)=$periode->get_date_limit($p_id);
482 }
483 }
484
485 /* if p_jrn : 0 if means all ledgers, if -1 means all ledger of this
486 * type otherwise only one ledger */
487 $fil_ledger='';
488 $fil_amount='';
489 $fil_date='';
490 $fil_desc='';
491 $fil_sec='';
492 $fil_qcode='';
493 $fil_account='';
494 $fil_paid='';
495 $fil_date_paid='';
496 $fil_hide_operation='';
497 $fil_tag='';
498 $fil_currency="";
499 $fil_vat="";
500
501 $and='';
502 $g_user=new Noalyss_user($this->cn);
503 $p_action=(isset ($ledger_type)) ? $ledger_type:$this->type;
504 if ($p_action=='')
505 $p_action='ALL';
506 if ($r_jrn==-1)
507 {
508
509 /* from compta.php the p_action is quick_writing instead of ODS */
510 if ($p_action=='quick_writing')
511 $p_action='ODS';
512
513
514 $fil_ledger=$g_user->get_ledger_sql($p_action, 3);
515 $and=' and ';
516 }
517 else
518 {
519
520 if ($p_action=='quick_writing')
521 $p_action='ODS';
522
523 $aLedger=$g_user->get_ledger($p_action, 3);
524 $fil_ledger='';
525 $sp='';
526 for ($i=0; $i<count($r_jrn); $i++)
527 {
528 if (isset($r_jrn[$i]))
529 {
530 $a=$r_jrn[$i];
531 $fil_ledger.=$sp.$a;
532 $sp=',';
533 }
534 }
535 $fil_ledger=' jrn_def_id in ('.$fil_ledger.')';
536 $and=' and ';
537
538 /* no ledger selected */
539 if ($sp=='')
540 {
541 $fil_ledger='';
542 $and='';
543 }
544 }
545 //----
546 // Search tags
547 if ( isset($p_array[$op."tag"] ))
548 {
549 $strTag=join(",", $p_array[$op."tag"]);
550 if ($p_array[$op."tag_option"] == 1){
551 // any tag
552 $fil_tag=$and.' jr_id in (select jrn_id from operation_tag where tag_id in ('.sql_string($strTag).')) ';
553 } else {
554 // all tags
555 $aTag=$p_array[$op."tag"];
556 $sub_tag=""; $nb_tag=count($aTag);
557 $and2='';
558 for ($x=0;$x < $nb_tag;$x++) {
559 $sub_tag = " tag_id = ".sql_string($aTag[$x]);
560 $fil_tag=$and.' jr_id in (select jrn_id from operation_tag where '.$sub_tag.')' ;
561 $and=" and ";
562 }
563 }
564 $and=" and ";
565 }
566 /* format the number */
567 $amount_min=abs(toNumber($amount_min));
568 $amount_max=abs(toNumber($amount_max));
569 if ($amount_min>0&&isNumber($amount_min))
570 {
571 $fil_amount=$and.' jr_montant >='.$amount_min;
572 $and=' and ';
573 }
574 if ($amount_max>0&&isNumber($amount_max))
575 {
576 $fil_amount.=$and.' jr_montant <='.$amount_max;
577 $and=' and ';
578 }
579 /* -------------------------------------------------------------------------- *
580 * if both amount are the same then we need to search into the detail
581 * and we reset the fil_amount
582 * -------------------------------------------------------------------------- */
583 if (isNumber($amount_min)&&
584 isNumber($amount_max)&&
585 $amount_min>0&&
586 bccomp($amount_min, $amount_max, 2)==0)
587 {
588 $fil_amount=$and.' ( ';
589
590 // Look in detail
591 $fil_amount.='jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$amount_min.') ';
592
593 //and the total operation
594 $fil_amount.=' or ';
595 $fil_amount.=' jr_montant = '.$amount_min;
596
597 $fil_amount.=')';
598 $and=" and ";
599 }
600 // date
601 if (isset($date_start)&&isDate($date_start)!=null)
602 {
603 $fil_date=$and." jr_date >= to_date('".$date_start."','DD.MM.YYYY')";
604 $and=" and ";
605 }
606 if (isset($date_end)&&isDate($date_end)!=null)
607 {
608 $fil_date.=$and." jr_date <= to_date('".$date_end."','DD.MM.YYYY')";
609 $and=" and ";
610 }
611 // date paiement
612 if (isset($date_paid_start)&&isDate($date_paid_start)!=null)
613 {
614 $fil_date_paid=$and." jr_date_paid >= to_date('".$date_paid_start."','DD.MM.YYYY')";
615 $and=" and ";
616 }
617 if (isset($date_paid_end)&&isDate($date_paid_end)!=null)
618 {
619 $fil_date_paid.=$and." jr_date_paid <= to_date('".$date_paid_end."','DD.MM.YYYY')";
620 $and=" and ";
621 }
622 // comment
623 if (isset($desc)&&$desc!=null)
624 {
626 $fil_desc=$and." ( upper(jr_comment) like upper('%".$desc."%') or upper(jr_pj_number) like upper('%".$desc."%') ".
627 " or upper(jr_internal) like upper('%".$desc."%')
628 or jr_grpt_id in (select j_grpt from jrnx where j_text ilike '%".$desc."%')
629 or jr_id in (select jr_id from jrn_info where ji_value is not null and ji_value ilike '%$desc%')
630 or jr_id in (select jr_id from jrn_note where upper(n_text) ilike '%$desc%' )
631 )";
632 $and=" and ";
633 }
634 // Poste
635 if (isset($accounting)&&$accounting!=null)
636 {
637 $fil_account=$and." jr_grpt_id in (select j_grpt
638 from jrnx where j_poste::text like '".sql_string($accounting)."%' ) ";
639 $and=" and ";
640 }
641 // Quick Code
642 $qcode=(isset($p_array[$this->div."qcode"]))?$p_array[$this->div."qcode"]:"";
643 if ($qcode!="")
644 {
645 $fil_qcode=$and." jr_grpt_id in ( select j_grpt from
646 jrnx where trim(j_qcode) = upper(trim('".sql_string($qcode)."')))";
647 $and=" and ";
648 }
649
650 // Only the unpaid, paid or all
651 if ( isset($operation_filter)) {
652 switch ($operation_filter) {
653 case "unpaid":
654 $fil_paid=$and."(jr_rapt is null or jr_rapt = '') and jr_valid = true ";
655 $and=" and ";
656 break;
657 case "all":
658 $fil_paid="";
659 break;
660 case "paid":
661 $fil_paid=$and."(jr_rapt is not null or jr_rapt = 'paid') and jr_valid = true ";
662 $and=" and ";
663 break;
664 default:
665 throw new Exception(_("ALS01 Etat inconnu"),10);
666
667 }
668 }
669 // Operations which must not be seen in the result
670 if ( isset ($hide_operation) && trim($hide_operation) !="")
671 {
672 $fil_hide_operation=$and.sprintf( ' jr_id not in (%s)',sql_string($hide_operation));
673 $and=" and ";
674 }
675 global $g_user;
676 if ($g_user->admin==0&&$g_user->is_local_admin()==0 && $g_user->get_status_security_ledger()==1 )
677 {
678
679 $fil_sec=$and." jr_def_id in ( select uj_jrn_id ".
680 " from user_sec_jrn where ".
681 " uj_login='".sql_string($_SESSION[SESSION_KEY.'g_user'])."'".
682 " and uj_priv in ('R','W'))";
683 $and=" and ";
684 }
685 if ( isset($p_currency_code) && $p_currency_code !=-1) {
686 $fil_currency=$and." x.currency_id = ".sql_string($p_currency_code);
687 $and=" and ";
688 }
689 // VAT Code
690 if ( isset($tva_id_search) && ! empty (trim($tva_id_search??"")))
691 {
692 $fil_vat = $and." jr_internal in
693 ( select distinct qp_internal
694 from quant_purchase
695 where qp_vat_code=".sql_string($tva_id_search).
696 " union all
697 select distinct qs_internal
698 from quant_sold
699 where qs_vat_code=".sql_string($tva_id_search).")";
700
701 }
702 $where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.
703 $fil_qcode.$fil_paid.$fil_account.$fil_date_paid.$fil_hide_operation.$fil_tag.$fil_currency.$fil_vat;
704
705 $sql.=" where ".$where;
706
707 // Q?? Why do we return where if it is included in SQL ?
708 return array($sql, $where);
709 }
710
711 /**
712 * @brief return a html string with the search_form
713 * \return a HTML string with the FORM
714 * \see build_search_sql
715 * \see search_form
716 * \see list_operation
717 */
719 {
720 $http=new HttpInput();
721 $r='';
722 $r.='<div id="search_form" style="display:none">';
723 $r.=HtmlInput::title_box(_('Recherche'), "search_form", "hide", "", "n");
724 $r.='<FORM METHOD="GET" >';
725 $r.=$this->search_form();
726
727 $r.=HtmlInput::submit('search', _('Rechercher'));
728
729 $button_search=new IButton("{$this->div}button", _('Recherches sauvées'));
730 $button_search->javascript=$this->build_search_filter();
731 $r.=$button_search->input();
732
733
734
735 $r.=HtmlInput::hidden('ac', $http->request('ac'));
736
737
738 /* when called from commercial.php some hidden values are needed */
739 if (isset($_REQUEST['sa']))
740 $r.=HtmlInput::hidden("sa", $http->request('sa'));
741 if (isset($_REQUEST['sb']))
742 $r.=HtmlInput::hidden("sb", $http->request('sb'));
743 if (isset($_REQUEST['sc']))
744 $r.=HtmlInput::hidden("sc", $http->request('sc'));
745 if (isset($_REQUEST['f_id']))
746 $r.=HtmlInput::hidden("f_id", $http->request('f_id'));
747
748
749
750
751 $r.=HtmlInput::button_hide("search_form");
752 $r.='</FORM>';
753
754 $r.='</div>';
755 $button=new IButton('tfs');
756 $button->label=_("Chercher");
757 $button->javascript="toggleHideShow('search_form','tfs');";
758 $r.=$button->input();
759 return $r;
760 }
761
762 /**
763 * @brief Show all the operation
764 * @param$sql is the sql stmt, normally created by build_search_sql
765 * @param$offset the offset
766 * @param$p_paid if we want to see info about payment
767 \code
768 // Example
769 // Build the sql
770 list($sql,$where)=$Ledger->build_search_sql($_GET);
771 // Count nb of line
772 $max_line=$cn->count_sql($sql);
773
774 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
775 $page=(isset($_GET['offset']))?$_GET['page']:1;
776 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
777 // create the nav. bar
778 $bar=navigation_bar($offset,$max_line,$step,$page);
779 // show a part
780 list($count,$html)= $Ledger->list_operation($sql,$offset,0);
781 echo $html;
782 // show nav bar
783 echo $bar;
784
785 \endcode
786 * \see build_search_sql
787 * \see display_search_form
788 * \see search_form
789
790 * \return HTML string
791 */
792 public function list_operation($sql, $offset, $p_paid=0)
793 {
794 global $g_parameter, $g_user;
795 bcscale(2);
796 $table=new Sort_Table();
798 $amount_paid=0.0;
799 $amount_unpaid=0.0;
800 $limit=($_SESSION[SESSION_KEY.'g_pagesize']!=-1)?" LIMIT ".$_SESSION[SESSION_KEY.'g_pagesize']:"";
801 $offset=($_SESSION[SESSION_KEY.'g_pagesize']!=-1)?" OFFSET ".Database::escape_string($offset):"";
802 $order=" order by jr_date_order asc,jr_internal asc";
803 // Sort
804 $url="?".CleanUrl();
805 $str_dossier=dossier::get();
806 $table->add(_("Date"), $url,
807 'order by jr_date asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
808 'order by jr_date desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
809 "da", "dd");
810 $table->add(_('Echeance'), $url, " order by jr_ech asc",
811 " order by jr_ech desc", 'ea', 'ed');
812 $table->add(_('Paiement'), $url, " order by jr_date_paid asc",
813 " order by jr_date_paid desc", 'eap', 'edp');
814 $table->add(_('Pièce'), $url,
815 ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
816 ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric desc ',
817 "pja", "pjd");
818 $table->add(_('Tiers'), $url, " order by name asc",
819 " order by name desc", 'na', 'nd');
820 $table->add(_('Montant'), $url, " order by jr_montant asc",
821 " order by jr_montant desc", "ma", "md");
822 $table->add(_("Description"), $url, "order by jr_comment asc",
823 "order by jr_comment desc", "ca", "cd");
824
825 $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
826 $order=$table->get_sql_order($ord);
827
828 // Count
829 $count=$this->cn->count_sql($sql);
830 // Add the limit
831 $sql.=$order.$limit.$offset;
832 // Execute SQL stmt
833 $Res=$this->cn->exec_sql($sql);
834
835 //starting from here we can refactor, so that instead of returning the generated HTML,
836 //this function returns a tree structure.
837
838 $r="";
839
840
842
843 if ($Max==0)
844 {
845 return array(0, _("Aucun enregistrement trouvé"));
846 }
847
848 $r.='<table class="result" id="history_operation_t">';
849
850
851 $r.="<tr >";
852 $r.='<th>'.$table->get_header(0).'</th>';
853 if ($p_paid!=0)
854 {
855 $r.='<th>'.$table->get_header(1).'</td>';
856 }
857 if ($p_paid!=0)
858 {
859 $r.='<th>'.$table->get_header(2).'</th>';
860 }
861 $r.='<th>'.$table->get_header(3).'</th>';
862 $r.=th('Journal');
863 if ( $this->type != "ODS")
864 {
865 $r.='<th>'.$table->get_header(4).'</th>';
866 }
867 $r.="<th>"._("n° interne")."</th>";
868 $r.='<th>'.$table->get_header(6).'</th>';
869 $r.=th('Notes', ' style="width:15%"');
870 $r.='<th>'.$table->get_header(5).'</th>';
871 // if $p_paid is not equal to 0 then we have a paid column
872 if ($p_paid!=0)
873 {
874 $r.="<th> "._('Payé')."</th>";
875 }
876 $r.="<th>"._('Concerne')."</th>";
877 $r.="<th>"._('Document')."</th>";
878 $r.="</tr>";
879 // Total Amount
880 $tot=0.0;
882 for ($i=0; $i<$Max; $i++)
883 {
884
885
887
888 if ($i%2==0)
889 {
890 $tr='<TR class="odd">';
891 }
892 else
893 {
894 $tr='<TR class="even">';
895 }
896 $r.=$tr;
897
898 // date
899 $r.="<TD>";
900 $r.=$row['str_jr_date'];
901 $r.="</TD>";
902 // echeance
903 if ($p_paid!=0)
904 {
905 $r.="<TD>";
906 $r.=$row['str_jr_ech'];
907 $r.="</TD>";
908 $r.="<TD>";
909 $r.=$row['str_jr_date_paid'];
910 $r.="</TD>";
911 }
912
913 // pj
914 $r.="<TD>";
915 $r.=$row['jr_pj_number'];
916 $r.="</TD>";
917
918 // Ledger
919 $r.=td($row['jrn_def_name']);
920
921
922 if ($this->type != 'ODS')
923 {
924 // Tiers
925 $other=($row['quick_code']!='')?HtmlInput::card_detail($row['quick_code'],h($row['name'].' '.$row['first_name'])):'';
926 $r.=td($other);
927 }
928
929 // Internal number
930 $r.="<TD>";
931 $r.=sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
932 $row['jr_id'], $gDossier, $row['jr_internal']);
933 $r.="</TD>";
934
935 // comment
936 $r.="<TD>";
937 $tmp_jr_comment=h($row['jr_comment']).$row['tag_operation'];
938 $r.=$tmp_jr_comment;
939 if ( $row['analytic_op'] != "")
940 $r.=sprintf('<span style="float:right;background:black;color:white;">&ni;</span>');
941 $r.="</TD>";
942 $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
943 // Amount
944 // If the ledger is financial :
945 // the credit must be negative and written in red
946 $positive=0;
947
948 // Check ledger type :
949 if ($row['jrn_def_type']=='FIN')
950 {
951 $positive=$this->cn->get_value("select qf_amount from quant_fin where jr_id=$1",
952 array($row['jr_id']));
953 if ($this->cn->count()!=0)
954 {
955 $positive=($positive<0)?1:0;
956 }
957 }
958 $r.="<TD align=\"right\">";
959 $t_amount=$row['jr_montant'];
960 if ($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
961 $t_amount=$row['total_invoice'];
962 $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
963 //STAN $positive always == 0
964 if ($row ['jrn_def_type']=='FIN')
965 {
966 $r.=( $positive!=0 )?"<font color=\"red\"> - ".nbm($t_amount)."</font>":nbm($t_amount);
967 }
968 else
969 {
970 $r.=( $t_amount<0 )?"<font color=\"red\"> ".nbm($t_amount)."</font>":nbm($t_amount);
971 }
972 $r.="</TD>";
973
974
975 // Show the paid column if p_paid is not null
976 if ($p_paid!=0)
977 {
978 $w=new ICheckBox();
979 $w->set_range("paid_operation_ck");
980 $w->name="rd_paid".$row['jr_id'];
981 $w->selected=($row['jr_rapt']=='paid')?true:false;
982 // if p_paid == 2 then readonly
983 $w->readonly=( $p_paid==2)?true:false;
984 $h=new IHidden();
985 $h->name="set_jr_id".$row['jr_id'];
986 $r.='<TD>'.$w->input().$h->input().'</TD>';
987 if ($row['jr_rapt']=='paid')
988 {
989 $amount_paid=bcadd($amount_paid, $t_amount);
990 }
991 else
992 {
993 $amount_unpaid=bcadd($amount_unpaid, $t_amount);
994 }
995 }
996
997 // Rapprochement
998 $rec=new Acc_Reconciliation($this->cn);
999 $rec->set_jr_id($row['jr_id']);
1000 $a=$rec->get();
1001 $r.="<TD>";
1002 if ($a!=null)
1003 {
1004
1005 foreach ($a as $key=> $element)
1006 {
1007 $operation=new Acc_Operation($this->cn);
1008 $operation->jr_id=$element;
1009 $l_amount=$this->cn->get_value("select jr_montant from jrn ".
1010 " where jr_id=$1", array($element));
1011 $r.="<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > ".$operation->get_internal()."[".nbm($l_amount)."]</A>";
1012 }//for
1013 }// if ( $a != null ) {
1014 $r.="</TD>";
1015
1016 if ($row['jr_valid']=='f')
1017 {
1018 $r.="<TD>"._("Opération annulée")."</TD>";
1019 }
1020 else
1021 {
1022
1023 } // else
1024 //document
1025 if ($row['jr_pj_name']!="")
1026 {
1027 $r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
1028 }
1029 else
1030 $r.="<TD></TD>";
1031
1032 // end row
1033 $r.="</tr>";
1034 }
1035 $amount_paid=round($amount_paid, 4);
1036 $amount_unpaid=round($amount_unpaid, 4);
1037 $tot=round($tot, 4);
1038 $r.="<TR>";
1039 $r.='<TD COLSPAN="5">Total</TD>';
1040 $r.=td("").td("");
1041 $r.='<TD ALIGN="RIGHT">'.nbm($tot)."</TD>";
1042 $r.="</tr>";
1043 if ($p_paid!=0)
1044 {
1045 $r.="<TR>";
1046 $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
1047 $r.=td("").td("").td("").td('');
1048 $r.='<TD ALIGN="RIGHT">'.nbm($amount_paid)."</TD>";
1049 $r.="</tr>";
1050
1051 $r.="<TR>";
1052 $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
1053 $r.=td("").td("").td("").td('');
1054 $r.='<TD ALIGN="RIGHT">'.nbm($amount_unpaid)."</TD>";
1055 $r.="</tr>";
1056 }
1057 $r.="</table>";
1058
1059 return array($count, $r);
1060 }
1061
1062 /**
1063 * @brief Show all the operation
1064 * @param$sql is the sql stmt, normally created by build_search_sql
1065 * @param$offset the offset
1066 * @param$p_paid if we want to see info about payment
1067 @code
1068 // Example
1069 // Build the sql
1070 list($sql,$where)=$Ledger->build_search_sql($_GET);
1071 // Count nb of line
1072 $max_line=$this->cn->count_sql($sql);
1073
1074 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
1075 $page=(isset($_GET['offset']))?$_GET['page']:1;
1076 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
1077 // create the nav. bar
1078 $bar=navigation_bar($offset,$max_line,$step,$page);
1079 // show a part
1080 list($count,$html)= $Ledger->list_operation($sql,$offset,0);
1081 echo $html;
1082 // show nav bar
1083 echo $bar;
1084
1085 @endcode
1086 * @see build_search_sql
1087 * @see display_search_form
1088 * @see search_form
1089
1090 * @return HTML string
1091 */
1092 public function list_operation_to_reconcile($sql, $p_target)
1093 {
1094 global $g_parameter, $g_user;
1096 $limit=" LIMIT ".MAX_RECONCILE;
1097 // Sort
1098 // Count
1099 $count=$this->cn->count_sql($sql);
1100 // Add the limit
1101 $sql.=" order by jr_date asc ".$limit;
1102
1103 // Execute SQL stmt
1104 $Res=$this->cn->exec_sql($sql);
1105
1106 //starting from here we can refactor, so that instead of returning the generated HTML,
1107 //this function returns a tree structure.
1108
1109 $r="";
1110
1111
1113
1114 if ($Max==0)
1115 return array(0, _("Aucun enregistrement trouvé"));
1116 $r.=HtmlInput::hidden("target", $p_target);
1117 $r.='<table class="result">';
1118
1119
1120 $r.="<tr >";
1121 $r.="<th>"._("Selection")."</th>";
1122 $r.="<th>"._("Internal")."</th>";
1123
1124 if ($this->type=='ALL')
1125 {
1126 $r.=th(_('Journal'));
1127 }
1128
1129 $r.='<th>'._("Date").'</th>';
1130 $r.='<th>'._("Pièce").'</td>';
1131 $r.=th(_('tiers'));
1132 $r.='<th>'._("Description").'</th>';
1133 $r.=th(_('Notes'), ' ');
1134 $r.='<th>'._("Montant").'</th>';
1135 $r.="<th>"._('Concerne')."</th>";
1136 $r.="</tr>";
1137 // Total Amount
1138 $tot=0.0;
1141 for ($i=0; $i<$Max; $i++)
1142 {
1143
1144
1146
1147 if ($i%2==0)
1148 $tr='<TR class="odd">';
1149 else
1150 $tr='<TR class="even">';
1151 $r.=$tr;
1152 // Radiobox
1153 //
1154
1155 $r.='<td><INPUT TYPE="CHECKBOX" name="jr_concerned'.$row['jr_id'].'" ID="jr_concerned'.$row['jr_id'].'" value="'.$row['quick_code'].'"> </td>';
1156 //internal code
1157 // button modify
1158 $r.="<TD>";
1159 // If url contains
1160 //
1161
1162 $href=basename($_SERVER['PHP_SELF']);
1163
1164
1165 $r.=sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
1166 $row['jr_id'], $gDossier, $row['jr_internal']);
1167 $r.="</TD>";
1168 if ($this->type=='ALL')
1169 $r.=td($row['jrn_def_name']);
1170 // date
1171 $r.="<TD>";
1172 $r.=$row['str_jr_date'];
1173 $r.="</TD>";
1174
1175 // pj
1176 $r.="<TD>";
1177 $r.=$row['jr_pj_number'];
1178 $r.="</TD>";
1179
1180 // Tiers
1181 $other=($row['quick_code']!='')?'['.$row['quick_code'].'] '.$row['name'].' '.$row['first_name']:'';
1182 $r.=td($other);
1183 // comment
1184 $r.="<TD>";
1185 $tmp_jr_comment=h($row['jr_comment']).$row['tag_operation'];
1186 $r.=$tmp_jr_comment;
1187 $r.="</TD>";
1188 $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
1189 // Amount
1190 // If the ledger is financial :
1191 // the credit must be negative and written in red
1192 $positive=0;
1193
1194 // Check ledger type :
1195 if ($row['jrn_def_type']=='FIN')
1196 {
1197 $positive=$this->cn->get_value("select qf_amount from quant_fin where jr_id=$1",
1198 array($row['jr_id']));
1199 if ($this->cn->count()!=0)
1200 $positive=($positive<0)?1:0;
1201 }
1202 $r.="<TD align=\"right\">";
1203
1204 $r.=( $positive!=0 )?"<font color=\"red\"> - ".nbm($row['total_invoice'])."</font>":nbm($row['total_invoice']);
1205 $r.="</TD>";
1206
1207
1208
1209 // Rapprochement
1210 $rec=new Acc_Reconciliation($this->cn);
1211 $rec->set_jr_id($row['jr_id']);
1212 $a=$rec->get();
1213 $r.="<TD>";
1214 if ($a!=null)
1215 {
1216
1217 foreach ($a as $key=> $element)
1218 {
1219 $operation=new Acc_Operation($this->cn);
1220 $operation->jr_id=$element;
1221 $l_amount=$this->cn->get_value("select jr_montant from jrn ".
1222 " where jr_id=$1", array($element));
1223 $r.="<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > ".$operation->get_internal()."[".nbm($l_amount)."]</A>";
1224 }//for
1225 }// if ( $a != null ) {
1226 $r.="</TD>";
1227
1228 if ($row['jr_valid']=='f')
1229 {
1230 $r.="<TD>"._("Opération annulée")."</TD>";
1231 }
1232 // end row
1233 $r.="</tr>";
1234 }
1235 $r.='</table>';
1236 return array($count, $r);
1237 }
1238 /**
1239 * return the html code to create an hidden div and a button
1240 * to show this DIV. This contains all the available ledgers
1241 * for the user in READ or RW
1242 *@param $p_selected is an array of checkbox
1243 *@param $p_div div suffix for the list of ledgers
1244 *@note the choosen ledger are stored in the array r_jrn (_GET)
1245 */
1246 function select_ledger($p_selected,$p_div)
1247 {
1248 global $g_user;
1249 $r = '';
1250 /* security : filter ledger on user */
1251 $p_array = $g_user->get_ledger($this->type, 3,FALSE);
1252
1253 ob_start();
1254
1255
1256 /* create a hidden div for the ledger */
1257 echo '<div id="div_jrn'.$p_div.'" >';
1258 echo HtmlInput::title_box(_("Journaux"), $p_div."jrn_search");
1259 echo '<div style="padding:5px">';
1260 echo '<form method="GET" id="'.$p_div.'search_frm" onsubmit="return hide_ledger_choice(\''.$p_div.'search_frm\')">';
1261 $nb_array=(empty($p_array))?0:count($p_array);
1262 echo HtmlInput::hidden('nb_jrn', $nb_array);
1263 echo _('Filtre ').HtmlInput::filter_table($p_div.'tb_jrn', '0,1,2', 2);
1264 echo HtmlInput::anchor_action(_('Inverser sel'),' toggle_checkbox(\''."{$p_div}search_frm".'\')','sel_'.$p_div,"nav");
1265 echo "-";
1266 echo HtmlInput::anchor_action(_('Effacer sel'),' unselect_checkbox(\''."{$p_div}search_frm".'\')','unsel_'.$p_div,"nav");
1267 echo "-";
1268 echo HtmlInput::anchor_action(_('Financier'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'FIN\') ','selfin_'.$p_div,"nav");
1269 echo "-";
1270 echo HtmlInput::anchor_action(_('Vente'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'VEN\') ','selfven_'.$p_div,"nav");
1271 echo "-";
1272 echo HtmlInput::anchor_action(_('Achat'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'ACH\') ','selfach_'.$p_div,"nav");
1273 echo "-";
1274 echo HtmlInput::anchor_action(_('Op.Diverses'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'ODS\') ','selfods_'.$p_div,"nav");
1275 echo '<table class="result" id="'.$p_div.'tb_jrn">';
1276 echo '<tr>';
1277 echo th(_('Nom'));
1278 echo th(_('Description'));
1279 echo th(_('Type'));
1280 echo '</tr>';
1281 echo '<tr>';
1282 echo '<td>';
1283
1284 echo '</td>';
1285 echo '</tr>';
1286 for ($e=0;$e<$nb_array;$e++)
1287 {
1288 $row=$p_array[$e];
1289// if ( $row['jrn_enable']==0) continue;
1290 $r=new ICheckBox($p_div.'r_jrn'.$e,$row['jrn_def_id']);
1291 $r->set_attribute("ledger_type", $row['jrn_def_type']);
1292 $idx=$row['jrn_def_id'];
1293 if ( $p_selected != null && in_array($row['jrn_def_id'],$p_selected))
1294 {
1295 $r->selected=true;
1296 }
1297 $class=($e%2==0)?' class="even" ':' class="odd" ';
1298 echo '<tr '.$class.'>';
1299 echo '<td style="white-space: nowrap">'.$r->input().$row['jrn_def_name'].'</td>';
1300 echo '<td >'.$row['jrn_def_description'].'</td>';
1301 echo '<td >'.$row['jrn_def_type'].'</td>';
1302 echo '</tr>';
1303
1304 }
1305 echo '</table>';
1306 echo HtmlInput::hidden('div',$p_div);
1307 echo HtmlInput::submit('save',_('Valider'));
1308 echo HtmlInput::button_close($p_div."jrn_search");
1309 echo '</form>';
1310 echo '</div>';
1311 echo '</div>';
1312
1313 $ret=ob_get_contents();
1314 ob_end_clean();
1315 return $ret;
1316 }
1317
1318 /**
1319 * @brief use a user_filter row and turns it into an array for
1320 * javascript purpose
1321 * @param User_Filter_SQL $user_filter_sql
1322 * @return array
1323 */
1324 static function build_array(User_Filter_SQL $user_filter_sql)
1325 {
1326 $record=$user_filter_sql->to_array();
1327
1328 $record['desc']=$record['description'];
1329 $record['r_jrn']=explode(",", $record['r_jrn']??"");
1330 $record['tag']=explode(",",$record['uf_tag']??"");
1331 $record['tag_option']=$record["uf_tag_option"];
1332 $record['p_currency_code']=$record['uf_currency_code'];
1333 return $record;
1334 }
1335
1336 /**
1337 * @brief build an HTML string with a button to show the list of
1338 * saved search
1339 * @return string HTML button
1340 * @throws Exception if $_REQUEST['ac'] is not set
1341 */
1342 public function button_propose_filter()
1343 {
1344 $http=new HttpInput();
1345 $button=HtmlInput::button_action("Recherches sauvées",
1346 sprintf("display_list_filter('%s','%s','%s')"
1347 ,Dossier::id()
1348 , $http->request("ac")
1349 ,$this->type
1350 ),uniqid(),'smallbutton');
1351 return $button;
1352 }
1353
1354 /**
1355 * @brief display a list of saved search
1356 */
1357 public function display_list_filter()
1358 {
1359 require_once NOALYSS_TEMPLATE."/acc_ledger_search-display_list_filter.php";
1360
1361 }
1362}
isNumber($p_int)
Definition: ac_common.php:215
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
isDate($p_date)
Definition: ac_common.php:236
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:511
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
global $g_parameter
global $g_user
if no group available , then stop
$href
Definition: adm.inc.php:31
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
Definition: ajax_admin.php:38
h( $row[ 'oa_description'])
$idx
$url
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
catch(Exception $e) $exercice
$_REQUEST['ac']
foreach($array as $idx=> $m) $w
$str_dossier
Definition: anc_od.inc.php:33
$input_from cn
Definition: balance.inc.php:66
$input_from id
Definition: balance.inc.php:63
$input_from type
Definition: balance.inc.php:65
$date_start
if(! isset($_GET['submit_query'])) $p_action
$_GET['qcode']
$class
display currency , convert to euro , and save them if used.
build_search_filter()
Build the button for managing the filter for search.
$type
type of ledger : FIN,ODS,VEN,ACH
list_operation($sql, $offset, $p_paid=0)
Show all the operation.
display_search_form()
return a html string with the search_form
display_list_filter()
display a list of saved search
button_propose_filter()
build an HTML string with a button to show the list of saved search
$all
Flag to indicate if all ledgers must searched (1 for yes)
build_search_sql($p_array, $p_order="", $p_where="")
this function will create a sql stmt to use to create the list for the ledger,
$cn
Database Connection.
build_name_filter()
Build the button for saving the filter for search.
static build_array(User_Filter_SQL $user_filter_sql)
use a user_filter row and turns it into an array for javascript purpose
$id
prefix for id of DOM id id of the ledger
__construct($p_type, $p_all=1, $p_div="")
return a HTML string with the form for the search
select_ledger($p_selected, $p_div)
return the html code to create an hidden div and a button to show this DIV.
list_operation_to_reconcile($sql, $p_target)
Show all the operation.
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static id()
return the 'gDossier' value after a check
static connect()
static button_hide($div_name)
Hide the HTML popup.
static button_close($div_name, $class='smallbutton')
close button for the HTML popup
static card_detail($p_qcode, $pname='', $p_style="", $p_nohistory=false, $nofollowup=false)
show the detail of a card
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static anchor_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
Anchor Html with javascript.
manage the http input (get , post, request) and extract from an array
Html Input.
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input.
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
Html Input.
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30
let you choose a TVA in a popup
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
Class to manage the company parameter (address, name...)
For the periode tables parm_periode and jrn_periode.
Description of class_syn_sort_table.
const EXC_PARAM_VALUE
Definition: constant.php:343
$Res
$count
$r_jrn
$date_end_hidden
$ord
Definition: menu.inc.php:115
$table
Definition: menu.inc.php:103
$button_search
Definition: recherche.php:90
toNumber($p_num)
remove the useless space, change comma by period and try to return a number