29require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
30require_once NOALYSS_INCLUDE.
"/database/parm_periode_sql.class.php";
87 $sql_start=
"select p_id from parm_periode where p_exercice=$1 order by p_start ASC limit 1";
89 $sql_end=
"select p_id from parm_periode where p_exercice=$1 order by p_end DESC limit 1";
103 $sql=
"select status from jrn_periode ".
104 " where jrn_def_id=".$this->jrn_def_id.
105 " and p_id =".$this->p_id;
107 $sql=
"select p_closed as status from parm_periode ".
109 " p_id =".$this->p_id;
125 $sql=
"select status from jrn_periode ".
126 " where jrn_def_id=$1 ".
131 $sql=
"select p_closed as status from parm_periode ".
134 $status=$this->
cn->get_value(
$sql,[$this->
p_id]);
137 if ($status==
'OP'||
$status==
'f')
return 1;
147 $sql=
"select status from jrn_periode ".
148 " where jrn_def_id=".$this->jrn_def_id.
149 " and p_id =".$this->p_id;
151 $sql=
"select p_centralized as status from parm_periode ".
153 " p_id =".$this->p_id;
165 $this->
cn->exec_sql(
"update parm_periode set p_closed='f',p_central='f' where p_id=$1",
168 $this->
cn->exec_sql(
"update jrn_periode set status='OP' ".
169 " where p_id = $1", [$this->
p_id]);
175 $this->
cn->exec_sql(
"update jrn_periode set status='OP'
176 where jrn_def_id=$1 and
179 $this->
cn->exec_sql(
"update parm_periode set p_closed=false where p_id=".$this->
p_id);
191 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=$1",
193 $this->
cn->exec_sql(
"update jrn_periode set status='CL'
194 where p_id = $1", [$this->
p_id]);
200 $this->
cn->exec_sql(
"update jrn_periode set status='CL' ".
201 " where jrn_def_id=$1 and
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]);
211 if ($nJrnPeriode==$nJrn)
212 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=$1",
225 $this->
cn->exec_sql(
"update parm_periode set p_central=true");
230 $this->
cn->exec_sql(
"update jrn_periode set status='CE' ".
232 " p_id = $1", [$this->
p_id]);
249 if (
isDate($p_date_start)==
null ||
250 isDate($p_date_end)==
null ||
256 throw new Exception(_(
"Paramètre invalide"),10);
258 $overlap_start=$this->
cn->get_value(
"select count(*) from parm_periode
260 p_start <= to_date($1,'DD-MM-YYYY')
261 and p_end >= to_date($1,'DD-MM-YYYY')
264 $overlap_end=$this->
cn->get_value(
"select count(*) from parm_periode
266 p_start <= to_date($1,'DD-MM-YYYY')
267 and p_end >= to_date($1,'DD-MM-YYYY')
270 if ( $overlap_start > 0 || $overlap_end > 0)
272 throw new Exception (_(
"Période chevauchant une autre"),20);
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)
278 to_date($2,'DD.MM.YYYY'),
279 to_date($3,'DD.MM.YYYY'),
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");
294 $this->
cn->rollback();
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",
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'];
330 $max=$this->
cn->get_value(
"select p_id from parm_periode where p_exercice=$1 order by p_start asc limit 1",
332 $min=$this->
cn->get_value(
"select p_id from parm_periode where p_exercice=$1 order by p_start desc limit 1",
336 if ($rMax->load() == -1)
337 throw new Exception(
'Periode n\'existe pas');
340 if ($rMin->load() == -1)
341 throw new Exception(
'Periode n\'existe pas');
342 return array($rMax, $rMin);
360 $sql=
"select to_char(p_start,'DD.MM.YYYY') as p_start,
361 to_char(p_end,'DD.MM.YYYY') as p_end
364 $Res=$this->
cn->exec_sql(
$sql, array($p_periode));
400 $sql=
"select p_exercice from parm_periode where p_id=$1";
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') ";
419 throw (
new Exception(_(
'Aucune période trouvée').
" $p_date ", 101));
421 throw (
new Exception(sprintf(_(
"Trop de périodes trouvées %s pour %s"),$nb_periode,
$p_date),
445 throw new Exception(_(
"Exercice n'est pas un nombre"));
448 throw new Exception(sprintf(_(
"Exercice doit être entre %s et %s "),
COMPTA_MIN_YEAR,
451 throw new Exception(_(
"Année n'est pas un nombre"));
454 throw new Exception(sprintf(_(
"Année doit être entre %s et %s "),
COMPTA_MIN_YEAR,
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 "));
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 "));
470 $month=$p_from_month;
471 for (
$i=1;
$i<=$p_month;
$i++)
475 if (
$i==1&&$p_opening==1)
477 $fdate_start=sprintf(
'01.%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));
487 elseif (
$i==$p_month && $p_closing ==1 )
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));
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));
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')",
520 $this->
cn->rollback();
539 echo
'<table class="result" id="periode_tbl">';
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"));
553 for (
$i=0;
$i<$nb_periode;
$i++)
573 jr_tech_per = $1", [$this->
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"> ',
589 $obj->getp(
"p_start"),
590 $obj->getp(
"p_exercice"),
595 if (
$obj->getp(
"p_closed")==
"f")
598 $checkbox->set_range(
"sel_per_close_ck");
601 echo
"<td>".$checkbox->input().
"</td>";
609 echo
td(
$obj->getp(
"p_exercice"));
610 echo
td(
$obj->getp(
"p_exercice_label"),
'class="visible_gt800"');
613 $closed=
$obj->getp(
'p_closed');
614 $status=($closed==
't')?_(
"Fermée"):_(
"Ouvert");
621 $js=sprintf(
"%s.box_display('%d')", $p_js,
$obj->p_id);
626 $js=sprintf(
"%s.remove('%d')", $p_js,
$obj->p_id);
638 if (
$obj->getp(
"p_closed")==
'f')
640 $javascript=sprintf(
'%s.close_periode(\'%d\')', $p_js,
$obj->p_id);
645 $javascript=sprintf(
"%s.open_periode('%d')", $p_js,
$obj->p_id);
668 $exercice->value=
$cn->get_value(
'select max(p_exercice::float)+1 from parm_periode');
672 $nb_month=
new INum(
'nb_month');
677 $month=[_(
'Janvier'), _(
'Février'), _(
'Mars'), _(
'Avril'),
678 _(
'Mai'), _(
'Juin'), _(
'Juillet'), _(
'Août'), _(
'Septembre'),
679 _(
'Octobre'), _(
'Novembre'), _(
'Décembre')];
682 $strMonth=$month[(
$i-1)];
683 $amonth[]=array(
"value"=>
$i,
"label"=>$strMonth);
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);
692 require_once NOALYSS_TEMPLATE.
'/periode_add_exercice.php';
700 require_once NOALYSS_TEMPLATE.
"/periode-form_exercice_label.php";
703 $this->
cn->exec_sql(
"delete from parm_periode where p_id=$1",[$this->
p_id]);
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);
714 }
catch (Exception
$ex) {
723 $http=new \HttpInput();
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à').
737 $html.=
'<form method="post" id="insert_periode_frm" onsubmit="'.$p_js_var.
'.insert_periode();return false;">' ;
748 'onclick="$(\'periode_add\').hide()"');
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();
771 return $this->
cn->get_value(
"select to_char(p_start,'DD.MM.YYYY') from parm_periode order by p_start limit 1");
781 return $this->
cn->get_value(
"select p_id from parm_periode order by p_start asc limit 1");
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
th($p_string, $p_extra='', $raw='')
noalyss_strlentrim($p_string)
tr($p_string, $p_extra='')
record_log($p_message)
Record an error message into the log file of the server.
td($p_string='', $p_extra='')
surround the string with td
if(headers_sent() &&DEBUGNOALYSS > 0) $html
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
catch(Exception $e) $exercice
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
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...
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.
__construct($p_cn, $p_id=0)
get_date_limit($p_periode=0)
Give the start & end date of a periode.
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
if( $delta< 0) elseif( $delta==0)