diff --git a/htdocs/compta/bank/various_payment/list.php b/htdocs/compta/bank/various_payment/list.php
index 93ec0ed20dc..a3b02dc48bd 100644
--- a/htdocs/compta/bank/various_payment/list.php
+++ b/htdocs/compta/bank/various_payment/list.php
@@ -213,6 +213,9 @@ if ($arrayfields['account']['checked']) {
$sql = "SELECT v.rowid, v.sens, v.amount, v.label, v.datep as datep, v.datev as datev, v.fk_typepayment as type, v.num_payment, v.fk_bank, v.accountancy_code, v.subledger_account, v.fk_projet as fk_project,";
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number as bank_account_number, ba.fk_accountancy_journal as accountancy_journal, ba.label as blabel,";
$sql .= " pst.code as payment_code";
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."payment_various as v";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON v.fk_typepayment = pst.id";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON v.fk_bank = b.rowid";
@@ -265,11 +268,27 @@ if ($search_all) {
$sql .= $db->order($sortfield, $sortorder);
-$totalnboflines = 0;
-$resql = $db->query($sql);
-if ($resql) {
- $totalnboflines = $db->num_rows($resql);
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+ $db->free($resql);
}
+
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
@@ -355,7 +374,7 @@ if ($resql) {
print '';
print '';
- print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
+ print_barre_liste($langs->trans("MenuVariousPayment"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'object_payment', 0, $newcardbutton, '', $limit, 0, 0, 1);
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index 46cf6b73ac4..6a8a37f35b7 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -597,6 +597,9 @@ if (!empty($extrafields->attributes[$object->table_element]['label'])) {
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
@@ -911,21 +914,12 @@ $parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- /* This old and fast method to get and count full list returns all record so use a high amount of memory.
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
- */
/* The fast and low memory method to get and count full list converts the sql into a sql count */
- if ($sall || $search_user > 0) {
- $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql);
- } else {
- $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql);
- $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount);
- }
- $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
-
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
$resql = $db->query($sqlforcount);
if ($resql) {
$objforcount = $db->fetch_object($resql);
@@ -934,7 +928,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
dol_print_error($db);
}
- if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
@@ -942,13 +936,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
}
// Complete request and execute it with limit
-$sql .= ' ORDER BY ';
-$listfield = explode(',', $sortfield);
-$listorder = explode(',', $sortorder);
-foreach ($listfield as $key => $value) {
- $sql .= $listfield[$key].' '.($listorder[$key] ? $listorder[$key] : 'DESC').',';
-}
-$sql .= ' f.rowid DESC ';
+$sql .= $db->order($sortfield, $sortorder);
if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
diff --git a/htdocs/compta/paiement/cheque/list.php b/htdocs/compta/paiement/cheque/list.php
index 9ab1ab7f1bd..c6909129dda 100644
--- a/htdocs/compta/paiement/cheque/list.php
+++ b/htdocs/compta/paiement/cheque/list.php
@@ -59,7 +59,7 @@ if (!$sortorder) {
$sortorder = "DESC";
}
if (!$sortfield) {
- $sortfield = "dp";
+ $sortfield = "bc.date_bordereau";
}
$year = GETPOST("year");
@@ -94,9 +94,12 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
llxHeader('', $langs->trans("ChequesReceipts"));
-$sql = "SELECT bc.rowid, bc.ref as ref, bc.date_bordereau as dp,";
+$sql = "SELECT bc.rowid, bc.ref, bc.date_bordereau,";
$sql .= " bc.nbcheque, bc.amount, bc.statut,";
$sql .= " ba.rowid as bid, ba.label";
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
$sql .= " ".MAIN_DB_PREFIX."bank_account as ba";
$sql .= " WHERE bc.fk_bank_account = ba.rowid";
@@ -116,14 +119,25 @@ $sql .= dolSqlDateFilter('bc.date_bordereau', 0, $month, $year);
$sql .= $db->order($sortfield, $sortorder);
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
+ $db->free($resql);
}
$sql .= $db->plimit($limit + 1, $offset);
@@ -193,7 +207,7 @@ if ($resql) {
print '
';
print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "bc.ref", "", $param, "", $sortfield, $sortorder);
- print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "dp", "", $param, 'align="center"', $sortfield, $sortorder);
+ print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "bc.date_bordereau", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("NbOfCheques", $_SERVER["PHP_SELF"], "bc.nbcheque", "", $param, 'class="right"', $sortfield, $sortorder);
print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "bc.amount", "", $param, 'class="right"', $sortfield, $sortorder);
@@ -216,7 +230,7 @@ if ($resql) {
print '';
// Date
- print '| '.dol_print_date($db->jdate($objp->dp), 'day').' | '; // TODO Use date hour
+ print ''.dol_print_date($db->jdate($objp->date_bordereau), 'day').' | '; // TODO Use date hour
// Bank
print '';
diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php
index 6deab76a20e..c88d77eff42 100644
--- a/htdocs/compta/paiement/list.php
+++ b/htdocs/compta/paiement/list.php
@@ -195,6 +195,9 @@ if (GETPOST("orphelins", "alpha")) {
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
+
+ $sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_paiement = c.id";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid";
@@ -257,16 +260,25 @@ if (GETPOST("orphelins", "alpha")) {
}
$sql .= $db->order($sortfield, $sortorder);
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
- // if total resultset is smaller then paging size (filtering), goto and load page 0
- if (($page * $limit) > $nbtotalofrecords) {
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
+ $db->free($resql);
}
$sql .= $db->plimit($limit + 1, $offset);
diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php
index 4690fd3bbb2..dfac774d8cf 100644
--- a/htdocs/compta/prelevement/list.php
+++ b/htdocs/compta/prelevement/list.php
@@ -112,6 +112,9 @@ $sql = "SELECT p.rowid, p.ref, p.statut as status, p.datec";
$sql .= " , f.rowid as facid, f.ref as invoiceref, f.total_ttc";
$sql .= " , s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.email";
$sql .= " , pl.amount, pl.statut as statut_ligne, pl.rowid as rowid_ligne";
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
@@ -157,12 +160,22 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
+ $db->free($resql);
}
$sql .= $db->plimit($limit + 1, $offset);
diff --git a/htdocs/compta/prelevement/orders_list.php b/htdocs/compta/prelevement/orders_list.php
index 5aca0730f67..3578fb5ca67 100644
--- a/htdocs/compta/prelevement/orders_list.php
+++ b/htdocs/compta/prelevement/orders_list.php
@@ -97,6 +97,9 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
llxHeader('', $langs->trans("WithdrawalsReceipts"));
$sql = "SELECT p.rowid, p.ref, p.amount, p.statut, p.datec";
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " WHERE p.entity IN (".getEntity('invoice').")";
if ($type == 'bank-transfer') {
@@ -116,12 +119,22 @@ $sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
+ $db->free($resql);
}
$sql .= $db->plimit($limit + 1, $offset);
diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php
index 024984d98b6..cf8622af8ec 100644
--- a/htdocs/compta/sociales/list.php
+++ b/htdocs/compta/sociales/list.php
@@ -194,6 +194,9 @@ if (isModEnabled('project')) {
$sql .= " c.libelle as type_label, c.accountancy_code as type_accountancy_code,";
$sql .= " ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,";
$sql .= " SUM(pc.amount) as alreadypayed, pay.code as payment_code";
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,";
$sql .= " ".MAIN_DB_PREFIX."chargesociales as cs";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (cs.fk_account = ba.rowid)";
@@ -253,11 +256,27 @@ if (isModEnabled('project')) {
}
$sql .= $db->order($sortfield, $sortorder);
-$totalnboflines = 0;
-$result = $db->query($sql);
-if ($result) {
- $totalnboflines = $db->num_rows($result);
+// Count total nb of records
+$nbtotalofrecords = '';
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
+
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
+ $page = 0;
+ $offset = 0;
+ }
+ $db->free($resql);
}
+
$sql .= $db->plimit($limit + 1, $offset);
$resql = $db->query($sql);
@@ -363,7 +382,7 @@ print '';
$center = '';
-print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $totalnboflines, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
+print_barre_liste($langs->trans("SocialContributions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $center, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
print ' ';
diff --git a/htdocs/compta/tva/list.php b/htdocs/compta/tva/list.php
index ffc2ef8ca68..0019c54d7dc 100644
--- a/htdocs/compta/tva/list.php
+++ b/htdocs/compta/tva/list.php
@@ -150,6 +150,9 @@ $sql = 'SELECT t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepa
$sql.= ' ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,';
$sql.= ' t.num_payment, pst.code as payment_code,';
$sql .= ' SUM(ptva.amount) as alreadypayed';
+
+$sqlfields = $sql; // $sql fields to remove for count total
+
$sql .= ' FROM '.MAIN_DB_PREFIX.'tva as t';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pst ON (t.fk_typepayment = pst.id)';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON (t.fk_account = ba.rowid)';
@@ -190,16 +193,25 @@ if ($search_status != '' && $search_status >= 0) {
$sql .= " GROUP BY t.rowid, t.amount, t.label, t.datev, t.datep, t.paye, t.fk_typepayment, t.fk_account, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, t.num_payment, pst.code";
$sql .= $db->order($sortfield, $sortorder);
+// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
- $resql = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($resql);
+ /* The fast and low memory method to get and count full list converts the sql into a sql count */
+ $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
+ $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
+ $resql = $db->query($sqlforcount);
+ if ($resql) {
+ $objforcount = $db->fetch_object($resql);
+ $nbtotalofrecords = $objforcount->nbtotalofrecords;
+ } else {
+ dol_print_error($db);
+ }
- // if total resultset is smaller then paging size (filtering), goto and load page 0
- if (($page * $limit) > $nbtotalofrecords) {
+ if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
+ $db->free($resql);
}
$sql .= $db->plimit($limit + 1, $offset);
|