diff --git a/include/class_periode.php b/include/class_periode.php index 6422cc057..19acfeccc 100644 --- a/include/class_periode.php +++ b/include/class_periode.php @@ -345,6 +345,9 @@ class Periode } function insert($p_date_start,$p_date_end,$p_exercice) { + try + { + if (isDate($p_date_start) == null || isDate($p_date_end) == null || strlen (trim($p_exercice)) == 0 || @@ -352,7 +355,7 @@ class Periode ||$p_exercice < 2000 || $p_exercice > 2099 ) { - return 1; + throw new Exception ("Paramètre invalide"); } $p_id=$this->cn->get_next_seq('s_periode'); $sql=sprintf(" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice)". @@ -362,8 +365,6 @@ class Periode $p_date_start, $p_date_end, $p_exercice); - try - { $this->cn->start(); $Res=$this->cn->exec_sql($sql); $Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ". @@ -484,18 +485,31 @@ class Periode /** *add a exerice of 13 periode */ - function insert_exercice($p_exercice) + function insert_exercice($p_exercice,$nb_periode) { try { + if ( $nb_periode != 12 && $nb_periode != 13) throw new Exception ('Nombre de période incorrectes'); $this->cn->start(); for ($i=1;$i < 12;$i++) { $date_start=sprintf('01.%02d.%d',$i,$p_exercice); $date_end=$this->cn->get_value("select to_char(to_date('$date_start','DD.MM.YYYY')+interval '1 month'-interval '1 day','DD.MM.YYYY')"); - $this->insert($date_start,$date_end,$p_exercice); + if ( $this->insert($date_start,$date_end,$p_exercice) != 0) + { + throw new Exception('Erreur insertion période'); + } } - $this->insert('01.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice); + if ( $nb_periode==12 && $this->insert('01.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 ) + { + throw new Exception('Erreur insertion période'); + } + if ( $nb_periode==13) + { + if ($this->insert('01.12.'.$p_exercice,'30.12.'.$p_exercice,$p_exercice) != 0 ) throw new Exception('Erreur insertion période'); + if ($this->insert('31.12.'.$p_exercice,'31.12.'.$p_exercice,$p_exercice) != 0 ) throw new Exception('Erreur insertion période'); + } + $this->cn->commit(); } diff --git a/include/periode.inc.php b/include/periode.inc.php index f3ca20b11..12d5d2e52 100644 --- a/include/periode.inc.php +++ b/include/periode.inc.php @@ -51,7 +51,7 @@ if (isset($_POST['add_exercice'])) { $obj=new Periode($cn); $exercice=$cn->get_value('select max(p_exercice::float)+1 from parm_periode'); - if ( $obj->insert_exercice($exercice) == 1 ) + if ( $obj->insert_exercice($exercice,$_POST['nb_exercice']) == 1 ) { alert(_('Valeurs invalides')); } @@ -102,6 +102,12 @@ if ( $choose=="yes" ) $per->set_jrn($jrn); $per->display_form_periode(); + $nb_exercice=new ISelect("nb_exercice"); + $nb_exercice->value=array( + array('value'=>12,'label'=>"12 périodes"), + array('value'=>13,'label'=>"13 périodes") + ); + require_once('template/periode_add_exercice.php'); } else diff --git a/include/template/periode_add_exercice.php b/include/template/periode_add_exercice.php index 59c3d600b..def3c6556 100644 --- a/include/template/periode_add_exercice.php +++ b/include/template/periode_add_exercice.php @@ -1,11 +1,15 @@
Ajout d'un exercice -Ajout d'un exercice comptable de 12 périodes, commençant le 1 janvier et terminant le 31 décembre. Si vous souhaitez une 13ième période (le 31/12) -pour faire tous les écritures de fin d'exercice: amortissements, régulations de compte... Il vous suffit de raccourcir d'allonger la période de décembre jusqu'au 30/12 -et d'ajouter une période d'un jour allant du 31/12 au 31/12 + +
input(); echo HtmlInput::hidden("jrn_def_id","0"); echo Dossier::hidden(); echo HtmlInput::submit("add_exercice","Ajout d'un exercice comptable");