diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index e2a7b14033c..6c389f20239 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -713,27 +713,36 @@ class AccountancyCategory // extends CommonObject * Function to show result of an accounting account from the ledger with a direction and a period * * @param int $cpt Id accounting account - * @param string $month Specifig month - Can be empty * @param string $date_start Date start * @param string $date_end Date end * @param int $sens Sens of the account: 0: credit - debit, 1: debit - credit * @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 */ - public function getResult($cpt, $month, $date_start, $date_end, $sens, $thirdparty_code='nofilter') + public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code='nofilter', $month=0, $year=0) { $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; - $sql .= " WHERE t.numero_compte = '" . $cpt."'"; + $sql .= " WHERE t.numero_compte = '" . $this->db->escape($cpt) . "'"; + /* if (! empty($date_start) && ! empty($date_end)) $sql.= " AND t.doc_date >= '".$this->db->idate($date_start)."' AND t.doc_date <= '".$this->db->idate($date_end)."'"; if (! empty($month)) { $sql .= " AND MONTH(t.doc_date) = " . $month; } + */ + if (! empty($date_start) && ! empty($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))."'"; + } if ($thirdparty_code != 'nofilter') { $sql .= " AND thirdparty_code = '".$this->db->escape($thirdparty_code)."'"; } + //print $sql; dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); @@ -856,13 +865,12 @@ class AccountancyCategory // extends CommonObject if ($num) { while ($obj = $this->db->fetch_object($resql)) { - $name_cat = $obj->name_cat; $data[] = array ( 'id' => $obj->rowid, 'account_number' => $obj->account_number, 'account_label' => $obj->account_label, ); - $i ++; + $i++; } } return $data; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index e08ebb17ed1..ee94b4ab5fc 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -303,7 +303,7 @@ if ($modecompta == 'BOOKKEEPING') foreach($cpts as $i => $cpt) { - $return = $AccCat->getResult($cpt['account_number'], 0, $date_start, $date_end, $cpt['dc']); + $return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultN=0; diff --git a/htdocs/compta/resultat/result.php b/htdocs/compta/resultat/result.php index c4a6e2ec755..3f53cfdc27c 100644 --- a/htdocs/compta/resultat/result.php +++ b/htdocs/compta/resultat/result.php @@ -78,7 +78,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end { // We define date_start and date_end $year_end=$year_start + ($nbofyear - 1); - $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); + $month_start=GETPOST("month",'int')?GETPOST("month",'int'):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); $date_startmonth = $month_start; if (! GETPOST('month')) { @@ -108,8 +108,10 @@ if (($date_start < dol_time_plus_duree($date_end, -1, 'y')) || ($date_start > $d // $date_start and $date_end are defined. We force $start_year and $nbofyear $tmps=dol_getdate($date_start); $start_year = $tmps['year']; +$start_month = $tmps['mon']; $tmpe=dol_getdate($date_end); $year_end = $tmpe['year']; +$month_end = $tmpe['mon']; $nbofyear = ($year_end - $start_year) + 1; $date_start_previous = dol_time_plus_duree($date_start, -1, 'y'); @@ -374,7 +376,6 @@ elseif ($modecompta=="BOOKKEEPING") } } - print "\n"; //var_dump($sommes); @@ -390,7 +391,7 @@ elseif ($modecompta=="BOOKKEEPING") $totCat['M'][$k] = 0; } - // Set $cpts of with array of accounts in the category/group + // Set $cpts with array of accounts in the category/group $cpts = $AccCat->getCptsCat($cat['rowid']); print "