mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 01:42:19 +00:00
Replace enum
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
@@ -46,7 +47,7 @@ class IsAssetAccountId implements ValidationRule
|
||||
|
||||
return;
|
||||
}
|
||||
if (AccountType::ASSET !== $account->accountType->type && AccountType::DEFAULT !== $account->accountType->type) {
|
||||
if (AccountTypeEnum::ASSET->value !== $account->accountType->type && AccountTypeEnum::DEFAULT->value !== $account->accountType->type) {
|
||||
$fail('validation.no_asset_account')->translate();
|
||||
}
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -49,13 +50,13 @@ class UniqueAccountNumber implements ValidationRule
|
||||
$this->expectedType = $expectedType;
|
||||
// a very basic fix to make sure we get the correct account type:
|
||||
if ('expense' === $expectedType) {
|
||||
$this->expectedType = AccountType::EXPENSE;
|
||||
$this->expectedType = AccountTypeEnum::EXPENSE->value;
|
||||
}
|
||||
if ('revenue' === $expectedType) {
|
||||
$this->expectedType = AccountType::REVENUE;
|
||||
$this->expectedType = AccountTypeEnum::REVENUE->value;
|
||||
}
|
||||
if ('asset' === $expectedType) {
|
||||
$this->expectedType = AccountType::ASSET;
|
||||
$this->expectedType = AccountTypeEnum::ASSET->value;
|
||||
}
|
||||
app('log')->debug(sprintf('Expected type is "%s"', $this->expectedType));
|
||||
}
|
||||
@@ -106,20 +107,20 @@ class UniqueAccountNumber implements ValidationRule
|
||||
private function getMaxOccurrences(): array
|
||||
{
|
||||
$maxCounts = [
|
||||
AccountType::ASSET => 0,
|
||||
AccountType::EXPENSE => 0,
|
||||
AccountType::REVENUE => 0,
|
||||
AccountTypeEnum::ASSET->value => 0,
|
||||
AccountTypeEnum::EXPENSE->value => 0,
|
||||
AccountTypeEnum::REVENUE->value => 0,
|
||||
];
|
||||
|
||||
if ('expense' === $this->expectedType || AccountType::EXPENSE === $this->expectedType) {
|
||||
if ('expense' === $this->expectedType || AccountTypeEnum::EXPENSE->value === $this->expectedType) {
|
||||
// IBAN should be unique amongst expense and asset accounts.
|
||||
// may appear once in revenue accounts
|
||||
$maxCounts[AccountType::REVENUE] = 1;
|
||||
$maxCounts[AccountTypeEnum::REVENUE->value] = 1;
|
||||
}
|
||||
if ('revenue' === $this->expectedType || AccountType::REVENUE === $this->expectedType) {
|
||||
if ('revenue' === $this->expectedType || AccountTypeEnum::REVENUE->value === $this->expectedType) {
|
||||
// IBAN should be unique amongst revenue and asset accounts.
|
||||
// may appear once in expense accounts
|
||||
$maxCounts[AccountType::EXPENSE] = 1;
|
||||
$maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
|
||||
}
|
||||
|
||||
return $maxCounts;
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules;
|
||||
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
@@ -50,16 +51,16 @@ class UniqueIban implements ValidationRule
|
||||
$this->expectedTypes = [$expectedType];
|
||||
// a very basic fix to make sure we get the correct account type:
|
||||
if ('expense' === $expectedType) {
|
||||
$this->expectedTypes = [AccountType::EXPENSE];
|
||||
$this->expectedTypes = [AccountTypeEnum::EXPENSE->value];
|
||||
}
|
||||
if ('revenue' === $expectedType) {
|
||||
$this->expectedTypes = [AccountType::REVENUE];
|
||||
$this->expectedTypes = [AccountTypeEnum::REVENUE->value];
|
||||
}
|
||||
if ('asset' === $expectedType) {
|
||||
$this->expectedTypes = [AccountType::ASSET];
|
||||
$this->expectedTypes = [AccountTypeEnum::ASSET->value];
|
||||
}
|
||||
if ('liabilities' === $expectedType) {
|
||||
$this->expectedTypes = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||
$this->expectedTypes = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,21 +124,21 @@ class UniqueIban implements ValidationRule
|
||||
private function getMaxOccurrences(): array
|
||||
{
|
||||
$maxCounts = [
|
||||
AccountType::ASSET => 0,
|
||||
AccountType::EXPENSE => 0,
|
||||
AccountType::REVENUE => 0,
|
||||
AccountTypeEnum::ASSET->value => 0,
|
||||
AccountTypeEnum::EXPENSE->value => 0,
|
||||
AccountTypeEnum::REVENUE->value => 0,
|
||||
'liabilities' => 0,
|
||||
];
|
||||
|
||||
if (in_array('expense', $this->expectedTypes, true) || in_array(AccountType::EXPENSE, $this->expectedTypes, true)) {
|
||||
if (in_array('expense', $this->expectedTypes, true) || in_array(AccountTypeEnum::EXPENSE->value, $this->expectedTypes, true)) {
|
||||
// IBAN should be unique amongst expense and asset accounts.
|
||||
// may appear once in revenue accounts
|
||||
$maxCounts[AccountType::REVENUE] = 1;
|
||||
$maxCounts[AccountTypeEnum::REVENUE->value] = 1;
|
||||
}
|
||||
if (in_array('revenue', $this->expectedTypes, true) || in_array(AccountType::REVENUE, $this->expectedTypes, true)) {
|
||||
if (in_array('revenue', $this->expectedTypes, true) || in_array(AccountTypeEnum::REVENUE->value, $this->expectedTypes, true)) {
|
||||
// IBAN should be unique amongst revenue and asset accounts.
|
||||
// may appear once in expense accounts
|
||||
$maxCounts[AccountType::EXPENSE] = 1;
|
||||
$maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
|
||||
}
|
||||
|
||||
return $maxCounts;
|
||||
@@ -147,7 +148,7 @@ class UniqueIban implements ValidationRule
|
||||
{
|
||||
$typesArray = [$type];
|
||||
if ('liabilities' === $type) {
|
||||
$typesArray = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
|
||||
$typesArray = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
||||
}
|
||||
$query
|
||||
= auth()->user()
|
||||
|
Reference in New Issue
Block a user