Acc_Ledger_Search , fix small bug + Test file
This commit is contained in:
parent
9f54258d8f
commit
5715a582f8
4 changed files with 156 additions and 14 deletions
|
|
@ -19,8 +19,7 @@
|
|||
*/
|
||||
// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
|
||||
|
||||
if (!defined('ALLOWED'))
|
||||
die('Appel direct ne sont pas permis');
|
||||
// if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
|
||||
|
||||
/**
|
||||
* @file
|
||||
|
|
@ -36,8 +35,8 @@ class Acc_Ledger_Search
|
|||
|
||||
/**
|
||||
* @brief return a HTML string with the form for the search
|
||||
* @param $p_type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN
|
||||
* @param $all_type_ledger
|
||||
* @param $p_type if the type of ledger possible values=ALL,VEN,ACH,ODS,FIN: uppercase !
|
||||
* @param $all_type_ledger
|
||||
* values :
|
||||
* - 1 means all the ledger of this type
|
||||
* - 0 No have the "Tous les journaux" availables
|
||||
|
|
@ -50,7 +49,7 @@ class Acc_Ledger_Search
|
|||
function __construct($p_type, $p_all=1, $p_div="")
|
||||
{
|
||||
$this->cn=Dossier::connect();
|
||||
$this->type=$p_type;
|
||||
$this->set_type($p_type);
|
||||
$this->all=$p_all;
|
||||
$this->div=$p_div;
|
||||
}
|
||||
|
|
@ -72,6 +71,10 @@ class Acc_Ledger_Search
|
|||
|
||||
public function set_type($type)
|
||||
{
|
||||
if (! in_array($type, ["ALL","VEN","ACH","ODS","FIN"]))
|
||||
{
|
||||
throw new Exception ("ALS02 : type invalide $type",EXC_PARAM_VALUE);
|
||||
}
|
||||
$this->type=$type;
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +268,7 @@ class Acc_Ledger_Search
|
|||
* @brief this function will create a sql stmt to use to create the list for
|
||||
* the ledger,
|
||||
* @param $p_array is usually the $_GET,
|
||||
* @param $p_order the order of the row
|
||||
* @param $p_order the order of the row --> not used
|
||||
* @param $p_where is the sql condition if not null then the $p_array will not be used
|
||||
* \note the p_action will be used to filter the ledger but gl means ALL
|
||||
* struct array $p_array
|
||||
|
|
@ -407,7 +410,7 @@ class Acc_Ledger_Search
|
|||
|
||||
$and='';
|
||||
$g_user=new User($this->cn);
|
||||
$p_action=$ledger_type;
|
||||
$p_action=(isset ($ledger_type)) ? $ledger_type:$this->type;
|
||||
if ($p_action=='')
|
||||
$p_action='ALL';
|
||||
if ($r_jrn==-1)
|
||||
|
|
@ -571,6 +574,8 @@ class Acc_Ledger_Search
|
|||
$where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.
|
||||
$fil_qcode.$fil_paid.$fil_account.$fil_date_paid.$fil_hide_operation;
|
||||
$sql.=" where ".$where;
|
||||
|
||||
// Q?? Why do we return where if it is included in SQL ?
|
||||
return array($sql, $where);
|
||||
}
|
||||
|
||||
|
|
@ -583,6 +588,7 @@ class Acc_Ledger_Search
|
|||
*/
|
||||
function display_search_form()
|
||||
{
|
||||
$http=new HttpInput();
|
||||
$r='';
|
||||
$r.='<div id="search_form" style="display:none">';
|
||||
$r.=HtmlInput::title_box(_('Recherche'), "search_form", "hide", "", "n");
|
||||
|
|
@ -597,18 +603,18 @@ class Acc_Ledger_Search
|
|||
|
||||
|
||||
|
||||
$r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
|
||||
$r.=HtmlInput::hidden('ac', $http->request('ac'));
|
||||
|
||||
|
||||
/* when called from commercial.php some hidden values are needed */
|
||||
if (isset($_REQUEST['sa']))
|
||||
$r.=HtmlInput::hidden("sa", $_REQUEST['sa']);
|
||||
$r.=HtmlInput::hidden("sa", $http->request('sa'));
|
||||
if (isset($_REQUEST['sb']))
|
||||
$r.=HtmlInput::hidden("sb", $_REQUEST['sb']);
|
||||
$r.=HtmlInput::hidden("sb", $http->request('sb'));
|
||||
if (isset($_REQUEST['sc']))
|
||||
$r.=HtmlInput::hidden("sc", $_REQUEST['sc']);
|
||||
$r.=HtmlInput::hidden("sc", $http->request('sc'));
|
||||
if (isset($_REQUEST['f_id']))
|
||||
$r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
|
||||
$r.=HtmlInput::hidden("f_id", $http->request('f_id'));
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
|
|||
require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
|
||||
require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
|
||||
|
||||
$ledger=new Acc_Ledger_Search($cn,0);
|
||||
$http=new HttpInput();
|
||||
|
||||
$ledger=new Acc_Ledger_Search($http->get("ledger_type"),0);
|
||||
|
||||
list($sql,$where)=$ledger->build_search_sql($_GET);
|
||||
|
||||
$order=" order by jr_date_order asc,substring(jr_pj_number,'[0-9]+$')::numeric asc ";
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ echo $f_accounting->input(); ?>
|
|||
|
||||
<tr>
|
||||
<td style="text-align:right;width:30em">
|
||||
<?php echo _('Statut')?>
|
||||
<?php echo _('Etat')?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
|
|
|||
133
unit-test/include/class/acc_ledger_search.Test.php
Normal file
133
unit-test/include/class/acc_ledger_search.Test.php
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
* PhpCompta is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PhpCompta is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PhpCompta; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// Copyright (2002-2019) Author Dany De Bontridder <danydb@noalyss.eu>
|
||||
if ( ! defined("ALLOWED")) {
|
||||
define('ALLOWED',1);
|
||||
}
|
||||
/**
|
||||
* @file
|
||||
* @brief concern acc_ledger_search
|
||||
* @coversDefaultClass acc_ledger_search
|
||||
*/
|
||||
class Acc_Ledger_Test extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
include 'global.php';
|
||||
global $g_user;
|
||||
$g_user->set_periode(119);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::build_search_sql
|
||||
*/
|
||||
function test_all_ledger()
|
||||
{
|
||||
global $g_connection;
|
||||
// all legder
|
||||
$ledger=new Acc_Ledger_Search('ALL');
|
||||
$result=$ledger->build_search_sql(NULL);
|
||||
$a_result=$g_connection->get_array($result[0]);
|
||||
$this->assertEquals(4,count($a_result));
|
||||
$this->assertEquals(" jrn_def_id in (3,83,1,35,4,2,36,-1) and jr_date >= to_date('02.01.2019','DD.MM.YYYY')".
|
||||
" and jr_date <= to_date('31.01.2019','DD.MM.YYYY')",$result[1]);
|
||||
|
||||
// Expect exception
|
||||
try {
|
||||
$ledger=new Acc_Ledger_Search('ALL1');
|
||||
$this->assertTrue(FALSE,"Exception not thrown with invalide type");
|
||||
} catch (Exception $e) {
|
||||
$this->assertEquals($e->getCode(),1005,"Exception is type invalide");
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @covers ::display_search_form
|
||||
*/
|
||||
function test_display_search_form()
|
||||
{
|
||||
put_global(array(["key"=>"ac","value"=>"phpunit"]));
|
||||
$ledger=new Acc_Ledger_Search('ALL');
|
||||
$r=$ledger->display_search_form();
|
||||
$this->assertEquals(9068,strlen($r),"Size of the html string for display_search_form");
|
||||
}
|
||||
/**
|
||||
* @covers ::build_search_filter
|
||||
*/
|
||||
function test_build_search_filter()
|
||||
{
|
||||
$ledger=new Acc_Ledger_Search('ALL');
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ALL','all_type':1,'dossier':%d})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for ALL");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('FIN');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'FIN','all_type':1,'dossier':%d})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for FIN");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('VEN');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'VEN','all_type':1,'dossier':%d})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for VEN");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('ACH');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ACH','all_type':1,'dossier':%d})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for ACH");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('ODS');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ODS','all_type':1,'dossier':%d})"
|
||||
,Dossier::id());
|
||||
|
||||
$this->assertEquals($ret,$result,"Build filter for ODS");
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue