Skip to content

Firefly III: a personal finances manager

Fix storing of virtual balance.

James Cole1778f0b4f3db
diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php
index 86c324f8ed..c5a1d4bdff 100644
--- a/app/Factory/AccountFactory.php
+++ b/app/Factory/AccountFactory.php
@@ -98,7 +98,7 @@ class AccountFactory
'user_id' => $this->user->id,
'account_type_id' => $type->id,
'name' => $data['name'],
- 'virtual_balance' => $data['virtual_balance'] ?? '0',
+ 'virtual_balance' => $data['virtual_balance'] ?? null,
'active' => true === $data['active'],
'iban' => $data['iban'],
];
@@ -109,12 +109,12 @@ class AccountFactory
// remove virtual balance when not an asset account or a liability
if (!in_array($type->type, $this->canHaveVirtual, true)) {
- $databaseData['virtual_balance'] = '0';
+ $databaseData['virtual_balance'] = null;
}
// fix virtual balance when it's empty
- if ('' === $databaseData['virtual_balance']) {
- $databaseData['virtual_balance'] = '0';
+ if ('' === (string)$databaseData['virtual_balance']) {
+ $databaseData['virtual_balance'] = null;
}
$return = Account::create($databaseData);
diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php
index f8389f7c2f..ed0e426bcf 100644
--- a/app/Factory/TransactionJournalFactory.php
+++ b/app/Factory/TransactionJournalFactory.php
@@ -538,15 +538,15 @@ class TransactionJournalFactory
$dataRow = $row->getArrayCopy();
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
- $json = json_encode($dataRow);
+ $json = json_encode($dataRow, JSON_THROW_ON_ERROR, 512);
if (false === $json) {
// @codeCoverageIgnoreStart
- $json = json_encode((string) microtime());
+ $json = json_encode((string) microtime(), JSON_THROW_ON_ERROR, 512);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
// @codeCoverageIgnoreEnd
}
$hash = hash('sha256', $json);
- Log::debug(sprintf('The hash is: %s', $hash));
+ Log::debug(sprintf('The hash is: %s', $hash), $dataRow);
return $hash;
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 83e756efcb..1b92e96505 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -94,12 +94,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read int|null $notes_count
* @property-read int|null $piggy_banks_count
* @property-read int|null $transactions_count
- * @property \Illuminate\Support\Carbon|null $created_at
- * @property \Illuminate\Support\Carbon|null $updated_at
- * @property int $account_type_id
- * @property bool $encrypted
- * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta
- * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks
*/
class Account extends Model
{
@@ -258,7 +252,11 @@ class Account extends Model
*/
public function setVirtualBalanceAttribute($value): void
{
- $this->attributes['virtual_balance'] = (string) $value;
+ $value = (string)$value;
+ if('' === $value) {
+ $value = null;
+ }
+ $this->attributes['virtual_balance'] = $value;
}
/**
diff --git a/app/Services/Internal/Support/JournalServiceTrait.php b/app/Services/Internal/Support/JournalServiceTrait.php
index ee7289477a..b181d2c723 100644
--- a/app/Services/Internal/Support/JournalServiceTrait.php
+++ b/app/Services/Internal/Support/JournalServiceTrait.php
@@ -359,6 +359,7 @@ trait JournalServiceTrait
'account_type_id' => null,
'account_type' => $preferredType,
'name' => $data['name'],
+ 'virtual_balance' => null,
'active' => true,
'iban' => $data['iban'],
]