Fix: When a custom compta group would be unactive, its code would stay in the computed formula. This would lead to wrong totals if the code is a number.

This commit is contained in:
Thomas Negre
2022-09-01 17:19:08 +02:00
parent 30ce816c0c
commit ce78e0164a
2 changed files with 10 additions and 3 deletions

View File

@@ -785,12 +785,13 @@ class AccountancyCategory // extends CommonObject
}
/**
* Return list of custom groups that are active
* Return list of custom groups.
*
* @param int $categorytype -1=All, 0=Only non computed groups, 1=Only computed groups
* @param int $active 1= active, 0=not active
* @return array|int Array of groups or -1 if error
*/
public function getCats($categorytype = -1)
public function getCats($categorytype = -1, $active = 1)
{
global $conf, $mysoc;
@@ -801,7 +802,7 @@ class AccountancyCategory // extends CommonObject
$sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type, c.sens";
$sql .= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
$sql .= " WHERE c.active = 1";
$sql .= " WHERE c.active = " . (int) $active;
$sql .= " AND c.entity = ".$conf->entity;
if ($categorytype >= 0) {
$sql .= " AND c.category_type = 1";

View File

@@ -274,6 +274,7 @@ if ($modecompta == 'CREANCES-DETTES') {
} elseif ($modecompta == "BOOKKEEPING") {
// Get array of all report groups that are active
$cats = $AccCat->getCats(); // WARNING: Computed groups must be after group they include
$unactive_cats = $AccCat->getCats(-1, 0);
/*
$sql = 'SELECT DISTINCT t.numero_compte as nb FROM '.MAIN_DB_PREFIX.'accounting_bookkeeping as t, '.MAIN_DB_PREFIX.'accounting_account as aa';
@@ -325,6 +326,11 @@ if ($modecompta == 'CREANCES-DETTES') {
$vars = array();
// Unactive categories have a total of 0 to be used in the formula.
foreach($unactive_cats as $un_cat) {
$vars[$un_cat['code']] = 0;
}
// Previous Fiscal year (N-1)
foreach ($sommes as $code => $det) {
$vars[$code] = $det['NP'];