This commit is contained in:
James Cole
2025-08-02 19:17:37 +02:00
parent f35e361915
commit bb3b06cf08
2 changed files with 8 additions and 4 deletions

View File

@@ -96,7 +96,10 @@ class StoreRequest extends FormRequest
function (Validator $validator): void {
// validate start before end only if both are there.
$data = $validator->getData();
$currency = $this->getCurrencyFromData($data);
$currency = $this->getCurrencyFromData($validator, $data);
if(null === $currency) {
return;
}
$targetAmount = (string) ($data['target_amount'] ?? '0');
$currentAmount = '0';
if (array_key_exists('accounts', $data) && is_array($data['accounts'])) {
@@ -130,7 +133,7 @@ class StoreRequest extends FormRequest
}
}
private function getCurrencyFromData(array $data): TransactionCurrency
private function getCurrencyFromData(Validator $validator, array $data): ?TransactionCurrency
{
if (array_key_exists('transaction_currency_code', $data) && '' !== (string) $data['transaction_currency_code']) {
$currency = TransactionCurrency::whereCode($data['transaction_currency_code'])->first();
@@ -144,7 +147,7 @@ class StoreRequest extends FormRequest
return $currency;
}
}
throw new FireflyException('Unexpected empty currency.');
$validator->errors()->add('transaction_currency_id', trans('validation.require_currency_id_code'));
return null;
}
}

View File

@@ -77,6 +77,7 @@ return [
'at_least_one_repetition' => 'Need at least one repetition.',
'require_repeat_until' => 'Require either a number of repetitions, or an end date (repeat_until). Not both.',
'require_currency_info' => 'The content of this field is invalid without currency information.',
'require_currency_id_code' => 'Please set either "transaction_currency_id" or "transaction_currency_code".',
'not_transfer_account' => 'This account is not an account that can be used for transfers.',
'require_currency_amount' => 'The content of this field is invalid without foreign amount information.',
'require_foreign_currency' => 'This field requires a number',