Skip to content

Commit

Permalink
NEW : add date value filter on account records list
Browse files Browse the repository at this point in the history
  • Loading branch information
FHenry committed May 18, 2015
1 parent 756de27 commit ca53d3b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion htdocs/compta/bank/account.php
Expand Up @@ -7,6 +7,7 @@
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es>
* Copyright (C) 2012-2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2011-2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -67,6 +68,8 @@
$req_desc=GETPOST("req_desc",'',3);
$req_debit=GETPOST("req_debit",'',3);
$req_credit=GETPOST("req_credit",'',3);
$req_month = GETPOST('req_month', 'aplha');
$req_year = GETPOST('req_year', 'int');

$vline=GETPOST("vline");
$page=GETPOST('page','int');
Expand All @@ -87,6 +90,8 @@
$req_desc="";
$req_debit="";
$req_credit="";
$req_month="";
$req_year="";
}

/*
Expand Down Expand Up @@ -253,6 +258,18 @@
$param.='&amp;paiementtype='.urlencode($paiementtype);
$mode_search = 1;
}
if ($req_month)
{
$sql_rech.=" AND MONTH(b.datev) IN (".$db->escape($req_month).")";
$param.='&amp;req_month='.urlencode($req_month);
$mode_search = 1;
}
if ($req_year)
{
$sql_rech.=" AND YEAR(b.datev) = '".$db->escape($req_year)."'";
$param.='&amp;req_year='.urlencode($req_year);
$mode_search = 1;
}

$sql = "SELECT count(*) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
Expand Down Expand Up @@ -398,6 +415,8 @@
print '<input type="hidden" name="thirdparty" value="'.$thirdparty.'">';
print '<input type="hidden" name="nbpage" value="'.$totalPages.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="req_year" value="'.$req_year.'">';
print '<input type="hidden" name="req_month" value="'.$req_month.'">';

$navig ='<div data-role="fieldcontain">';
if ($limitsql > $viewline) $navig.='<a href="account.php?'.$param.'&amp;page='.($page+1).'">'.img_previous().'</a>';
Expand Down Expand Up @@ -489,9 +508,12 @@
print '<input type="hidden" name="action" value="search">';
print '<input type="hidden" name="id" value="'.$object->id.'">';

$period_filter .= $langs->trans('Month') . ':<input class="flat" type="text" size="4" name="req_month" value="' . $req_month . '">';
$period_filter .= $langs->trans('Year') . ':' . $formother->selectyear($req_year ? $req_year : - 1, 'req_year', 1, 20, 5);

print '<tr class="liste_titre">';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>'.$period_filter.'</td>';
print '<td>';
//$filtertype=array('TIP'=>'TIP','PRE'=>'PRE',...)
$filtertype='';
Expand Down

2 comments on commit ca53d3b

@eldy
Copy link

@eldy eldy commented on ca53d3b May 18, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace test on date using sql function MONTH and YEAR with something like this

if ($month > 0)
{
if ($year > 0)
$sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
else
$sql.= " AND date_format(d.dated, '%m') = '".$month."'";
}
else if ($year > 0)
{
$sql.= " AND d.dated BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
}

We must not use SQL date function (this creates bugs like timezone errors and is not portable). All dates search functions must be used by formatting on PHP side.

@FHenry
Copy link
Owner Author

@FHenry FHenry commented on ca53d3b May 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change input by real date input.
The way I use to do was more "user friendly" because they can input in month 1,3,4 or/and a year. YEAR and MONTH are ported into pgsql function.
Anyway with two date input it's better because always compatible whatever database engine and more Dolibarr UX respectfull

Please sign in to comment.