Merge pull request #10152 from defrance/patch-134

refactoring list.php with dol_sql_datefilter
This commit is contained in:
Laurent Destailleur 2018-12-14 19:06:29 +01:00 committed by GitHub
commit 38ddfd9a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 149 deletions

View File

@ -329,45 +329,20 @@ if ($viewstatut != '' && $viewstatut != '-1')
{
$sql.= ' AND p.fk_statut IN ('.$db->escape($viewstatut).')';
}
if ($search_month > 0)
{
if ($search_year > 0 && empty($search_day))
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
else if ($search_year > 0 && ! empty($search_day))
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
else
$sql.= " AND date_format(p.datep, '%m') = '".$db->escape($search_month)."'";
}
else if ($search_year > 0)
{
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
}
if ($search_month_end > 0)
{
if ($search_yearfin > 0 && empty($search_dayfin))
$sql.= " AND p.fin_validite BETWEEN '".$db->idate(dol_get_first_day($search_yearfin,$search_month_end,false))."' AND '".$db->idate(dol_get_last_day($search_yearfin,$search_month_end,false))."'";
else if ($search_yearfin > 0 && ! empty($search_dayfin))
$sql.= " AND p.fin_validite BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month_end, $search_dayfin, $search_yearfin))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month_end, $search_dayfin, $search_yearfin))."'";
else
$sql.= " AND date_format(p.fin_validite, '%m') = '".$db->escape($search_month_end)."'";
}
else if ($search_yearfin > 0)
{
$sql.= " AND p.fin_validite BETWEEN '".$db->idate(dol_get_first_day($search_yearfin,1,false))."' AND '".$db->idate(dol_get_last_day($search_yearfin,12,false))."'";
}
if ($search_monthdelivery > 0)
{
if ($search_yeardelivery > 0 && empty($search_daydelivery))
$sql.= " AND p.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_yeardelivery,$search_monthdelivery,false))."' AND '".$db->idate(dol_get_last_day($search_yeardelivery,$search_monthdelivery,false))."'";
else if ($search_yeardelivery > 0 && ! empty($search_daydelivery))
$sql.= " AND p.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_monthdelivery, $search_daydelivery, $search_yeardelivery))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_monthdelivery, $search_daydelivery, $search_yeardelivery))."'";
else
$sql.= " AND date_format(p.date_livraison, '%m') = '".$db->escape($search_monthdelivery)."'";
}
else if ($search_yeardelivery > 0)
{
$sql.= " AND p.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_yeardelivery,1,false))."' AND '".$db->idate(dol_get_last_day($search_yeardelivery,12,false))."'";
}
$sql.= dol_sql_datefilter(
"p.datep",
$search_day, $search_month, $search_year
);
$sql.= dol_sql_datefilter(
"p.fin_validite",
$search_dayfin, $search_month_end, $search_yearfin
);
$sql.= dol_sql_datefilter(
"p.date_livraison",
$search_daydelivery, $search_monthdelivery, $search_yeardelivery
);
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$db->escape($search_sale);
if ($search_user > 0)
{

View File

@ -10,6 +10,8 @@
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
*
* 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
@ -301,32 +303,17 @@ if ($viewstatut <> '')
$sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed
}
}
if ($search_ordermonth > 0)
{
if ($search_orderyear > 0 && empty($search_orderday))
$sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,$search_ordermonth,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,$search_ordermonth,false))."'";
else if ($search_orderyear > 0 && ! empty($search_orderday))
$sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_ordermonth, $search_orderday, $search_orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_ordermonth, $search_orderday, $search_orderyear))."'";
else
$sql.= " AND date_format(c.date_commande, '%m') = '".$search_ordermonth."'";
}
else if ($search_orderyear > 0)
{
$sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,12,false))."'";
}
if ($search_deliverymonth > 0)
{
if ($search_deliveryyear > 0 && empty($search_deliveryday))
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,$search_deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,$search_deliverymonth,false))."'";
else if ($search_deliveryyear > 0 && ! empty($search_deliveryday))
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."'";
else
$sql.= " AND date_format(c.date_livraison, '%m') = '".$search_deliverymonth."'";
}
else if ($search_deliveryyear > 0)
{
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,12,false))."'";
}
$sql.= dol_sql_datefilter(
"c.date_commande",
$search_orderday, $search_ordermonth, $search_orderyear
);
$sql.= dol_sql_datefilter(
"c.date_livraison",
$search_deliveryday, $search_deliverymonth, $search_deliveryyear
);
if ($search_town) $sql.= natural_search('s.town', $search_town);
if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
if ($search_state) $sql.= natural_search("state.nom",$search_state);

View File

