Prepare code for performance enhancement
This commit is contained in:
parent
72fc0226e3
commit
5727cf2910
@ -724,48 +724,50 @@ class AccountancyCategory // extends CommonObject
|
||||
* @param string $thirdparty_code Thirdparty code
|
||||
* @param string $month Specifig month - Can be empty
|
||||
* @param string $year Specifig year - Can be empty
|
||||
* @return integer Result in table
|
||||
* @return integer <0 if KO, >= 0 if OK
|
||||
*/
|
||||
public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code='nofilter', $month=0, $year=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$this->sdc = 0;
|
||||
$this->sdcpermonth = array();
|
||||
|
||||
$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) . "'";
|
||||
$sql .= " WHERE t.entity = ".$conf->entity;
|
||||
$sql .= " AND 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)."'";
|
||||
$sql .= " AND (t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."')";
|
||||
if (! empty($month) && ! empty($year)) {
|
||||
$sql .= " AND t.doc_date BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."'";
|
||||
$sql .= " AND (t.doc_date BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."')";
|
||||
}
|
||||
if ($thirdparty_code != 'nofilter')
|
||||
{
|
||||
$sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
|
||||
}
|
||||
$sql .= " AND t.entity = ".$conf->entity;
|
||||
//print $sql;
|
||||
|
||||
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql) {
|
||||
if ($resql)
|
||||
{
|
||||
$num = $this->db->num_rows($resql);
|
||||
$this->sdc = 0;
|
||||
if ($num) {
|
||||
if ($num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($sens == 1) {
|
||||
$this->sdc = $obj->debit - $obj->credit;
|
||||
} else {
|
||||
$this->sdc = $obj->credit - $obj->debit;
|
||||
}
|
||||
$this->sdcpermonth[$year.'_'.$month.'_'.$sens] = $this->sdc;
|
||||
}
|
||||
return $num;
|
||||
} else {
|
||||
$this->error = "Error " . $this->db->lasterror();
|
||||
dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
|
||||
|
||||
return - 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -437,7 +437,7 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
// @TODO Optimize mode when $showaccountdetail == 'no'
|
||||
|
||||
// N-1
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start_previous, $date_end_previous, $cpt['dc']);
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start_previous, $date_end_previous, $cpt['dc']?$cpt['dc']:0);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultNP=0;
|
||||
@ -458,7 +458,7 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
if (($k+1) < $start_month) $yeartoprocess++;
|
||||
|
||||
//var_dump($monthtoprocess.'_'.$yeartoprocess);
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc'], 'nofilter', $monthtoprocess, $yeartoprocess);
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']?$cpt['dc']:0, 'nofilter', $monthtoprocess, $yeartoprocess);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultM=0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user