mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Fix #3335 Reconciliation account currency is wrong when base account has non-default currency
This commit is contained in:
@@ -36,6 +36,7 @@ use FireflyIII\Models\TransactionType;
|
|||||||
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
|
||||||
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -473,25 +474,34 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
if (AccountType::ASSET !== $account->accountType->type) {
|
if (AccountType::ASSET !== $account->accountType->type) {
|
||||||
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
|
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
|
||||||
}
|
}
|
||||||
|
$currency = $this->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
||||||
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name]);
|
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
|
||||||
|
|
||||||
/** @var AccountType $type */
|
/** @var AccountType $type */
|
||||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||||
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get();
|
$current = $this->user->accounts()->where('account_type_id', $type->id)
|
||||||
|
->where('name', $name)
|
||||||
// TODO no longer need to loop like this
|
->first();
|
||||||
|
|
||||||
/** @var Account $current */
|
/** @var Account $current */
|
||||||
foreach ($accounts as $current) {
|
if (null !== $current) {
|
||||||
if ($current->name === $name) {
|
|
||||||
return $current;
|
return $current;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$data = [
|
||||||
|
'account_type_id' => null,
|
||||||
|
'account_type' => AccountType::RECONCILIATION,
|
||||||
|
'active' => true,
|
||||||
|
'name' => $name,
|
||||||
|
'currency_id' => $currency->id,
|
||||||
|
'currency_code' => $currency->code,
|
||||||
|
];
|
||||||
|
|
||||||
/** @var AccountFactory $factory */
|
/** @var AccountFactory $factory */
|
||||||
$factory = app(AccountFactory::class);
|
$factory = app(AccountFactory::class);
|
||||||
$factory->setUser($account->user);
|
$factory->setUser($account->user);
|
||||||
$account = $factory->findOrCreate($name, $type->type);
|
|
||||||
|
$account = $factory->create($data);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user