@ -4,6 +4,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018 charlene Benke <charlie@patas-monkey.com>
*
* 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
@ -55,6 +56,7 @@ if (! $sortfield) $sortfield="d.dated";
$year=GETPOST("year");
$month=GETPOST("month");
$day=GETPOST("day");
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers
{
@ -64,6 +66,7 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','a
// $search_amount="";
$year="";
$month="";
$day="";
}
/*
@ -103,19 +106,10 @@ if ($search_company)
$sql .= natural_search('s.nom', $search_company);
}
// if ($search_amount) $sql.=" AND d.km='".$db->escape(price2num(trim($search_amount)))."'";
if ($month > 0)
{
if ($year > 0 && empty($day))
$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 if ($year > 0 && ! empty($day))
$sql.= " AND d.dated BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
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))."'";
}
$sql.= dol_sql_datefilter(
"d.dated", $day, $month, $year
);
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($limit + 1, $offset);

View File

@ -12,6 +12,7 @@
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
*
* 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
@ -88,7 +89,7 @@ $search_country=GETPOST("search_country",'int');
$search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
$search_user = GETPOST('search_user','int');
$search_sale = GETPOST('search_sale','int');
$search_day = GETPOST('search_day','int');
$search_day = GETPOST('search_day','int');
$search_month = GETPOST('search_month','int');
$search_year = GETPOST('search_year','int');
$search_day_lim = GETPOST('search_day_lim','int');
@ -450,32 +451,16 @@ if ($search_status != '-1' && $search_status != '')
}
}
if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$db->escape($search_paymentmode);
if ($search_month > 0)
{
if ($search_year > 0 && empty($search_day))
$sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'";
else if ($search_year > 0 && ! empty($search_day))
$sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'";
else
$sql.= " AND date_format(f.datef, '%m') = '".$search_month."'";
}
else if ($search_year > 0)
{
$sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'";
}
if ($search_month_lim > 0)
{
if ($search_year_lim > 0 && empty($search_day_lim))
$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($search_year_lim,$search_month_lim,false))."' AND '".$db->idate(dol_get_last_day($search_year_lim,$search_month_lim,false))."'";
else if ($search_year_lim > 0 && ! empty($search_day_lim))
$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month_lim, $search_day_lim, $search_year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month_lim, $search_day_lim, $search_year_lim))."'";
else
$sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$db->escape($search_month_lim)."'";
}
else if ($search_year_lim > 0)
{
$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($search_year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($search_year_lim,12,false))."'";
}
$sql.= dol_sql_datefilter(
"f.datef",
$search_day, $search_month, $search_year
);
$sql.= dol_sql_datefilter(
"f.date_lim_reglement",
$search_day_lim, $search_month_lim, $search_year_lim
);
if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
if ($search_user > 0)

View File

@ -7,6 +7,7 @@
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
*
* 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
@ -163,19 +164,8 @@ else
else $sql.= " AND f.fk_user_author = ".$userid;
}
// Search criteria
if ($month > 0)
{
if ($year > 0 && empty($day))
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
else if ($year > 0 && ! empty($day))
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
else
$sql.= " AND date_format(p.datep, '%m') = '".$month."'";
}
else if ($year > 0)
{
$sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
}
$sql.= dol_sql_datefilter("p.datep", $day, $month, $year);
if ($search_ref) $sql .= natural_search('p.ref', $search_ref);
if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'";

View File

@ -3,8 +3,9 @@
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
*
* 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
@ -76,6 +77,8 @@ $search_amount_ttc = GETPOST('search_amount_ttc','alpha');
$search_status = (GETPOST('search_status','intcomma')!=''?GETPOST('search_status','intcomma'):GETPOST('statut','intcomma'));
$month_start = GETPOST("month_start","int");
$year_start = GETPOST("year_start","int");
$day_start = GETPOST("day_start","int");
$day_end = GETPOST("day_end","int");
$month_end = GETPOST("month_end","int");
$year_end = GETPOST("year_end","int");
$optioncss = GETPOST('optioncss','alpha');
@ -158,8 +161,10 @@ if (empty($reshook))
$search_status="";
$month_start="";
$year_start="";
$day ="";
$month_end="";
$year_end="";
$day_end = "";
$toselect='';
$search_array_options=array();
}
@ -271,34 +276,17 @@ if (!empty($sall)) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
// Ref
if (!empty($search_ref)) $sql.= natural_search('d.ref', $search_ref);
// Date Start
if ($month_start > 0)
{
if ($year_start > 0 && empty($day))
$sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,false))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,false))."'";
else if ($year_start > 0 && ! empty($day))
$sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_start, $day, $year_start))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_start, $day, $year_start))."'";
else
$sql.= " AND date_format(d.date_debut, '%m') = '".$month_start."'";
}
else if ($year_start > 0)
{
$sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,false))."' AND '".$db->idate(dol_get_last_day($year_start,12,false))."'";
}
// Date Start
if ($month_end > 0)
{
if ($year_end > 0 && empty($day))
$sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,false))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,false))."'";
else if ($year_end > 0 && ! empty($day))
$sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_end, $day, $year_end))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_end, $day, $year_end))."'";
else
$sql.= " AND date_format(d.date_fin, '%m') = '".$month_end."'";
}
else if ($year_end > 0)
{
$sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'";
}
// Amount
$sql.= dol_sql_datefilter(
"d.date_debut",
$day_start, $month_start, $year_start
);
// Date End
$sql.= dol_sql_datefilter(
"d.date_fin",
$day_end, $month_end, $year_end
);
if ($search_amount_ht != '') $sql.= natural_search('d.total_ht', $search_amount_ht, 1);
if ($search_amount_ttc != '') $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1);
// User
@ -539,6 +527,9 @@ if ($resql)
if (! empty($arrayfields['d.date_debut']['checked']))
{
print '<td class="liste_titre" align="center">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY))
print '<input class="flat width25" type="text" maxlength="2" name="day_start" value="'.dol_escape_htmltag($day_start).'">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
$formother->select_year($year_start,'year_start',1, $min_year, $max_year);
print '</td>';
@ -547,7 +538,9 @@ if ($resql)
if (! empty($arrayfields['d.date_fin']['checked']))
{
print '<td class="liste_titre" align="center">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY))
print '<input class="flat width25" type="text" maxlength="2" name="day_end" value="'.dol_escape_htmltag($day_end).'">';
print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
print '</td>';
}