noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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.
 
 count_operation ()
 count the number of operation of a Periode
 
 delete ()
 
 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
 
 get_date_limit ($p_periode=0)
 Give the start & end date of a periode.
 
 get_exercice ($p_id=0)
 
 get_first_date ()
 retrieve the first day of the first exercice
 
 get_first_periode ()
 retrieve the first periode of the folder or -1 if none
 
 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.
 
 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
 
 is_centralized ()
 Return 1 if periode is centralized.
 
 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
 
 is_open ()
 Return 1 if the periode is open otherwise 0.
 
 last_day ($p=0)
 return the last day of periode the this->p_id must be set
 
 limit_year ($p_exercice)
 return the p_id of the start and the end of the exercice into an array
 
 load ()
 load data from database
 
 reopen ()
 
 set_ledger ($p_jrn)
 
 set_periode ($pp_id)
 
 verify_delete ()
 Verify before delete that the month is not used.
 

Static Public Member Functions

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

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

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,
62]
63EOF;
64 return $r;
65
66 }
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

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

◆ centralized()

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

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

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 }

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 193 of file periode.class.php.

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 }

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 573 of file periode.class.php.

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

References $count, cn, and p_id.

◆ delete()

Periode::delete ( )

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

709 {
710 $this->cn->exec_sql("delete from parm_periode where p_id=$1",[$this->p_id]);
711 }

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 537 of file periode.class.php.

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);
563 Periode::display_row_global($obj, $i, $p_js);
564 }
565 echo '</tbody>';
566 echo '</table>';
567 }
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
_("actif, passif,charge,...")
static num_row($ret)
wrapper for the function pg_num_rows

References $cn, $i, $obj, $periode, $ret, _, 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 590 of file periode.class.php.

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

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

References $cn.

◆ 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 420 of file periode.class.php.

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 }
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 382 of file periode.class.php.

383 {
384 if ($p==0)
386 list($p_start, $p_end)=$this->get_date_limit($p);
387 return $p_start;
388 }
$p
Definition calendar.php:9
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 670 of file periode.class.php.

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 }
catch(Exception $e) $exercice
$from
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input.

References $cn, $exercice, $exercice_label, $from, $i, $year, and _.

◆ form_exercice_label()

static Periode::form_exercice_label ( )
static

form to change the label of exercice

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

705 {
706 $cn=Dossier::connect();
707 require_once NOALYSS_TEMPLATE."/periode-form_exercice_label.php";
708 }

References $cn.

◆ 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 728 of file periode.class.php.

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

References $cn, $html, $http, $p_end, $p_exercice, $p_start, $title, _, td(), 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 363 of file periode.class.php.

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

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 403 of file periode.class.php.

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 }

References $p_id, $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 776 of file periode.class.php.

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

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 786 of file periode.class.php.

786 :int
787 {
788 return $this->cn->get_value("select p_id from parm_periode order by p_start asc limit 1");
789 }

References cn.

◆ get_limit()

Periode::get_limit ( $p_exercice)

return the max (to periode) and the min periode (from periode) of the exercice given in parameter

Parameters
$p_exerciceis the exercice (parm_periode.p_exercice)
Returns
an array of Periode object

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

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 }

References $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 250 of file periode.class.php.

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 }
isNumber($p_int)
isDate($p_date)
noalyss_strlentrim($p_string)
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...
const COMPTA_MIN_YEAR
Definition constant.php:140
const COMPTA_MAX_YEAR
Definition constant.php:139
$p_exercice

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 446 of file periode.class.php.

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
491 $this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
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
504 $this->insert($date_end, $date_end, $p_exercice,$p_exercice_label);
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));
512 $this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
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 }
$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 150 of file periode.class.php.

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 }

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 {
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 }

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

◆ 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 126 of file periode.class.php.

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 }

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 395 of file periode.class.php.

396 {
397 if ($p==0)
399 list($p_start, $p_end)=$this->get_date_limit($p);
400 return $p_end;
401 }

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 309 of file periode.class.php.

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

References $row, cn, and p_id.

◆ reopen()

Periode::reopen ( )

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

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 }

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 716 of file periode.class.php.

716 {
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 }
$ex

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(), get_exercice(), and insert().

◆ $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: