Replace various enums

This commit is contained in:
James Cole
2022-04-13 14:39:13 +02:00
parent 9cfced1732
commit 089514908d
22 changed files with 87 additions and 69 deletions

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Api\V1\Controllers\Autocomplete;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest; use FireflyIII\Api\V1\Requests\Autocomplete\AutocompleteRequest;
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;
@@ -60,7 +61,7 @@ class AccountController extends Controller
return $next($request); return $next($request);
} }
); );
$this->balanceTypes = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,]; $this->balanceTypes = [AccountTypeEnum::ASSET, AccountTypeEnum::LOAN, AccountTypeEnum::DEBT, AccountTypeEnum::MORTGAGE,];
} }
/** /**
@@ -109,7 +110,7 @@ class AccountController extends Controller
} }
// custom order. // custom order.
$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE]; $order = [AccountTypeEnum::ASSET, AccountTypeEnum::REVENUE, AccountTypeEnum::EXPENSE];
usort( usort(
$return, function ($a, $b) use ($order) { $return, function ($a, $b) use ($order) {
$pos_a = array_search($a['type'], $order); $pos_a = array_search($a['type'], $order);

View File

@@ -27,9 +27,9 @@ namespace FireflyIII\Api\V1\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest; use FireflyIII\Api\V1\Requests\Data\DateRequest;
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\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Api\ApiSupport; use FireflyIII\Support\Http\Api\ApiSupport;
@@ -94,7 +94,7 @@ class AccountController extends Controller
$end = $dates['end']; $end = $dates['end'];
// user's preferences // user's preferences
$defaultSet = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); $defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET])->pluck('id')->toArray();
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet); $frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
$default = app('amount')->getDefaultCurrency(); $default = app('amount')->getDefaultCurrency();

View File

@@ -25,6 +25,8 @@ namespace FireflyIII\Api\V1\Controllers\Data;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DestroyRequest; use FireflyIII\Api\V1\Requests\Data\DestroyRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -94,70 +96,70 @@ class DestroyController extends Controller
case 'accounts': case 'accounts':
$this->destroyAccounts( $this->destroyAccounts(
[ [
AccountType::ASSET, AccountType::DEFAULT, AccountTypeEnum::ASSET, AccountTypeEnum::DEFAULT,
AccountType::BENEFICIARY, AccountType::EXPENSE, AccountTypeEnum::BENEFICIARY, AccountTypeEnum::EXPENSE,
AccountType::REVENUE, AccountType::INITIAL_BALANCE, AccountTypeEnum::REVENUE, AccountTypeEnum::INITIAL_BALANCE,
AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE, AccountTypeEnum::CREDITCARD,
] ]
); );
break; break;
case 'asset_accounts': case 'asset_accounts':
$this->destroyAccounts( $this->destroyAccounts(
[ [
AccountType::ASSET, AccountType::DEFAULT, AccountTypeEnum::ASSET, AccountTypeEnum::DEFAULT,
] ]
); );
break; break;
case 'expense_accounts': case 'expense_accounts':
$this->destroyAccounts( $this->destroyAccounts(
[ [
AccountType::BENEFICIARY, AccountType::EXPENSE, AccountTypeEnum::BENEFICIARY, AccountTypeEnum::EXPENSE,
] ]
); );
break; break;
case 'revenue_accounts': case 'revenue_accounts':
$this->destroyAccounts( $this->destroyAccounts(
[ [
AccountType::REVENUE, AccountTypeEnum::REVENUE,
] ]
); );
break; break;
case 'liabilities': case 'liabilities':
$this->destroyAccounts( $this->destroyAccounts(
[ [
AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE, AccountTypeEnum::CREDITCARD,
] ]
); );
break; break;
case 'transactions': case 'transactions':
$this->destroyTransactions( $this->destroyTransactions(
[ [
TransactionType::WITHDRAWAL, TransactionTypeEnum::WITHDRAWAL,
TransactionType::DEPOSIT, TransactionTypeEnum::DEPOSIT,
TransactionType::TRANSFER, TransactionTypeEnum::TRANSFER,
TransactionType::RECONCILIATION, TransactionTypeEnum::RECONCILIATION,
TransactionType::OPENING_BALANCE, TransactionTypeEnum::OPENING_BALANCE,
] ]
); );
break; break;
case 'withdrawals': case 'withdrawals':
$this->destroyTransactions( $this->destroyTransactions(
[ [
TransactionType::WITHDRAWAL, TransactionTypeEnum::WITHDRAWAL,
] ]
); );
break; break;
case 'deposits': case 'deposits':
$this->destroyTransactions( $this->destroyTransactions(
[ [
TransactionType::DEPOSIT, TransactionTypeEnum::DEPOSIT,
] ]
); );
break; break;
case 'transfers': case 'transfers':
$this->destroyTransactions( $this->destroyTransactions(
[ [
TransactionType::TRANSFER, TransactionTypeEnum::TRANSFER,
] ]
); );
break; break;

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use Exception; use Exception;
use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Data\DateRequest; use FireflyIII\Api\V1\Requests\Data\DateRequest;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface; use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -357,7 +358,7 @@ class BasicController extends Controller
/** @var NetWorthInterface $netWorthHelper */ /** @var NetWorthInterface $netWorthHelper */
$netWorthHelper = app(NetWorthInterface::class); $netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper->setUser($user); $netWorthHelper->setUser($user);
$allAccounts = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]); $allAccounts = $this->accountRepository->getActiveAccountsByType([AccountTypeEnum::ASSET, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE]);
// filter list on preference of being included. // filter list on preference of being included.
$filtered = $allAccounts->filter( $filtered = $allAccounts->filter(

View File

@@ -23,6 +23,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;
@@ -49,7 +50,7 @@ class AutocompleteRequest extends FormRequest
$limit = 0 === $limit ? 10 : $limit; $limit = 0 === $limit ? 10 : $limit;
// 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, AccountTypeEnum::RECONCILIATION]);
return [ return [
'types' => $array, 'types' => $array,

View File

@@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Data\Export; namespace FireflyIII\Api\V1\Requests\Data\Export;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\AccountType; use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes; use FireflyIII\Support\Request\ConvertsDataTypes;
@@ -54,7 +54,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 === $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;
@@ -73,7 +74,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])) { if (in_array($type, [AccountTypeEnum::ASSET, AccountTypeEnum::LOAN, AccountTypeEnum::DEBT, AccountTypeEnum::MORTGAGE])) {
$return->push($account); $return->push($account);
} }
} }
@@ -220,7 +221,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 ($type === AccountType::EXPENSE) { if ($type === AccountTypeEnum::EXPENSE) {
$return->push($account); $return->push($account);
} }
} }
@@ -238,7 +239,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 ($type === AccountType::REVENUE) { if ($type === AccountTypeEnum::REVENUE) {
$return->push($account); $return->push($account);
} }
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
@@ -124,7 +125,7 @@ class CorrectOpeningBalanceCurrencies extends Command
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
/** @var Account $account */ /** @var 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 !== $account->accountType()->first()->type) {
return $account; return $account;
} }
} }

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -176,11 +178,11 @@ class FixAccountTypes extends Command
$combination = sprintf('%s%s%s', $type, $source->account->accountType->type, $dest->account->accountType->type); $combination = sprintf('%s%s%s', $type, $source->account->accountType->type, $dest->account->accountType->type);
switch ($combination) { switch ($combination) {
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::ASSET, AccountTypeEnum::LOAN):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::ASSET, AccountTypeEnum::DEBT):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::ASSET, AccountTypeEnum::MORTGAGE):
// from an asset to a liability should be a withdrawal: // from an asset to a liability should be a withdrawal:
$withdrawal = TransactionType::whereType(TransactionType::WITHDRAWAL)->first(); $withdrawal = TransactionType::whereType(TransactionTypeEnum::WITHDRAWAL)->first();
$journal->transactionType()->associate($withdrawal); $journal->transactionType()->associate($withdrawal);
$journal->save(); $journal->save();
$message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id); $message = sprintf('Converted transaction #%d from a transfer to a withdrawal.', $journal->id);
@@ -189,11 +191,11 @@ class FixAccountTypes extends Command
// check it again: // check it again:
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::LOAN, AccountTypeEnum::ASSET):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::DEBT, AccountTypeEnum::ASSET):
case sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET): case sprintf('%s%s%s', TransactionTypeEnum::TRANSFER, AccountTypeEnum::MORTGAGE, AccountTypeEnum::ASSET):
// from a liability to an asset should be a deposit. // from a liability to an asset should be a deposit.
$deposit = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $deposit = TransactionType::whereType(TransactionTypeEnum::DEPOSIT)->first();
$journal->transactionType()->associate($deposit); $journal->transactionType()->associate($deposit);
$journal->save(); $journal->save();
$message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id); $message = sprintf('Converted transaction #%d from a transfer to a deposit.', $journal->id);
@@ -203,11 +205,11 @@ class FixAccountTypes extends Command
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
case sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE): case sprintf('%s%s%s', TransactionTypeEnum::WITHDRAWAL, AccountTypeEnum::ASSET, AccountTypeEnum::REVENUE):
// 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 = $dest->account; $oldDest = $dest->account;
$result = $this->factory->findOrCreate($dest->account->name, AccountType::EXPENSE); $result = $this->factory->findOrCreate($dest->account->name, AccountTypeEnum::EXPENSE);
$dest->account()->associate($result); $dest->account()->associate($result);
$dest->save(); $dest->save();
$message = sprintf( $message = sprintf(
@@ -218,11 +220,11 @@ class FixAccountTypes extends Command
Log::debug($message); Log::debug($message);
$this->inspectJournal($journal); $this->inspectJournal($journal);
break; break;
case sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET): case sprintf('%s%s%s', TransactionTypeEnum::DEPOSIT, AccountTypeEnum::EXPENSE, AccountTypeEnum::ASSET):
// 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);
$oldSource = $dest->account; $oldSource = $dest->account;
$source->account()->associate($result); $source->account()->associate($result);
$source->save(); $source->save();

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction; namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Enums\TransactionTypeEnum;
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;
@@ -91,7 +92,7 @@ class FixFrontpageAccounts 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, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE], true)
&& true === $account->active) { && true === $account->active) {
$fixed[] = $account->id; $fixed[] = $account->id;
} }

View File

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

View File

@@ -25,6 +25,8 @@ namespace FireflyIII\Console\Commands\Tools;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
@@ -166,7 +168,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, AccountTypeEnum::DEBT, AccountTypeEnum::ASSET, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE];
$this->groups = new Collection; $this->groups = new Collection;
} }

View File

@@ -26,7 +26,6 @@ namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta; use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -146,7 +145,7 @@ class AccountCurrencies extends Command
{ {
Log::debug(sprintf('Now in updateCurrenciesForUser(%s, %s)', $user->email, $systemCurrencyCode)); Log::debug(sprintf('Now in updateCurrenciesForUser(%s, %s)', $user->email, $systemCurrencyCode));
$this->accountRepos->setUser($user); $this->accountRepos->setUser($user);
$accounts = $this->accountRepos->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $this->accountRepos->getAccountsByType([AccountTypeEnum::DEFAULT, AccountTypeEnum::ASSET]);
// get user's currency preference: // get user's currency preference:
$defaultCurrencyCode = app('preferences')->getForUser($user, 'currencyPreference', $systemCurrencyCode)->data; $defaultCurrencyCode = app('preferences')->getForUser($user, 'currencyPreference', $systemCurrencyCode)->data;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -66,8 +67,8 @@ class CCLiabilities extends Command
} }
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first(); $ccType = AccountType::where('type', AccountTypeEnum::CREDITCARD)->first();
$debtType = AccountType::where('type', AccountType::DEBT)->first(); $debtType = AccountType::where('type', AccountTypeEnum::DEBT)->first();
if (null === $ccType || null === $debtType) { if (null === $ccType || null === $debtType) {
$this->info('No incorrectly stored credit card liabilities.'); $this->info('No incorrectly stored credit card liabilities.');

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
@@ -218,23 +220,23 @@ class OtherCurrenciesCorrections extends Command
switch ($journal->transactionType->type) { switch ($journal->transactionType->type) {
default: default:
break; break;
case TransactionType::WITHDRAWAL: case TransactionTypeEnum::WITHDRAWAL:
$lead = $journal->transactions()->where('amount', '<', 0)->first(); $lead = $journal->transactions()->where('amount', '<', 0)->first();
break; break;
case TransactionType::DEPOSIT: case TransactionTypeEnum::DEPOSIT:
$lead = $journal->transactions()->where('amount', '>', 0)->first(); $lead = $journal->transactions()->where('amount', '>', 0)->first();
break; break;
case TransactionType::OPENING_BALANCE: case TransactionTypeEnum::OPENING_BALANCE:
// whichever isn't an initial balance account: // whichever isn't an initial balance account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin( $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id' 'account_types', 'accounts.account_type_id', '=', 'account_types.id'
)->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']); )->where('account_types.type', '!=', AccountTypeEnum::INITIAL_BALANCE)->first(['transactions.*']);
break; break;
case TransactionType::RECONCILIATION: case TransactionTypeEnum::RECONCILIATION:
// whichever isn't the reconciliation account: // whichever isn't the reconciliation account:
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin( $lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
'account_types', 'accounts.account_type_id', '=', 'account_types.id' 'account_types', 'accounts.account_type_id', '=', 'account_types.id'
)->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']); )->where('account_types.type', '!=', AccountTypeEnum::RECONCILIATION)->first(['transactions.*']);
break; break;
} }

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\StoredAccount; use FireflyIII\Events\StoredAccount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -260,7 +262,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 ($account->accountType->type !== AccountType::ASSET) { if ($account->accountType->type !== AccountTypeEnum::ASSET) {
$accountRole = ''; $accountRole = '';
} }
// only liability may have direction: // only liability may have direction:
@@ -281,10 +283,10 @@ class AccountFactory
{ {
$fields = $this->validFields; $fields = $this->validFields;
if ($account->accountType->type === AccountType::ASSET) { if ($account->accountType->type === AccountTypeEnum::ASSET) {
$fields = $this->validAssetFields; $fields = $this->validAssetFields;
} }
if ($account->accountType->type === AccountType::ASSET && 'ccAsset' === $data['account_role']) { if ($account->accountType->type === AccountTypeEnum::ASSET && 'ccAsset' === $data['account_role']) {
$fields = $this->validCCFields; $fields = $this->validCCFields;
} }

View File

@@ -23,6 +23,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;
@@ -151,7 +152,7 @@ class CreateController extends Controller
// update preferences if necessary: // update preferences if necessary:
$frontPage = app('preferences')->get('frontPageAccounts', [])->data; $frontPage = app('preferences')->get('frontPageAccounts', [])->data;
if (AccountType::ASSET === $account->accountType->type) { if (AccountTypeEnum::ASSET === $account->accountType->type) {
$frontPage[] = $account->id; $frontPage[] = $account->id;
app('preferences')->set('frontPageAccounts', $frontPage); app('preferences')->set('frontPageAccounts', $frontPage);
} }

View File

@@ -24,10 +24,10 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use Exception; use Exception;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Events\RequestedVersionCheckStatus; use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Middleware\Installer; use FireflyIII\Http\Middleware\Installer;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
@@ -115,7 +115,7 @@ class HomeController extends Controller
} }
$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])->pluck('id')->toArray());
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth()); $start = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */ /** @var Carbon $end */

View File

@@ -23,9 +23,9 @@ 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\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
@@ -54,7 +54,7 @@ class JavascriptController extends Controller
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
{ {
$accounts = $repository->getAccountsByType( $accounts = $repository->getAccountsByType(
[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD] [AccountTypeEnum::DEFAULT, AccountTypeEnum::ASSET, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE, AccountTypeEnum::CREDITCARD]
); );
$preference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR')); $preference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'));
/** @noinspection NullPointerExceptionInspection */ /** @noinspection NullPointerExceptionInspection */

View File

@@ -22,9 +22,9 @@ 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\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Http\Controllers\CreateStuff; use FireflyIII\Support\Http\Controllers\CreateStuff;
@@ -117,7 +117,7 @@ class NewUserController extends Controller
app('preferences')->set('currencyPreference', $currency->code); app('preferences')->set('currencyPreference', $currency->code);
// store frontpage preferences: // store frontpage preferences:
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray(); $accounts = $this->repository->getAccountsByType([AccountTypeEnum::ASSET])->pluck('id')->toArray();
app('preferences')->set('frontPageAccounts', $accounts); app('preferences')->set('frontPageAccounts', $accounts);
// mark. // mark.

View File

@@ -22,9 +22,9 @@ 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\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference; use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
@@ -71,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, AccountTypeEnum::ASSET, AccountTypeEnum::LOAN, AccountTypeEnum::DEBT, AccountTypeEnum::MORTGAGE]);
$isDocker = env('IS_DOCKER', false); $isDocker = env('IS_DOCKER', false);
// group accounts // group accounts
@@ -81,7 +81,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, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN], true)) {
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }

View File

@@ -24,12 +24,12 @@ 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;
use FireflyIII\Http\Requests\ReportFormRequest; use FireflyIII\Http\Requests\ReportFormRequest;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Support\Http\Controllers\RenderPartialViews; use FireflyIII\Support\Http\Controllers\RenderPartialViews;
@@ -272,7 +272,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, AccountTypeEnum::ASSET, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN, AccountTypeEnum::MORTGAGE]
); );
// group accounts by role: // group accounts by role:
@@ -282,7 +282,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, AccountTypeEnum::DEBT, AccountTypeEnum::LOAN], true)) {
$role = sprintf('opt_group_l_%s', $type); $role = sprintf('opt_group_l_%s', $type);
} }