Task #0002101: Exercice : pouvoir donner un texte libre

This commit is contained in:
sparkyx 2021-12-02 17:26:15 +01:00
parent 7bc7bed8d8
commit bc7169b2ac
12 changed files with 176 additions and 53 deletions

View file

@ -3334,7 +3334,7 @@ var Periode = function (p_ledger) {
onSuccess: function (req) {
remove_waiting_box();
var json = req.responseText.evalJSON();
var y = calcy(100);
var y = 100;
add_div({"id": "mod_periode", "style": "position:fixed;top:" + y + "px;width:50%", "cssclass": "inner_box", 'html': "wait"});
$('mod_periode').update(json.content);
}

View file

@ -61,9 +61,10 @@ if ( isset($_GET['f_id']))
$array['to_periode']=$limit_periode[1]->last_day();
if (isset($_GET['ex']))
{
$ex=$http->get('ex','number');
$limit_periode=$per->get_limit($ex);
if ( $ex < $year)
$ex=$http->get('ex','string');
$other_year=$exercice->exercice_from_label($ex);
$limit_periode=$per->get_limit($other_year);
if ( $other_year < $year)
$array['from_periode']=$limit_periode[0]->first_day();
else
$array['to_periode']=$limit_periode[1]->last_day();
@ -75,7 +76,8 @@ if ( isset($_GET['f_id']))
*/
if ($exercice->count() > 1 )
{
$default=$http->get("ex","number",$year);
$default_ex=$http->get("ex","string",$year);
$default=$exercice->exercice_from_label($default_ex);
$dossier=dossier::id();
if ( $div != 'popup')
{
@ -132,6 +134,7 @@ if ( isset($_GET['f_id']))
///////////////////////////////////////////////////////////////////////////
if ( isset($_REQUEST['pcm_val']))
{
$exercice=new Exercice($cn);
$pcm_val=$http->request("pcm_val");
$poste=new Acc_Account_Ledger($cn,$pcm_val);
$poste->load();
@ -143,7 +146,6 @@ if ( isset($_REQUEST['pcm_val']))
}
else
{
$exercice=new Exercice($cn);
$old='';
$per=new Periode($cn);
$limit_periode=$per->get_limit($year);
@ -151,9 +153,10 @@ if ( isset($_REQUEST['pcm_val']))
$array['to_periode']=$limit_periode[1]->last_day();
if (isset($_GET['ex']))
{
$ex=$http->get("ex","number");
$limit_periode=$per->get_limit($ex);
if ( $ex < $year)
$ex=$http->get("ex","string");
$other_year=$exercice->exercice_from_label($ex);
$limit_periode=$per->get_limit($other_year);
if ( $other_year < $year)
$array['from_periode']=$limit_periode[0]->first_day();
else
$array['to_periode']=$limit_periode[1]->last_day();
@ -164,7 +167,9 @@ if ( isset($_REQUEST['pcm_val']))
*/
if ($exercice->count() > 1 )
{
$default=$http->get("ex","number",$year);
$default_ex=$http->get("ex","string",$year);
$default=$exercice->exercice_from_label($default_ex);
$dossier=dossier::id();
if ( $div != 'popup')
{

View file

@ -175,6 +175,7 @@ switch ($act)
'onclick="removeDiv(\'mod_periode\')"');
$html.=HtmlInput::hidden('p_id', $periode_id);
$html.='</form>';
$a_answer['status']="OK";
$a_answer['content']=$html;
break;
// Save a modification of a periode
@ -187,19 +188,27 @@ switch ($act)
$p_start=$http->post("p_start", "date");
$p_end=$http->post("p_end", "date");
$p_exercice=$http->post("p_exercice", "number");
if ($p_exercice>2099||$p_exercice<1980)
if ($p_exercice>COMPTA_MAX_YEAR||$p_exercice<COMPTA_MIN_YEAR)
{
$html='';
$html.=_('Erreur exercice invalide');
$a_answer['content']=_('Erreur exercice invalide');
}
else
{
$sql="update parm_periode set p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3 where p_id=$4";
$sql="update parm_periode set p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3,p_exercice_label=$5 where p_id=$4";
try
{
$cn->start();
$exercice_label=$cn->get_value("select distinct p_exercice_label from "
. " parm_periode where p_exercice=$1",
[$p_exercice]);
if (empty($exercice_label)) {
$exercice_label=$p_exercice;
}
$cn->exec_sql($sql,
array($p_start, $p_end, $p_exercice, $periode_id));
array($p_start, $p_end, $p_exercice, $periode_id,$exercice_label));
$a_answer["status"]="OK";
$cn->commit();
}
catch (Exception $e)
{
@ -207,15 +216,15 @@ switch ($act)
$html=$e->getTrace();
throw $e;
}
$parm_periode=new Parm_periode_SQL($cn, $periode_id);
ob_start();
Periode::display_row_global($parm_periode, 0, $js_var);
$a_answer['content']=ob_get_clean();
}
$parm_periode=new Parm_periode_SQL($cn, $periode_id);
ob_start();
Periode::display_row_global($parm_periode, 0, $js_var);
$a_answer['content']=ob_get_clean();
}
catch (Exception $ex)
{
$html=$ex->getTrace();
$html=$ex->getMessagei();
$a_answer['content']=$html;
}
break;
@ -239,8 +248,13 @@ switch ($act)
$p_start=$http->post("p_start", "date");
$p_end=$http->post("p_end", "date");
$p_exercice=$http->post("p_exercice", "number");
$exercice_label=$cn->get_value("select distinct p_exercice_label from parm_periode where p_exercice=$1",
[$p_exercice]);
if (empty($exercice_label)) {
$exercice_label=$p_exercice;
}
$obj=new Periode($cn);
$p_id=$obj->insert($p_start, $p_end, $p_exercice);
$p_id=$obj->insert($p_start, $p_end, $p_exercice,$exercice_label);
$parm_periode=new Parm_periode_SQL($cn, $p_id);
ob_start();
Periode::display_row_global($parm_periode, 0, $js_var);

View file

@ -34,7 +34,7 @@ class Exercice
$this->cn=$cn;
}
/**
*return the number of different exercices into a folder
*@brief return the number of different exercices into a folder
*@param $cn is the database connexion object database
*@return the count of exercice
*/
@ -44,7 +44,7 @@ class Exercice
return $count;
}
/**
*Show a ISelect with the different exercices
*@brief Show a ISelect with the different exercices
*@param $name of the iselect
*@param $selected the selected year (default = '')
*@param $js javascript (default = '')
@ -53,13 +53,13 @@ class Exercice
function select($name,$selected='',$js='')
{
$iselect=new ISelect($name);
$iselect->value=$this->cn->make_array('select distinct p_exercice,p_exercice from parm_periode order by 1 desc');
$iselect->value=$this->cn->make_array('select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc');
$iselect->selected=$selected;
$iselect->javascript=$js;
return $iselect;
}
/**
*Show a ISelect with the different exercices, display start and end date
*@brief Show a ISelect with the different exercices, display start and end date
*@param $name of the iselect
*@param $selected the selected year (default = '')
*@param $js javascript (default = '')
@ -77,4 +77,15 @@ class Exercice
$iselect->javascript=$js;
return $iselect;
}
/**
* @brief retrieve the exercice from the exercice label
* @param string $p_label
*/
function exercice_from_label($p_label)
{
$value = $this->cn->get_value("select distinct p_exercice from parm_periode where p_exercice_label=$1",
[$p_label]);
if ($value == "") return -1;
return $value;
}
}

View file

@ -223,7 +223,7 @@ class Periode
* @return int p_id of the new periode
* @exception Exception 10 Invalide date or exercice, 20 overlapping periode
*/
function insert($p_date_start, $p_date_end, $p_exercice)
function insert($p_date_start, $p_date_end, $p_exercice,$p_exercice_label)
{
try
{
@ -254,16 +254,16 @@ class Periode
throw new Exception (_("Période chevauchant une autre"),20);
}
$p_id=$this->cn->get_next_seq('s_periode');
$sql=" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice)
$sql=" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice,p_exercice_label)
values
($1,
to_date($2,'DD.MM.YYYY'),
to_date($3,'DD.MM.YYYY'),
'f',
$4)";
$4,$5)";
$this->cn->start();
$Res=$this->cn->exec_sql($sql,[$p_id, $p_date_start, $p_date_end, $p_exercice]);
$Res=$this->cn->exec_sql($sql,[$p_id, $p_date_start, $p_date_end, $p_exercice,$p_exercice_label]);
$Res=$this->cn->exec_sql("insert into jrn_periode (jrn_def_id,p_id,status) ".
"select jrn_def_id,$p_id,'OP' from jrn_def");
$this->cn->commit();
@ -286,7 +286,7 @@ class Periode
{
if ($this->p_id=='')
$this->p_id=-1;
$row=$this->cn->get_array("select p_start,p_end,p_exercice,p_closed,p_central from parm_periode where p_id=$1",
$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",
array($this->p_id));
if ($row==null)
return -1;
@ -294,6 +294,7 @@ class Periode
$this->p_start=$row[0]['p_start'];
$this->p_end=$row[0]['p_end'];
$this->p_exercice=$row[0]['p_exercice'];
$this->p_exercice_label=$row[0]['p_exercice_label'];
$this->p_closed=$row[0]['p_closed'];
$this->p_central=$row[0]['p_central'];
return 0;
@ -415,9 +416,10 @@ class Periode
* @param $p_month number of month of the exercice
* @param $p_opening 1 if we create a one-day periode for opening writings
* @param $p_closing 1 if we create a one-day periode for closing writings
* @param $p_exercice_label label of the exercice
*/
function insert_exercice($p_exercice, $p_year, $p_from_month, $p_month,
$p_opening, $p_closing)
$p_opening, $p_closing,$p_exercice_label)
{
try
{
@ -442,7 +444,9 @@ class Periode
throw new Exception(_("Mois de début n'existe pas "));
if ($p_from_month>13||$p_from_month<1)
throw new Exception(_("Mois de début n'existe pas "));
if ( empty($p_exercice_label)) {
$p_exercice_label=$p_exercice;
}
$this->cn->start();
$year=$p_year;
$month=$p_from_month;
@ -453,13 +457,13 @@ class Periode
if ($i==1&&$p_opening==1)
{
$fdate_start=sprintf('01.%02d.%d', $month, $year);
$this->insert($fdate_start, $fdate_start, $p_exercice);
$this->insert($fdate_start, $fdate_start, $p_exercice,$p_exercice_label);
$date_start=sprintf('02.%02d.%d', $month, $year);
$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($fdate_start));
$this->insert($date_start, $date_end, $p_exercice);
$this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
}
// The last month, we create a one-day periode for closing
elseif ($i==$p_month && $p_closing ==1 )
@ -467,12 +471,12 @@ class Periode
$fdate_start=sprintf('01.%02d.%d', $month, $year);
$date_end=$this->cn->get_value("select to_char(to_date($1,'DD.MM.YYYY')+interval '1 month'-interval '2 day','DD.MM.YYYY')",
array($fdate_start));
$this->insert($fdate_start, $date_end, $p_exercice);
$this->insert($fdate_start, $date_end, $p_exercice,$p_exercice_label);
$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($fdate_start));
$this->insert($date_end, $date_end, $p_exercice);
$this->insert($date_end, $date_end, $p_exercice,$p_exercice_label);
}
else
@ -480,7 +484,7 @@ class Periode
$date_start=sprintf('01.%02d.%d', $month, $year);
$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));
$this->insert($date_start, $date_end, $p_exercice);
$this->insert($date_start, $date_end, $p_exercice,$p_exercice_label);
}
$month++;
if ($month == 13 )
@ -521,6 +525,7 @@ class Periode
echo th(_("Date Début"));
echo th(_("Date Fin"));
echo th(_("Exercice"));
echo th(_("Libellé"),'class="visible_gt800"');
echo th(_("nb opérations"));
echo th(_("Status"));
echo "</tr>";
@ -584,6 +589,7 @@ class Periode
echo td(format_date($obj->getp("p_start"), "YYYY-MM-DD", "DD.MM.YYYY"));
echo td(format_date($obj->getp("p_end"), "YYYY-MM-DD", "DD.MM.YYYY"));
echo td($obj->getp("p_exercice"));
echo td($obj->getp("p_exercice_label"),'class="visible_gt800"');
$nb_operation=$periode->count_operation();
echo td($nb_operation);
$closed=$obj->getp('p_closed');
@ -634,6 +640,7 @@ class Periode
* - from_month
* - day_opening
* - day_closing
* - p_exercice_label
*/
static function form_exercice_add()
{
@ -663,8 +670,17 @@ class Periode
$day_closing->value=1;
$day_opening->value=1;
$day_closing->set_check(1);
$exercice_label=new IText("p_exercice_label");
require_once NOALYSS_TEMPLATE.'/periode_add_exercice.php';
}
/**
* @brief form to change the label of exercice
*/
static function form_exercice_label()
{
$cn=Dossier::connect();
require_once NOALYSS_TEMPLATE."/periode-form_exercice_label.php";
}
function delete() {
$this->cn->exec_sql("delete from parm_periode where p_id=$1",[$this->p_id]);
}
@ -686,9 +702,10 @@ class Periode
*/
static function form_periode_add($p_js_var)
{
$http=new \HttpInput();
$cn=Dossier::connect();
$p_exercice=new ISelect('p_exercice');
$p_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by 1 desc");
$p_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc");
$title=_('Ajout période');
$title_par="<p>"._('On ne peut ajouter une période que sur un exercice qui existe déjà').
"</p>";
@ -700,7 +717,7 @@ class Periode
$html.=HtmlInput::title_box($title, 'periode_add','hide');
$html.=$title_par;
$html.='<form method="post" id="insert_periode_frm" onsubmit="'.$p_js_var.'.insert_periode();return false;">' ;
$html.=HtmlInput::hidden("ac", $_REQUEST['ac']);
$html.=HtmlInput::hidden("ac", $http->request('ac'));
$html.=Dossier::hidden();
$html.='<table>';
@ -721,7 +738,7 @@ class Periode
{
$cn=Dossier::connect();
$i_exercice=new ISelect("p_exercice_sel");
$i_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by 1 desc", 1);
$i_exercice->value=$cn->make_array("select distinct p_exercice,p_exercice_label from parm_periode order by 1 desc", 1);
$i_exercice->javascript="onchange=\"Periode.filter_exercice('periode_tbl')\"";
$i_exercice->selected=$p_sel;
echo $i_exercice->input();

View file

@ -116,7 +116,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
if ( ! defined ("SYSINFO_DISPLAY")) {
define ("SYSINFO_DISPLAY",TRUE);
}
define ("DBVERSION",171);
define ("DBVERSION",172);
define ("MONO_DATABASE",25);
define ("DBVERSIONREPO",20);
define ('NOTFOUND','--not found--');

View file

@ -46,6 +46,7 @@ function __construct(DatabaseCore $p_cn,$p_id=-1)
,"p_start"=>"p_start"
,"p_end"=>"p_end"
,"p_exercice"=>"p_exercice"
,"p_exercice_label"=>"p_exercice_label"
,"p_closed"=>"p_closed"
,"p_central"=>"p_central"
);
@ -57,6 +58,7 @@ function __construct(DatabaseCore $p_cn,$p_id=-1)
,"p_start"=>"date"
,"p_end"=>"date"
,"p_exercice"=>"text"
,"p_exercice_label"=>"text"
,"p_closed"=>"boolean"
,"p_central"=>"boolean"
);

