Index: src/include/lib/Garradin/Accounting/Reports.php ================================================================== --- src/include/lib/Garradin/Accounting/Reports.php +++ src/include/lib/Garradin/Accounting/Reports.php @@ -35,10 +35,14 @@ } if (!empty($criterias['creator'])) { $where[] = sprintf('t.id_creator = %d', $criterias['creator']); } + + if (!empty($criterias['service_user'])) { + $where[] = sprintf('t.id IN (SELECT tu.id_transaction FROM acc_transactions_users tu WHERE id_service_user = %d)', $criterias['service_user']); + } if (!count($where)) { throw new \LogicException('Unknown criteria'); } @@ -185,36 +189,24 @@ return $out; } /** * Return list of favorite accounts (accounts with a type), grouped by type, with their current sum - * @param int $chart_id - * @param int $year_id * @return \Generator list of accounts grouped by type */ - static public function getClosingSumsFavoriteAccounts(int $chart_id, int $year_id, bool $include_all = false): \Generator - { - if ($include_all) { - // List all accounts, including those with no amount - $sql = sprintf('SELECT a.id, a.code, a.label, a.description, a.type, - (SELECT SUM(l.credit) - SUM(l.debit) FROM %s l INNER JOIN %s t ON t.id = l.id_transaction WHERE l.id_account = a.id AND t.id_year = %d) AS sum - FROM %s a - WHERE a.id_chart = %d AND a.type != 0 - GROUP BY a.id - ORDER BY a.type, a.code COLLATE NOCASE;', - Line::TABLE, Transaction::TABLE, $year_id, Account::TABLE, $chart_id); - } - else { - $sql = sprintf('SELECT a.id, a.code, a.label, a.description, a.type, - SUM(l.credit) - SUM(l.debit) AS sum - FROM %s a - INNER JOIN %s t ON t.id = l.id_transaction - INNER JOIN %s l ON a.id = l.id_account - WHERE t.id_year = %d AND a.type != 0 - GROUP BY l.id_account - ORDER BY a.type, a.code COLLATE NOCASE;', Account::TABLE, Transaction::TABLE, Line::TABLE, $year_id); - } + static public function getClosingSumsFavoriteAccounts(array $criterias): \Generator + { + $where = self::getWhereClause($criterias); + + $sql = sprintf('SELECT a.id, a.code, a.label, a.description, a.type, + SUM(l.credit) - SUM(l.debit) AS sum + FROM %s a + INNER JOIN %s t ON t.id = l.id_transaction + INNER JOIN %s l ON a.id = l.id_account + WHERE a.type != 0 AND %s + GROUP BY l.id_account + ORDER BY a.type, a.code COLLATE NOCASE;', Account::TABLE, Transaction::TABLE, Line::TABLE, $where); $group = null; foreach (DB::getInstance()->iterate($sql) as $row) { if (null !== $group && $row->type !== $group->type) { @@ -239,20 +231,10 @@ if (null !== $group) { yield $group; } } - static public function getClosingSums(int $year_id): array - { - // Find sums, link them to accounts - $sql = sprintf('SELECT l.id_account, SUM(l.credit) - SUM(l.debit) - FROM %s l - INNER JOIN %s t ON t.id = l.id_transaction - WHERE t.id_year = %d GROUP BY l.id_account;', Line::TABLE, Transaction::TABLE, $year_id); - return DB::getInstance()->getAssoc($sql); - } - /** * Grand livre */ static public function getGeneralLedger(array $criterias): \Generator { Index: src/include/lib/Garradin/Accounting/Years.php ================================================================== --- src/include/lib/Garradin/Accounting/Years.php +++ src/include/lib/Garradin/Accounting/Years.php @@ -22,10 +22,15 @@ static public function listOpen() { $em = EntityManager::getInstance(Year::class); return $em->all('SELECT * FROM @TABLE WHERE closed = 0 ORDER BY end_date;'); } + + static public function listAssoc() + { + return DB::getInstance()->getAssoc('SELECT id, label FROM acc_years ORDER BY end_date;'); + } static public function listClosed() { $em = EntityManager::getInstance(Year::class); return $em->all('SELECT * FROM @TABLE WHERE closed = 1 ORDER BY end_date;'); ADDED src/templates/acc/transactions/service_user.tpl Index: src/templates/acc/transactions/service_user.tpl ================================================================== --- src/templates/acc/transactions/service_user.tpl +++ src/templates/acc/transactions/service_user.tpl @@ -0,0 +1,32 @@ +{include file="admin/_head.tpl" title="Écritures liées à une inscription" current="acc/accounts"} + +
+ {linkbutton href="membres/fiche.php?id=%d"|args:$user_id label="Retour à la fiche membre" shape="user"} +
+ +{include file="acc/reports/_journal.tpl"} + +Numéro | +Compte | +Solde débiteur | +Solde créditeur | +
---|---|---|---|
{$account.code} | +{$account.label} | +{if $account.sum < 0}{$account.sum|raw|html_money}{/if} | +{if $account.sum > 0}{$account.sum|raw|html_money}{/if} | +
Cette liste représente le solde des comptes uniquement pour les écritures liées à un membre, et ce sur tous les exercices réunis.
+ + +Cette liste représente le solde des comptes uniquement pour les écritures liées à ce membre.
Numéro | Compte | -Solde | +Solde débiteur | +Solde créditeur |
---|---|---|---|---|
{$account.code} | {$account.label} | -{$account.sum|raw|html_money:false} | +{if $account.sum < 0}{$account.sum|raw|html_money}{/if} | +{if $account.sum > 0}{$account.sum|raw|html_money}{/if} |