Optimize performance: Remove call for year N, can be done with total of
each month
This commit is contained in:
parent
97af22369d
commit
72fc0226e3
@ -732,6 +732,7 @@ class AccountancyCategory // extends CommonObject
|
|||||||
|
|
||||||
$sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
|
$sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
|
||||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t";
|
$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) . "'";
|
$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
|
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)."'";
|
$sql .= " AND t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."'";
|
||||||
|
|||||||
@ -445,23 +445,12 @@ elseif ($modecompta=="BOOKKEEPING")
|
|||||||
$resultNP=$AccCat->sdc;
|
$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['NP'] += $resultNP;
|
||||||
$totCat['N'] += $resultN;
|
|
||||||
$sommes[$code]['NP'] += $resultNP;
|
$sommes[$code]['NP'] += $resultNP;
|
||||||
$sommes[$code]['N'] += $resultN;
|
|
||||||
$totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
|
$totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
|
||||||
$totPerAccount[$cpt['account_number']]['N'] = $resultN;
|
|
||||||
|
|
||||||
// Each month
|
// Each month
|
||||||
|
$resultN = 0;
|
||||||
foreach($months as $k => $v)
|
foreach($months as $k => $v)
|
||||||
{
|
{
|
||||||
$monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12
|
$monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12
|
||||||
@ -479,7 +468,22 @@ elseif ($modecompta=="BOOKKEEPING")
|
|||||||
$totCat['M'][$k] += $resultM;
|
$totCat['M'][$k] += $resultM;
|
||||||
$sommes[$code]['M'][$k] += $resultM;
|
$sommes[$code]['M'][$k] += $resultM;
|
||||||
$totPerAccount[$cpt['account_number']]['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', ...)
|
// Now output columns for row $code ('VTE', 'MAR', ...)
|
||||||
@ -497,7 +501,6 @@ elseif ($modecompta=="BOOKKEEPING")
|
|||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
// Loop on detail of all accounts
|
// 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')
|
if ($showaccountdetail != 'no')
|
||||||
{
|
{
|
||||||
foreach($cpts as $i => $cpt)
|
foreach($cpts as $i => $cpt)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user