From 8ea668ed8629213e8af26b8a06c926a0d56dbff0 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 10 Jun 2021 17:26:07 +0200 Subject: [PATCH] Bug simple report : FROM 00.0000 was computed from user preference instead of end period. Improve ergonomy Signed-off-by: sparkyx --- include/impress_rapport.inc.php | 24 +++++++----- include/lib/impress.class.php | 38 +++++++++---------- unit-test/include/class/impressTest.class.php | 11 +++++- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/include/impress_rapport.inc.php b/include/impress_rapport.inc.php index 6ed2dc8b2..30c55e52e 100644 --- a/include/impress_rapport.inc.php +++ b/include/impress_rapport.inc.php @@ -84,7 +84,7 @@ if ( isset( $_GET['bt_html'] ) ) } catch (Exception $ex) { - alert($ex->getMessage());; + alert($ex->getMessage()); } @@ -101,7 +101,7 @@ if ( isset( $_GET['bt_html'] ) ) { $t=($from_periode==$to_periode)?"":" -> ".getPeriodeName($cn,$to_periode,'p_end'); - echo '

'.$form_id + echo '

'.$form_id ." ".$form_label ." - ".getPeriodeName($cn,$from_periode,'p_start') ." ".$t @@ -109,7 +109,7 @@ if ( isset( $_GET['bt_html'] ) ) } else { - echo '

'.$form_id." ".$form_label. + echo '

'.$form_id." ".$form_label. ' Date :'. $from_date. " au ". @@ -124,8 +124,10 @@ if ( isset( $_GET['bt_html'] ) ) printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id); echo dossier::hidden(). - HtmlInput::submit('bt_other',"Autre Rapport"). - $hid->input("type","rapport").$hid->input("ac",$access_code).""; + $hid->input("form_id",$form_id). + HtmlInput::submit('bt_other',"Autre Rapport"). + $hid->input("type","rapport"). + $hid->input("ac",$access_code).""; echo '
%s

',$periode_name[$a]); + printf( '

%s

',$periode_name[$a]); $a++; ShowReportResult($e); } @@ -227,22 +229,24 @@ printf( ' onsubmit="waiting_box()">'); echo 'Choisissez un autre exercice :'; $ex=new Exercice($cn); -$wex=$ex->select('exercice',$exercice,' onchange="submit(this)"'); +$wex=$ex->select('exercice',$exercice, + sprintf(' onchange="updatePeriode(\'%s\',\'exercice\',\'from_periode\',\'to_periode\',1)"',Dossier::id(),$exercice)); echo $wex->input(); echo dossier::hidden(); echo HtmlInput::get_to_hidden(array('ac','type')); -echo ''; + echo ''; echo '
'; $hidden=new IHidden(); -echo $hidden->input("ac",$_GET['ac']); +echo $hidden->input("ac",$access_code); echo $hidden->input("type","rapport"); echo dossier::hidden(); echo ''; $w=new ISelect(); +$w->selected=$http->request("form_id","string",0); $w->table=1; print td(_("Choisissez le rapport")); print $w->input("form_id",$ret); @@ -282,7 +286,7 @@ $date_to=new IDate('to_date'); $date_to->id='to_date'; echo td(_("Calendrier depuis :")); -echo td($date_from->input('from_date')); +echo td($date_from->input('to_date')); echo td(_("jusque")); echo td($date_to->input('to_date')); echo ''; diff --git a/include/lib/impress.class.php b/include/lib/impress.class.php index ea12d7218..0969a42a4 100644 --- a/include/lib/impress.class.php +++ b/include/lib/impress.class.php @@ -314,27 +314,27 @@ class Impress */ static public function compute_periode($p_cn, $p_from,$p_end) { - global $g_user; // There is a FROM clause // then we must modify the cond for the periode // Get the periode - /* ! \note special value for the clause FROM=00.0000 + /* ! \note special value for the clause FROM=00.0000, we take the first day of the exercice of $p_end */ if ($p_from=='00.0000') { - + $current_exercice=$p_cn->get_value('select p_exercice from parm_periode where p_id=$1', + [$p_end]); + if ( $current_exercice=="") { + throw new Execution(_('CP329')); + } + $first_day=$p_cn->get_value("select to_char(min(p_start),'DD.MM.YYYY') as p_start from parm_periode where p_exercice=$1", + [$current_exercice]); + $last_day=$p_cn->get_value("select to_char(p_end,'DD.MM.YYYY') from parm_periode where p_id=$1",[$p_end]); // retrieve the first month of this periode - $user_periode=$g_user->get_periode(); - $oPeriode=new Periode($p_cn); - $periode=$oPeriode->get_exercice($user_periode); - list($first, $last)=$oPeriode->get_limit($periode); - $ret=$first->get_date_limit(); - $end_date=$oPeriode->get_date_limit($p_end); - if ($ret==null) + if (empty($first_day)) throw new Exception('Pas de limite à cette période', 1); - $cond=sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per'); + $cond=sql_filter_per($p_cn, $first_day, $last_day, 'date', 'j_tech_per'); } else { @@ -349,17 +349,13 @@ class Impress /* if none periode is found then we take the first periode of the year */ - $user_periode=$g_user->get_periode(); - - $year=$oPeriode->get_exercice($user_periode); - list($first, $last)=$oPeriode->get_limit($year); - $ret=$first->get_date_limit(); - $end_date=$oPeriode->get_date_limit($p_end); - if ($ret==null) - { + + $first_day=$p_cn->get_value("select to_char(min(p_start),'DD.MM.YYYY') as p_start from parm_periode"); + $last_day=$p_cn->get_value("select to_char(p_end,'DD.MM.YYYY') from parm_periode where p_id=$1",[$p_end]); + // retrieve the first month of this periode + if (empty($first_day)) throw new Exception('Pas de limite à cette période', 1); - } - $cond=sql_filter_per($p_cn, $ret['p_start'], $end_date['p_end'], 'date', 'j_tech_per'); + $cond=sql_filter_per($p_cn, $first_day, $last_day, 'date', 'j_tech_per'); } } return $cond; diff --git a/unit-test/include/class/impressTest.class.php b/unit-test/include/class/impressTest.class.php index 1c6604514..c2293503e 100644 --- a/unit-test/include/class/impressTest.class.php +++ b/unit-test/include/class/impressTest.class.php @@ -180,15 +180,22 @@ class ImpressTest extends TestCase function test_computePeriode() { global $g_connection,$g_parameter,$g_user; - $g_user->set_periode(110); + $g_user->set_periode(98); $this->assertEquals(trim("j_tech_per in (select p_id from parm_periode where p_start >= to_date('01.01.2017','DD.MM.YYYY') and p_end <= to_date('30.11.2017','DD.MM.YYYY'))"),trim(\Impress::compute_periode($g_connection, "00.0000",115)) ," SQL from 01.01.2017 to 01.11.2017"); + $this->assertEquals(trim("j_tech_per in (select p_id from parm_periode where p_start >= to_date('01.01.2020','DD.MM.YYYY') and p_end <= to_date('30.09.2020','DD.MM.YYYY'))"),trim(\Impress::compute_periode($g_connection, "00.0000",140)) + ," SQL from 01.01.2020 to 01.11.2020"); + $this->assertEquals(trim("j_tech_per in (select p_id from parm_periode where p_start >= to_date('01.01.2019','DD.MM.YYYY') and p_end <= to_date('30.09.2019','DD.MM.YYYY'))"),trim(\Impress::compute_periode($g_connection, "00.0000",127)) + ," SQL from 01.01.2019 to 30.09.2019"); $this->assertEquals( trim("j_tech_per in (select p_id from parm_periode where p_start >= to_date('01.02.2017','DD.MM.YYYY') and p_end <= to_date('31.10.2017','DD.MM.YYYY'))"), trim(\Impress::compute_periode($g_connection, "02.2017",114)), " SQL from 01.02.2017 to 01.10.2017"); - + $this->assertEquals( + trim("j_tech_per in (select p_id from parm_periode where p_start >= to_date('01.01.2017','DD.MM.YYYY') and p_end <= to_date('31.10.2017','DD.MM.YYYY'))"), + trim(\Impress::compute_periode($g_connection, "02.2000",114)), + " From periode doesn't exist, we start from the first period found SQL from 01.02.2017 to 01.10.2017"); } /** * @covers Impress::parse_formula