noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_fiche.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 include_once("class/class_fiche_attr.php");
24 require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
25 require_once NOALYSS_INCLUDE.'/lib/class_itva_popup.php';
26 require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
28 require_once NOALYSS_INCLUDE.'/class/class_fiche_def.php';
29 require_once NOALYSS_INCLUDE.'/lib/class_iposte.php';
30 
31 /*! \file
32  * \brief define Class fiche, this class are using
33  * class attribut
34  */
35 /*!
36  * \brief define Class fiche and fiche def, those class are using
37  * class attribut. When adding or modifing new card in a IPOPUP
38  * the ipopup for the accounting item is ipop_account
39  */
40 
41 //-----------------------------------------------------
42 // class fiche
43 //-----------------------------------------------------
44 class Fiche
45 {
46  var $cn; /*! < $cn database connection */
47  var $id; /*! < $id fiche.f_id */
48  var $fiche_def; /*! < $fiche_def fd_id */
49  var $attribut; /*! < $attribut array of attribut object */
50  var $fiche_def_ref; /*!< $fiche_def_ref Type */
51  var $row; /*! < All the row from the ledgers */
52  var $quick_code; /*!< quick_code of the card */
53  function __construct($p_cn,$p_id=0)
54  {
55  $this->cn=$p_cn;
56  $this->id=$p_id;
57  $this->quick_code='';
58  }
59  /**
60  *@brief used with a usort function, to sort an array of Fiche on the name
61  */
62  static function cmp_name(Fiche $o1,Fiche $o2)
63  {
64  return strcmp($o1->strAttribut(ATTR_DEF_NAME),$o2->strAttribut(ATTR_DEF_NAME));
65  }
66 
67  /**
68  *@brief get the available bank_account filtered by the security
69  *@return array of card
70  */
71  function get_bk_account()
72  {
73  global $g_user;
74  $sql_ledger=$g_user->get_ledger_sql('FIN',3);
75  $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
76  . "jrn_def_bank,jrn_def_description from jrn_def where jrn_def_type='FIN' and $sql_ledger
77  order by jrn_def_name");
78 
79  if ( count($avail) == 0 )
80  return null;
81 
82  for ($i=0;$i<count($avail);$i++)
83  {
84  $t=new Fiche($this->cn,$avail[$i]['jrn_def_bank']);
85  $t->ledger_name=$avail[$i]['jrn_def_name'];
86  $t->ledger_description=$avail[$i]['jrn_def_description'];
87  $t->getAttribut();
88  $all[$i]=$t;
89 
90  }
91  return $all;
92  }
93 
94 
95  /*! get_by_qcode($p_qcode)
96  * \brief Retrieve a card thx his quick_code
97  * complete the object,, set the id member of the object or set it
98  * to 0 if no card is found
99  * \param $p_qcode quick_code (ad_id=23)
100  * \param $p_all retrieve all the attribut of the card, possible value
101  * are true or false. false retrieves only the f_id. By default true
102  * \return 0 success 1 error not found
103  */
104  function get_by_qcode($p_qcode=null,$p_all=true)
105  {
106  if ( $p_qcode == null )
107  $p_qcode=$this->quick_code;
108  $p_qcode=trim($p_qcode);
109  $sql="select f_id from fiche_detail
110  where ad_id=23 and ad_value=upper($1)";
111  $this->id=$this->cn->get_value($sql,array($p_qcode));
112  if ( $this->cn->count()==0)
113  {
114  $this->id=0;
115  return 1;
116  }
117 
118 
119  if ( $p_all )
120  $this->getAttribut();
121  return 0;
122  }
123  /**
124  *@brief set an attribute by a value, if the attribut array is empty
125  * a call to getAttribut is performed
126  *@param the AD_ID
127  *@param the value
128  *@see constant.php table: attr_def
129  */
130  function setAttribut($p_ad_id,$p_value)
131  {
132  if ( sizeof($this->attribut)==0 ) $this->getAttribut();
133  for ($e=0;$e <sizeof($this->attribut);$e++)
134  {
135  if ( $this->attribut[$e]->ad_id == $p_ad_id )
136  {
137  $this->attribut[$e]->av_text=$p_value;
138  break;
139  }
140  }
141  }
142  /**
143  *\brief get all the attribute of a card, add missing ones
144  * and sort the array ($this->attribut) by ad_id
145  */
146  function getAttribut()
147  {
148  if ( $this->id == 0)
149  {
150  return;
151  }
152  $sql="select *
153  from
154  fiche
155  natural join fiche_detail
156  join jnt_fic_attr on (jnt_fic_attr.fd_id=fiche.fd_id and fiche_detail.ad_id=jnt_fic_attr.ad_id)
157  join attr_def on (attr_def.ad_id=fiche_detail.ad_id) where f_id=".$this->id.
158  " order by jnt_order";
159 
160  $Ret=$this->cn->exec_sql($sql);
161  if ( ($Max=Database::num_row($Ret)) == 0 )
162  return ;
163  for ($i=0;$i<$Max;$i++)
164  {
166  $this->fiche_def=$row['fd_id'];
167  $t=new Fiche_Attr ($this->cn);
168  $t->ad_id=$row['ad_id'];
169  $t->ad_text=$row['ad_text'];
170  $t->av_text=$row['ad_value'];
171  $t->ad_type=$row['ad_type'];
172  $t->ad_size=$row['ad_size'];
173  $t->ad_extra=$row['ad_extra'];
174  $t->jnt_order=$row['jnt_order'];
175  $this->attribut[$i]=$t;
176  }
177  $e=new Fiche_Def($this->cn,$this->fiche_def);
178  $e->GetAttribut();
179 
180  if ( sizeof($this->attribut) != sizeof($e->attribut ) )
181  {
182 
183  /*
184  * !! Missing attribute
185  */
186  foreach ($e->attribut as $f )
187  {
188  $flag=0;
189  foreach ($this->attribut as $g )
190  {
191  if ( $g->ad_id == $f->ad_id )
192  $flag=1;
193  }
194  if ( $flag == 0 )
195  {
196  // there's a missing one, we insert it
197  $t=new Fiche_Attr ($f->ad_id);
198  $t->av_text="";
199  $t->ad_text=$f->ad_text;
200  $t->jnt_order=$f->jnt_order;
201  $t->ad_type=$f->ad_type;
202  $t->ad_size=$f->ad_size;
203  $t->ad_id=$f->ad_id;
204  $t->ad_extra=$f->ad_extra;
205  $this->attribut[$Max]=$t;
206  $Max++;
207  } // if flag == 0
208 
209  }// foreach
210 
211 
212  }//missing attribut
213  }
214  /**
215  * @brief find the card with the p_attribut equal to p_value, it is not case sensitive
216  * @param $p_attribut attribute to find see table attr_def
217  * @param $p_value value in attr_value.av_text
218  * @return return ARRAY OF jft_id,f_id,fd_id,ad_id,av_text
219  */
220  function seek($p_attribut,$p_value)
221  {
222  $sql="select jft_id,f_id,fd_id,ad_id,ad_value from fiche join fiche_detail using (f_id)
223  where ad_id=$1 and upper(ad_value)=upper($2)";
224  $res=$this->cn->get_array($sql,array($p_attribut,$p_value));
225  return $res;
226  }
227 
228  /*!
229  * \brief give the size of a card object
230  *
231  * \return size
232  */
233  function size()
234  {
235  if ( isset ($this->ad_id))
236  return sizeof($this->ad_id);
237  else
238  return 0;
239  }
240 
241 
242  /*!
243  **************************************************
244  * \brief Return array of card from the frd family
245  *
246  * \param $p_frd_id the fiche_def_ref.frd_id
247  * \param $p_search p_search is a filter on the name
248  * \param $p_sql extra sql condition
249  *
250  * \return array of fiche object
251  */
252  function count_by_modele($p_frd_id,$p_search="",$p_sql="")
253  {
254  $sql="select *
255  from
256  fiche join fiche_Def using (fd_id)
257  where frd_id=".$p_frd_id;
258  if ( $p_search != "" )
259  {
260  $a=sql_string($p_search);
261  $sql="select * from vw_fiche_attr where frd_id=".$p_frd_id.
262  " and vw_name ~* '$p_search'";
263  }
264 
265  $Ret=$this->cn->exec_sql($sql.$p_sql);
266 
267  return Database::num_row($Ret) ;
268  }
269  /*!
270  **************************************************
271  * \brief Return array of card from the frd family
272  *
273  *
274  * \param $p_frd_id the fiche_def_ref.frd_id
275  * \param $p_offset
276  * \param $p_search is an optional filter
277  *\param $p_order : possible values are name, f_id
278  * \return array of fiche object
279  */
280  function GetByDef($p_frd_id,$p_offset=-1,$p_search="",$p_order='')
281  {
282  switch($p_order)
283  {
284  case 'name' :
285  $order=' order by name';
286  break;
287  case 'f_id':
288  $order='order by f_id';
289  break;
290  default:
291  $order='';
292  }
293  if ( $p_offset == -1 )
294  {
295  $sql="select *
296  from
297  fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
298  where frd_id=".$p_frd_id." $p_search ".$order;
299  }
300  else
301  {
302  $limit=($_SESSION['g_pagesize']!=-1)?"limit ".$_SESSION['g_pagesize']:"";
303  $sql="select *
304  from
305  fiche join fiche_Def using (fd_id) join vw_fiche_name using(f_id)
306  where frd_id=".$p_frd_id." $p_search $order "
307  .$limit." offset ".$p_offset;
308 
309  }
310 
311  $Ret=$this->cn->exec_sql($sql);
312  if ( ($Max=Database::num_row($Ret)) == 0 )
313  return ;
314  $all[0]=new Fiche($this->cn);
315 
316  for ($i=0;$i<$Max;$i++)
317  {
319  $t=new Fiche($this->cn,$row['f_id']);
320  $t->getAttribut();
321  $all[$i]=clone $t;
322 
323  }
324  return $all;
325  }
326  function ShowTable()
327  {
328  echo "<TR><TD> ".
329  $this->id."</TD>".
330  "<TR> <TD>".
331  $this->attribut_value."</TD>".
332  "<TR> <TD>".
333  $this->attribut_def."</TD></TR>";
334  }
335  /***
336  * @brief return the string of the given attribute
337  * (attr_def.ad_id)
338  * @param $p_ad_id the AD_ID from attr_def.ad_id
339  * @param $p_return 1 return NOTFOUND otherwise an empty string
340  * @see constant.php
341  * @return string
342  */
343  function strAttribut($p_ad_id,$p_return=1)
344  {
345  $return=($p_return==1)?NOTFOUND:"";
346  if ( sizeof ($this->attribut) == 0 )
347  {
348 
349  if ($this->id==0) {
350  return $return;
351  }
352  // object is not in memory we need to look into the database
353  $sql="select ad_value from fiche_detail
354  where f_id= $1 and ad_id= $2 ";
355  $Res=$this->cn->exec_sql($sql,array($this->id,$p_ad_id));
357  // if not found return error
358  if ( $row == false )
359  return $return;
360 
361  return $row[0]['ad_value'];
362  }
363 
364  foreach ($this->attribut as $e)
365  {
366  if ( $e->ad_id == $p_ad_id )
367  return $e->av_text;
368  }
369  return $return;
370  }
371  /**
372  * @brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
373  *The array can be used with the function insert, it will return a struct like this :
374  * in the first key (av_textX), X is the ATTR_DEF::AD_ID
375  \verbatim
376  Example
377  Array
378  (
379  [av_text1] => Nom
380  [av_text12] => Personne de contact
381  [av_text5] => Poste Comptable
382  [av_text13] => numéro de tva
383  [av_text14] => Adresse
384  [av_text15] => code postal
385  [av_text24] => Ville
386  [av_text16] => pays
387  [av_text17] => téléphone
388  [av_text18] => email
389  [av_text23] => Quick Code
390  )
391 
392  \endverbatim
393  *\param $pfd_id FICHE_DEF::FD_ID
394  *\return an array of attribute
395  *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
396  *\see fiche::insert()
397  */
398  function to_array($pfd_id)
399  {
400  $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
401  " ad_text ".
402  " from fiche_def join jnt_fic_attr using (fd_id)".
403  " join attr_def using (ad_id) ".
404  " where fd_id=$1 order by jnt_order";
405  $ret=$this->cn->get_array($sql,array($pfd_id));
406  if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$pfd_id,1);
407  $array=array();
408  foreach($ret as $idx=>$val)
409  {
410  $a=str_replace(' ','',$val['key']);
411  $array[$a]=$val['ad_text'];
412  }
413  return $array;
414 
415  }
416  /*!
417  * \brief insert a new record
418  * show a blank card to be filled
419  *
420  * \param $p_fiche_def is the fiche_def.fd_id
421  *
422  * \return HTML Code
423  */
424  function blank($p_fiche_def)
425  {
426  // array = array of attribute object sorted on ad_id
427  $f=new Fiche_Def($this->cn,$p_fiche_def);
428  $f->get();
429  $array=$f->getAttribut();
430  $r=h2(_('Catégorie').' '.$f->label,"");
431  $r.='<table style="width:98%;margin:1%">';
432  foreach ($array as $attr)
433  {
434  $table=0;
435  $msg="";$bulle='';
436  if ( $attr->ad_id == ATTR_DEF_ACCOUNT)
437  {
438  $w=new IPoste("av_text".$attr->ad_id);
439  $w->set_attribute('ipopup','ipop_account');
440  $w->set_attribute('account',"av_text".$attr->ad_id);
441  $w->dbl_click_history();
442  // account created automatically
443  $sql="select account_auto($p_fiche_def)";
444  $ret_sql=$this->cn->exec_sql($sql);
445  $a=Database::fetch_array($ret_sql,0);
446  $label=new ISpan();
447  $label->name="av_text".$attr->ad_id."_label";
448 
449  if ( $a['account_auto'] == 't' )
450  $msg.=$label->input()." <span style=\"color:red\">".
451  _("Rappel: Poste créé automatiquement à partir de ")
452  .$f->class_base." </span> ";
453  else
454  {
455  // if there is a class base in fiche_def_ref, this account will be the
456  // the default one
457  if ( strlen(trim($f->class_base)) != 0 )
458  {
459  $msg.="<TD>".$label->input()." <span style=\"color:red\">"._("Rappel: Poste par défaut sera ").
460  $f->class_base.
461  " !</span> ";
462  $w->value=$f->class_base;
463  }
464 
465  }
466  $r.="<TR>".td(_("Poste Comptable"),' class="input_text" ' ).td($w->input().$msg)."</TR>";
467  continue;
468  }
469  elseif ( $attr->ad_id == ATTR_DEF_TVA)
470  {
471  $w=new ITva_Popup('popup_tva');
472  $w->table=1;
473  }
474 
475  else
476  {
477  switch ($attr->ad_type)
478  {
479  case 'text':
480  $w = new IText();
481  $w->css_size = "100%";
482  break;
483  case 'numeric':
484  $w = new INum();
485  $w->prec=($attr->ad_extra=="")?2:$attr->ad_extra;
486  $w->size = $attr->ad_size;
487  break;
488  case 'date':
489  $w = new IDate();
490  break;
491  case 'zone':
492  $w = new ITextArea();
493  $w->style=' class="itextarea" style="margin:0px;width:100%"';
494  break;
495  case 'poste':
496  $w = new IPoste("av_text" . $attr->ad_id);
497  $w->set_attribute('ipopup', 'ipop_account');
498  $w->set_attribute('account', "av_text" . $attr->ad_id);
499  $w->table = 1;
500  $bulle = HtmlInput::infobulle(14);
501  break;
502  case 'select':
503  $w = new ISelect("av_text" . $attr->ad_id);
504  $w->value = $this->cn->make_array($attr->ad_extra);
505  $w->style= 'style="width:100%"';
506  break;
507  case 'card':
508  $w = new ICard("av_text" . $attr->ad_id);
509  // filter on frd_id
510  $w->extra = $attr->ad_extra;
511  $w->extra2 = 0;
512  $label = new ISpan();
513  $label->name = "av_text" . $attr->ad_id . "_label";
514  $w->set_attribute('ipopup', 'ipopcard');
515  $w->set_attribute('typecard', $attr->ad_extra);
516  $w->set_attribute('inp', "av_text" . $attr->ad_id);
517  $w->set_attribute('label', "av_text" . $attr->ad_id . "_label");
518  $msg = $w->search();
519  $msg.=$label->input();
520  break;
521  }
522  $w->table = 0;
523  }
524  $w->table = $table;
525  $w->label = $attr->ad_text;
526  $w->name = "av_text" . $attr->ad_id;
527  if ($attr->ad_id == 21 || $attr->ad_id==22||$attr->ad_id==20||$attr->ad_id==31)
528  {
529  $bulle=HtmlInput::infobulle(21);
530  }
531  $r.="<TR>" . td(_($w->label)." $bulle", ' class="input_text" ') . td($w->input()." $msg")." </TR>";
532  }
533  $r.= '</table>';
534  return $r;
535  }
536 
537 
538  /*!
539  * \brief Display object instance, getAttribute
540  * sort the attribute and add missing ones
541  * \param $p_readonly true= if can not modify, otherwise false
542  *
543  *
544  * \return string to display or FNT string for fiche non trouvé
545  */
547  {
548  $this->GetAttribut();
549  $attr=$this->attribut;
550  /* show card type here */
551  $type_card=$this->cn->get_value('select fd_label '
552  . ' from fiche_def join fiche using (fd_id) where f_id=$1',
553  array($this->id));
554  $ret="";
555  $ret.=h2(_("Catégorie")." ".$type_card, 'style="display:inline"');
556  $ret.='<span style="margin-right:5px;float:right">'.
557  _('id fiche').':'.$this->id."</span>";
558  $ret.="<table style=\"width:98%;margin:1%\">";
559  if (empty($attr))
560  {
561  return 'FNT';
562  }
563 
564  /* for each attribute */
565  foreach ($attr as $r)
566  {
567  $msg="";
568  $bulle="";
569  if ($p_readonly)
570  {
571  $w=new IText();
572  $w->table=1;
573  $w->readOnly=true;
574  $w->css_size="100%";
575  }
576  if ($p_readonly==false)
577  {
578 
579  if ($r->ad_id==ATTR_DEF_ACCOUNT)
580  {
581  $w=new IPoste("av_text".$r->ad_id);
582  $w->set_attribute('ipopup', 'ipop_account');
583  $w->set_attribute('account', "av_text".$r->ad_id);
584  $w->dbl_click_history();
585  // account created automatically
586  $w->table=0;
587  $w->value=$r->av_text;
588  // account created automatically
589  $sql="select account_auto($this->fiche_def)";
590  $ret_sql=$this->cn->exec_sql($sql);
591  $a=Database::fetch_array($ret_sql, 0);
592  $bulle=HtmlInput::infobulle(10);
593 
594  if ($a['account_auto']=='t')
595  $bulle.=HtmlInput::warnbulle(11);
596  }
597  elseif ($r->ad_id==ATTR_DEF_TVA)
598  {
599  $w=new ITva_Popup('popup_tva');
600  $w->table=1;
601  $w->value=$r->av_text;
602  }
603  else
604  {
605  switch ($r->ad_type)
606  {
607  case 'text':
608  $w=new IText('av_text'.$r->ad_id);
609  $w->css_size="100%";
610  $w->value=$r->av_text;
611  break;
612  case 'numeric':
613  $w=new INum('av_text'.$r->ad_id);
614  $w->size=$r->ad_size;
615  $w->prec=($r->ad_extra=="")?2:$r->ad_extra;
616  $w->value=$r->av_text;
617  break;
618  case 'date':
619  $w=new IDate('av_text'.$r->ad_id);
620  $w->value=$r->av_text;
621  break;
622  case 'zone':
623  $w=new ITextArea('av_text'.$r->ad_id);
624  $w->style=' class="itextarea" style="margin:0px;width:100%"';
625  $w->value=$r->av_text;
626  break;
627  case 'poste':
628  $w=new IPoste("av_text".$r->ad_id);
629  $w->set_attribute('ipopup', 'ipop_account');
630  $w->set_attribute('account', "av_text".$r->ad_id);
631  $w->dbl_click_history();
632  $w->width=$r->ad_size;
633  $w->table=0;
634  $bulle=HtmlInput::infobulle(14);
635  $w->value=$r->av_text;
636  break;
637  case 'card':
638  $uniq=rand(0, 1000);
639  $w=new ICard("av_text".$r->ad_id);
640  $w->id="card_".$this->id.$uniq;
641  // filter on ad_extra
642 
643  $filter=$r->ad_extra;
644  $w->width=$r->ad_size;
645  $w->extra=$filter;
646  $w->extra2=0;
647  $label=new ISpan();
648  $label->name="av_text".$uniq.$r->ad_id."_label";
649  $fiche=new Fiche($this->cn);
650  $fiche->get_by_qcode($r->av_text);
651  if ($fiche->id==0)
652  {
653  $label->value=(trim($r->av_text)=='')?"":" "._("Fiche non trouvée")." ";
654  $r->av_text="";
655  }
656  else
657  {
658  $label->value=$fiche->strAttribut(ATTR_DEF_NAME).
659  " ".
660  $fiche->strAttribut(ATTR_DEF_FIRST_NAME,0);
661  }
662  $w->set_attribute('ipopup', 'ipopcard');
663  $w->set_attribute('typecard', $filter);
664  $w->set_attribute('inp', "av_text".$r->ad_id);
665  $w->set_attribute('label', $label->name);
666  $w->autocomplete=0;
667  $w->dblclick="fill_ipopcard(this);";
668  $msg=$w->search();
669  $msg.=$label->input();
670  $w->value=$r->av_text;
671  break;
672  case 'select':
673  $w=new ISelect();
674  $w->value=$this->cn->make_array($r->ad_extra);
675  $w->selected=$r->av_text;
676  $w->style=' style="width:100%" ';
677  break;
678  default:
679  var_dump($r);
680  throw new Exception("Type invalide");
681  }
682  $w->table=0;
683  }
684  }
685  else
686  {
687  switch ($r->ad_type)
688  {
689  case 'select':
690  $x=new ISelect();
691  $x->value=$this->cn->make_array($r->ad_extra);
692  $x->selected=$r->av_text;
693  $value=$x->display();
694  $w->value=$value;
695  break;
696  default:
697  $w->value=$r->av_text;
698  }
699  }
700 
701  $w->name="av_text".$r->ad_id;
702  $w->readOnly=$p_readonly;
703 
704  if ($r->ad_id==21||$r->ad_id==22||$r->ad_id==20||$r->ad_id==31)
705  {
706  $bulle=HtmlInput::infobulle(21);
707  }
708  $ret.="<TR>".td(_($r->ad_text).$bulle).td($w->input()." ".$msg)." </TR>";
709  }
710 
711  $ret.="</table>";
712 
713  return $ret;
714  }
715 
716  /*!
717  * \brief Save a card, call insert or update
718  *
719  * \param p_fiche_def (default 0)
720  */
721  function Save($p_fiche_def=0)
722  {
723  // new card or only a update ?
724  if ( $this->id == 0 )
725  $this->insert($p_fiche_def);
726  else
727  $this->update();
728  }
729  /*!
730  * \brief insert a new record
731  *
732  * \param $p_fiche_def fiche_def.fd_id
733  * \param $p_array is the array containing the data
734  *\param $transation if we want to manage the transaction in this function
735  * true for small insert and false for a larger loading, the BEGIN / COMMIT sql
736  * must be done into the caller
737  av_textX where X is the ad_id
738  *\verb
739  example
740  av_text1=>'name'
741  \endverb
742  */
743  function insert($p_fiche_def,$p_array=null,$transaction=true)
744  {
745  if ($p_array==null)
747 
748  $fiche_id=$this->cn->get_next_seq('s_fiche');
749  $this->id=$fiche_id;
750  // first we create the card
751  if ($transaction)
752  $this->cn->start();
753  /*
754  * Sort the array for having the name AFTER the quickcode and the
755  * Accounting
756  */
757  ksort($p_array);
758 
759  try
760  {
761  $sql=sprintf("insert into fiche(f_id,fd_id)".
762  " values (%d,%d)", $fiche_id, $p_fiche_def);
763  $Ret=$this->cn->exec_sql($sql);
764  // parse the $p_array array
765  foreach ($p_array as $name=> $value)
766  {
767  /* avoid the button for searching an accounting item */
768  if (preg_match('/^av_text[0-9]+$/', $name)==0)
769  continue;
770 
771  list ($id)=sscanf($name, "av_text%d");
772  if ($id==null)
773  continue;
774 
775  // Special traitement
776  // quickcode
777  if ($id==ATTR_DEF_QUICKCODE)
778  {
779  $sql=sprintf("select insert_quick_code(%d,'%s')", $fiche_id,
780  sql_string($value));
781  $this->cn->exec_sql($sql);
782  continue;
783  }
784  // name
785  if ($id==ATTR_DEF_NAME)
786  {
787  if (strlen(trim($value))==0)
788  $value="pas de nom";
789  }
790  // account
791  if ($id==ATTR_DEF_ACCOUNT)
792  {
793  $v=mb_substr(sql_string($value), 0, 40);
794  try
795  {
796 
797  if (strlen(trim($v))!=0)
798  {
799  if (strpos($value, ',')==0)
800  {
801  $v=$this->cn->get_value("select format_account($1)",
802  array($value));
803  }
804  else
805  {
806  $ac_array=explode(",", $value);
807  if (count($ac_array)<>2)
808  throw new Exception('Désolé, il y a trop de virgule dans le poste comptable '.h($value));
809  $part1=$ac_array[0];
810  $part2=$ac_array[1];
811  $part1=$this->cn->get_value('select format_account($1)',
812  array($part1));
813  $part2=$this->cn->get_value('select format_account($1)',
814  array($part2));
815  $v=$part1.','.$part2;
816  }
817  $parameter=array($this->id, $v);
818  }
819  else
820  {
821  $parameter=array($this->id, null);
822  }
823  $v=$this->cn->get_value("select account_insert($1,$2)",
824  $parameter);
825  }
826  catch (Exception $e)
827  {
828  throw new Exception("Erreur : ce compte [$v] n'a pas de compte parent.".
829  "L'opération est annulée", 1);
830  }
831  continue;
832  }
833  // TVA
834  if ($id==ATTR_DEF_TVA)
835  {
836  // Verify if the rate exists, if not then do not update
837  if (strlen(trim($value))!=0)
838  {
839  if (isNumber($value)==0)
840  continue;
841  if ($this->cn->count_sql("select * from tva_rate where tva_id=".$value)==0)
842  {
843  continue;
844  }
845  }
846  }
847  // Normal traitement
848  $value2=sql_string($value);
849 
850  $sql=sprintf("select attribut_insert(%d,%d,'%s')", $fiche_id,
851  $id, strip_tags(trim($value2)));
852  $this->cn->exec_sql($sql);
853  }
854  }
855  catch (Exception $e)
856  {
857  $this->cn->rollback();
858  throw ($e);
859  return;
860  }
861  if ($transaction)
862  $this->cn->commit();
863  return;
864  }
865 
866  /*!\brief update a card
867  */
868  function update($p_array=null)
869  {
870  global $g_user;
871  if ($p_array==null)
873 
874  try
875  {
876  $this->cn->start();
877  // parse the $p_array array
878  foreach ($p_array as $name=> $value)
879  {
880  if (preg_match('/^av_text[0-9]+$/', $name)==0)
881  continue;
882 
883  list ($id)=sscanf($name, "av_text%d");
884 
885  if ($id==null)
886  continue;
887 
888  // retrieve jft_id to update table attr_value
889  $sql=" select jft_id from fiche_detail where ad_id=$id and f_id=$this->id";
890  $Ret=$this->cn->exec_sql($sql);
891  if (Database::num_row($Ret)==0)
892  {
893  // we need to insert this new attribut
894  $jft_id=$this->cn->get_next_seq('s_jnt_fic_att_value');
895 
896  $sql2="insert into fiche_detail(jft_id,ad_id,f_id,ad_value) values ($1,$2,$3,NULL)";
897 
898  $ret2=$this->cn->exec_sql($sql2,
899  array($jft_id, $id, $this->id));
900  }
901  else
902  {
904  $jft_id=$tmp['jft_id'];
905  }
906  // Special traitement
907  // quickcode
908  if ($id==ATTR_DEF_QUICKCODE)
909  {
910  $sql=sprintf("select update_quick_code(%d,'%s')", $jft_id,
911  sql_string($value));
912  $this->cn->exec_sql($sql);
913  continue;
914  }
915  // name
916  if ($id==ATTR_DEF_NAME)
917  {
918  if (strlen(trim($value))==0)
919  continue;
920  }
921  // account
922  if ($id==ATTR_DEF_ACCOUNT)
923  {
924  $v=sql_string($value);
925  if (trim($v)!='')
926  {
927  if (strpos($v, ',')!=0)
928  {
929  $ac_array=explode(",", $v);
930  if (count($ac_array)<>2)
931  throw new Exception('Désolé, il y a trop de virgule dans le poste comptable '.h($v));
932  $part1=$ac_array[0];
933  $part2=$ac_array[1];
934  $part1=$this->cn->get_value('select format_account($1)',
935  array($part1));
936  $part2=$this->cn->get_value('select format_account($1)',
937  array($part2));
938  $v=$part1.','.$part2;
939  }
940  else
941  {
942  $v=$this->cn->get_value('select format_account($1)',
943  array($value));
944  }
945  $sql=sprintf("select account_update(%d,'%s')",
946  $this->id, $v);
947  try
948  {
949  $this->cn->exec_sql($sql);
950  }
951  catch (Exception $e)
952  {
953  throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
954  "L'op&eacute;ration est annul&eacute;e");
955  }
956  continue;
957  }
958  if (strlen(trim($v))==0)
959  {
960 
961  $sql=sprintf("select account_update(%d,null)", $this->id);
962  try
963  {
964  $Ret=$this->cn->exec_sql($sql);
965  }
966  catch (Exception $e)
967  {
968  throw new Exception(__LINE__."Erreur : ce compte [$v] n'a pas de compte parent.".
969  "L'opération est annulée");
970  }
971 
972  continue;
973  }
974  }
975  // TVA
976  if ($id==ATTR_DEF_TVA)
977  {
978  // Verify if the rate exists, if not then do not update
979  if (strlen(trim($value))!=0)
980  {
981  if ($this->cn->count_sql("select * from tva_rate where tva_id=".$value)==0)
982  {
983  continue;
984  }
985  }
986  }
987  // Normal traitement
988  $sql="update fiche_detail set ad_value=$1 where jft_id=$2";
989  $this->cn->exec_sql($sql, array(strip_tags($value), $jft_id));
990  }
991  }
992  catch (Exception $e)
993  {
994  echo '<span class="error">'.
995  $e->getMessage().
996  '</span>';
997  error_log($e->getMessage());
998  error_log($e->getTraceAsString());
999  $this->cn->rollback();
1000  return;
1001  }
1002  $this->cn->commit();
1003  return;
1004  }
1005 
1006  /*!\brief remove a card
1007  */
1008  function remove($silent=false)
1009  {
1010  if ( $this->id==0 ) return;
1011  // verify if that card has not been used is a ledger
1012  // if the card has its own account in PCMN
1013  // Get the fiche_def.fd_id from fiche.f_id
1014  $this->Get();
1015  $fiche_def=new Fiche_Def($this->cn,$this->fiche_def);
1016  $fiche_def->get();
1017 
1018  // if the card is used do not removed it
1020 
1021  if ( $this->cn->count_sql("select * from jrnx where j_qcode='".Database::escape_string($qcode)."'") != 0)
1022  {
1023  if ( ! $silent ) {
1024  alert(_('Impossible cette fiche est utilisée dans un journal'));
1025  }
1026  return 1;
1027  }
1028 
1029  $this->delete();
1030  return 0;
1031  }
1032 
1033 
1034  /*!\brief return the name of a card
1035  *
1036  */
1037  function getName()
1038  {
1039  $sql="select ad_value from fiche_detail
1040  where ad_id=1 and f_id=$1";
1041  $Res=$this->cn->exec_sql($sql,array($this->id));
1043  if ( sizeof($r) == 0 )
1044  return 1;
1045  return $r[0]['ad_value'];
1046  }
1047 
1048  /*!\brief return the quick_code of a card
1049  * \return null if not quick_code is found
1050  */
1051  function get_quick_code()
1052  {
1053  $sql="select ad_value from fiche_detail where ad_id=23 and f_id=$1";
1054  $Res=$this->cn->exec_sql($sql,array($this->id));
1056  if ( sizeof($r) == 0 )
1057  return null;
1058  return $r[0]['ad_value'];
1059  }
1060 
1061  /*!\brief Synonum of fiche::getAttribut
1062  */
1063  function Get()
1064  {
1065  $this->getAttribut();
1066  }
1067  /*!\brief Synonum of fiche::getAttribut
1068  */
1069  function load()
1070  {
1071  $this->getAttribut();
1072  }
1073  /*!\brief get all the card thanks the fiche_def_ref
1074  * \param $p_offset (default =-1)
1075  * \param $p_search sql condition
1076  * \return array of fiche object
1077  */
1078  function get_by_category($p_offset=-1,$p_search="",$p_order='')
1079  {
1080  return fiche::GetByDef($this->fiche_def_ref,$p_offset,$p_search,$p_order);
1081  }
1082  /*!\brief retrieve the frd_id of the fiche it is the type of the
1083  * card (bank, purchase...)
1084  * (fiche_def_ref primary key)
1085  */
1087  {
1088  $result=$this->cn->get_array("select frd_id from fiche join fiche_Def using (fd_id) where f_id=".$this->id);
1089  if ( $result == null )
1090  return null;
1091 
1092  return $result[0]['frd_id'];
1093  }
1094  /**
1095  *@brief fetch and return and array
1096  *@see get_row get_row_date
1097  */
1098  private function get_row_result($res)
1099  {
1100  $array=array();
1101  $tot_cred=0.0;
1102  $tot_deb=0.0;
1104  if ( $Max == 0 ) return null;
1105  bcscale(2);
1106  for ($i=0;$i<$Max;$i++)
1107  {
1109  if ($array[$i]['j_debit']=='t')
1110  {
1111  $tot_deb=bcadd($tot_deb, $array[$i]['deb_montant'] );
1112  }
1113  else
1114  {
1115  $tot_cred=bcadd($tot_cred,$array[$i]['cred_montant'] );
1116  }
1117  }
1118  $this->row=$array;
1119  return array($array,$tot_deb,$tot_cred);
1120  }
1121  /*!
1122  * \brief Get data for poste
1123  *
1124  * \param $p_from periode from
1125  * \param $p_to end periode
1126  *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
1127  * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
1128  * (tot_deb,tot_credit
1129  *
1130  */
1131  function get_row_date($p_from,$p_to,$op_let=0)
1132  {
1133  global $g_user;
1134  if ( $this->id == 0 )
1135  {
1136  echo_error("class_fiche",__LINE__,"id is 0");
1137  return;
1138  }
1139  $filter_sql=$g_user->get_ledger_sql('ALL',3);
1140  $sql_let='';
1141  switch ($op_let)
1142  {
1143  case 0:
1144  break;
1145  case 1:
1146  $sql_let=' and j_id in (select j_id from letter_cred union select j_id from letter_deb)';
1147  break;
1148  case '2':
1149  $sql_let=' and j_id not in (select j_id from letter_cred union select j_id from letter_deb) ';
1150  break;
1151  }
1152 
1154  $Res=$this->cn->exec_sql("select distinct substring(jr_pj_number,'[0-9]+$'),j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
1155  "case when j_debit='t' then j_montant else 0 end as deb_montant,".
1156  "case when j_debit='f' then j_montant else 0 end as cred_montant,".
1157  " jr_comment as description,jrn_def_name as jrn_name,".
1158  " jr_pj_number,".
1159  "j_debit, jr_internal,jr_id,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter, ".
1160  " jr_tech_per,p_exercice,jrn_def_name,
1161  jrn_def_code".
1162  " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
1163  " left join jrn on jr_grpt_id=j_grpt".
1164  " left join parm_periode on (p_id=jr_tech_per) ".
1165  " where j_qcode=$1 and ".
1166  " ( to_date($2,'DD.MM.YYYY') <= j_date and ".
1167  " to_date($3,'DD.MM.YYYY') >= j_date )".
1168  " and $filter_sql $sql_let ".
1169  " order by j_date,substring(jr_pj_number,'[0-9]+$')",array($qcode,$p_from,$p_to));
1170 
1171  return $this->get_row_result($Res);
1172  }
1173 
1174  /*!
1175  * \brief Get data for poste
1176  *
1177  * \param $p_from periode from
1178  * \param $p_to end periode
1179  * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
1180  * (tot_deb,tot_credit
1181  *
1182  */
1183  function get_row($p_from,$p_to)
1184  {
1185  if ( $this->id == 0 )
1186  {
1187  echo_error("class_fiche",__LINE__,"id is 0");
1188  return;
1189  }
1191  $periode=sql_filter_per($this->cn,$p_from,$p_to,'p_id','jr_tech_per');
1192 
1193  $Res=$this->cn->exec_sql("select j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_qcode,".
1194  "case when j_debit='t' then j_montant else 0 end as deb_montant,".
1195  "case when j_debit='f' then j_montant else 0 end as cred_montant,".
1196  " jr_comment as description,jrn_def_name as jrn_name,".
1197  "j_debit, jr_internal,jr_id ".
1198  " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
1199  " left join jrn on jr_grpt_id=j_grpt".
1200  " where j_qcode='".$qcode."' and ".$periode.
1201  " order by j_date::date");
1202  return $this->get_row_result($Res);
1203 
1204  }
1205  /*!
1206  * \brief HtmlTable, display a HTML of a card for the asked period
1207  *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
1208  * \return none
1209  */
1210  function HtmlTableDetail($p_array=null,$op_let=0)
1211  {
1212  if ( $p_array == null)
1214 
1215  $name=$this->getName();
1216 
1217  list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
1218  $p_array['to_periode'],
1219  $op_let
1220  );
1221 
1222  if ( count($this->row ) == 0 )
1223  return;
1225 
1226  $rep="";
1227  $already_seen=array();
1228  echo '<h2 class="info">'.$this->id." ".$name.'</h2>';
1229  echo "<TABLE class=\"result\" style=\"width:100%;border-collapse:separate;border-spacing:5px\">";
1230  echo "<TR>".
1231  "<TH>"._("n° de pièce / Code interne")." </TH>".
1232  "<TH>"._("Date")."</TH>".
1233  "<TH>"._("Description")." </TH>".
1234  "<TH>"._('Montant')." </TH>".
1235  "<TH> "._('Débit/Crédit')." </TH>".
1236  "</TR>";
1237 
1238  foreach ( $this->row as $op )
1239  {
1240  if ( in_array($op['jr_internal'],$already_seen) )
1241  continue;
1242  else
1243  $already_seen[]=$op['jr_internal'];
1244  echo "<TR style=\"text-align:center;background-color:lightgrey\">".
1245  "<td>".$op['jr_pj_number']." / ".$op['jr_internal']."</td>".
1246  "<td>".$op['j_date']."</td>".
1247  "<td>".h($op['description'])."</td>".
1248  "<td>"."</td>".
1249  "<td>"."</td>".
1250  "</TR>";
1251  $ac=new Acc_Operation($this->cn);
1252  $ac->jr_id=$op['jr_id'];
1253  $ac->qcode=$qcode;
1254  echo $ac->display_jrnx_detail(1);
1255 
1256  }
1257  $solde_type=($tot_deb>$tot_cred)?_("solde débiteur"):_("solde créditeur");
1258  $diff=round(abs($tot_deb-$tot_cred),2);
1259  echo "<TR>".
1260  "<TD>$solde_type".
1261  "<TD>$diff</TD>".
1262  "<TD></TD>".
1263  "<TD>$tot_deb</TD>".
1264  "<TD>$tot_cred</TD>".
1265  "</TR>";
1266 
1267  echo "</table>";
1268 
1269  return;
1270  }
1271  /*!
1272  * \brief HtmlTable, display a HTML of a card for the asked period
1273  * \param $p_array default = null keys = from_periode, to_periode
1274  *\param $op_let 0 all operation, 1 only lettered one, 2 only unlettered one
1275  *\return -1 if nothing is found otherwise 0
1276  *\see get_row_date
1277  */
1278  function HtmlTable($p_array=null,$op_let=0,$from_div=1)
1279  {
1280  if ( $p_array == null)
1282  $progress=0;
1283  // if from_periode is greater than to periode then swap the values
1284  if (cmpDate($p_array['from_periode'],$p_array['to_periode']) > 0)
1285  {
1286  $tmp=$p_array['from_periode'];
1287  $p_array['from_periode']=$p_array['to_periode'];
1288  $p_array['to_periode']=$tmp;
1289 
1290  }
1291  list($array, $tot_deb, $tot_cred) = $this->get_row_date($p_array['from_periode'], $p_array['to_periode'], $op_let);
1292 
1293  if ( count($this->row ) == 0 )
1294  return -1;
1295 
1296  $rep="";
1297  if ( $from_div==1)
1298  {
1299  echo "<TABLE id=\"tbpopup\" class=\"resultfooter\" style=\"margin:1%;width:98%;;border-collapse:separate;border-spacing:0px 5px\">";
1300  }
1301  else
1302  {
1303  echo "<TABLE id=\"tb" . $from_div . "\"class=\"result\" style=\"margin:1%;width:98%;border-collapse:separate;border-spacing:0px 2px\">";
1304  }
1305  echo '<tbody>';
1306  echo "<TR>".
1307  "<TH style=\"text-align:left\">"._('Date')."</TH>".
1308  "<TH style=\"text-align:left\">"._('n° pièce')." </TH>".
1309  "<TH style=\"text-align:left\">"._('Code interne')." </TH>".
1310  "<TH style=\"text-align:left\">"._('Description')." </TH>".
1311  "<TH style=\"text-align:right\">"._('Débit')." </TH>".
1312  "<TH style=\"text-align:right\">"._('Crédit')." </TH>".
1313  th('Prog.','style="text-align:right"').
1314  th('Let.','style="text-align:right"');
1315  "</TR>"
1316  ;
1317  $old_exercice="";$sum_deb=0;$sum_cred=0;
1318  bcscale(2);
1319  $idx=0;
1320  foreach ( $this->row as $op )
1321  {
1322  $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']);
1323  $let = '';
1324  $html_let = "";
1325  if ($op['letter'] != -1)
1326  {
1327  $let = strtoupper(base_convert($op['letter'], 10, 36));
1329  }
1330  $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
1331 
1332  /*
1333  * reset prog. balance to zero if we change of exercice
1334  */
1335  if ( $old_exercice != $op['p_exercice'])
1336  {
1337  if ($old_exercice != '' )
1338  {
1339  $progress=bcsub($sum_deb,$sum_cred);
1340  $side="&nbsp;".$this->get_amount_side($progress);
1341  echo "<TR class=\"highlight\">".
1342  "<TD>$old_exercice</TD>".
1343  td('').
1344  "<TD></TD>".
1345  "<TD>Totaux</TD>".
1346  "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
1347  "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
1348  td(nbm(abs($progress)).$side,'style="text-align:right"').
1349  td('').
1350  "</TR>";
1351  $sum_cred=0;
1352  $sum_deb=0;
1353  $progress=0;
1354  }
1355  }
1356  $progress=bcadd($progress,$tmp_diff);
1357  $side="&nbsp;".$this->get_amount_side($progress);
1358  $sum_cred=bcadd($sum_cred,$op['cred_montant']);
1359  $sum_deb=bcadd($sum_deb,$op['deb_montant']);
1360  if ($idx%2 == 0) $class='class="odd"'; else $class=' class="even"';
1361  $idx++;
1362 
1363  echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
1364  "<TD>".smaller_date(format_date($op['j_date_fmt']))."</TD>".
1365  td(h($op['jr_pj_number'])).
1366  "<TD>".$vw_operation."</TD>".
1367  "<TD>".h($op['description'])."</TD>".
1368  "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
1369  "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
1370  td(nbm(abs($progress)).$side,'style="text-align:right"').
1371  td($html_let, ' style="text-align:right"') .
1372  "</TR>";
1373  $old_exercice=$op['p_exercice'];
1374 
1375  }
1376  $solde_type=($sum_deb>$sum_cred)?"solde débiteur":"solde créditeur";
1377  $diff=abs(bcsub($sum_deb,$sum_cred));
1378  echo '<tfoot>';
1379  echo "<TR class=\"highlight\">".
1380  "<TD>Totaux</TD>".
1381  "<TD ></TD>".
1382  "<TD ></TD>".
1383  "<TD></TD>".
1384  "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
1385  "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
1386  "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
1387 
1388  "</TR>";
1389  echo "<TR style=\"font-weight:bold\">".
1390  "<TD>$solde_type</TD>".
1391  "<TD style=\"text-align:right\">".nbm($diff)."</TD>".
1392  "<TD></TD>".
1393  "</TR>";
1394  echo '</tfoot>';
1395  echo '</tbody>';
1396 
1397  echo "</table>";
1398 
1399  return 0;
1400  }
1401  /*!
1402  * \brief Display HTML Table Header (button)
1403  *
1404  * \return none
1405  */
1406  function HtmlTableHeader($p_array=null)
1407  {
1408  if ( $p_array == null)
1410 
1411  $hid=new IHidden();
1412  echo '<div class="noprint">';
1413  echo "<table >";
1414  echo '<TR>';
1415 
1416  echo '<TD><form method="GET" ACTION="">'.
1417  HtmlInput::submit('bt_other',"Autre poste").
1418  HtmlInput::array_to_hidden(array('gDossier','ac'), $_REQUEST).
1419  dossier::hidden().
1420  $hid->input("type","poste").$hid->input('p_action','impress')."</form></TD>";
1421  $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$_REQUEST['ople']):'';
1422 
1423  echo '<TD><form method="GET" ACTION="export.php">'.
1424  HtmlInput::submit('bt_pdf',_("Export PDF")).
1425  dossier::hidden().$str_ople.
1426  HtmlInput::hidden('act','PDF:fichedetail').
1427  $hid->input("type","poste").
1428  $hid->input('p_action','impress').
1429  $hid->input("f_id",$this->id).
1430  dossier::hidden().
1431  $hid->input("from_periode",$p_array['from_periode']).
1432  $hid->input("to_periode",$p_array['to_periode']);
1433  if (isset($p_array['oper_detail']))
1434  echo $hid->input('oper_detail','on');
1435 
1436  echo "</form></TD>";
1437 
1438  echo '<TD><form method="GET" ACTION="export.php">'.
1439  HtmlInput::submit('bt_csv',_("Export CSV")).
1440  HtmlInput::hidden('act','CSV:fichedetail').
1441  dossier::hidden().$str_ople.
1442  $hid->input("type","poste").
1443  $hid->input('p_action','impress').
1444  $hid->input("f_id",$this->id).
1445  $hid->input("from_periode",$p_array['from_periode']).
1446  $hid->input("to_periode",$p_array['to_periode']);
1447  if (isset($p_array['oper_detail']))
1448  echo $hid->input('oper_detail','on');
1449 
1450  echo "</form></TD>";
1451  echo "</form></TD>";
1452  echo '<td style="vertical-align:top">';
1453  echo HtmlInput::print_window();
1454  echo '</td>';
1455  echo "</table>";
1456  echo '</div>';
1457 
1458  }
1459  /*!
1460  * \brief give the balance of an card
1461  * \return
1462  * balance of the card
1463  *
1464  */
1465  function get_solde_detail($p_cond="")
1466  {
1467  if ( $this->id == 0 ) return array('credit'=>0,'debit'=>0,'solde'=>0);
1469 
1470  if ( $p_cond != "") $p_cond=" and ".$p_cond;
1471  $Res=$this->cn->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
1472  ( select j_poste,
1473  case when j_debit='t' then j_montant else 0 end as deb,
1474  case when j_debit='f' then j_montant else 0 end as cred
1475  from jrnx
1476  where
1477  j_qcode = ('$qcode'::text)
1478  $p_cond
1479  ) as m ");
1481  if ($Max==0) return 0;
1483 
1484  return array('debit'=>$r['sum_deb'],
1485  'credit'=>$r['sum_cred'],
1486  'solde'=>abs($r['sum_deb']-$r['sum_cred']));
1487  }
1488  /**
1489  *get the bank balance with receipt or not
1490  *
1491  */
1492  function get_bk_balance($p_cond="")
1493  {
1494  if ( $this->id == 0 ) throw new Exception('fiche->id est nul');
1496 
1497  if ( $p_cond != "") $p_cond=" and ".$p_cond;
1498  $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
1499  ( select j_poste,
1500  case when j_debit='t' then j_montant else 0 end as deb,
1501  case when j_debit='f' then j_montant else 0 end as cred
1502  from jrnx
1503  join jrn on (jr_grpt_id=j_grpt)
1504  where
1505  j_qcode = ('$qcode'::text)
1506  $p_cond
1507  ) as m ";
1508 
1509  $Res=$this->cn->exec_sql($sql);
1511  if ($Max==0) return 0;
1513 
1514  return array('debit'=>$r['sum_deb'],
1515  'credit'=>$r['sum_cred'],
1516  'solde'=>abs($r['sum_deb']-$r['sum_cred']));
1517 
1518  }
1519  /*!\brief check if an attribute is empty
1520  *\param $p_attr the id of the attribut to check (ad_id)
1521  *\return return true is the attribute is empty or missing
1522  */
1523  function empty_attribute($p_attr)
1524  {
1525  $sql="select ad_value
1526  from fiche_detail
1527  natural join fiche
1528  left join attr_def using (ad_id) where f_id=".$this->id.
1529  " and ad_id = ".$p_attr.
1530  " order by ad_id";
1531  $res=$this->cn->exec_sql($sql);
1532  if ( Database::num_row($res) == 0 ) return true;
1533  $text=Database::fetch_result($res,0,0);
1534  return (strlen(trim($text)) > 0)?false:true;
1535 
1536 
1537  }
1538  /*! Summary
1539  * \brief show the default screen
1540  *
1541  * \param $p_search (filter)
1542  * \param $p_action used for specific action bank, red if credit < debit
1543  * \param $p_sql SQL to filter the number of card must start with AND
1544  * \param $p_amount true : only cards with at least one operation default : false
1545  * \return: string to display
1546  */
1547  function Summary($p_search="",$p_action="",$p_sql="",$p_amount=false)
1548  {
1549  global $g_user;
1550  $bank=new Acc_Parm_Code($this->cn,'BANQUE');
1551  $cash=new Acc_Parm_Code($this->cn,'CAISSE');
1552  $cc=new Acc_Parm_Code($this->cn,'COMPTE_COURANT');
1553 
1554  bcscale(4);
1556  $p_search=sql_string($p_search);
1557  $script=$_SERVER['PHP_SELF'];
1558  // Creation of the nav bar
1559  // Get the max numberRow
1560  $filter_amount='';
1561  global $g_user;
1562 
1563  $filter_year=" j_tech_per in (select p_id from parm_periode ".
1564  "where p_exercice='".$g_user->get_exercice()."')";
1565 
1566  if ( $p_amount) $filter_amount=' and f_id in (select f_id from jrnx where '.$filter_year.')';
1567 
1568  $all_tiers=$this->count_by_modele($this->fiche_def_ref,"",$p_sql.$filter_amount);
1569  // Get offset and page variable
1570  $offset=( isset ($_REQUEST['offset'] )) ?$_REQUEST['offset']:0;
1571  $page=(isset($_REQUEST['page']))?$_REQUEST['page']:1;
1572  $bar=navigation_bar($offset,$all_tiers,$_SESSION['g_pagesize'],$page);
1573 
1574  // set a filter ?
1575  $search=$p_sql;
1576 
1577  $exercice=$g_user->get_exercice();
1578  $tPeriode=new Periode($this->cn);
1579  list($max,$min)=$tPeriode->get_limit($exercice);
1580 
1581 
1582  if ( trim($p_search) != "" )
1583  {
1584  $search.=" and f_id in
1585  (select distinct f_id from fiche_detail
1586  where
1587  ad_id in (1,32,30,23,18,13) and ad_value ~* '$p_search')";
1588  }
1589  // Get The result Array
1590  $step_tiers=$this->get_by_category($offset,$search.$filter_amount,'name');
1591 
1592  if ( $all_tiers == 0 || count($step_tiers)==0 ) return "";
1593  $r="";
1594  $r.=$bar;
1595 
1596  $r.='<table id="tiers_tb" class="sortable" style="width:90%;margin-left:5%">
1597  <TR >
1598  <TH>'._('Quick Code').HtmlInput::infobulle(17).'</TH>'.
1599  '<th>'._('Poste comptable').'</th>'.
1600  '<th class="sorttable_sorted_reverse">'._('Nom').'<span id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>
1601  <th>'._('Adresse').'</th>
1602  <th style="text-align:right">'._('Total débit').'</th>
1603  <th style="text-align:right">'._('Total crédit').'</th>
1604  <th style="text-align:right">'._('Solde').'</th>';
1605  $r.='</TR>';
1606  if ( sizeof ($step_tiers ) == 0 )
1607  return $r;
1608 
1609  $i=0;
1610  $deb=0;$cred=0;
1611  foreach ($step_tiers as $tiers )
1612  {
1613  $i++;
1614 
1615  /* Filter on the default year */
1616  $amount=$tiers->get_solde_detail($filter_year);
1617 
1618  /* skip the tiers without operation */
1619  if ( $p_amount && $amount['debit']==0 && $amount['credit'] == 0 && $amount['solde'] == 0 ) continue;
1620 
1621  $odd="";
1622  $odd = ($i % 2 == 0 ) ? ' odd ': ' even ';
1623  $accounting=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
1624  if ( $p_action == 'bank' && $amount['debit'] < $amount['credit'] ){
1625  if ( strpos($accounting,$bank->p_value)===0 || strpos($accounting,$cash->p_value)===0 || strpos($accounting,$cc->p_value)===0){
1626  //put in red if c>d
1627  $odd.=" notice ";
1628  }
1629  }
1630 
1631  $odd=' class="'.$odd.'"';
1632 
1633  $r.="<TR $odd>";
1634  $url_detail=$script.'?'.http_build_query(array('sb'=>'detail','sc'=>'sv','ac'=>$_REQUEST['ac'],'f_id'=>$tiers->id,'gDossier'=>$gDossier));
1635  $e=sprintf('<A HREF="%s" title="Détail" class="line"> ',
1636  $url_detail);
1637 
1638  $r.="<TD> $e".$tiers->strAttribut(ATTR_DEF_QUICKCODE)."</A></TD>";
1639  $r.="<TD sorttable_customkey=\"text{$accounting}\"> $e".$accounting."</TD>";
1640  $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_NAME))."</TD>";
1641  $r.="<TD>".h($tiers->strAttribut(ATTR_DEF_ADRESS).
1642  " ".$tiers->strAttribut(ATTR_DEF_CP).
1643  " ".$tiers->strAttribut(ATTR_DEF_PAYS)).
1644  "</TD>";
1645  $str_deb=(($amount['debit']==0)?0:nbm($amount['debit']));
1646  $str_cred=(($amount['credit']==0)?0:nbm($amount['credit']));
1647  $str_solde=nbm($amount['solde']);
1648  $r.='<TD sorttable_customkey="'.$amount['debit'].'" align="right"> '.$str_deb.'</TD>';
1649  $r.='<TD sorttable_customkey="'.$amount['credit'].'" align="right"> '.$str_cred.'</TD>';
1650  $side=($amount['debit'] > $amount['credit'])?'D':'C';
1651  $side=($amount['debit'] == $amount['credit'])?'=':$side;
1652  $red="";
1653  if ( $p_action == 'customer' && $amount['debit'] < $amount['credit'] ){
1654  //put in red if d>c
1655  $red=" notice ";
1656  }
1657  if ( $p_action == 'supplier' && $amount['debit'] > $amount['credit'] ){
1658  //put in red if c>d
1659  $red=" notice ";
1660  }
1661  $r.='<TD class="'.$red.'" sorttable_customkey="'.$amount['solde'].'" align="right"> '.$str_solde."$side </TD>";
1662  $deb=bcadd($deb,$amount['debit']);
1663  $cred=bcadd($cred,$amount['credit']);
1664 
1665  $r.="</TR>";
1666 
1667  }
1668  $r.="<tfoot >";
1669  $solde=abs(bcsub($deb,$cred));
1670  $side=($deb > $cred)?'Débit':'Crédit';
1671  $r.='<tr class="highlight">';
1672  $r.=td("").td("").td("").td("Totaux").td(nbm($deb),'class="num"').td(nbm($cred),'class="num"').td(" $side ".nbm($solde),'class="num"');
1673  $r.='</tr>';
1674  $r.="</tfoot>";
1675  $r.="</TABLE>";
1676  $r.=$bar;
1677  return $r;
1678  }
1679  /*!
1680  * \brief get the fd_id of the card : fd_id, it set the attribute fd_id
1681  */
1682  function get_categorie()
1683  {
1684  if ( $this->id == 0 ) throw new Exception('class_fiche : f_id = 0 ');
1685  $sql='select fd_id from fiche where f_id=$1';
1686  $R=$this->cn->get_value($sql, array($this->id));
1687  if ( $R == "" )
1688  $this->fd_id=0;
1689  else
1690  $this->fd_id=$R;
1691  }
1692  /*!
1693  ***************************************************
1694  * \brief Check if a fiche is used by a jrn
1695  * return 1 if the fiche is in the range otherwise 0, the quick_code
1696  * or the id must be set
1697  *
1698  *
1699  * \param $p_jrn journal_id
1700  * \param $p_type : deb or cred default empty
1701  *
1702  * \return 1 if the fiche is in the range otherwise < 1
1703  * -1 the card doesn't exist
1704  * -2 the ledger has no card to check
1705  *
1706  */
1708  {
1709  // check if we have a quick_code or a f_id
1710  if (($this->quick_code==null || $this->quick_code == "" )
1711  && $this->id == 0 )
1712  {
1713  throw new Exception( 'erreur ni quick_code ni f_id ne sont donnes');
1714  }
1715 
1716  //retrieve the quick_code
1717  if ( $this->quick_code=="")
1718  $this->quick_code=$this->get_quick_code();
1719 
1720 
1721  if ( $this->quick_code==null)
1722  return -1;
1723 
1724  if ( $this->id == 0 )
1725  if ( $this->get_by_qcode(null,false) == 1)
1726  return -1;
1727 
1728  $get="";
1729  if ( $p_type == 'deb' )
1730  {
1731  $get='jrn_def_fiche_deb';
1732  }
1733  if ( $p_type == 'cred' )
1734  {
1735  $get='jrn_def_fiche_cred';
1736  }
1737  if ( $get != "" )
1738  {
1739  $Res=$this->cn->exec_sql("select $get as fiche from jrn_def where jrn_def_id=$p_jrn");
1740  }
1741  else
1742  {
1743  // Get all the fiche type (deb and cred)
1744  $Res=$this->cn->exec_sql(" select jrn_def_fiche_cred as fiche
1745  from jrn_def where jrn_def_id=$p_jrn
1746  union
1747  select jrn_def_fiche_deb
1748  from jrn_def where jrn_def_id=$p_jrn"
1749  );
1750  }
1752  if ( $Max==0)
1753  {
1754  return -2;
1755  }
1756  /* convert the array to a string */
1758  $str_list="";
1759  $comma='';
1760  foreach ($list as $row)
1761  {
1762  if ( $row['fiche'] != '' )
1763  {
1764  $str_list.=$comma.$row['fiche'];
1765  $comma=',';
1766  }
1767  }
1768  // Normally Max must be == 1
1769 
1770  if ( $str_list=="")
1771  {
1772  return -3;
1773  }
1774 
1775  $sql="select *
1776  from fiche
1777  where
1778  fd_id in (".$str_list.") and f_id= ".$this->id;
1779 
1780  $Res=$this->cn->exec_sql($sql);
1782  if ($Max==0 )
1783  return 0;
1784  else
1785  return 1;
1786  }
1787  /*!\brief get all the card from a categorie
1788  *\param $p_cn database connx
1789  *\param $pFd_id is the category id
1790  *\param $p_order for the sort, possible values is name_asc,name_desc or nothing
1791  *\return an array of card, but only the fiche->id is set
1792  */
1793  static function get_fiche_def($p_cn,$pFd_id,$p_order='')
1794  {
1795  switch ($p_order)
1796  {
1797  case 'name_asc':
1798  $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';
1799  break;
1800  case 'name_desc':
1801  $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';
1802  break;
1803  default:
1804  $sql='select f_id from fiche where fd_id=$1 ';
1805  }
1806  $array=$p_cn->get_array($sql,array($pFd_id));
1807 
1808  return $array;
1809  }
1810  /*!\brief check if a card is used
1811  *\return return true is a card is used otherwise false
1812  */
1813  function is_used()
1814  {
1815  /* retrieve first the quickcode */
1817  $sql='select count(*) as c from jrnx where j_qcode=$1';
1818  $count=$this->cn->get_value($sql,array($qcode));
1819  if ( $count == 0 ) return false;
1820  return true;
1821  }
1822  /*\brief remove a card without verification */
1823  function delete()
1824  {
1825  // Remove from attr_value
1826  $Res=$this->cn->exec_sql("delete from fiche_detail
1827  where
1828  f_id=".$this->id);
1829 
1830  // Remove from fiche
1831  $Res=$this->cn->exec_sql("delete from fiche where f_id=".$this->id);
1832 
1833  }
1834  /*!\brief create the sql statement for retrieving all
1835  * the card
1836  *\return string with sql statement
1837  *\param $array contains the condition
1838  \verbatim
1839  [jrn] => 2
1840  [typecard] => cred / deb / filter or list
1841  [query] => string
1842  \endverbatim
1843  *\note the typecard cred, deb or filter must be used with jrn, the value of list means a list of fd_id
1844  *\see ajax_card.php cards.js
1845  */
1846  function build_sql($array)
1847  {
1848  if (!empty($array))
1849  extract($array, EXTR_SKIP);
1850  $and='';
1851  $filter_fd_id='true';
1852  $filter_query='';
1853  if (isset($typecard))
1854  {
1855  if (strpos($typecard, "sql")==false)
1856  {
1857  switch ($typecard)
1858  {
1859  case 'cred':
1860  if (!isset($jrn))
1861  throw ('Erreur pas de valeur pour jrn');
1862  $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
1863  array($jrn));
1864  $filter_fd_id=" fd_id in (".$filter_jrn.")";
1865  $and=" and ";
1866  break;
1867  case 'deb':
1868  if (!isset($jrn))
1869  throw ('Erreur pas de valeur pour jrn');
1870  $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
1871  array($jrn));
1872  $filter_fd_id=" fd_id in (".$filter_jrn.")";
1873  $and=" and ";
1874  break;
1875  case 'filter':
1876  if (!isset($jrn))
1877  throw ('Erreur pas de valeur pour jrn');
1878  $filter_jrn=$this->cn->make_list("select jrn_def_fiche_deb from jrn_Def where jrn_def_id=$1",
1879  array($jrn));
1880 
1881  if (trim($filter_jrn)!='')
1882  $fp1=" fd_id in (".$filter_jrn.")";
1883  else
1884  $fp1="fd_id < 0";
1885 
1886  $filter_jrn=$this->cn->make_list("select jrn_def_fiche_cred from jrn_Def where jrn_def_id=$1",
1887  array($jrn));
1888 
1889  if (trim($filter_jrn)!='')
1890  $fp2=" fd_id in (".$filter_jrn.")";
1891  else
1892  $fp2="fd_id < 0";
1893 
1894  $filter_fd_id='('.$fp1.' or '.$fp2.')';
1895 
1896  $and=" and ";
1897  break;
1898  case 'all':
1899  $filter_fd_id=' true';
1900  break;
1901  default:
1902  if (trim($typecard)!='')
1903  $filter_fd_id=' fd_id in ('.$typecard.')';
1904  else
1905  $filter_fd_id=' fd_id < 0';
1906  }
1907  }
1908  else
1909  {
1910  $filter_fd_id=str_replace('[sql]', '', $typecard);
1911  }
1912  }
1913 
1914  $and=" and ";
1915  if (isset($query))
1916  {
1918 
1919  if (strlen(trim($query))>1)
1920  {
1921  $filter_query=$and."(vw_name ilike '%$query%' or quick_code ilike ('%$query%') "
1922  ." or vw_description ilike '%$query%' or tva_num ilike '%$query%' or accounting like upper('$query%'))";
1923  }
1924  else
1925  {
1926  $filter_query='';
1927  }
1928  }
1929  $sql="select * from vw_fiche_attr where ".$filter_fd_id.$filter_query;
1930  return $sql;
1931  }
1932 
1933  /**
1934  *@brief move a card to another cat. The properties will changed
1935  * and be removed
1936  *@param $p_fdid the fd_id of destination
1937  */
1938  function move_to($p_fdid)
1939  {
1940  $this->cn->start();
1941  $this->cn->exec_sql('update fiche set fd_id=$1 where f_id=$2',array($p_fdid,$this->id));
1942  // add missing
1943  $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($p_fdid));
1944  // add to the destination missing fields
1945  $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));
1946  $this->cn->commit();
1947  }
1948  /**
1949  * return the letter C if amount is > 0, D if < 0 or =
1950  * @param type $p_amount
1951  * @return string
1952  */
1953  function get_amount_side($p_amount)
1954  {
1955  if ($p_amount == 0)
1956  return "=";
1957  if ($p_amount < 0)
1958  return "C";
1959  if ($p_amount > 0)
1960  return "D";
1961  }
1962  static function test_me()
1963  {
1965  $a=new Fiche($cn);
1966  $select_cat=new ISelect('fd_id');
1967  $select_cat->value=$cn->make_array('select fd_id,fd_label from fiche_def where frd_id='.
1969  echo '<FORM METHOD="GET"> ';
1970  echo dossier::hidden();
1971  echo HtmlInput::hidden('test_select',$_GET['test_select']);
1972  echo 'Choix de la catégorie';
1973  echo $select_cat->input();
1974  echo HtmlInput::submit('go_card','Afficher');
1975  echo '</form>';
1976  if ( isset ($_GET['go_card']))
1977  {
1978  $empty=$a->to_array($_GET['fd_id']);
1979  print_r($empty);
1980  }
1981  }
1982 
1984  {
1985  $r = "<h2>" . h($this->getName()) . " " . h($this->getAttribut(ATTR_DEF_FIRST_NAME)) . '[' . $this->get_quick_code() . ']</h2>';
1986  return $r;
1987  }
1988  function get_all_account()
1989  {
1990 
1991  }
1992  /**
1993  * @brief Return a string with the HTML code to display a button to export the
1994  * history in CSV
1995  * @param type $p_from from date (DD.MM.YYYY)
1996  * @param type $p_to to date (DD.MM.YYYY)
1997  * @return HTML string
1998  */
1999  function button_csv($p_from,$p_to) {
2000  $href="export.php?".http_build_query(
2001  array(
2002  "gDossier"=>Dossier::id(),
2003  "f_id"=>$this->id,
2004  "ople"=>0,
2005  "type"=>"poste",
2006  "from_periode"=>$p_from,
2007  "to_periode"=>$p_to,
2008  "act"=>"CSV:fichedetail"
2009  )
2010  );
2011  return '<a class="smallbutton" style="display:inline" href="'.$href.'">'._("Export CSV").'</a>';
2012 
2013  }
2014  /**
2015  * @brief Return a string with the HTML code to display a button to export the
2016  * history in PDF
2017  * @param type $p_from from date (DD.MM.YYYY)
2018  * @param type $p_to to date (DD.MM.YYYY)
2019  * @return HTML string
2020  */
2021  function button_pdf($p_from,$p_to) {
2022  $href="export.php?".http_build_query(
2023  array(
2024  "gDossier"=>Dossier::id(),
2025  "f_id"=>$this->id,
2026  "ople"=>0,
2027  "type"=>"poste",
2028  "from_periode"=>$p_from,
2029  "to_periode"=>$p_to,
2030  "act"=>"PDF:fichedetail"
2031  )
2032  );
2033  return '<a class="smallbutton" style="display:inline" href="'.$href.'">'._("Export PDF").'</a>';
2034 
2035  }
2036  /**
2037  * @brief Filter in javascript the table with the history
2038  * @param type $p_table_id id of the table containting the data to filter
2039  * @return html string
2040  */
2041 
2042  function filter_history($p_table_id) {
2043  return _('Cherche').' '.HtmlInput::filter_table($p_table_id, '0,1,2,3,5,6,7', 1);
2044  }
2045 }
2046 
2047 ?>
to_array($pfd_id)
make an array of attributes of the category of card (FICHE_DEF.FD_ID) The array can be used with the ...
blank($p_fiche_def)
insert a new record show a blank card to be filled
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:666
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...
$_GET['qcode']
$_POST['ac']
Definition: do.php:279
__construct($p_cn, $p_id=0)
Definition: class_fiche.php:53
getAttribut()
get all the attribute of a card, add missing ones and sort the array ($this->attribut) by ad_id ...
static fetch_all($ret)
wrapper for the function pg_fetch_all
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...
update($p_array=null)
update a card
if($g_user->check_dossier(dossier::id(), true)=='X') $op
Definition: ajax_ledger.php:89
get_bk_balance($p_cond="")
get the bank balance with receipt or not
const ATTR_DEF_TVA
Definition: constant.php:190
Manage the table parm_code which contains the custom parameter for the module accountancy.
HtmlTableDetail($p_array=null, $op_let=0)
HtmlTable, display a HTML of a card for the asked period.
const ATTR_DEF_ADRESS
Definition: constant.php:192
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
filter_history($p_table_id)
Filter in javascript the table with the history.
count_by_modele($p_frd_id, $p_search="", $p_sql="")
Return array of card from the frd family.
static infobulle($p_comment)
define Class fiche and fiche def, those class are using class attribut
$side
static num_row($ret)
wrapper for the function pg_NumRows
get_gestion_title()
$class
insert($p_fiche_def, $p_array=null, $transaction=true)
insert a new record
static get_fiche_def($p_cn, $pFd_id, $p_order='')
get all the card from a categorie
Manage the table attr_def.
get_by_category($p_offset=-1, $p_search="", $p_order='')
get all the card thanks the fiche_def_ref
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
show a button, for selecting a account and a input text for manually inserting an account the differe...
get_row($p_from, $p_to)
Get data for poste.
Save($p_fiche_def=0)
Save a card, call insert or update.
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:121
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...
ShowTable()
Get()
Synonum of fiche::getAttribut.
const FICHE_TYPE_CLIENT
Definition: constant.php:214
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:767
setAttribut($p_ad_id, $p_value)
set an attribute by a value, if the attribut array is empty a call to getAttribut is performed ...
const ATTR_DEF_FIRST_NAME
Definition: constant.php:207
const ATTR_DEF_CP
Definition: constant.php:193
let you choose a TVA in a popup
isNumber(&$p_int)
Definition: ac_common.php:202
button_csv($p_from, $p_to)
Return a string with the HTML code to display a button to export the history in CSV.
$value
static cmp_name(Fiche $o1, Fiche $o2)
used with a usort function, to sort an array of Fiche on the name
Definition: class_fiche.php:62
foreach($array as $idx=> $m) $w
$idx
get_row_date($p_from, $p_to, $op_let=0)
Get data for poste.
Display($p_readonly)
Display object instance, getAttribute sort the attribute and add missing ones.
static test_me()
build_sql($array)
create the sql statement for retrieving all the card
switch($ss_action) $f
get_amount_side($p_amount)
return the letter C if amount is > 0, D if < 0 or =
get_all_account()
size()
give the size of a card object
$from_div
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
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:153
seek($p_attribut, $p_value)
find the card with the p_attribut equal to p_value, it is not case sensitive
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:81
static warnbulle($p_comment)
static print_window()
Javascript to print the current window.
For the periode tables parm_periode and jrn_periode.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
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:622
get_quick_code()
return the quick_code of a card
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Summary($p_search="", $p_action="", $p_sql="", $p_amount=false)
show the default screen
static filter_table($p_table_id, $p_col, $start_row)
for($i=0;$i<$nb_jrn;$i++) $deb
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
function clone(object)
$select_cat
empty_attribute($p_attr)
check if an attribute is empty
static array_to_hidden($array, $global_array)
transform request data to hidden
$ac
Definition: action.inc.php:54
$_REQUEST['ac']
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
move_to($p_fdid)
move a card to another cat.
strAttribut($p_ad_id, $p_return=1)
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
Definition: ac_common.php:175
$input_from cn
Definition: balance.inc.php:71
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
$all
$uniq
static id()
return the $_REQUEST['gDossier'] after a check
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
Definition: ac_common.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.
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
$count
Definition: modele.inc.php:255
static connect()
const ATTR_DEF_QUICKCODE
Definition: constant.php:206
$fiche_def_ref
Definition: class_fiche.php:50
foreach($Fiche->row as $op) $solde_type
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
load()
Synonum of fiche::getAttribut.
is_used()
check if a card is used
get_row_result($res)
fetch and return and array
$limit
Definition: dashboard.php:157
if(!isset($_GET['submit_query'])) $p_action
const ATTR_DEF_PAYS
Definition: constant.php:194
HtmlTable($p_array=null, $op_let=0, $from_div=1)
HtmlTable, display a HTML of a card for the asked period.
GetByDef($p_frd_id, $p_offset=-1, $p_search="", $p_order='')
Return array of card from the frd family.
const ATTR_DEF_NAME
Definition: constant.php:185
get_bk_account()
get the available bank_account filtered by the security
Definition: class_fiche.php:71
const ATTR_DEF_ACCOUNT
Definition: constant.php:184
static hidden($p_name, $p_value, $p_id="")
HtmlTableHeader($p_array=null)
Display HTML Table Header (button)
get_categorie()
get the fd_id of the card : fd_id, it set the attribute fd_id
const NOTFOUND
Definition: constant.php:114
get_solde_detail($p_cond="")
give the balance of an card
getName()
return the name of a card
$href
Definition: adm.inc.php:38
static show_reconcile($p_div, $let, $span="")
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: class_idate.php:31
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40