noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
fiche.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20
21
22// Copyright Author Dany De Bontridder danydb@aevalys.eu
23
24/*! \file
25 * \brief define Class fiche, this class are using
26 * class attribut
27 */
28/*!
29 * \brief define Class fiche and fiche def, those class are using
30 * class attribut. When adding or modifing new card in a IPOPUP
31 * the ipopup for the accounting item is ipop_account
32 */
33
34//-----------------------------------------------------
35// class fiche
36//-----------------------------------------------------
37class Fiche
38{
39 var $cn; /*! < $cn database connection */
40 var $id; /*! < $id fiche.f_id */
41 var $fiche_def; /*! < $fiche_def fd_id */
42 var $attribut; /*! < $attribut array of Card_Property objects */
43 var $fiche_def_ref; /*!< $fiche_def_ref Type */
44 var $row; /*! < All the row from the ledgers */
45 var $quick_code; /*!< quick_code of the card */
46 private $f_enable; /*!< if card is enable (fiche.f_enable) */
47 private $display_mode ; /*!< how the card is displaid */
50 var $ledger_name; ///!< this variable is a mistake, it shouldn't exist, need code rewrite
51 var $ledger_description; ///!< this variable is a mistake, it shouldn't exist, need code rewrite
52
53 function __construct($p_cn,$p_id=0)
54 {
55 $this->cn=$p_cn;
56 // in PHP7 , a null string == 0
57 // in PHP8 , a null string == a null string and is not equal to 0
58 // to fix this, we set the fix here
59 if ( isNumber($p_id) == 1 ) {
60 $this->id=$p_id;
61 } else {
62 $this->id=0;
63 }
64 $this->quick_code='';
65 $this->attribut=array();
66 $this->f_enable='1';
67 if ($p_id != 0 ) { $this->load();} else {
68 $this->fiche_def=0;
69 }
70
71 $this->display_mode="window";
72 }
73
74 /**
75 * @brief how the card is display : either in a window or a greated container
76 * @param string $p_mode can be large or window
77 * @return Fiche
78 * @throws Exception
79 */
80 function setDisplayMode($p_mode) {
81 if ( ! in_array($p_mode,array("window","large"))) {
82 throw new Exception("FIC70 invalide display mode");
83 }
84 $this->display_mode=$p_mode;
85 return $this;
86 }
87
88 /**
89 * @return string
90 */
91 public function getDisplayMode(): string
92 {
94 }
95 public function set_fiche_def($p_fiche_def)
96 {
97 $this->fiche_def=$p_fiche_def;
98 return $this;
99 }
100
101 public function get_id()
102 {
103 return $this->id;
104 }
105
106 public function get_fiche_def_ref()
107 {
109 }
110
111 public function get_f_enable()
112 {
113 return $this->f_enable;
114 }
115
116 public function set_id($id)
117 {
118 $this->id=$id;
119 return $this;
120 }
121
123 {
124 $this->fiche_def_ref=$fiche_def_ref;
125 return $this;
126 }
127
128 public function set_f_enable($f_enable)
129 {
130 $this->f_enable=$f_enable;
131 return $this;
132 }
133
134 /**
135 *@brief used with a usort function, to sort an array of Fiche on the name
136 */
137 static function cmp_name(Fiche $o1,Fiche $o2)
138 {
139 return strcmp($o1->get_attribute(ATTR_DEF_NAME),$o2->get_attribute(ATTR_DEF_NAME));
140 }
141
142 /**
143 *@brief get the available bank_account filtered by the security
144 *@return array of card
145 */
146 function get_bk_account()
147 {
148 global $g_user;
149 $sql_ledger=$g_user->get_ledger_sql('FIN',3);
150 $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
151 . "jrn_def_bank,jrn_def_description,currency_id from jrn_def where jrn_def_type='FIN' and $sql_ledger
152 order by jrn_def_name");
153
154 if ( count($avail) == 0 )
155 return null;
156
157 for ($i=0;$i<count($avail);$i++)
158 {
159 $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
160 $t->ledger_name=$avail[$i]['jrn_def_name'];
161 $t->ledger_description=$avail[$i]['jrn_def_description'];
162 $t->load_attribute();
163 $all[$i]=$t;
164
165 }
166 return $all;
167 }
168
169
170 /*! get_by_qcode($p_qcode)
171 * \brief Retrieve a card thx his quick_code
172 * complete the object,, set the id member of the object or set it
173 * to 0 if no card is found
174 * \param $p_qcode quick_code (ad_id=23)
175 * \param $p_all retrieve all the attribut of the card, possible value
176 * are true or false. false retrieves only the f_id. By default true
177 * \returns 0 success , card found / 1 error card not found
178 */
179 function get_by_qcode($p_qcode=null,$p_all=true)
180 {
181 if ( $p_qcode == null )
182 $p_qcode=$this->quick_code;
183 $p_qcode=trim($p_qcode);
184 $sql="select f_id from fiche_detail
185 where ad_id=23 and ad_value=upper($1)";
186 $this->id=$this->cn->get_value($sql,array($p_qcode));
187 if ( $this->cn->count()==0)
188 {
189 $this->id=0;
190 return 1;
191 }
192
193
194 if ( $p_all )
195 $this->load_attribute();
196 return 0;
197 }
198 /**
199 * @brief replace by set_attribute
200 * @deprecated since version 9.3.0.12
201 */
202 function setAttribut($p_ad_id,$p_value) {
203 $this->set_attribute($p_ad_id, $p_value);
204 }
205 /**
206 *@brief set an attribute by a value, if the attribut array is empty
207 * a call to load_attribute is performed
208 *@param int AD_ID attr_def.ad_id
209 *@param int value value of this attribute
210 *@see constant.php table: attr_def
211 */
212 function set_attribute($p_ad_id,$p_value)
213 {
214 if ( $this->fiche_def == 0) throw new Exception ("FICHE.179 Invalid category",EXC_INVALID);
215 if ( sizeof($this->attribut)==0 ) $this->load_attribute();
216
217 for ($e=0;$e <sizeof($this->attribut);$e++)
218 {
219 if ( $this->attribut[$e]->ad_id == $p_ad_id )
220 {
221 $this->attribut[$e]->av_text=$p_value;
222 break;
223 }
224 }
225 }
226 /**
227 * @brief replace by load_attribute
228 * @deprecated since version 9.3.0.12
229 * @return type
230 */
231 function getAttribut() {
232 return Card_Property::load($this);
233 }
234 /**
235 *\brief get all the attribute of a card, add missing ones
236 * and sort the array ($this->attribut) by ad_id
237 */
238 function load_attribute()
239 {
240 Card_Property::load($this);
241 }
242 /**
243 * @brief find the card with the p_attribut equal to p_value, it is not case sensitive
244 * @param int $p_attribut attribute to find see table attr_def
245 * @param string $p_value value in attr_value.av_text
246 * @return array returns ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
247 */
248 function seek($p_attribut,$p_value)
249 {
250 $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join fiche_detail using (f_id)
251 where ad_id=$1 and upper(ad_value)=upper($2)";
252 $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
253 return $res;
254 }
255
256 /*!
257 **************************************************
258 * \brief Count the nb of card with the reference card id frd_id
259 *
260 * \param $p_frd_id the fiche_def_ref.frd_id
261 * \param $p_search p_search is a filter on the name
262 * \param $p_sql extra sql condition
263 *
264 * \return nb of item found
265 */
266 function count_by_modele($p_frd_id,$p_search="",$p_sql="")
267 {
268 // Scan for SQL inject
269 $this->cn->search_sql_inject($p_sql);
270
271 if ( $p_search != "" )
272 {
273 $result = $this->cn->get_value("select count(*) from
274 vw_fiche_attr
275 where
276 frd_id=$1
277 and vw_name ilike '%'||$2||'%'",
278 [$p_frd_id,$p_search]);
279 return $result;
280 } else {
281 $result = $this->cn->get_value("select count(*)
282 from
283 fiche join fiche_Def using (fd_id)
284 where frd_id=$1 ".$p_sql
285 ,[$p_frd_id]);
286 return $result;
287 }
288
289
290 }
291 /*!
292 **************************************************
293 * \brief Return array of card from the frd family deprecated , use insert get_by_category_id
294 *
295 * \deprecated
296 * \see Fiche::get_by_category
297 * \param $p_frd_id the fiche_def_ref.frd_id NOT USED , $this->fiche_def_ref will be used instead
298 * \param $p_offset
299 * \param $p_search is an optional filter
300 *\param $p_order : possible values are name, f_id
301 * \return array of fiche object
302 */
303 function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
304 {
305 return $this->get_by_category($p_offset,$p_search,$p_order);
306 }
307 function ShowTable()
308 {
309 echo "<TR><TD> ".
310 $this->id."</TD>".
311 "<TR> <TD>".
312 $this->attribut_value."</TD>".
313 "<TR> <TD>".
314 $this->attribut_def."</TD></TR>";
315 }
316 /**
317 * @brief use get_attribute instead
318 * @deprecated since version 9.3.12
319 * @param int $p_ad_id AD_ID from attr_def.ad_id
320 * @param int $p_return 1 return NOTFOUND otherwise an empty string
321 */
322 function strAttribut($p_ad_id,$p_return=1)
323 {
324 return $this->get_attribute($p_ad_id,$p_return);
325 }
326 /***
327 * @brief return the string of the given attribute
328 * (attr_def.ad_id)
329 * @param int $p_ad_id AD_ID from attr_def.ad_id
330 * @param int $p_return 1 return NOTFOUND otherwise an empty string
331 * @see constant.php
332 * @return string
333 * @note reread data from database and so it reset previous unsaved change
334 */
335 function get_attribute($p_ad_id,$p_return=1)
336 {
337 $return=($p_return==1)?NOTFOUND:"";
338 if ( empty ($this->attribut) )
339 {
340
341 $this->load_attribute();
342 }
343
344 foreach ($this->attribut as $e)
345 {
346 if ( $e->ad_id == $p_ad_id )
347 return noalyss_trim($e->av_text);
348 }
349 return $return;
350 }
351 /*!
352 * \brief turn a card into an array , then it can be saved thanks update or insert
353 * \see Fiche::insert , Fiche::update
354 *
355 */
356 function to_array()
357 {
358 $a_return=[];
359 if ( empty ($this->attribut)) {
360 $this->load_attribute();
361 }
362 foreach ($this->attribut as $attr)
363 {
364 $a_return['av_text'.$attr->ad_id]=$attr->av_text;
365 }
366 $a_return['f_enable']=$this->get_f_enable();
367 return $a_return;
368 }
369 /*!
370 * \brief insert a new record
371 * show a blank card to be filled
372 *
373 * \param $p_fiche_def is the fiche_def.fd_id
374 *
375 * \return HTML Code
376 */
377 function blank($p_fiche_def)
378 {
379 // array = array of attribute object sorted on ad_id
380 $fiche_def=new Fiche_Def($this->cn,$p_fiche_def);
381 $fiche_def->get();
382 $array=$fiche_def->load_attribute();
383 $r="";
384 $r.='<table style="width:98%;margin:1%">';
385 foreach ($array as $attr)
386 {
387 $table=0;
388 $msg="";$bulle='';
389 $r.=$attr->input($fiche_def);
390
391 }
392 $r.= '</table>';
393 return $r;
394 }
395
396 public function __toString(): string
397 {
398 return print_r($this,true);
399 }
400
401 /**
402 *
403 * @return string with the category
404 */
406 {
407 $type_card=$this->cn->get_value('select fd_label '
408 . ' from fiche_def join fiche using (fd_id) where f_id=$1',
409 array($this->id));
410 return $type_card;
411 }
412
413 /*!
414 * \brief Display object instance, getAttribute
415 * sort the attribute and add missing ones
416 * \param $p_readonly true= if can not modify, otherwise false
417 *\param string $p_in if called from an ajax it is the id of the html
418 * elt containing
419 *
420 * \return string to display or FNT string for fiche non trouvé
421 */
422 function Display($p_readonly,$p_in="")
423 {
424 $this->load_attribute();
426 $ret="";
427 $ret.='<span style="margin-right:5px;float:right;font-size:80%">'.
428 _('id').':'.$this->id."</span>";
429 $ret.="<table style=\"width:98%;margin:1%\">";
430 if (empty($attr))
431 {
432 return 'FNT';
433 }
434
435 $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
436 /* for each attribute */
437 foreach ($attr as $r)
438 {
439 $msg="";
440 $bulle="";
441 $r->setDisplayMode($this->display_mode);
442 if ($p_readonly)
443 {
444 $ret .= $r->print();
445 }
446 if ($p_readonly==false)
447 {
448 $ret .= $r->input($fiche_def);
449
450 }
451 }
452 // Display if the card is enable or not
453 $enable_is=new InputSwitch("f_enable");
454 $enable_is->value=$this->f_enable;
455 $enable_is->readOnly=$p_readonly;
456
457 $ret.=tr(
458 td(_("Actif"),'class="input_text"').td($enable_is->input(),'class="input_text"')
459 );
460
461
462 $ret.="</table>";
463
464 return $ret;
465 }
466
467 /*!
468 * \brief Save a card, call insert or update
469 * \see Fiche::insert , Fiche::update
470 *
471 * \param p_fiche_def (default 0)
472 */
473 function save($p_fiche_def=0)
474 {
475 // new card or only a update ?
476 if ( $this->id == 0 )
477 $this->insert($p_fiche_def);
478 else
479 $this->update();
480 }
481 /*!
482 * \brief insert a new record thanks an array , either as parameter or $_POST
483 *
484 * \param $p_fiche_def fiche_def.fd_id
485 * \param $p_array (double array) array containing arrays of key (av_textX where X is AD_ID ), value of the property
486 *\param $transation DEPRECATED : if we are in a transaction, we don't commit here , else if not, the
487 * then a transaction is started and committed
488 *
489 av_textX where X is the ad_id
490 *\verbatim
491 example
492 av_text1=>'name'
493 \endverbatim
494 */
495 function insert($p_fiche_def, $p_array=null, $transaction=true)
496 {
497 if ($p_array==null)
499
500 $fiche_id=$this->cn->get_next_seq('s_fiche');
501 $this->id=$fiche_id;
502 $this->fiche_def=$p_fiche_def;
503 try
504 {
505
506 // by default the card is available
507 if (!isset($p_array['f_enable']))
508 {
509 $p_array['f_enable']=1;
510 }
511 $Ret=$this->cn->exec_sql("insert into fiche(f_id,f_enable,fd_id) values ($1,$2,$3)",
512 array($fiche_id, $p_array['f_enable'], $p_fiche_def));
513 // first we need to save the name , to compute properly the quickcode
514 if ( empty ($p_array['av_text'.ATTR_DEF_NAME])) {
515
516 $p_array['av_text'.ATTR_DEF_NAME]=_("Nom vide");
517 }
518 // the name must be saved first
519 $this->cn->exec_sql("insert into fiche_detail (f_id,ad_id,ad_value) values ($1,$2,$3)",
520 array($fiche_id,1,$p_array['av_text'.ATTR_DEF_NAME]));
521
522 // compute a quick_code
523 if (!isset($p_array["av_text".ATTR_DEF_QUICKCODE]))
524 {
525 $p_array["av_text".ATTR_DEF_QUICKCODE]="";
526 }
527 // by default the quick_code is the base account of the class + first letters of the name
528 if ( $p_array["av_text".ATTR_DEF_QUICKCODE] =="")
529 {
530 if ( ! empty( $p_array['av_text'. ATTR_DEF_ACCOUNT])) {
531 $base_acc=substr($p_array['av_text'. ATTR_DEF_ACCOUNT]??"",0, 3);
532 }else {
533 $base_acc=$this->cn->get_value("select substr(fd_class_base,1,2) from fiche_def where fd_id = $1",
534 [$p_fiche_def]);
535 }
536 $p_array["av_text".ATTR_DEF_QUICKCODE]=sprintf("%s%s"
537 , $base_acc
538 , substr($p_array["av_text".ATTR_DEF_NAME], 0, 4)
539 );
540 }
541 $sql=sprintf("select insert_quick_code(%d,'%s')", $fiche_id,
543 $this->cn->exec_sql($sql);
544 // get the card properties for this card category
545 $fiche_def=new Fiche_Def($this->cn, $p_fiche_def);
546
547 $this->attribut=$fiche_def->load_attribute();
548
549 if (empty($this->attribut))
550 {
551 throw new Exception("FICHE.UPDATE02"._("Aucun attribut ")."($p_fiche_def)", EXC_INVALID);
552 }
553 // for each property set the attribut on the card
554 foreach ($this->attribut as $property)
555 {
556 $key='av_text'.$property->ad_id;
557 if (isset($p_array[$key]))
558 {
559 $this->set_attribute($property->ad_id, $p_array[$key]);
560 }
561 }
562 // For accounting
563
565 // reread from database
566 $this->load_attribute();
567 }
568 catch (Exception $e)
569 {
570 record_log($e);
571 $this->cn->rollback();
572 throw (new \Exception ("F561 ". __CLASS__.".".__FUNCTION__,561,$e));
573 return;
574 }
575 return;
576 }
577
578 /*!
579 * \brief update a card with an array
580 * \param $p_array (optional) is the array containing the data , if NULL then $_POST will be uses
581 *\param $transation if we want to manage the transaction in this function
582 * true for small insert and false for a larger loading, the BEGIN / COMMIT sql
583 * must be done into the caller
584 av_textX where X is the ad_id
585 *\verb
586 example
587 av_text1=>'name'
588 \endverb
589 */
590 function update($p_array=null)
591 {
592 if ($p_array==null)
593 {
595 }
596 $this->fiche_def = $this->cn->get_value("select fd_id from fiche where f_id=$1",[$this->id]);
597 // unexistant category of cardf
598 if ( empty($this->fiche_def)) {
599 throw new Exception('FICHE.UPDATE524 category not found',EXC_INVALID);
600 }
601 if ( $this->cn->size()==0) {
602 throw new Exception("FICHE.UPDATE01"._("Fiche n'existe pas"),EXC_INVALID);
603 }
604
605
606 // get the card properties for this card category
607 $this->load_attribute();
608
609 if ( empty ($this->attribut) ) {
610 throw new Exception("FICHE.UPDATE02"._("Aucun attribut ")."($this->fiche_def)",EXC_INVALID);
611 }
612 // for each property set the attribut on the card
613 foreach($this->attribut as $property) {
614 $key='av_text'.$property->ad_id;
615 if ( isset($p_array[$key])) {
616 $this->set_attribute($property->ad_id, $p_array[$key]);
617 }
618 }
619 if ( isset($p_array['f_enable'])) {
620 $this->set_f_enable($p_array["f_enable"]);
621 }else {
622 $this->set_f_enable(1);
623 }
624 // save all
626 $this->quick_code=$this->get_attribute(ATTR_DEF_QUICKCODE);
627 }
628
629 /*!\brief remove a card, check if not used first, must be synchro with is_used
630 */
631 function remove($silent=false)
632 {
633 if ( $this->id==0 ) return;
634 // verify if that card has not been used is a ledger nor in the followup
635 // if the card has its own account in PCMN
636 // Get the fiche_def.fd_id from fiche.f_id
637 if ( $this->is_used() == FALSE) {
638 $this->delete();
639 return 0;
640 }
641
642 if ( ! $silent ) {
643 alert(_('Impossible cette fiche est utilisée dans un journal'));
644 }
645 return 1;
646 }
647
648
649 /*!\brief return the name of a card
650 *
651 */
652 function getName()
653 {
654 $sql="select ad_value from fiche_detail
655 where ad_id=1 and f_id=$1";
656 $Res=$this->cn->exec_sql($sql,array($this->id));
658 if ( empty($r) )
659 throw new Exception (_("Fiche n'existe pas"), 1000);
660 return $r[0]['ad_value'];
661 }
662
663 /*!\brief return the quick_code of a card
664 * \return null if not quick_code is found
665 */
666 function get_quick_code()
667 {
668 $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
669 $Res=$this->cn->exec_sql($sql,array($this->id));
671 if ( $r == FALSE || sizeof($r) == 0 )
672 return null;
673 return $r[0]['ad_value'];
674 }
675
676 /*!\brief Synonum of fiche::load_attribute
677 */
678 function Get()
679 {
680 $this->load_attribute();
681 }
682 /*!\brief Synonum of fiche::load_attribute
683 */
684 function load() :void
685 {
686 $this->load_attribute();
687 }
688 /*!
689 * \brief get all the card thanks the fiche_def_ref
690 * \param $p_offset (default =-1)
691 * \param $p_search sql condition
692 * \return array of fiche object
693 */
694 function get_by_category($p_offset=-1,$p_search="",$p_order='')
695 {
696 switch($p_order)
697 {
698 case 'name' :
699 $order=' order by name';
700 break;
701 case 'f_id':
702 $order='order by f_id';
703 break;
704 default:
705 $order='';
706 }
707 if ( $p_offset == -1 )
708 {
709 $sql="select *
710 from
711 fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
712 where frd_id=".$this->fiche_def_ref." $p_search ".$order;
713 }
714 else
715 {
716 $limit=($_SESSION[SESSION_KEY.'g_pagesize']!=-1)?"limit ".$_SESSION[SESSION_KEY.'g_pagesize']:"";
717 $sql="select *
718 from
719 fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
720 where frd_id=".$this->fiche_def_ref." $p_search $order "
721 .$limit." offset ".$p_offset;
722
723 }
724
725 $Ret=$this->cn->exec_sql($sql);
726 if ( ($Max=Database::num_row($Ret)) == 0 )
727 return [];
728 $all[0]=new Fiche($this->cn);
729
730 for ($i=0;$i<$Max;$i++)
731 {
733 $t=new Fiche($this->cn,$row['f_id']);
734 $t->load_attribute();
735 $all[$i]=clone $t;
736
737 }
738 return $all;
739 }
740 /*!\brief retrieve the frd_id of the fiche it is the type of the
741 * card (bank, purchase...)
742 * (fiche_def_ref primary key)
743 */
745 {
746 $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=$1",[$this->id]);
747 if ( $result == null )
748 return null;
749
750 return $result[0]['frd_id'];
751 }
752 /**
753 *@brief fetch and return and array
754 *@see get_row get_row_date
755 * @deprecated since version 6920
756 */
758 {
759 $array=array();
760 $tot_cred=0.0;
761 $tot_deb=0.0;
763 if ( $Max == 0 ) return null;
764 bcscale(2);
765 for ($i=0;$i<$Max;$i++)
766 {
768 if ($array[$i]['j_debit']=='t')
769 {
770 $tot_deb=bcadd($tot_deb, $array[$i]['deb_montant'] );
771 }
772 else
773 {
774 $tot_cred=bcadd($tot_cred,$array[$i]['cred_montant'] );
775 }
776 }
777 $this->row=$array;
778 $this->tot_deb=$tot_deb;
779 $this->tot_cred=$tot_cred;
780 return array($array,$tot_deb,$tot_cred);
781 }
782 /*!
783 * \brief Get data for poste
784 *
785 * \param $p_from periode from
786 * \param $p_to end periode
787 *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
788 * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
789 * (tot_deb,tot_credit
790 *
791 */
792 function get_row_date($p_from,$p_to,$op_let=0)
793 {
794 global $g_user;
795 if ( $this->id == 0 )
796 {
797 echo_error("class_fiche",__LINE__,"id is 0");
798 return;
799 }
800 $filter_sql=$g_user->get_ledger_sql('ALL',3);
801 $sql_let='';
802 switch ($op_let)
803 {
804 case 0:
805 break;
806 case 1:
807 $sql_let=' and j1.j_id in (select j_id from letter_cred union select j_id from letter_deb)';
808 break;
809 case '2':
810 $sql_let=' and j1.j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
811 break;
812 }
813
815 $this->row=$this->cn->get_array("
816 with sqlletter as
817 (select j_id,jl_id from letter_cred union all select j_id , jl_id from letter_deb )
818 select distinct substring(jr_pj_number,'[0-9]+$'),j1.j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
819 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
820 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
821 " jr_comment as description,jrn_def_name as jrn_name,j_poste,".
822 " jr_pj_number,".
823 "j_debit, jr_internal,jr_id,(select distinct jl_id from sqlletter where sqlletter.j_id=j1.j_id ) as letter , ".
824 "jr_optype , ".
825 " jr_tech_per,p_exercice,jrn_def_name,
826 (with cred as (select jl_id, sum(j_montant) as amount_cred from letter_cred lc1 left join jrnx as j3 on (j3.j_id=lc1.j_id) group by jl_id ),
827 deb as (select jl_id, sum(j_montant) as amount_deb from letter_deb ld1 left join jrnx as j2 on (j2.j_id = ld1.j_id) group by jl_id )
828 select amount_deb-amount_cred
829 from
830 cred
831 full join deb using (jl_id) where jl_id=(select distinct jl_id from sqlletter where sqlletter.j_id=j1.j_id )) as delta_letter,
832 jrn_def_code,
833 jrn.currency_rate,
834 jrn.currency_rate_ref,
835 jrn.currency_id,
836 (select cr_code_iso from currency where id=jrn.currency_id) as cr_code_iso,
837 j_montant,
838 sum_oc_amount as oc_amount,
839 sum_oc_vat_amount as oc_vat_amount ,
840 case when exists(select 1 from operation_analytique oa where j1.j_id=oa.j_id) then 1 else 0 end as op_analytic
841 from jrnx as j1 left join jrn_def on jrn_def_id=j_jrn_def
842 left join (select j_id,
843 coalesce(oc_amount,0) as sum_oc_amount ,
844 coalesce(oc_vat_amount,0) as sum_oc_vat_amount
845 from jrnx left join operation_currency using (j_id)
846 ) as v1 on (v1.j_id=j1.j_id )
847 left join jrn on jr_grpt_id=j_grpt".
848 " left join parm_periode on (p_id=jr_tech_per) ".
849 " where j_qcode=$1 and ".
850 " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
851 " to_date($3,'DD.MM.YYYY') >= j_date )".
852 " and $filter_sql $sql_let ".
853 " order by j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));
854
855 $res_saldo = $this->cn->exec_sql("select sum(deb_montant),sum(cred_montant) from
856 (select case when j_debit='t' then j_montant else 0 end as deb_montant,
857 case when j_debit='f' then j_montant else 0 end as cred_montant
858 from jrnx j1
859 join jrn_def on (jrn_def_id=j_jrn_def )
860 join jrn on (jr_grpt_id=j_grpt)
861 join tmp_pcmn on (j_poste=pcm_val)
862 join parm_periode on (p_id=jr_tech_per)
863 where f_id=$1 and
864 ( to_date($2,'DD.MM.YYYY') <= j_date and
865 to_date($3,'DD.MM.YYYY') >= j_date )
866 and $filter_sql $sql_let ) as m",array($this->id,$p_from,$p_to));
867 $this->tot_deb=$this->tot_cred=0;
868
869 if ( Database::num_row($res_saldo) > 0 ) {
870 $this->tot_deb=Database::fetch_result($res_saldo, 0, 0);
871 $this->tot_cred=Database::fetch_result($res_saldo, 0, 1);
872 }
873
875 }
876
877 /*!
878 * \brief Get data for poste
879 *
880 * \param $p_from periode periode.p_id
881 * \param $p_to end periode periode.p_id
882 * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
883 * (tot_deb,tot_credit
884 *
885 */
886 function get_row($p_from,$p_to)
887 {
888 if ( $this->id == 0 )
889 {
890 echo_error("class_fiche",__LINE__,"id is 0");
891 return;
892 }
894 $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
895
896 $this->row=$this->cn->get_array("select j_date,
897 to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
898 j_qcode,
899 case when j_debit='t' then j_montant else 0 end as deb_montant,
900 case when j_debit='f' then j_montant else 0 end as cred_montant,
901 jr_comment as description,
902 jrn_def_name as jrn_name,
903 j_debit,
904 jr_internal,
905 jr_id
906 from jrnx
907 left join jrn_def on jrn_def_id=j_jrn_def
908 left join jrn on jr_grpt_id=j_grpt
909 where
910 j_qcode=$1 and {$periode}
911 order by j_date::date",array(
912 $qcode
913 ));
914 $res_saldo = $this->cn->exec_sql("select sum(deb_montant),sum(cred_montant) from
915 (select case when j_debit='t' then j_montant else 0 end as deb_montant,
916 case when j_debit='f' then j_montant else 0 end as cred_montant
917 from jrnx
918 left join jrn_def on jrn_def_id=j_jrn_def
919 left join jrn on jr_grpt_id=j_grpt
920 where
921 j_qcode=$1 and {$periode} ) as m",
922 array($this->id));
923 $this->tot_deb=$this->tot_cred=0;
924
925 if ( Database::num_row($res_saldo) > 0 ) {
926 $this->tot_deb=Database::fetch_result($res_saldo, 0, 0);
927 $this->tot_cred=Database::fetch_result($res_saldo, 0, 1);
928 }
929 return array($this->row,$this->tot_deb,$this->tot_cred);
930
931 }
932 /*!
933 * \brief HtmlTable, display a HTML of a card for the asked period
934 *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
935 * \return none
936 */
937 function HtmlTableDetail($p_array=null,$op_let=0)
938 {
939 if ( $p_array == null)
941
942 $name=$this->getName();
943
944 list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
945 $p_array['to_periode'],
946 $op_let
947 );
948
949 if ( count($this->row ) == 0 )
950 return;
952
953 $rep="";
954 $already_seen=array();
955 echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
956 echo "<TABLE class=\"result\" style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
957 echo "<TR>".
958 "<TH>"._("n° de pièce / Code interne")." </TH>".
959 "<TH>"._("Date")."</TH>".
960 "<TH>"._("Description")." </TH>".
961 "<TH>"._('Montant')." </TH>".
962 "<TH> "._('Débit/Crédit')." </TH>".
963 "</TR>";
964
965 foreach ( $this->row as $op )
966 {
967 if ( in_array($op['jr_internal'],$already_seen) )
968 continue;
969 else
970 $already_seen[]=$op['jr_internal'];
971 echo "<TR style=\"text-align:center;background-color:lightgrey\">".
972 "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
973 "<td>".$op['j_date']."</td>".
974 "<td>".h($op['description'])."</td>".
975 "<td>"."</td>".
976 "<td>"."</td>".
977 "</TR>";
978 $ac=new Acc_Operation($this->cn);
979 $ac->jr_id=$op['jr_id'];
980 $ac->qcode=$qcode;
981 echo $ac->display_jrnx_detail(1);
982
983 }
984 $solde_type=($tot_deb>$tot_cred)?_("solde débiteur"):_("solde créditeur");
985 $diff=round(abs($tot_deb-$tot_cred),2);
986 echo "<TR>".
987 "<TD>$solde_type".
988 "<TD>$diff</TD>".
989 "<TD></TD>".
990 "<TD>$tot_deb</TD>".
991 "<TD>$tot_cred</TD>".
992 "</TR>";
993
994 echo "</table>";
995
996 return;
997 }
998 /*!
999 * \brief HtmlTable, display a HTML of a card for the asked period
1000 * \param $p_array default = null keys = from_periode, to_periode
1001 *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
1002 *\return -1 if nothing is found otherwise 0
1003 *\see get_row_date
1004 */
1005 function HtmlTable($p_array=null,$op_let=0,$from_div=1)
1006 {
1007 if ( $p_array == null)
1009 global $g_parameter;
1010 $progress=0;
1011 // if from_periode is greater than to periode then swap the values
1012 if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 0)
1013 {
1014 $tmp=$p_array['from_periode'];
1015 $p_array['from_periode']=$p_array['to_periode'];
1016 $p_array['to_periode']=$tmp;
1017
1018 }
1019 list($array, $tot_deb, $tot_cred) = $this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
1020
1021 if ( count($this->row ) == 0 )
1022 return -1;
1023
1025 $type=$acc_account_ledger->get_type();
1026 // label warning if the saldo is incorrect
1027 $label="";
1028 if (in_array($type,array('CHA','ACT','PASINV','PROINV')) && $tot_deb<$tot_cred)
1029 {
1030
1031 $label.=_("Solde créditeur au lieu de débiteur").'<span class="icon">&#xe80e;</span>';
1032 }
1033 if (in_array($type,array('PRO','PAS','ACTINV','CHAINV')) && $tot_deb>$tot_cred)
1034 {
1035
1036 $label.=_("Solde débiteur au lieu de créditeur")." ".'<span class="icon">&#xe80e;</span>';
1037 }
1038 if ( $label !="" )
1039 echo '<span class="notice" >'.$label.'</span>';
1040 $rep="";
1041 if ( $from_div==1)
1042 {
1043 echo "<TABLE id=\"tbpopup\" class=\"resultfooter\" style=\"margin:1%;width:98%;;border-collapse:collapse;border-spacing:0px 5px\">";
1044 }
1045 else
1046 {
1047 echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" style=\"margin:1%;width:98%;border-collapse:collapse;border-spacing:0px 2px\">";
1048 }
1049 echo '<tbody>';
1050 echo "<TR>".
1051 "<TH style=\"text-align:left\">"._('Date')."</TH>".
1052 "<TH style=\"text-align:left\">"._('Pièce')." </TH>".
1053 "<TH style=\"text-align:left\">"._('Poste')." </TH>".
1054 "<TH style=\"text-align:left\">"._('Interne')." </TH>".
1055 "<TH style=\"text-align:left\">"._('Tiers')." </TH>".
1056 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('Description')." </TH>".
1057 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('Type')."</TH>".
1058 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('ISO')."</TH>".
1059 "<TH class=\"visible_gt800\" style=\"text-align:right\">"._('Dev.')."</TH>".
1060 "<TH style=\"text-align:right\">"._('Débit')." </TH>".
1061 "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
1062 th('Prog.','style="text-align:right"').
1063 th('Let.','class="visible_gt800" style="text-align:right"');
1064 "</TR>"
1065 ;
1066 $old_exercice="";$sum_deb=0;$sum_cred=0;
1067 bcscale(2);
1068 $idx=0;
1069 $operation=new Acc_Operation($this->cn);
1070 foreach ( $this->row as $op )
1071 {
1072 $vw_operation = sprintf('<A class="detail" style="text-decoration:underline;color:red" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], dossier::id(), $op['jr_internal']);
1073 $let = '';
1074 $html_let = "";
1075 if ($op['letter'] != "")
1076 {
1077 $let = strtoupper(base_convert($op['letter'], 10, 36));
1078 $html_let = HtmlInput::show_reconcile($from_div, $let);
1079 if ( $op['delta_letter'] != 0) $html_let='<img src="image/warning.png" onmouseover="displayBulle(\'delta = '.$op['delta_letter'].'\')" onmouseleave="hideBulle()" style="height:12px"/>'.$html_let;
1080 }
1081 $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
1082
1083 /*
1084 * reset prog. balance to zero if we change of exercice
1085 */
1086 if ( $old_exercice != $op['p_exercice'])
1087 {
1088 if ($old_exercice != '' )
1089 {
1090 $progress=bcsub($sum_deb,$sum_cred);
1091 $side="&nbsp;".$this->get_amount_side($progress);
1092 echo "<TR class=\"highlight\">".
1093 td($op['p_exercice']).
1094 td("",' class="visible_gt800" ').
1095 td("",' class="visible_gt800" ').
1096 td("",' class="visible_gt800" ').
1097 td().
1098 td(_('Totaux')).
1099 td("",' class="visible_gt800" ').
1100 td("",' class="" ').
1101 "<TD></TD>".
1102 "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
1103 "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
1104 td(nbm(abs($progress)).$side,'style="text-align:right"').
1105 td("",' class="visible_gt800" ').
1106 "</TR>";
1107 $sum_cred=0;
1108 $sum_deb=0;
1109 $progress=0;
1110 }
1111 }
1112 $progress=bcadd($progress,$tmp_diff);
1113 $side="&nbsp;".$this->get_amount_side($progress);
1114 $sum_cred=bcadd($sum_cred,$op['cred_montant']);
1115 $sum_deb=bcadd($sum_deb,$op['deb_montant']);
1116 if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"';
1117 $idx++;
1118
1119 $tiers=$operation->find_tiers($op['jr_id'], $op['j_id'], $op['j_qcode']);
1120 $op_analytic=($op['op_analytic']==1)?'<span style="float:right;background:black;color:white;">&ni;</span>':'';
1121 echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
1122 "<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
1123 td(h($op['jr_pj_number'])).
1124 td($op['j_poste']).
1125 "<TD>".$vw_operation."</TD>".
1126 td($tiers, ' class="visible_gt800" ').
1127 "<TD class=\"visible_gt800\" >".h($op['description']).$op_analytic."</TD>".
1128 td($op['jr_optype']);
1129
1130 /// If the currency is not the default one , then show the amount
1131 if ( $op['currency_id'] > 0 && $op['oc_amount'] != 0)
1132 {
1133 echo td($op['cr_code_iso'], ' class="visible_gt800" ').
1134 td(nbm($op['oc_amount'],4),' class="visible_gt800" style="text-align:right;padding-left:10px;"');
1135 } else {
1136 echo td("",' class="visible_gt800" ').td("",' class="visible_gt800" ');
1137 }
1138
1139 echo "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
1140 "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
1141 td(nbm(abs($progress)).$side,'style="text-align:right"').
1142 td($html_let, ' style="text-align:right" class="visible_gt800" ') .
1143 "</TR>";
1144 $old_exercice=$op['p_exercice'];
1145
1146 }
1147 $solde_type=($sum_deb>$sum_cred)?_("solde débiteur"):_("solde créditeur");
1148 $solde_side=($sum_deb>$sum_cred)?"D":"C";
1149 $diff=abs(bcsub($sum_deb,$sum_cred));
1150 echo '<tfoot>';
1151 echo "<TR class=\"highlight\">".
1152 td($op['p_exercice']).
1153 td("",' class="visible_gt800" ').
1154 td("",' class="visible_gt800" ').
1155 td("",' class="visible_gt800" ').
1156 td().
1157 td(_('Totaux')).
1158 td("",' class="visible_gt800" ').
1159 td("",' class="" ').
1160 "<TD></TD>".
1161 "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
1162 "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
1163 "<TD style=\"text-align:right\">".nbm($diff).$solde_side."</TD>".
1164 td("",' class="visible_gt800" ').
1165 "</TR>";
1166 echo "<TR style=\"font-weight:bold\">".
1167 "<TD>$solde_type</TD>".
1168 "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
1169 "<TD></TD>".
1170 "</TR>";
1171 // take saldo from 1st day until last
1172 if ($g_parameter->MY_REPORT=='N') {
1173 $solde_until_now=$this->get_solde_detail(" j_date <= to_date('{$p_array['to_periode']}','DD.MM.YYYY') ");
1174 echo '<tr style="font-weight:bold;color:orangered">';
1175 echo td(_("Solde global"));
1176 echo td("D : ".nbm($solde_until_now['debit']),'class="num"');
1177 echo td("C : ".nbm($solde_until_now['credit']),'class="num"');
1178 echo td("Delta : ".nbm($solde_until_now['solde'])." ".$this->get_amount_side($solde_until_now['debit']-$solde_until_now['credit']),'class="num"');
1179 echo '</tr>';
1180
1181 }
1182 echo '</tfoot>';
1183 echo '</tbody>';
1184
1185 echo "</table>";
1186
1187 return 0;
1188 }
1189 /*!
1190 * \brief Display HTML Table Header (button)
1191 *
1192 * \return none
1193 */
1195 {
1196 if ( $p_array == null)
1198
1199 $hid=new IHidden();
1200 echo '<div class="noprint">';
1201 echo "<table >";
1202 echo '<TR>';
1203
1204 echo '<TD><form method="GET" ACTION="">'.
1205 HtmlInput::submit('bt_other',_("Autre poste")).
1206 HtmlInput::array_to_hidden(array('gDossier','ac'), $_REQUEST).
1207 dossier::hidden().
1208 $hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
1209 $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
1210
1211 echo '<TD><form method="GET" ACTION="export.php" ';
1212 $id=uniqid("export_");
1213 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
1214 echo
1215 HtmlInput::submit('bt_pdf',_("Export PDF")).
1216 dossier::hidden().$str_ople.
1217 HtmlInput::hidden('act','PDF:fichedetail').
1218 $hid->input("type","poste").
1219 $hid->input('p_action','impress').
1220 $hid->input("f_id",$this->id).
1221 dossier::hidden().
1222 $hid->input("from_periode",$p_array['from_periode']).
1223 $hid->input("to_periode",$p_array['to_periode']);
1224 if (isset($p_array['oper_detail']))
1225 echo $hid->input('oper_detail','on');
1226
1227 echo "</form></TD>";
1228
1229 echo '<TD><form method="GET" ACTION="export.php" ';
1230 $id=uniqid("export_");
1231 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
1232
1233 echo HtmlInput::submit('bt_csv',_("Export CSV")).
1234 HtmlInput::hidden('act','CSV:fichedetail').
1235 dossier::hidden().$str_ople.
1236 $hid->input("type","poste").
1237 $hid->input('p_action','impress').
1238 $hid->input("f_id",$this->id).
1239 $hid->input("from_periode",$p_array['from_periode']).
1240 $hid->input("to_periode",$p_array['to_periode']);
1241 if (isset($p_array['oper_detail']))
1242 echo $hid->input('oper_detail','on');
1243
1244 echo "</form></TD>";
1245 echo "</form></TD>";
1246 echo '<td style="vertical-align:top">';
1247 echo HtmlInput::print_window();
1248 echo '</td>';
1249 echo "</table>";
1250 echo '</div>';
1251
1252 }
1253 /*!
1254 * \brief give the balance of an card
1255 * \return
1256 * balance of the card
1257 *
1258 */
1259 function get_solde_detail($p_cond="")
1260 {
1261 if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
1263
1264 if ( $p_cond != "") $p_cond=" and ".$p_cond;
1265 $Res=$this->cn->exec_sql("select coalesce(sum(deb),0) as sum_deb,
1266 coalesce(sum(cred),0) as sum_cred from
1267 ( select j_poste,
1268 case when j_debit='t' then j_montant else 0 end as deb,
1269 case when j_debit='f' then j_montant else 0 end as cred
1270 from jrnx
1271 where
1272 j_qcode = ('$qcode'::text)
1273 $p_cond
1274 ) as m ");
1276 if ($Max==0) return 0;
1278
1279 return array('debit'=>$r['sum_deb'],
1280 'credit'=>$r['sum_cred'],
1281 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
1282 }
1283 /**
1284 * Get the sum in Currency
1285 * @param string $p_cond
1286 * @return type
1287 * @throws Exception
1288 */
1289 function get_bk_balance_currency($p_cond="")
1290 {
1291 if ( $this->id == 0 ) throw new Exception('fiche->id est nul');
1292
1293 if ( $p_cond != "") $p_cond=" and ".$p_cond;
1294
1295 $sql = "
1296 select sum(sum_oc_amount)
1297 from
1298 v_all_card_currency
1299 where
1300 f_id=$1
1301 $p_cond";
1302 $val=$this->cn->get_value($sql,[$this->id]);
1303
1304 return $val;
1305
1306 }
1307 /**
1308 *get the bank balance with receipt or not in Euro
1309 *
1310 */
1311 function get_bk_balance($p_cond="")
1312 {
1313 if ( $this->id == 0 ) throw new Exception('fiche->id est nul');
1315
1316 if ( $p_cond != "") $p_cond=" and ".$p_cond;
1317 $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
1318 ( select j_poste,
1319 case when j_debit='t' then j_montant else 0 end as deb,
1320 case when j_debit='f' then j_montant else 0 end as cred
1321 from jrnx
1322 join jrn on (jr_grpt_id=j_grpt)
1323 where
1324 j_qcode = ('$qcode'::text)
1325 $p_cond
1326 ) as m ";
1327
1328 $Res=$this->cn->exec_sql($sql);
1330 if ($Max==0) return 0;
1332
1333 return array('debit'=>$r['sum_deb'],
1334 'credit'=>$r['sum_cred'],
1335 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
1336
1337 }
1338 /*!\brief check if an attribute is empty
1339 *\param $p_attr the id of the attribut to check (ad_id)
1340 *\return return true is the attribute is empty or missing
1341 */
1342 function empty_attribute($p_attr)
1343 {
1344 $sql="select ad_value
1345 from fiche_detail
1346 natural join fiche
1347 left join attr_def using (ad_id) where f_id=$1 ".
1348 " and ad_id = $2 ".
1349 " order by ad_id";
1350 $res=$this->cn->exec_sql($sql,[$this->id,$p_attr]);
1351 if ( Database::num_row($res) == 0 ) return true;
1353 return (strlen(noalyss_trim($text)) > 0)?false:true;
1354
1355
1356 }
1357 /*!
1358 * \brief show the default screen
1359 *
1360 * \param $p_search (filter)
1361 * \param $p_action used for specific action bank, red if credit < debit
1362 * \param $p_sql SQL to filter the number of card must start with AND
1363 * \param $p_amount true : only cards with at least one operation default : false
1364 * \return: string to display
1365 */
1366 function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
1367 {
1368 global $g_user;
1369 global $g_parameter;
1370 $http=new HttpInput();
1371 $bank=new Acc_Parm_Code($this->cn,'BANQUE');
1372 $cash=new Acc_Parm_Code($this->cn,'CAISSE');
1373 $cc=new Acc_Parm_Code($this->cn,'COMPTE_COURANT');
1374
1375 bcscale(4);
1376 $gDossier=dossier::id();
1377 $p_search=sql_string($p_search);
1378 $script=$_SERVER['PHP_SELF']??"";
1379 // Creation of the nav bar
1380 // Get the max numberRow
1381 $filter_amount='';
1382
1383 $filter_year=" j_tech_per in (select p_id from parm_periode ".
1384 "where p_exercice='".$g_user->get_exercice()."')";
1385
1386 if ($p_amount) {
1387 $filter_amount = ' and f_id in (select f_id from jrnx where ' . $filter_year . ')';
1388 }
1389
1390 $all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
1391 // Get offset and page variable
1392 $offset=$http->request("offset","number",0);
1393 $page=$http->request("page","number",1);
1394 $bar=navigation_bar($offset,$all_tiers,$_SESSION[SESSION_KEY.'g_pagesize'],$page);
1395
1396 // set a filter ?
1397 $search=$p_sql;
1398
1399 if ( noalyss_trim($p_search) != "" )
1400 {
1401 $search.=" and f_id in
1402 (select distinct f_id from fiche_detail
1403 where
1404 ad_id in (1,32,30,23,18,13) and ad_value ilike '%$p_search%')";
1405 }
1406 // Get The result Array
1407 $step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');
1408
1409 if ( $all_tiers == 0 || empty($step_tiers ) ) { return ""; }
1410 $r="";
1411 $r.=$bar;
1412
1413 $r.='<table id="tiers_tb" class="sortable" style="">
1414 <TR >
1415 <TH>'._('Quick Code').Icon_Action::infobulle(17).'</TH>'.
1416 '<th>'._('Poste comptable').'</th>'.
1417 '<th class="sorttable_sorted">'._('Nom').'</span>'.'</th>'.
1418 '<th>'._('Compte en banque').'</th>'.
1419 '<th>'._('Adresse').'</th>'.
1420 '<th>'._('site web').'</th>'.
1421 '<th style="text-align:right">'._('Total débit').'</th>
1422 <th style="text-align:right">'._('Total crédit').'</th>
1423 <th style="text-align:right">'._('Solde').'</th>';
1424 $r.='</TR>';
1425 if ( sizeof ($step_tiers ) == 0 )
1426 return $r;
1427
1428 $i=0;
1429 $deb=0;$cred=0;
1430 foreach ($step_tiers as $tiers )
1431 {
1432 $i++;
1433
1434 /* Filter on the default year */
1435 if ( $g_parameter->MY_REPORT == 'N') {
1436 list($l_from,$l_to)=(new Periode($this->cn))->get_limit($g_user->get_exercice());
1437 $condition = sprintf (" j_date <= to_date('%s','DD.MM.YYYY') ", $l_to->last_day());
1438 $amount = $tiers->get_solde_detail($condition);
1439 } else {
1440 $amount=$tiers->get_solde_detail($filter_year);
1441 }
1442
1443 /* skip the tiers without operation */
1444 if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;
1445
1446 $odd="";
1447 $odd = ($i % 2 == 0 ) ? ' odd ': ' even ';
1448 $accounting=$tiers->get_attribute(ATTR_DEF_ACCOUNT,0);
1449 if ( ! empty($accounting) && $p_action == 'bank'
1450 && $amount['debit'] < $amount['credit']
1451 &&
1452 ( /** the accounting is a financial account *****/
1453 (!empty ($bank->value) && strpos($accounting,$bank->p_value)===0 )
1454 || (!empty ($cash->value) && strpos($accounting,$cash->p_value)===0 )
1455 || ( !empty ($cc->value) && strpos($accounting,$cc->p_value)===0)
1456 )
1457 )
1458 {
1459 //put in red if c>d
1460 $odd.=" notice ";
1461 }
1462
1463 $odd=' class="'.$odd.'"';
1464
1465 $r.="<TR $odd>";
1466 $url_detail=$script.'?'.http_build_query(array('sb'=>'detail','sc'=>'sv','ac'=>$_REQUEST['ac'],'f_id'=>$tiers->id,'gDossier'=>$gDossier));
1467 $e=sprintf('<A HREF="%s" title="Détail" class="line"> ',
1468 $url_detail);
1469
1470 $r.="<TD> $e".$tiers->get_attribute(ATTR_DEF_QUICKCODE)."</A></TD>";
1471 $r.="<TD sorttable_customkey=\"text{$accounting}\"> $e".$accounting."</TD>";
1472 $r.="<TD>".h($tiers->get_attribute(ATTR_DEF_NAME))."</TD>";
1473 $r.=td($tiers->get_attribute(ATTR_DEF_BQ_NO,0));
1474 $r.="<TD>".h($tiers->get_attribute(ATTR_DEF_ADRESS,0).
1475 " ".$tiers->get_attribute(ATTR_DEF_POSTCODE,0).
1476 " ".$tiers->get_attribute(ATTR_DEF_COUNTRY,0)).
1477 "</TD>";
1478 $r.='<td>'.linkTo($tiers->get_attribute(ATTR_DEF_WEBSITE,0)).'</td>';
1479 $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
1480 $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
1481 $str_solde=nbm($amount['solde']);
1482 $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> '.$str_deb.'</TD>';
1483 $r.='<TD sorttable_customkey="'.$amount['credit'].'" align="right"> '.$str_cred.'</TD>';
1484 $side=($amount['debit'] > $amount['credit'])?'D':'C';
1485 $side=($amount['debit'] == $amount['credit'])?'=':$side;
1486 $red="";
1487 if ( $p_action == 'customer' && $amount['debit'] < $amount['credit'] ){
1488 //put in red if d>c
1489 $red=" notice ";
1490 }
1491 if ( $p_action == 'supplier' && $amount['debit'] > $amount['credit'] ){
1492 //put in red if c>d
1493 $red=" notice ";
1494 }
1495 $r.='<TD class="'.$red.'" sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."$side </TD>";
1496 $deb=bcadd($deb,$amount['debit']);
1497 $cred=bcadd($cred,$amount['credit']);
1498
1499 $r.="</TR>";
1500
1501 }
1502 $r.="<tfoot >";
1503 $solde=abs(bcsub($deb,$cred));
1504 $side=($deb > $cred)?'Débit':'Crédit';
1505 $r.='<tr class="highlight">';
1506 $r.=td("").td("").td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td(" $side ".nbm($solde),'class="num"');
1507 $r.='</tr>';
1508 $r.="</tfoot>";
1509 $r.="</TABLE>";
1510 $r.=$bar;
1511
1512 return $r;
1513 }
1514 /*!
1515 * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
1516 */
1517 function get_categorie()
1518 {
1519 if ( $this->id == 0 ) throw new Exception('class_fiche : f_id = 0 ');
1520 $sql='select fd_id from fiche where f_id=$1';
1521 $R=$this->cn->get_value($sql, array($this->id));
1522 if ( $R == "" )
1523 $this->fiche_def=0;
1524 else
1525 $this->fiche_def=$R;
1526 return $this->fiche_def;
1527 }
1528 /*!
1529 * \brief Check if a card can be used and then belong tp a specific ledger, it the card
1530 *
1531 * return 1 if the fiche is in the range otherwise 0, the quick_code
1532 * or the id must be set
1533 *
1534 *
1535 * \param $jrn_def_id journal_id (JRN.JRN_DEF_ID)
1536 * \param $side : deb or cred , default empty = both
1537 *
1538 * \return 1 if the card belongs to the ledger,
1539 * 0 the card doesn't belong,
1540 * -1 the card doesn't exist,
1541 * -2 the ledger has no card to check,
1542 * -3 there is no category of card for this ledger
1543 *
1544 */
1545 function belong_ledger($jrn_def_id,$side="")
1546 {
1547 // check if we have a quick_code or a f_id
1548 if (($this->quick_code==null || $this->quick_code == "" )
1549 && $this->id == 0 )
1550 {
1551 throw new Exception( 'erreur ni quick_code ni f_id ne sont donnes');
1552 }
1553
1554 //retrieve the quick_code
1555 if ($this->quick_code == "") {
1556 $this->quick_code = $this->get_quick_code();
1557 }
1558
1559
1560 if ($this->quick_code == null) {
1561 return -1;
1562 }
1563
1564 if ($this->id == 0 && $this->get_by_qcode(null, false) == 1) {
1565 return -1;
1566 }
1567
1568 if ( $side == 'deb' )
1569 {
1570 $Res=$this->cn->exec_sql("select jrn_def_fiche_deb as fiche from jrn_def where jrn_def_id=$1",[$jrn_def_id]);
1571 }elseif ( $side == 'cred' )
1572 {
1573 $Res=$this->cn->exec_sql("select jrn_def_fiche_cred as fiche from jrn_def where jrn_def_id=$1",[$jrn_def_id]);
1574 }
1575 else
1576 {
1577 // Get all the fiche type (deb and cred)
1578 $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
1579 from jrn_def where jrn_def_id=$1
1580 union
1581 select jrn_def_fiche_deb
1582 from jrn_def where jrn_def_id=$1",
1583 [$jrn_def_id]
1584 );
1585 }
1586 if ( Database::num_row($Res)==0)
1587 {
1588 return -2;
1589 }
1590 /* convert the array to a string */
1592 $str_list="";
1593 $comma='';
1594 foreach ($list as $row)
1595 {
1596 if ( $row['fiche'] != '' )
1597 {
1598 $str_list.=$comma.$row['fiche'];
1599 $comma=',';
1600 }
1601 }
1602 // Normally Max must be == 1
1603
1604 if ( $str_list=="")
1605 {
1606 return -3;
1607 }
1608
1609 $sql="select *
1610 from fiche
1611 where
1612 fd_id in (".$str_list.") and f_id= ".$this->id;
1613
1614 $Res=$this->cn->exec_sql($sql);
1615 if (Database::num_row($Res) == 0) {
1616 return 0;
1617 }
1618 return 1;
1619
1620 }
1621 /*!
1622 * \brief get all the card from a categorie
1623 *\param $p_cn database connx
1624 *\param $card_category_id is the category id
1625 *\param $p_order for the sort, possible values is name_asc,name_desc or nothing
1626 * \param $inactive int possible values : 1 = inactive included, 0 = only active ones (default 1)
1627 *\return an array of card, but only the fiche->id is set
1628 */
1629 static function get_fiche_def($p_cn,$card_category_id,$p_order='',$inactive=1)
1630 {
1631 // var $cond_active string SQL cond for filtering active or not
1632 $cond_active=($inactive == 1)?"":" and f_enable='1' ";
1633
1634 switch ($p_order)
1635 {
1636 case 'name_asc':
1637 $sql="select f_id,ad_value from fiche join fiche_detail using (f_id)
1638 where
1639 ad_id=1
1640 and fd_id=$1
1641 $cond_active
1642 order by 2 asc";
1643 break;
1644 case 'name_desc':
1645 $sql="select f_id,ad_value from fiche join fiche_detail using (f_id)
1646 where ad_id=1
1647 and fd_id=$1
1648 $cond_active
1649 order by 2 desc";
1650 break;
1651 default:
1652 $sql="select f_id from fiche where fd_id=$1 $cond_active ";
1653 }
1654 $array=$p_cn->get_array($sql,array($card_category_id));
1655
1656 return $array;
1657 }
1658 /*!\brief check if a card is used
1659 *\return return true is a card is used otherwise false
1660 */
1661 function is_used()
1662 {
1663 /* retrieve first the quickcode */
1665 $sql='select count(*) as c from jrnx where j_qcode=$1';
1666 $count=$this->cn->get_value($sql,array($qcode));
1667 if ( $count > 0 ) return TRUE;
1668 $count=$this->cn->get_value("select count(*) from action_gestion where f_id_dest=$1 or ag_contact=$1 ",
1669 [$this->id]);
1670 if ( $count > 0 ) return TRUE;
1671 $count=$this->cn->get_value("select count(*) from action_person where f_id=$1 ",
1672 [$this->id]);
1673 if ( $count > 0 ) return TRUE;
1674
1675 $count=$this->cn->get_value("
1676 select count(*)
1677 from attr_def
1678 join fiche_detail using (ad_id)
1679 where ad_type='card'
1680 and ad_value=$1"
1681 ,[$qcode]);
1682
1683 if ( $count > 0 ) return TRUE;
1684
1685 return FALSE;
1686
1687 }
1688 /*\brief remove a card without verification */
1689 function delete()
1690 {
1691 $this->cn->start();
1692
1693 // Remove from attr_value
1694 $Res=$this->cn->exec_sql("delete from fiche_detail
1695 where
1696 f_id= $1",[ $this->id] );
1697
1698 // Remove from fiche
1699 $Res=$this->cn->exec_sql("delete from fiche where f_id=$1",[$this->id]);
1700
1701 $this->cn->commit();
1702
1703
1704 }
1705 /*!\brief create the sql statement for retrieving all
1706 * the card
1707 *\return string with sql statement
1708 *\param $array contains the condition
1709 \verbatim
1710 [jrn] => 2
1711 [typecard] => cred / deb / filter or list
1712 [query] => string
1713 \endverbatim
1714 *\note the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
1715 *\see ajax_card.php cards.js
1716 */
1718 {
1719 if (!empty($array))
1720 extract($array, EXTR_SKIP);
1721 $and='';
1722 $filter_fd_id='true';
1723 $filter_query='';
1724 if (isset($typecard))
1725 {
1726 if (strpos($typecard, "sql")==false)
1727 {
1728 switch ($typecard)
1729 {
1730 case 'cred':
1731 if (!isset($jrn))
1732 throw Exception('Erreur pas de valeur pour jrn');
1733 $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
1734 array($jrn));
1735 $filter_fd_id=(empty($filter_jrn))?" fd_id in (-1) ":" fd_id in (".$filter_jrn.")";
1736 $and=" and ";
1737 break;
1738 case 'deb':
1739 if (!isset($jrn))
1740 throw Exception('Erreur pas de valeur pour jrn');
1741 $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
1742 array($jrn));
1743 $filter_fd_id=(empty($filter_jrn))?"fd_id in (-1) ":" fd_id in (".$filter_jrn.")";
1744 $and=" and ";
1745 break;
1746 case 'filter':
1747 if (!isset($jrn))
1748 throw Exception('Erreur pas de valeur pour jrn');
1749 $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
1750 array($jrn));
1751
1752 if (noalyss_trim($filter_jrn)!='')
1753 $fp1=" fd_id in (".$filter_jrn.")";
1754 else
1755 $fp1="fd_id < 0";
1756
1757 $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
1758 array($jrn));
1759
1760 if (noalyss_trim($filter_jrn)!='')
1761 $fp2=" fd_id in (".$filter_jrn.")";
1762 else
1763 $fp2="fd_id < 0";
1764
1765 $filter_fd_id='('.$fp1.' or '.$fp2.')';
1766
1767 $and=" and ";
1768 break;
1769 case 'all':
1770 $filter_fd_id=' true';
1771 break;
1772 default:
1773 if (noalyss_trim($typecard)!='')
1774 $filter_fd_id=' fd_id in ('.$typecard.')';
1775 else
1776 $filter_fd_id=' fd_id < 0';
1777 }
1778 }
1779 else
1780 {
1781 $filter_fd_id=noalyss_str_replace('[sql]', '', $typecard);
1782 }
1783 }
1784
1785 $and=" and ";
1786 if (isset($query))
1787 {
1789
1791 {
1793 $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') "
1794 ." or vw_description ilike '%$query%' or tva_num ilike '%$query%' or accounting like upper('$query%'))";
1795 }
1796 else
1797 {
1798 $filter_query='';
1799 }
1800 }
1801 $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
1802 return $sql;
1803 }
1804
1805 /**
1806 *@brief move a card to another cat. The properties will changed
1807 * and be removed
1808 *@param $p_fdid the fd_id of destination
1809 */
1810 function move_to($p_fdid)
1811 {
1812 $this->cn->start();
1813 $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
1814 // add missing
1815 $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
1816 // add to the destination missing fields
1817 $this->cn->exec_sql("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) select $1,ad_id,100 from fiche_detail where f_id=$2 and ad_id not in (select ad_id from jnt_fic_attr where fd_id=$3)",array($p_fdid,$this->id,$p_fdid));
1818 $this->cn->commit();
1819 }
1820 /**
1821 * @brief return the letter C if amount is > 0, D if < 0 or =
1822 * @param type $p_amount
1823 * @return string
1824 */
1825 function get_amount_side($p_amount)
1826 {
1827 if ($p_amount == 0)
1828 return "";
1829 if ($p_amount < 0)
1830 return "C";
1831 if ($p_amount > 0)
1832 return "D";
1833 }
1834 static function test_me()
1835 {
1836 $cn=Dossier::connect();
1837 $http=new HttpInput();
1838 echo h1('Test select category');
1839 $a=new Fiche($cn);
1840 $select_cat=new ISelect('fd_id');
1841 $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
1843 echo '<FORM METHOD="GET"> ';
1844 echo dossier::hidden();
1845 echo HtmlInput::hidden('test_select',$http->get('test_select',"string",1));
1846 echo 'Choix de la catégorie';
1847 echo $select_cat->input();
1848 echo HtmlInput::submit('go_card','Afficher');
1849 echo '</form>';
1850 if ( isset ($_GET['go_card']))
1851 {
1852 $empty=$a->to_array($_GET['fd_id']);
1853 print_r($empty);
1854 }
1855 // testing insert
1856 echo h1("Insert new card");
1857 $name="test ".microtime();
1858 $fiche=new Fiche($cn);
1859 $fiche_def=new Fiche_Def($cn,1);
1860 $fiche_def->get();
1861
1862 $fiche->set_fiche_def($fiche_def->id);
1863
1864 $fiche->set_attribute(ATTR_DEF_NAME,$name);
1865 $fiche->set_attribute(ATTR_DEF_ACCOUNT,$fiche_def->class_base.$name);
1866
1867 echo p(print_r($fiche->to_array(),false));
1868 $fiche->insert(1,$fiche->to_array());
1869 assert($name == $fiche->get_attribute(ATTR_DEF_NAME));
1870
1871 echo p("fiche ATTR_DEF_ACCOUNT after insert ",$fiche->get_attribute(ATTR_DEF_ACCOUNT));
1872 $accounting=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
1873 $acc_accounting=new Acc_Account($cn,$accounting);
1874
1875 echo p("accounting id",$acc_accounting->get_parameter("id"));
1876 assert($acc_accounting->get_lib("pcm_lib") == $name,"Cannot create a new accouting with
1877 the right label");
1878 }
1879
1881 {
1882 $r = "<h2 id=\"gestion_title\">" . h($this->getName()) . " " . h($this->get_attribute(ATTR_DEF_FIRST_NAME,0)) . '[' . $this->get_quick_code() . ']</h2>';
1883 return $r;
1884 }
1886 {
1887
1888 }
1889 /**
1890 * @brief Return a string with the HTML code to display a button to export the
1891 * history in CSV
1892 * @param type $p_from from date (DD.MM.YYYY)
1893 * @param type $p_to to date (DD.MM.YYYY)
1894 * @return HTML string
1895 */
1896 function button_csv($p_from,$p_to) {
1897 $href="export.php?".http_build_query(
1898 array(
1899 "gDossier"=>Dossier::id(),
1900 "f_id"=>$this->id,
1901 "ople"=>0,
1902 "type"=>"poste",
1903 "from_periode"=>$p_from,
1904 "to_periode"=>$p_to,
1905 "act"=>"CSV:fichedetail"
1906 )
1907 );
1908 return '<a class="smallbutton" style="display:inline-block" href="'.$href.'">'._("Export CSV").'</a>';
1909
1910 }
1911 /**
1912 * @brief Return a string with the HTML code to display a button to export the
1913 * history in PDF
1914 * @param type $p_from from date (DD.MM.YYYY)
1915 * @param type $p_to to date (DD.MM.YYYY)
1916 * @return HTML string
1917 */
1918 function button_pdf($p_from,$p_to) {
1919 $href="export.php?".http_build_query(
1920 array(
1921 "gDossier"=>Dossier::id(),
1922 "f_id"=>$this->id,
1923 "ople"=>0,
1924 "type"=>"poste",
1925 "from_periode"=>$p_from,
1926 "to_periode"=>$p_to,
1927 "act"=>"PDF:fichedetail"
1928 )
1929 );
1930 return '<a class="smallbutton" style="display:inline-block" href="'.$href.'">'._("Export PDF").'</a>';
1931
1932 }
1933 /**
1934 * @brief Filter in javascript the table with the history
1935 * @param type $p_table_id id of the table containting the data to filter
1936 * @return html string
1937 */
1938
1939 function filter_history($p_table_id) {
1940 return _('Cherche').' '.HtmlInput::filter_table($p_table_id, '0,1,2,3,4,5,6,7,8,9,10', 1);
1941 }
1942 /**
1943 * Returns the Acc_Ledger_Fin ledger for which the card is the default bank account or null if no ledger is found.
1944 */
1946 {
1947 try {
1948 $id=$this->cn->get_value("select jrn_def_id from jrn_def where jrn_def_bank = $1 ",[$this->id]);
1949 if ($id == "") { return NULL;}
1950 $ledger=new Acc_Ledger_Fin($this->cn,$id);
1951 $ledger->load();
1952 return $ledger;
1953 }
1954 catch (Exception $e) {
1955 record_log(__FILE__.":".__LINE__);
1956 record_log($e->getMessage());
1957 throw $e;
1958 }
1959 }
1960 /**
1961 * @brief display card as a table row , the tag TR must be added
1962 *
1963 * @return HTML string starting
1964 *
1965 */
1966 function display_row()
1967 {
1968 $this->load_attribute();
1969 foreach($this->attribut as $attr) {
1970 $sort="";
1971
1972 if ($attr->ad_type!='select')
1973 {
1974
1975 if ($attr->ad_type=="date") {
1976 // format YYYYMMDD
1977 $sort='sorttable_customkey="'.format_date($attr->av_text, "DD.MM.YYYY", "YYYYMMDD").'"';
1978 }
1979 elseif ($attr->ad_type=="poste"){
1980 $sort='sorttable_customkey="TEXT'.$attr->av_text.'"';
1981 }
1982 echo td($attr->av_text, 'style="padding: 0 10 1 10;white-space:nowrap;" '.$sort);
1983 }
1984 else {
1985 $value=$this->cn->make_array($attr->ad_extra);
1986 $row_content="";
1987 for ($e=0; $e<count($value); $e++) {
1988 if ( $value[$e]['value']==$attr->av_text) {
1989 $row_content=h($value[$e]['label']);
1990 break;
1991 }
1992 }
1993 echo td($row_content, 'style="padding: 0 10 1 10;white-space:nowrap;"');
1994
1995 }
1996 }
1997
1998 }
1999 /**
2000 * @brief create a card from a qcode and returns a card
2001 * @param $cn Database cnx
2002 * @param $p_qcode (string) qcode of the card
2003 */
2004 static function from_qcode(Database $cn,string $p_qcode)
2005 {
2006 $card=new Fiche($cn);
2007 $card->get_by_qcode($p_qcode);
2008 return $card;
2009 }
2010}
2011
2012?>
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
isNumber($p_int)
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
noalyss_strlentrim($p_string)
p($p_string, $p_extra='')
Definition ac_common.php:39
h1($p_string, $p_class="")
Definition ac_common.php:72
noalyss_str_replace($search, $replace, $string)
echo_error($p_log, $p_line="", $p_message="")
log error into the /tmp/noalyss_error.log it doesn't work on windows
tr($p_string, $p_extra='')
Definition ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
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.
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
noalyss_trim($p_string)
alert($p_msg, $buffer=false)
alert in javascript
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'])
$from_div
$_REQUEST['ac']
if(trim($query)==''|| $filter=='') $search
if(isset( $_REQUEST[ 'show'])) if(isset($_REQUEST['del'])) $ac
$input_from cn
$select_cat
_("actif, passif,charge,...")
if(! isset($_GET['submit_query'])) $p_action
$_GET['qcode']
$fiche_def
$class
Display the Plugin and for each profile were it is installed or not.
Manage the account from the table jrn, jrnx or tmp_pcmn.
Manage the account from the table tmp_pcmn.
the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
Manage the table parm_code which contains the custom parameter for the module accountancy.
static update(Fiche $p_fiche)
update all the data of the card , including f_enable. if we are in a transaction we don't commit here...
static load(Fiche $fiche)
Load all the attribute of a card , it modifies the parameter $fiche.
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
contains the class for connecting to Noalyss
define Class fiche and fiche def, those class are using class attribut
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
button_pdf($p_from, $p_to)
Return a string with the HTML code to display a button to export the history in PDF.
strAttribut($p_ad_id, $p_return=1)
use get_attribute instead
empty_attribute($p_attr)
check if an attribute is empty
get_row_date($p_from, $p_to, $op_let=0)
Get data for poste.
is_used()
check if a card is used
HtmlTableDetail($p_array=null, $op_let=0)
HtmlTable, display a HTML of a card for the asked period.
display_row()
display card as a table row , the tag TR must be added
static from_qcode(Database $cn, string $p_qcode)
create a card from a qcode and returns a card
$ledger_description
!< this variable is a mistake, it shouldn't exist, need code rewrite
insert($p_fiche_def, $p_array=null, $transaction=true)
insert a new record thanks an array , either as parameter or $_POST
get_categorie()
get the fd_id of the card : fd_id, it set the attribute fd_id
belong_ledger($jrn_def_id, $side="")
Check if a card can be used and then belong tp a specific ledger, it the card.
filter_history($p_table_id)
Filter in javascript the table with the history.
HtmlTable($p_array=null, $op_let=0, $from_div=1)
HtmlTable, display a HTML of a card for the asked period.
static cmp_name(Fiche $o1, Fiche $o2)
used with a usort function, to sort an array of Fiche on the name
update($p_array=null)
update a card with an array
get_row($p_from, $p_to)
Get data for poste.
__construct($p_cn, $p_id=0)
!< this variable is a mistake, it shouldn't exist, need code rewrite
move_to($p_fdid)
move a card to another cat.
set_fiche_def_ref($fiche_def_ref)
seek($p_attribut, $p_value)
find the card with the p_attribut equal to p_value, it is not case sensitive
static test_me()
static get_fiche_def($p_cn, $card_category_id, $p_order='', $inactive=1)
get all the card from a categorie
button_csv($p_from, $p_to)
Return a string with the HTML code to display a button to export the history in CSV.
set_attribute($p_ad_id, $p_value)
set an attribute by a value, if the attribut array is empty a call to load_attribute is performed
get_bank_ledger()
Returns the Acc_Ledger_Fin ledger for which the card is the default bank account or null if no ledger...
HtmlTableHeader($p_array=null)
Display HTML Table Header (button)
Get()
Synonum of fiche::load_attribute.
getDisplayMode()
Display($p_readonly, $p_in="")
Display object instance, getAttribute sort the attribute and add missing ones.
get_bk_account()
get the available bank_account filtered by the security
save($p_fiche_def=0)
Save a card, call insert or update.
get_row_result_deprecated($res)
fetch and return and array
get_amount_side($p_amount)
return the letter C if amount is > 0, D if < 0 or =
set_id($id)
count_by_modele($p_frd_id, $p_search="", $p_sql="")
Count the nb of card with the reference card id frd_id.
get_by_category($p_offset=-1, $p_search="", $p_order='')
get all the card thanks the fiche_def_ref
build_sql($array)
create the sql statement for retrieving all the card
get_gestion_title()
get_by_qcode($p_qcode=null, $p_all=true)
Retrieve a card thx his quick_code complete the object,, set the id member of the object or set it to...
Summary($p_search="", $p_action="", $p_sql="", $p_amount=false)
show the default screen
get_fiche_def_ref_id()
retrieve the frd_id of the fiche it is the type of the card (bank, purchase...) (fiche_def_ref primar...
get_quick_code()
return the quick_code of a card
get_all_account()
setAttribut($p_ad_id, $p_value)
replace by set_attribute
set_f_enable($f_enable)
get_bk_balance_currency($p_cond="")
Get the sum in Currency.
GetByDef($p_frd_id, $p_offset=-1, $p_search="", $p_order='')
Return array of card from the frd family deprecated , use insert get_by_category_id.
getAttribut()
replace by load_attribute
load()
Synonum of fiche::load_attribute.
setDisplayMode($p_mode)
how the card is display : either in a window or a greated container
blank($p_fiche_def)
insert a new record show a blank card to be filled
get_attribute($p_ad_id, $p_return=1)
return the string of the given attribute (attr_def.ad_id)
set_fiche_def($p_fiche_def)
load_attribute()
get all the attribute of a card, add missing ones and sort the array ($this->attribut) by ad_id
get_f_enable()
getName()
return the name of a card
get_solde_detail($p_cond="")
give the balance of an card
to_array()
turn a card into an array , then it can be saved thanks update or insert
getLabelCategory()
get_bk_balance($p_cond="")
get the bank balance with receipt or not in Euro
get_fiche_def_ref()
manage the http input (get , post, request) and extract from an array
Html Input.
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
show a switch, when you click on it an hidden field is changed, the value is 1 or 0
$t
Definition compute.php:46
const EXC_INVALID
Definition constant.php:358
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition constant.php:135
const ATTR_DEF_ADRESS
Definition constant.php:230
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_COUNTRY
Definition constant.php:232
const ATTR_DEF_WEBSITE
Definition constant.php:246
const ATTR_DEF_BQ_NO
Definition constant.php:224
const ATTR_DEF_POSTCODE
Definition constant.php:231
const FICHE_TYPE_CLIENT
Definition constant.php:259
const ATTR_DEF_FIRST_NAME
Definition constant.php:245
const ATTR_DEF_QUICKCODE
Definition constant.php:244
const ATTR_DEF_ACCOUNT
Definition constant.php:222
$_POST['ac']
Definition do.php:323
$count
foreach( $Fiche->row as $op) $solde_type
if(count($array)==0) $acc_account_ledger
$typecard
Definition fid_card.php:62
catch(\Exception $e) $bar
if( $delta< 0) elseif( $delta==0)
$side
$table
Definition menu.inc.php:104
$script
Definition popup.php:131
for($i=0;$i< count($aHeading);$i++) $sort
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
for($i=0;$i< $nb_jrn;$i++) $deb