From ed3f0ce86bfb764f46d0ba9f579da07ffdf24f2c Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Mon, 28 Dec 2015 00:20:48 +0100
Subject: [PATCH] Fix totalnboflines not correctly managed

---
 htdocs/compta/salaries/index.php |  6 ++++++
 htdocs/compta/sociales/index.php |  6 ++++++
 htdocs/compta/tva/reglement.php  |  6 ++++++
 htdocs/contrat/list.php          |  8 ++++++--
 htdocs/contrat/services.php      |  6 ++++++
 htdocs/fichinter/list.php        |  6 ++++++
 htdocs/product/stock/list.php    | 35 ++++++++++++++++++++------------
 7 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php
index f3312761141..52f1938a857 100644
--- a/htdocs/compta/salaries/index.php
+++ b/htdocs/compta/salaries/index.php
@@ -108,6 +108,12 @@ if ($typeid) {
     $sql .= " AND s.fk_typepayment=".$typeid;
 }
 //$sql.= " GROUP BY u.rowid, u.lastname, u.firstname, s.rowid, s.fk_user, s.amount, s.label, s.datev, s.fk_typepayment, s.num_payment, pst.code";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($limit+1,$offset);
 
diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php
index dec724c95d5..63c156609c8 100644
--- a/htdocs/compta/sociales/index.php
+++ b/htdocs/compta/sociales/index.php
@@ -119,6 +119,12 @@ if ($typeid) {
     $sql .= " AND cs.fk_type=".$typeid;
 }
 $sql.= " GROUP BY cs.rowid, cs.fk_type, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($limit+1,$offset);
 
diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php
index b603101ad29..91140bb97ca 100644
--- a/htdocs/compta/tva/reglement.php
+++ b/htdocs/compta/tva/reglement.php
@@ -115,6 +115,12 @@ if ($filtre) {
 if ($typeid) {
     $sql .= " AND t.fk_typepayment=".$typeid;
 }
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($limit+1,$offset);
 
diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php
index 22b619c599c..e8c722dcab3 100644
--- a/htdocs/contrat/list.php
+++ b/htdocs/contrat/list.php
@@ -136,17 +136,21 @@ if ($search_contract) {
 if (!empty($search_ref_supplier)) {
 	$sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
 }
-
 if ($search_sale > 0)
 {
 	$sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
 }
-
 if ($sall) {
     $sql .= natural_search(array_keys($fieldstosearchall), $sall);
 }
 if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
 $sql.= " GROUP BY c.rowid, c.ref, c.datec, c.date_contrat, c.statut, c.ref_supplier, s.nom, s.rowid";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($conf->liste_limit + 1, $offset);
 
diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php
index c59c67fe91c..b7b257ca07a 100644
--- a/htdocs/contrat/services.php
+++ b/htdocs/contrat/services.php
@@ -147,6 +147,12 @@ $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year);
 $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year);
 if (! empty($filter_op1) && $filter_op1 != -1 && $filter_date1 != '') $sql.= " AND date_ouverture_prevue ".$filter_op1." '".$db->idate($filter_date1)."'";
 if (! empty($filter_op2) && $filter_op2 != -1 && $filter_date2 != '') $sql.= " AND date_fin_validite ".$filter_op2." '".$db->idate($filter_date2)."'";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql .= $db->order($sortfield,$sortorder);
 $sql .= $db->plimit($limit + 1, $offset);
 
diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php
index 241b8f522b0..74edaf72099 100644
--- a/htdocs/fichinter/list.php
+++ b/htdocs/fichinter/list.php
@@ -123,6 +123,12 @@ if ($socid)
 if ($sall) {
 	$sql .= natural_search(array_keys($fieldstosearchall), $sall);
 }
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($limit+1, $offset);
 //print $sql;
diff --git a/htdocs/product/stock/list.php b/htdocs/product/stock/list.php
index a7dde67013a..833e285f608 100644
--- a/htdocs/product/stock/list.php
+++ b/htdocs/product/stock/list.php
@@ -68,6 +68,12 @@ if ($search_label) $sql.= natural_search("e.lieu", $search_label);		// label
 if ($search_status != '' && $search_status >= 0) $sql.= " AND e.statut = ".$search_status;
 if ($sall) $sql.= natural_search(array('e.label','e.description','e.lieu','e.address','e.town'), $sall);
 $sql.= " GROUP BY e.rowid, e.label, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays";
+$totalnboflines=0;
+$result=$db->query($sql);
+if ($result)
+{
+    $totalnboflines = $db->num_rows($result);
+}
 $sql.= $db->order($sortfield,$sortorder);
 $sql.= $db->plimit($limit+1, $offset);
 
@@ -81,7 +87,7 @@ if ($result)
 	$help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
 	llxHeader("",$langs->trans("ListOfWarehouses"),$help_url);
 
-	print_barre_liste($langs->trans("ListOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder,'',$num);
+	print_barre_liste($langs->trans("ListOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $totalnboflines);
 
 	print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -168,20 +174,23 @@ if ($result)
             $i++;
 		}
 
-		print '<tr class="liste_total">';
-        print '<td colspan="2" align="right">'.$langs->trans("Total").'</td>';
-        print '<td align="right">'.price(price2num($total,'MT'),1,$langs,0,0,-1,$conf->currency).'</td>';
-        print '<td align="right">';
-		if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($totalsell,'MT'),1,$langs,0,0,-1,$conf->currency);
-        else
+		if ($totalnboflines <= $limit)
 		{
-			$htmltext=$langs->trans("OptionMULTIPRICESIsOn");
-           	print $form->textwithtooltip($langs->trans("Variable"),$htmltext);
+    		print '<tr class="liste_total">';
+            print '<td colspan="2" align="right">'.$langs->trans("Total").'</td>';
+            print '<td align="right">'.price(price2num($total,'MT'),1,$langs,0,0,-1,$conf->currency).'</td>';
+            print '<td align="right">';
+    		if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($totalsell,'MT'),1,$langs,0,0,-1,$conf->currency);
+            else
+    		{
+    			$htmltext=$langs->trans("OptionMULTIPRICESIsOn");
+               	print $form->textwithtooltip($langs->trans("Variable"),$htmltext);
+    		}
+            print '</td>';
+            print '<td></td>';
+            print '<td></td>';
+            print "</tr>\n";
 		}
-        print '</td>';
-        print '<td></td>';
-        print '<td></td>';
-        print "</tr>\n";
 	}
 
 	$db->free($result);
-- 
GitLab