View file

@ -39,7 +39,7 @@ $cn=Dossier::connect();
if ( isset ( $_REQUEST['poste_fille']) )
{ //choisit de voir tous les postes
$a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like $1||'%'",array($r_poste));
$a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like $1||'%' order by pcm_val::text",array($r_poste));
}
else
{

View file

@ -31,16 +31,16 @@ $poste_id=$http->request("poste_id");
$from_periode=$http->request("from_periode");
$to_periode=$http->request("to_periode");
$ople=$http->request("ople");
$poste_fille=$http->request("poste_fille","string",0);
$poste_fille=$http->request("poste_fille","string",-1);
$gDossier=dossier::id();
/* Security */
$cn=Dossier::connect();
if ( $poste_fille == 'on' )
if ( $poste_fille <> -1)
{ //choisit de voir tous les postes
$a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like $1||'%' order by pcm_val",array($poste_id));
$a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like $1||'%' order by pcm_val::text",array($poste_id));
}
else
{

View file

@ -40,6 +40,52 @@ $p_ledger_id=$http->request("jrn_def_id", "number", 0);
</script>
<?php
//-------------------------------------------------------------------
//Modify exercice label
//-------------------------------------------------------------------
if ( isset($_POST['mod_exercice_label_bt'])) {
$err = 0;
$p_exercice_label=$http->post("p_exercice_label");
$p_exercice=$http->post("p_exercice");
if (empty(trim($p_exercice_label))) {
echo_warning(_("Libellé exercice ne peut pas être vide"));
$err =1;
}
if ($err == 0 && $cn->get_value("select count(*) from parm_periode where p_exercice_label=$1 and p_exercice <>$2",
[$p_exercice_label,$p_exercice]) > 0)
{
echo_warning(_("Le même libellé ne peut pas être utilisé pour 2 exercices"));
$err=1;
}
if ($err == 0) {
try
{
$cn->start();
/**
* @todo
* Rewrite : split table parm_periode into parm_periode and parm_exercice
* disabling temporarily a trigger is not the right solution ,
* but make the trigger more flexible and less secure
* is worst. The trigger is disable in a transaction means it is still enable
* for other session.
*/
$cn->exec_sql("alter table parm_periode disable trigger parm_periode_check_periode_trg");
$cn->exec_sql("update parm_periode set p_exercice_label=$1 where p_exercice=$2",
[$p_exercice_label,$p_exercice]);
$cn->exec_sql("alter table parm_periode enable trigger parm_periode_check_periode_trg");
$cn->commit();
}
catch (Exception $exc)
{
echo_warning( $exc->getMessage());
error_log($exc->getTraceAsString());
$cn->rollback();
}
}
}
//--------------------------------------------------------------------
// Add an exercice
// receive nb_exercice
@ -50,6 +96,7 @@ if (isset($_POST['add_exercice']))
try
{
$p_exercice=$http->post("p_exercice", "number");
$p_exercice_label=$http->post("p_exercice_label", "string");
$p_year=$http->post("p_year", "number");
$nb_month=$http->post("nb_month", "number");
$from_month=$http->post("from_month", "number");
@ -57,7 +104,7 @@ if (isset($_POST['add_exercice']))
$day_closing=$http->post("day_closing", "string", 0);
$exercice=new Periode($cn);
$exercice->insert_exercice($p_exercice, $p_year, $from_month, $nb_month,
$day_opening, $day_closing);
$day_opening, $day_closing,$p_exercice_label);
}
catch (Exception $ex)
{
@ -111,6 +158,13 @@ if ($p_ledger_id==0)
echo '<div id="periode_add" style="display:none;width:auto" class="inner_box">';
Periode::form_periode_add("jsper");
echo '</div>';
//-------------------------------------------------------------------
// Change label of Exercice
//-------------------------------------------------------------------
echo HtmlInput::button_action(_("Modifie libellé exercice"), "\$('exercice_label_div').show()");
echo '<div id="exercice_label_div" style="display:none;width:60ch" class="inner_box">';
Periode::form_exercice_label("jsper");
echo '</div>';
//-------------------------------------------------------------------
// List of Periode

View file

@ -1,6 +1,12 @@
<?php
/**
* @file
* @brief Form to add new exercice
*/
//This file is part of NOALYSS and is under GPL
//see licence.txt
$http=new HttpInput();
?>
<?php echo HtmlInput::title_box(_("Ajout d'un exercice"), "exercice_add",
"hide"); ?>
@ -14,7 +20,7 @@ de fin d'exercice: amortissements, régulations de compte... Avec une 13ième p
<form method="post" style="padding-left: 20%" id="exercice_frm" onsubmit="return (validate() && confirm_box($('exercice_frm'), '<?php echo _("Confirmez vous l\'ajout d\'un exercice comptable ?") ?>'))">
<?php
echo HtmlInput::hidden("ac", $_REQUEST['ac']);
echo HtmlInput::hidden("ac", $http->request('ac'));
echo HtmlInput::hidden("jrn_def_id", "0");
echo HtmlInput::hidden("add_exercice", "1");
echo Dossier::hidden();
@ -22,7 +28,16 @@ de fin d'exercice: amortissements, régulations de compte... Avec une 13ième p
<table>
<tr>
<td>
<?= _("Exercice") ?>
<?=_("Nom de l'exercice")?>
</td>
<td>
<?=$exercice_label->input()?>
</td>
</tr>
<tr>
<td>
<?= _("Exercice fiscal ou comptable") ?>
</td>
<td>
<?php echo $exercice->input() ?>

