noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
fiche_def.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
20require_once NOALYSS_INCLUDE.'/lib/user_common.php';
21
22/*! \file
23 * \brief define Class fiche and fiche def, those class are using
24 * class attribut
25 */
26/*!
27 * \brief define Class fiche and fiche def, those class are using
28 * class attribut
29 */
31{
32 var $cn; //!< database connection
33 var $id; //!< id (fiche_def.fd_id
34 var $label; //!< fiche_def.fd_label
35 var $class_base; //!< fiche_def.fd_class_base
36 var $fiche_def; //!< fiche_def.frd_id = fiche_def_ref.frd_id
37 var $create_account; //!< fd_create_account: flag
38 var $all;
39 var $attribut; //!< get from attr_xxx tables
40 var $fd_description; //!< Description of the Card Category
41
42 function __construct($p_cn,$p_id = 0)
43 {
44 $this->cn=$p_cn;
45 $this->id=$p_id;
46
47
48 }
49
50 public function __toString(): string
51 {
52 return "fiche_def".print_r($this,true);
53 }
54
55 /*!\brief show the content of the form to create a new Fiche_Def_Ref
56 */
57 function input ()
58 {
59
60 return;
61 }
62
63 /*!
64 * \brief Get attribut of a fiche_def
65 *
66 * \return array of Card_Property
67 */
68 function getAttribut()
69 {
70 $sql="select * from jnt_fic_attr ".
71 " natural join attr_def where fd_id= $1".
72 " order by jnt_order";
73
74 $Ret=$this->cn->exec_sql($sql,[$this->id]);
75
76 if ( ($Max=Database::num_row($Ret)) == 0 )
77 return ;
78 for ($i=0;$i < $Max;$i++)
79 {
81 $t = new Card_Property($this->cn);
82 $t->ad_id=$row['ad_id'];
83 $t->ad_text=$row['ad_text'];
84 $t->av_text="";
85 $t->jnt_order=$row['jnt_order'];
86 $t->ad_size=$row['ad_size'];
87 $t->ad_type=$row['ad_type'];
88 $t->ad_extra=$row['ad_extra'];
89 $this->attribut[$i]=clone $t;
90 }
91 return $this->attribut;
92 }
93
94 /**
95 * @brief alias for Fiche_Def->get(),
96 * @return void
97 */
98 function load():void
99 {
100 $this->get();
101 }
102 /*!
103 * \brief Get attribut of the fiche_def
104 *
105 */
106 function get()
107 {
108 if ( $this->id == 0 )
109 return 0;
110 /* $this->cn->exec_sql('select fiche_attribut_synchro($1)',
111 array($this->id));
112 */
113 $sql="select * from fiche_def ".
114 " where fd_id= $1";
115 $Ret=$this->cn->exec_sql($sql,[$this->id]);
116 if ( ($Max=Database::num_row($Ret)) == 0 )
117 return ;
119 $this->label=$row['fd_label'];
120 $this->class_base=$row['fd_class_base'];
121 $this->fiche_def=$row['frd_id'];
122 $this->create_account=($row['fd_create_account']=='f')?false:true;
123 $this->fd_description=$row['fd_description'];
124 }
125 /*!
126 * \brief Get all the fiche_def
127 *
128 * \return an array of fiche_def object
129 */
130 function get_all()
131 {
132 $sql="select * from fiche_def ";
133
134 $Ret=$this->cn->exec_sql($sql);
135 if ( ($Max=Database::num_row($Ret)) == 0 )
136 return array();
137 $all=array();
138 for ( $i = 0; $i < $Max;$i++)
139 {
141 $all[$i]=new Fiche_Def($this->cn,$row['fd_id']);
142 $all[$i]->label=$row['fd_label'];
143 $all[$i]->class_base=$row['fd_class_base'];
144 $all[$i]->fiche_def=$row['frd_id'];
145 $all[$i]->create_account=$row['fd_create_account'];
146 }
147 return $all;
148 }
149 /*!
150 **************************************************
151 * \brief Check in vw_fiche_def if a fiche has
152 * a attribut X
153 *
154 *
155 * \param $p_attr attribut to check
156 * \return true or false
157 */
158 function HasAttribute($p_attr)
159 {
160 return ($this->cn->count_sql("select * from vw_fiche_def where ad_id=$p_attr and fd_id=".$this->id)>0)?true:false;
161
162 }
163 /*!
164 **************************************************
165 * \brief Display all card categories into a table
166 *
167 * \return HTML row
168 */
169 function display()
170 {
171 $tab = new Sort_Table();
172
173 $url = HtmlInput::get_to_string(array('ac', 'gDossier'));
174 $tab->add(_("Nom de fiche"), $url, "order by fd_label asc", "order by fd_label desc", "na", "nd");
175 $tab->add(_("Basé sur le poste comptable"), $url, "order by fd_class_base asc", "order by fd_class_base desc", "pa", "pd");
176 $tab->add(_("Calcul automatique du poste comptable"), $url, "order by fd_create_account asc", "order by fd_create_account desc", "ca", "cd");
177 $tab->add(_("Basé sur le modèle"), $url, "order by frd_text asc", "order by frd_text desc", "ma", "md");
178
179 $order = (isset($_GET['ord'])) ? $tab->get_sql_order($_GET["ord"]) : $tab->get_sql_order("na");
180
181
182 $res = $this->cn->exec_sql("SELECT fd_id, fd_class_base, fd_label, fd_create_account, fiche_def_ref.frd_id,
183frd_text , fd_description FROM fiche_def join fiche_def_ref on (fiche_def.frd_id=fiche_def_ref.frd_id)
184$order
185");
186
187 require_once NOALYSS_TEMPLATE.'/fiche_def-display.php';
188 }
189 /*!
190 * \brief Add a fiche category thanks the element from the array
191 * you cannot add twice the same cat. name
192 * table : insert into fiche_def
193 * insert into attr_def
194 *
195 * \param $array array
196 * index FICHE_REF
197 * nom_mod
198 * class_base
199 * fd_description
200 * create
201 */
202 function Add($array)
203 {
204 /**
205 * Check needed info
206 */
207 $http=new HttpInput();
208 $http->set_array($array);
209 $p_nom_mod = $http->extract('nom_mod',"string","");
210 $p_fd_description = $http->extract('fd_description',"string", "");
211
212 $p_fiche_def= $http->extract('FICHE_REF',"string", "");
213 $p_create= $http->extract('create',"string", "off");
214
215 // If there is no description then add a empty one
216 if ( ! isset ($p_fd_description)) {
217 $p_fd_description="";
218 }
219 // Format correctly the name of the cat. of card
220 $p_nom_mod=sql_string($p_nom_mod);
221
222
223 // Name can't be empty
224 if ( noalyss_strlentrim($p_nom_mod) == 0 )
225 {
226 alert (_('Le nom de la catégorie ne peut pas être vide'));
227 return 1;
228 }
229 // $p_fiche_def can't be empty
230 if ( noalyss_strlentrim($p_fiche_def) == 0 )
231 {
232 alert (_('Un modéle de catégorie est obligatoire'));
233 return 1;
234 }
235
236 /* check if the cat. name already exists */
237 $sql="select count(*) from fiche_Def where upper(fd_label)=upper($1)";
238 $count=$this->cn->get_value($sql,array(trim($p_nom_mod)));
239
240 if ($count != 0 ) {
241 alert (_('Catégorie existante'));
242 return 1;
243 }
244 $default_acc=$this->cn->get_value("select frd_class_base from fiche_def_ref where frd_id=$1",[$p_fiche_def]);
245
246 // if the account is empty, takes the account of the template from fiche_def_ref
247 $p_class_base=$http->extract('class_base',"string", "");
248 $p_class_base=(noalyss_trim($p_class_base)=='')?$default_acc:$p_class_base;
249
250 // Set the value of fiche_def.fd_create_account
251 // automatic creation for 'poste comptable'
252 if ( $p_create == "on" && noalyss_strlentrim($p_class_base) != 0)
253 $p_create='true';
254 else
255 $p_create='false';
256 $add_accounting=false;
257 // Class is valid ?
258 if ( sql_string($p_class_base) != null || ( $p_class_base !='' && strpos(',',$p_class_base) != 0 ))
259 {
260 // p_class is a valid number
261 $sql="insert into fiche_def(fd_label,fd_class_base,frd_id,fd_create_account,fd_description)
262 values ($1,$2,$3,$4,$5) returning fd_id";
263
264 $this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_class_base,$p_fiche_def,$p_create,$p_fd_description));
265
266 // p_class must be added to tmp_pcmn if it is a single accounting
267 if ( strpos(',',$p_class_base) ==0)
268 {
269 $sql="select account_add($1,$2)";
270 $Res=$this->cn->exec_sql($sql,array($p_class_base,$p_nom_mod));
271 }
272 // Get the fd_id
273 $fd_id=$this->cn->get_current_seq('s_fdef');
274
275// // update jnt_fic_attr
276// $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
277// values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
278// $Res=$this->cn->exec_sql($sql);
279 $add_accounting=true;
280 }
281 else
282 {
283 //There is no class base not even as default
284 $sql="insert into fiche_def(fd_label,frd_id,fd_create_account,fd_description) values ($1,$2,$3,$4) returning fd_id";
285
286
287 $this->id=$this->cn->get_value($sql,array($p_nom_mod,$p_fiche_def,$p_create,$p_fd_description));
288
289 // Get the fd_id
290 $fd_id=$this->cn->get_current_seq('s_fdef');
291
292 }
293
294 // Get the default attr_def from attr_min
295 $def_attr=$this->get_attr_min($p_fiche_def);
296
297 //if defaut attr not null
298 // build the sql insert for the table attr_def
299 $add_qcode=true;
300 if (sizeof($def_attr) != 0 )
301 {
302 // insert all the mandatory fields into jnt_fiche_attr
303 foreach ( $def_attr as $row)
304 {
305
306 $count=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1 and ad_id=$2",array($fd_id,$row['ad_id']));
307 if ($count == 0)
308 {
309 $sql=sprintf("insert into jnt_fic_Attr(fd_id,ad_id,jnt_order)
310 values (%d,%s,%d)",
311 $fd_id,$row['ad_id'],$row['ad_default_order']);
312 $this->cn->exec_sql($sql);
313 }
314 // if there is an accounting , then not needed to add one
315 if ( $row['ad_id']==ATTR_DEF_ACCOUNT) $add_accounting=FALSE;
316 if ( $row['ad_id']==ATTR_DEF_QUICKCODE) $add_qcode=FALSE;
317 }
318 }
319 // if there is an base accounting, and the accounting is not in ATTR_MIN,
320 // then it is needed to add it
321 if ( $add_accounting) {
322 $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
323 values (%d,%d,10)",$fd_id,ATTR_DEF_ACCOUNT);
324 $Res=$this->cn->exec_sql($sql);
325 }
326 // if there is no quick code in attr_min, it is added
327 if ( $add_qcode) {
328 $sql=sprintf("insert into jnt_fic_attr(fd_id,ad_id,jnt_order)
329 values (%d,%d,10000)",$fd_id,ATTR_DEF_QUICKCODE);
330 $Res=$this->cn->exec_sql($sql);
331 }
332 $this->id=$fd_id;
333 return 0;
334
335 }//--------------end function Add ----------------------------
336 /*!
337 * \brief Get all the card where the fiche_def.fd_id is given in parameter
338 * \param $step = 0 we don't use the offset, page_size,...
339 * $step = 1 we use the jnr_bar_nav
340 *
341 * \return array ('f_id'=>..,'ad_value'=>..)
342 *\see fiche
343 */
344 function get_by_type($step=0)
345 {
346 $sql="select f_id,ad_value
347 from
348 fiche join fiche_detail using(f_id)
349 where ad_id=1 and fd_id=$1 order by 2";
350
351 // we use navigation_bar
352 if ($step == 1 && $_SESSION[SESSION_KEY.'g_pagesize'] != -1 )
353 {
354 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
355 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
356 $sql.=" offset $offset limit $step";
357 }
358
359 $Ret=$this->cn->get_array($sql,array($this->id));
360
361 return $Ret;
362 }
363 /*!
364 * \brief Get all the card where the fiche_def.frd_id is given in parameter
365 * \return array of fiche or null is nothing is found
366 */
367 function get_by_category($p_cat)
368 {
369 $sql="select f_id,ad_value
370 from
371 fiche join fiche_def using(fd_id)
372 join fiche_detail using(f_id)
373 where ad_id=1 and frd_id=$1 order by 2 ";
374
375 $Ret=$this->cn->exec_sql($sql,array($p_cat));
376 if ( ($Max=Database::num_row($Ret)) == 0 )
377 return null;
378 $all[0]=new Fiche($this->cn);
379
380 for ($i=0;$i<$Max;$i++)
381 {
383 $t=new Fiche($this->cn,$row['f_id']);
384 $t->getAttribut();
385 $all[$i]=$t;
386
387 }
388 return $all;
389 }
390
391 /*!\brief list the card of a fd_id
392 */
393 function myList()
394 {
395 $this->get();
396 echo '<H2 class="info">'.$this->id." ".$this->label.'</H2>';
397
398 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
399 $sql_limit="";
400 $sql_offset="";
401 $bar="";
402 if ( $step != -1 )
403 {
404
405 $page=(isset($_GET['page']))?$_GET['page']:1;
406 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
407 $max_line=$this->cn->count_sql("select f_id,ad_value from
408 fiche join fiche_detail using (f_id)
409 where fd_id='".$this->id."' and ad_id=".ATTR_DEF_NAME." order by f_id");
410 $sql_limit=" limit ".$step;
411 $sql_offset=" offset ".$offset;
413 }
414
415 // Get all name the cards of the select category
416 // 1 for attr_def.ad_id is always the name
417 $Res=$this->cn->exec_sql("select f_id,vw_name,quick_code from ".
418 " vw_fiche_attr ".
419 " where fd_id='".$this->id.
420 "' order by f_id $sql_offset $sql_limit ");
422 echo $bar;
423 $str="";
424 // save the url
425 // with offet &offset=15&step=15&page=2&size=15
426 if ( $_SESSION[SESSION_KEY.'g_pagesize'] != -1)
427 {
428 $str=sprintf("&offset=%s&step=%s&page=%s&size=%s",
429 $offset,
430 $step,
431 $page,
432 $max_line);
433 }
434
435
436 echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
437 echo HtmlInput::hidden('ac',$_REQUEST['ac']);
438 echo dossier::hidden();
439 echo HtmlInput::hidden("fiche",$this->id);
440 echo HtmlInput::submit('add','Ajout fiche');
441 echo '</FORM>';
442 $str_dossier=dossier::get();
443 echo '<table>';
444 for ( $i = 0; $i < $Max; $i++)
445 {
447 if ( $i%2 == 0)
448 echo '<TR class="odd">';
449 else
450 echo '<TR class="even">';
451
452 $span_mod='<TD><A href="?p_action=fiche&'.$str_dossier.
453 '&action=detail&fiche_id='.$l_line['f_id'].$str.'&fiche='.
454 $_REQUEST['fiche'].'&ac='.$_REQUEST['ac'].'">'.$l_line['quick_code']
455 .'</A></TD>';
456
457 echo $span_mod.'<TD>'.h($l_line['vw_name'])."</TD>";
458 echo '</tr>';
459 }
460 echo '</table>';
461 echo '<FORM METHOD="POST" action="?p_action=fiche&action=vue'.$str.'">';
462 echo HtmlInput::hidden('ac',$_REQUEST['ac']);
463 echo dossier::hidden();
464 echo HtmlInput::hidden("fiche",$this->id);
465 echo HtmlInput::submit('add','Ajout fiche');
466 echo '</FORM>';
467 echo $bar;
468
469 }
470
471 /*!\brief Display all the attribut of the fiche_def
472 *\param $str give the action possible values are remove, empty
473 */
475 {
476 if ( $this->id == 0 )
477 return ;
478 $this->cn->exec_sql('select fiche_attribut_synchro($1)',array($this->id));
479
480 $MaxLine=sizeof($this->attribut);
481 $r="<TABLE>";
482 $r.="<tr>".th('Nom attribut').th('').th('Ordre','style="text-align:right"').'</tr>';
483 // Display each attribute
484 $add_action="";
485 for ($i=0;$i<$MaxLine;$i++)
486 {
487 $class="even";
488 if ( $i % 2 == 0 )
489 $class="odd";
490
491 $r.='<TR class="'.$class.'"><td>';
492 // Can change the name
493 if ( $this->attribut[$i]->ad_id == ATTR_DEF_NAME )
494 {
495 continue;
496 }
497 else
498 {
499 if ( $str == "remove" )
500 {
501 //Only for the not mandatory attribute (not defined in attr_min)
502 if ( $this->cn->count_sql("select * from attr_min where frd_id=".
503 $this->fiche_def." and ad_id = ".$this->attribut[$i]->ad_id) == 0
504 && $this->attribut[$i]->ad_id != ATTR_DEF_QUICKCODE
505 && $this->attribut[$i]->ad_id != ATTR_DEF_ACCOUNT
506 )
507 {
508 $add_action=sprintf( '</TD><TD> Supprimer <input type="checkbox" name="chk_remove[]" value="%d">',
509 $this->attribut[$i]->ad_id);
510 }
511 else
512 $add_action="</td><td>";
513 }
514 // The attribut.
515 $a=sprintf('%s ', $this->attribut[$i]->ad_text);
516 $r.=$a.$add_action;
517 /*---------------------------------------- */
518 /* ORDER OF THE CARD */
519 /*---------------------------------------- */
520 $order=new IText();
521 $order->name='jnt_order'.$this->attribut[$i]->ad_id;
522 $order->size=3;
523 $order->value=$this->attribut[$i]->jnt_order;
524 $r.='</td><td> '.$order->input();
525 }
526 $r.= '</td></tr>';
527 }
528
529 // Show the possible attribute which are not already attribute of the model
530 // of card
531 $Res=$this->cn->exec_sql("select ad_id,ad_text from attr_def
532 where
533 ad_id not in (select ad_id from fiche_def natural join jnt_fic_attr
534 where fd_id=$1) order by ad_text",array($this->id) );
536
537 // Show the unused attribute
538 $r.='<TR> <TD>';
539 $r.= '<SELECT NAME="ad_id">';
540 for ($i=0;$i<$M;$i++)
541 {
543 $a=sprintf('<OPTION VALUE="%s"> %s',
544 $l['ad_id'],$l['ad_text']);
545 $r.=$a;
546 }
547 $r.='</SELECT>';
548
549 $r.="</TABLE>";
550 return $r;
551 }
552 /*!\brief Save the label of the fiche_def
553 * \param $p_label label
554 */
555 function SaveLabel($p_label)
556 {
557 if ( $this->id == 0 ) return;
558 $p_label=sql_string($p_label);
559 if (strlen(trim ($p_label)) == 0 )
560 {
561 return;
562 }
563 $sql=sprintf("update fiche_def set fd_label='%s' ".
564 "where fd_id=%d",
565 $p_label,$this->id);
566 $Res=$this->cn->exec_sql($sql);
567
568 }
569 /*!\brief set the auto create accounting item for each card and
570 * save it into the database
571 * \param $p_label true or false
572 */
573 function set_autocreate($p_label)
574 {
575 if ( $this->id == 0 ) return;
576 if ($p_label==true)
577 $t='t';
578 if ($p_label==false)
579 $t='f';
580
581 $sql="update fiche_def set fd_create_account=$1 ".
582 "where fd_id=$2";
583
584 $Res=$this->cn->exec_sql($sql,array($t,$this->id));
585
586
587 }
588 /*!\brief Save the class base
589 * \param $p_label label
590 */
591 function save_class_base($p_label)
592 {
593 if ( $this->id == 0 ) return;
594 $p_label=sql_string($p_label);
595
596 $sql="update fiche_def set fd_class_base=$1 ".
597 "where fd_id=$2";
598
599 $Res=$this->cn->exec_sql($sql,array($p_label,$this->id));
600 }
601 function save_description($p_description)
602 {
603 if ( $this->id == 0) return;
604 $this->cn->exec_sql("update fiche_def set fd_description=$1 where fd_id=$2",array($p_description,$this->id));
605 }
606
607
608 /*!\brief insert a new attribut for this fiche_def
609 * \param $p_ad_id id of the attribut
610 * \param int $p_order order of the attribut if -1 then computed
611 */
612 function insertAttribut($p_ad_id,$p_order=-1)
613 {
614 if ( $this->id == 0 ) return;
615 /* ORDER */
616 $this->GetAttribut();
618 if ( $p_order == -1 ) {
619 $order = $this->cn->get_value("select ad_default_order from attr_def where ad_id=$1",[$p_ad_id]);
620 if ( $order == 0 || empty($order)) {
621 $max=$this->cn->get_value("select count(*) from jnt_fic_attr where fd_id=$1",[$this->id]);
622 $order=$max*15;
623 }
624 }
625 // Insert a new attribute for the model
626 // it means insert a row in jnt_fic_attr
627 $sql=sprintf("insert into jnt_fic_attr (fd_id,ad_id,jnt_order) values (%d,%d,%d)",
628 $this->id,$p_ad_id,$order);
629 $Res=$this->cn->exec_sql($sql);
630 }
631 /*!\brief remove an attribut for this fiche_def
632 * \param array of ad_id to remove
633 * \remark you can't remove the attribut defined in attr_min
634 */
636 {
637 foreach ($array as $ch)
638 {
639 $this->cn->start();
640 $sql="delete from jnt_fic_attr where fd_id=$1 ".
641 " and ad_id=$2";
642 $this->cn->exec_sql($sql,array($this->id,$ch));
643
644 $sql="delete from fiche_detail where jft_id in ( select ".
645 " jft_id from fiche_Detail ".
646 " join fiche using(f_id) ".
647 " where ".
648 "fd_id = $1 and ".
649 "ad_id=$2)";
650 $this->cn->exec_sql($sql,array($this->id,$ch));
651
652 $this->cn->commit();
653 }
654 }
655
656 /*!\brief save the order of a card, update the column jnt_fic_attr.jnt_order
657 *\param $p_array containing the order
658 */
660 {
661 extract($p_array, EXTR_SKIP);
662 $this->GetAttribut();
663 foreach ($this->attribut as $row)
664 {
665 if ( $row->ad_id == 1 ) continue;
666 if ( ${'jnt_order'.$row->ad_id} <= 0 ) continue;
667 $sql='update jnt_fic_attr set jnt_order=$1 where fd_id=$2 and ad_id=$3';
668 $this->cn->exec_sql($sql,array(${'jnt_order'.$row->ad_id},
669 $this->id,
670 $row->ad_id));
671
672 }
673 /* correct the order */
674 $this->cn->exec_sql('select attribute_correct_order()');
675 }
676
677
678 /*!\brief remove all the card from a categorie after having verify
679 *that the card is not used and then remove also the category
680 *\return the remains items, not equal to 0 if a card remains and
681 *then the category is not removed
682 */
683 function remove()
684 {
685 if ( $this->id >= 500000 ) {
686 throw new Exception(_('Catégorie verrouillée '));
687 }
688 $remain=0;
689 /* get all the card */
690 $aFiche=fiche::get_fiche_def($this->cn,$this->id);
691 if ( $aFiche != null )
692 {
693 /* check if the card is used */
694 foreach ($aFiche as $dfiche)
695 {
696 $fiche=new Fiche($this->cn,$dfiche['f_id']);
697
698 /* if the card is not used then remove it otherwise increment remains */
699 if ( $fiche->is_used() == false )
700 {
701 $fiche->delete();
702 }
703 else
704 $remain++;
705 }
706 }
707 /* if remains == 0 then remove cat */
708 if ( $remain == 0 )
709 {
710 $sql='delete from jnt_fic_attr where fd_id=$1';
711 $this->cn->exec_sql($sql,array($this->id));
712 $sql='delete from fiche_def where fd_id=$1';
713 $this->cn->exec_sql($sql,array($this->id));
714 }
715
716 return $remain;
717
718 }
719 /*!
720 * \brief retrieve the mandatory field of the card model
721 *
722 * \param $p_fiche_def_ref
723 * \return array of ad_id (attr_min.ad_id) and labels (attr_def.ad_text)
724 */
725 function get_attr_min($p_fiche_def_ref)
726 {
727
728 // find the min attr for the fiche_def_ref
729 $Sql="select ad_id,ad_text ,attr_min.ad_default_order
730 from attr_min
731 join attr_def using(ad_id)
732 join fiche_def_ref using(frd_id)
733 where
734 frd_id= $1 order by ad_default_order";
735 $Res=$this->cn->exec_sql($Sql,array($p_fiche_def_ref));
737
738 // test the number of returned rows
739 if ($Num == 0 ) return null;
740
741 // Get Results & Store them in a array
742 for ($i=0;$i<$Num;$i++)
743 {
745 $array[$i]['ad_id']=$f['ad_id'];
746 $array[$i]['ad_text']=$f['ad_text'];
747 $array[$i]['ad_default_order']=$f['ad_default_order'];
748 }
749 return $array;
750 }
751 /*!
752 * \brief count the number of fiche_def (category) which has the frd_id (type of category)
753 *\param $p_frd_id is the frd_id in constant.php the FICHE_TYPE_
754 *\return the number of cat. of card of the given type
755 *\see constant.php
756 */
757 function count_category($p_frd_id)
758 {
759 $ret=$this->cn->count_sql("select fd_id from fiche_def where frd_id=$1",array($p_frd_id));
760 return $ret;
761 }
762
763 /**
764 * @brief ask for detail
765 * @return string
766 */
767 function input_detail()
768 {
769 $r = "";
770 // Save the label
771
772 $this->get();
773 $this->GetAttribut();
774 $r.= '<H2 class="info">' . $this->id . " " . h($this->label) . '</H2>';
775 $r.='<fieldset><legend>'._('Données générales').'</legend>';
776
777 $nom_mod=$this->label;
778 /* the accounting item */
779 $class_base=new IPoste('class_base');
780 $class_base->set_attribute('ipopup','ipop_account');
781 $class_base->set_attribute('account','class_base');
782 $class_base->set_attribute('label','acc_label');
784 $f_class_base=$class_base->input();
785 $fd_description=new ITextarea('fd_description');
786 $fd_description->width=80;
787 $fd_description->heigh=4;
788 $fd_description->style='class="itextarea form-control input_text" style="margin-left:0px;vertical-align:text-top"';
790 $r.='<form method="post" style="display:inline">';
791 $r.=\HtmlInput::hidden('fd_id',$this->id);
792 ob_start();
793 require_once NOALYSS_TEMPLATE.'/fiche_def_input.php';
794 $r.=ob_get_contents();
795 ob_clean();
796 $r.=HtmlInput::submit('change_name', _('Sauver'));
797 $r.='</form>';
798 $r.='<form method="post" style="display:inline" id="catcard_remove" onsubmit="return confirm_box(this,\'Effacer?\')">';
799 $r.=HtmlInput::hidden("action", "remove_cat");
800 $r.=HtmlInput::hidden('fd_id',$this->id);
801 $r.=HtmlInput::submit('remove_cat', _('Effacer'));
802 $r.='</form>';
803
804 require NOALYSS_TEMPLATE.'/fiche_def-input_detail.php';
805
806 $r.='</fieldset>';
807 $r.='<hr>';
808 /* attributes */
809 $r.='<fieldset><legend>'._('Détails').'</legend>';
810
811 $r.= '<FORM id="input_detail_frm" method="POST">';
812 $r.=dossier::hidden();
813 $r.=HtmlInput::hidden("fd_id", $this->id);
814 $r.=HtmlInput::hidden("action", "");
815 // $r.= $this->DisplayAttribut("remove");
816 ob_start();
817 require NOALYSS_TEMPLATE."/fiche_def-input_detail-2.php";
818 $r.=ob_get_contents();
819 ob_clean();
820
821 $r.= "</form>";
822
823 $r.='</fieldset>';
824 return $r;
825 }
826
827
828 /**
829 * @brief input for creating a new category
830 * @return void
831 */
832 function input_new()
833 {
834 $single=new Single_Record("dup");
835 echo '<form method="post" style="display:inline" onsubmit="return check_new_category()">';
836 echo $single->hidden();
837 echo HtmlInput::hidden("p_action","fiche");
838 echo dossier::hidden();
839 $ref=$this->cn->get_array("select * from fiche_def_ref order by frd_text");
840 $iradio=new IRadio();
841 $nom_mod="";
842 /* the accounting item */
843 $class_base=new IPoste('class_base');
844 $class_base->set_attribute('ipopup','ipop_account');
845 $class_base->set_attribute('account','class_base');
846 $class_base->set_attribute('label','acc_label');
847 $f_class_base=$class_base->input();
848 $fd_description=new ITextarea('fd_description');
849 $fd_description->width=80;
850 $fd_description->heigh=4;
851 $fd_description->style='class="itextarea form-control input_text" style="margin-left:0px;vertical-align:text-top"';
852 require_once NOALYSS_TEMPLATE.'/fiche_def_input.php';
853 require_once NOALYSS_TEMPLATE.'/fiche_def-input_new.php';
854
855 echo HtmlInput::submit("add_modele" ,_("Sauve"));
856 echo '</FORM>';
857 }
858 /**
859 * @brief make an array of attributes of the category of card (FICHE_DEF.FD_ID)
860 *The array can be used with the function insert, it will return a struct like this :
861 * in the first key (av_textX), X is the ATTR_DEF::AD_ID
862 \verbatim
863 Example
864 Array
865 (
866 [av_text1] => Nom
867 [av_text12] => Personne de contact
868 [av_text5] => Poste Comptable
869 [av_text13] => numéro de tva
870 [av_text14] => Adresse
871 [av_text15] => code postal
872 [av_text24] => Ville
873 [av_text16] => pays
874 [av_text17] => téléphone
875 [av_text18] => email
876 [av_text23] => Quick Code
877 )
878
879 \endverbatim
880 *\param $pfd_id FICHE_DEF::FD_ID
881 *\return an array of attribute
882 *\exception Exception if the cat of card doesn't exist, Exception.getCode()=1
883 *\see fiche::insert()
884 */
885 function to_array()
886 {
887 $sql="select 'av_text'||to_char(ad_id,'9999') as key,".
888 " ad_text ".
889 " from fiche_def join jnt_fic_attr using (fd_id)".
890 " join attr_def using (ad_id) ".
891 " where fd_id=$1 order by jnt_order";
892 $ret=$this->cn->get_array($sql,array($this->id));
893 if ( empty($ret)) throw new Exception(_('Cette categorie de card n\'existe pas').' '.$this->id,1);
894 $array=array();
895 foreach($ret as $idx=>$val)
896 {
897 $a=noalyss_str_replace(' ','',$val['key']);
898 $array[$a]=$val['ad_text'];
899 }
900 return $array;
901
902 }
903
904 /**
905 * @brief display existing attribut
906 * @param $attribut_id int SQL attr_def.ad_id
907 * @param $attribut_text SQL attr_def.ad_text
908 * @return void
909 */
910 public static function print_existing_attribut($attribut_id,$attribut_text)
911 {
912 include NOALYSS_TEMPLATE.'/fiche_def-print_existing_attribut.php';
913 }
914
915 /**
916 * @brief display available attribut
917 * @param $attribut_id int SQL attr_def.ad_id
918 * @param $attribut_text SQL attr_def.ad_text
919 * @return void
920 */
921 public static function print_available_attribut($attribut_id,$attribut_text,$class)
922 {
923 include NOALYSS_TEMPLATE.'/fiche_def-print_available_attribut.php';
924 }
925}
926?>
noalyss_strlentrim($p_string)
noalyss_str_replace($search, $replace, $string)
sql_string($p_string)
Fix the problem with the quote char for the database.
noalyss_trim($p_string)
alert($p_msg, $buffer=false)
alert in javascript
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$ret label
$_REQUEST['ac']
$str_dossier
$input_from cn
_("actif, passif,charge,...")
$_GET['qcode']
contains the attributes of a card , manage them, save them , ...
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
define Class fiche and fiche def, those class are using class attribut
static print_existing_attribut($attribut_id, $attribut_text)
display existing attribut
save_description($p_description)
input()
show the content of the form to create a new Fiche_Def_Ref
load()
alias for Fiche_Def->get(),
$id
id (fiche_def.fd_id
getAttribut()
Get attribut of a fiche_def.
save_class_base($p_label)
Save the class base.
Add($array)
Add a fiche category thanks the element from the array you cannot add twice the same cat....
DisplayAttribut($str="")
Display all the attribut of the fiche_def.
$cn
database connection
to_array()
make an array of attributes of the category of card (FICHE_DEF.FD_ID) The array can be used with the ...
get_by_type($step=0)
Get all the card where the fiche_def.fd_id is given in parameter.
myList()
list the card of a fd_id
__construct($p_cn, $p_id=0)
display()
Display all card categories into a table.
count_category($p_frd_id)
count the number of fiche_def (category) which has the frd_id (type of category)
get_by_category($p_cat)
Get all the card where the fiche_def.frd_id is given in parameter.
get_attr_min($p_fiche_def_ref)
retrieve the mandatory field of the card model
$attribut
get from attr_xxx tables
$fiche_def
fiche_def.frd_id = fiche_def_ref.frd_id
removeAttribut($array)
remove an attribut for this fiche_def
insertAttribut($p_ad_id, $p_order=-1)
insert a new attribut for this fiche_def
$fd_description
Description of the Card Category.
$create_account
fd_create_account: flag
$class_base
fiche_def.fd_class_base
HasAttribute($p_attr)
Check in vw_fiche_def if a fiche has a attribut X.
input_new()
input for creating a new category
set_autocreate($p_label)
set the auto create accounting item for each card and save it into the database
input_detail()
ask for detail
save_order($p_array)
save the order of a card, update the column jnt_fic_attr.jnt_order
static print_available_attribut($attribut_id, $attribut_text, $class)
display available attribut
get_all()
Get all the fiche_def.
$label
fiche_def.fd_label
SaveLabel($p_label)
Save the label of the fiche_def.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
manage the http input (get , post, request) and extract from an array
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input.
Html Input.
Manage the TEXTAREA html element.
Objec to check a double insert into the database, this duplicate occurs after a refresh of the web pa...
Description of class_syn_sort_table.
$t
Definition compute.php:46
const ATTR_DEF_NAME
Definition constant.php:216
const ATTR_DEF_QUICKCODE
Definition constant.php:237
const ATTR_DEF_ACCOUNT
Definition constant.php:215
$count
$str
Definition fiche.inc.php:91
$fd_id
catch(\Exception $e) $bar
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)