noalyss Version-9
Public Member Functions | Static Public Member Functions | Data Fields
Periode Class Reference

For the periode tables parm_periode and jrn_periode. More...

+ Collaboration diagram for Periode:

Public Member Functions

 __construct ($p_cn, $p_id=0)
 
 __toString ()
 
 centralized ()
 
 close ()
 Close a periode , if Periode::jrn_def_id is set to a different value than 0 , it close only for this ledger id ; otherwise close for all periode. More...
 
 count_operation ()
 count the number of operation of a Periode More...
 
 delete ()
 
 find_periode ($p_date)
 retrieve the periode thanks the date_end More...
 
 first_day ($p=0)
 return the first day of periode the this->p_id must be set More...
 
 get_date_limit ($p_periode=0)
 Give the start & end date of a periode. More...
 
 get_exercice ($p_id=0)
 
 get_first_date ()
 retrieve the first day of the first exercice More...
 
 get_first_periode ()
 retrieve the first periode of the folder or -1 if none More...
 
 get_limit ($p_exercice)
 return the max and the min periode of the exercice given in parameter More...
 
 insert ($p_date_start, $p_date_end, $p_exercice, $p_exercice_label)
 Add new periode. More...
 
 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 More...
 
 is_centralized ()
 Return 1 if periode is centralized. More...
 
 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 More...
 
 is_open ()
 Return 1 if the periode is open otherwise 0. More...
 
 last_day ($p=0)
 return the last day of periode the this->p_id must be set More...
 
 limit_year ($p_exercice)
 return the p_id of the start and the end of the exercice into an array More...
 
 load ()
 load data from database More...
 
 reopen ()
 
 set_ledger ($p_jrn)
 
 set_periode ($pp_id)
 
 verify_delete ()
 Verify before delete that the month is not used. More...
 

Static Public Member Functions

static display_periode_global ($p_js)
 Display a table with all the periode. More...
 
static display_row_global (Parm_Periode_SQL $obj, $p_nb, $p_js)
 Display each row for the global. More...
 
static filter_exercice ($p_sel)
 
static form_exercice_add ()
 display a form (method POST) to input a new exercice variable in the FORM More...
 
static form_exercice_label ()
 form to change the label of exercice More...
 
static form_periode_add ($p_js_var)
 Display a form for the input of a new periode. More...
 

Data Fields

 $cn
 
 $jrn_def_id
 
 $p_central
 
 $p_closed
 
 $p_end
 
 $p_exercice
 
 $p_exercice_label
 
 $p_id
 
 $p_start
 
 $status
 

Detailed Description

For the periode tables parm_periode and jrn_periode.

Definition at line 32 of file periode.class.php.

Constructor & Destructor Documentation

◆ __construct()

Periode::__construct (   $p_cn,
  $p_id = 0 
)

Definition at line 46 of file periode.class.php.

47 {
48 $this->p_id=$p_id;
49 $this->cn=$p_cn;
50 $this->jrn_def_id=0;
51 }
$profile p_id
margin jrn_def_id
$input_from cn
Definition: balance.inc.php:66

References $p_id, cn, jrn_def_id, and p_id.

Member Function Documentation

◆ __toString()

Periode::__toString ( )

Definition at line 53 of file periode.class.php.

53 : 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 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
For the periode tables parm_periode and jrn_periode.

References $jrn_def_id, $p_end, $p_id, $p_start, $r, and $status.

◆ centralized()

Periode::centralized ( )
Deprecated:
since version 5
Returns
type

Definition at line 221 of file periode.class.php.

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 }

References cn, jrn_def_id, and p_id.

◆ close()

Periode::close ( )

Close a periode , if Periode::jrn_def_id is set to a different value than 0 , it close only for this ledger id ; otherwise close for all periode.

Definition at line 187 of file periode.class.php.

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 }

References cn, jrn_def_id, and p_id.

◆ count_operation()

Periode::count_operation ( )

count the number of operation of a Periode

Returns
integer

Definition at line 566 of file periode.class.php.

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 }
$count

References $count, cn, and p_id.

◆ delete()

Periode::delete ( )

Definition at line 702 of file periode.class.php.

