mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Fix #3135
This commit is contained in:
@@ -40,17 +40,16 @@ class AccountUpdateService
|
|||||||
|
|
||||||
/** @var AccountRepositoryInterface */
|
/** @var AccountRepositoryInterface */
|
||||||
protected $accountRepository;
|
protected $accountRepository;
|
||||||
/** @var array */
|
|
||||||
private $canHaveVirtual;
|
|
||||||
/** @var User */
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];
|
protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];
|
||||||
|
/** @var array */
|
||||||
|
private $canHaveVirtual;
|
||||||
|
/** @var User */
|
||||||
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -81,7 +80,13 @@ class AccountUpdateService
|
|||||||
// update the account itself:
|
// update the account itself:
|
||||||
$account->name = $data['name'] ?? $account->name;
|
$account->name = $data['name'] ?? $account->name;
|
||||||
$account->active = $data['active'] ?? $account->active;
|
$account->active = $data['active'] ?? $account->active;
|
||||||
$account->iban = $data['iban'] ?? $account->iban;
|
$account->iban = $data['iban'] ?? $account->iban;
|
||||||
|
|
||||||
|
// if account type is a liability, the liability type (account type)
|
||||||
|
// can be updated to another one.
|
||||||
|
if ($this->isLiability($account) && $this->isLiabilityTypeId((int)($data['account_type_id'] ?? 0))) {
|
||||||
|
$account->account_type_id = (int)$data['account_type_id'];
|
||||||
|
}
|
||||||
|
|
||||||
// update virtual balance (could be set to zero if empty string).
|
// update virtual balance (could be set to zero if empty string).
|
||||||
if (null !== $data['virtual_balance']) {
|
if (null !== $data['virtual_balance']) {
|
||||||
@@ -118,8 +123,8 @@ class AccountUpdateService
|
|||||||
$location->locatable()->associate($account);
|
$location->locatable()->associate($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
$location->latitude = $data['latitude'] ?? config('firefly.default_location.latitude');
|
||||||
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
$location->longitude = $data['longitude'] ?? config('firefly.default_location.longitude');
|
||||||
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
$location->zoom_level = $data['zoom_level'] ?? config('firefly.default_location.zoom_level');
|
||||||
$location->save();
|
$location->save();
|
||||||
}
|
}
|
||||||
@@ -147,4 +152,30 @@ class AccountUpdateService
|
|||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isLiability(Account $account): bool
|
||||||
|
{
|
||||||
|
$type = $account->accountType->type;
|
||||||
|
|
||||||
|
return in_array($type, [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $accountTypeId
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isLiabilityTypeId(int $accountTypeId): bool
|
||||||
|
{
|
||||||
|
if (0 === $accountTypeId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1 === AccountType::whereIn('type', [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->where('id', $accountTypeId)->count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user