Index: src/include/data/1.1.0_schema.sql ================================================================== --- src/include/data/1.1.0_schema.sql +++ src/include/data/1.1.0_schema.sql @@ -205,11 +205,11 @@ SUM(l.credit) AS credit, SUM(l.debit) AS debit FROM acc_accounts a INNER JOIN acc_transactions_lines l ON l.id_account = a.id INNER JOIN acc_transactions t ON t.id = l.id_transaction - GROUP BY t.id_year, l.id_analytical, a.id + GROUP BY l.id_analytical, a.id ); CREATE TABLE IF NOT EXISTS acc_years -- Exercices ( Index: src/include/data/schema.sql ================================================================== --- src/include/data/schema.sql +++ src/include/data/schema.sql @@ -205,11 +205,11 @@ SUM(l.credit) AS credit, SUM(l.debit) AS debit FROM acc_accounts a INNER JOIN acc_transactions_lines l ON l.id_account = a.id INNER JOIN acc_transactions t ON t.id = l.id_transaction - GROUP BY t.id_year, l.id_analytical, a.id + GROUP BY l.id_analytical, a.id ); CREATE TABLE IF NOT EXISTS acc_years -- Exercices ( Index: src/include/lib/Garradin/Accounting/Reports.php ================================================================== --- src/include/lib/Garradin/Accounting/Reports.php +++ src/include/lib/Garradin/Accounting/Reports.php @@ -264,12 +264,18 @@ * @param string|null $order Order of rows (SQL clause), if NULL will order by CODE * @param bool $remove_zero Remove accounts where the balance is zero from the list */ static public function getAccountsBalances(array $criterias, ?string $order = null, bool $remove_zero = true) { + $group = 'code'; + $having = ''; $order = $order ?: 'code COLLATE NOCASE'; - $remove_zero = $remove_zero ? 'code HAVING balance != 0' : ''; + + if ($remove_zero) { + $having = 'HAVING balance != 0'; + } + $table = null; if (!empty($criterias['analytical'])) { $table = 'acc_accounts_projects_balances'; } @@ -292,25 +298,24 @@ END AS balance FROM %s l INNER JOIN %s t ON t.id = l.id_transaction INNER JOIN %s a ON a.id = l.id_account WHERE %s - GROUP BY l.id_account %s + GROUP BY l.id_account AND %s %s ORDER BY %s'; - $sql = sprintf($query, Line::TABLE, Transaction::TABLE, Account::TABLE, $where, $remove_zero, $order); + $sql = sprintf($query, Line::TABLE, Transaction::TABLE, Account::TABLE, $where, $group, $having, $order); } else { $where = self::getWhereClause($criterias); - $remove_zero = $remove_zero ? 'GROUP BY ' . $remove_zero : ''; - $query = 'SELECT * FROM %s + $query = 'SELECT *, SUM(credit) AS credit, SUM(debit) AS debit, SUM(balance) AS balance FROM %s WHERE %s - %s + GROUP BY %s %s ORDER BY %s'; - $sql = sprintf($query, $table, $where, $remove_zero, $order); + $sql = sprintf($query, $table, $where, $group, $having, $order); } $db = DB::getInstance();