702 {
703 $this->cn->exec_sql("delete from parm_periode where p_id=$1",[$this->p_id]);
704 }

References cn, and p_id.

◆ display_periode_global()

static Periode::display_periode_global (   $p_js)
static

Display a table with all the periode.

Parameters
$p_jsjavascript variable
See also
noalyss_script.js

Definition at line 530 of file periode.class.php.

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 }
th($p_string, $p_extra='', $raw='')
Definition: ac_common.php:58
static num_row($ret)
wrapper for the function pg_num_rows
static connect()
static display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
Display each row for the global.

References $cn, $i, $obj, $periode, $ret, Dossier\connect(), display_row_global(), DatabaseCore\num_row(), and th().

+ Here is the call graph for this function:

◆ display_row_global()

static Periode::display_row_global ( Parm_Periode_SQL  $obj,
  $p_nb,
  $p_js 
)
static

Display each row for the global.

Parameters
$objParm_Periode_SQL
$p_nbnot used so far
$p_jsjavascript variable

Display a checkbox to select several month to close

Can close if open

Definition at line 583 of file periode.class.php.

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 }
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
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$class
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.
$nb_operation

References $checkbox, $class, $js, $nb_operation, $obj, $periode, $status, format_date(), Icon_Action\iconoff(), Icon_Action\iconon(), Icon_Action\modify(), td(), and Icon_Action\trash().

Referenced by display_periode_global().

+ Here is the call graph for this function:

◆ filter_exercice()

static Periode::filter_exercice (   $p_sel)
static

Definition at line 755 of file periode.class.php.

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 }
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...

References $cn, and Dossier\connect().

+ Here is the call graph for this function:

◆ find_periode()

Periode::find_periode (   $p_date)

retrieve the periode thanks the date_end

Parameters
$p_dateformat DD.MM.YYYY
Returns
the periode id
Exceptions
ifnot periode is found or if more than one periode is found

Definition at line 413 of file periode.class.php.

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 }
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all

References $p_date, $per, $ret, $sql, cn, DatabaseCore\fetch_result(), DatabaseCore\num_row(), and p_id.

+ Here is the call graph for this function:

◆ first_day()

Periode::first_day (   $p = 0)

return the first day of periode the this->p_id must be set

Returns
a string with the date (DD.MM.YYYY)

Definition at line 375 of file periode.class.php.

376 {
377 if ($p==0)
379 list($p_start, $p_end)=$this->get_date_limit($p);
380 return $p_start;
381 }
$p
Definition: array.php:34
get_date_limit($p_periode=0)
Give the start & end date of a periode.

References $p, $p_end, $p_id, $p_start, and get_date_limit().

+ Here is the call graph for this function:

◆ form_exercice_add()

static Periode::form_exercice_add ( )
static

display a form (method POST) to input a new exercice variable in the FORM

  • p_exercice
  • p_year
  • nb_month
  • from_month
  • day_opening
  • day_closing
  • p_exercice_label

Definition at line 663 of file periode.class.php.

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 }
catch(Exception $e) $exercice
$from
Definition: balance.inc.php:61
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.
Definition: itext.class.php:30

References $cn, $exercice, $exercice_label, $from, $i, $year, and Dossier\connect().

+ Here is the call graph for this function:

◆ form_exercice_label()

static Periode::form_exercice_label ( )
static

form to change the label of exercice

Definition at line 697 of file periode.class.php.

698 {
700 require_once NOALYSS_TEMPLATE."/periode-form_exercice_label.php";
701 }

References $cn, and Dossier\connect().

+ Here is the call graph for this function:

◆ form_periode_add()

static Periode::form_periode_add (   $p_js_var)
static

Display a form for the input of a new periode.

Definition at line 721 of file periode.class.php.

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 }
tr($p_string, $p_extra='')
Definition: ac_common.php:88
if(headers_sent() &&DEBUGNOALYSS > 0) $html
static hidden()
return a string to set gDossier into a FORM
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 : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34

References $cn, $html, $http, $p_end, $p_exercice, $p_start, $title, HtmlInput\button(), Dossier\connect(), HtmlInput\hidden(), Dossier\hidden(), HtmlInput\submit(), td(), HtmlInput\title_box(), and tr().

