This commit is contained in:
James Cole 2024-01-02 22:28:58 +01:00
parent c3068d10bf
commit 98b95ab891
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
8 changed files with 75 additions and 4 deletions

View File

@ -30,6 +30,7 @@ use FireflyIII\Rules\BelongsUser;
use FireflyIII\Rules\IsBoolean;
use FireflyIII\Rules\IsDateOrTime;
use FireflyIII\Rules\IsValidPositiveAmount;
use FireflyIII\Rules\IsValidZeroOrMoreAmount;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
use FireflyIII\Validation\GroupValidation;
@ -117,7 +118,7 @@ class UpdateRequest extends FormRequest
// amount
'transactions.*.amount' => ['nullable', new IsValidPositiveAmount()],
'transactions.*.foreign_amount' => ['nullable', new IsValidPositiveAmount()],
'transactions.*.foreign_amount' => ['nullable', new IsValidZeroOrMoreAmount()],
// description
'transactions.*.description' => 'nullable|between:1,1000',

View File

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace FireflyIII\Rules;
use FireflyIII\Support\Validation\ValidatesAmountsTrait;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Log;
class IsValidZeroOrMoreAmount implements ValidationRule
{
use ValidatesAmountsTrait;
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
$value = (string)$value;
// must not be empty:
if($this->emptyString($value)) {
$fail('validation.filled')->translate();
Log::info(sprintf('IsValidZeroOrMoreAmount: "%s" cannot be empty.', $value));
return;
}
// must be a number:
if(!$this->isValidNumber($value)) {
$fail('validation.numeric')->translate();
Log::info(sprintf('IsValidZeroOrMoreAmount: "%s" is not a number.', $value));
return;
}
// must not be scientific notation:
if($this->scientificNumber($value)) {
$fail('validation.scientific_notation')->translate();
Log::info(sprintf('IsValidZeroOrMoreAmount: "%s" cannot be in the scientific notation.', $value));
return;
}
// must be more than zero:
if(!$this->zeroOrMore($value)) {
$fail('validation.more_than_zero_correct')->translate();
Log::info(sprintf('IsValidZeroOrMoreAmount: "%s" must be more than zero.', $value));
return;
}
// must be less than 100 million and 1709:
if($this->moreThanLots($value)) {
Log::info(sprintf('IsValidPositiveAmount: "%s" must be less than %s.', $value, self::BIG_AMOUNT));
$fail('validation.lte.numeric')->translate(['value' => self::BIG_AMOUNT]);
}
Log::info(sprintf('IsValidZeroOrMoreAmount: "%s" is a valid positive amount.', $value));
}
}

View File

@ -47,6 +47,11 @@ trait ValidatesAmountsTrait
return -1 === bccomp($value, '0') || 0 === bccomp($value, '0');
}
final protected function zeroOrMore(string $value): bool
{
return 1 === bccomp($value, '0') || 0 === bccomp($value, '0');
}
final protected function moreThanLots(string $value): bool
{
return 1 === bccomp($value, self::BIG_AMOUNT) || 0 === bccomp($value, self::BIG_AMOUNT);

View File

@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 6.1.4 - 2024-01-03
### Fixed
- [Issue 8328](https://github.com/firefly-iii/firefly-iii/issues/8328) Asking for non-zero foreign amount despite not being used
## 6.1.3 - 2024-01-03
### Fixed

View File

@ -114,7 +114,7 @@ return [
'handle_debts' => true,
// see cer.php for exchange rates feature flag.
],
'version' => '6.1.3',
'version' => '6.1.4',
'api_version' => '2.0.12',
'db_version' => 22,

File diff suppressed because one or more lines are too long

View File

@ -652,7 +652,7 @@ export default {
}
}
// set foreign currency info:
if (row.foreign_amount.amount !== '' && parseFloat(row.foreign_amount.amount) !== .00) {
if (row.foreign_amount.amount.toString() !== '' && parseFloat(row.foreign_amount.amount) !== .00) {
foreignAmount = row.foreign_amount.amount;
foreignCurrency = row.foreign_amount.currency_id;
}

View File

@ -35,6 +35,7 @@ return [
'iban' => 'This is not a valid IBAN.',
'zero_or_more' => 'The value cannot be negative.',
'more_than_zero' => 'The value must be more than zero.',
'more_than_zero_correct' => 'The value must be zero or more.',
'no_asset_account' => 'This is not an asset account.',
'date_or_time' => 'The value must be a valid date or time value (ISO 8601).',
'source_equals_destination' => 'The source account equals the destination account.',
@ -254,6 +255,7 @@ return [
'amount_required_for_auto_budget' => 'The amount is required.',
'auto_budget_amount_positive' => 'The amount must be more than zero.',
'auto_budget_period_mandatory' => 'The auto budget period is a mandatory field.',
// no access to administration: