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