Replace enum

This commit is contained in:
James Cole 2025-01-03 09:15:52 +01:00
parent 1787f4421b
commit a8ae496fda
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
57 changed files with 257 additions and 204 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Autocomplete; namespace FireflyIII\Api\V1\Requests\Autocomplete;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
@ -46,7 +47,7 @@ class AutocompleteRequest extends FormRequest
} }
// remove 'initial balance' from allowed types. its internal // remove 'initial balance' from allowed types. its internal
$array = array_diff($array, [AccountType::INITIAL_BALANCE, AccountType::RECONCILIATION]); $array = array_diff($array, [AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::RECONCILIATION->value]);
return [ return [
'types' => $array, 'types' => $array,

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Data\Export; namespace FireflyIII\Api\V1\Requests\Data\Export;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
@ -55,7 +56,7 @@ class ExportRequest extends FormRequest
$accountId = (int) $part; $accountId = (int) $part;
if (0 !== $accountId) { if (0 !== $accountId) {
$account = $repository->find($accountId); $account = $repository->find($accountId);
if (null !== $account && AccountType::ASSET === $account->accountType->type) { if (null !== $account && AccountTypeEnum::ASSET->value === $account->accountType->type) {
$accounts->push($account); $accounts->push($account);
} }
} }

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Insight; namespace FireflyIII\Api\V1\Requests\Insight;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -70,7 +71,7 @@ class GenericRequest extends FormRequest
/** @var Account $account */ /** @var Account $account */
foreach ($this->accounts as $account) { foreach ($this->accounts as $account) {
$type = $account->accountType->type; $type = $account->accountType->type;
if (in_array($type, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true)) { if (in_array($type, [AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value], true)) {
$return->push($account); $return->push($account);
} }
} }
@ -191,7 +192,7 @@ class GenericRequest extends FormRequest
/** @var Account $account */ /** @var Account $account */
foreach ($this->accounts as $account) { foreach ($this->accounts as $account) {
$type = $account->accountType->type; $type = $account->accountType->type;
if (AccountType::EXPENSE === $type) { if (AccountTypeEnum::EXPENSE->value === $type) {
$return->push($account); $return->push($account);
} }
} }
@ -207,7 +208,7 @@ class GenericRequest extends FormRequest
/** @var Account $account */ /** @var Account $account */
foreach ($this->accounts as $account) { foreach ($this->accounts as $account) {
$type = $account->accountType->type; $type = $account->accountType->type;
if (AccountType::REVENUE === $type) { if (AccountTypeEnum::REVENUE->value === $type) {
$return->push($account); $return->push($account);
} }
} }

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Api\V2\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\DateRequest; use FireflyIII\Api\V2\Request\Generic\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -81,7 +82,7 @@ class CategoryController extends Controller
/** @var Carbon $end */ /** @var Carbon $end */
$end = $this->parameters->get('end'); $end = $this->parameters->get('end');
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::ASSET, AccountType::DEFAULT]); $accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value]);
$default = app('amount')->getDefaultCurrency(); $default = app('amount')->getDefaultCurrency();
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$currencies = []; $currencies = [];

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\DateRequest; use FireflyIII\Api\V2\Request\Generic\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -353,7 +354,7 @@ class BasicController extends Controller
$netWorthHelper = app(NetWorthInterface::class); $netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper->setUserGroup($userGroup); $netWorthHelper->setUserGroup($userGroup);
$allAccounts = $this->accountRepository->getActiveAccountsByType( $allAccounts = $this->accountRepository->getActiveAccountsByType(
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT] [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value]
); );
// filter list on preference of being included. // filter list on preference of being included.

View File

