diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index e6cd028b036..30861f5c985 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -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) { diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 428c4745e8a..4b9b769855c 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -10,6 +10,8 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2018 Charlene Benke + * * 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); diff --git a/htdocs/compta/deplacement/list.php b/htdocs/compta/deplacement/list.php index 3dfbac0e726..b04fd1388b6 100644 --- a/htdocs/compta/deplacement/list.php +++ b/htdocs/compta/deplacement/list.php @@ -4,6 +4,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2018 charlene Benke * * 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); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index d9ed88fa4f6..8b8b018e6ee 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -12,6 +12,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015-2016 Ferran Marcet * Copyright (C) 2017 Josep Lluís Amador + * Copyright (C) 2018 Charlene Benke * * 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) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index 260e0802aff..bcf99538498 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -7,6 +7,7 @@ * Copyright (C) 2015 Juanjo Menent * Copyright (C) 2017 Alexandre Spangaro * Copyright (C) 2018 Ferran Marcet + * Copyright (C) 2018 Charlene Benke * * 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)."'"; diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 317614afc4c..13c5878b6b8 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -3,8 +3,9 @@ * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015 Alexandre Spangaro - * Copyright (C) 2018 Ferran Marcet + * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2018 Ferran Marcet + * Copyright (C) 2018 Charlene Benke * * 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 ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) + print ''; + print ''; $formother->select_year($year_start,'year_start',1, $min_year, $max_year); print ''; @@ -547,7 +538,9 @@ if ($resql) if (! empty($arrayfields['d.date_fin']['checked'])) { print ''; - print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) + print ''; + print ''; $formother->select_year($year_end,'year_end',1, $min_year, $max_year); print ''; }