From f83ab0a7dc08845230e563e53a30517d87936b06 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 1 Jun 2022 19:23:40 +0200 Subject: [PATCH] Fix sqlite issues. --- .../Extensions/CollectorProperties.php | 1 + app/Helpers/Collector/GroupCollector.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Helpers/Collector/Extensions/CollectorProperties.php b/app/Helpers/Collector/Extensions/CollectorProperties.php index 544478e881..39c8e50b6a 100644 --- a/app/Helpers/Collector/Extensions/CollectorProperties.php +++ b/app/Helpers/Collector/Extensions/CollectorProperties.php @@ -33,6 +33,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; trait CollectorProperties { private array $fields; + private array $stringFields; private bool $hasAccountInfo; private bool $hasBillInformation; private bool $hasBudgetInformation; diff --git a/app/Helpers/Collector/GroupCollector.php b/app/Helpers/Collector/GroupCollector.php index 358914c74a..b36f9c251b 100644 --- a/app/Helpers/Collector/GroupCollector.php +++ b/app/Helpers/Collector/GroupCollector.php @@ -87,6 +87,7 @@ class GroupCollector implements GroupCollectorInterface 'category_id', 'budget_id', ]; + $this->stringFields = ['amount', 'foreign_amount']; $this->total = 0; $this->fields = [ # group @@ -375,6 +376,9 @@ class GroupCollector implements GroupCollectorInterface // convert values to integers: $result = $this->convertToInteger($result); + // convert back to strings because SQLite is dumb like that. + $result = $this->convertToStrings($result); + $result['reconciled'] = 1 === (int) $result['reconciled']; if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well. $tagId = (int) $augumentedJournal['tag_id']; @@ -506,7 +510,7 @@ class GroupCollector implements GroupCollectorInterface $groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['currency_decimal_places']; $groups[$groudId]['sums'][$currencyId]['amount'] = '0'; } - $groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], (string)($transaction['amount'] ?? '0')); + $groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']); if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) { $currencyId = (int) $transaction['foreign_currency_id']; @@ -815,4 +819,17 @@ class GroupCollector implements GroupCollectorInterface return $this; } + + /** + * @param array $array + * @return array + */ + private function convertToStrings(array $array): array + { + foreach ($this->stringFields as $field) { + $array[$field] = array_key_exists($field, $array) ? (string) $array[$field] : '0'; + } + + return $array; + } }