Add 12 or 13 periodes

This commit is contained in:
Dany De Bontridder 2012-01-16 14:27:52 +00:00
parent da4089960d
commit 3c53e601a0
3 changed files with 35 additions and 11 deletions

View file

@ -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();
}

View file

@ -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

View file

@ -1,11 +1,15 @@
<fieldset><legend>Ajout d'un exercice</legend>
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
<ul>
<li>
Exercice en 12 périodes : Ajout d'un exercice comptable de 12 périodes, commençant le 1 janvier et terminant le 31 décembre. </li>
<li> Exercice en 13 périodes: Ajout d'une période d'un jour le 31/12. Cette période est utilisée
pour faire tous les écritures de fin d'exercice: amortissements, régulations de compte... Avec une 13ième période, cela simplifie les prévisions, les rapports...</li>
</ul>
<form method="post" onsubmit="return confirm('Confirmez vous l\'ajout d\'un exercice comptable ?')">
<?
echo HtmlInput::hidden("ac",$_REQUEST['ac']);
echo HtmlInput::hidden("jrn_def_id","0");
echo $nb_exercice->input();
echo HtmlInput::hidden("jrn_def_id","0");
echo Dossier::hidden();
echo HtmlInput::submit("add_exercice","Ajout d'un exercice comptable");