From 42b04102ba58305ca8ff2bb534ce81c1ce1dcef3 Mon Sep 17 00:00:00 2001
From: fmarcet <fmarcet@imedia>
Date: Thu, 11 Jun 2015 12:40:16 +0200
Subject: [PATCH] New: Add due date filter on invoices lists

---
 htdocs/compta/facture/list.php | 23 +++++++++++++++++++++-
 htdocs/fourn/facture/list.php  | 36 ++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 08a14b75602..6d9a6329d4e 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -10,6 +10,7 @@
  * Copyright (C) 2013      Florian Henry		  	<florian.henry@open-concept.pro>
  * Copyright (C) 2013      Cédric Salvador       <csalvador@gpcsolutions.fr>
  * Copyright (C) 2015      Jean-François Ferry	<jfefe@aternatik.fr>
+ * Copyright (C) 2015	   Ferran Marcet		<fmarcet@2byte.es>
  *
  * 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,6 +89,9 @@ $search_sale = GETPOST('search_sale','int');
 $day	= GETPOST('day','int');
 $month	= GETPOST('month','int');
 $year	= GETPOST('year','int');
+$day_lim	= GETPOST('day_lim','int');
+$month_lim	= GETPOST('month_lim','int');
+$year_lim	= GETPOST('year_lim','int');
 $filtre	= GETPOST('filtre');
 
 // Security check
@@ -213,6 +217,19 @@ else if ($year > 0)
 {
     $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
 }
+if ($month_lim > 0)
+{
+	if ($year_lim > 0 && empty($day_lim))
+		$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,$month_lim,false))."' AND '".$db->idate(dol_get_last_day($year_lim,$month_lim,false))."'";
+	else if ($year_lim > 0 && ! empty($day_lim))
+		$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'";
+	else
+		$sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'";
+}
+else if ($year_lim > 0)
+{
+	$sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($year_lim,12,false))."'";
+}
 if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
 if ($search_user > 0)
 {
@@ -322,7 +339,11 @@ if ($resql)
     print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
     $formother->select_year($year?$year:-1,'year',1, 20, 5);
     print '</td>';
-    print '<td class="liste_titre" align="left">&nbsp;</td>';
+ 	print '<td class="liste_titre" align="center">';
+    if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.$day_lim.'">';
+    print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.$month_lim.'">';
+    $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
+    print '</td>';
     print '<td class="liste_titre" align="left"><input class="flat" type="text" size="8" name="search_societe" value="'.$search_societe.'"></td>';
     print '<td class="liste_titre" align="right"><input class="flat" type="text" size="6" name="search_montant_ht" value="'.$search_montant_ht.'"></td>';
     print '<td class="liste_titre" align="right">&nbsp;</td>';
diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php
index 010e9b95ae6..88a82573d7a 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -8,7 +8,8 @@
  * Copyright (C) 2015      Marcos García        <marcosgdf@gmail.com>
  * Copyright (C) 2015	   juanjo Menent		<jmenent@2byte.es>
  * Copyright (C) 2015 	   Abbes Bahfir 	<bafbes@gmail.com>
-
+ * Copyright (C) 2015	   Ferran Marcet		<fmarcet@2byte.es>
+ * 
  * 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
  * the Free Software Foundation; either version 3 of the License, or
@@ -74,8 +75,12 @@ $search_company = GETPOST("search_company","alpha");
 $search_amount_no_tax = GETPOST("search_amount_no_tax","alpha");
 $search_amount_all_tax = GETPOST("search_amount_all_tax","alpha");
 $search_status=GETPOST('search_status','alpha');
+$day = GETPOST("day","int");
 $month = GETPOST("month","int");
 $year = GETPOST("year","int");
+$day_lim	= GETPOST('day_lim','int');
+$month_lim	= GETPOST('month_lim','int');
+$year_lim	= GETPOST('year_lim','int');
 $filter = GETPOST("filtre");
 
 if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter"))		// Both test must be present to be compatible with all browsers
@@ -163,15 +168,30 @@ if ($search_ref_supplier)
 }
 if ($month > 0)
 {
-	if ($year > 0)
+	if ($year > 0 && empty($day))
 	$sql.= " AND fac.datef 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 fac.datef 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(fac.datef, '%m') = '$month'";
+	$sql.= " AND date_format(fac.datef, '%m') = '".$month."'";
 }
 else if ($year > 0)
 {
 	$sql.= " AND fac.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
 }
+if ($month_lim > 0)
+{
+	if ($year_lim > 0 && empty($day_lim))
+		$sql.= " AND fac.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,$month_lim,false))."' AND '".$db->idate(dol_get_last_day($year_lim,$month_lim,false))."'";
+	else if ($year_lim > 0 && ! empty($day_lim))
+		$sql.= " AND fac.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'";
+	else
+		$sql.= " AND date_format(fac.date_lim_reglement, '%m') = '".$month_lim."'";
+}
+else if ($year_lim > 0)
+{
+	$sql.= " AND fac.datef BETWEEN '".$db->idate(dol_get_first_day($year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($year_lim,12,false))."'";
+}
 if ($search_label)
 {
     $sql .= natural_search('fac.libelle', $search_label);
@@ -260,11 +280,15 @@ if ($resql)
 		print '</td>';
 	}
 	print '<td class="liste_titre" colspan="1" align="center">';
+	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
 	print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
-	$syear = $year;
-	$formother->select_year($syear?$syear:-1,'year',1, 20, 5);
+	$formother->select_year($year?$year:-1,'year',1, 20, 5);
+	print '</td>';
+	print '<td class="liste_titre" colspan="1" align="center">';
+	if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.$day_lim.'">';
+	print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.$month_lim.'">';
+	$formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
 	print '</td>';
-	print '<td class="liste_titre">&nbsp;</td>';
 	print '<td class="liste_titre" align="left">';
 	print '<input class="flat" size="16" type="text" name="search_label" value="'.$search_label.'">';
 	print '</td>';
-- 
GitLab