View file

@ -333,8 +333,8 @@ class FicheTest extends TestCase
array('ÀÉ@Ê', 'AE@E'),
array('ça&"', 'CA'),
array("", "QC"),
array(",,,,", "QC"),
array("####", "QC")
array(",,,,", "QC0"),
array("####", "QC0")
);
}
@ -408,9 +408,14 @@ where
$this->assertEquals($fiche->get_quick_code(),$fiche_related1->strAttribut($nAttribute['ad_id']),'Attribute QC is not set');
$this->assertEquals($fiche->get_quick_code(),$fiche_related2->strAttribut($nAttribute['ad_id']),'Attribute QC is not set');
}
$fiche->remove();
$fiche_related1->remove();
$fiche_related2->remove();
if ( $fiche->id == 872 ) {
$this->assertEquals($fiche->remove(),1,"Removed used card not allowed {$fiche->id}");
} else {
$this->assertEquals($fiche->remove(),0,"Cannot remove {$fiche->id}");
}
$this->assertEquals($fiche_related1->remove(),0,"Cannot remove {$fiche_related1->id}");
$this->assertEquals($fiche_related2->remove(),0,"Cannot remove {$fiche_related2->id}");
foreach ($aAttribute as $nAttribute) {
$fiche_def->removeAttribut($nAttribute['ad_id']);
}