Optimize performance: Remove call for year N, can be done with total of

each month
This commit is contained in:
Laurent Destailleur 2018-11-22 19:45:35 +01:00
parent 97af22369d
commit 72fc0226e3
2 changed files with 17 additions and 13 deletions

View File

@ -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)."'";

View File

@ -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 "</tr>\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)