mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
This commit is contained in:
@@ -126,10 +126,10 @@ trait DepositValidation
|
||||
$result = false;
|
||||
}
|
||||
|
||||
// if there is an iban, it can only be in use by a revenue account, or we will fail.
|
||||
// if there is an iban, it can only be in use by a valid source type, or we will fail.
|
||||
if (null !== $accountIban && '' !== $accountIban) {
|
||||
app('log')->debug('Check if there is not already an account with this IBAN');
|
||||
$existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
|
||||
$existing = $this->findExistingAccount($validTypes, ['iban' => $accountIban], true);
|
||||
if (null !== $existing) {
|
||||
$this->sourceError = (string)trans('validation.deposit_src_iban_exists');
|
||||
return false;
|
||||
|
@@ -90,13 +90,15 @@ trait WithdrawalValidation
|
||||
*/
|
||||
protected function validateWithdrawalDestination(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
Log::debug('Now in validateWithdrawalDestination()', $array);
|
||||
// source can be any of the following types.
|
||||
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
app('log')->debug('Source type can be: ', $validTypes);
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && null === $accountNumber && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL return false,
|
||||
// because the destination of a withdrawal can never be created automatically.
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_need_data');
|
||||
@@ -113,15 +115,18 @@ trait WithdrawalValidation
|
||||
$this->setDestination($found);
|
||||
return true;
|
||||
}
|
||||
// todo explain error in log message.
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// if there is an iban, it can only be in use by a revenue account or we will fail.
|
||||
// if there is an iban, it can only be in use by a valid destination type, or we will fail.
|
||||
// the inverse of $validTypes is
|
||||
if (null !== $accountIban && '' !== $accountIban) {
|
||||
app('log')->debug('Check if there is not already an account with this IBAN');
|
||||
$existing = $this->findExistingAccount([AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], ['iban' => $accountIban]);
|
||||
// the inverse flag reverses the search, searching for everything that is NOT a valid type.
|
||||
$existing = $this->findExistingAccount($validTypes, ['iban' => $accountIban], true);
|
||||
if (null !== $existing) {
|
||||
$this->destError = (string)trans('validation.withdrawal_dest_iban_exists');
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user