28 require_once NOALYSS_INCLUDE.
'/lib/ac_common.php';
29 require_once NOALYSS_INCLUDE.
'/lib/class_database.php';
59 $sql_start=
"select p_id from parm_periode where p_exercice=$1 order by p_start ASC limit 1";
61 $sql_end=
"select p_id from parm_periode where p_exercice=$1 order by p_end DESC limit 1";
70 if ( $this->jrn_def_id != 0 )
71 $sql=
"select status from jrn_periode ".
72 " where jrn_def_id=".$this->jrn_def_id.
73 " and p_id =".$this->p_id;
75 $sql=
"select p_closed as status from parm_periode ".
77 " p_id =".$this->p_id;
90 if ( $this->jrn_def_id != 0 )
91 $sql=
"select status from jrn_periode ".
92 " where jrn_def_id=".$this->jrn_def_id.
93 " and p_id =".$this->p_id;
95 $sql=
"select p_closed as status from parm_periode ".
97 " p_id =".$this->p_id;
108 if ( $this->jrn_def_id != 0 )
109 $sql=
"select status from jrn_periode ".
110 " where jrn_def_id=".$this->jrn_def_id.
111 " and p_id =".$this->p_id;
113 $sql=
"select p_centralized as status from parm_periode ".
115 " p_id =".$this->p_id;
124 if ( $this->jrn_def_id == 0 )
126 $this->
cn->exec_sql(
"update parm_periode set p_closed='f',p_central='f' where p_id=$1",
127 array(
$_GET[
'p_per']));
129 $this->
cn->exec_sql(
"update jrn_periode set status='OP' ".
130 " where p_id = ".$this->
p_id);
136 $this->
cn->exec_sql(
"update jrn_periode set status='OP' ".
137 " where jrn_def_id=".$this->jrn_def_id.
" and ".
138 " p_id = ".$this->p_id);
140 $this->
cn->exec_sql(
"update parm_periode set p_closed=false where p_id=".$this->
p_id);
150 if ( $this->jrn_def_id == 0 )
152 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=".
154 $this->
cn->exec_sql(
"update jrn_periode set status='CL' ".
155 " where p_id = ".$this->
p_id);
161 $this->
cn->exec_sql(
"update jrn_periode set status='CL' ".
162 " where jrn_def_id=".$this->jrn_def_id.
" and ".
163 " p_id = ".$this->p_id);
167 $nJrn=$this->
cn->count_sql(
"select * from jrn_periode where ".
168 " p_id=".$this->
p_id);
169 $nJrnPeriode=$this->
cn->count_sql(
"select * from jrn_periode where ".
170 " p_id=".$this->
p_id.
" and status='CL'");
172 if ( $nJrnPeriode==$nJrn)
173 $this->
cn->exec_sql(
"update parm_periode set p_closed=true where p_id=".$this->
p_id);
180 if ( $this->jrn_def_id == 0 )
182 $this->
cn->exec_sql(
"update parm_periode set p_central=true");
187 $this->
cn->exec_sql(
"update jrn_periode set status='CE' ".
189 " p_id = ".$this->
p_id);
203 if ( $this->jrn_def_id==0 )
205 $Res=$this->
cn->exec_sql(
"select p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as date_end,p_central,p_closed,p_exercice,
206 (select count(jr_id) as count_op from jrn where jr_tech_per = p_id) as count_op
208 order by p_start,p_end");
210 echo
'<form id="periode_frm" method="POST" onsubmit="return confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >';
212 echo
'<TABLE ALIGN="CENTER">';
214 echo
'<th>'.ICheckBox::toggle_checkbox(
"per_toggle",
"periode_frm").
"</th>";
215 echo
'<TH> Date début </TH>';
216 echo
'<TH> Date fin </TH>';
217 echo
'<TH> Exercice </TH>';
220 for ($i=0;$i<
$Max;$i++)
227 if ( $l_line[
'p_closed'] ==
't')
229 echo
'<TR class="'.$class.
'" style="'.
$style.
'">';
231 if ( $l_line[
'p_closed'] ==
'f') {
232 $per_to_close=
new ICheckBox(
'sel_per_close[]');
233 $per_to_close->value=$l_line[
'p_id'];
234 echo $per_to_close->input();
238 echo
'<TD ALIGN="CENTER"> '.$l_line[
'date_start'].
'</TD>';
239 echo
'<TD ALIGN="CENTER"> '.$l_line[
'date_end'].
'</TD>';
240 echo
'<TD ALIGN="CENTER"> '.$l_line[
'p_exercice'].
'</TD>';
242 if ( $l_line[
'p_closed'] ==
't' )
244 $closed=($l_line[
'p_central']==
't')?
'<TD>Centralisée</TD>':
'<TD>Fermée</TD>';
246 $remove=sprintf(_(
'Nombre opérations %d'),$l_line[
'count_op']);
247 $remove=
td($remove,
' class="mtitle" ');
248 $change=
td (
'<A class="mtitle" HREF="javascript:void(0)"'
249 .
' onclick="return confirm_box(null,\''._(
'Confirmez Réouverture').
' ?\',function() {window.location=\'do.php?ac='.
$_REQUEST[
'ac'].
'&action=reopen&p_per='.$l_line[
'p_id'].
'&'.
$str_dossier.
'\';} )
"> Réouverture</A>',' class="mtitle
"');
254 if ($l_line['count_op'] == 0 )
256 $change=HtmlInput::display_periode($l_line['p_id']);
260 $change="Non modifiable
";
262 $change=td($change,' class="mtitle
" ');
266 $remove='<TD class="mtitle
">';
269 if ($l_line['count_op'] == 0 )
271 $go='do.php?'.http_build_query(array('ac'=>$_REQUEST['ac'],
272 'action'=>'delete_per',
273 'p_per'=>$l_line['p_id'],
274 'gDossier'=>Dossier::id()));
276 $remove.='<A class="mtitle
" HREF="javascript:
void(0)
" '
277 . 'onclick="return confirm_box (null,\
''._(
'Confirmez effacement ?').
'\',
function() {
window.location=\
''.$go.
'\'});
" >'
282 $remove.=sprintf(_('Nombre opérations %d'),$l_line['count_op']);
294 echo '<p style="text-align:center
">';
295 echo HtmlInput::hidden("close_per
", 1);
296 echo HtmlInput::submit('close_per_bt','Fermeture des périodes sélectionnées');
299 $but=new IButton('show_per_add','Ajout d\'une période');
300 $but->javascript="$(
'periode_add_div').
show();
";
302 echo '<div class="inner_box
" style="width:40%;
" id="periode_add_div
">';
303 echo HtmlInput::title_box("Ajout d
'une période","periode_add_div","hide");
304 echo '<FORM METHOD=
"POST">
';
305 echo dossier::hidden();
306 $istart=new IDate('p_date_start
');
307 $iend=new IDate('p_date_end
');
308 $iexercice=new INum('p_exercice
');
312 echo td('Date de début
');
313 echo td($istart->input());
315 echo td('Date de fin
');
316 echo td($iend->input());
320 echo td($iexercice->input());
324 echo HtmlInput::submit('add_per
','Valider
');
327 echo create_script("$('periode_add_div
').hide();new Draggable('periode_add_div
',{starteffect:function()
329 new Effect.Highlight(obj.id,{scroll:window,queue:'end
'});
335 $Res=$this->cn->exec_sql("select p_id,to_char(p_start,'DD.MM.YYYY
') as date_start,to_char(p_end,'DD.MM.YYYY
') as date_end,status,p_exercice
336 from parm_periode join jrn_periode using (p_id) where jrn_def_id=".$this->jrn_def_id."
337 order by p_start,p_end");
338 $Max=Database::num_row($Res);
339 $r=$this->cn->exec_sql('select jrn_Def_name
from jrn_Def where jrn_Def_id=
'.
341 $jrn_name=Database::fetch_result($r,0,0);
342 echo '<
h2> Journal
'.$jrn_name.'</
h2>
';
343 echo '<form
id=
"periode_frm" method=
"POST" onsubmit=
"return confirm_box(this,\'Confirmez-vous la fermeture des périodes choisies ?\')" >
';
344 echo HtmlInput::array_to_hidden(array('ac
','gDossier
','jrn_def_id
','choose
'), $_REQUEST);
346 echo '<TABLE ALIGN=
"CENTER">
';
348 echo '<
th>
'.ICheckBox::toggle_checkbox("per_toggle", "periode_frm")."</th>";
349 echo '<TH> Date début </TH>
';
350 echo '<TH> Date fin </TH>
';
354 for ($i=0;$i<$Max;$i++)
356 $l_line=Database::fetch_array($Res,$i);
357 if ( $l_line['status
'] != 'OP
' )
358 echo '<TR
style=
"COLOR:RED">
';
362 if ( $l_line['status
'] == 'OP
') {
363 $per_to_close=new ICheckBox('sel_per_close[]
');
364 $per_to_close->value=$l_line['p_id'];
365 echo $per_to_close->input();
368 echo '<TD ALIGN=
"CENTER">
'.$l_line['date_start
'].'</TD>
';
369 echo '<TD ALIGN=
"CENTER">
'.$l_line['date_end
'].'</TD>
';
370 echo '<TD ALIGN=
"CENTER">
'.$l_line['p_exercice
'].'</TD>
';
372 if ( $l_line['status
'] != 'OP
' )
374 $go='do.php?
'.http_build_query(array('ac
'=>$_REQUEST['ac
'],
376 'p_per
'=>$l_line['p_id'],
377 'gDossier
'=>Dossier::id(),
378 'jrn_def_id
'=>$this->jrn_def_id));
380 $closed=td ('<A
class=
"mtitle" HREF=
"javascript:void(0)" '
381 . 'onclick=
"return confirm_box(null,\''._('Confirmez Réouverture').' ?\',function() {window.location=\''.$go.'\';} );"> Réouverture</A>
',' class=
"mtitle"');
390 echo '<p style=
"text-align:center">
';
391 echo HtmlInput::submit('close_per
','Fermeture des périodes sélectionnées
');
397 function insert($p_date_start,$p_date_end,$p_exercice)
402 if (isDate($p_date_start) == null ||
403 isDate($p_date_end) == null ||
404 strlen (trim($p_exercice)) == 0 ||
405 (string) $p_exercice != (string)(int) $p_exercice
406 ||$p_exercice < COMPTA_MIN_YEAR || $p_exercice > COMPTA_MAX_YEAR)
409 throw new Exception ("Paramètre invalide");
411 $p_id=$this->cn->get_next_seq('s_periode
');
412 $sql=sprintf(" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice)".
413 "values (%d,to_date('%s
','DD.MM.YYYY
'),to_date('%s
','DD.MM.YYYY
')".
420 $Res=$this->cn->exec_sql($sql);
421 $Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ".
422 "select jrn_def_id,$p_id,'OP
' from jrn_def");
427 $this->cn->rollback();
437 if ($this->p_id == '
') $this->p_id=-1;
438 $row=$this->cn->get_array("select p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1",
440 if ($row == null ) return -1;
442 $this->p_start=$row[0]['p_start
'];
443 $this->p_end=$row[0]['p_end
'];
444 $this->p_exercice=$row[0]['p_exercice
'];
445 $this->p_closed=$row[0]['p_closed
'];
446 $this->p_central=$row[0]['p_central
'];
455 function get_limit($p_exercice)
458 $max=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start asc limit 1",array($p_exercice));
459 $min=$this->cn->get_value("select p_id from parm_periode where p_exercice=$1 order by p_start desc limit 1",array($p_exercice));
460 $rMax=new Periode($this->cn);
462 if ( $rMax->load() ) throw new Exception('
Periode n\
'existe pas');
465 if ( $rMin->load() )
throw new Exception(
'Periode n\'existe pas');
466 return array($rMax,$rMin);
481 $sql=
"select to_char(p_start,'DD.MM.YYYY') as p_start,
482 to_char(p_end,'DD.MM.YYYY') as p_end
485 $Res=$this->
cn->exec_sql(
$sql,array($p_periode));
514 $sql=
"select p_exercice from parm_periode where p_id=".$p_id;
527 $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') ";
530 if ( $nb_periode == 0 )
531 throw (
new Exception(
'Aucune période trouvée',101));
532 if ( $nb_periode > 1 )
533 throw (
new Exception(
"Trop de périodes trouvées $nb_periode pour $p_date",100));
545 if ( $nb_periode != 12 && $nb_periode != 13)
throw new Exception (
'Nombre de période incorrectes');
547 for ($i=1;$i < 12;$i++)
550 $date_end=$this->
cn->get_value(
"select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')",array(
$date_start));
553 throw new Exception(
'Erreur insertion période');
558 throw new Exception(
'Erreur insertion période');
560 if ( $nb_periode==13)
563 throw new Exception(
'Erreur insertion période');
565 throw new Exception(
'Erreur insertion période');
573 $this->
cn->rollback();
581 $obj->display_form_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...
function confirm_box(p_obj, p_message, p_callback_true)
Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise false.
find_periode($p_date)
retrieve the periode thanks the date_end
td($p_string='', $p_extra='')
surround the string with td
static num_row($ret)
wrapper for the function pg_NumRows
h2($p_string, $p_class="", $raw="")
th($p_string, $p_extra='', $raw='')
is_open()
Return 1 if the periode is open otherwise 0.
get_date_limit($p_periode=0)
Give the start & end date of a periode.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
__construct($p_cn, $p_id=0)
Calendar prototype show
Shows the calendar.
For the periode tables parm_periode and jrn_periode.
insert_exercice($p_exercice, $nb_periode)
add a exerice of 13 periode
display_form_periode()
Display all the periode and their status.
close()
Close a periode , if Periode::jrn_def_id is set to a different value than 0 , it close only for this ...
is_centralized()
Return 1 if periode is centralized.
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
limit_year($p_exercice)
return the p_id of the start and the end of the exercice into an array
tr($p_string, $p_extra='')
insert($p_date_start, $p_date_end, $p_exercice)
first_day($p=0)
return the first day of periode the this->p_id must be set
last_day($p=0)
return the last day of periode the this->p_id must be set