Browse Source

Fix pagination show two times the same account on balance of accounts

Laurent Destailleur 6 years ago
parent
commit
aa6996e2d0

+ 15 - 8
htdocs/accountancy/bookkeeping/balance.php

@@ -41,6 +41,21 @@ $page = GETPOST("page");
 $sortorder = GETPOST("sortorder", 'alpha');
 $sortfield = GETPOST("sortfield", 'alpha');
 $action = GETPOST('action', 'alpha');
+if (GETPOST("exportcsv",'alpha')) $action = 'export_csv';
+
+// Load variable for pagination
+$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
+$sortfield = GETPOST('sortfield','alpha');
+$sortorder = GETPOST('sortorder','alpha');
+$page = GETPOST('page','int');
+if (empty($page) || $page == -1 || GETPOST('button_search','alpha') || GETPOST('button_removefilter','alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; }     // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
+$offset = $limit * $page;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+//if (! $sortfield) $sortfield="p.date_fin";
+//if (! $sortorder) $sortorder="DESC";
+
+
 $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
 $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
 
@@ -53,14 +68,6 @@ if ($search_accountancy_code_end == - 1) {
 	$search_accountancy_code_end = '';
 }
 
-if (GETPOST("exportcsv",'alpha')) $action = 'export_csv';
-
-
-$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):$conf->liste_limit;
-if (empty($page) || $page < 0) { $page = 0; }
-
-$offset = $limit * $page;
-
 $object = new BookKeeping($db);
 
 $formaccounting = new FormAccounting($db);

+ 7 - 2
htdocs/accountancy/class/bookkeeping.class.php

@@ -986,16 +986,21 @@ class BookKeeping extends CommonObject
 		}
 
 		$resql = $this->db->query($sql);
-		if ($resql) {
+		if ($resql)
+		{
 			$num = $this->db->num_rows($resql);
 
-			while ( $obj = $this->db->fetch_object($resql) ) {
+			$i = 0;
+			while ($obj = $this->db->fetch_object($resql) && $i < $num)
+			{
 				$line = new BookKeepingLine();
 
 				$line->numero_compte = $obj->numero_compte;
 				$line->debit = $obj->debit;
 				$line->credit = $obj->credit;
 				$this->lines[] = $line;
+
+				$i++;
 			}
 			$this->db->free($resql);