Add running balance column.

This commit is contained in:
James Cole
2025-04-26 14:20:00 +02:00
parent 37ca460ff2
commit bd1232644f
5 changed files with 29 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ trait CollectorProperties
private HasMany $query;
private ?int $startRow;
private array $stringFields;
private array $booleanFields;
/*
* This array is used to collect ALL tags the user may search for (using 'setTags').
* This way the user can call 'setTags' multiple times and get a joined result.

View File

@@ -82,6 +82,7 @@ class GroupCollector implements GroupCollectorInterface
$this->hasJoinedAttTables = false;
$this->expandGroupSearch = false;
$this->hasJoinedMetaTables = false;
$this->booleanFields = ['balance_dirty'];
$this->integerFields = [
'transaction_group_id',
'user_id',
@@ -100,7 +101,7 @@ class GroupCollector implements GroupCollectorInterface
'category_id',
'budget_id',
];
$this->stringFields = ['amount', 'foreign_amount', 'native_amount', 'native_foreign_amount'];
$this->stringFields = ['amount', 'foreign_amount', 'native_amount', 'native_foreign_amount','balance_after'];
$this->total = 0;
$this->fields = [
// group
@@ -131,6 +132,8 @@ class GroupCollector implements GroupCollectorInterface
// currency info:
'source.amount as amount',
'source.balance_after as balance_after',
'source.balance_dirty as balance_dirty',
'source.native_amount as native_amount',
'source.transaction_currency_id as currency_id',
'currency.code as currency_code',
@@ -596,6 +599,9 @@ class GroupCollector implements GroupCollectorInterface
// convert values to integers:
$result = $this->convertToInteger($result);
// convert to boolean
$result = $this->convertToBoolean($result);
// convert back to strings because SQLite is dumb like that.
$result = $this->convertToStrings($result);
@@ -653,6 +659,15 @@ class GroupCollector implements GroupCollectorInterface
return $array;
}
private function convertToBoolean(array $array): array
{
foreach ($this->booleanFields as $field) {
$array[$field] = array_key_exists($field, $array) ? (bool) $array[$field] : null;
}
return $array;
}
private function convertToStrings(array $array): array
{
foreach ($this->stringFields as $field) {