Fix sqlite issues.

This commit is contained in:
James Cole
2022-06-01 19:23:40 +02:00
parent ced55b5065
commit f83ab0a7dc
2 changed files with 19 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;
}
}