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";
105 $sql=
"select status from jrn_periode ".
106 " where jrn_def_id=$2 ".
112 $sql=
"select p_closed as status from parm_periode ".
131 $sql=
"select status from jrn_periode ".
132 " where jrn_def_id=$1 ".
137 $sql=
"select p_closed as status from parm_periode ".
153 $sql=
"select status from jrn_periode ".
154 " where jrn_def_id=".$this->jrn_def_id.
155 " and p_id =".$this->p_id;
157 $sql=
"select p_centralized as status from parm_periode ".
159 " p_id =".$this->p_id;
171 $this->
cn->exec_sql(
"update parm_periode set p_closed='f',p_central='f' where p_id=$1",
174 $this->
cn->exec_sql(
"update jrn_periode set status='OP' ".
175 " where p_id = $1", [$this->
p_id]);
181 $this->
cn->exec_sql(
"update jrn_periode set status='OP'
182 where jrn_def_id=$1 and
185 $this->
cn->exec_sql(
"update parm_periode set p_closed=false where p_id=".$this->
p_id);
197 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=$1",
199 $this->
cn->exec_sql(
"update jrn_periode set status='CL'
200 where p_id = $1", [$this->
p_id]);
206 $this->
cn->exec_sql(
"update jrn_periode set status='CL' ".
207 " where jrn_def_id=$1 and
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]);
217 if ($nJrnPeriode==$nJrn)
218 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=$1",
231 $this->
cn->exec_sql(
"update parm_periode set p_central=true");
236 $this->
cn->exec_sql(
"update jrn_periode set status='CE' ".
238 " p_id = $1", [$this->
p_id]);
255 if (
isDate($p_date_start)==
null ||
256 isDate($p_date_end)==
null ||
262 throw new Exception(
_(
"Paramètre invalide"),10);
264 $overlap_start=$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 $overlap_end=$this->
cn->get_value(
"select count(*) from parm_periode
272 p_start <= to_date($1,'DD-MM-YYYY')
273 and p_end >= to_date($1,'DD-MM-YYYY')
276 if ( $overlap_start > 0 || $overlap_end > 0)
278 throw new Exception (
_(
"Période chevauchant une autre"),20);
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)
284 to_date($2,'DD.MM.YYYY'),
285 to_date($3,'DD.MM.YYYY'),
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");
300 $this->
cn->rollback();
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",
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'];
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",
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",
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);
367 $sql=
"select to_char(p_start,'DD.MM.YYYY') as p_start,
368 to_char(p_end,'DD.MM.YYYY') as p_end
371 $Res=$this->
cn->exec_sql(
$sql, array($p_periode));
407 $sql=
"select p_exercice from parm_periode where p_id=$1";
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') ";
426 throw (
new Exception(
_(
'Aucune période trouvée').
" $p_date ", 101));
428 throw (
new Exception(sprintf(
_(
"Trop de périodes trouvées %s pour %s"),$nb_periode,
$p_date),
452 throw new Exception(
_(
"Exercice n'est pas un nombre"));
455 throw new Exception(sprintf(
_(
"Exercice doit être entre %s et %s "),
COMPTA_MIN_YEAR,
458 throw new Exception(
_(
"Année n'est pas un nombre"));
461 throw new Exception(sprintf(
_(
"Année doit être entre %s et %s "),
COMPTA_MIN_YEAR,
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 "));
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 "));
477 $month=$p_from_month;
478 for (
$i=1;
$i<=$p_month;
$i++)
482 if (
$i==1&&$p_opening==1)
484 $fdate_start=sprintf(
'01.%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));
494 elseif (
$i==$p_month && $p_closing ==1 )
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));
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));
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')",
527 $this->
cn->rollback();
539 $cn=Dossier::connect();
546 echo
'<table class="result" id="periode_tbl">';
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"));
560 for (
$i=0;
$i<$nb_periode;
$i++)
580 jr_tech_per = $1", [$this->
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"> ',
596 $obj->getp(
"p_start"),
597 $obj->getp(
"p_exercice"),
602 if (
$obj->getp(
"p_closed")==
"f")
605 $checkbox->set_range(
"sel_per_close_ck");
608 echo
"<td>".$checkbox->input().
"</td>";
616 echo
td(
$obj->getp(
"p_exercice"));
617 echo
td(
$obj->getp(
"p_exercice_label"),
'class="visible_gt800"');
620 $closed=
$obj->getp(
'p_closed');
621 $status=($closed==
't')?
_(
"Fermée"):
_(
"Ouvert");
628 $js=sprintf(
"%s.box_display('%d')", $p_js,
$obj->p_id);
633 $js=sprintf(
"%s.remove('%d')", $p_js,
$obj->p_id);
645 if (
$obj->getp(
"p_closed")==
'f')
647 $javascript=sprintf(
'%s.close_periode(\'%d\')', $p_js,
$obj->p_id);
652 $javascript=sprintf(
"%s.open_periode('%d')", $p_js,
$obj->p_id);
672 $cn=Dossier::connect();
675 $exercice->value=
$cn->get_value(
'select max(p_exercice::float)+1 from parm_periode');
679 $nb_month=
new INum(
'nb_month');
684 $month=[
_(
'Janvier'),
_(
'Février'),
_(
'Mars'),
_(
'Avril'),
685 _(
'Mai'),
_(
'Juin'),
_(
'Juillet'),
_(
'Août'),
_(
'Septembre'),
686 _(
'Octobre'),
_(
'Novembre'),
_(
'Décembre')];
689 $strMonth=$month[(
$i-1)];
690 $amonth[]=array(
"value"=>
$i,
"label"=>$strMonth);
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);
699 require_once NOALYSS_TEMPLATE.
'/periode_add_exercice.php';
706 $cn=Dossier::connect();
707 require_once NOALYSS_TEMPLATE.
"/periode-form_exercice_label.php";
710 $this->
cn->exec_sql(
"delete from parm_periode where p_id=$1",[$this->
p_id]);
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);
721 }
catch (Exception
$ex) {
730 $http=new \HttpInput();
731 $cn=Dossier::connect();
733 $p_exercice->value=
$cn->make_array(
"select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc");
735 $title_par=
"<p>"._(
'On ne peut ajouter une période que sur un exercice qui existe déjà').
742 $html.=HtmlInput::title_box(
$title,
'periode_add',
'hide');
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();
753 $html.=HtmlInput::submit(
'add_per',
_(
'sauver'));
754 $html.=HtmlInput::button(
'close',
_(
'fermer'),
755 'onclick="$(\'periode_add\').hide()"');
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();
778 return $this->
cn->get_value(
"select to_char(p_start,'DD.MM.YYYY') from parm_periode order by p_start limit 1");
788 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 or in the log folder of NOALYSS Record also t...
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
_("actif, passif,charge,...")
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 : 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.
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 (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
if( $delta< 0) elseif( $delta==0)