Replace enum

This commit is contained in:
James Cole
2025-01-03 09:09:15 +01:00
parent d009ce31ca
commit 36351a5dd9
36 changed files with 68 additions and 67 deletions

View File

@@ -275,7 +275,7 @@ class CorrectsAccountTypes extends Command
private function makeDeposit(TransactionJournal $journal): void private function makeDeposit(TransactionJournal $journal): void
{ {
// 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->value)->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);
@@ -313,7 +313,7 @@ class CorrectsAccountTypes extends Command
private function shouldComeFromRevenueAccount(string $transactionType, string $sourceType, string $destinationType): bool private function shouldComeFromRevenueAccount(string $transactionType, string $sourceType, string $destinationType): bool
{ {
return TransactionType::DEPOSIT === $transactionType && AccountType::EXPENSE === $sourceType && AccountType::ASSET === $destinationType; return TransactionTypeEnum::DEPOSIT->value === $transactionType && AccountType::EXPENSE === $sourceType && AccountType::ASSET === $destinationType;
} }
private function makeRevenueSource(TransactionJournal $journal, Transaction $source): void private function makeRevenueSource(TransactionJournal $journal, Transaction $source): void

View File

@@ -104,7 +104,7 @@ class UpgradesVariousCurrencyInformation extends Command
private function updateOtherJournalsCurrencies(): void private function updateOtherJournalsCurrencies(): void
{ {
$set = $this->cliRepos->getAllJournals( $set = $this->cliRepos->getAllJournals(
[TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION] [TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION]
); );
/** @var TransactionJournal $journal */ /** @var TransactionJournal $journal */
@@ -186,7 +186,7 @@ class UpgradesVariousCurrencyInformation extends Command
break; break;
case TransactionType::DEPOSIT: case TransactionTypeEnum::DEPOSIT->value:
$lead = $journal->transactions()->where('amount', '>', 0)->first(); $lead = $journal->transactions()->where('amount', '>', 0)->first();
break; break;

View File

@@ -452,7 +452,7 @@ class TransactionJournalFactory
return match ($type) { return match ($type) {
default => $this->getCurrency($currency, $source), default => $this->getCurrency($currency, $source),
TransactionType::DEPOSIT => $this->getCurrency($currency, $destination), TransactionTypeEnum::DEPOSIT->value => $this->getCurrency($currency, $destination),
}; };
} }

View File

@@ -182,7 +182,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end) $collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) ->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->setCategories($this->categories)->withAccountInformation() ->setCategories($this->categories)->withAccountInformation()
; ;

View File

@@ -149,7 +149,7 @@ class UpdatedGroupEventHandler
->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id]) ->where('amount', '<', 0)->update(['account_id' => $sourceAccount->id])
; ;
} }
if (TransactionTypeEnum::TRANSFER->value === $type || TransactionType::DEPOSIT === $type) { if (TransactionTypeEnum::TRANSFER->value === $type || TransactionTypeEnum::DEPOSIT->value === $type) {
// set all destination transactions to destination account: // set all destination transactions to destination account:
Transaction::whereIn('transaction_journal_id', $all) Transaction::whereIn('transaction_journal_id', $all)
->where('amount', '>', 0)->update(['account_id' => $destAccount->id]) ->where('amount', '>', 0)->update(['account_id' => $destAccount->id])

View File

@@ -143,7 +143,7 @@ class PopupReport implements PopupReportInterface
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($attributes['accounts']) $collector->setAccounts($attributes['accounts'])
->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value, TransactionType::DEPOSIT]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value, TransactionTypeEnum::DEPOSIT->value])
->withAccountInformation() ->withAccountInformation()
->withBudgetInformation() ->withBudgetInformation()
->withCategoryInformation() ->withCategoryInformation()
@@ -222,7 +222,7 @@ class PopupReport implements PopupReportInterface
->setSourceAccounts(new Collection([$account])) ->setSourceAccounts(new Collection([$account]))
->setDestinationAccounts($attributes['accounts']) ->setDestinationAccounts($attributes['accounts'])
->setRange($attributes['startDate'], $attributes['endDate']) ->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) ->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->withAccountInformation() ->withAccountInformation()
->withBudgetInformation() ->withBudgetInformation()
->withCategoryInformation() ->withCategoryInformation()

