mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 16:40:10 +00:00
Code cleanup
This commit is contained in:
@@ -208,7 +208,7 @@ trait AugumentData
|
||||
$cache->addProperty('get-limits');
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$set = $blRepository->getBudgetLimits($budget, $start, $end);
|
||||
|
||||
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use phpseclib3\Crypt\RSA;
|
||||
|
||||
/**
|
||||
* Trait CreateStuff
|
||||
@@ -41,7 +42,7 @@ trait CreateStuff
|
||||
/**
|
||||
* Creates an asset account.
|
||||
*
|
||||
* @param NewUserFormRequest $request
|
||||
* @param NewUserFormRequest $request
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
* @return bool
|
||||
@@ -57,7 +58,7 @@ trait CreateStuff
|
||||
'virtual_balance' => 0,
|
||||
'account_type_id' => null,
|
||||
'active' => true,
|
||||
'account_role' => 'defaultAsset',
|
||||
'account_role' => 'defaultAsset',
|
||||
'opening_balance' => $request->input('bank_balance'),
|
||||
'opening_balance_date' => new Carbon,
|
||||
'currency_id' => $currency->id,
|
||||
@@ -72,7 +73,7 @@ trait CreateStuff
|
||||
* Creates a cash wallet.
|
||||
*
|
||||
* @param TransactionCurrency $currency
|
||||
* @param string $language
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -87,7 +88,7 @@ trait CreateStuff
|
||||
'virtual_balance' => 0,
|
||||
'account_type_id' => null,
|
||||
'active' => true,
|
||||
'account_role' => 'cashWalletAsset',
|
||||
'account_role' => 'cashWalletAsset',
|
||||
'opening_balance' => null,
|
||||
'opening_balance_date' => null,
|
||||
'currency_id' => $currency->id,
|
||||
@@ -109,7 +110,7 @@ trait CreateStuff
|
||||
$keys = $rsa->createKey(4096);
|
||||
}
|
||||
if (8 === PHP_MAJOR_VERSION) {
|
||||
$keys = \phpseclib3\Crypt\RSA::createKeys(4096);
|
||||
$keys = RSA::createKeys(4096);
|
||||
}
|
||||
|
||||
[$publicKey, $privateKey] = [
|
||||
@@ -130,9 +131,9 @@ trait CreateStuff
|
||||
/**
|
||||
* Create a savings account.
|
||||
*
|
||||
* @param NewUserFormRequest $request
|
||||
* @param NewUserFormRequest $request
|
||||
* @param TransactionCurrency $currency
|
||||
* @param string $language
|
||||
* @param string $language
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -162,7 +163,7 @@ trait CreateStuff
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return \FireflyIII\User
|
||||
* @return User
|
||||
*/
|
||||
protected function createUser(array $data): User // create object
|
||||
{
|
||||
|
||||
@@ -33,6 +33,25 @@ use FireflyIII\Support\Cronjobs\TelemetryCronjob;
|
||||
*/
|
||||
trait CronRunner
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function runAutoBudget(): string
|
||||
{
|
||||
/** @var AutoBudgetCronjob $autoBudget */
|
||||
$autoBudget = app(AutoBudgetCronjob::class);
|
||||
try {
|
||||
$result = $autoBudget->fire();
|
||||
} catch (FireflyException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (false === $result) {
|
||||
return 'The auto budget cron job did not fire.';
|
||||
}
|
||||
|
||||
return 'The auto budget cron job fired successfully.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -55,7 +74,8 @@ trait CronRunner
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function runTelemetry(): string {
|
||||
protected function runTelemetry(): string
|
||||
{
|
||||
/** @var TelemetryCronjob $telemetry */
|
||||
$telemetry = app(TelemetryCronjob::class);
|
||||
try {
|
||||
@@ -70,23 +90,4 @@ trait CronRunner
|
||||
return 'The telemetry cron job fired successfully.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function runAutoBudget(): string
|
||||
{
|
||||
/** @var AutoBudgetCronjob $autoBudget */
|
||||
$autoBudget = app(AutoBudgetCronjob::class);
|
||||
try {
|
||||
$result = $autoBudget->fire();
|
||||
} catch (FireflyException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (false === $result) {
|
||||
return 'The auto budget cron job did not fire.';
|
||||
}
|
||||
|
||||
return 'The auto budget cron job fired successfully.';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ trait DateCalculation
|
||||
if ($start->lte($today) && $end->gte($today)) {
|
||||
$difference = $today->diffInDays($end);
|
||||
}
|
||||
|
||||
return 0 === $difference ? 1 : $difference;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ trait GetConfigurationData
|
||||
*/
|
||||
protected function errorReporting(int $value): string // get configuration
|
||||
{
|
||||
$array = [
|
||||
$array = [
|
||||
-1 => 'ALL errors',
|
||||
E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED => 'E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED',
|
||||
E_ALL => 'E_ALL',
|
||||
@@ -51,6 +51,7 @@ trait GetConfigurationData
|
||||
E_ALL & ~E_NOTICE & ~E_STRICT => 'E_ALL & ~E_NOTICE & ~E_STRICT',
|
||||
E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR => 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR',
|
||||
];
|
||||
|
||||
return $array[$value] ?? (string)$value;
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ trait GetConfigurationData
|
||||
*/
|
||||
protected function getDateRangeConfig(): array // get configuration + get preferences.
|
||||
{
|
||||
$viewRange = (string) app('preferences')->get('viewRange', '1M')->data;
|
||||
$viewRange = (string)app('preferences')->get('viewRange', '1M')->data;
|
||||
/** @var Carbon $start */
|
||||
$start = session('start');
|
||||
/** @var Carbon $end */
|
||||
@@ -197,6 +198,7 @@ trait GetConfigurationData
|
||||
|
||||
return $steps;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -86,9 +86,9 @@ trait ModelInformation
|
||||
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$liabilityTypes = [
|
||||
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||
$loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||
$mortgage->id => (string) trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::DEBT)),
|
||||
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::LOAN)),
|
||||
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountType::MORTGAGE)),
|
||||
];
|
||||
asort($liabilityTypes);
|
||||
|
||||
@@ -103,7 +103,7 @@ trait ModelInformation
|
||||
{
|
||||
$roles = [];
|
||||
foreach (config('firefly.accountRoles') as $role) {
|
||||
$roles[$role] = (string) trans(sprintf('firefly.account_role_%s', $role));
|
||||
$roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));
|
||||
}
|
||||
|
||||
return $roles;
|
||||
@@ -124,7 +124,7 @@ trait ModelInformation
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
@@ -133,8 +133,8 @@ trait ModelInformation
|
||||
$billTriggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
|
||||
$values = [
|
||||
$bill->transactionCurrency()->first()->name,
|
||||
round((float) $bill->amount_min, 12),
|
||||
round((float) $bill->amount_max, 12),
|
||||
round((float)$bill->amount_min, 12),
|
||||
round((float)$bill->amount_max, 12),
|
||||
$bill->name,
|
||||
];
|
||||
foreach ($billTriggers as $index => $trigger) {
|
||||
@@ -178,7 +178,7 @@ trait ModelInformation
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
@@ -70,8 +70,8 @@ trait PeriodOverview
|
||||
* performance reasons.
|
||||
*
|
||||
* @param Account $account The account involved
|
||||
* @param Carbon $date The start date.
|
||||
* @param Carbon $end The end date.
|
||||
* @param Carbon $date The start date.
|
||||
* @param Carbon $end The end date.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -124,30 +124,145 @@ trait PeriodOverview
|
||||
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
|
||||
$transferredAway = $this->filterTransferredAway($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||
$transferredIn = $this->filterTransferredIn($account, $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']));
|
||||
$entries[] =
|
||||
[
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('accounts.show', [$account->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||
];
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferredAway) + count($transferredIn),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of journals by a set of dates, and then group them by currency.
|
||||
*
|
||||
* @param array $array
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterJournalsByDate(array $array, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
if ($journal['date'] <= $end && $journal['date'] >= $start) {
|
||||
$result[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterTransferredAway(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['source_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['destination_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (!isset($return[$currencyId])) {
|
||||
$return[$currencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount'] ?? '0');
|
||||
$return[$currencyId]['count']++;
|
||||
|
||||
if (null !== $foreignCurrencyId && null !== $journal['foreign_amount']) {
|
||||
if (!isset($return[$foreignCurrencyId])) {
|
||||
$return[$foreignCurrencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => (int)$foreignCurrencyId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
'currency_code' => $journal['foreign_currency_code'],
|
||||
'currency_symbol' => $journal['foreign_currency_symbol'],
|
||||
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
|
||||
];
|
||||
|
||||
}
|
||||
$return[$foreignCurrencyId]['count']++;
|
||||
$return[$foreignCurrencyId]['amount'] = bcadd($return[$foreignCurrencyId]['amount'], $journal['foreign_amount']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overview for single category. Has been refactored recently.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array
|
||||
@@ -200,17 +315,19 @@ trait PeriodOverview
|
||||
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
|
||||
$transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[] =
|
||||
[
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route('categories.show',
|
||||
[$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
$entries[]
|
||||
= [
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'categories.show',
|
||||
[$category->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
@@ -254,18 +371,18 @@ trait PeriodOverview
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
foreach ($dates as $currentDate) {
|
||||
$set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[] =
|
||||
[
|
||||
'title' => $title,
|
||||
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($set),
|
||||
'spent' => $this->groupByCurrency($set),
|
||||
'earned' => [],
|
||||
'transferred_away' => [],
|
||||
'transferred_in' => [],
|
||||
];
|
||||
$set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('budgets.no-budget', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($set),
|
||||
'spent' => $this->groupByCurrency($set),
|
||||
'earned' => [],
|
||||
'transferred_away' => [],
|
||||
'transferred_in' => [],
|
||||
];
|
||||
}
|
||||
$cache->store($entries);
|
||||
|
||||
@@ -336,15 +453,15 @@ trait PeriodOverview
|
||||
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
|
||||
$transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[] =
|
||||
[
|
||||
'title' => $title,
|
||||
'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' => route('categories.no-category', [$currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
Log::debug('End of loops');
|
||||
$cache->store($entries);
|
||||
@@ -355,7 +472,7 @@ trait PeriodOverview
|
||||
/**
|
||||
* This shows a period overview for a tag. It goes back in time and lists all relevant transactions and sums.
|
||||
*
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
@@ -374,7 +491,7 @@ trait PeriodOverview
|
||||
$cache->addProperty('tag-period-entries');
|
||||
$cache->addProperty($tag->id);
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
/** @var array $dates */
|
||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||
@@ -409,17 +526,19 @@ trait PeriodOverview
|
||||
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
|
||||
$transferred = $this->filterJournalsByDate($transferSet, $currentDate['start'], $currentDate['end']);
|
||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||
$entries[] =
|
||||
[
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route('tags.show',
|
||||
[$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
$entries[]
|
||||
= [
|
||||
'transactions' => 0,
|
||||
'title' => $title,
|
||||
'route' => route(
|
||||
'tags.show',
|
||||
[$tag->id, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]
|
||||
),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
@@ -473,127 +592,18 @@ trait PeriodOverview
|
||||
}
|
||||
|
||||
|
||||
$entries[] =
|
||||
[
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
$entries[]
|
||||
= [
|
||||
'title' => $title,
|
||||
'route' =>
|
||||
route('transactions.index', [$transactionType, $currentDate['start']->format('Y-m-d'), $currentDate['end']->format('Y-m-d')]),
|
||||
'total_transactions' => count($spent) + count($earned) + count($transferred),
|
||||
'spent' => $this->groupByCurrency($spent),
|
||||
'earned' => $this->groupByCurrency($earned),
|
||||
'transferred' => $this->groupByCurrency($transferred),
|
||||
];
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
* @return array
|
||||
*/
|
||||
private function filterTransferredAway(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['source_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return only transactions where $account is the source.
|
||||
* @param Account $account
|
||||
* @param array $journals
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function filterTransferredIn(Account $account, array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if ($account->id === (int)$journal['destination_account_id']) {
|
||||
$return[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter a list of journals by a set of dates, and then group them by currency.
|
||||
*
|
||||
* @param array $array
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @return array
|
||||
*/
|
||||
private function filterJournalsByDate(array $array, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$result = [];
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
if ($journal['date'] <= $end && $journal['date'] >= $start) {
|
||||
$result[] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function groupByCurrency(array $journals): array
|
||||
{
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$foreignCurrencyId = $journal['foreign_currency_id'];
|
||||
if (!isset($return[$currencyId])) {
|
||||
$return[$currencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_name' => $journal['currency_name'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], $journal['amount'] ?? '0');
|
||||
$return[$currencyId]['count']++;
|
||||
|
||||
if (null !== $foreignCurrencyId && null !== $journal['foreign_amount']) {
|
||||
if (!isset($return[$foreignCurrencyId])) {
|
||||
$return[$foreignCurrencyId] = [
|
||||
'amount' => '0',
|
||||
'count' => 0,
|
||||
'currency_id' => (int)$foreignCurrencyId,
|
||||
'currency_name' => $journal['foreign_currency_name'],
|
||||
'currency_code' => $journal['foreign_currency_code'],
|
||||
'currency_symbol' => $journal['foreign_currency_symbol'],
|
||||
'currency_decimal_places' => $journal['foreign_currency_decimal_places'],
|
||||
];
|
||||
|
||||
}
|
||||
$return[$foreignCurrencyId]['count']++;
|
||||
$return[$foreignCurrencyId]['amount'] = bcadd($return[$foreignCurrencyId]['amount'], $journal['foreign_amount']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,50 +45,6 @@ use Throwable;
|
||||
trait RenderPartialViews
|
||||
{
|
||||
|
||||
/**
|
||||
* Get options for double report.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function doubleReportOptions(): string // render a view
|
||||
{
|
||||
/** @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]);
|
||||
$set = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($expense as $account) {
|
||||
// loop revenue, find same account:
|
||||
/** @var Account $otherAccount */
|
||||
foreach ($revenue as $otherAccount) {
|
||||
if (
|
||||
(
|
||||
($otherAccount->name === $account->name)
|
||||
||
|
||||
(null !== $account->iban && null !== $otherAccount->iban && $otherAccount->iban === $account->iban)
|
||||
)
|
||||
&& $otherAccount->id !== $account->id
|
||||
) {
|
||||
$set[] = $account;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = prefixView('reports.options.double', compact('set'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* View for transactions in a budget for an account.
|
||||
*
|
||||
@@ -103,10 +59,10 @@ trait RenderPartialViews
|
||||
|
||||
/** @var BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = app(BudgetRepositoryInterface::class);
|
||||
$budget = $budgetRepository->findNull((int) $attributes['budgetId']);
|
||||
$budget = $budgetRepository->findNull((int)$attributes['budgetId']);
|
||||
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$account = $accountRepos->findNull((int) $attributes['accountId']);
|
||||
$account = $accountRepos->findNull((int)$attributes['accountId']);
|
||||
|
||||
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
|
||||
// @codeCoverageIgnoreStart
|
||||
@@ -160,7 +116,7 @@ trait RenderPartialViews
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$budget = $budgetRepository->findNull((int) $attributes['budgetId']);
|
||||
$budget = $budgetRepository->findNull((int)$attributes['budgetId']);
|
||||
if (null === $budget) {
|
||||
$budget = new Budget;
|
||||
}
|
||||
@@ -192,7 +148,7 @@ trait RenderPartialViews
|
||||
|
||||
/** @var CategoryRepositoryInterface $categoryRepository */
|
||||
$categoryRepository = app(CategoryRepositoryInterface::class);
|
||||
$category = $categoryRepository->findNull((int) $attributes['categoryId']);
|
||||
$category = $categoryRepository->findNull((int)$attributes['categoryId']);
|
||||
$journals = $popupHelper->byCategory($category, $attributes);
|
||||
|
||||
try {
|
||||
@@ -228,6 +184,49 @@ trait RenderPartialViews
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options for double report.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function doubleReportOptions(): string // render a view
|
||||
{
|
||||
/** @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]);
|
||||
$set = [];
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($expense as $account) {
|
||||
// loop revenue, find same account:
|
||||
/** @var Account $otherAccount */
|
||||
foreach ($revenue as $otherAccount) {
|
||||
if (
|
||||
(
|
||||
($otherAccount->name === $account->name)
|
||||
|| (null !== $account->iban && null !== $otherAccount->iban && $otherAccount->iban === $account->iban)
|
||||
)
|
||||
&& $otherAccount->id !== $account->id
|
||||
) {
|
||||
$set[] = $account;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
try {
|
||||
$result = prefixView('reports.options.double', compact('set'))->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
|
||||
$result = 'Could not render view.';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the expenses that went to the given expense account.
|
||||
*
|
||||
@@ -243,7 +242,7 @@ trait RenderPartialViews
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
|
||||
$account = $accountRepository->findNull((int) $attributes['accountId']);
|
||||
$account = $accountRepository->findNull((int)$attributes['accountId']);
|
||||
|
||||
if (null === $account) {
|
||||
return 'This is an unknown account. Apologies.';
|
||||
@@ -317,7 +316,7 @@ trait RenderPartialViews
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
@@ -369,7 +368,7 @@ trait RenderPartialViews
|
||||
|
||||
/** @var PopupReportInterface $popupHelper */
|
||||
$popupHelper = app(PopupReportInterface::class);
|
||||
$account = $accountRepository->findNull((int) $attributes['accountId']);
|
||||
$account = $accountRepository->findNull((int)$attributes['accountId']);
|
||||
|
||||
if (null === $account) {
|
||||
return 'This is an unknown category. Apologies.';
|
||||
|
||||
@@ -98,6 +98,7 @@ trait RequestInformation
|
||||
// also check cache first:
|
||||
if ($help->inCache($route, $language)) {
|
||||
Log::debug(sprintf('Help text %s was in cache.', $language));
|
||||
|
||||
return $help->getFromCache($route, $language);
|
||||
}
|
||||
$baseHref = route('index');
|
||||
@@ -117,6 +118,24 @@ trait RequestInformation
|
||||
return '<p>' . trans('firefly.route_has_no_help') . '</p>'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageName(): string // get request info
|
||||
{
|
||||
return str_replace('.', '_', RouteFacade::currentRouteName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specific name of a page for intro.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSpecificPageName(): string // get request info
|
||||
{
|
||||
return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of triggers.
|
||||
*
|
||||
@@ -152,7 +171,6 @@ trait RequestInformation
|
||||
$specificPage = $this->getSpecificPageName();
|
||||
|
||||
|
||||
|
||||
// indicator if user has seen the help for this page ( + special page):
|
||||
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
|
||||
// is there an intro for this route?
|
||||
@@ -172,24 +190,6 @@ trait RequestInformation
|
||||
return $shownDemo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPageName(): string // get request info
|
||||
{
|
||||
return str_replace('.', '_', RouteFacade::currentRouteName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specific name of a page for intro.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSpecificPageName(): string // get request info
|
||||
{
|
||||
return null === RouteFacade::current()->parameter('objectType') ? '' : '_' . RouteFacade::current()->parameter('objectType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if date is outside session range.
|
||||
*
|
||||
@@ -249,7 +249,7 @@ trait RequestInformation
|
||||
/**
|
||||
* Validate users new password.
|
||||
*
|
||||
* @param User $user
|
||||
* @param User $user
|
||||
* @param string $current
|
||||
* @param string $new
|
||||
*
|
||||
|
||||
@@ -36,8 +36,138 @@ use Throwable;
|
||||
*/
|
||||
trait RuleManagement
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function createDefaultRule(): void
|
||||
{
|
||||
/** @var RuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = app(RuleRepositoryInterface::class);
|
||||
if (0 === $ruleRepository->count()) {
|
||||
$data = [
|
||||
'rule_group_id' => $ruleRepository->getFirstRuleGroup()->id,
|
||||
'stop_processing' => 0,
|
||||
'title' => (string)trans('firefly.default_rule_name'),
|
||||
'description' => (string)trans('firefly.default_rule_description'),
|
||||
'trigger' => 'store-journal',
|
||||
'strict' => true,
|
||||
'active' => true,
|
||||
'triggers' => [
|
||||
[
|
||||
'type' => 'description_is',
|
||||
'value' => (string)trans('firefly.default_rule_trigger_description'),
|
||||
'stop_processing' => false,
|
||||
|
||||
],
|
||||
[
|
||||
'type' => 'from_account_is',
|
||||
'value' => (string)trans('firefly.default_rule_trigger_from_account'),
|
||||
'stop_processing' => false,
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
'actions' => [
|
||||
[
|
||||
'type' => 'prepend_description',
|
||||
'value' => (string)trans('firefly.default_rule_action_prepend'),
|
||||
'stop_processing' => false,
|
||||
],
|
||||
[
|
||||
'type' => 'set_category',
|
||||
'value' => (string)trans('firefly.default_rule_action_set_category'),
|
||||
'stop_processing' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$ruleRepository->store($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousActions(Request $request): array
|
||||
{
|
||||
$index = 0;
|
||||
$triggers = [];
|
||||
$oldInput = $request->old('actions');
|
||||
if (is_array($oldInput)) {
|
||||
foreach ($oldInput as $oldAction) {
|
||||
try {
|
||||
$triggers[] = prefixView(
|
||||
'rules.partials.action',
|
||||
[
|
||||
'oldAction' => $oldAction['type'],
|
||||
'oldValue' => $oldAction['value'],
|
||||
'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
$renderedEntries = [];
|
||||
$oldInput = $request->old('triggers');
|
||||
if (is_array($oldInput)) {
|
||||
foreach ($oldInput as $oldTrigger) {
|
||||
try {
|
||||
$renderedEntries[] = prefixView(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']),
|
||||
'oldValue' => $oldTrigger['value'],
|
||||
'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $submittedOperators
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseFromOperators(array $submittedOperators): array
|
||||
@@ -49,7 +179,7 @@ trait RuleManagement
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
@@ -77,135 +207,6 @@ trait RuleManagement
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function createDefaultRule(): void
|
||||
{
|
||||
/** @var RuleRepositoryInterface $ruleRepository */
|
||||
$ruleRepository = app(RuleRepositoryInterface::class);
|
||||
if (0 === $ruleRepository->count()) {
|
||||
$data = [
|
||||
'rule_group_id' => $ruleRepository->getFirstRuleGroup()->id,
|
||||
'stop_processing' => 0,
|
||||
'title' => (string) trans('firefly.default_rule_name'),
|
||||
'description' => (string) trans('firefly.default_rule_description'),
|
||||
'trigger' => 'store-journal',
|
||||
'strict' => true,
|
||||
'active' => true,
|
||||
'triggers' => [
|
||||
[
|
||||
'type' => 'description_is',
|
||||
'value' => (string) trans('firefly.default_rule_trigger_description'),
|
||||
'stop_processing' => false,
|
||||
|
||||
],
|
||||
[
|
||||
'type' => 'from_account_is',
|
||||
'value' => (string) trans('firefly.default_rule_trigger_from_account'),
|
||||
'stop_processing' => false,
|
||||
|
||||
],
|
||||
|
||||
],
|
||||
'actions' => [
|
||||
[
|
||||
'type' => 'prepend_description',
|
||||
'value' => (string) trans('firefly.default_rule_action_prepend'),
|
||||
'stop_processing' => false,
|
||||
],
|
||||
[
|
||||
'type' => 'set_category',
|
||||
'value' => (string) trans('firefly.default_rule_action_set_category'),
|
||||
'stop_processing' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$ruleRepository->store($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousActions(Request $request): array
|
||||
{
|
||||
$index = 0;
|
||||
$triggers = [];
|
||||
$oldInput = $request->old('actions');
|
||||
if (is_array($oldInput)) {
|
||||
foreach ($oldInput as $oldAction) {
|
||||
try {
|
||||
$triggers[] = prefixView(
|
||||
'rules.partials.action',
|
||||
[
|
||||
'oldAction' => $oldAction['type'],
|
||||
'oldValue' => $oldAction['value'],
|
||||
'oldChecked' => 1 === (int) ($oldAction['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
return $triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function getPreviousTriggers(Request $request): array
|
||||
{
|
||||
// TODO duplicated code.
|
||||
$operators = config('firefly.search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
$index = 0;
|
||||
$renderedEntries = [];
|
||||
$oldInput = $request->old('triggers');
|
||||
if (is_array($oldInput)) {
|
||||
foreach ($oldInput as $oldTrigger) {
|
||||
try {
|
||||
$renderedEntries[] = prefixView(
|
||||
'rules.partials.trigger',
|
||||
[
|
||||
'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']),
|
||||
'oldValue' => $oldTrigger['value'],
|
||||
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
|
||||
'count' => $index + 1,
|
||||
'triggers' => $triggers,
|
||||
]
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
return $renderedEntries;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -215,8 +216,8 @@ trait RuleManagement
|
||||
$repository = app(RuleGroupRepositoryInterface::class);
|
||||
if (0 === $repository->count()) {
|
||||
$data = [
|
||||
'title' => (string) trans('firefly.default_rule_group_name'),
|
||||
'description' => (string) trans('firefly.default_rule_group_description'),
|
||||
'title' => (string)trans('firefly.default_rule_group_name'),
|
||||
'description' => (string)trans('firefly.default_rule_group_description'),
|
||||
'active' => true,
|
||||
];
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $opposing
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -63,8 +63,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
@@ -85,8 +85,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $budgets
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -105,8 +105,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -129,8 +129,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $categories
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -149,14 +149,14 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $opposing
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getIncomeForOpposing(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$total =$accounts->merge($opposing);
|
||||
$total = $accounts->merge($opposing);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($total)->setRange($start, $end)->withAccountInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
@@ -169,8 +169,8 @@ trait TransactionCalculation
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $tags
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,8 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
use Log;
|
||||
@@ -40,6 +42,33 @@ use Log;
|
||||
trait UserNavigation
|
||||
{
|
||||
|
||||
/**
|
||||
* Functionality:.
|
||||
*
|
||||
* - If the $identifier contains the word "delete" then a remembered uri with the text "/show/" in it will not be returned but instead the index (/)
|
||||
* will be returned.
|
||||
* - If the remembered uri contains "jscript/" the remembered uri will not be returned but instead the index (/) will be returned.
|
||||
*
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getPreviousUri(string $identifier): string
|
||||
{
|
||||
Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
|
||||
$uri = (string)session($identifier);
|
||||
Log::debug(sprintf('The URI is %s', $uri));
|
||||
|
||||
if (false !== strpos($uri, 'jscript')) {
|
||||
$uri = $this->redirectUri; // @codeCoverageIgnore
|
||||
Log::debug(sprintf('URI is now %s (uri contains jscript)', $uri));
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Return direct link %s', $uri));
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return false if you cant edit this account type.
|
||||
*
|
||||
@@ -73,38 +102,10 @@ trait UserNavigation
|
||||
return in_array($type, $editable, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
protected function redirectGroupToAccount(TransactionGroup $group)
|
||||
{
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
Log::error(sprintf('No journals in group #%d', $group->id));
|
||||
|
||||
return redirect(route('index'));
|
||||
}
|
||||
// prefer redirect to everything but expense and revenue:
|
||||
$transactions = $journal->transactions;
|
||||
$ignore = [AccountType::REVENUE, AccountType::EXPENSE, AccountType::RECONCILIATION, AccountType::INITIAL_BALANCE];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$type = $transaction->account->accountType->type;
|
||||
if (!in_array($type, $ignore, true)) {
|
||||
return redirect(route('accounts.edit', [$transaction->account_id]));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
protected function redirectAccountToAccount(Account $account)
|
||||
{
|
||||
@@ -136,31 +137,32 @@ trait UserNavigation
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Functionality:.
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* - If the $identifier contains the word "delete" then a remembered uri with the text "/show/" in it will not be returned but instead the index (/)
|
||||
* will be returned.
|
||||
* - If the remembered uri contains "jscript/" the remembered uri will not be returned but instead the index (/) will be returned.
|
||||
*
|
||||
* @param string $identifier
|
||||
*
|
||||
* @return string
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
protected function getPreviousUri(string $identifier): string
|
||||
protected function redirectGroupToAccount(TransactionGroup $group)
|
||||
{
|
||||
Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
|
||||
$uri = (string)session($identifier);
|
||||
Log::debug(sprintf('The URI is %s', $uri));
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $group->transactionJournals()->first();
|
||||
if (null === $journal) {
|
||||
Log::error(sprintf('No journals in group #%d', $group->id));
|
||||
|
||||
if (false !== strpos($uri, 'jscript')) {
|
||||
$uri = $this->redirectUri; // @codeCoverageIgnore
|
||||
Log::debug(sprintf('URI is now %s (uri contains jscript)', $uri));
|
||||
return redirect(route('index'));
|
||||
}
|
||||
// prefer redirect to everything but expense and revenue:
|
||||
$transactions = $journal->transactions;
|
||||
$ignore = [AccountType::REVENUE, AccountType::EXPENSE, AccountType::RECONCILIATION, AccountType::INITIAL_BALANCE];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$type = $transaction->account->accountType->type;
|
||||
if (!in_array($type, $ignore, true)) {
|
||||
return redirect(route('accounts.edit', [$transaction->account_id]));
|
||||
}
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Return direct link %s', $uri));
|
||||
return $uri;
|
||||
return redirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,6 +180,7 @@ trait UserNavigation
|
||||
Log::debug(sprintf('Saving URL %s under key %s', $return, $identifier));
|
||||
session()->put($identifier, $return);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user