noalyss Version-9
periode.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/*!\file
24 * \brief definition of the class periode
25 */
26/*!
27 * \brief For the periode tables parm_periode and jrn_periode
28 */
29require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
30require_once NOALYSS_INCLUDE."/database/parm_periode_sql.class.php";
31
33{
34
35 var $cn; /*!< database connection */
36 var $jrn_def_id; /*!< the jr, 0 means all the ledger */
37 var $p_id; /*!< pk of parm_periode */
38 var $status; /*!< status is CL for closed, OP for
39 open and CE for centralized */
40 var $p_start; /*!< start of the periode */
41 var $p_end; /*!< end of the periode */
42 var $p_exercice ; /*!< exercice */
43 var $p_closed ; /*!< if exercice is closed */
44 var $p_central ; /*!< NOT USED */
45 var $p_exercice_label ; /*!< Label of the exercice */
46 function __construct($p_cn, $p_id=0)
47 {
48 $this->p_id=$p_id;
49 $this->cn=$p_cn;
50 $this->jrn_def_id=0;
51 }
52
53 public function __toString(): string
54 {
55 $r=<<<EOF
56Object Periode [
57 \$jrn_def_id=>$this->jrn_def_id,
58 \$p_id=>$this->p_id,
59 \$status => $this->status,
60 \$p_start => $this->p_start,
61 \$p_end => $this->p_end,
62]
63EOF;
64 return $r;
65
66 }
67
69 {
70 $this->jrn_def_id=$p_jrn;
71 }
72
73 function set_periode($pp_id)
74 {
75 $this->p_id=$pp_id;
76 }
77
78 /**
79 * \brief return the p_id of the start and the end of the exercice
80 * into an array
81 * \param $p_exercice
82 * \return array [start]=>,[end]=>
83 */
84
86 {
87 $sql_start="select p_id from parm_periode where p_exercice=$1 order by p_start ASC limit 1";
88 $start=$this->cn->get_value($sql_start, array($p_exercice));
89 $sql_end="select p_id from parm_periode where p_exercice=$1 order by p_end DESC limit 1";
90 $end=$this->cn->get_value($sql_end, array($p_exercice));
91 return array("start"=>$start, "end"=>$end);
92 }
93
94 /*!
95 * \brief check if a periode is closed. If jrn_def_id is set to a no zero value then check only for this ledger
96 * @see Periode::set_ledger
97 * \return 1 is the periode is closed otherwise return 0
98 */
99
100 function is_closed()
101 {
102 if ($this->jrn_def_id!=0)
103 $sql="select status from jrn_periode ".
104 " where jrn_def_id=".$this->jrn_def_id.
105 " and p_id =".$this->p_id;
106 else
107 $sql="select p_closed as status from parm_periode ".
108 " where ".
109 " p_id =".$this->p_id;
110 $res=$this->cn->exec_sql($sql);
111 $status=Database::fetch_result($res, 0, 0);
112 if ($status=='CL'||$status=='t'||$status=='CE')
113 return 1;
114 return 0;
115 }
116
117 ///Return 1 if the periode is open otherwise 0
118 //!\note For only a ledger you must set Periode::jrn_def_id to the ledger id
119 ///@see Periode::set_ledger
120 function is_open()
121 {
122 /* if jrn_Def_id == 0 then we check the global otherwise we check
123 a ledger */
124 if ($this->jrn_def_id!=0){
125 $sql="select status from jrn_periode ".
126 " where jrn_def_id=$1 ".
127 " and p_id = $2";
128 $status=$this->cn->get_value($sql,[$this->jrn_def_id,$this->p_id]);
129 }
130 else {
131 $sql="select p_closed as status from parm_periode ".
132 " where ".
133 " p_id = $1 ";
134 $status=$this->cn->get_value($sql,[$this->p_id]);
135 }
136
137 if ($status=='OP'||$status=='f') return 1;
138 return 0;
139 }
140
141 ///Return 1 if periode is centralized
142 ///@deprecated
143 //!\note deprecated , centralization not used anymore
144 function is_centralized()
145 {
146 if ($this->jrn_def_id!=0)
147 $sql="select status from jrn_periode ".
148 " where jrn_def_id=".$this->jrn_def_id.
149 " and p_id =".$this->p_id;
150 else
151 $sql="select p_centralized as status from parm_periode ".
152 " where ".
153 " p_id =".$this->p_id;
154 $res=$this->cn->exec_sql($sql);
155 $status=Database::fetch_result($res, 0, 0);
156 if ($status=='CE'||$status=='t')
157 return 1;
158 return 0;
159 }
160
161 function reopen()
162 {
163 if ($this->jrn_def_id==0)
164 {
165 $this->cn->exec_sql("update parm_periode set p_closed='f',p_central='f' where p_id=$1",
166 array($this->p_id));
167
168 $this->cn->exec_sql("update jrn_periode set status='OP' ".
169 " where p_id = $1", [$this->p_id]);
170
171 return;
172 }
173 else
174 {
175 $this->cn->exec_sql("update jrn_periode set status='OP'
176 where jrn_def_id=$1 and
177 p_id = $2 ", [$this->jrn_def_id, $this->p_id]);
178 /* if one ledger is open then the periode is open */
179 $this->cn->exec_sql("update parm_periode set p_closed=false where p_id=".$this->p_id);
180 return;
181 }
182 }
183
184 ///Close a periode , if Periode::jrn_def_id is set to a different value
185 /// than 0 , it close only for this ledger id ; otherwise close for all
186 /// periode
187 function close()
188 {
189 if ($this->jrn_def_id==0)
190 {
191 $this->cn->exec_sql("update parm_periode set p_closed=true where p_id=$1",
192 [$this->p_id]);
193 $this->cn->exec_sql("update jrn_periode set status='CL'
194 where p_id = $1", [$this->p_id]);
195
196 return;
197 }
198 else
199 {
200 $this->cn->exec_sql("update jrn_periode set status='CL' ".
201 " where jrn_def_id=$1 and
202 p_id = $2", [$this->jrn_def_id, $this->p_id]);
203 /* if all ledgers have this periode closed then synchro with
204 the table parm_periode
205 */
206 $nJrn=$this->cn->count_sql("select * from jrn_periode where ".
207 " p_id=$1", [$this->p_id]);
208 $nJrnPeriode=$this->cn->count_sql("select * from jrn_periode where ".
209 " p_id=$1 and status='CL'", [$this->p_id]);
210
211 if ($nJrnPeriode==$nJrn)
212 $this->cn->exec_sql("update parm_periode set p_closed=true where p_id=$1",
213 [$this->p_id]);
214 return;
215 }
216 }
217 /**
218 * @deprecated since version 5
219 * @return type
220 */
221 function centralized()
222 {
223 if ($this->jrn_def_id==0)
224 {
225 $this->cn->exec_sql("update parm_periode set p_central=true");
226 return;
227 }
228 else
229 {
230 $this->cn->exec_sql("update jrn_periode set status='CE' ".
231 " where ".
232 " p_id = $1", [$this->p_id]);
233 return;
234 }
235 }
236 /**
237 * Add new periode
238 * @param date $p_date_start
239 * @param date $p_date_end
240 * @param int $p_exercice
241 * @return int p_id of the new periode
242 * @exception Exception 10 Invalide date or exercice, 20 overlapping periode
243 */
244 function insert($p_date_start, $p_date_end, $p_exercice,$p_exercice_label)
245 {
246 try
247 {
248
249 if (isDate($p_date_start)==null ||
250 isDate($p_date_end)==null ||
252 isNumber($p_exercice) ==0 ||
255 {
256 throw new Exception(_("Paramètre invalide"),10);
257 }
258 $overlap_start=$this->cn->get_value("select count(*) from parm_periode
259 where
260 p_start <= to_date($1,'DD-MM-YYYY')
261 and p_end >= to_date($1,'DD-MM-YYYY')
262
263 ",[$p_date_start]);
264 $overlap_end=$this->cn->get_value("select count(*) from parm_periode
265 where
266 p_start <= to_date($1,'DD-MM-YYYY')
267 and p_end >= to_date($1,'DD-MM-YYYY')
268
269 ",[$p_date_end]);
270 if ( $overlap_start > 0 || $overlap_end > 0)
271 {
272 throw new Exception (_("Période chevauchant une autre"),20);
273 }
274 $p_id=$this->cn->get_next_seq('s_periode');
275 $sql=" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice,p_exercice_label)
276 values
277 ($1,
278 to_date($2,'DD.MM.YYYY'),
279 to_date($3,'DD.MM.YYYY'),
280 'f',
281 $4,$5)";
282
283 $this->cn->start();
284 $Res=$this->cn->exec_sql($sql,[$p_id, $p_date_start, $p_date_end, $p_exercice,$p_exercice_label]);
285 $Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ".
286 "select jrn_def_id,$p_id,'OP' from jrn_def");
287 $this->cn->commit();
288 return $p_id;
289 }
290 catch (Exception $e)
291 {
292 record_log($e->getMessage()." - ".$e->getCode());
293 record_log($e);
294 $this->cn->rollback();
295 throw $e;
296 }
297 }
298
299 /*!\brief load data from database
300 * \return 0 on success and -1 on error
301 */
302
303 function load():int
304 {
305 if ($this->p_id=='')
306 $this->p_id=-1;
307 $row=$this->cn->get_array("select p_start,p_end,p_exercice,p_closed,p_central,p_exercice_label from parm_periode where p_id=$1",
308 array($this->p_id));
309 if ($row==null)
310 return -1;
311
312 $this->p_start=$row[0]['p_start'];
313 $this->p_end=$row[0]['p_end'];
314 $this->p_exercice=$row[0]['p_exercice'];
315 $this->p_exercice_label=$row[0]['p_exercice_label'];
316 $this->p_closed=$row[0]['p_closed'];
317 $this->p_central=$row[0]['p_central'];
318 return 0;
319 }
320
321 /*!\brief return the max and the min periode of the exercice given
322 * in parameter
323 * \param $p_exercice is the exercice
324 * \return an array of Periode object
325 */
326
328 {
329
330 $max=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start asc limit 1",
331 array($p_exercice));
332 $min=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start desc limit 1",
333 array($p_exercice));
334 $rMax=new Periode($this->cn);
335 $rMax->p_id=$max;
336 if ($rMax->load() == -1)
337 throw new Exception('Periode n\'existe pas');
338 $rMin=new Periode($this->cn);
339 $rMin->p_id=$min;
340 if ($rMin->load() == -1)
341 throw new Exception('Periode n\'existe pas');
342 return array($rMax, $rMin);
343 }
344
345 /*!
346 * \brief Give the start & end date of a periode
347 * \param $p_periode is the periode id, if omitted the value is the current object
348 * \return array containing the start date & the end date, index are p_start and p_end or NULL if
349 * nothing is found
350 \verbatim
351 $ret['p_start']=>'01.01.2009'
352 $ret['p_end']=>'31.01.2009'
353 \endverbatim
354 */
355
356 public function get_date_limit($p_periode=0)
357 {
358 if ($p_periode==0)
359 $p_periode=$this->p_id;
360 $sql="select to_char(p_start,'DD.MM.YYYY') as p_start,
361 to_char(p_end,'DD.MM.YYYY') as p_end
362 from parm_periode
363 where p_id=$1";
364 $Res=$this->cn->exec_sql($sql, array($p_periode));
365 if (Database::num_row($Res)==0)
366 return null;
367 return Database::fetch_array($Res, 0,PGSQL_BOTH);
368 }
369
370 /*!\brief return the first day of periode
371 * the this->p_id must be set
372 * \return a string with the date (DD.MM.YYYY)
373 */
374
375 public function first_day($p=0)
376 {
377 if ($p==0)
379 list($p_start, $p_end)=$this->get_date_limit($p);
380 return $p_start;
381 }
382
383 /*!\brief return the last day of periode
384 * the this->p_id must be set
385 * \return a string with the date (DD.MM.YYYY)
386 */
387
388 public function last_day($p=0)
389 {
390 if ($p==0)
392 list($p_start, $p_end)=$this->get_date_limit($p);
393 return $p_end;
394 }
395
396 function get_exercice($p_id=0)
397 {
398 if ($p_id==0)
400 $sql="select p_exercice from parm_periode where p_id=$1";
401 $Res=$this->cn->exec_sql($sql,[$p_id]);
402 if (Database::num_row($Res)==0)
403 return null;
404 return Database::fetch_result($Res, 0, 0);
405 }
406
407 /*!\brief retrieve the periode thanks the date_end
408 * \param $p_date format DD.MM.YYYY
409 * \return the periode id
410 * \exception if not periode is found or if more than one periode is found
411 */
412
414 {
415 $sql="select p_id from parm_periode where p_start <= to_date($1,'DD.MM.YYYY') and p_end >= to_date($1,'DD.MM.YYYY') ";
416 $ret=$this->cn->exec_sql($sql, array($p_date));
417 $nb_periode=Database::num_row($ret);
418 if ($nb_periode==0)
419 throw (new Exception(_('Aucune période trouvée')." $p_date ", 101));
420 if ($nb_periode>1)
421 throw (new Exception(sprintf(_("Trop de périodes trouvées %s pour %s"),$nb_periode,$p_date),
422 100));
424 $this->p_id=$per;
425 return $per;
426 }
427
428 /**
429 * add a exercice starting in year p_year with p_month month, with a starting
430 * and a closing
431 * @param $p_exercice the exercice
432 * @param $p_year the starting year
433 * @param $p_from_month starting month
434 * @param $p_month number of month of the exercice
435 * @param $p_opening 1 if we create a one-day periode for opening writings
436 * @param $p_closing 1 if we create a one-day periode for closing writings
437 * @param $p_exercice_label label of the exercice
438 */
439 function insert_exercice($p_exercice, $p_year, $p_from_month, $p_month,
440 $p_opening, $p_closing,$p_exercice_label)
441 {
442 try
443 {
444 if (isNumber($p_exercice)==0)
445 throw new Exception(_("Exercice n'est pas un nombre"));
446
448 throw new Exception(sprintf(_("Exercice doit être entre %s et %s "), COMPTA_MIN_YEAR,
450 if (isNumber($p_year)==0)
451 throw new Exception(_("Année n'est pas un nombre"));
452
453 if ($p_year>COMPTA_MAX_YEAR||$p_year<COMPTA_MIN_YEAR)
454 throw new Exception(sprintf(_("Année doit être entre %s et %s "), COMPTA_MIN_YEAR,
456
457 if (isNumber($p_month)==0)
458 throw new Exception(_("Nombre de mois n'est pas un nombre"));
459 if ($p_month<1||$p_month>60)
460 throw new Exception(_("Nombre de mois doit être compris entre 1 & 60 "));
461 if (isNumber($p_month)==0)
462 throw new Exception(_("Mois de début n'existe pas "));
463 if ($p_from_month>13||$p_from_month<1)
464 throw new Exception(_("Mois de début n'existe pas "));
465 if ( empty($p_exercice_label)) {
467 }
468 $this->cn->start();
469 $year=$p_year;
470 $month=$p_from_month;
471 for ($i=1; $i<=$p_month; $i++)
472 {
473
474 // create first a periode of day
475 if ($i==1&&$p_opening==1)
476 {
477 $fdate_start=sprintf('01.%02d.%d', $month, $year);
478 $this->insert($fdate_start, $fdate_start, $p_exercice,$p_exercice_label);
479
480 $date_start=sprintf('02.%02d.%d', $month, $year);
481 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
482 array($fdate_start));
483
484 $this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
485 }
486 // The last month, we create a one-day periode for closing
487 elseif ($i==$p_month && $p_closing ==1 )
488 {
489 $fdate_start=sprintf('01.%02d.%d', $month, $year);
490 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '2 day','DD.MM.YYYY')",
491 array($fdate_start));
492 $this->insert($fdate_start, $date_end, $p_exercice,$p_exercice_label);
493
494 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
495 array($fdate_start));
496
497 $this->insert($date_end, $date_end, $p_exercice,$p_exercice_label);
498
499 }
500 else
501 {
502 $date_start=sprintf('01.%02d.%d', $month, $year);
503 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
504 array($date_start));
505 $this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
506 }
507 $month++;
508 if ($month == 13 )
509 {
510 $year++;
511 $month=1;
512 }
513 }
514
515 $this->cn->commit();
516 }
517 catch (Exception $e)
518 {
519 record_log($e);
520 $this->cn->rollback();
521 throw $e;
522 }
523 }
524
525 /**
526 * Display a table with all the periode
527 * @param $p_js javascript variable
528 * @see noalyss_script.js
529 */
530 static function display_periode_global($p_js)
531 {
533 $periode=new Parm_Periode_SQL($cn);
534 $ret=$periode->seek(" order by p_start asc");
535 $nb_periode=Database::num_row($ret);
536
537 if ($nb_periode==0)
538 return;
539 echo '<table class="result" id="periode_tbl">';
540 echo "<thead>";
541 echo "<tr>";
542 echo th("");
543 echo th(_("Date Début"));
544 echo th(_("Date Fin"));
545 echo th(_("Exercice"));
546 echo th(_("Libellé"),'class="visible_gt800"');
547 echo th(_("nb opérations"));
548 echo th(_("Status"));
549 echo "</tr>";
550 echo "</thead>";
551 echo '<tbody>';
552
553 for ($i=0; $i<$nb_periode; $i++)
554 {
555 $obj=$periode->next($ret, $i);
557 }
558 echo '</tbody>';
559 echo '</table>';
560 }
561
562 /**
563 * count the number of operation of a Periode
564 * @return integer
565 */
567 {
568 $count=$this->cn->get_value("
569 select count(*)
570 from
571 jrn
572 where
573 jr_tech_per = $1", [$this->p_id]);
574 return $count;
575 }
576
577 /**
578 * @brief Display each row for the global
579 * @param $obj Parm_Periode_SQL
580 * @param $p_nb not used so far
581 * @param $p_js javascript variable
582 */
583 static function display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
584 {
585 $periode=new Periode($obj->cn, $obj->p_id);
586 $class=($p_nb%2==0)?"even":"odd";
587 printf('<tr id="row_per_%d" customkey="%s" per_exercice="%s" p_id="%s" class="%s"> ',
588 $obj->getp("p_id"),
589 $obj->getp("p_start"),
590 $obj->getp("p_exercice"),
591 $obj->getp("p_id"), $class);
592 /**
593 * Display a checkbox to select several month to close
594 */
595 if ($obj->getp("p_closed")=="f")
596 {
597 $checkbox=new ICheckBox("sel_per_close[]");
598 $checkbox->set_range("sel_per_close_ck");
599 $checkbox->set_attribute("per_id", $obj->getp("p_id"));
600 $checkbox->value=$obj->getp("p_id");
601 echo "<td>".$checkbox->input()."</td>";
602 }
603 else
604 {
605 echo td("");
606 }
607 echo td(format_date($obj->getp("p_start"), "YYYY-MM-DD", "DD.MM.YYYY"));
608 echo td(format_date($obj->getp("p_end"), "YYYY-MM-DD", "DD.MM.YYYY"));
609 echo td($obj->getp("p_exercice"));
610 echo td($obj->getp("p_exercice_label"),'class="visible_gt800"');
611 $nb_operation=$periode->count_operation();
612 echo td($nb_operation);
613 $closed=$obj->getp('p_closed');
614 $status=($closed=='t')?_("Fermée"):_("Ouvert");
615 echo td($status);
616
617 // if no operation then this periode can be removed or updated
618 if ($nb_operation==0)
619 {
620 // Updatable
621 $js=sprintf("%s.box_display('%d')", $p_js, $obj->p_id);
622 echo "<td>";
623 echo Icon_Action::modify(uniqid(), $js);
624 echo "</td>";
625 //removable
626 $js=sprintf("%s.remove('%d')", $p_js, $obj->p_id);
627 echo "<td>";
628 echo Icon_Action::trash(uniqid(), $js);
629 echo "</td>";
630 }
631 else
632 {
633 echo td(""), td("");
634 }
635
636 /// Can close if open
637 echo "<td>";
638 if ($obj->getp("p_closed")=='f')
639 {
640 $javascript=sprintf('%s.close_periode(\'%d\')', $p_js, $obj->p_id);
641 echo Icon_Action::iconon(uniqid(), $javascript);
642 }
643 else
644 {
645 $javascript=sprintf("%s.open_periode('%d')", $p_js, $obj->p_id);
646 echo Icon_Action::iconoff(uniqid(),$javascript );
647 }
648 echo "</td>";
649 echo "</tr>";
650 }
651
652 /**
653 * @brief display a form (method POST) to input a new exercice
654 * variable in the FORM
655 * - p_exercice
656 * - p_year
657 * - nb_month
658 * - from_month
659 * - day_opening
660 * - day_closing
661 * - p_exercice_label
662 */
663 static function form_exercice_add()
664 {
666 $exercice=new INum('p_exercice');
667 $exercice->prec=0;
668 $exercice->value=$cn->get_value('select max(p_exercice::float)+1 from parm_periode');
669 $year=new INum('p_year');
670 $year->prec=0;
671 $year->value=$exercice->value;
672 $nb_month=new INum('nb_month');
673 $nb_month->prec=0;
674 $nb_month->value=12;
675 $from=new ISelect('from_month');
676 $amonth=array();
677 $month=[_('Janvier'), _('Février'), _('Mars'), _('Avril'),
678 _('Mai'), _('Juin'), _('Juillet'), _('Août'), _('Septembre'),
679 _('Octobre'), _('Novembre'), _('Décembre')];
680 for ($i=1; $i<13; $i++)
681 {
682 $strMonth=$month[($i-1)];
683 $amonth[]=array("value"=>$i, "label"=>$strMonth);
684 }
685 $from->value=$amonth;
686 $day_opening=new ICheckBox("day_opening");
687 $day_closing=new ICheckBox("day_closing");
688 $day_closing->value=1;
689 $day_opening->value=1;
690 $day_closing->set_check(1);
691 $exercice_label=new IText("p_exercice_label");
692 require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
693 }
694 /**
695 * @brief form to change the label of exercice
696 */
697 static function form_exercice_label()
698 {
700 require_once NOALYSS_TEMPLATE."/periode-form_exercice_label.php";
701 }
702 function delete() {
703 $this->cn->exec_sql("delete from parm_periode where p_id=$1",[$this->p_id]);
704 }
705 /**
706 * Verify before delete that the month is not used
707 * @exception Exception code 1 if periode used
708 */
709 function verify_delete() {
710 try {
711 if ( $this->cn->get_value("select count(*) from jrn where jr_tech_per =$1 ",[$this->p_id]) > 0) {
712 throw new Exception(_("Effacement impossible"), 1);
713 }
714 } catch (Exception $ex) {
715 throw $ex;
716 }
717 }
718 /**
719 * @brief Display a form for the input of a new periode
720 */
721 static function form_periode_add($p_js_var)
722 {
723 $http=new \HttpInput();
725 $p_exercice=new ISelect('p_exercice');
726 $p_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc");
727 $title=_('Ajout période');
728 $title_par="<p>"._('On ne peut ajouter une période que sur un exercice qui existe déjà').
729 "</p>";
730
731 $p_start=new IDate('p_start');
732 $p_end=new IDate('p_end');
733
734 $html='';
735 $html.=HtmlInput::title_box($title, 'periode_add','hide');
736 $html.=$title_par;
737 $html.='<form method="post" id="insert_periode_frm" onsubmit="'.$p_js_var.'.insert_periode();return false;">' ;
738 $html.=HtmlInput::hidden("ac", $http->request('ac'));
740 $html.='<table>';
741
742 $html.=tr(td(_(' Début période : ')).td($p_start->input()));
743 $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
744 $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
745 $html.='</table>';
746 $html.=HtmlInput::submit('add_per', _('sauver'));
747 $html.=HtmlInput::button('close', _('fermer'),
748 'onclick="$(\'periode_add\').hide()"');
749 $html.='</form>';
750 echo $html;
751 }
752 /**
753 *@brief
754 */
755 static function filter_exercice($p_sel)
756 {
758 $i_exercice=new ISelect("p_exercice_sel");
759 $i_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc", 1);
760 $i_exercice->javascript="onchange=\"Periode.filter_exercice('periode_tbl')\"";
761 $i_exercice->selected=$p_sel;
762 echo $i_exercice->input();
763 }
764
765 /**
766 * @brief retrieve the first day of the first exercice
767 * @return : string date format "DD.MM.YYYYY"
768 */
769 function get_first_date():string
770 {
771 return $this->cn->get_value("select to_char(p_start,'DD.MM.YYYY') from parm_periode order by p_start limit 1");
772 }
773
774 /**
775 * @brief retrieve the first periode of the folder or -1 if none
776 *
777 * @return int
778 */
779 function get_first_periode():int
780 {
781 return $this->cn->get_value("select p_id from parm_periode order by p_start asc limit 1");
782 }
783}
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
Definition: ac_common.php:852
isNumber($p_int)
Definition: ac_common.php:215
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
isDate($p_date)
Definition: ac_common.php:236
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
tr($p_string, $p_extra='')
Definition: ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
if(headers_sent() &&DEBUGNOALYSS > 0) $html
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
catch(Exception $e) $exercice
$profile p_id
margin jrn_def_id
$p
Definition: array.php:34
$from
Definition: balance.inc.php:61
$input_from cn
Definition: balance.inc.php:66
$ex
Definition: balance.inc.php:45
$date_start
$class
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
static hidden()
return a string to set gDossier into a FORM
static connect()
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Html Input.
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
Definition: itext.class.php:30
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
static iconoff($p_id, $p_javascript, $p_style="")
Display a icon OFF.
static iconon($p_id, $p_javascript, $p_style="")
Display a icon ON.
static trash($p_id, $p_javascript)
Display the icon of a trashbin.
For the periode tables parm_periode and jrn_periode.
get_first_date()
retrieve the first day of the first exercice
limit_year($p_exercice)
return the p_id of the start and the end of the exercice into an array
find_periode($p_date)
retrieve the periode thanks the date_end
first_day($p=0)
return the first day of periode the this->p_id must be set
insert_exercice($p_exercice, $p_year, $p_from_month, $p_month, $p_opening, $p_closing, $p_exercice_label)
add a exercice starting in year p_year with p_month month, with a starting and a closing
static form_exercice_add()
display a form (method POST) to input a new exercice variable in the FORM
load()
load data from database
static form_periode_add($p_js_var)
Display a form for the input of a new periode.
set_periode($pp_id)
__construct($p_cn, $p_id=0)
get_exercice($p_id=0)
get_date_limit($p_periode=0)
Give the start & end date of a periode.
set_ledger($p_jrn)
get_first_periode()
retrieve the first periode of the folder or -1 if none
is_open()
Return 1 if the periode is open otherwise 0.
is_centralized()
Return 1 if periode is centralized.
static form_exercice_label()
form to change the label of exercice
static filter_exercice($p_sel)
last_day($p=0)
return the last day of periode the this->p_id must be set
close()
Close a periode , if Periode::jrn_def_id is set to a different value than 0 , it close only for this ...
static display_periode_global($p_js)
Display a table with all the periode.
verify_delete()
Verify before delete that the month is not used.
static display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
Display each row for the global.
count_operation()
count the number of operation of a Periode
get_limit($p_exercice)
return the max and the min periode of the exercice given in parameter
insert($p_date_start, $p_date_end, $p_exercice, $p_exercice_label)
Add new periode.
is_closed()
check if a periode is closed. If jrn_def_id is set to a no zero value then check only for this ledger
const COMPTA_MIN_YEAR
Definition: constant.php:141
const COMPTA_MAX_YEAR
Definition: constant.php:140
$Res
$count
if( $delta< 0) elseif( $delta==0)
$nb_operation