View File

@@ -95,7 +95,7 @@ class NoCategoryController extends Controller
$collector->setRange($start, $end) $collector->setRange($start, $end)
->setLimit($pageSize)->setPage($page)->withoutCategory() ->setLimit($pageSize)->setPage($page)->withoutCategory()
->withAccountInformation()->withBudgetInformation() ->withAccountInformation()->withBudgetInformation()
->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
; ;
$groups = $collector->getPaginatedGroups(); $groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category', [$start->format('Y-m-d'), $end->format('Y-m-d')])); $groups->setPath(route('categories.no-category', [$start->format('Y-m-d'), $end->format('Y-m-d')]));
@@ -128,7 +128,7 @@ class NoCategoryController extends Controller
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory() $collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()
->withAccountInformation()->withBudgetInformation() ->withAccountInformation()->withBudgetInformation()
->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) ->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
; ;
$groups = $collector->getPaginatedGroups(); $groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category.all')); $groups->setPath(route('categories.no-category.all'));

View File

@@ -377,7 +377,7 @@ class AccountController extends Controller
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$result = []; $result = [];
$chartData = []; $chartData = [];

View File

@@ -113,7 +113,7 @@ class TransactionController extends Controller
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
} }
if ('deposit' === $objectType) { if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
} }
if ('transfer' === $objectType || 'transfers' === $objectType) { if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]); $collector->setTypes([TransactionTypeEnum::TRANSFER->value]);
@@ -163,7 +163,7 @@ class TransactionController extends Controller
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
} }
if ('deposit' === $objectType) { if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
} }
if ('transfer' === $objectType || 'transfers' === $objectType) { if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]); $collector->setTypes([TransactionTypeEnum::TRANSFER->value]);
@@ -213,7 +213,7 @@ class TransactionController extends Controller
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]); $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
} }
if ('deposit' === $objectType) { if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
} }
if ('transfer' === $objectType || 'transfers' === $objectType) { if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]); $collector->setTypes([TransactionTypeEnum::TRANSFER->value]);

View File

@@ -84,7 +84,7 @@ class BoxController extends Controller
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end) $collector->setRange($start, $end)
->setTypes([TransactionType::DEPOSIT]) ->setTypes([TransactionTypeEnum::DEPOSIT->value])
; ;
$set = $collector->getExtractedJournals(); $set = $collector->getExtractedJournals();

View File

@@ -242,7 +242,7 @@ class ReconcileController extends Controller
foreach ($array as $journal) { foreach ($array as $journal) {
$inverse = false; $inverse = false;
if (TransactionType::DEPOSIT === $journal['transaction_type_type']) { if (TransactionTypeEnum::DEPOSIT->value === $journal['transaction_type_type']) {
$inverse = true; $inverse = true;
} }
// transfer to this account? then positive amount: // transfer to this account? then positive amount:
@@ -251,7 +251,7 @@ class ReconcileController extends Controller
} }
// opening balance into account? then positive amount: // opening balance into account? then positive amount:
if (TransactionType::OPENING_BALANCE === $journal['transaction_type_type'] if (TransactionTypeEnum::OPENING_BALANCE->value === $journal['transaction_type_type']
&& $account->id === $journal['destination_account_id']) { && $account->id === $journal['destination_account_id']) {
$inverse = true; $inverse = true;
} }

View File

