From a5571b1040ecf09f9db9332e56cdffbe426eb230 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 13 Mar 2016 01:20:54 +0100
Subject: [PATCH] NEW Show a badge with number of withdraw requests done on the
 withdraw tab of invoice.

---
 htdocs/compta/facture/prelevement.php |  4 +++-
 htdocs/core/lib/invoice.lib.php       | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php
index 47abb50fb8b..00254b7440f 100644
--- a/htdocs/compta/facture/prelevement.php
+++ b/htdocs/compta/facture/prelevement.php
@@ -454,7 +454,7 @@ if ($object->id > 0)
 
 
 	/*
-	 * Withdrawal request
+	 * Withdrawal opened requests
 	 */
 
 	$sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
@@ -564,6 +564,8 @@ if ($object->id > 0)
 		dol_print_error($db);
 	}
 
+	// Closed requests
+	
 	$sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande,";
 	$sql.= " pfd.date_traite, pfd.fk_prelevement_bons, pfd.amount,";
 	$sql.= " pb.ref,";
diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php
index 4946004a772..f947caf5609 100644
--- a/htdocs/core/lib/invoice.lib.php
+++ b/htdocs/core/lib/invoice.lib.php
@@ -64,8 +64,20 @@ function facture_prepare_head($object)
 	//if ($fac->mode_reglement_code == 'PRE')
 	if (! empty($conf->prelevement->enabled))
 	{
+	    $nbStandingOrders=0;
+	    $sql = "SELECT COUNT(pfd.rowid) as nb";
+	    $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
+	    $sql .= " WHERE pfd.fk_facture = ".$object->id;
+        $resql=$db->query($sql);
+        if ($resql) 
+        {
+            $obj=$db->fetch_object($resql);
+            if ($obj) $nbStandingOrders = $obj->nb;
+        }
+        else dol_print_error($db);
 		$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id;
 		$head[$h][1] = $langs->trans('StandingOrders');
+		if ($nbStandingOrders > 0) $head[$h][1].= ' <span class="badge">'.$nbStandingOrders.'</span>';
 		$head[$h][2] = 'standingorders';
 		$h++;
 	}
-- 
GitLab