+ Here is the call graph for this function:

◆ get_date_limit()

Periode::get_date_limit (   $p_periode = 0)

Give the start & end date of a periode.

Parameters
$p_periodeis the periode id, if omitted the value is the current object
Returns
array containing the start date & the end date, index are p_start and p_end or NULL if nothing is found
$ret['p_start']=>'01.01.2009'
$ret['p_end']=>'31.01.2009'

Definition at line 356 of file periode.class.php.

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 }
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
$Res

References $p_id, $Res, $sql, cn, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

Referenced by first_day(), and last_day().

+ Here is the call graph for this function:

◆ get_exercice()

Periode::get_exercice (   $p_id = 0)

Definition at line 396 of file periode.class.php.

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 }

References $p_id, $Res, $sql, cn, DatabaseCore\fetch_result(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_first_date()

Periode::get_first_date ( )

retrieve the first day of the first exercice

Returns
: string date format "DD.MM.YYYYY"

Definition at line 769 of file periode.class.php.

769 :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 }

References cn.

◆ get_first_periode()

Periode::get_first_periode ( )

retrieve the first periode of the folder or -1 if none

Returns
int

Definition at line 779 of file periode.class.php.

779 :int
780 {
781 return $this->cn->get_value("select p_id from parm_periode order by p_start asc limit 1");
782 }

References cn.

◆ get_limit()

Periode::get_limit (   $p_exercice)

return the max and the min periode of the exercice given in parameter

Parameters
$p_exerciceis the exercice
Returns
an array of Periode object

Definition at line 327 of file periode.class.php.

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 }

References $max, $min, $p_exercice, and cn.

◆ insert()

Periode::insert (   $p_date_start,
  $p_date_end,
  $p_exercice,
  $p_exercice_label 
)

Add new periode.

Parameters
date$p_date_start
date$p_date_end
int$p_exercice
Returns
int p_id of the new periode
Exceptions
Exception10 Invalide date or exercice, 20 overlapping periode

Definition at line 244 of file periode.class.php.

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 }
isNumber($p_int)
Definition: ac_common.php:215
isDate($p_date)
Definition: ac_common.php:236
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
const COMPTA_MIN_YEAR
Definition: constant.php:141
const COMPTA_MAX_YEAR
Definition: constant.php:140

References $e, $p_exercice, $p_exercice_label, $p_id, $Res, $sql, cn, COMPTA_MAX_YEAR, COMPTA_MIN_YEAR, isDate(), isNumber(), noalyss_strlentrim(), and record_log().

Referenced by insert_exercice().

+ Here is the call graph for this function:

◆ insert_exercice()

Periode::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

Parameters
$p_exercicethe exercice
$p_yearthe starting year
$p_from_monthstarting month
$p_monthnumber of month of the exercice
$p_opening1 if we create a one-day periode for opening writings
$p_closing1 if we create a one-day periode for closing writings
$p_exercice_labellabel of the exercice

Definition at line 439 of file periode.class.php.

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
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
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));
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 }
$date_start
insert($p_date_start, $p_date_end, $p_exercice, $p_exercice_label)
Add new periode.
if( $delta< 0) elseif( $delta==0)

References $date_end, $date_start, $e, $i, $p_exercice, $p_exercice_label, $year, cn, COMPTA_MAX_YEAR, COMPTA_MIN_YEAR, elseif, insert(), isNumber(), and record_log().

+ Here is the call graph for this function:

◆ is_centralized()

Periode::is_centralized ( )

Return 1 if periode is centralized.

Deprecated:
Note
deprecated , centralization not used anymore

Definition at line 144 of file periode.class.php.

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);
156 if ($status=='CE'||$status=='t')
157 return 1;
158 return 0;
159 }

References $res, $sql, $status, cn, DatabaseCore\fetch_result(), and jrn_def_id.

+ Here is the call graph for this function:

◆ is_closed()

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

See also
Periode::set_ledger
Returns
1 is the periode is closed otherwise return 0

Definition at line 100 of file periode.class.php.

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);
112 if ($status=='CL'||$status=='t'||$status=='CE')
113 return 1;
114 return 0;
115 }