@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\SingleDateRequest; use FireflyIII\Api\V2\Request\Generic\SingleDateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Helpers\Report\NetWorthInterface; use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -67,7 +68,7 @@ class NetWorthController extends Controller
public function get(SingleDateRequest $request): JsonResponse public function get(SingleDateRequest $request): JsonResponse
{ {
$date = $request->getDate(); $date = $request->getDate();
$accounts = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); $accounts = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
// filter list on preference of being included. // filter list on preference of being included.
$filtered = $accounts->filter( $filtered = $accounts->filter(

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Autocomplete; namespace FireflyIII\Api\V2\Request\Autocomplete;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Support\Http\Api\AccountFilter; use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
@ -65,7 +66,7 @@ class AutocompleteRequest extends FormRequest
} }
// remove 'initial balance' from allowed types. its internal // remove 'initial balance' from allowed types. its internal
$array['account_types'] = array_diff($array['account_types'], [AccountType::INITIAL_BALANCE, AccountType::RECONCILIATION, AccountType::CREDITCARD]); $array['account_types'] = array_diff($array['account_types'], [AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::RECONCILIATION->value, AccountTypeEnum::CREDITCARD->value]);
$array['account_types'] = $this->getAccountTypeParameter($array['account_types']); $array['account_types'] = $this->getAccountTypeParameter($array['account_types']);
return $array; return $array;

View File

@ -246,12 +246,12 @@ class CorrectsAccountTypes extends Command
private function shouldBeTransfer(string $transactionType, string $sourceType, string $destinationType): bool private function shouldBeTransfer(string $transactionType, string $sourceType, string $destinationType): bool
{ {
return TransactionTypeEnum::TRANSFER->value === $transactionType && AccountType::ASSET === $sourceType && $this->isLiability($destinationType); return TransactionTypeEnum::TRANSFER->value === $transactionType && AccountTypeEnum::ASSET->value === $sourceType && $this->isLiability($destinationType);
} }
private function isLiability(string $destinationType): bool private function isLiability(string $destinationType): bool
{ {
return AccountType::LOAN === $destinationType || AccountType::DEBT === $destinationType || AccountType::MORTGAGE === $destinationType; return AccountTypeEnum::LOAN->value === $destinationType || AccountTypeEnum::DEBT->value === $destinationType || AccountTypeEnum::MORTGAGE->value === $destinationType;
} }
private function makeTransfer(TransactionJournal $journal): void private function makeTransfer(TransactionJournal $journal): void
@ -269,7 +269,7 @@ class CorrectsAccountTypes extends Command
private function shouldBeDeposit(string $transactionType, string $sourceType, string $destinationType): bool private function shouldBeDeposit(string $transactionType, string $sourceType, string $destinationType): bool
{ {
return TransactionTypeEnum::TRANSFER->value === $transactionType && $this->isLiability($sourceType) && AccountType::ASSET === $destinationType; return TransactionTypeEnum::TRANSFER->value === $transactionType && $this->isLiability($sourceType) && AccountTypeEnum::ASSET->value === $destinationType;
} }
private function makeDeposit(TransactionJournal $journal): void private function makeDeposit(TransactionJournal $journal): void
@ -287,7 +287,7 @@ class CorrectsAccountTypes extends Command
private function shouldGoToExpenseAccount(string $transactionType, string $sourceType, string $destinationType): bool private function shouldGoToExpenseAccount(string $transactionType, string $sourceType, string $destinationType): bool
{ {
return TransactionTypeEnum::WITHDRAWAL->value === $transactionType && AccountType::ASSET === $sourceType && AccountType::REVENUE === $destinationType; return TransactionTypeEnum::WITHDRAWAL->value === $transactionType && AccountTypeEnum::ASSET->value === $sourceType && AccountTypeEnum::REVENUE->value === $destinationType;
} }
private function makeExpenseDestination(TransactionJournal $journal, Transaction $destination): void private function makeExpenseDestination(TransactionJournal $journal, Transaction $destination): void
@ -295,7 +295,7 @@ class CorrectsAccountTypes extends Command
// withdrawals with a revenue account as destination instead of an expense account. // withdrawals with a revenue account as destination instead of an expense account.
$this->factory->setUser($journal->user); $this->factory->setUser($journal->user);
$oldDest = $destination->account; $oldDest = $destination->account;
$result = $this->factory->findOrCreate($destination->account->name, AccountType::EXPENSE); $result = $this->factory->findOrCreate($destination->account->name, AccountTypeEnum::EXPENSE->value);
$destination->account()->associate($result); $destination->account()->associate($result);
$destination->save(); $destination->save();
$message = sprintf( $message = sprintf(
@ -313,7 +313,7 @@ class CorrectsAccountTypes extends Command
private function shouldComeFromRevenueAccount(string $transactionType, string $sourceType, string $destinationType): bool private function shouldComeFromRevenueAccount(string $transactionType, string $sourceType, string $destinationType): bool
{ {
return TransactionTypeEnum::DEPOSIT->value === $transactionType && AccountType::EXPENSE === $sourceType && AccountType::ASSET === $destinationType; return TransactionTypeEnum::DEPOSIT->value === $transactionType && AccountTypeEnum::EXPENSE->value === $sourceType && AccountTypeEnum::ASSET->value === $destinationType;
} }
private function makeRevenueSource(TransactionJournal $journal, Transaction $source): void private function makeRevenueSource(TransactionJournal $journal, Transaction $source): void
@ -321,7 +321,7 @@ class CorrectsAccountTypes extends Command
// deposits with an expense account as source instead of a revenue account. // deposits with an expense account as source instead of a revenue account.
// find revenue account. // find revenue account.
$this->factory->setUser($journal->user); $this->factory->setUser($journal->user);
$result = $this->factory->findOrCreate($source->account->name, AccountType::REVENUE); $result = $this->factory->findOrCreate($source->account->name, AccountTypeEnum::REVENUE->value);
$oldSource = $source->account; $oldSource = $source->account;
$source->account()->associate($result); $source->account()->associate($result);
$source->save(); $source->save();

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -73,7 +74,7 @@ class CorrectsFrontpageAccounts extends Command
$accountIdInt = (int) $accountId; $accountIdInt = (int) $accountId;
$account = $repository->find($accountIdInt); $account = $repository->find($accountIdInt);
if (null !== $account if (null !== $account
&& in_array($account->accountType->type, [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true) && in_array($account->accountType->type, [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value], true)
&& true === $account->active) { && true === $account->active) {
$fixed[] = $account->id; $fixed[] = $account->id;
} }

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -78,14 +79,14 @@ class CorrectsIbans extends Command
continue; continue;
} }
$type = $account->accountType->type; $type = $account->accountType->type;
if (in_array($type, [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true)) { if (in_array($type, [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value], true)) {
$type = 'liabilities'; $type = 'liabilities';
} }
if (array_key_exists($iban, $set[$userId])) { if (array_key_exists($iban, $set[$userId])) {
// iban already in use! two exceptions exist: // iban already in use! two exceptions exist:
if ( if (
!(AccountType::EXPENSE === $set[$userId][$iban] && AccountType::REVENUE === $type) // allowed combination !(AccountTypeEnum::EXPENSE->value === $set[$userId][$iban] && AccountTypeEnum::REVENUE->value === $type) // allowed combination
&& !(AccountType::REVENUE === $set[$userId][$iban] && AccountType::EXPENSE === $type) // also allowed combination. && !(AccountTypeEnum::REVENUE->value === $set[$userId][$iban] && AccountTypeEnum::EXPENSE->value === $type) // also allowed combination.
) { ) {
$this->friendlyWarning( $this->friendlyWarning(
sprintf( sprintf(

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -97,7 +98,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
/** @var null|Account $account */ /** @var null|Account $account */
$account = $transaction->account()->first(); $account = $transaction->account()->first();
if (null !== $account && AccountType::INITIAL_BALANCE !== $account->accountType()->first()->type) { if (null !== $account && AccountTypeEnum::INITIAL_BALANCE->value !== $account->accountType()->first()->type) {
return $account; return $account;
} }
} }

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Console\Commands\Export;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -229,7 +230,7 @@ class ExportsData extends Command
$final = new Collection(); $final = new Collection();
$accounts = new Collection(); $accounts = new Collection();
$accountList = (string) $this->option('accounts'); $accountList = (string) $this->option('accounts');
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
if ('' !== $accountList) { if ('' !== $accountList) {
$accountIds = explode(',', $accountList); $accountIds = explode(',', $accountList);
$accounts = $this->accountRepository->getAccountsById($accountIds); $accounts = $this->accountRepository->getAccountsById($accountIds);

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Console\Commands\Tools;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
@ -154,7 +155,7 @@ class ApplyRules extends Command
$this->ruleGroupSelection = []; $this->ruleGroupSelection = [];
$this->ruleRepository = app(RuleRepositoryInterface::class); $this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class); $this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->acceptedAccounts = [AccountType::DEFAULT, AccountType::DEBT, AccountType::ASSET, AccountType::LOAN, AccountType::MORTGAGE]; $this->acceptedAccounts = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value];
$this->groups = new Collection(); $this->groups = new Collection();
} }

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
@ -104,7 +105,7 @@ class UpgradesAccountCurrencies extends Command
private function updateCurrenciesForUser(User $user): void private function updateCurrenciesForUser(User $user): void
{ {
$this->accountRepos->setUser($user); $this->accountRepos->setUser($user);
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value]);
// get user's currency preference: // get user's currency preference:
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup); $defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -52,8 +53,8 @@ class UpgradesCreditCardLiabilities extends Command
return 0; return 0;
} }
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first(); $ccType = AccountType::where('type', AccountTypeEnum::CREDITCARD->value)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first(); $debtType = AccountType::where('type', AccountTypeEnum::DEBT->value)->first();
if (null === $ccType || null === $debtType) { if (null === $ccType || null === $debtType) {
$this->markAsExecuted(); $this->markAsExecuted();

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -198,7 +199,7 @@ class UpgradesVariousCurrencyInformation extends Command
'accounts.account_type_id', 'accounts.account_type_id',
'=', '=',
'account_types.id' 'account_types.id'
)->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']); )->where('account_types.type', '!=', AccountTypeEnum::INITIAL_BALANCE->value)->first(['transactions.*']);
break; break;
@ -209,7 +210,7 @@ class UpgradesVariousCurrencyInformation extends Command
'accounts.account_type_id', 'accounts.account_type_id',
'=', '=',
'account_types.id' 'account_types.id'
)->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']); )->where('account_types.type', '!=', AccountTypeEnum::RECONCILIATION->value)->first(['transactions.*']);
break; break;
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\StoredAccount; use FireflyIII\Events\StoredAccount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@ -242,7 +243,7 @@ class AccountFactory
$currency = $this->getCurrency($currencyId, $currencyCode); $currency = $this->getCurrency($currencyId, $currencyCode);
// only asset account may have a role: // only asset account may have a role:
if (AccountType::ASSET !== $account->accountType->type) { if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
$accountRole = ''; $accountRole = '';
} }
// only liability may have direction: // only liability may have direction:
@ -258,10 +259,10 @@ class AccountFactory
private function storeMetaData(Account $account, array $data): void private function storeMetaData(Account $account, array $data): void
{ {
$fields = $this->validFields; $fields = $this->validFields;
if (AccountType::ASSET === $account->accountType->type) { if (AccountTypeEnum::ASSET->value === $account->accountType->type) {
$fields = $this->validAssetFields; $fields = $this->validAssetFields;
} }
if (AccountType::ASSET === $account->accountType->type && 'ccAsset' === $data['account_role']) { if (AccountTypeEnum::ASSET->value === $account->accountType->type && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields; $fields = $this->validCCFields;
} }

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Helpers\Report; namespace FireflyIII\Helpers\Report;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -187,7 +188,7 @@ class NetWorth implements NetWorthInterface
private function getAccounts(): Collection private function getAccounts(): Collection
{ {
$accounts = $this->getRepository()->getAccountsByType( $accounts = $this->getRepository()->getAccountsByType(
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE] [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]
); );
$filtered = new Collection(); $filtered = new Collection();

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Account; namespace FireflyIII\Http\Controllers\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
@ -149,7 +150,7 @@ class CreateController extends Controller
if (!is_array($frontpage)) { if (!is_array($frontpage)) {
$frontpage = []; $frontpage = [];
} }
if (AccountType::ASSET === $account->accountType->type) { if (AccountTypeEnum::ASSET->value === $account->accountType->type) {
$frontpage[] = $account->id; $frontpage[] = $account->id;
app('preferences')->set('frontpageAccounts', $frontpage); app('preferences')->set('frontpageAccounts', $frontpage);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Account; namespace FireflyIII\Http\Controllers\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -82,7 +83,7 @@ class ReconcileController extends Controller
if (!$this->isEditableAccount($account)) { if (!$this->isEditableAccount($account)) {
return $this->redirectAccountToAccount($account); return $this->redirectAccountToAccount($account);
} }
if (AccountType::ASSET !== $account->accountType->type) { if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
session()->flash('error', (string) trans('firefly.must_be_asset_account')); session()->flash('error', (string) trans('firefly.must_be_asset_account'));
return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))])); return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))]));

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Http\Middleware\IsDemoUser;
@ -352,7 +353,7 @@ class DebugController extends Controller
$user = auth()->user(); $user = auth()->user();
// has liabilities // has liabilities
if ($user->accounts()->accountTypeIn([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->count() > 0) { if ($user->accounts()->accountTypeIn([AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value])->count() > 0) {
$flags[] = '<span title="Has liabilities">:credit_card:</span>'; $flags[] = '<span title="Has liabilities">:credit_card:</span>';
} }

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException; use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\RequestedVersionCheckStatus; use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -145,7 +146,7 @@ class HomeController extends Controller
$count = $repository->count($types); $count = $repository->count($types);
$subTitle = (string) trans('firefly.welcome_back'); $subTitle = (string) trans('firefly.welcome_back');
$transactions = []; $transactions = [];
$frontpage = app('preferences')->getFresh('frontpageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray()); $frontpage = app('preferences')->getFresh('frontpageAccounts', $repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray());
$frontpageArray = $frontpage->data; $frontpageArray = $frontpage->data;
if (!is_array($frontpageArray)) { if (!is_array($frontpageArray)) {
$frontpageArray = []; $frontpageArray = [];

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -47,7 +48,7 @@ class JavascriptController extends Controller
public function accounts(AccountRepositoryInterface $repository): Response public function accounts(AccountRepositoryInterface $repository): Response
{ {
$accounts = $repository->getAccountsByType( $accounts = $repository->getAccountsByType(
[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD] [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::CREDITCARD->value]
); );
$data = ['accounts' => []]; $data = ['accounts' => []];

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json; namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface; use FireflyIII\Helpers\Report\NetWorthInterface;
@ -163,7 +164,7 @@ class BoxController extends Controller
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$allAccounts = $accountRepository->getActiveAccountsByType( $allAccounts = $accountRepository->getActiveAccountsByType(
[AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE] [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]
); );
app('log')->debug(sprintf('Found %d accounts.', $allAccounts->count())); app('log')->debug(sprintf('Found %d accounts.', $allAccounts->count()));

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\NewUserFormRequest; use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -114,7 +115,7 @@ class NewUserController extends Controller
$currencyRepository->makeDefault($currency); $currencyRepository->makeDefault($currency);
// store frontpage preferences: // store frontpage preferences:
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); $accounts = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
app('preferences')->set('frontpageAccounts', $accounts); app('preferences')->set('frontpageAccounts', $accounts);
// mark. // mark.

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency; use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency;
use FireflyIII\Events\Test\UserTestNotificationChannel; use FireflyIII\Events\Test\UserTestNotificationChannel;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -70,7 +71,7 @@ class PreferencesController extends Controller
*/ */
public function index(AccountRepositoryInterface $repository) public function index(AccountRepositoryInterface $repository)
{ {
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); $accounts = $repository->getAccountsByType([AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$isDocker = env('IS_DOCKER', false); $isDocker = env('IS_DOCKER', false);
$groupedAccounts = []; $groupedAccounts = [];
@ -79,7 +80,7 @@ class PreferencesController extends Controller
$type = $account->accountType->type; $type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role')); $role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) { if (in_array($type, [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value], true)) {
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers; namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Report\ReportGeneratorFactory; use FireflyIII\Generator\Report\ReportGeneratorFactory;
use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Helpers\Report\ReportHelperInterface;
@ -242,7 +243,7 @@ class ReportController extends Controller
$months = $this->helper->listOfMonths($start); $months = $this->helper->listOfMonths($start);
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data; $customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$accounts = $repository->getAccountsByType( $accounts = $repository->getAccountsByType(
[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE] [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value]
); );
// group accounts by role: // group accounts by role:
@ -253,7 +254,7 @@ class ReportController extends Controller
$type = $account->accountType->type; $type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role')); $role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) { if (in_array($type, [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value], true)) {
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction; namespace FireflyIII\Http\Controllers\Transaction;
use Exception; use Exception;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -140,9 +141,9 @@ class ConvertController extends Controller
private function getValidDepositSources(): array private function getValidDepositSources(): array
{ {
// make repositories // make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; $liabilityTypes = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value];
$accountList = $this->accountRepository $accountList = $this->accountRepository
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]) ->getActiveAccountsByType([AccountTypeEnum::REVENUE->value, AccountTypeEnum::CASH->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value])
; ;
$grouped = []; $grouped = [];
@ -159,11 +160,11 @@ class ConvertController extends Controller
if (in_array($account->accountType->type, $liabilityTypes, true)) { if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_'.$account->accountType->type; $role = 'l_'.$account->accountType->type;
} }
if (AccountType::CASH === $account->accountType->type) { if (AccountTypeEnum::CASH->value === $account->accountType->type) {
$role = 'cash_account'; $role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash')); $name = sprintf('(%s)', trans('firefly.cash'));
} }
if (AccountType::REVENUE === $account->accountType->type) { if (AccountTypeEnum::REVENUE->value === $account->accountType->type) {
$role = 'revenue_account'; $role = 'revenue_account';
} }
@ -177,9 +178,9 @@ class ConvertController extends Controller
private function getValidWithdrawalDests(): array private function getValidWithdrawalDests(): array
{ {
// make repositories // make repositories
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; $liabilityTypes = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value];
$accountList = $this->accountRepository->getActiveAccountsByType( $accountList = $this->accountRepository->getActiveAccountsByType(
[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE] [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::CASH->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]
); );
$grouped = []; $grouped = [];
@ -196,11 +197,11 @@ class ConvertController extends Controller
if (in_array($account->accountType->type, $liabilityTypes, true)) { if (in_array($account->accountType->type, $liabilityTypes, true)) {
$role = 'l_'.$account->accountType->type; $role = 'l_'.$account->accountType->type;
} }
if (AccountType::CASH === $account->accountType->type) { if (AccountTypeEnum::CASH->value === $account->accountType->type) {
$role = 'cash_account'; $role = 'cash_account';
$name = sprintf('(%s)', trans('firefly.cash')); $name = sprintf('(%s)', trans('firefly.cash'));
} }
if (AccountType::EXPENSE === $account->accountType->type) { if (AccountTypeEnum::EXPENSE->value === $account->accountType->type) {
$role = 'expense_account'; $role = 'expense_account';
} }
@ -217,7 +218,7 @@ class ConvertController extends Controller
private function getLiabilities(): array private function getLiabilities(): array
{ {
// make repositories // make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); $accountList = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$grouped = []; $grouped = [];
// group accounts: // group accounts:
@ -239,7 +240,7 @@ class ConvertController extends Controller
private function getAssetAccounts(): array private function getAssetAccounts(): array
{ {
// make repositories // make repositories
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]); $accountList = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::ASSET->value]);
$grouped = []; $grouped = [];
// group accounts: // group accounts:

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction; namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -132,7 +133,7 @@ class MassController extends Controller
$withdrawalSources = $accountRepository->getAccountsByType($array); $withdrawalSources = $accountRepository->getAccountsByType($array);
// valid deposit destinations: // valid deposit destinations:
$array = config(sprintf('firefly.source_dests.%s.%s', TransactionTypeEnum::DEPOSIT->value, AccountType::REVENUE)); $array = config(sprintf('firefly.source_dests.%s.%s', TransactionTypeEnum::DEPOSIT->value, AccountTypeEnum::REVENUE->value));
$depositDestinations = $accountRepository->getAccountsByType($array); $depositDestinations = $accountRepository->getAccountsByType($array);
/** @var BudgetRepositoryInterface $budgetRepository */ /** @var BudgetRepositoryInterface $budgetRepository */

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait; use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait;
use FireflyIII\User; use FireflyIII\User;
@ -131,7 +132,7 @@ class Account extends Model
{ {
$name = $this->name; $name = $this->name;
if (AccountType::CASH === $this->accountType->type) { if (AccountTypeEnum::CASH->value === $this->accountType->type) {
return ''; return '';
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
@ -228,7 +229,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getCashAccount(): Account public function getCashAccount(): Account
{ {
/** @var AccountType $type */ /** @var AccountType $type */
$type = AccountType::where('type', AccountType::CASH)->first(); $type = AccountType::where('type', AccountTypeEnum::CASH->value)->first();
/** @var AccountFactory $factory */ /** @var AccountFactory $factory */
$factory = app(AccountFactory::class); $factory = app(AccountFactory::class);
@ -348,14 +349,14 @@ class AccountRepository implements AccountRepositoryInterface
*/ */
public function getReconciliation(Account $account): ?Account public function getReconciliation(Account $account): ?Account
{ {
if (AccountType::ASSET !== $account->accountType->type) { if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
throw new FireflyException(sprintf('%s is not an asset account.', $account->name)); throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
} }
$currency = $this->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $currency = $this->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]); $name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
/** @var AccountType $type */ /** @var AccountType $type */
$type = AccountType::where('type', AccountType::RECONCILIATION)->first(); $type = AccountType::where('type', AccountTypeEnum::RECONCILIATION->value)->first();
/** @var null|Account $current */ /** @var null|Account $current */
$current = $this->user->accounts()->where('account_type_id', $type->id) $current = $this->user->accounts()->where('account_type_id', $type->id)
@ -369,7 +370,7 @@ class AccountRepository implements AccountRepositoryInterface
$data = [ $data = [
'account_type_id' => null, 'account_type_id' => null,
'account_type_name' => AccountType::RECONCILIATION, 'account_type_name' => AccountTypeEnum::RECONCILIATION->value,
'active' => true, 'active' => true,
'name' => $name, 'name' => $name,
'currency_id' => $currency->id, 'currency_id' => $currency->id,
@ -444,18 +445,18 @@ class AccountRepository implements AccountRepositoryInterface
public function isLiability(Account $account): bool public function isLiability(Account $account): bool
{ {
return in_array($account->accountType->type, [AccountType::CREDITCARD, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true); return in_array($account->accountType->type, [AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value], true);
} }
public function maxOrder(string $type): int public function maxOrder(string $type): int
{ {
$sets = [ $sets = [
AccountType::ASSET => [AccountType::DEFAULT, AccountType::ASSET], AccountTypeEnum::ASSET->value => [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
AccountType::EXPENSE => [AccountType::EXPENSE, AccountType::BENEFICIARY], AccountTypeEnum::EXPENSE->value => [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
AccountType::REVENUE => [AccountType::REVENUE], AccountTypeEnum::REVENUE->value => [AccountTypeEnum::REVENUE->value],
AccountType::LOAN => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], AccountTypeEnum::LOAN->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
AccountType::DEBT => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], AccountTypeEnum::DEBT->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
AccountType::MORTGAGE => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], AccountTypeEnum::MORTGAGE->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
]; ];
if (array_key_exists(ucfirst($type), $sets)) { if (array_key_exists(ucfirst($type), $sets)) {
$order = (int) $this->getAccountsByType($sets[ucfirst($type)])->max('order'); $order = (int) $this->getAccountsByType($sets[ucfirst($type)])->max('order');
@ -463,7 +464,7 @@ class AccountRepository implements AccountRepositoryInterface
return $order; return $order;
} }
$specials = [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION]; $specials = [AccountTypeEnum::CASH->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value];
$order = (int) $this->getAccountsByType($specials)->max('order'); $order = (int) $this->getAccountsByType($specials)->max('order');
app('log')->debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order)); app('log')->debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order));
@ -473,7 +474,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountsByType(array $types, ?array $sort = []): Collection public function getAccountsByType(array $types, ?array $sort = []): Collection
{ {
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types); $res = array_intersect([AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], $types);
$query = $this->user->accounts(); $query = $this->user->accounts();
if (0 !== count($types)) { if (0 !== count($types)) {
$query->accountTypeIn($types); $query->accountTypeIn($types);
@ -531,11 +532,11 @@ class AccountRepository implements AccountRepositoryInterface
public function resetAccountOrder(): void public function resetAccountOrder(): void
{ {
$sets = [ $sets = [
[AccountType::DEFAULT, AccountType::ASSET], [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
// [AccountType::EXPENSE, AccountType::BENEFICIARY], // [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
// [AccountType::REVENUE], // [AccountTypeEnum::REVENUE->value],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
// [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION], // [AccountTypeEnum::CASH->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value],
]; ];
foreach ($sets as $set) { foreach ($sets as $set) {
$list = $this->getAccountsByType($set); $list = $this->getAccountsByType($set);
@ -555,7 +556,7 @@ class AccountRepository implements AccountRepositoryInterface
} }
} }
// reset the rest to zero. // reset the rest to zero.
$all = [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE]; $all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value];
$this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') $this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereNotIn('account_types.type', $all) ->whereNotIn('account_types.type', $all)
->update(['order' => 0]) ->update(['order' => 0])

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Account; namespace FireflyIII\Repositories\UserGroups\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -287,8 +288,8 @@ class AccountRepository implements AccountRepositoryInterface
public function resetAccountOrder(): void public function resetAccountOrder(): void
{ {
$sets = [ $sets = [
[AccountType::DEFAULT, AccountType::ASSET], [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE], [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
]; ];
foreach ($sets as $set) { foreach ($sets as $set) {
$list = $this->getAccountsByType($set); $list = $this->getAccountsByType($set);
@ -308,7 +309,7 @@ class AccountRepository implements AccountRepositoryInterface
} }
} }
// reset the rest to zero. // reset the rest to zero.
$all = [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE]; $all = [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value];
$this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') $this->user->accounts()->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereNotIn('account_types.type', $all) ->whereNotIn('account_types.type', $all)
->update(['order' => 0]) ->update(['order' => 0])
@ -318,7 +319,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection
{ {
$sortable = ['name', 'active']; // TODO yes this is a duplicate array. $sortable = ['name', 'active']; // TODO yes this is a duplicate array.
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types); $res = array_intersect([AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], $types);
$query = $this->userGroup->accounts(); $query = $this->userGroup->accounts();
if (0 !== count($types)) { if (0 !== count($types)) {
$query->accountTypeIn($types); $query->accountTypeIn($types);

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules; namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Contracts\Validation\ValidationRule;
@ -46,7 +47,7 @@ class IsAssetAccountId implements ValidationRule
return; 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(); $fail('validation.no_asset_account')->translate();
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules; namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -49,13 +50,13 @@ class UniqueAccountNumber implements ValidationRule
$this->expectedType = $expectedType; $this->expectedType = $expectedType;
// a very basic fix to make sure we get the correct account type: // a very basic fix to make sure we get the correct account type:
if ('expense' === $expectedType) { if ('expense' === $expectedType) {
$this->expectedType = AccountType::EXPENSE; $this->expectedType = AccountTypeEnum::EXPENSE->value;
} }
if ('revenue' === $expectedType) { if ('revenue' === $expectedType) {
$this->expectedType = AccountType::REVENUE; $this->expectedType = AccountTypeEnum::REVENUE->value;
} }
if ('asset' === $expectedType) { if ('asset' === $expectedType) {
$this->expectedType = AccountType::ASSET; $this->expectedType = AccountTypeEnum::ASSET->value;
} }
app('log')->debug(sprintf('Expected type is "%s"', $this->expectedType)); app('log')->debug(sprintf('Expected type is "%s"', $this->expectedType));
} }
@ -106,20 +107,20 @@ class UniqueAccountNumber implements ValidationRule
private function getMaxOccurrences(): array private function getMaxOccurrences(): array
{ {
$maxCounts = [ $maxCounts = [
AccountType::ASSET => 0, AccountTypeEnum::ASSET->value => 0,
AccountType::EXPENSE => 0, AccountTypeEnum::EXPENSE->value => 0,
AccountType::REVENUE => 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. // IBAN should be unique amongst expense and asset accounts.
// may appear once in revenue 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. // IBAN should be unique amongst revenue and asset accounts.
// may appear once in expense accounts // may appear once in expense accounts
$maxCounts[AccountType::EXPENSE] = 1; $maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
} }
return $maxCounts; return $maxCounts;

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules; namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Support\Facades\Steam; use FireflyIII\Support\Facades\Steam;
@ -50,16 +51,16 @@ class UniqueIban implements ValidationRule
$this->expectedTypes = [$expectedType]; $this->expectedTypes = [$expectedType];
// a very basic fix to make sure we get the correct account type: // a very basic fix to make sure we get the correct account type:
if ('expense' === $expectedType) { if ('expense' === $expectedType) {
$this->expectedTypes = [AccountType::EXPENSE]; $this->expectedTypes = [AccountTypeEnum::EXPENSE->value];
} }
if ('revenue' === $expectedType) { if ('revenue' === $expectedType) {
$this->expectedTypes = [AccountType::REVENUE]; $this->expectedTypes = [AccountTypeEnum::REVENUE->value];
} }
if ('asset' === $expectedType) { if ('asset' === $expectedType) {
$this->expectedTypes = [AccountType::ASSET]; $this->expectedTypes = [AccountTypeEnum::ASSET->value];
} }
if ('liabilities' === $expectedType) { 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 private function getMaxOccurrences(): array
{ {
$maxCounts = [ $maxCounts = [
AccountType::ASSET => 0, AccountTypeEnum::ASSET->value => 0,
AccountType::EXPENSE => 0, AccountTypeEnum::EXPENSE->value => 0,
AccountType::REVENUE => 0, AccountTypeEnum::REVENUE->value => 0,
'liabilities' => 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. // IBAN should be unique amongst expense and asset accounts.
// may appear once in revenue 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. // IBAN should be unique amongst revenue and asset accounts.
// may appear once in expense accounts // may appear once in expense accounts
$maxCounts[AccountType::EXPENSE] = 1; $maxCounts[AccountTypeEnum::EXPENSE->value] = 1;
} }
return $maxCounts; return $maxCounts;
@ -147,7 +148,7 @@ class UniqueIban implements ValidationRule
{ {
$typesArray = [$type]; $typesArray = [$type];
if ('liabilities' === $type) { if ('liabilities' === $type) {
$typesArray = [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $typesArray = [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
} }
$query $query
= auth()->user() = auth()->user()

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support; namespace FireflyIII\Services\Internal\Support;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Factory\AccountMetaFactory;
@ -96,7 +97,7 @@ trait AccountServiceTrait
public function updateMetaData(Account $account, array $data): void public function updateMetaData(Account $account, array $data): void
{ {
$fields = $this->validFields; $fields = $this->validFields;
if (AccountType::ASSET === $account->accountType->type) { if (AccountTypeEnum::ASSET->value === $account->accountType->type) {
$fields = $this->validAssetFields; $fields = $this->validAssetFields;
} }
@ -119,11 +120,11 @@ trait AccountServiceTrait
} }
// only asset account may have a role: // only asset account may have a role:
if (AccountType::ASSET !== $account->accountType->type) { if (AccountTypeEnum::ASSET->value !== $account->accountType->type) {
$data['account_role'] = ''; $data['account_role'] = '';
} }
if (AccountType::ASSET === $account->accountType->type && 'ccAsset' === $data['account_role']) { if (AccountTypeEnum::ASSET->value === $account->accountType->type && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields; $fields = $this->validCCFields;
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support; namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory; use FireflyIII\Factory\AccountMetaFactory;
@ -258,7 +259,7 @@ trait JournalServiceTrait
} }
if (null === $account) { if (null === $account) {
// final attempt, create it. // final attempt, create it.
if (AccountType::ASSET === $preferredType) { if (AccountTypeEnum::ASSET->value === $preferredType) {
throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data))); throw new FireflyException(sprintf('TransactionFactory: Cannot create asset account with these values: %s', json_encode($data)));
} }
// fix name of account if only IBAN is given: // fix name of account if only IBAN is given:
@ -312,7 +313,7 @@ trait JournalServiceTrait
{ {
// return cash account. // return cash account.
if (null === $account && '' === (string) $data['name'] if (null === $account && '' === (string) $data['name']
&& in_array(AccountType::CASH, $types, true)) { && in_array(AccountTypeEnum::CASH->value, $types, true)) {
$account = $this->accountRepository->getCashAccount(); $account = $this->accountRepository->getCashAccount();
} }
app('log')->debug('Cannot return cash account, return input instead.'); app('log')->debug('Cannot return cash account, return input instead.');

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support; namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\BillFactory; use FireflyIII\Factory\BillFactory;
@ -189,7 +190,7 @@ trait RecurringTransactionTrait
} }
// maybe we can create it? Try to avoid LOAN and other asset types. // maybe we can create it? Try to avoid LOAN and other asset types.
$cannotCreate = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]; $cannotCreate = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::CREDITCARD->value];
/** @var AccountFactory $factory */ /** @var AccountFactory $factory */
$factory = app(AccountFactory::class); $factory = app(AccountFactory::class);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update; namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\UpdatedAccount; use FireflyIII\Events\UpdatedAccount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@ -153,7 +154,7 @@ class AccountUpdateService
{ {
$type = $account->accountType->type; $type = $account->accountType->type;
return in_array($type, [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true); return in_array($type, [AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value], true);
} }
private function getAccountType(string $type): AccountType private function getAccountType(string $type): AccountType
@ -171,7 +172,7 @@ class AccountUpdateService
} }
// skip if not of orderable type. // skip if not of orderable type.
$type = $account->accountType->type; $type = $account->accountType->type;
if (!in_array($type, [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], true)) { if (!in_array($type, [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value], true)) {
app('log')->debug('Will not change order of this account.'); app('log')->debug('Will not change order of this account.');
return $account; return $account;
@ -180,9 +181,9 @@ class AccountUpdateService
$oldOrder = $account->order; $oldOrder = $account->order;
$newOrder = $data['order']; $newOrder = $data['order'];
app('log')->debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder)); app('log')->debug(sprintf('Order is set to be updated from %s to %s', $oldOrder, $newOrder));
$list = $this->getTypeIds([AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT]); $list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
if (AccountType::ASSET === $type) { if (AccountTypeEnum::ASSET->value === $type) {
$list = $this->getTypeIds([AccountType::ASSET]); $list = $this->getTypeIds([AccountTypeEnum::ASSET->value]);
} }
if ($newOrder > $oldOrder) { if ($newOrder > $oldOrder) {

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder; namespace FireflyIII\Support\Binder;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Routing\Route; use Illuminate\Routing\Route;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -44,7 +45,7 @@ class AccountList implements BinderInterface
/** @var Collection $collection */ /** @var Collection $collection */
$collection = auth()->user()->accounts() $collection = auth()->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereIn('account_types.type', [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]) ->whereIn('account_types.type', [AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value])
->orderBy('accounts.name', 'ASC') ->orderBy('accounts.name', 'ASC')
->get(['accounts.*']) ->get(['accounts.*'])
; ;

View File

@ -47,7 +47,7 @@ class AccountForm
*/ */
public function activeDepositDestinations(string $name, mixed $value = null, ?array $options = null): string public function activeDepositDestinations(string $name, mixed $value = null, ?array $options = null): string
{ {
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::REVENUE]; $types = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::REVENUE->value];
$repository = $this->getAccountRepository(); $repository = $this->getAccountRepository();
$grouped = $this->getAccountsGrouped($types, $repository); $grouped = $this->getAccountsGrouped($types, $repository);
$cash = $repository->getCashAccount(); $cash = $repository->getCashAccount();
@ -63,7 +63,7 @@ class AccountForm
$repository = $this->getAccountRepository(); $repository = $this->getAccountRepository();
} }
$accountList = $repository->getActiveAccountsByType($types); $accountList = $repository->getActiveAccountsByType($types);
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN]; $liabilityTypes = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value];
$grouped = []; $grouped = [];
/** @var Account $account */ /** @var Account $account */
@ -74,10 +74,10 @@ class AccountForm
} }
if ('' === $role) { if ('' === $role) {
$role = 'no_account_type'; $role = 'no_account_type';
if (AccountType::EXPENSE === $account->accountType->type) { if (AccountTypeEnum::EXPENSE->value === $account->accountType->type) {
$role = 'expense_account'; $role = 'expense_account';
} }
if (AccountType::REVENUE === $account->accountType->type) { if (AccountTypeEnum::REVENUE->value === $account->accountType->type) {
$role = 'revenue_account'; $role = 'revenue_account';
} }
} }
@ -93,7 +93,7 @@ class AccountForm
*/ */
public function activeWithdrawalDestinations(string $name, mixed $value = null, ?array $options = null): string public function activeWithdrawalDestinations(string $name, mixed $value = null, ?array $options = null): string
{ {
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::EXPENSE]; $types = [AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::EXPENSE->value];
$repository = $this->getAccountRepository(); $repository = $this->getAccountRepository();
$grouped = $this->getAccountsGrouped($types, $repository); $grouped = $this->getAccountsGrouped($types, $repository);
@ -118,7 +118,7 @@ class AccountForm
$selected = request()->old($name) ?? []; $selected = request()->old($name) ?? [];
// get all asset accounts: // get all asset accounts:
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::DEBT]; $types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value];
$grouped = $this->getAccountsGrouped($types); $grouped = $this->getAccountsGrouped($types);
unset($options['class']); unset($options['class']);
@ -168,7 +168,7 @@ class AccountForm
*/ */
public function longAccountList(string $name, $value = null, ?array $options = null): string public function longAccountList(string $name, $value = null, ?array $options = null): string
{ {
$types = [AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN]; $types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value];
$grouped = $this->getAccountsGrouped($types); $grouped = $this->getAccountsGrouped($types);
return $this->select($name, $grouped, $value, $options); return $this->select($name, $grouped, $value, $options);

View File

@ -36,53 +36,53 @@ trait AccountFilter
= [ = [
'all' => [ 'all' => [
AccountTypeEnum::DEFAULT->value, AccountTypeEnum::DEFAULT->value,
AccountType::CASH, AccountTypeEnum::CASH->value,
AccountType::ASSET, AccountTypeEnum::ASSET->value,
AccountType::EXPENSE, AccountTypeEnum::EXPENSE->value,
AccountType::REVENUE, AccountTypeEnum::REVENUE->value,
AccountType::INITIAL_BALANCE, AccountTypeEnum::INITIAL_BALANCE->value,
AccountType::BENEFICIARY, AccountTypeEnum::BENEFICIARY->value,
AccountType::IMPORT, AccountTypeEnum::IMPORT->value,
AccountType::RECONCILIATION, AccountTypeEnum::RECONCILIATION->value,
AccountType::LOAN, AccountTypeEnum::LOAN->value,
AccountType::DEBT, AccountTypeEnum::DEBT->value,
AccountType::MORTGAGE, AccountTypeEnum::MORTGAGE->value,
], ],
'asset' => [AccountType::DEFAULT, AccountType::ASSET], 'asset' => [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
'cash' => [AccountType::CASH], 'cash' => [AccountTypeEnum::CASH->value],
'expense' => [AccountType::EXPENSE, AccountType::BENEFICIARY], 'expense' => [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
'revenue' => [AccountType::REVENUE], 'revenue' => [AccountTypeEnum::REVENUE->value],
'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION], 'special' => [AccountTypeEnum::CASH->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value],
'hidden' => [AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION], 'hidden' => [AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value],
'liability' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD], 'liability' => [AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::CREDITCARD->value],
'liabilities' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD], 'liabilities' => [AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::CREDITCARD->value],
AccountType::DEFAULT => [AccountType::DEFAULT], AccountTypeEnum::DEFAULT->value => [AccountTypeEnum::DEFAULT->value],
AccountType::CASH => [AccountType::CASH], AccountTypeEnum::CASH->value => [AccountTypeEnum::CASH->value],
AccountType::ASSET => [AccountType::ASSET], AccountTypeEnum::ASSET->value => [AccountTypeEnum::ASSET->value],
AccountType::EXPENSE => [AccountType::EXPENSE], AccountTypeEnum::EXPENSE->value => [AccountTypeEnum::EXPENSE->value],
AccountType::REVENUE => [AccountType::REVENUE], AccountTypeEnum::REVENUE->value => [AccountTypeEnum::REVENUE->value],
AccountType::INITIAL_BALANCE => [AccountType::INITIAL_BALANCE], AccountTypeEnum::INITIAL_BALANCE->value => [AccountTypeEnum::INITIAL_BALANCE->value],
AccountType::BENEFICIARY => [AccountType::BENEFICIARY], AccountTypeEnum::BENEFICIARY->value => [AccountTypeEnum::BENEFICIARY->value],
AccountType::IMPORT => [AccountType::IMPORT], AccountTypeEnum::IMPORT->value => [AccountTypeEnum::IMPORT->value],
AccountType::RECONCILIATION => [AccountType::RECONCILIATION], AccountTypeEnum::RECONCILIATION->value => [AccountTypeEnum::RECONCILIATION->value],
AccountType::LOAN => [AccountType::LOAN], AccountTypeEnum::LOAN->value => [AccountTypeEnum::LOAN->value],
AccountType::MORTGAGE => [AccountType::MORTGAGE], AccountTypeEnum::MORTGAGE->value => [AccountTypeEnum::MORTGAGE->value],
AccountType::DEBT => [AccountType::DEBT], AccountTypeEnum::DEBT->value => [AccountTypeEnum::DEBT->value],
AccountType::CREDITCARD => [AccountType::CREDITCARD], AccountTypeEnum::CREDITCARD->value => [AccountTypeEnum::CREDITCARD->value],
'default account' => [AccountType::DEFAULT], 'default account' => [AccountTypeEnum::DEFAULT->value],
'cash account' => [AccountType::CASH], 'cash account' => [AccountTypeEnum::CASH->value],
'asset account' => [AccountType::ASSET], 'asset account' => [AccountTypeEnum::ASSET->value],
'expense account' => [AccountType::EXPENSE], 'expense account' => [AccountTypeEnum::EXPENSE->value],
'revenue account' => [AccountType::REVENUE], 'revenue account' => [AccountTypeEnum::REVENUE->value],
'initial balance account' => [AccountType::INITIAL_BALANCE], 'initial balance account' => [AccountTypeEnum::INITIAL_BALANCE->value],
'reconciliation' => [AccountType::RECONCILIATION], 'reconciliation' => [AccountTypeEnum::RECONCILIATION->value],
'loan' => [AccountType::LOAN], 'loan' => [AccountTypeEnum::LOAN->value],
'mortgage' => [AccountType::MORTGAGE], 'mortgage' => [AccountTypeEnum::MORTGAGE->value],
'debt' => [AccountType::DEBT], 'debt' => [AccountTypeEnum::DEBT->value],
'credit card' => [AccountType::CREDITCARD], 'credit card' => [AccountTypeEnum::CREDITCARD->value],
'credit-card' => [AccountType::CREDITCARD], 'credit-card' => [AccountTypeEnum::CREDITCARD->value],
'creditcard' => [AccountType::CREDITCARD], 'creditcard' => [AccountTypeEnum::CREDITCARD->value],
'cc' => [AccountType::CREDITCARD], 'cc' => [AccountTypeEnum::CREDITCARD->value],
]; ];
/** /**

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Api; namespace FireflyIII\Support\Http\Api;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -52,7 +53,7 @@ trait CollectsAccountsFromFilter
} }
// if no preselected, but no accounts: // if no preselected, but no accounts:
if ('empty' === $queryParameters['preselected'] && 0 === $collection->count()) { if ('empty' === $queryParameters['preselected'] && 0 === $collection->count()) {
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray(); $defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value])->pluck('id')->toArray();
$frontpage = app('preferences')->get('frontpageAccounts', $defaultSet); $frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) { if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
@ -65,13 +66,13 @@ trait CollectsAccountsFromFilter
// both options are overruled by "preselected" // both options are overruled by "preselected"
if ('all' === $queryParameters['preselected']) { if ('all' === $queryParameters['preselected']) {
return $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); return $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
} }
if ('assets' === $queryParameters['preselected']) { if ('assets' === $queryParameters['preselected']) {
return $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]); return $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value]);
} }
if ('liabilities' === $queryParameters['preselected']) { if ('liabilities' === $queryParameters['preselected']) {
return $this->repository->getAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); return $this->repository->getAccountsByType([AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
} }
return $collection; return $collection;

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers; namespace FireflyIII\Support\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@ -59,7 +60,7 @@ trait AugumentData
$collection = new Collection(); $collection = new Collection();
$collection->push($expenseAccount); $collection->push($expenseAccount);
$revenue = $repository->findByName($expenseAccount->name, [AccountType::REVENUE]); $revenue = $repository->findByName($expenseAccount->name, [AccountTypeEnum::REVENUE->value]);
if (null !== $revenue) { if (null !== $revenue) {
$collection->push($revenue); $collection->push($revenue);
} }
@ -106,7 +107,7 @@ trait AugumentData
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$accounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::EXPENSE, AccountType::CASH]); $accounts = $repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::CASH->value]);
$grouped = $accounts->groupBy('id')->toArray(); $grouped = $accounts->groupBy('id')->toArray();
$return = []; $return = [];
foreach ($accountIds as $combinedId) { foreach ($accountIds as $combinedId) {

View File

@ -78,13 +78,13 @@ trait ModelInformation
// types of liability: // types of liability:
/** @var AccountType $debt */ /** @var AccountType $debt */
$debt = $repository->getAccountTypeByType(AccountType::DEBT); $debt = $repository->getAccountTypeByType(AccountTypeEnum::DEBT->value);
/** @var AccountType $loan */ /** @var AccountType $loan */
$loan = $repository->getAccountTypeByType(AccountType::LOAN); $loan = $repository->getAccountTypeByType(AccountTypeEnum::LOAN->value);
/** @var AccountType $mortgage */ /** @var AccountType $mortgage */
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE); $mortgage = $repository->getAccountTypeByType(AccountTypeEnum::MORTGAGE->value);
$liabilityTypes = [ $liabilityTypes = [
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::DEBT->value)), $debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::DEBT->value)),
$loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::LOAN->value)), $loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::LOAN->value)),

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers; namespace FireflyIII\Support\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\PopupReportInterface; use FireflyIII\Helpers\Report\PopupReportInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@ -192,8 +193,8 @@ trait RenderPartialViews
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
$expense = $repository->getActiveAccountsByType([AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); $expense = $repository->getActiveAccountsByType([AccountTypeEnum::EXPENSE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$revenue = $repository->getActiveAccountsByType([AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]); $revenue = $repository->getActiveAccountsByType([AccountTypeEnum::REVENUE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$set = []; $set = [];
/** @var Account $account */ /** @var Account $account */

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers; namespace FireflyIII\Support\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -61,7 +62,7 @@ trait UserNavigation
*/ */
final protected function isEditableAccount(Account $account): bool final protected function isEditableAccount(Account $account): bool
{ {
$editable = [AccountType::EXPENSE, AccountType::REVENUE, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $editable = [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::ASSET->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
$type = $account->accountType->type; $type = $account->accountType->type;
return in_array($type, $editable, true); return in_array($type, $editable, true);
@ -86,7 +87,7 @@ trait UserNavigation
final protected function redirectAccountToAccount(Account $account) final protected function redirectAccountToAccount(Account $account)
{ {
$type = $account->accountType->type; $type = $account->accountType->type;
if (AccountType::RECONCILIATION === $type || AccountType::INITIAL_BALANCE === $type || AccountType::LIABILITY_CREDIT === $type) { if (AccountTypeEnum::RECONCILIATION->value === $type || AccountTypeEnum::INITIAL_BALANCE->value === $type || AccountTypeEnum::LIABILITY_CREDIT->value === $type) {
// reconciliation must be stored somewhere in this account's transactions. // reconciliation must be stored somewhere in this account's transactions.
/** @var null|Transaction $transaction */ /** @var null|Transaction $transaction */
@ -128,7 +129,7 @@ trait UserNavigation
} }
// prefer redirect to everything but expense and revenue: // prefer redirect to everything but expense and revenue:
$transactions = $journal->transactions; $transactions = $journal->transactions;
$ignore = [AccountType::REVENUE, AccountType::EXPENSE, AccountType::RECONCILIATION, AccountType::INITIAL_BALANCE]; $ignore = [AccountTypeEnum::REVENUE->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::RECONCILIATION->value, AccountTypeEnum::INITIAL_BALANCE->value];
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search; namespace FireflyIII\Support\Search;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\SearchDirection; use FireflyIII\Enums\SearchDirection;
use FireflyIII\Enums\StringPosition; use FireflyIII\Enums\StringPosition;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@ -1938,7 +1939,7 @@ class OperatorQuerySearch implements SearchInterface
app('log')->debug(sprintf('searchAccount("%s", %s, %s)', $value, $stringPosition->name, $searchDirection->name)); app('log')->debug(sprintf('searchAccount("%s", %s, %s)', $value, $stringPosition->name, $searchDirection->name));
// search direction (default): for source accounts // search direction (default): for source accounts
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setSourceAccounts'; $collectorMethod = 'setSourceAccounts';
if ($prohibited) { if ($prohibited) {
$collectorMethod = 'excludeSourceAccounts'; $collectorMethod = 'excludeSourceAccounts';
@ -1947,7 +1948,7 @@ class OperatorQuerySearch implements SearchInterface
// search direction: for destination accounts // search direction: for destination accounts
if (SearchDirection::DESTINATION === $searchDirection) { // destination if (SearchDirection::DESTINATION === $searchDirection) { // destination
// destination can be // destination can be
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
$collectorMethod = 'setDestinationAccounts'; $collectorMethod = 'setDestinationAccounts';
if ($prohibited) { if ($prohibited) {
$collectorMethod = 'excludeDestinationAccounts'; $collectorMethod = 'excludeDestinationAccounts';
@ -1955,7 +1956,7 @@ class OperatorQuerySearch implements SearchInterface
} }
// either account could be: // either account could be:
if (SearchDirection::BOTH === $searchDirection) { if (SearchDirection::BOTH === $searchDirection) {
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE, AccountType::REVENUE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setAccounts'; $collectorMethod = 'setAccounts';
if ($prohibited) { if ($prohibited) {
$collectorMethod = 'excludeAccounts'; $collectorMethod = 'excludeAccounts';
@ -2018,7 +2019,7 @@ class OperatorQuerySearch implements SearchInterface
app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection->name, $stringPosition->name)); app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection->name, $stringPosition->name));
// search direction (default): for source accounts // search direction (default): for source accounts
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::REVENUE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setSourceAccounts'; $collectorMethod = 'setSourceAccounts';
if (true === $prohibited) { if (true === $prohibited) {
$collectorMethod = 'excludeSourceAccounts'; $collectorMethod = 'excludeSourceAccounts';
@ -2027,7 +2028,7 @@ class OperatorQuerySearch implements SearchInterface
// search direction: for destination accounts // search direction: for destination accounts
if (SearchDirection::DESTINATION === $searchDirection) { if (SearchDirection::DESTINATION === $searchDirection) {
// destination can be // destination can be
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
$collectorMethod = 'setDestinationAccounts'; $collectorMethod = 'setDestinationAccounts';
if (true === $prohibited) { if (true === $prohibited) {
$collectorMethod = 'excludeDestinationAccounts'; $collectorMethod = 'excludeDestinationAccounts';
@ -2036,7 +2037,7 @@ class OperatorQuerySearch implements SearchInterface
// either account could be: // either account could be:
if (SearchDirection::BOTH === $searchDirection) { if (SearchDirection::BOTH === $searchDirection) {
$searchTypes = [AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT, AccountType::EXPENSE, AccountType::REVENUE]; $searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setAccounts'; $collectorMethod = 'setAccounts';
if (true === $prohibited) { if (true === $prohibited) {
$collectorMethod = 'excludeAccounts'; $collectorMethod = 'excludeAccounts';

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig; namespace FireflyIII\Support\Twig;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@ -103,12 +104,12 @@ class TransactionGroupTwig extends AbstractExtension
} }
// opening balance and it comes from initial balance? its expense. // opening balance and it comes from initial balance? its expense.
if (TransactionTypeEnum::OPENING_BALANCE->value === $transactionType && AccountType::INITIAL_BALANCE !== $sourceType) { if (TransactionTypeEnum::OPENING_BALANCE->value === $transactionType && AccountTypeEnum::INITIAL_BALANCE->value !== $sourceType) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }
// reconciliation and it comes from reconciliation? // reconciliation and it comes from reconciliation?
if (TransactionTypeEnum::RECONCILIATION->value === $transactionType && AccountType::RECONCILIATION !== $sourceType) { if (TransactionTypeEnum::RECONCILIATION->value === $transactionType && AccountTypeEnum::RECONCILIATION->value !== $sourceType) {
$amount = bcmul($amount, '-1'); $amount = bcmul($amount, '-1');
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions; namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray; use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog; use FireflyIII\Events\TriggeredAuditLog;
@ -148,7 +149,7 @@ class ConvertToDeposit implements ActionInterface
$validTypes = config('firefly.expected_source_types.source.Deposit'); $validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes); $opposingAccount = $repository->findByName($opposingName, $validTypes);
if (null === $opposingAccount) { if (null === $opposingAccount) {
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::REVENUE); $opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::REVENUE->value);
} }
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $actionValue, $opposingAccount->name)); app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $actionValue, $opposingAccount->name));
@ -236,7 +237,7 @@ class ConvertToDeposit implements ActionInterface
$validTypes = config('firefly.expected_source_types.source.Deposit'); $validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes); $opposingAccount = $repository->findByName($opposingName, $validTypes);
if (null === $opposingAccount) { if (null === $opposingAccount) {
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::REVENUE); $opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::REVENUE->value);
} }
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $actionValue, $opposingAccount->name)); app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $actionValue, $opposingAccount->name));

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions; namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray; use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog; use FireflyIII\Events\TriggeredAuditLog;
@ -142,7 +143,7 @@ class ConvertToWithdrawal implements ActionInterface
$validTypes = config('firefly.expected_source_types.destination.Withdrawal'); $validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes); $opposingAccount = $repository->findByName($opposingName, $validTypes);
if (null === $opposingAccount) { if (null === $opposingAccount) {
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::EXPENSE); $opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::EXPENSE->value);
} }
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $actionValue, $opposingName)); app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $actionValue, $opposingName));
@ -228,7 +229,7 @@ class ConvertToWithdrawal implements ActionInterface
$validTypes = config('firefly.expected_source_types.destination.Withdrawal'); $validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes); $opposingAccount = $repository->findByName($opposingName, $validTypes);
if (null === $opposingAccount) { if (null === $opposingAccount) {
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::EXPENSE); $opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::EXPENSE->value);
} }
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $actionValue, $opposingName)); app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $actionValue, $opposingName));

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account; namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -173,7 +174,7 @@ trait DepositValidation
// set the source to be a (dummy) revenue account. // set the source to be a (dummy) revenue account.
$account = new Account(); $account = new Account();
$accountType = AccountType::whereType(AccountType::REVENUE)->first(); $accountType = AccountType::whereType(AccountTypeEnum::REVENUE->value)->first();
$account->accountType = $accountType; $account->accountType = $accountType;
$this->setSource($account); $this->setSource($account);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account; namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -43,7 +44,7 @@ trait LiabilityValidation
// if the ID is not null the source account should be a dummy account of the type liability credit. // if the ID is not null the source account should be a dummy account of the type liability credit.
// the ID of the destination must belong to a liability. // the ID of the destination must belong to a liability.
if (null !== $accountId) { if (null !== $accountId) {
if (AccountType::LIABILITY_CREDIT !== $this->source?->accountType?->type) { if (AccountTypeEnum::LIABILITY_CREDIT->value !== $this->source?->accountType?->type) {
app('log')->error('Source account is not a liability.'); app('log')->error('Source account is not a liability.');
return false; return false;
@ -104,7 +105,7 @@ trait LiabilityValidation
app('log')->error('Array has a name, return true.'); app('log')->error('Array has a name, return true.');
// set the source to be a (dummy) revenue account. // set the source to be a (dummy) revenue account.
$account = new Account(); $account = new Account();
$accountType = AccountType::whereType(AccountType::LIABILITY_CREDIT)->first(); $accountType = AccountType::whereType(AccountTypeEnum::LIABILITY_CREDIT->value)->first();
$account->accountType = $accountType; $account->accountType = $accountType;
$this->setSource($account); $this->setSource($account);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account; namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -126,7 +127,7 @@ trait OBValidation
$account = new Account(); $account = new Account();
/** @var AccountType $accountType */ /** @var AccountType $accountType */
$accountType = AccountType::whereType(AccountType::INITIAL_BALANCE)->first(); $accountType = AccountType::whereType(AccountTypeEnum::INITIAL_BALANCE->value)->first();
$account->accountType = $accountType; $account->accountType = $accountType;
$this->setSource($account); $this->setSource($account);
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account; namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@ -39,7 +40,7 @@ trait WithdrawalValidation
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null; $accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
app('log')->debug('Now in validateGenericSource', $array); app('log')->debug('Now in validateGenericSource', $array);
// source can be any of the following types. // source can be any of the following types.
$validTypes = [AccountType::ASSET, AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]; $validTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) { if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
// if both values are NULL we return TRUE // if both values are NULL we return TRUE
// because we assume the user doesn't want to submit / change anything. // because we assume the user doesn't want to submit / change anything.

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation; namespace FireflyIII\Validation;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
@ -316,12 +317,12 @@ class FireflyValidator extends Validator
$account = $repository->findByName( $account = $repository->findByName(
$value, $value,
[ [
AccountType::DEFAULT, AccountTypeEnum::DEFAULT->value,
AccountType::ASSET, AccountTypeEnum::ASSET->value,
AccountType::LOAN, AccountTypeEnum::LOAN->value,
AccountType::DEBT, AccountTypeEnum::DEBT->value,
AccountType::MORTGAGE, AccountTypeEnum::MORTGAGE->value,
AccountType::CREDITCARD, AccountTypeEnum::CREDITCARD->value,
] ]
); );

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation; namespace FireflyIII\Validation;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@ -308,7 +309,7 @@ trait TransactionValidation
{ {
$type = $account->accountType->type; $type = $account->accountType->type;
return AccountType::ASSET === $type; return AccountTypeEnum::ASSET->value === $type;
} }
private function hasForeignCurrencyInfo(array $transaction): bool private function hasForeignCurrencyInfo(array $transaction): bool