noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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()]);
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);
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 $acc_tva=Acc_Tva::build($this->cn, $tva_id_search);
693 if ($acc_tva->tva_id != -1 )
694 {
695 $fil_vat = $and." jr_internal in
696 ( select distinct qp_internal
697 from quant_purchase
698 where qp_vat_code=".sql_string($acc_tva->tva_id ).
699 " union all
700 select distinct qs_internal
701 from quant_sold
702 where qs_vat_code=".sql_string($acc_tva->tva_id ).")";
703 }
704
705 }
706 $where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.
707 $fil_qcode.$fil_paid.$fil_account.$fil_date_paid.$fil_hide_operation.$fil_tag.$fil_currency.$fil_vat;
708
709 $sql.=" where ".$where;
710
711 // Q?? Why do we return where if it is included in SQL ?
712 return array($sql, $where);
713 }
714
715 /**
716 * @brief return a html string with the search_form
717 * \return a HTML string with the FORM
718 * \see build_search_sql
719 * \see search_form
720 * \see list_operation
721 */
723 {
724 $http=new HttpInput();
725 $r='';
726 $r.='<div id="search_form" style="display:none">';
727 $r.=HtmlInput::title_box(_('Recherche'), "search_form", "hide", "", "n");
728 $r.='<FORM METHOD="GET" >';
729 $r.=$this->search_form();
730
731 $r.=HtmlInput::submit('search', _('Rechercher'));
732
733 $button_search=new IButton("{$this->div}button", _('Recherches sauvées'));
734 $button_search->javascript=$this->build_search_filter();
735 $r.=$button_search->input();
736
737
738
739 $r.=HtmlInput::hidden('ac', $http->request('ac'));
740
741
742 /* when called from commercial.php some hidden values are needed */
743 if (isset($_REQUEST['sa']))
744 $r.=HtmlInput::hidden("sa", $http->request('sa'));
745 if (isset($_REQUEST['sb']))
746 $r.=HtmlInput::hidden("sb", $http->request('sb'));
747 if (isset($_REQUEST['sc']))
748 $r.=HtmlInput::hidden("sc", $http->request('sc'));
749 if (isset($_REQUEST['f_id']))
750 $r.=HtmlInput::hidden("f_id", $http->request('f_id'));
751
752
753
754
755 $r.=HtmlInput::button_hide("search_form");
756 $r.='</FORM>';
757
758 $r.='</div>';
759 $button=new IButton('tfs');
760 $button->label=_("Chercher");
761 $button->javascript="toggleHideShow('search_form','tfs');";
762 $r.=$button->input();
763 return $r;
764 }
765
766 /**
767 * @brief Show all the operation
768 * @param$sql is the sql stmt, normally created by build_search_sql
769 * @param$offset the offset
770 * @param$p_paid if we want to see info about payment
771 \code
772 // Example
773 // Build the sql
774 list($sql,$where)=$Ledger->build_search_sql($_GET);
775 // Count nb of line
776 $max_line=$cn->count_sql($sql);
777
778 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
779 $page=(isset($_GET['offset']))?$_GET['page']:1;
780 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
781 // create the nav. bar
782 $bar=navigation_bar($offset,$max_line,$step,$page);
783 // show a part
784 list($count,$html)= $Ledger->list_operation($sql,$offset,0);
785 echo $html;
786 // show nav bar
787 echo $bar;
788
789 \endcode
790 * \see build_search_sql
791 * \see display_search_form
792 * \see search_form
793
794 * \return HTML string
795 */
796 public function list_operation($sql, $offset, $p_paid=0)
797 {
798 global $g_parameter, $g_user;
799 bcscale(2);
800 $table=new Sort_Table();
801 $gDossier=dossier::id();
802 $amount_paid=0.0;
803 $amount_unpaid=0.0;
804 $limit=($_SESSION[SESSION_KEY.'g_pagesize']!=-1)?" LIMIT ".$_SESSION[SESSION_KEY.'g_pagesize']:"";
805 $offset=($_SESSION[SESSION_KEY.'g_pagesize']!=-1)?" OFFSET ".Database::escape_string($offset):"";
806 $order=" order by jr_date_order asc,jr_internal asc";
807 // Sort
808 $url="?".CleanUrl();
809 $str_dossier=dossier::get();
810 $table->add(_("Date"), $url,
811 'order by jr_date asc,substring(jr_pj_number,\'[0-9]+$\')::numeric asc',
812 'order by jr_date desc,substring(jr_pj_number,\'[0-9]+$\')::numeric desc',
813 "da", "dd");
814 $table->add(_('Echeance'), $url, " order by jr_ech asc",
815 " order by jr_ech desc", 'ea', 'ed');
816 $table->add(_('Paiement'), $url, " order by jr_date_paid asc",
817 " order by jr_date_paid desc", 'eap', 'edp');
818 $table->add(_('Pièce'), $url,
819 ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric asc ',
820 ' order by substring(jr_pj_number,\'[0-9]+$\')::numeric desc ',
821 "pja", "pjd");
822 $table->add(_('Tiers'), $url, " order by name asc",
823 " order by name desc", 'na', 'nd');
824 $table->add(_('Montant'), $url, " order by jr_montant asc",
825 " order by jr_montant desc", "ma", "md");
826 $table->add(_("Description"), $url, "order by jr_comment asc",
827 "order by jr_comment desc", "ca", "cd");
828
829 $ord=(!isset($_GET['ord']))?'da':$_GET['ord'];
830 $order=$table->get_sql_order($ord);
831
832 // Count
833 $count=$this->cn->count_sql($sql);
834 // Add the limit
835 $sql.=$order.$limit.$offset;
836 // Execute SQL stmt
837 $Res=$this->cn->exec_sql($sql);
838
839 //starting from here we can refactor, so that instead of returning the generated HTML,
840 //this function returns a tree structure.
841
842 $r="";
843
844
846
847 if ($Max==0)
848 {
849 return array(0, _("Aucun enregistrement trouvé"));
850 }
851
852 $r.='<table class="result" id="history_operation_t">';
853
854
855 $r.="<tr >";
856 $r.='<th>'.$table->get_header(0).'</th>';
857 if ($p_paid!=0)
858 {
859 $r.='<th>'.$table->get_header(1).'</td>';
860 }
861 if ($p_paid!=0)
862 {
863 $r.='<th>'.$table->get_header(2).'</th>';
864 }
865 $r.='<th>'.$table->get_header(3).'</th>';
866 $r.=th('Journal');
867 if ( $this->type != "ODS")
868 {
869 $r.='<th>'.$table->get_header(4).'</th>';
870 }
871 $r.="<th>"._("n° interne")."</th>";
872 $r.='<th>'.$table->get_header(6).'</th>';
873 $r.=th('Notes', ' style="width:15%"');
874 $r.='<th>'.$table->get_header(5).'</th>';
875 // if $p_paid is not equal to 0 then we have a paid column
876 if ($p_paid!=0)
877 {
878 $r.="<th> "._('Payé')."</th>";
879 }
880 $r.="<th>"._('Concerne')."</th>";
881 $r.="<th>"._('Document')."</th>";
882 $r.="</tr>";
883 // Total Amount
884 $tot=0.0;
885 $gDossier=dossier::id();
886 for ($i=0; $i<$Max; $i++)
887 {
888
889
891
892 if ($i%2==0)
893 {
894 $tr='<TR class="odd">';
895 }
896 else
897 {
898 $tr='<TR class="even">';
899 }
900 $r.=$tr;
901
902 // date
903 $r.="<TD>";
904 $r.=$row['str_jr_date'];
905 $r.="</TD>";
906 // echeance
907 if ($p_paid!=0)
908 {
909 $r.="<TD>";
910 $r.=$row['str_jr_ech'];
911 $r.="</TD>";
912 $r.="<TD>";
913 $r.=$row['str_jr_date_paid'];
914 $r.="</TD>";
915 }
916
917 // pj
918 $r.="<TD>";
919 $r.=$row['jr_pj_number'];
920 $r.="</TD>";
921
922 // Ledger
923 $r.=td($row['jrn_def_name']);
924
925
926 if ($this->type != 'ODS')
927 {
928 // Tiers
929 $other=($row['quick_code']!='')?HtmlInput::card_detail($row['quick_code'],h($row['name'].' '.$row['first_name'])):'';
930 $r.=td($other);
931 }
932
933 // Internal number
934 $r.="<TD>";
935 $r.=sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
936 $row['jr_id'], $gDossier, $row['jr_internal']);
937 $r.="</TD>";
938
939 // comment
940 $r.="<TD>";
941 $tmp_jr_comment=h($row['jr_comment']).$row['tag_operation'];
942 $r.=$tmp_jr_comment;
943 if ( $row['analytic_op'] != "")
944 $r.=sprintf('<span style="float:right;background:black;color:white;">&ni;</span>');
945 $r.="</TD>";
946 $r.=td(h($row['n_text']), ' style="font-size:0.87em%"');
947 // Amount
948 // If the ledger is financial :
949 // the credit must be negative and written in red
950 $positive=0;
951
952 // Check ledger type :
953 if ($row['jrn_def_type']=='FIN')
954 {
955 $positive=$this->cn->get_value("select qf_amount from quant_fin where jr_id=$1",
956 array($row['jr_id']));
957 if ($this->cn->count()!=0)
958 {
959 $positive=($positive<0)?1:0;
960 }
961 }
962 $r.="<TD align=\"right\">";
963 $t_amount=$row['jr_montant'];
964 if ($row['total_invoice']!=null&&$row['total_invoice']!=$row['jr_montant'])
965 $t_amount=$row['total_invoice'];
966 $tot=($positive!=0)?bcsub($tot, $t_amount):bcadd($tot, $t_amount);
967 //STAN $positive always == 0
968 if ($row ['jrn_def_type']=='FIN')
969 {
970 $r.=( $positive!=0 )?"<font color=\"red\"> - ".nbm($t_amount)."</font>":nbm($t_amount);
971 }
972 else
973 {
974 $r.=( $t_amount<0 )?"<font color=\"red\"> ".nbm($t_amount)."</font>":nbm($t_amount);
975 }
976 $r.="</TD>";
977
978
979 // Show the paid column if p_paid is not null
980 if ($p_paid!=0)
981 {
982 $w=new ICheckBox();
983 $w->set_range("paid_operation_ck");
984 $w->name="rd_paid".$row['jr_id'];
985 $w->selected=($row['jr_rapt']=='paid')?true:false;
986 // if p_paid == 2 then readonly
987 $w->readonly=( $p_paid==2)?true:false;
988 $w->javascript='onclick="operation_payment.check_item(this)"';
989 $h=new IHidden();
990 $h->name="set_jr_id".$row['jr_id'];
991 $r.='<TD>'.$w->input().$h->input().'</TD>';
992 if ($row['jr_rapt']=='paid')
993 {
994 $amount_paid=bcadd($amount_paid, $t_amount);
995 }
996 else
997 {
998 $amount_unpaid=bcadd($amount_unpaid, $t_amount);
999 }
1000 }
1001
1002 // Rapprochement
1003 $rec=new Acc_Reconciliation($this->cn);
1004 $rec->set_jr_id($row['jr_id']);
1005 $a=$rec->get();
1006 $r.="<TD>";
1007 if ($a!=null)
1008 {
1009
1010 foreach ($a as $key=> $element)
1011 {
1012 $operation=new Acc_Operation($this->cn);
1013 $operation->jr_id=$element;
1014 $l_amount=$this->cn->get_value("select jr_montant from jrn ".
1015 " where jr_id=$1", array($element));
1016 $r.="<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > ".$operation->get_internal()."[".nbm($l_amount)."]</A>";
1017 }//for
1018 }// if ( $a != null ) {
1019 $r.="</TD>";
1020
1021 if ($row['jr_valid']=='f')
1022 {
1023 $r.="<TD>"._("Opération annulée")."</TD>";
1024 }
1025 else
1026 {
1027
1028 } // else
1029 //document
1030 if ($row['jr_pj_name']!="")
1031 {
1032 $r.='<td>'.HtmlInput::show_receipt_document($row['jr_id']).'</td>';
1033 }
1034 else
1035 $r.="<TD></TD>";
1036
1037 // end row
1038 $r.="</tr>";
1039 }
1040 $amount_paid=round($amount_paid, 4);
1041 $amount_unpaid=round($amount_unpaid, 4);
1042 $tot=round($tot, 4);
1043 $r.="<TR>";
1044 $r.='<TD COLSPAN="5">Total</TD>';
1045 $r.=td("").td("");
1046 $r.='<TD ALIGN="RIGHT">'.nbm($tot)."</TD>";
1047 $r.="</tr>";
1048 if ($p_paid!=0)
1049 {
1050 $r.="<TR>";
1051 $r.='<TD COLSPAN="5">'._("Payé").'</TD>';
1052 $r.=td("").td("").td("").td('');
1053 $r.='<TD ALIGN="RIGHT">'.nbm($amount_paid)."</TD>";
1054 $r.="</tr>";
1055
1056 $r.="<TR>";
1057 $r.='<TD COLSPAN="5">'._("Non payé").'</TD>';
1058 $r.=td("").td("").td("").td('');
1059 $r.='<TD ALIGN="RIGHT">'.nbm($amount_unpaid)."</TD>";
1060 $r.="</tr>";
1061 }
1062 $r.="</table>";
1063
1064 return array($count, $r);
1065 }
1066
1067 /**
1068 * @brief Show all the operation
1069 * @param$sql is the sql stmt, normally created by build_search_sql
1070 * @param$offset the offset
1071 * @param$p_paid if we want to see info about payment
1072 @code
1073 // Example
1074 // Build the sql
1075 list($sql,$where)=$Ledger->build_search_sql($_GET);
1076 // Count nb of line
1077 $max_line=$this->cn->count_sql($sql);
1078
1079 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
1080 $page=(isset($_GET['offset']))?$_GET['page']:1;
1081 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
1082 // create the nav. bar
1083 $bar=navigation_bar($offset,$max_line,$step,$page);
1084 // show a part
1085 list($count,$html)= $Ledger->list_operation($sql,$offset,0);
1086 echo $html;
1087 // show nav bar
1088 echo $bar;
1089
1090 @endcode
1091 * @see build_search_sql
1092 * @see display_search_form
1093 * @see search_form
1094
1095 * @return HTML string
1096 */
1097 public function list_operation_to_reconcile($sql, $p_target)
1098 {
1099 global $g_parameter, $g_user;
1100 $gDossier=dossier::id();
1101 $limit=" LIMIT ".MAX_RECONCILE;
1102 // Sort
1103 // Count
1104 $count=$this->cn->count_sql($sql);
1105 // Add the limit
1106 $sql.=" order by jr_date asc ".$limit;
1107
1108 // Execute SQL stmt
1109 $Res=$this->cn->exec_sql($sql);
1110
1111 //starting from here we can refactor, so that instead of returning the generated HTML,
1112 //this function returns a tree structure.
1113
1114 $r="";
1115
1116
1118
1119 if ($Max==0)
1120 return array(0, _("Aucun enregistrement trouvé"));
1121 $r.=HtmlInput::hidden("target", $p_target);
1122 $r.='<table class="result">';
1123
1124
1125 $r.="<tr >";
1126 $r.="<th>"._("Selection")."</th>";
1127 $r.="<th>"._("Internal")."</th>";
1128
1129 if ($this->type=='ALL')
1130 {
1131 $r.=th(_('Journal'));
1132 }
1133
1134 $r.='<th>'._("Date").'</th>';
1135 $r.='<th>'._("Pièce").'</td>';
1136 $r.=th(_('tiers'));
1137 $r.='<th>'._("Description").'</th>';
1138 $r.=th(_('Notes'), ' ');
1139 $r.='<th>'._("Montant").'</th>';
1140 $r.="<th>"._('Concerne')."</th>";
1141 $r.="</tr>";
1142 // Total Amount
1143 $tot=0.0;
1144 $gDossier=dossier::id();
1145 $str_dossier=Dossier::id();
1146 for ($i=0; $i<$Max; $i++)
1147 {
1148
1149
1151
1152 if ($i%2==0)
1153 $tr='<TR class="odd">';
1154 else
1155 $tr='<TR class="even">';
1156 $r.=$tr;
1157 // Radiobox
1158 //
1159
1160 $r.='<td><INPUT TYPE="CHECKBOX" name="jr_concerned'.$row['jr_id'].'" ID="jr_concerned'.$row['jr_id'].'" value="'.$row['quick_code'].'"> </td>';
1161 //internal code
1162 // button modify
1163 $r.="<TD>";
1164 // If url contains
1165 //
1166
1167 $href=basename($_SERVER['PHP_SELF']);
1168
1169
1170 $r.=sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s </A>',
1171 $row['jr_id'], $gDossier, $row['jr_internal']);
1172 $r.="</TD>";
1173 if ($this->type=='ALL')
1174 $r.=td($row['jrn_def_name']);
1175 // date
1176 $r.="<TD>";
1177 $r.=$row['str_jr_date'];
1178 $r.="</TD>";
1179
1180 // pj
1181 $r.="<TD>";
1182 $r.=$row['jr_pj_number'];
1183 $r.="</TD>";
1184
1185 // Tiers
1186 $other=($row['quick_code']!='')?'['.$row['quick_code'].'] '.$row['name'].' '.$row['first_name']:'';
1187 $r.=td($other);
1188 // comment
1189 $r.="<TD>";
1190 $tmp_jr_comment=h($row['jr_comment']).$row['tag_operation'];
1191 $r.=$tmp_jr_comment;
1192 $r.="</TD>";
1193 $r.=td(h($row['n_text']), ' style="font-size:0.87em"');
1194 // Amount
1195 // If the ledger is financial :
1196 // the credit must be negative and written in red
1197 $positive=0;
1198
1199 // Check ledger type :
1200 if ($row['jrn_def_type']=='FIN')
1201 {
1202 $positive=$this->cn->get_value("select qf_amount from quant_fin where jr_id=$1",
1203 array($row['jr_id']));
1204 if ($this->cn->count()!=0)
1205 $positive=($positive<0)?1:0;
1206 }
1207 $r.="<TD align=\"right\">";
1208
1209 $r.=( $positive!=0 )?"<font color=\"red\"> - ".nbm($row['total_invoice'])."</font>":nbm($row['total_invoice']);
1210 $r.="</TD>";
1211
1212
1213
1214 // Rapprochement
1215 $rec=new Acc_Reconciliation($this->cn);
1216 $rec->set_jr_id($row['jr_id']);
1217 $a=$rec->get();
1218 $r.="<TD>";
1219 if ($a!=null)
1220 {
1221
1222 foreach ($a as $key=> $element)
1223 {
1224 $operation=new Acc_Operation($this->cn);
1225 $operation->jr_id=$element;
1226 $l_amount=$this->cn->get_value("select jr_montant from jrn ".
1227 " where jr_id=$1", array($element));
1228 $r.="<A class=\"detail\" HREF=\"javascript:modifyOperation('".$element."',".$gDossier.")\" > ".$operation->get_internal()."[".nbm($l_amount)."]</A>";
1229 }//for
1230 }// if ( $a != null ) {
1231 $r.="</TD>";
1232
1233 if ($row['jr_valid']=='f')
1234 {
1235 $r.="<TD>"._("Opération annulée")."</TD>";
1236 }
1237 // end row
1238 $r.="</tr>";
1239 }
1240 $r.='</table>';
1241 return array($count, $r);
1242 }
1243 /**
1244 * return the html code to create an hidden div and a button
1245 * to show this DIV. This contains all the available ledgers
1246 * for the user in READ or RW
1247 *@param $p_selected is an array of checkbox
1248 *@param $p_div div suffix for the list of ledgers
1249 *@note the choosen ledger are stored in the array r_jrn (_GET)
1250 */
1251 function select_ledger($p_selected,$p_div)
1252 {
1253 global $g_user;
1254 $r = '';
1255 /* security : filter ledger on user */
1256 $p_array = $g_user->get_ledger($this->type, 3,FALSE);
1257
1258 ob_start();
1259
1260
1261 /* create a hidden div for the ledger */
1262 echo '<div id="div_jrn'.$p_div.'" >';
1263 echo HtmlInput::title_box(_("Journaux"), $p_div."jrn_search");
1264 echo '<div style="padding:5px">';
1265 echo '<form method="GET" id="'.$p_div.'search_frm" onsubmit="return hide_ledger_choice(\''.$p_div.'search_frm\')">';
1266 $nb_array=(empty($p_array))?0:count($p_array);
1267 echo HtmlInput::hidden('nb_jrn', $nb_array);
1268 echo _('Filtre ').HtmlInput::filter_table($p_div.'tb_jrn', '0,1,2', 2);
1269 echo HtmlInput::anchor_action(_('Inverser sel'),' toggle_checkbox(\''."{$p_div}search_frm".'\')','sel_'.$p_div,"nav");
1270 echo "-";
1271 echo HtmlInput::anchor_action(_('Effacer sel'),' unselect_checkbox(\''."{$p_div}search_frm".'\')','unsel_'.$p_div,"nav");
1272 echo "-";
1273 echo HtmlInput::anchor_action(_('Financier'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'FIN\') ','selfin_'.$p_div,"nav");
1274 echo "-";
1275 echo HtmlInput::anchor_action(_('Vente'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'VEN\') ','selfven_'.$p_div,"nav");
1276 echo "-";
1277 echo HtmlInput::anchor_action(_('Achat'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'ACH\') ','selfach_'.$p_div,"nav");
1278 echo "-";
1279 echo HtmlInput::anchor_action(_('Op.Diverses'),' select_checkbox_attribute(\''."{$p_div}search_frm".'\',\'ledger_type\',\'ODS\') ','selfods_'.$p_div,"nav");
1280 echo '<table class="result" id="'.$p_div.'tb_jrn">';
1281 echo '<tr>';
1282 echo th(_('Nom'));
1283 echo th(_('Description'));
1284 echo th(_('Type'));
1285 echo '</tr>';
1286 echo '<tr>';
1287 echo '<td>';
1288
1289 echo '</td>';
1290 echo '</tr>';
1291 for ($e=0;$e<$nb_array;$e++)
1292 {
1293 $row=$p_array[$e];
1294// if ( $row['jrn_enable']==0) continue;
1295 $r=new ICheckBox($p_div.'r_jrn'.$e,$row['jrn_def_id']);
1296 $r->set_attribute("ledger_type", $row['jrn_def_type']);
1297 $idx=$row['jrn_def_id'];
1298 if ( $p_selected != null && in_array($row['jrn_def_id'],$p_selected))
1299 {
1300 $r->selected=true;
1301 }
1302 $class=($e%2==0)?' class="even" ':' class="odd" ';
1303 echo '<tr '.$class.'>';
1304 echo '<td style="white-space: nowrap">'.$r->input().$row['jrn_def_name']."(".$row['jrn_def_code'].")".'</td>';
1305 echo '<td >'.$row['jrn_def_description'].'</td>';
1306 echo '<td >'.$row['jrn_def_type'].'</td>';
1307 echo '</tr>';
1308
1309 }
1310 echo '</table>';
1311 echo HtmlInput::hidden('div',$p_div);
1312 echo HtmlInput::submit('save',_('Valider'));
1313 echo HtmlInput::button_close($p_div."jrn_search");
1314 echo '</form>';
1315 echo '</div>';
1316 echo '</div>';
1317
1318 $ret=ob_get_contents();
1319 ob_end_clean();
1320 return $ret;
1321 }
1322
1323 /**
1324 * @brief use a user_filter row and turns it into an array for
1325 * javascript purpose
1326 * @param User_Filter_SQL $user_filter_sql
1327 * @return array
1328 */
1329 static function build_array(User_Filter_SQL $user_filter_sql)
1330 {
1331 $record=$user_filter_sql->to_array();
1332
1333 $record['desc']=$record['description'];
1334 $record['r_jrn']=explode(",", $record['r_jrn']??"");
1335 $record['tag']=explode(",",$record['uf_tag']??"");
1336 $record['tag_option']=$record["uf_tag_option"];
1337 $record['p_currency_code']=$record['uf_currency_code'];
1338 return $record;
1339 }
1340
1341 /**
1342 * @brief build an HTML string with a button to show the list of
1343 * saved search
1344 * @return string HTML button
1345 * @throws Exception if $_REQUEST['ac'] is not set
1346 */
1347 public function button_propose_filter()
1348 {
1349 $http=new HttpInput();
1350 $button=HtmlInput::button_action("Recherches sauvées",
1351 sprintf("display_list_filter('%s','%s','%s')"
1352 ,Dossier::id()
1353 , $http->request("ac")
1354 ,$this->type
1355 ),uniqid(),'smallbutton');
1356 return $button;
1357 }
1358
1359 /**
1360 * @brief display a list of saved search
1361 */
1362 public function display_list_filter()
1363 {
1364 require_once NOALYSS_TEMPLATE."/acc_ledger_search-display_list_filter.php";
1365
1366 }
1367}
isNumber($p_int)
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
isDate($p_date)
noalyss_str_replace($search, $replace, $string)
sql_string($p_string)
Fix the problem with the quote char for the database.
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.
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
h( $row[ 'oa_description'])
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
$input_from cn
_("actif, passif,charge,...")
$input_from type
$date_start
if(! isset($_GET['submit_query'])) $p_action
$_GET['qcode']
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 build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
static escape_string($p_string)
wrapper for the function pg_escape_string
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 hidden($p_name, $p_value, $p_id="")
manage the http input (get , post, request) and extract from an array
Html Input.
Html Input.
Html Input.
Html Input.
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
Class to manage the company parameter (address, name...)
Description of class_syn_sort_table.
const EXC_PARAM_VALUE
Definition constant.php:343
$count
$date_end_hidden
$ord
Definition menu.inc.php:116
$table
Definition menu.inc.php:104
$button_search
Definition recherche.php:90
toNumber($p_num)
remove the useless space, change comma by period and try to return a number