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