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;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
@ -46,7 +47,7 @@ class AutocompleteRequest extends FormRequest
}
// 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 [
'types' => $array,

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Data\Export;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Request\ChecksLogin;
@ -55,7 +56,7 @@ class ExportRequest extends FormRequest
$accountId = (int) $part;
if (0 !== $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);
}
}

View File

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

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Api\V2\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -81,7 +82,7 @@ class CategoryController extends Controller
/** @var Carbon $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();
$converter = new ExchangeRateConverter();
$currencies = [];

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
use Carbon\Carbon;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -353,7 +354,7 @@ class BasicController extends Controller
$netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper->setUserGroup($userGroup);
$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.

View File

@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Summary;
use FireflyIII\Api\V2\Controllers\Controller;
use FireflyIII\Api\V2\Request\Generic\SingleDateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -67,7 +68,7 @@ class NetWorthController extends Controller
public function get(SingleDateRequest $request): JsonResponse
{
$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.
$filtered = $accounts->filter(

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Autocomplete;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Request\ChecksLogin;
@ -65,7 +66,7 @@ class AutocompleteRequest extends FormRequest
}
// 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']);
return $array;

View File

@ -246,12 +246,12 @@ class CorrectsAccountTypes extends Command
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
{
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
@ -269,7 +269,7 @@ class CorrectsAccountTypes extends Command
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
@ -287,7 +287,7 @@ class CorrectsAccountTypes extends Command
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
@ -295,7 +295,7 @@ class CorrectsAccountTypes extends Command
// withdrawals with a revenue account as destination instead of an expense account.
$this->factory->setUser($journal->user);
$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->save();
$message = sprintf(
@ -313,7 +313,7 @@ class CorrectsAccountTypes extends Command
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
@ -321,7 +321,7 @@ class CorrectsAccountTypes extends Command
// deposits with an expense account as source instead of a revenue account.
// find revenue account.
$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;
$source->account()->associate($result);
$source->save();

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -73,7 +74,7 @@ class CorrectsFrontpageAccounts extends Command
$accountIdInt = (int) $accountId;
$account = $repository->find($accountIdInt);
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) {
$fixed[] = $account->id;
}

View File

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

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -97,7 +98,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
foreach ($transactions as $transaction) {
/** @var null|Account $account */
$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;
}
}

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Console\Commands\Export;
use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -229,7 +230,7 @@ class ExportsData extends Command
$final = new Collection();
$accounts = new Collection();
$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) {
$accountIds = explode(',', $accountList);
$accounts = $this->accountRepository->getAccountsById($accountIds);

View File

@ -27,6 +27,7 @@ namespace FireflyIII\Console\Commands\Tools;
use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Rule;
@ -154,7 +155,7 @@ class ApplyRules extends Command
$this->ruleGroupSelection = [];
$this->ruleRepository = app(RuleRepositoryInterface::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();
}

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
@ -104,7 +105,7 @@ class UpgradesAccountCurrencies extends Command
private function updateCurrenciesForUser(User $user): void
{
$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:
$defaultCurrency = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);

View File

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

View File

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

View File

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

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Helpers\Report;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -187,7 +188,7 @@ class NetWorth implements NetWorthInterface
private function getAccounts(): Collection
{
$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();

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Account;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException;
@ -82,7 +83,7 @@ class ReconcileController extends Controller
if (!$this->isEditableAccount($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'));
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;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser;
@ -352,7 +353,7 @@ class DebugController extends Controller
$user = auth()->user();
// 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>';
}

View File

@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@ -145,7 +146,7 @@ class HomeController extends Controller
$count = $repository->count($types);
$subTitle = (string) trans('firefly.welcome_back');
$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;
if (!is_array($frontpageArray)) {
$frontpageArray = [];

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -47,7 +48,7 @@ class JavascriptController extends Controller
public function accounts(AccountRepositoryInterface $repository): Response
{
$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' => []];

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface;
@ -163,7 +164,7 @@ class BoxController extends Controller
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$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()));

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Requests\NewUserFormRequest;
use FireflyIII\Models\AccountType;
@ -114,7 +115,7 @@ class NewUserController extends Controller
$currencyRepository->makeDefault($currency);
// 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);
// mark.

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency;
use FireflyIII\Events\Test\UserTestNotificationChannel;
use FireflyIII\Exceptions\FireflyException;
@ -70,7 +71,7 @@ class PreferencesController extends Controller
*/
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);
$groupedAccounts = [];
@ -79,7 +80,7 @@ class PreferencesController extends Controller
$type = $account->accountType->type;
$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);
}

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Report\ReportGeneratorFactory;
use FireflyIII\Helpers\Report\ReportHelperInterface;
@ -242,7 +243,7 @@ class ReportController extends Controller
$months = $this->helper->listOfMonths($start);
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$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:
@ -253,7 +254,7 @@ class ReportController extends Controller
$type = $account->accountType->type;
$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);
}

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
@ -132,7 +133,7 @@ class MassController extends Controller
$withdrawalSources = $accountRepository->getAccountsByType($array);
// 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);
/** @var BudgetRepositoryInterface $budgetRepository */

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
@ -228,7 +229,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getCashAccount(): Account
{
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::CASH)->first();
$type = AccountType::where('type', AccountTypeEnum::CASH->value)->first();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -348,14 +349,14 @@ class AccountRepository implements AccountRepositoryInterface
*/
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));
}
$currency = $this->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
/** @var AccountType $type */
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
$type = AccountType::where('type', AccountTypeEnum::RECONCILIATION->value)->first();
/** @var null|Account $current */
$current = $this->user->accounts()->where('account_type_id', $type->id)
@ -369,7 +370,7 @@ class AccountRepository implements AccountRepositoryInterface
$data = [
'account_type_id' => null,
'account_type_name' => AccountType::RECONCILIATION,
'account_type_name' => AccountTypeEnum::RECONCILIATION->value,
'active' => true,
'name' => $name,
'currency_id' => $currency->id,
@ -444,18 +445,18 @@ class AccountRepository implements AccountRepositoryInterface
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
{
$sets = [
AccountType::ASSET => [AccountType::DEFAULT, AccountType::ASSET],
AccountType::EXPENSE => [AccountType::EXPENSE, AccountType::BENEFICIARY],
AccountType::REVENUE => [AccountType::REVENUE],
AccountType::LOAN => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
AccountType::DEBT => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
AccountType::MORTGAGE => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
AccountTypeEnum::ASSET->value => [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
AccountTypeEnum::EXPENSE->value => [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
AccountTypeEnum::REVENUE->value => [AccountTypeEnum::REVENUE->value],
AccountTypeEnum::LOAN->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
AccountTypeEnum::DEBT->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
AccountTypeEnum::MORTGAGE->value => [AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
];
if (array_key_exists(ucfirst($type), $sets)) {
$order = (int) $this->getAccountsByType($sets[ucfirst($type)])->max('order');
@ -463,7 +464,7 @@ class AccountRepository implements AccountRepositoryInterface
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');
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
{
$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();
if (0 !== count($types)) {
$query->accountTypeIn($types);
@ -531,11 +532,11 @@ class AccountRepository implements AccountRepositoryInterface
public function resetAccountOrder(): void
{
$sets = [
[AccountType::DEFAULT, AccountType::ASSET],
// [AccountType::EXPENSE, AccountType::BENEFICIARY],
// [AccountType::REVENUE],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
// [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
[AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
// [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
// [AccountTypeEnum::REVENUE->value],
[AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
// [AccountTypeEnum::CASH->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value],
];
foreach ($sets as $set) {
$list = $this->getAccountsByType($set);
@ -555,7 +556,7 @@ class AccountRepository implements AccountRepositoryInterface
}
}
// 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')
->whereNotIn('account_types.type', $all)
->update(['order' => 0])

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroups\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
@ -287,8 +288,8 @@ class AccountRepository implements AccountRepositoryInterface
public function resetAccountOrder(): void
{
$sets = [
[AccountType::DEFAULT, AccountType::ASSET],
[AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
[AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
[AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
];
foreach ($sets as $set) {
$list = $this->getAccountsByType($set);
@ -308,7 +309,7 @@ class AccountRepository implements AccountRepositoryInterface
}
}
// 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')
->whereNotIn('account_types.type', $all)
->update(['order' => 0])
@ -318,7 +319,7 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountsByType(array $types, ?array $sort = [], ?array $filters = []): Collection
{
$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();
if (0 !== count($types)) {
$query->accountTypeIn($types);

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Rules;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use Illuminate\Contracts\Validation\ValidationRule;
@ -46,7 +47,7 @@ class IsAssetAccountId implements ValidationRule
return;
}
if (AccountType::ASSET !== $account->accountType->type && AccountType::DEFAULT !== $account->accountType->type) {
if (AccountTypeEnum::ASSET->value !== $account->accountType->type && AccountTypeEnum::DEFAULT->value !== $account->accountType->type) {
$fail('validation.no_asset_account')->translate();
}
}

View File

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

View File

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

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountMetaFactory;
@ -258,7 +259,7 @@ trait JournalServiceTrait
}
if (null === $account) {
// 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)));
}
// fix name of account if only IBAN is given:
@ -312,7 +313,7 @@ trait JournalServiceTrait
{
// return cash account.
if (null === $account && '' === (string) $data['name']
&& in_array(AccountType::CASH, $types, true)) {
&& in_array(AccountTypeEnum::CASH->value, $types, true)) {
$account = $this->accountRepository->getCashAccount();
}
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;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\BillFactory;
@ -189,7 +190,7 @@ trait RecurringTransactionTrait
}
// 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 */
$factory = app(AccountFactory::class);

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\UpdatedAccount;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
@ -153,7 +154,7 @@ class AccountUpdateService
{
$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
@ -171,7 +172,7 @@ class AccountUpdateService
}
// skip if not of orderable 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.');
return $account;
@ -180,9 +181,9 @@ class AccountUpdateService
$oldOrder = $account->order;
$newOrder = $data['order'];
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]);
if (AccountType::ASSET === $type) {
$list = $this->getTypeIds([AccountType::ASSET]);
$list = $this->getTypeIds([AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value]);
if (AccountTypeEnum::ASSET->value === $type) {
$list = $this->getTypeIds([AccountTypeEnum::ASSET->value]);
}
if ($newOrder > $oldOrder) {

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
@ -44,7 +45,7 @@ class AccountList implements BinderInterface
/** @var Collection $collection */
$collection = auth()->user()->accounts()
->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')
->get(['accounts.*'])
;

View File

@ -47,7 +47,7 @@ class AccountForm
*/
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();
$grouped = $this->getAccountsGrouped($types, $repository);
$cash = $repository->getCashAccount();
@ -63,7 +63,7 @@ class AccountForm
$repository = $this->getAccountRepository();
}
$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 = [];
/** @var Account $account */
@ -74,10 +74,10 @@ class AccountForm
}
if ('' === $role) {
$role = 'no_account_type';
if (AccountType::EXPENSE === $account->accountType->type) {
if (AccountTypeEnum::EXPENSE->value === $account->accountType->type) {
$role = 'expense_account';
}
if (AccountType::REVENUE === $account->accountType->type) {
if (AccountTypeEnum::REVENUE->value === $account->accountType->type) {
$role = 'revenue_account';
}
}
@ -93,7 +93,7 @@ class AccountForm
*/
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();
$grouped = $this->getAccountsGrouped($types, $repository);
@ -118,7 +118,7 @@ class AccountForm
$selected = request()->old($name) ?? [];
// 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);
unset($options['class']);
@ -168,7 +168,7 @@ class AccountForm
*/
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);
return $this->select($name, $grouped, $value, $options);

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Api;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\AccountType;
use Illuminate\Support\Collection;
@ -52,7 +53,7 @@ trait CollectsAccountsFromFilter
}
// if no preselected, but no accounts:
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);
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
@ -65,13 +66,13 @@ trait CollectsAccountsFromFilter
// both options are overruled by "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']) {
return $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
return $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value]);
}
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;

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Account;
@ -59,7 +60,7 @@ trait AugumentData
$collection = new Collection();
$collection->push($expenseAccount);
$revenue = $repository->findByName($expenseAccount->name, [AccountType::REVENUE]);
$revenue = $repository->findByName($expenseAccount->name, [AccountTypeEnum::REVENUE->value]);
if (null !== $revenue) {
$collection->push($revenue);
}
@ -106,7 +107,7 @@ trait AugumentData
{
/** @var AccountRepositoryInterface $repository */
$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();
$return = [];
foreach ($accountIds as $combinedId) {

View File

@ -78,13 +78,13 @@ trait ModelInformation
// types of liability:
/** @var AccountType $debt */
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
$debt = $repository->getAccountTypeByType(AccountTypeEnum::DEBT->value);
/** @var AccountType $loan */
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
$loan = $repository->getAccountTypeByType(AccountTypeEnum::LOAN->value);
/** @var AccountType $mortgage */
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
$mortgage = $repository->getAccountTypeByType(AccountTypeEnum::MORTGAGE->value);
$liabilityTypes = [
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::DEBT->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;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\PopupReportInterface;
use FireflyIII\Models\Account;
@ -192,8 +193,8 @@ trait RenderPartialViews
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$expense = $repository->getActiveAccountsByType([AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$revenue = $repository->getActiveAccountsByType([AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$expense = $repository->getActiveAccountsByType([AccountTypeEnum::EXPENSE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$revenue = $repository->getActiveAccountsByType([AccountTypeEnum::REVENUE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]);
$set = [];
/** @var Account $account */

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -61,7 +62,7 @@ trait UserNavigation
*/
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;
return in_array($type, $editable, true);
@ -86,7 +87,7 @@ trait UserNavigation
final protected function redirectAccountToAccount(Account $account)
{
$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.
/** @var null|Transaction $transaction */
@ -128,7 +129,7 @@ trait UserNavigation
}
// prefer redirect to everything but expense and revenue:
$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 */
foreach ($transactions as $transaction) {

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\SearchDirection;
use FireflyIII\Enums\StringPosition;
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));
// 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';
if ($prohibited) {
$collectorMethod = 'excludeSourceAccounts';
@ -1947,7 +1948,7 @@ class OperatorQuerySearch implements SearchInterface
// search direction: for destination accounts
if (SearchDirection::DESTINATION === $searchDirection) { // destination
// 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';
if ($prohibited) {
$collectorMethod = 'excludeDestinationAccounts';
@ -1955,7 +1956,7 @@ class OperatorQuerySearch implements SearchInterface
}
// either account could be:
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';
if ($prohibited) {
$collectorMethod = 'excludeAccounts';
@ -2018,7 +2019,7 @@ class OperatorQuerySearch implements SearchInterface
app('log')->debug(sprintf('searchAccountNr(%s, %d, %d)', $value, $searchDirection->name, $stringPosition->name));
// 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';
if (true === $prohibited) {
$collectorMethod = 'excludeSourceAccounts';
@ -2027,7 +2028,7 @@ class OperatorQuerySearch implements SearchInterface
// search direction: for destination accounts
if (SearchDirection::DESTINATION === $searchDirection) {
// 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';
if (true === $prohibited) {
$collectorMethod = 'excludeDestinationAccounts';
@ -2036,7 +2037,7 @@ class OperatorQuerySearch implements SearchInterface
// either account could be:
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';
if (true === $prohibited) {
$collectorMethod = 'excludeAccounts';

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
@ -103,12 +104,12 @@ class TransactionGroupTwig extends AbstractExtension
}
// 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');
}
// 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');
}

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog;
@ -148,7 +149,7 @@ class ConvertToDeposit implements ActionInterface
$validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
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));
@ -236,7 +237,7 @@ class ConvertToDeposit implements ActionInterface
$validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
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));

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog;
@ -142,7 +143,7 @@ class ConvertToWithdrawal implements ActionInterface
$validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
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));
@ -228,7 +229,7 @@ class ConvertToWithdrawal implements ActionInterface
$validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
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));

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
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.
// the ID of the destination must belong to a liability.
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.');
return false;
@ -104,7 +105,7 @@ trait LiabilityValidation
app('log')->error('Array has a name, return true.');
// set the source to be a (dummy) revenue account.
$account = new Account();
$accountType = AccountType::whereType(AccountType::LIABILITY_CREDIT)->first();
$accountType = AccountType::whereType(AccountTypeEnum::LIABILITY_CREDIT->value)->first();
$account->accountType = $accountType;
$this->setSource($account);
}

View File

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

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Validation\Account;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
@ -39,7 +40,7 @@ trait WithdrawalValidation
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
app('log')->debug('Now in validateGenericSource', $array);
// 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 both values are NULL we return TRUE
// 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;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
@ -316,12 +317,12 @@ class FireflyValidator extends Validator
$account = $repository->findByName(
$value,
[
AccountType::DEFAULT,
AccountType::ASSET,
AccountType::LOAN,
AccountType::DEBT,
AccountType::MORTGAGE,
AccountType::CREDITCARD,
AccountTypeEnum::DEFAULT->value,
AccountTypeEnum::ASSET->value,
AccountTypeEnum::LOAN->value,
AccountTypeEnum::DEBT->value,
AccountTypeEnum::MORTGAGE->value,
AccountTypeEnum::CREDITCARD->value,
]
);

View File

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