References $res, $sql, $status, cn, DatabaseCore\fetch_result(), and jrn_def_id.

+ Here is the call graph for this function:

◆ is_open()

Periode::is_open ( )

Return 1 if the periode is open otherwise 0.

Note
For only a ledger you must set Periode::jrn_def_id to the ledger id
See also
Periode::set_ledger

Definition at line 120 of file periode.class.php.

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 }

References $sql, $status, cn, jrn_def_id, and p_id.

◆ last_day()

Periode::last_day (   $p = 0)

return the last day of periode the this->p_id must be set

Returns
a string with the date (DD.MM.YYYY)

Definition at line 388 of file periode.class.php.

389 {
390 if ($p==0)
392 list($p_start, $p_end)=$this->get_date_limit($p);
393 return $p_end;
394 }

References $p, $p_end, $p_id, $p_start, and get_date_limit().

+ Here is the call graph for this function:

◆ limit_year()

Periode::limit_year (   $p_exercice)

return the p_id of the start and the end of the exercice into an array

Parameters
$p_exercice
Returns
array [start]=>,[end]=>

Definition at line 85 of file periode.class.php.

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 }

References $end, $p_exercice, $start, and cn.

◆ load()

Periode::load ( )

load data from database

Returns
0 on success and -1 on error

Definition at line 303 of file periode.class.php.

303 :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 }

References $row, cn, and p_id.

◆ reopen()

Periode::reopen ( )

Definition at line 161 of file periode.class.php.

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 }

References cn, jrn_def_id, and p_id.

◆ set_ledger()

Periode::set_ledger (   $p_jrn)

Definition at line 68 of file periode.class.php.

69 {
70 $this->jrn_def_id=$p_jrn;
71 }

References $p_jrn, and jrn_def_id.

◆ set_periode()

Periode::set_periode (   $pp_id)

Definition at line 73 of file periode.class.php.

74 {
75 $this->p_id=$pp_id;
76 }

References p_id.

◆ verify_delete()

Periode::verify_delete ( )

Verify before delete that the month is not used.

Exceptions
Exceptioncode 1 if periode used

Definition at line 709 of file periode.class.php.

709 {
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 }
$ex
Definition: balance.inc.php:45

References $ex, and cn.

Field Documentation

◆ $cn

Periode::$cn

database connection

Definition at line 35 of file periode.class.php.

Referenced by display_periode_global(), filter_exercice(), form_exercice_add(), form_exercice_label(), and form_periode_add().

◆ $jrn_def_id

Periode::$jrn_def_id

the jr, 0 means all the ledger

Definition at line 36 of file periode.class.php.

Referenced by __toString().

◆ $p_central

Periode::$p_central

NOT USED

Definition at line 44 of file periode.class.php.

◆ $p_closed

Periode::$p_closed

if exercice is closed

Definition at line 43 of file periode.class.php.

◆ $p_end

Periode::$p_end

end of the periode

Definition at line 41 of file periode.class.php.

Referenced by __toString(), first_day(), form_periode_add(), and last_day().

◆ $p_exercice

Periode::$p_exercice

exercice

Definition at line 42 of file periode.class.php.

Referenced by form_periode_add(), get_limit(), insert(), insert_exercice(), and limit_year().

◆ $p_exercice_label

Periode::$p_exercice_label

Label of the exercice

Definition at line 45 of file periode.class.php.

Referenced by insert(), and insert_exercice().

◆ $p_id

Periode::$p_id

pk of parm_periode

Definition at line 37 of file periode.class.php.

Referenced by __construct(), __toString(), first_day(), get_date_limit(), get_exercice(), insert(), and last_day().

◆ $p_start

Periode::$p_start

start of the periode

Definition at line 40 of file periode.class.php.

Referenced by __toString(), first_day(), form_periode_add(), and last_day().

◆ $status

Periode::$status

status is CL for closed, OP for open and CE for centralized

Definition at line 38 of file periode.class.php.

Referenced by __toString(), display_row_global(), is_centralized(), is_closed(), and is_open().


The documentation for this class was generated from the following file: