mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 07:38:29 +00:00
Fix tests
This commit is contained in:
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Requests;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class JournalFormRequest.
|
||||
@@ -237,12 +238,19 @@ class JournalFormRequest extends Request
|
||||
{
|
||||
$data = $validator->getData();
|
||||
$type = $data['what'] ?? 'invalid';
|
||||
Log::debug(sprintf('Type is %s', $type));
|
||||
if ($type === 'withdrawal') {
|
||||
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)$data['native_amount'];
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
||||
Log::debug(sprintf('Selected currency is %d, account currency is %d', $selectedCurrency, $accountCurrency));
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
) {
|
||||
Log::debug('ADD validation error on native_amount');
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -252,9 +260,12 @@ class JournalFormRequest extends Request
|
||||
if ($type === 'deposit') {
|
||||
$selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0);
|
||||
$accountCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$nativeAmount = (string)$data['native_amount'];
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric', ['attribute' => 'native_amount']));
|
||||
$nativeAmount = (string)($data['native_amount'] ?? '');
|
||||
if ($selectedCurrency !== $accountCurrency && '' === $nativeAmount
|
||||
&& $selectedCurrency !== 0
|
||||
&& $accountCurrency !== 0
|
||||
) {
|
||||
$validator->errors()->add('native_amount', trans('validation.numeric_native'));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -262,17 +273,29 @@ class JournalFormRequest extends Request
|
||||
|
||||
// and for transfers
|
||||
if ($type === 'transfer') {
|
||||
|
||||
$sourceCurrency = (int)($data['source_account_currency'] ?? 0);
|
||||
$destinationCurrency = (int)($data['destination_account_currency'] ?? 0);
|
||||
$sourceAmount = (string)$data['source_amount'];
|
||||
$destinationAmount = (string)$data['destination_amount'];
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount) {
|
||||
$validator->errors()->add('source_amount', trans('validation.numeric', ['attribute' => 'source_amount']));
|
||||
$sourceAmount = (string)($data['source_amount'] ?? '');
|
||||
$destinationAmount = (string)($data['destination_amount'] ?? '');
|
||||
|
||||
Log::debug(sprintf('Source currency is %d, destination currency is %d', $sourceCurrency, $destinationCurrency));
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $sourceAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
) {
|
||||
$validator->errors()->add('source_amount', trans('validation.numeric_source'));
|
||||
}
|
||||
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount) {
|
||||
if ($sourceCurrency !== $destinationCurrency && '' === $destinationAmount
|
||||
&& $sourceCurrency !== 0
|
||||
&& $destinationCurrency !== 0
|
||||
) {
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric_destination'));
|
||||
$validator->errors()->add('destination_amount', trans('validation.numeric', ['attribute' => 'destination_amount']));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user