Fix validation error in transaction processing.

This commit is contained in:
James Cole
2025-05-11 07:35:20 +02:00
parent 01502b456e
commit 8cad430816

View File

@@ -233,16 +233,16 @@ trait TransactionValidation
return; return;
} }
Log::debug(sprintf('Source account expects %s', $sourceCurrency->code)); Log::debug(sprintf('Source account expects #%d: %s', $sourceCurrency->id, $sourceCurrency->code));
Log::debug(sprintf('Destination account expects %s', $destinationCurrency->code)); Log::debug(sprintf('Destination account expects #%d: %s', $destinationCurrency->id, $destinationCurrency->code));
Log::debug(sprintf('Amount is %s', $transaction['amount'])); Log::debug(sprintf('Amount is %s', $transaction['amount']));
if (TransactionTypeEnum::DEPOSIT->value === ucfirst($transactionType)) { if (TransactionTypeEnum::DEPOSIT->value === ucfirst($transactionType)) {
Log::debug(sprintf('Processing as a "%s"', $transactionType)); Log::debug(sprintf('Processing as a "%s"', $transactionType));
// use case: deposit from liability account to an asset account // use case: deposit from liability account to an asset account
// the foreign amount must be in the currency of the source // the amount must be in the currency of the SOURCE
// the amount must be in the currency of the destination // the foreign amount must be in the currency of the DESTINATION
// no foreign currency information is present: // no foreign currency information is present:
if (!$this->hasForeignCurrencyInfo($transaction)) { if (!$this->hasForeignCurrencyInfo($transaction)) {
@@ -255,7 +255,7 @@ trait TransactionValidation
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false; $foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
$foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0); $foreignCurrencyId = (int) ($transaction['foreign_currency_id'] ?? 0);
Log::debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction); Log::debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
if ($foreignCurrencyCode !== $sourceCurrency->code && $foreignCurrencyId !== $sourceCurrency->id) { if ($foreignCurrencyCode !== $destinationCurrency->code && $foreignCurrencyId !== $destinationCurrency->id) {
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string) trans('validation.require_foreign_src')); $validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string) trans('validation.require_foreign_src'));
return; return;