This commit is contained in:
James Cole
2023-08-26 18:40:23 +02:00
parent 5b0637558f
commit 63297c43b7
3 changed files with 20 additions and 7 deletions

View File

@@ -114,7 +114,11 @@ trait DepositValidation
// source can be any of the following types.
$validTypes = array_keys($this->combinations[$this->transactionType]);
if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) {
if (null === $accountId &&
null === $accountName &&
null === $accountIban &&
null === $accountNumber &&
false === $this->canCreateTypes($validTypes)) {
// if both values are NULL return false,
// because the source of a deposit can't be created.
// (this never happens).
@@ -122,12 +126,12 @@ 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 revenue account, 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]);
if (null !== $existing) {
$this->destError = (string)trans('validation.deposit_src_iban_exists');
$this->sourceError = (string)trans('validation.deposit_src_iban_exists');
return false;
}
}

View File

@@ -265,6 +265,7 @@ class AccountValidator
if (null !== $accountId && $accountId > 0) {
$first = $this->accountRepository->find($accountId);
if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) {
app('log')->debug(sprintf('ID: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban'));
return $first;
}
}
@@ -273,6 +274,7 @@ class AccountValidator
if (null !== $accountIban && '' !== (string)$accountIban) {
$first = $this->accountRepository->findByIbanNull($accountIban, $validTypes);
if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) {
app('log')->debug(sprintf('Iban: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban'));
return $first;
}
}
@@ -281,14 +283,19 @@ class AccountValidator
if (null !== $accountNumber && '' !== (string)$accountNumber) {
$first = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes);
if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) {
app('log')->debug(sprintf('Number: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban'));
return $first;
}
}
// find by name:
if ('' !== (string)$accountName) {
return $this->accountRepository->findByName($accountName, $validTypes);
$first = $this->accountRepository->findByName($accountName, $validTypes);
if (null !== $first) {
app('log')->debug(sprintf('Name: Found %s account #%d ("%s", IBAN "%s")', $first->accountType->type, $first->id, $first->name, $first->iban ?? 'no iban'));
}
}
app('log')->debug('Found nothing!');
return null;
}

View File

@@ -103,6 +103,7 @@ trait TransactionValidation
*/
protected function validateSingleAccount(Validator $validator, int $index, string $transactionType, array $transaction): void
{
app('log')->debug(sprintf('Now in validateSingleAccount(%d)', $index));
/** @var AccountValidator $accountValidator */
$accountValidator = app(AccountValidator::class);
@@ -203,7 +204,8 @@ trait TransactionValidation
array $transaction,
string $transactionType,
int $index
): void {
): void
{
Log::debug('Now in sanityCheckForeignCurrency()');
if (0 !== $validator->errors()->count()) {
Log::debug('Already have errors, return');
@@ -784,8 +786,8 @@ trait TransactionValidation
private function compareAccountData(string $type, array $comparison): bool
{
return match ($type) {
default => $this->compareAccountDataWithdrawal($comparison),
'deposit' => $this->compareAccountDataDeposit($comparison),
default => $this->compareAccountDataWithdrawal($comparison),
'deposit' => $this->compareAccountDataDeposit($comparison),
'transfer' => $this->compareAccountDataTransfer($comparison),
};
}