mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Better currency validation for foreign amount
This commit is contained in:
parent
292b9ac9d0
commit
01c4d25646
@ -50,19 +50,19 @@ trait CurrencyValidation
|
|||||||
if (!is_array($transaction)) {
|
if (!is_array($transaction)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!array_key_exists('foreign_amount', $transaction)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$foreignAmount = '';
|
||||||
|
if (array_key_exists('foreign_amount', $transaction)) {
|
||||||
|
$foreignAmount = (string) $transaction['foreign_amount'];
|
||||||
|
}
|
||||||
|
if('' === $foreignAmount) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// if foreign amount is present, then the currency must be as well.
|
// if foreign amount is present, then the currency must be as well.
|
||||||
if (array_key_exists('foreign_amount', $transaction)
|
if (!(array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction)) && 0 !== bccomp('0', $transaction['foreign_amount'])) {
|
||||||
&& !(array_key_exists('foreign_currency_id', $transaction)
|
$validator->errors()->add('transactions.' . $index . '.foreign_amount', (string) trans('validation.require_currency_info'));
|
||||||
|| array_key_exists(
|
|
||||||
'foreign_currency_code',
|
|
||||||
$transaction
|
|
||||||
))
|
|
||||||
&& 0 !== bccomp('0', $transaction['foreign_amount'])
|
|
||||||
) {
|
|
||||||
$validator->errors()->add(
|
|
||||||
'transactions.'.$index.'.foreign_amount',
|
|
||||||
(string)trans('validation.require_currency_info')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// if the currency is present, then the amount must be present as well.
|
// if the currency is present, then the amount must be present as well.
|
||||||
if ((array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
|
if ((array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
|
||||||
|
Loading…
Reference in New Issue
Block a user