diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index b70341e21f7..6bb7be94f81 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -732,6 +732,7 @@ class AccountancyCategory // extends CommonObject $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; + //if (in_array($this->db->type, array('mysql', 'mysqli'))) $sql.=' USE INDEX idx_accounting_bookkeeping_doc_date'; $sql .= " WHERE t.numero_compte = '" . $this->db->escape($cpt) . "'"; if (! empty($date_start) && ! empty($date_end) && (empty($month) || empty($year))) // If month/year provided, it is stronger than filter date_start/date_end $sql .= " AND t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."'"; diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index 9e3c28f529d..39b6a8dc79a 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -445,23 +445,12 @@ elseif ($modecompta=="BOOKKEEPING") $resultNP=$AccCat->sdc; } - // N - $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']); - if ($return < 0) { - setEventMessages(null, $AccCat->errors, 'errors'); - $resultN=0; - } else { - $resultN=$AccCat->sdc; - } - $totCat['NP'] += $resultNP; - $totCat['N'] += $resultN; $sommes[$code]['NP'] += $resultNP; - $sommes[$code]['N'] += $resultN; $totPerAccount[$cpt['account_number']]['NP'] = $resultNP; - $totPerAccount[$cpt['account_number']]['N'] = $resultN; // Each month + $resultN = 0; foreach($months as $k => $v) { $monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12 @@ -479,7 +468,22 @@ elseif ($modecompta=="BOOKKEEPING") $totCat['M'][$k] += $resultM; $sommes[$code]['M'][$k] += $resultM; $totPerAccount[$cpt['account_number']]['M'][$k] = $resultM; + + $resultN += $resultM; } + + // N + /*$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultN=0; + } else { + $resultN=$AccCat->sdc; + }*/ + + $totCat['N'] += $resultN; + $sommes[$code]['N'] += $resultN; + $totPerAccount[$cpt['account_number']]['N'] = $resultN; } // Now output columns for row $code ('VTE', 'MAR', ...) @@ -497,7 +501,6 @@ elseif ($modecompta=="BOOKKEEPING") print "\n"; // Loop on detail of all accounts - // This make 14 calls for each detail of account (N-1, N and 12 monthes m) if ($showaccountdetail != 'no') { foreach($cpts as $i => $cpt)