noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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
32class Periode
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,
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 {
104
105 $sql="select status from jrn_periode ".
106 " where jrn_def_id=$2 ".
107 " and p_id = $1";
108 $status=$this->cn->get_value($sql,[$this->p_id,$this->jrn_def_id]);
109 }
110 else
111 {
112 $sql="select p_closed as status from parm_periode ".
113 " where ".
114 " p_id = $1";
115 $status=$this->cn->get_value($sql,[$this->p_id]);
116
117 }
118 if ($status=='CL'||$status=='t'||$status=='CE')
119 return 1;
120 return 0;
121 }
122
123 ///Return 1 if the periode is open otherwise 0
124 //!\note For only a ledger you must set Periode::jrn_def_id to the ledger id
125 ///@see Periode::set_ledger
126 function is_open()
127 {
128 /* if jrn_Def_id == 0 then we check the global otherwise we check
129 a ledger */
130 if ($this->jrn_def_id!=0){
131 $sql="select status from jrn_periode ".
132 " where jrn_def_id=$1 ".
133 " and p_id = $2";
134 $status=$this->cn->get_value($sql,[$this->jrn_def_id,$this->p_id]);
135 }
136 else {
137 $sql="select p_closed as status from parm_periode ".
138 " where ".
139 " p_id = $1 ";
140 $status=$this->cn->get_value($sql,[$this->p_id]);
141 }
142
143 if ($status=='OP'||$status=='f') return 1;
144 return 0;
145 }
146
147 ///Return 1 if periode is centralized
148 ///@deprecated
149 //!\note deprecated , centralization not used anymore
150 function is_centralized()
151 {
152 if ($this->jrn_def_id!=0)
153 $sql="select status from jrn_periode ".
154 " where jrn_def_id=".$this->jrn_def_id.
155 " and p_id =".$this->p_id;
156 else
157 $sql="select p_centralized as status from parm_periode ".
158 " where ".
159 " p_id =".$this->p_id;
160 $res=$this->cn->exec_sql($sql);
162 if ($status=='CE'||$status=='t')
163 return 1;
164 return 0;
165 }
166
167 function reopen()
168 {
169 if ($this->jrn_def_id==0)
170 {
171 $this->cn->exec_sql("update parm_periode set p_closed='f',p_central='f' where p_id=$1",
172 array($this->p_id));
173
174 $this->cn->exec_sql("update jrn_periode set status='OP' ".
175 " where p_id = $1", [$this->p_id]);
176
177 return;
178 }
179 else
180 {
181 $this->cn->exec_sql("update jrn_periode set status='OP'
182 where jrn_def_id=$1 and
183 p_id = $2 ", [$this->jrn_def_id, $this->p_id]);
184 /* if one ledger is open then the periode is open */
185 $this->cn->exec_sql("update parm_periode set p_closed=false where p_id=".$this->p_id);
186 return;
187 }
188 }
189
190 ///Close a periode , if Periode::jrn_def_id is set to a different value
191 /// than 0 , it close only for this ledger id ; otherwise close for all
192 /// periode
193 function close()
194 {
195 if ($this->jrn_def_id==0)
196 {
197 $this->cn->exec_sql("update parm_periode set p_closed=true where p_id=$1",
198 [$this->p_id]);
199 $this->cn->exec_sql("update jrn_periode set status='CL'
200 where p_id = $1", [$this->p_id]);
201
202 return;
203 }
204 else
205 {
206 $this->cn->exec_sql("update jrn_periode set status='CL' ".
207 " where jrn_def_id=$1 and
208 p_id = $2", [$this->jrn_def_id, $this->p_id]);
209 /* if all ledgers have this periode closed then synchro with
210 the table parm_periode
211 */
212 $nJrn=$this->cn->count_sql("select * from jrn_periode where ".
213 " p_id=$1", [$this->p_id]);
214 $nJrnPeriode=$this->cn->count_sql("select * from jrn_periode where ".
215 " p_id=$1 and status='CL'", [$this->p_id]);
216
217 if ($nJrnPeriode==$nJrn)
218 $this->cn->exec_sql("update parm_periode set p_closed=true where p_id=$1",
219 [$this->p_id]);
220 return;
221 }
222 }
223 /**
224 * @deprecated since version 5
225 * @return type
226 */
227 function centralized()
228 {
229 if ($this->jrn_def_id==0)
230 {
231 $this->cn->exec_sql("update parm_periode set p_central=true");
232 return;
233 }
234 else
235 {
236 $this->cn->exec_sql("update jrn_periode set status='CE' ".
237 " where ".
238 " p_id = $1", [$this->p_id]);
239 return;
240 }
241 }
242 /**
243 * Add new periode
244 * @param date $p_date_start
245 * @param date $p_date_end
246 * @param int $p_exercice
247 * @return int p_id of the new periode
248 * @exception Exception 10 Invalide date or exercice, 20 overlapping periode
249 */
250 function insert($p_date_start, $p_date_end, $p_exercice,$p_exercice_label)
251 {
252 try
253 {
254
255 if (isDate($p_date_start)==null ||
256 isDate($p_date_end)==null ||
258 isNumber($p_exercice) ==0 ||
261 {
262 throw new Exception(_("Paramètre invalide"),10);
263 }
264 $overlap_start=$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_start]);
270 $overlap_end=$this->cn->get_value("select count(*) from parm_periode
271 where
272 p_start <= to_date($1,'DD-MM-YYYY')
273 and p_end >= to_date($1,'DD-MM-YYYY')
274
275 ",[$p_date_end]);
276 if ( $overlap_start > 0 || $overlap_end > 0)
277 {
278 throw new Exception (_("Période chevauchant une autre"),20);
279 }
280 $p_id=$this->cn->get_next_seq('s_periode');
281 $sql=" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice,p_exercice_label)
282 values
283 ($1,
284 to_date($2,'DD.MM.YYYY'),
285 to_date($3,'DD.MM.YYYY'),
286 'f',
287 $4,$5)";
288
289 $this->cn->start();
290 $Res=$this->cn->exec_sql($sql,[$p_id, $p_date_start, $p_date_end, $p_exercice,$p_exercice_label]);
291 $Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ".
292 "select jrn_def_id,$p_id,'OP' from jrn_def");
293 $this->cn->commit();
294 return $p_id;
295 }
296 catch (Exception $e)
297 {
298 record_log($e->getMessage()." - ".$e->getCode());
299 record_log($e);
300 $this->cn->rollback();
301 throw $e;
302 }
303 }
304
305 /*!\brief load data from database
306 * \return 0 on success and -1 on error
307 */
308
309 function load():int
310 {
311 if ($this->p_id=='')
312 $this->p_id=-1;
313 $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",
314 array($this->p_id));
315 if ($row==null)
316 return -1;
317
318 $this->p_start=$row[0]['p_start'];
319 $this->p_end=$row[0]['p_end'];
320 $this->p_exercice=$row[0]['p_exercice'];
321 $this->p_exercice_label=$row[0]['p_exercice_label'];
322 $this->p_closed=$row[0]['p_closed'];
323 $this->p_central=$row[0]['p_central'];
324 return 0;
325 }
326
327 /*!
328 * \brief return the max (to periode) and the min periode (from periode) of the exercice given
329 * in parameter
330 * \param $p_exercice is the exercice (parm_periode.p_exercice)
331 * \return an array of Periode object
332 */
333
335 {
336
337 $from_periode_id=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start asc limit 1",
338 array($p_exercice));
339 $to_periode_id=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start desc limit 1",
340 array($p_exercice));
341 $periodeFrom=new Periode($this->cn);
342 $periodeFrom->p_id=$from_periode_id;
343 if ($periodeFrom->load() == -1)
344 throw new Exception('Periode n\'existe pas');
345 $periodeTo=new Periode($this->cn);
346 $periodeTo->p_id=$to_periode_id;
347 if ($periodeTo->load() == -1)
348 throw new Exception('Periode n\'existe pas');
349 return array($periodeFrom, $periodeTo);
350 }
351
352 /*!
353 * \brief Give the start & end date of a periode
354 * \param $p_periode is the periode id, if omitted the value is the current object
355 * \return array containing the start date & the end date, index are p_start and p_end or NULL if
356 * nothing is found
357 \verbatim
358 $ret['p_start']=>'01.01.2009'
359 $ret['p_end']=>'31.01.2009'
360 \endverbatim
361 */
362
363 public function get_date_limit($p_periode=0)
364 {
365 if ($p_periode==0)
366 $p_periode=$this->p_id;
367 $sql="select to_char(p_start,'DD.MM.YYYY') as p_start,
368 to_char(p_end,'DD.MM.YYYY') as p_end
369 from parm_periode
370 where p_id=$1";
371 $Res=$this->cn->exec_sql($sql, array($p_periode));
372 if (Database::num_row($Res)==0)
373 return null;
374 return Database::fetch_array($Res, 0,PGSQL_BOTH);
375 }
376
377 /*!\brief return the first day of periode
378 * the this->p_id must be set
379 * \return a string with the date (DD.MM.YYYY)
380 */
381
382 public function first_day($p=0)
383 {
384 if ($p==0)
386 list($p_start, $p_end)=$this->get_date_limit($p);
387 return $p_start;
388 }
389
390 /*!\brief return the last day of periode
391 * the this->p_id must be set
392 * \return a string with the date (DD.MM.YYYY)
393 */
394
395 public function last_day($p=0)
396 {
397 if ($p==0)
399 list($p_start, $p_end)=$this->get_date_limit($p);
400 return $p_end;
401 }
402
403 function get_exercice($p_id=0)
404 {
405 if ($p_id==0)
407 $sql="select p_exercice from parm_periode where p_id=$1";
408 $Res=$this->cn->exec_sql($sql,[$p_id]);
409 if (Database::num_row($Res)==0)
410 return null;
411 return Database::fetch_result($Res, 0, 0);
412 }
413
414 /*!\brief retrieve the periode thanks the date_end
415 * \param $p_date format DD.MM.YYYY
416 * \return the periode id
417 * \exception if not periode is found or if more than one periode is found
418 */
419
421 {
422 $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') ";
423 $ret=$this->cn->exec_sql($sql, array($p_date));
424 $nb_periode=Database::num_row($ret);
425 if ($nb_periode==0)
426 throw (new Exception(_('Aucune période trouvée')." $p_date ", 101));
427 if ($nb_periode>1)
428 throw (new Exception(sprintf(_("Trop de périodes trouvées %s pour %s"),$nb_periode,$p_date),
429 100));
431 $this->p_id=$per;
432 return $per;
433 }
434
435 /**
436 * add a exercice starting in year p_year with p_month month, with a starting
437 * and a closing
438 * @param $p_exercice the exercice
439 * @param $p_year the starting year
440 * @param $p_from_month starting month
441 * @param $p_month number of month of the exercice
442 * @param $p_opening 1 if we create a one-day periode for opening writings
443 * @param $p_closing 1 if we create a one-day periode for closing writings
444 * @param $p_exercice_label label of the exercice
445 */
446 function insert_exercice($p_exercice, $p_year, $p_from_month, $p_month,
447 $p_opening, $p_closing,$p_exercice_label)
448 {
449 try
450 {
451 if (isNumber($p_exercice)==0)
452 throw new Exception(_("Exercice n'est pas un nombre"));
453
455 throw new Exception(sprintf(_("Exercice doit être entre %s et %s "), COMPTA_MIN_YEAR,
457 if (isNumber($p_year)==0)
458 throw new Exception(_("Année n'est pas un nombre"));
459
460 if ($p_year>COMPTA_MAX_YEAR||$p_year<COMPTA_MIN_YEAR)
461 throw new Exception(sprintf(_("Année doit être entre %s et %s "), COMPTA_MIN_YEAR,
463
464 if (isNumber($p_month)==0)
465 throw new Exception(_("Nombre de mois n'est pas un nombre"));
466 if ($p_month<1||$p_month>60)
467 throw new Exception(_("Nombre de mois doit être compris entre 1 & 60 "));
468 if (isNumber($p_month)==0)
469 throw new Exception(_("Mois de début n'existe pas "));
470 if ($p_from_month>13||$p_from_month<1)
471 throw new Exception(_("Mois de début n'existe pas "));
472 if ( empty($p_exercice_label)) {
474 }
475 $this->cn->start();
476 $year=$p_year;
477 $month=$p_from_month;
478 for ($i=1; $i<=$p_month; $i++)
479 {
480
481 // create first a periode of day
482 if ($i==1&&$p_opening==1)
483 {
484 $fdate_start=sprintf('01.%02d.%d', $month, $year);
485 $this->insert($fdate_start, $fdate_start, $p_exercice,$p_exercice_label);
486
487 $date_start=sprintf('02.%02d.%d', $month, $year);
488 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
489 array($fdate_start));
490
492 }
493 // The last month, we create a one-day periode for closing
494 elseif ($i==$p_month && $p_closing ==1 )
495 {
496 $fdate_start=sprintf('01.%02d.%d', $month, $year);
497 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '2 day','DD.MM.YYYY')",
498 array($fdate_start));
499 $this->insert($fdate_start, $date_end, $p_exercice,$p_exercice_label);
500
501 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
502 array($fdate_start));
503
505
506 }
507 else
508 {
509 $date_start=sprintf('01.%02d.%d', $month, $year);
510 $date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",
511 array($date_start));
513 }
514 $month++;
515 if ($month == 13 )
516 {
517 $year++;
518 $month=1;
519 }
520 }
521
522 $this->cn->commit();
523 }
524 catch (Exception $e)
525 {
526 record_log($e);
527 $this->cn->rollback();
528 throw $e;
529 }
530 }
531
532 /**
533 * Display a table with all the periode
534 * @param $p_js javascript variable
535 * @see noalyss_script.js
536 */
537 static function display_periode_global($p_js)
538 {
539 $cn=Dossier::connect();
540 $periode=new Parm_Periode_SQL($cn);
541 $ret=$periode->seek(" order by p_start asc");
542 $nb_periode=Database::num_row($ret);
543
544 if ($nb_periode==0)
545 return;
546 echo '<table class="result" id="periode_tbl">';
547 echo "<thead>";
548 echo "<tr>";
549 echo th("");
550 echo th(_("Date Début"));
551 echo th(_("Date Fin"));
552 echo th(_("Exercice"));
553 echo th(_("Libellé"),'class="visible_gt800"');
554 echo th(_("nb opérations"));
555 echo th(_("Status"));
556 echo "</tr>";
557 echo "</thead>";
558 echo '<tbody>';
559
560 for ($i=0; $i<$nb_periode; $i++)
561 {
562 $obj=$periode->next($ret, $i);
564 }
565 echo '</tbody>';
566 echo '</table>';
567 }
568
569 /**
570 * count the number of operation of a Periode
571 * @return integer
572 */
574 {
575 $count=$this->cn->get_value("
576 select count(*)
577 from
578 jrn
579 where
580 jr_tech_per = $1", [$this->p_id]);
581 return $count;
582 }
583
584 /**
585 * @brief Display each row for the global
586 * @param $obj Parm_Periode_SQL
587 * @param $p_nb not used so far
588 * @param $p_js javascript variable
589 */
590 static function display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
591 {
592 $periode=new Periode($obj->cn, $obj->p_id);
593 $class=($p_nb%2==0)?"even":"odd";
594 printf('<tr id="row_per_%d" customkey="%s" per_exercice="%s" p_id="%s" class="%s"> ',
595 $obj->getp("p_id"),
596 $obj->getp("p_start"),
597 $obj->getp("p_exercice"),
598 $obj->getp("p_id"), $class);
599 /**
600 * Display a checkbox to select several month to close
601 */
602 if ($obj->getp("p_closed")=="f")
603 {
604 $checkbox=new ICheckBox("sel_per_close[]");
605 $checkbox->set_range("sel_per_close_ck");
606 $checkbox->set_attribute("per_id", $obj->getp("p_id"));
607 $checkbox->value=$obj->getp("p_id");
608 echo "<td>".$checkbox->input()."</td>";
609 }
610 else
611 {
612 echo td("");
613 }
614 echo td(format_date($obj->getp("p_start"), "YYYY-MM-DD", "DD.MM.YYYY"));
615 echo td(format_date($obj->getp("p_end"), "YYYY-MM-DD", "DD.MM.YYYY"));
616 echo td($obj->getp("p_exercice"));
617 echo td($obj->getp("p_exercice_label"),'class="visible_gt800"');
618 $nb_operation=$periode->count_operation();
619 echo td($nb_operation);
620 $closed=$obj->getp('p_closed');
621 $status=($closed=='t')?_("Fermée"):_("Ouvert");
622 echo td($status);
623
624 // if no operation then this periode can be removed or updated
625 if ($nb_operation==0)
626 {
627 // Updatable
628 $js=sprintf("%s.box_display('%d')", $p_js, $obj->p_id);
629 echo "<td>";
630 echo Icon_Action::modify(uniqid(), $js);
631 echo "</td>";
632 //removable
633 $js=sprintf("%s.remove('%d')", $p_js, $obj->p_id);
634 echo "<td>";
635 echo Icon_Action::trash(uniqid(), $js);
636 echo "</td>";
637 }
638 else
639 {
640 echo td(""), td("");
641 }
642
643 /// Can close if open
644 echo "<td>";
645 if ($obj->getp("p_closed")=='f')
646 {
647 $javascript=sprintf('%s.close_periode(\'%d\')', $p_js, $obj->p_id);
648 echo Icon_Action::iconon(uniqid(), $javascript);
649 }
650 else
651 {
652 $javascript=sprintf("%s.open_periode('%d')", $p_js, $obj->p_id);
653 echo Icon_Action::iconoff(uniqid(),$javascript );
654 }
655 echo "</td>";
656 echo "</tr>";
657 }
658
659 /**
660 * @brief display a form (method POST) to input a new exercice
661 * variable in the FORM
662 * - p_exercice
663 * - p_year
664 * - nb_month
665 * - from_month
666 * - day_opening
667 * - day_closing
668 * - p_exercice_label
669 */
670 static function form_exercice_add()
671 {
672 $cn=Dossier::connect();
673 $exercice=new INum('p_exercice');
674 $exercice->prec=0;
675 $exercice->value=$cn->get_value('select max(p_exercice::float)+1 from parm_periode');
676 $year=new INum('p_year');
677 $year->prec=0;
678 $year->value=$exercice->value;
679 $nb_month=new INum('nb_month');
680 $nb_month->prec=0;
681 $nb_month->value=12;
682 $from=new ISelect('from_month');
683 $amonth=array();
684 $month=[_('Janvier'), _('Février'), _('Mars'), _('Avril'),
685 _('Mai'), _('Juin'), _('Juillet'), _('Août'), _('Septembre'),
686 _('Octobre'), _('Novembre'), _('Décembre')];
687 for ($i=1; $i<13; $i++)
688 {
689 $strMonth=$month[($i-1)];
690 $amonth[]=array("value"=>$i, "label"=>$strMonth);
691 }
692 $from->value=$amonth;
693 $day_opening=new ICheckBox("day_opening");
694 $day_closing=new ICheckBox("day_closing");
695 $day_closing->value=1;
696 $day_opening->value=1;
697 $day_closing->set_check(1);
698 $exercice_label=new IText("p_exercice_label");
699 require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
700 }
701 /**
702 * @brief form to change the label of exercice
703 */
704 static function form_exercice_label()
705 {
706 $cn=Dossier::connect();
707 require_once NOALYSS_TEMPLATE."/periode-form_exercice_label.php";
708 }
709 function delete() {
710 $this->cn->exec_sql("delete from parm_periode where p_id=$1",[$this->p_id]);
711 }
712 /**
713 * Verify before delete that the month is not used
714 * @exception Exception code 1 if periode used
715 */
716 function verify_delete() {
717 try {
718 if ( $this->cn->get_value("select count(*) from jrn where jr_tech_per =$1 ",[$this->p_id]) > 0) {
719 throw new Exception(_("Effacement impossible"), 1);
720 }
721 } catch (Exception $ex) {
722 throw $ex;
723 }
724 }
725 /**
726 * @brief Display a form for the input of a new periode
727 */
728 static function form_periode_add($p_js_var)
729 {
730 $http=new \HttpInput();
731 $cn=Dossier::connect();
732 $p_exercice=new ISelect('p_exercice');
733 $p_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc");
734 $title=_('Ajout période');
735 $title_par="<p>"._('On ne peut ajouter une période que sur un exercice qui existe déjà').
736 "</p>";
737
738 $p_start=new IDate('p_start');
739 $p_end=new IDate('p_end');
740
741 $html='';
742 $html.=HtmlInput::title_box($title, 'periode_add','hide');
743 $html.=$title_par;
744 $html.='<form method="post" id="insert_periode_frm" onsubmit="'.$p_js_var.'.insert_periode();return false;">' ;
745 $html.=HtmlInput::hidden("ac", $http->request('ac'));
746 $html.=Dossier::hidden();
747 $html.='<table>';
748
749 $html.=tr(td(_(' Début période : ')).td($p_start->input()));
750 $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
751 $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
752 $html.='</table>';
753 $html.=HtmlInput::submit('add_per', _('sauver'));
754 $html.=HtmlInput::button('close', _('fermer'),
755 'onclick="$(\'periode_add\').hide()"');
756 $html.='</form>';
757 echo $html;
758 }
759 /**
760 *@brief
761 */
762 static function filter_exercice($p_sel)
763 {
764 $cn=Dossier::connect();
765 $i_exercice=new ISelect("p_exercice_sel");
766 $i_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc", 1);
767 $i_exercice->javascript="onchange=\"Periode.filter_exercice('periode_tbl')\"";
768 $i_exercice->selected=$p_sel;
769 echo $i_exercice->input();
770 }
771
772 /**
773 * @brief retrieve the first day of the first exercice
774 * @return : string date format "DD.MM.YYYYY"
775 */
776 function get_first_date():string
777 {
778 return $this->cn->get_value("select to_char(p_start,'DD.MM.YYYY') from parm_periode order by p_start limit 1");
779 }
780
781 /**
782 * @brief retrieve the first periode of the folder or -1 if none
783 *
784 * @return int
785 */
786 function get_first_periode():int
787 {
788 return $this->cn->get_value("select p_id from parm_periode order by p_start asc limit 1");
789 }
790}
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
isNumber($p_int)
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
isDate($p_date)
noalyss_strlentrim($p_string)
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 or in the log folder of NOALYSS Record also t...
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
kd_id $checkbox
margin jrn_def_id
$from
$input_from cn
_("actif, passif,charge,...")
$ex
$date_start
$p
Definition calendar.php:9
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
Html Input.
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Html Input.
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.
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 (to periode) and the min periode (from 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:140
const COMPTA_MAX_YEAR
Definition constant.php:139
$count
if( $delta< 0) elseif( $delta==0)
$nb_operation