FIX #35658 leading-zero account numbers dropped from personalized group totals (#39208)

In compta/resultat/result.php and clientfourn.php the account number was cast to
(int) before being passed to AccountancyCategory::getSumDebitCredit(), which
compares it as a string (t.numero_compte = '...'). (int) '0510' -> 510 -> '510'
never matches the stored '0510' (numero_compte and account_number are varchar(32),
so leading zeros are significant). Accounts whose code starts with 0 were therefore
silently excluded from the current-year and per-month totals of a personalized
account group, while the previous-year column was already correct because it passes
a string array.

The (int) cast had no functional purpose: it was added to silence a phan notice in
"Qual: Fix phan notices" (#33484). Remove it and pass the raw string, and widen the
getSumDebitCredit() @param to string|int|array<?string> so the string argument is
accepted by static analysis and the cast is not reintroduced. Numeric codes are
unaffected (the callee already casts the scalar with (string)).
This commit is contained in:
Jam Balaya 2026-07-19 22:45:45 +09:00 committed by GitHub
parent 6251488091
commit e9e526c032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 3 deletions

View file

@ -624,7 +624,7 @@ class AccountancyCategory // extends CommonObject
/**
* Function to set the property ->sdc (and ->sdcperaccount) that is the result of an accounting account from the ledger with a direction and a period
*
* @param int|array<?string> $cpt Accounting account or array of accounting account
* @param string|int|array<?string> $cpt Accounting account or array of accounting account
* @param int $date_start Date start
* @param int $date_end Date end
* @param int<0,1> $sens Sens of the account: 0: credit - debit (use this by default), 1: debit - credit

View file

@ -386,7 +386,7 @@ if ($modecompta == 'BOOKKEEPING') {
$cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere);
foreach ($cpts as $j => $cpt) {
$return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc']));
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, (empty($cpt['dc']) ? 0 : $cpt['dc']));
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
$resultN = 0;

View file

@ -560,7 +560,7 @@ if ($modecompta == 'CREANCES-DETTES') {
) {
//var_dump($monthtoprocess.'_'.$yeartoprocess);
if (isset($cpt['account_number'])) {
$return = $AccCat->getSumDebitCredit((int) $cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess);
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, empty($cat['dc']) ? 0 : $cat['dc'], 'nofilter', $monthtoprocess, $yeartoprocess);
if ($return < 0) {
setEventMessages(null, $AccCat->errors, 'errors');
$resultM = 0;