mirror of
https://github.com/itflow-org/itflow
synced 2026-11-11 07:01:16 +00:00
Fix Transactions Money in and Money out on All accounts counting every transfer twice - a transfer is money moved between your own accounts, so across all accounts both of its lines are now left out of the totals, the Money in and Money out pills and their export, while the Transfers pill still lists them and a single account's view still counts them as money in and out of that account
This commit is contained in:
@@ -90,8 +90,11 @@ $count_sql = [];
|
||||
foreach ($shows as $key => $s) {
|
||||
$count_sql[] = $key === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)";
|
||||
}
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0)";
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0)";
|
||||
// Across every account a transfer is money moved between them, so Money in and Money out
|
||||
// leave it out (accountLedgerShows()) - except on Transfers, where it is what is listed
|
||||
$not_transfer = $all && $show !== 'transfers' ? "AND ledger.txn_kind NOT IN ('transfer_in', 'transfer_out')" : '';
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount > 0 THEN ledger.txn_amount END), 0)";
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query $not_transfer AND ledger.txn_amount < 0 THEN -ledger.txn_amount END), 0)";
|
||||
if ($transfer_cards) {
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query THEN -ledger.txn_amount END), 0)";
|
||||
$count_sql[] = "COALESCE(SUM(CASE WHEN 1 $show_query AND ledger.other_account_type = 3 THEN -ledger.txn_amount END), 0)";
|
||||
@@ -186,14 +189,14 @@ $is_card = $account && $account['type'] === 3;
|
||||
<a class="itflow-billing-stat <?= $show === 'in' ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => 'in'])) ?>">
|
||||
<div class="itflow-billing-stat-label"><i class="fas fa-arrow-down me-1"></i>Money in</div>
|
||||
<div class="itflow-billing-stat-value text-success-emphasis"><?= $money($total_in) ?></div>
|
||||
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers counted both ways' : '' ?></div>
|
||||
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers between accounts left out' : '' ?></div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
<a class="itflow-billing-stat <?= $show === 'out' ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => 'out'])) ?>">
|
||||
<div class="itflow-billing-stat-label"><i class="fas fa-arrow-up me-1"></i>Money out</div>
|
||||
<div class="itflow-billing-stat-value"><?= $money($total_out) ?></div>
|
||||
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?></div>
|
||||
<div class="itflow-billing-stat-note"><?= $dated ? escapeHtml(formatExportDateRange($dtf, $dtt)) : ($all ? 'All time' : 'Since it opened') ?><?= $all ? ' - transfers between accounts left out' : '' ?></div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
@@ -428,7 +431,7 @@ $is_card = $account && $account['type'] === 3;
|
||||
<tfoot>
|
||||
<tr class="table-light">
|
||||
<td colspan="<?= 4 + ($all ? 1 : 0) ?>" class="text-body-secondary small">
|
||||
<?= intval($num_rows[0]) ?> line<?= intval($num_rows[0]) === 1 ? '' : 's' ?><?= $num_rows[0] > count($rows) ? ' - the totals are for all of them, not just this page' : '' ?>
|
||||
<?= intval($num_rows[0]) ?> line<?= intval($num_rows[0]) === 1 ? '' : 's' ?><?= $num_rows[0] > count($rows) ? ' - the totals are for all of them, not just this page' : '' ?><?= $not_transfer !== '' && !in_array($show, ['in', 'out'], true) ? ' - transfers between accounts are listed but left out of the totals' : '' ?>
|
||||
</td>
|
||||
<td class="text-end fw-semibold text-nowrap itflow-money text-success-emphasis"><?= $money($total_in) ?></td>
|
||||
<td class="text-end fw-semibold text-nowrap itflow-money"><?= $money($total_out) ?></td>
|
||||
|
||||
@@ -471,14 +471,17 @@ function accountLedgerWhat(array $row) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The ways the ledger can be cut - ?show=. Across every account a transfer
|
||||
* shows once on Transfers, from the account it left.
|
||||
* The ways the ledger can be cut - ?show=. Across every account a transfer is
|
||||
* money moved between them, not money in or out: Money in and Money out leave
|
||||
* both of its lines out, and Transfers shows it once, from the account it left.
|
||||
* On one account a transfer is money in or out of that account like any other.
|
||||
*/
|
||||
function accountLedgerShows($all_accounts = false) {
|
||||
$not_transfer = $all_accounts ? " AND ledger.txn_kind NOT IN ('transfer_in', 'transfer_out')" : '';
|
||||
return [
|
||||
'' => ['label' => 'All', 'where' => ''],
|
||||
'in' => ['label' => 'Money in', 'icon' => 'fa-arrow-down', 'where' => 'ledger.txn_amount > 0'],
|
||||
'out' => ['label' => 'Money out', 'icon' => 'fa-arrow-up', 'where' => 'ledger.txn_amount < 0'],
|
||||
'in' => ['label' => 'Money in', 'icon' => 'fa-arrow-down', 'where' => 'ledger.txn_amount > 0' . $not_transfer],
|
||||
'out' => ['label' => 'Money out', 'icon' => 'fa-arrow-up', 'where' => 'ledger.txn_amount < 0' . $not_transfer],
|
||||
'transfers' => ['label' => 'Transfers', 'icon' => 'fa-exchange-alt', 'where' => $all_accounts ? "ledger.txn_kind = 'transfer_out'" : "ledger.txn_kind IN ('transfer_in', 'transfer_out')"],
|
||||
'uncleared' => ['label' => 'Uncleared', 'icon' => 'fa-hourglass-half', 'where' => 'ledger.txn_cleared_id IS NULL'],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user