@@ -332,7 +332,7 @@ class ConvertController extends Controller
]; ];
// also set the currency to the currency of the source account, in case you're converting a deposit into a transfer. // also set the currency to the currency of the source account, in case you're converting a deposit into a transfer.
if (TransactionTypeEnum::TRANSFER->value === $transactionType->type && TransactionType::DEPOSIT === $journal->transactionType->type) { if (TransactionTypeEnum::TRANSFER->value === $transactionType->type && TransactionTypeEnum::DEPOSIT->value === $journal->transactionType->type) {
$source = $this->accountRepository->find((int) $sourceId); $source = $this->accountRepository->find((int) $sourceId);
$sourceCurrency = $this->accountRepository->getAccountCurrency($source); $sourceCurrency = $this->accountRepository->getAccountCurrency($source);
$dest = $this->accountRepository->find((int) $destinationId); $dest = $this->accountRepository->find((int) $destinationId);

View File

@@ -132,7 +132,7 @@ class MassController extends Controller
$withdrawalSources = $accountRepository->getAccountsByType($array); $withdrawalSources = $accountRepository->getAccountsByType($array);
// valid deposit destinations: // valid deposit destinations:
$array = config(sprintf('firefly.source_dests.%s.%s', TransactionType::DEPOSIT, AccountType::REVENUE)); $array = config(sprintf('firefly.source_dests.%s.%s', TransactionTypeEnum::DEPOSIT->value, AccountType::REVENUE));
$depositDestinations = $accountRepository->getAccountsByType($array); $depositDestinations = $accountRepository->getAccountsByType($array);
/** @var BudgetRepositoryInterface $budgetRepository */ /** @var BudgetRepositoryInterface $budgetRepository */

View File

@@ -248,7 +248,7 @@ class RecurrenceFormRequest extends FormRequest
$rules['source_id'] = 'required|exists:accounts,id|belongsToUser:accounts'; $rules['source_id'] = 'required|exists:accounts,id|belongsToUser:accounts';
$rules['destination_name'] = 'min:1|max:255|nullable'; $rules['destination_name'] = 'min:1|max:255|nullable';
} }
if (strtolower(TransactionType::DEPOSIT) === $type) { if (strtolower(TransactionTypeEnum::DEPOSIT->value) === $type) {
$rules['source_name'] = 'min:1|max:255|nullable'; $rules['source_name'] = 'min:1|max:255|nullable';
$rules['destination_id'] = 'required|exists:accounts,id|belongsToUser:accounts'; $rules['destination_id'] = 'required|exists:accounts,id|belongsToUser:accounts';
} }

View File

@@ -212,7 +212,7 @@ class AccountTasker implements AccountTaskerInterface
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setDestinationAccounts($accounts)->setRange($start, $end); $collector->setDestinationAccounts($accounts)->setRange($start, $end);
$collector->excludeSourceAccounts($accounts); $collector->excludeSourceAccounts($accounts);
$collector->setTypes([TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value])->withAccountInformation(); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])->withAccountInformation();
$report = $this->groupIncomeBySource($collector->getExtractedJournals()); $report = $this->groupIncomeBySource($collector->getExtractedJournals());
// sort the result // sort the result

View File

@@ -102,7 +102,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->withoutCategory(); $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
} }
@@ -164,7 +164,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->withoutCategory(); $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);

View File

@@ -137,7 +137,7 @@ class OperationsRepository implements OperationsRepositoryInterface
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT]); $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value]);
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);
} }

View File

@@ -139,7 +139,7 @@ class OperationsRepository implements OperationsRepositoryInterface
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT]); $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$tagIds = []; $tagIds = [];
if (null !== $accounts && $accounts->count() > 0) { if (null !== $accounts && $accounts->count() > 0) {
$collector->setAccounts($accounts); $collector->setAccounts($accounts);

View File

@@ -173,7 +173,7 @@ class TagRepository implements TagRepositoryInterface
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user); $collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setTag($tag); $collector->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value])->setTag($tag);
return $collector->getExtractedJournals(); return $collector->getExtractedJournals();
} }
@@ -267,7 +267,7 @@ class TagRepository implements TagRepositoryInterface
'currency_symbol' => $journal['currency_symbol'], 'currency_symbol' => $journal['currency_symbol'],
'currency_decimal_places' => $journal['currency_decimal_places'], 'currency_decimal_places' => $journal['currency_decimal_places'],
TransactionTypeEnum::WITHDRAWAL->value => '0', TransactionTypeEnum::WITHDRAWAL->value => '0',
TransactionType::DEPOSIT => '0', TransactionTypeEnum::DEPOSIT->value => '0',
TransactionTypeEnum::TRANSFER->value => '0', TransactionTypeEnum::TRANSFER->value => '0',
TransactionType::RECONCILIATION => '0', TransactionType::RECONCILIATION => '0',
TransactionType::OPENING_BALANCE => '0', TransactionType::OPENING_BALANCE => '0',
@@ -289,7 +289,7 @@ class TagRepository implements TagRepositoryInterface
'currency_symbol' => $journal['foreign_currency_symbol'], 'currency_symbol' => $journal['foreign_currency_symbol'],
'currency_decimal_places' => $journal['foreign_currency_decimal_places'], 'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
TransactionTypeEnum::WITHDRAWAL->value => '0', TransactionTypeEnum::WITHDRAWAL->value => '0',
TransactionType::DEPOSIT => '0', TransactionTypeEnum::DEPOSIT->value => '0',
TransactionTypeEnum::TRANSFER->value => '0', TransactionTypeEnum::TRANSFER->value => '0',
TransactionType::RECONCILIATION => '0', TransactionType::RECONCILIATION => '0',
TransactionType::OPENING_BALANCE => '0', TransactionType::OPENING_BALANCE => '0',

View File

@@ -343,7 +343,7 @@ class CreditRecalculateService
} }
// in any other case, remove amount from left of debt. // in any other case, remove amount from left of debt.
if (in_array($type, [TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value], true)) { if (in_array($type, [TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value], true)) {
$usedAmount = app('steam')->negative($usedAmount); $usedAmount = app('steam')->negative($usedAmount);
return bcadd($leftOfDebt, $usedAmount); return bcadd($leftOfDebt, $usedAmount);
@@ -412,7 +412,7 @@ class CreditRecalculateService
*/ */
private function isDepositOut(string $amount, string $transactionType): bool private function isDepositOut(string $amount, string $transactionType): bool
{ {
return TransactionType::DEPOSIT === $transactionType && -1 === bccomp($amount, '0'); return TransactionTypeEnum::DEPOSIT->value === $transactionType && -1 === bccomp($amount, '0');
} }
/** /**
@@ -423,7 +423,7 @@ class CreditRecalculateService
*/ */
private function isDepositIn(string $amount, string $transactionType): bool private function isDepositIn(string $amount, string $transactionType): bool
{ {
return TransactionType::DEPOSIT === $transactionType && 1 === bccomp($amount, '0'); return TransactionTypeEnum::DEPOSIT->value === $transactionType && 1 === bccomp($amount, '0');
} }
/** /**

View File

@@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Authentication; namespace FireflyIII\Support\Authentication;
use FireflyIII\Console\Commands\Correction\CreateGroupMemberships; use FireflyIII\Console\Commands\Correction\CreatesGroupMemberships;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Role; use FireflyIII\Models\Role;
use FireflyIII\User; use FireflyIII\User;
@@ -82,7 +82,7 @@ class RemoteUserProvider implements UserProvider
} }
} }
// make sure the user gets an administration as well. // make sure the user gets an administration as well.
CreateGroupMemberships::createGroupMembership($user); CreatesGroupMemberships::createGroupMembership($user);
app('log')->debug(sprintf('Going to return user #%d (%s)', $user->id, $user->email)); app('log')->debug(sprintf('Going to return user #%d (%s)', $user->id, $user->email));

View File

@@ -45,7 +45,7 @@ class JournalList implements BinderInterface
// get the journals by using the collector. // get the journals by using the collector.
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value, TransactionType::RECONCILIATION]); $collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value, TransactionType::RECONCILIATION]);
$collector->withCategoryInformation()->withBudgetInformation()->withTagInformation()->withAccountInformation(); $collector->withCategoryInformation()->withBudgetInformation()->withTagInformation()->withAccountInformation();
$collector->setJournalIds($list); $collector->setJournalIds($list);
$result = $collector->getExtractedJournals(); $result = $collector->getExtractedJournals();

View File

@@ -220,7 +220,7 @@ class AccountBalanceGrouped
// deposit = incoming // deposit = incoming
// transfer or reconcile or opening balance, and these accounts are the destination. // transfer or reconcile or opening balance, and these accounts are the destination.
if ( if (
TransactionType::DEPOSIT === $journal['transaction_type_type'] TransactionTypeEnum::DEPOSIT->value === $journal['transaction_type_type']
|| ( || (
( (

View File

@@ -40,7 +40,7 @@ trait TransactionFilter
$types = [ $types = [
'all' => [ 'all' => [
TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::WITHDRAWAL->value,
TransactionType::DEPOSIT, TransactionTypeEnum::DEPOSIT->value,
TransactionTypeEnum::TRANSFER->value, TransactionTypeEnum::TRANSFER->value,
TransactionType::OPENING_BALANCE, TransactionType::OPENING_BALANCE,
TransactionType::RECONCILIATION, TransactionType::RECONCILIATION,
@@ -49,9 +49,9 @@ trait TransactionFilter
'withdrawals' => [TransactionTypeEnum::WITHDRAWAL->value], 'withdrawals' => [TransactionTypeEnum::WITHDRAWAL->value],
'expense' => [TransactionTypeEnum::WITHDRAWAL->value], 'expense' => [TransactionTypeEnum::WITHDRAWAL->value],
'expenses' => [TransactionTypeEnum::WITHDRAWAL->value], 'expenses' => [TransactionTypeEnum::WITHDRAWAL->value],
'income' => [TransactionType::DEPOSIT], 'income' => [TransactionTypeEnum::DEPOSIT->value],
'deposit' => [TransactionType::DEPOSIT], 'deposit' => [TransactionTypeEnum::DEPOSIT->value],
'deposits' => [TransactionType::DEPOSIT], 'deposits' => [TransactionTypeEnum::DEPOSIT->value],
'transfer' => [TransactionTypeEnum::TRANSFER->value], 'transfer' => [TransactionTypeEnum::TRANSFER->value],
'transfers' => [TransactionTypeEnum::TRANSFER->value], 'transfers' => [TransactionTypeEnum::TRANSFER->value],
'opening_balance' => [TransactionType::OPENING_BALANCE], 'opening_balance' => [TransactionType::OPENING_BALANCE],
@@ -59,7 +59,7 @@ trait TransactionFilter
'reconciliations' => [TransactionType::RECONCILIATION], 'reconciliations' => [TransactionType::RECONCILIATION],
'special' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION], 'special' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION],
'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION], 'specials' => [TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION],
'default' => [TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value], 'default' => [TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value],
]; ];
$return = []; $return = [];
$parts = explode(',', $type); $parts = explode(',', $type);

View File

@@ -98,7 +98,7 @@ trait PeriodOverview
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account])); $collector->setAccounts(new Collection([$account]));
$collector->setRange($start, $end); $collector->setRange($start, $end);
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals(); $earnedSet = $collector->getExtractedJournals();
// collect all income in this period: // collect all income in this period:
@@ -272,7 +272,7 @@ trait PeriodOverview
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setCategory($category); $collector->setCategory($category);
$collector->setRange($start, $end); $collector->setRange($start, $end);
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals(); $earnedSet = $collector->getExtractedJournals();
// collect all income in this period: // collect all income in this period:
@@ -394,7 +394,7 @@ trait PeriodOverview
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->withoutCategory(); $collector->withoutCategory();
$collector->setRange($start, $end); $collector->setRange($start, $end);
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals(); $earnedSet = $collector->getExtractedJournals();
// collect all income in this period: // collect all income in this period:
@@ -463,7 +463,7 @@ trait PeriodOverview
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setTag($tag); $collector->setTag($tag);
$collector->setRange($start, $end); $collector->setRange($start, $end);
$collector->setTypes([TransactionType::DEPOSIT]); $collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals(); $earnedSet = $collector->getExtractedJournals();
// collect all income in this period: // collect all income in this period:

View File

@@ -107,7 +107,7 @@ trait TransactionCalculation
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) $collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->setCategories($categories)->withAccountInformation() ->setCategories($categories)->withAccountInformation()
; ;
@@ -123,7 +123,7 @@ trait TransactionCalculation
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($total)->setRange($start, $end)->withAccountInformation()->setTypes([TransactionType::DEPOSIT]); $collector->setAccounts($total)->setRange($start, $end)->withAccountInformation()->setTypes([TransactionTypeEnum::DEPOSIT->value]);
return $collector->getExtractedJournals(); return $collector->getExtractedJournals();
} }
@@ -135,7 +135,7 @@ trait TransactionCalculation
{ {
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value]) $collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->setTags($tags)->withAccountInformation() ->setTags($tags)->withAccountInformation()
; ;

View File

@@ -75,7 +75,7 @@ trait UserNavigation
return false; return false;
} }
$type = $journal->transactionType->type; $type = $journal->transactionType->type;
$editable = [TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value, TransactionType::DEPOSIT, TransactionType::RECONCILIATION]; $editable = [TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value, TransactionTypeEnum::DEPOSIT->value, TransactionType::RECONCILIATION];
return in_array($type, $editable, true); return in_array($type, $editable, true);
} }

View File

@@ -75,7 +75,7 @@ class ConvertToDeposit implements ActionInterface
app('log')->debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id'])); app('log')->debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
$type = $object->transactionType->type; $type = $object->transactionType->type;
if (TransactionType::DEPOSIT === $type) { if (TransactionTypeEnum::DEPOSIT->value === $type) {
app('log')->error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id)); app('log')->error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_deposit'))); event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_deposit')));
@@ -95,7 +95,7 @@ class ConvertToDeposit implements ActionInterface
return false; return false;
} }
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::WITHDRAWAL->value, TransactionType::DEPOSIT)); event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::DEPOSIT->value));
return $res; return $res;
} }
@@ -111,7 +111,7 @@ class ConvertToDeposit implements ActionInterface
return false; return false;
} }
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::TRANSFER->value, TransactionType::DEPOSIT)); event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::TRANSFER->value, TransactionTypeEnum::DEPOSIT->value));
return $res; return $res;
} }
@@ -168,7 +168,7 @@ class ConvertToDeposit implements ActionInterface
; ;
// change transaction type of journal: // change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $newType = TransactionType::whereType(TransactionTypeEnum::DEPOSIT->value)->first();
\DB::table('transaction_journals') \DB::table('transaction_journals')
->where('id', '=', $journal->id) ->where('id', '=', $journal->id)
@@ -249,7 +249,7 @@ class ConvertToDeposit implements ActionInterface
; ;
// change transaction type of journal: // change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first(); $newType = TransactionType::whereType(TransactionTypeEnum::DEPOSIT->value)->first();
\DB::table('transaction_journals') \DB::table('transaction_journals')
->where('id', '=', $journal->id) ->where('id', '=', $journal->id)

View File

@@ -87,7 +87,7 @@ class ConvertToTransfer implements ActionInterface
return false; return false;
} }
if (TransactionType::DEPOSIT !== $type && TransactionTypeEnum::WITHDRAWAL->value !== $type) { if (TransactionTypeEnum::DEPOSIT->value !== $type && TransactionTypeEnum::WITHDRAWAL->value !== $type) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_transfer', ['type' => $type]))); event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_transfer', ['type' => $type])));
return false; return false;
@@ -102,7 +102,7 @@ class ConvertToTransfer implements ActionInterface
$expectedType = $this->getSourceType($journalId); $expectedType = $this->getSourceType($journalId);
// Withdrawal? Replace destination with account with same type as source. // Withdrawal? Replace destination with account with same type as source.
} }
if (TransactionType::DEPOSIT === $type) { if (TransactionTypeEnum::DEPOSIT->value === $type) {
$expectedType = $this->getDestinationType($journalId); $expectedType = $this->getDestinationType($journalId);
// Deposit? Replace source with account with same type as destination. // Deposit? Replace source with account with same type as destination.
} }
@@ -154,7 +154,7 @@ class ConvertToTransfer implements ActionInterface
return false; return false;
} }
if (false !== $res) { if (false !== $res) {
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionTypeEnum::TRANSFER->value)); event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value));
} }
return $res; return $res;

View File

@@ -80,12 +80,12 @@ class ConvertToWithdrawal implements ActionInterface
return false; return false;
} }
if (TransactionType::DEPOSIT !== $type && TransactionTypeEnum::TRANSFER->value !== $type) { if (TransactionTypeEnum::DEPOSIT->value !== $type && TransactionTypeEnum::TRANSFER->value !== $type) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_withdrawal', ['type' => $type]))); event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.unsupported_transaction_type_withdrawal', ['type' => $type])));
return false; return false;
} }
if (TransactionType::DEPOSIT === $type) { if (TransactionTypeEnum::DEPOSIT->value === $type) {
app('log')->debug('Going to transform a deposit to a withdrawal.'); app('log')->debug('Going to transform a deposit to a withdrawal.');
try { try {
@@ -97,7 +97,7 @@ class ConvertToWithdrawal implements ActionInterface
return false; return false;
} }
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionType::DEPOSIT, TransactionTypeEnum::WITHDRAWAL->value)); event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::WITHDRAWAL->value));
return $res; return $res;
} }

View File

@@ -72,7 +72,7 @@ class SetDestinationAccount implements ActionInterface
// if this is a transfer or a deposit, the new destination account must be an asset account or a default account, and it MUST exist: // if this is a transfer or a deposit, the new destination account must be an asset account or a default account, and it MUST exist:
$newAccount = $this->findAssetAccount($type, $accountName); $newAccount = $this->findAssetAccount($type, $accountName);
if ((TransactionType::DEPOSIT === $type || TransactionTypeEnum::TRANSFER->value === $type) && null === $newAccount) { if ((TransactionTypeEnum::DEPOSIT->value === $type || TransactionTypeEnum::TRANSFER->value === $type) && null === $newAccount) {
app('log')->error( app('log')->error(
sprintf( sprintf(
'Cant change destination account of journal #%d because no asset account with name "%s" exists.', 'Cant change destination account of journal #%d because no asset account with name "%s" exists.',

View File

@@ -111,7 +111,7 @@ class SetSourceAccount implements ActionInterface
// if this is a deposit, the new source account must be a revenue account and may be created: // if this is a deposit, the new source account must be a revenue account and may be created:
// or it's a liability // or it's a liability
if (TransactionType::DEPOSIT === $type) { if (TransactionTypeEnum::DEPOSIT->value === $type) {
$newAccount = $this->findDepositSourceAccount($accountName); $newAccount = $this->findDepositSourceAccount($accountName);
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions; namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray; use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
use FireflyIII\Events\TriggeredAuditLog; use FireflyIII\Events\TriggeredAuditLog;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
@@ -64,7 +65,7 @@ class SetSourceToCashAccount implements ActionInterface
return false; return false;
} }
$type = $object->transactionType->type; $type = $object->transactionType->type;
if (TransactionType::DEPOSIT !== $type) { if (TransactionTypeEnum::DEPOSIT->value !== $type) {
app('log')->error('Transaction must be deposit.'); app('log')->error('Transaction must be deposit.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_deposit'))); event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_deposit')));

View File

@@ -146,7 +146,7 @@ class AccountValidator
break; break;
case TransactionType::DEPOSIT: case TransactionTypeEnum::DEPOSIT->value:
$result = $this->validateDepositDestination($array); $result = $this->validateDepositDestination($array);
break; break;
@@ -191,7 +191,7 @@ class AccountValidator
break; break;
case TransactionType::DEPOSIT: case TransactionTypeEnum::DEPOSIT->value:
$result = $this->validateDepositSource($array); $result = $this->validateDepositSource($array);
break; break;

View File

@@ -237,7 +237,7 @@ trait TransactionValidation
app('log')->debug(sprintf('Amount is %s', $transaction['amount'])); app('log')->debug(sprintf('Amount is %s', $transaction['amount']));
if (TransactionType::DEPOSIT === ucfirst($transactionType)) { if (TransactionTypeEnum::DEPOSIT->value === ucfirst($transactionType)) {
app('log')->debug(sprintf('Processing as a "%s"', $transactionType)); app('log')->debug(sprintf('Processing as a "%s"', $transactionType));
// use case: deposit from liability account to an asset account // use case: deposit from liability account to an asset account
// the foreign amount must be in the currency of the source // the foreign amount must be in the currency of the source

View File

@@ -35,7 +35,7 @@ class TransactionTypeSeeder extends Seeder
{ {
$types = [ $types = [
TransactionType::WITHDRAWAL, TransactionType::WITHDRAWAL,
TransactionType::DEPOSIT, TransactionTypeEnum::DEPOSIT->value,
TransactionType::TRANSFER, TransactionType::TRANSFER,
TransactionType::OPENING_BALANCE, TransactionType::OPENING_BALANCE,
TransactionType::RECONCILIATION, TransactionType::RECONCILIATION,