🤖 Auto commit for release 'develop' on 2025-09-26

This commit is contained in:
JC5
2025-09-26 19:43:39 +02:00
parent 853a99852e
commit d3c557ca22
103 changed files with 1411 additions and 1336 deletions

View File

@@ -67,7 +67,7 @@ class AccountBalanceGrouped
/** @var array $currency */
foreach ($this->data as $currency) {
// income and expense array prepped:
$income = [
$income = [
'label' => 'earned',
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -86,7 +86,7 @@ class AccountBalanceGrouped
'entries' => [],
'pc_entries' => [],
];
$expense = [
$expense = [
'label' => 'spent',
'currency_id' => (string)$currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -108,22 +108,22 @@ class AccountBalanceGrouped
// loop all possible periods between $start and $end, and add them to the correct dataset.
$currentStart = clone $this->start;
while ($currentStart <= $this->end) {
$key = $currentStart->format($this->carbonFormat);
$label = $currentStart->toAtomString();
$key = $currentStart->format($this->carbonFormat);
$label = $currentStart->toAtomString();
// normal entries
$income['entries'][$label] = Steam::bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = Steam::bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
$income['entries'][$label] = Steam::bcround($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
$expense['entries'][$label] = Steam::bcround($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
// converted entries
$income['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_earned'] ?? '0', $currency['primary_currency_decimal_places']);
$expense['pc_entries'][$label] = Steam::bcround($currency[$key]['pc_spent'] ?? '0', $currency['primary_currency_decimal_places']);
// next loop
$currentStart = Navigation::addPeriod($currentStart, $this->preferredRange, 0);
$currentStart = Navigation::addPeriod($currentStart, $this->preferredRange, 0);
}
$chartData[] = $income;
$chartData[] = $expense;
$chartData[] = $income;
$chartData[] = $expense;
}
return $chartData;
@@ -193,7 +193,7 @@ class AccountBalanceGrouped
private function createDefaultDataEntry(array $journal): void
{
$currencyId = (int)$journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
$this->data[$currencyId] ??= [
'currency_id' => (string)$currencyId,
'currency_symbol' => $journal['currency_symbol'],
@@ -210,8 +210,8 @@ class AccountBalanceGrouped
private function createDefaultPeriodEntry(array $journal): void
{
$currencyId = (int)$journal['currency_id'];
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$period = $journal['date']->format($this->carbonFormat);
$this->data[$currencyId][$period] ??= [
'period' => $period,
'spent' => '0',
@@ -268,9 +268,9 @@ class AccountBalanceGrouped
private function processJournal(array $journal): void
{
// format the date according to the period
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$currency = $this->findCurrency($currencyId);
$period = $journal['date']->format($this->carbonFormat);
$currencyId = (int)$journal['currency_id'];
$currency = $this->findCurrency($currencyId);
// set the array with monetary info, if it does not exist.
$this->createDefaultDataEntry($journal);
@@ -278,12 +278,12 @@ class AccountBalanceGrouped
$this->createDefaultPeriodEntry($journal);
// is this journal's amount in- our outgoing?
$key = $this->getDataKey($journal);
$amount = 'spent' === $key ? Steam::negative($journal['amount']) : Steam::positive($journal['amount']);
$key = $this->getDataKey($journal);
$amount = 'spent' === $key ? Steam::negative($journal['amount']) : Steam::positive($journal['amount']);
// get conversion rate
$rate = $this->getRate($currency, $journal['date']);
$amountConverted = bcmul($amount, $rate);
$rate = $this->getRate($currency, $journal['date']);
$amountConverted = bcmul($amount, $rate);
// perhaps transaction already has the foreign amount in the primary currency.
if ((int)$journal['foreign_currency_id'] === $this->primary->id) {
@@ -292,7 +292,7 @@ class AccountBalanceGrouped
}
// add normal entry
$this->data[$currencyId][$period][$key] = bcadd((string)$this->data[$currencyId][$period][$key], $amount);
$this->data[$currencyId][$period][$key] = bcadd((string)$this->data[$currencyId][$period][$key], $amount);
// add converted entry
$convertedKey = sprintf('pc_%s', $key);

View File

@@ -128,7 +128,7 @@ class ExchangeRateConverter
if ($cache->has()) {
return (int)$cache->get();
}
$euro = Amount::getTransactionCurrencyByCode('EUR');
$euro = Amount::getTransactionCurrencyByCode('EUR');
++$this->queryCount;
$cache->store($euro->id);
@@ -144,13 +144,13 @@ class ExchangeRateConverter
if ($euroId === $currency->id) {
return '1';
}
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
if (null !== $rate) {
// app('log')->debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate));
return $rate;
}
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
if (null !== $rate) {
return bcdiv('1', $rate);
// app('log')->debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
@@ -175,7 +175,7 @@ class ExchangeRateConverter
return '1';
}
$key = sprintf('cer-%d-%d-%s', $from, $to, $date);
$key = sprintf('cer-%d-%d-%s', $from, $to, $date);
// perhaps the rate has been cached during this particular run
$preparedRate = $this->prepared[$date][$from][$to] ?? null;
@@ -185,7 +185,7 @@ class ExchangeRateConverter
return $preparedRate;
}
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($key);
if ($cache->has()) {
$rate = $cache->get();
@@ -198,14 +198,15 @@ class ExchangeRateConverter
}
/** @var null|CurrencyExchangeRate $result */
$result = $this->userGroup->currencyExchangeRates()
->where('from_currency_id', $from)
->where('to_currency_id', $to)
->where('date', '<=', $date)
->orderBy('date', 'DESC')
->first();
$result = $this->userGroup->currencyExchangeRates()
->where('from_currency_id', $from)
->where('to_currency_id', $to)
->where('date', '<=', $date)
->orderBy('date', 'DESC')
->first()
;
++$this->queryCount;
$rate = (string)$result?->rate;
$rate = (string)$result?->rate;
if ('' === $rate) {
app('log')->debug(sprintf('ExchangeRateConverter: Found no rate for #%d->#%d (%s) in the DB.', $from, $to, $date));
@@ -241,8 +242,8 @@ class ExchangeRateConverter
*/
private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
{
$key = $this->getCacheKey($from, $to, $date);
$res = Cache::get($key, null);
$key = $this->getCacheKey($from, $to, $date);
$res = Cache::get($key, null);
// find in cache
if (null !== $res) {
@@ -252,7 +253,7 @@ class ExchangeRateConverter
}
// find in database
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($from->id, $to->id, $date->format('Y-m-d'));
if (null !== $rate) {
Cache::forever($key, $rate);
Log::debug(sprintf('ExchangeRateConverter: Return DB rate from %s to %s on %s.', $from->code, $to->code, $date->format('Y-m-d')));
@@ -261,7 +262,7 @@ class ExchangeRateConverter
}
// find reverse in database
$rate = $this->getFromDB($to->id, $from->id, $date->format('Y-m-d'));
$rate = $this->getFromDB($to->id, $from->id, $date->format('Y-m-d'));
if (null !== $rate) {
$rate = bcdiv('1', $rate);
Cache::forever($key, $rate);

View File

@@ -31,7 +31,7 @@ use Illuminate\Support\Facades\Log;
class SummaryBalanceGrouped
{
private const string SUM = 'sum';
private const string SUM = 'sum';
private array $amounts = [];
private array $currencies;
private readonly CurrencyRepositoryInterface $currencyRepository;
@@ -48,9 +48,9 @@ class SummaryBalanceGrouped
public function groupData(): array
{
Log::debug('Now going to group data.');
$return = [];
$return = [];
foreach ($this->keys as $key) {
$title = match ($key) {
$title = match ($key) {
'sum' => 'balance',
'expense' => 'spent',
'income' => 'earned',
@@ -109,11 +109,11 @@ class SummaryBalanceGrouped
/** @var array $journal */
foreach ($journals as $journal) {
// transaction info:
$currencyId = (int)$journal['currency_id'];
$amount = bcmul((string)$journal['amount'], $multiplier);
$currency = $this->currencies[$currencyId] ?? Amount::getTransactionCurrencyById($currencyId);
$this->currencies[$currencyId] = $currency;
$pcAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
$currencyId = (int)$journal['currency_id'];
$amount = bcmul((string)$journal['amount'], $multiplier);
$currency = $this->currencies[$currencyId] ?? Amount::getTransactionCurrencyById($currencyId);
$this->currencies[$currencyId] = $currency;
$pcAmount = $converter->convert($currency, $this->default, $journal['date'], $amount);
if ((int)$journal['foreign_currency_id'] === $this->default->id) {
// use foreign amount instead
$pcAmount = $journal['foreign_amount'];

View File

@@ -59,8 +59,8 @@ trait ValidatesUserGroupTrait
}
/** @var User $user */
$user = auth()->user();
$groupId = 0;
$user = auth()->user();
$groupId = 0;
if (!$request->has('user_group_id')) {
$groupId = (int)$user->user_group_id;
Log::debug(sprintf('validateUserGroup: no user group submitted, use default group #%d.', $groupId));
@@ -71,7 +71,7 @@ trait ValidatesUserGroupTrait
}
/** @var UserGroupRepositoryInterface $repository */
$repository = app(UserGroupRepositoryInterface::class);
$repository = app(UserGroupRepositoryInterface::class);
$repository->setUser($user);
$memberships = $repository->getMembershipsFromGroupId($groupId);
@@ -82,14 +82,14 @@ trait ValidatesUserGroupTrait
}
// need to get the group from the membership:
$group = $repository->getById($groupId);
$group = $repository->getById($groupId);
if (null === $group) {
Log::debug(sprintf('validateUserGroup: group #%d does not exist.', $groupId));
throw new AuthorizationException((string)trans('validation.belongs_user_or_user_group'));
}
Log::debug(sprintf('validateUserGroup: validate access of user to group #%d ("%s").', $groupId, $group->title));
$roles = property_exists($this, 'acceptedRoles') ? $this->acceptedRoles : []; // @phpstan-ignore-line
$roles = property_exists($this, 'acceptedRoles') ? $this->acceptedRoles : []; // @phpstan-ignore-line
if (0 === count($roles)) {
Log::debug('validateUserGroup: no roles defined, so no access.');

View File

@@ -56,10 +56,10 @@ trait AugumentData
/** @var Account $expenseAccount */
foreach ($accounts as $expenseAccount) {
$collection = new Collection();
$collection = new Collection();
$collection->push($expenseAccount);
$revenue = $repository->findByName($expenseAccount->name, [AccountTypeEnum::REVENUE->value]);
$revenue = $repository->findByName($expenseAccount->name, [AccountTypeEnum::REVENUE->value]);
if (null !== $revenue) {
$collection->push($revenue);
}
@@ -116,7 +116,7 @@ trait AugumentData
$return[$accountId] = $grouped[$accountId][0]['name'];
}
}
$return[0] = '(no name)';
$return[0] = '(no name)';
return $return;
}
@@ -136,7 +136,7 @@ trait AugumentData
$return[$budgetId] = $grouped[$budgetId][0]['name'];
}
}
$return[0] = (string)trans('firefly.no_budget');
$return[0] = (string)trans('firefly.no_budget');
return $return;
}
@@ -158,7 +158,7 @@ trait AugumentData
$return[$categoryId] = $grouped[$categoryId][0]['name'];
}
}
$return[0] = (string)trans('firefly.no_category');
$return[0] = (string)trans('firefly.no_category');
return $return;
}
@@ -171,14 +171,14 @@ trait AugumentData
Log::debug('In getLimits');
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$opsRepository = app(OperationsRepositoryInterface::class);
/** @var BudgetLimitRepositoryInterface $blRepository */
$blRepository = app(BudgetLimitRepositoryInterface::class);
$blRepository = app(BudgetLimitRepositoryInterface::class);
$end->endOfMonth();
// properties for cache
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($budget->id);
@@ -189,25 +189,25 @@ trait AugumentData
return $cache->get();
}
$set = $blRepository->getBudgetLimits($budget, $start, $end);
$set = $blRepository->getBudgetLimits($budget, $start, $end);
$budgetCollection = new Collection()->push($budget);
// merge sets based on a key, in case of convert to primary currency
$limits = new Collection();
$limits = new Collection();
/** @var BudgetLimit $entry */
foreach ($set as $entry) {
Log::debug(sprintf('Now at budget limit #%d', $entry->id));
$currency = $entry->transactionCurrency;
$currency = $entry->transactionCurrency;
if ($this->convertToPrimary) {
// the sumExpenses method already handles this.
$currency = $this->primaryCurrency;
}
// clone because these objects change each other.
$currentStart = clone $entry->start_date;
$currentEnd = null === $entry->end_date ? null : clone $entry->end_date;
$currentStart = clone $entry->start_date;
$currentEnd = null === $entry->end_date ? null : clone $entry->end_date;
if (null === $currentEnd) {
$currentEnd = clone $currentStart;
@@ -219,9 +219,9 @@ trait AugumentData
$entry->pc_spent = $spent;
// normal amount:
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency, false);
$spent = $expenses[$entry->transactionCurrency->id]['sum'] ?? '0';
$entry->spent = $spent;
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency, false);
$spent = $expenses[$entry->transactionCurrency->id]['sum'] ?? '0';
$entry->spent = $spent;
$limits->push($entry);
}
@@ -240,7 +240,7 @@ trait AugumentData
/** @var array $journal */
foreach ($array as $journal) {
$name = '(no name)';
$name = '(no name)';
if (TransactionTypeEnum::WITHDRAWAL->value === $journal['transaction_type_type']) {
$name = $journal['destination_account_name'];
}
@@ -263,16 +263,16 @@ trait AugumentData
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$total = $assets->merge($opposing);
$total = $assets->merge($opposing);
$collector->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value])->setAccounts($total);
$journals = $collector->getExtractedJournals();
$sum = [
$journals = $collector->getExtractedJournals();
$sum = [
'grand_sum' => '0',
'per_currency' => [],
];
// loop to support multi currency
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
$currencyId = (int)$journal['currency_id'];
// if not set, set to zero:
if (!array_key_exists($currencyId, $sum['per_currency'])) {

View File

@@ -59,28 +59,28 @@ trait ChartGeneration
return $cache->get();
}
Log::debug('Regenerate chart.account.account-balance-chart from scratch.');
$locale = app('steam')->getLocale();
$locale = app('steam')->getLocale();
/** @var GeneratorInterface $generator */
$generator = app(GeneratorInterface::class);
$generator = app(GeneratorInterface::class);
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
$accountRepos = app(AccountRepositoryInterface::class);
$primary = app('amount')->getPrimaryCurrency();
$chartData = [];
$primary = app('amount')->getPrimaryCurrency();
$chartData = [];
Log::debug(sprintf('Start of accountBalanceChart(list, %s, %s)', $start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')));
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Now at account #%d ("%s)', $account->id, $account->name));
$currency = $accountRepos->getAccountCurrency($account) ?? $primary;
$usePrimary = $convertToPrimary && $primary->id !== $currency->id;
$field = $convertToPrimary ? 'pc_balance' : 'balance';
$currency = $usePrimary ? $primary : $currency;
$currency = $accountRepos->getAccountCurrency($account) ?? $primary;
$usePrimary = $convertToPrimary && $primary->id !== $currency->id;
$field = $convertToPrimary ? 'pc_balance' : 'balance';
$currency = $usePrimary ? $primary : $currency;
Log::debug(sprintf('Will use field %s', $field));
$currentSet = [
$currentSet = [
'label' => $account->name,
'currency_symbol' => $currency->symbol,
'entries' => [],
@@ -91,16 +91,16 @@ trait ChartGeneration
$previous = array_values($range)[0];
Log::debug(sprintf('Start balance for account #%d ("%s) is', $account->id, $account->name), $previous);
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale)));
$balance = $range[$format] ?? $previous;
$previous = $balance;
$format = $currentStart->format('Y-m-d');
$label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale)));
$balance = $range[$format] ?? $previous;
$previous = $balance;
$currentStart->addDay();
$currentSet['entries'][$label] = $balance[$field] ?? '0';
}
$chartData[] = $currentSet;
$chartData[] = $currentSet;
}
$data = $generator->multiSet($chartData);
$data = $generator->multiSet($chartData);
$cache->store($data);
return $data;

View File

@@ -32,6 +32,7 @@ use FireflyIII\User;
use Illuminate\Support\Facades\Log;
use Laravel\Passport\Passport;
use phpseclib3\Crypt\RSA;
use function Safe\file_put_contents;
/**
@@ -103,7 +104,7 @@ trait CreateStuff
return;
}
$key = RSA::createKey(4096);
$key = RSA::createKey(4096);
Log::alert('NO OAuth keys were found. They have been created.');

View File

@@ -90,19 +90,19 @@ trait DateCalculation
protected function getNextPeriods(Carbon $date, string $range): array
{
// select thing for next 12 periods:
$loop = [];
$loop = [];
/** @var Carbon $current */
$current = app('navigation')->startOfPeriod($date, $range);
$current = app('navigation')->endOfPeriod($current, $range);
$current->addDay();
$count = 0;
$count = 0;
while ($count < 12) {
$current = app('navigation')->endOfPeriod($current, $range);
$currentStart = app('navigation')->startOfPeriod($current, $range);
$loop[] = [
$loop[] = [
'label' => $current->format('Y-m-d'),
'title' => app('navigation')->periodShow($current, $range),
'start' => clone $currentStart,
@@ -122,7 +122,7 @@ trait DateCalculation
protected function getPreviousPeriods(Carbon $date, string $range): array
{
// select thing for last 12 periods:
$loop = [];
$loop = [];
/** @var Carbon $current */
$current = app('navigation')->startOfPeriod($date, $range);

View File

@@ -61,13 +61,13 @@ trait GetConfigurationData
$steps = [];
if (is_array($elements) && count($elements) > 0) {
foreach ($elements as $key => $options) {
$currentStep = $options;
$currentStep = $options;
// get the text:
$currentStep['intro'] = (string)trans('intro.' . $route . '_' . $key);
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$key);
// save in array:
$steps[] = $currentStep;
$steps[] = $currentStep;
}
}
app('log')->debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
@@ -82,22 +82,22 @@ trait GetConfigurationData
*/
protected function getDateRangeConfig(): array // get configuration + get preferences.
{
$viewRange = app('navigation')->getViewRange(false);
$viewRange = app('navigation')->getViewRange(false);
Log::debug(sprintf('dateRange: the view range is "%s"', $viewRange));
/** @var Carbon $start */
$start = session('start');
$start = session('start');
/** @var Carbon $end */
$end = session('end');
$end = session('end');
/** @var Carbon $first */
$first = session('first');
$title = sprintf('%s - %s', $start->isoFormat($this->monthAndDayFormat), $end->isoFormat($this->monthAndDayFormat));
$isCustom = true === session('is_custom_range', false);
$today = today(config('app.timezone'));
$ranges = [
$first = session('first');
$title = sprintf('%s - %s', $start->isoFormat($this->monthAndDayFormat), $end->isoFormat($this->monthAndDayFormat));
$isCustom = true === session('is_custom_range', false);
$today = today(config('app.timezone'));
$ranges = [
// first range is the current range:
$title => [$start, $end],
];
@@ -127,10 +127,10 @@ trait GetConfigurationData
// today:
/** @var Carbon $todayStart */
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
$todayStart = app('navigation')->startOfPeriod($today, $viewRange);
/** @var Carbon $todayEnd */
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
$ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd];
@@ -186,16 +186,16 @@ trait GetConfigurationData
// user is on page with specific instructions:
if ('' !== $specificPage) {
$routeKey = str_replace('.', '_', $route);
$elements = config(sprintf('intro.%s', $routeKey . '_' . $specificPage));
$elements = config(sprintf('intro.%s', $routeKey.'_'.$specificPage));
if (is_array($elements) && count($elements) > 0) {
foreach ($elements as $key => $options) {
$currentStep = $options;
$currentStep = $options;
// get the text:
$currentStep['intro'] = (string)trans('intro.' . $route . '_' . $specificPage . '_' . $key);
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$specificPage.'_'.$key);
// save in array:
$steps[] = $currentStep;
$steps[] = $currentStep;
}
}
}

View File

@@ -75,14 +75,14 @@ trait ModelInformation
protected function getLiabilityTypes(): array
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
// types of liability:
/** @var AccountType $debt */
$debt = $repository->getAccountTypeByType(AccountTypeEnum::DEBT->value);
$debt = $repository->getAccountTypeByType(AccountTypeEnum::DEBT->value);
/** @var AccountType $loan */
$loan = $repository->getAccountTypeByType(AccountTypeEnum::LOAN->value);
$loan = $repository->getAccountTypeByType(AccountTypeEnum::LOAN->value);
/** @var AccountType $mortgage */
$mortgage = $repository->getAccountTypeByType(AccountTypeEnum::MORTGAGE->value);
@@ -114,8 +114,8 @@ trait ModelInformation
protected function getTriggersForBill(Bill $bill): array // get info and argument
{
// TODO duplicate code
$operators = config('search.operators');
$triggers = [];
$operators = config('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));
@@ -165,8 +165,8 @@ trait ModelInformation
private function getTriggersForJournal(TransactionJournal $journal): array
{
// TODO duplicated code.
$operators = config('search.operators');
$triggers = [];
$operators = config('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));
@@ -174,18 +174,18 @@ trait ModelInformation
}
asort($triggers);
$result = [];
$journalTriggers = [];
$values = [];
$index = 0;
$result = [];
$journalTriggers = [];
$values = [];
$index = 0;
// amount, description, category, budget, tags, source, destination, notes, currency type
// ,type
/** @var null|Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
$source = $journal->transactions()->where('amount', '<', 0)->first();
/** @var null|Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
$destination = $journal->transactions()->where('amount', '>', 0)->first();
if (null === $destination || null === $source) {
return $result;
}
@@ -220,21 +220,21 @@ trait ModelInformation
++$index;
// category (if)
$category = $journal->categories()->first();
$category = $journal->categories()->first();
if (null !== $category) {
$journalTriggers[$index] = 'category_is';
$values[$index] = $category->name;
++$index;
}
// budget (if)
$budget = $journal->budgets()->first();
$budget = $journal->budgets()->first();
if (null !== $budget) {
$journalTriggers[$index] = 'budget_is';
$values[$index] = $budget->name;
++$index;
}
// tags (if)
$tags = $journal->tags()->get();
$tags = $journal->tags()->get();
/** @var Tag $tag */
foreach ($tags as $tag) {
@@ -243,7 +243,7 @@ trait ModelInformation
++$index;
}
// notes (if)
$notes = $journal->notes()->first();
$notes = $journal->notes()->first();
if (null !== $notes) {
$journalTriggers[$index] = 'notes_is';
$values[$index] = $notes->text;

View File

@@ -88,12 +88,12 @@ trait PeriodOverview
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->periodStatisticRepo = app(PeriodStatisticRepositoryInterface::class);
$range = Navigation::getViewRange(true);
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
/** @var array $dates */
$dates = Navigation::blockPeriods($start, $end, $range);
[$start, $end] = $this->getPeriodFromBlocks($dates, $start, $end);
$this->statistics = $this->periodStatisticRepo->allInRangeForModel($account, $start, $end);
$dates = Navigation::blockPeriods($start, $end, $range);
[$start, $end] = $this->getPeriodFromBlocks($dates, $start, $end);
$this->statistics = $this->periodStatisticRepo->allInRangeForModel($account, $start, $end);
// TODO needs to be re-arranged:
// get all period stats for entire range.
@@ -101,7 +101,7 @@ trait PeriodOverview
// create new ones, or use collected.
$entries = [];
$entries = [];
Log::debug(sprintf('Count of loops: %d', count($dates)));
foreach ($dates as $currentDate) {
$entries[] = $this->getSingleAccountPeriod($account, $currentDate['period'], $currentDate['start'], $currentDate['end']);
@@ -137,11 +137,11 @@ trait PeriodOverview
*/
protected function getCategoryPeriodOverview(Category $category, Carbon $start, Carbon $end): array
{
$range = Navigation::getViewRange(true);
$range = Navigation::getViewRange(true);
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for entries with their amounts.
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($range);
@@ -153,32 +153,32 @@ trait PeriodOverview
}
/** @var array $dates */
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
// collect all expenses in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setCategory($category);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals();
$earnedSet = $collector->getExtractedJournals();
// collect all income in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setCategory($category);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$spentSet = $collector->getExtractedJournals();
$spentSet = $collector->getExtractedJournals();
// collect all transfers in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setCategory($category);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]);
$transferSet = $collector->getExtractedJournals();
$transferSet = $collector->getExtractedJournals();
foreach ($dates as $currentDate) {
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
@@ -186,17 +186,17 @@ trait PeriodOverview
$title = 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),
];
'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);
@@ -212,11 +212,11 @@ trait PeriodOverview
*/
protected function getNoBudgetPeriodOverview(Carbon $start, Carbon $end): array
{
$range = Navigation::getViewRange(true);
$range = Navigation::getViewRange(true);
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToPrimary);
@@ -227,28 +227,28 @@ trait PeriodOverview
}
/** @var array $dates */
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
// get all expenses without a budget.
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->withoutBudget()->withAccountInformation()->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$journals = $collector->getExtractedJournals();
$journals = $collector->getExtractedJournals();
foreach ($dates as $currentDate) {
$set = $this->filterJournalsByDate($journals, $currentDate['start'], $currentDate['end']);
$title = 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' => [],
];
'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);
@@ -265,38 +265,38 @@ trait PeriodOverview
protected function getNoCategoryPeriodOverview(Carbon $theDate): array
{
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
$range = Navigation::getViewRange(true);
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = clone $theDate;
$end = Navigation::endOfPeriod($end, $range);
$range = Navigation::getViewRange(true);
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = clone $theDate;
$end = Navigation::endOfPeriod($end, $range);
Log::debug(sprintf('Start for getNoCategoryPeriodOverview() is %s', $start->format('Y-m-d')));
Log::debug(sprintf('End for getNoCategoryPeriodOverview() is %s', $end->format('Y-m-d')));
// properties for cache
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
// collect all expenses in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->withoutCategory();
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals();
$earnedSet = $collector->getExtractedJournals();
// collect all income in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->withoutCategory();
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$spentSet = $collector->getExtractedJournals();
$spentSet = $collector->getExtractedJournals();
// collect all transfers in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->withoutCategory();
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]);
@@ -310,13 +310,13 @@ trait PeriodOverview
$title = 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),
];
'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');
@@ -333,7 +333,7 @@ trait PeriodOverview
'total_transactions' => 0,
];
foreach ($types as $type) {
$set = $this->getSingleAccountPeriodByType($account, $start, $end, $type);
$set = $this->getSingleAccountPeriodByType($account, $start, $end, $type);
$return['total_transactions'] += $set['count'];
unset($set['count']);
$return[$type] = $set;
@@ -353,6 +353,7 @@ trait PeriodOverview
echo sprintf('End: "%s" vs "%s": %s', $statistic->end->toW3cString(), $end->toW3cString(), var_export($statistic->end->eq($end), true));
var_dump($statistic->end);
var_dump($end);
exit;
}
@@ -398,21 +399,21 @@ trait PeriodOverview
}
// each result must be grouped by currency, then saved as period statistic.
Log::debug(sprintf('Going to group %d found journal(s)', count($result)));
$grouped = $this->groupByCurrency($result);
$grouped = $this->groupByCurrency($result);
$this->saveGroupedAsStatistics($account, $start, $end, $type, $grouped);
return $grouped;
}
$grouped = [
$grouped = [
'count' => 0,
];
/** @var PeriodStatistic $statistic */
foreach ($statistics as $statistic) {
$id = (int)$statistic->transaction_currency_id;
$currency = Amount::getTransactionCurrencyById($id);
$grouped[$id] = [
$id = (int)$statistic->transaction_currency_id;
$currency = Amount::getTransactionCurrencyById($id);
$grouped[$id] = [
'amount' => (string)$statistic->amount,
'count' => (int)$statistic->count,
'currency_id' => $currency->id,
@@ -434,11 +435,11 @@ trait PeriodOverview
*/
protected function getTagPeriodOverview(Tag $tag, Carbon $start, Carbon $end): array // period overview for tags.
{
$range = Navigation::getViewRange(true);
$range = Navigation::getViewRange(true);
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for cache
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('tag-period-entries');
@@ -448,37 +449,37 @@ trait PeriodOverview
}
/** @var array $dates */
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
// collect all expenses in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setTag($tag);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$earnedSet = $collector->getExtractedJournals();
$earnedSet = $collector->getExtractedJournals();
// collect all income in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setTag($tag);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$spentSet = $collector->getExtractedJournals();
$spentSet = $collector->getExtractedJournals();
// collect all transfers in this period:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setTag($tag);
$collector->setRange($start, $end);
$collector->setTypes([TransactionTypeEnum::TRANSFER->value]);
$transferSet = $collector->getExtractedJournals();
$transferSet = $collector->getExtractedJournals();
// filer all of them:
$earnedSet = $this->filterJournalsByTag($earnedSet, $tag);
$spentSet = $this->filterJournalsByTag($spentSet, $tag);
$transferSet = $this->filterJournalsByTag($transferSet, $tag);
$earnedSet = $this->filterJournalsByTag($earnedSet, $tag);
$spentSet = $this->filterJournalsByTag($spentSet, $tag);
$transferSet = $this->filterJournalsByTag($transferSet, $tag);
foreach ($dates as $currentDate) {
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
@@ -487,17 +488,17 @@ trait PeriodOverview
$title = 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),
];
'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;
@@ -508,12 +509,12 @@ trait PeriodOverview
*/
protected function getTransactionPeriodOverview(string $transactionType, Carbon $start, Carbon $end): array
{
$range = Navigation::getViewRange(true);
$types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType));
$range = Navigation::getViewRange(true);
$types = config(sprintf('firefly.transactionTypesByType.%s', $transactionType));
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
// properties for cache
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('transactions-period-entries');
@@ -523,16 +524,16 @@ trait PeriodOverview
}
/** @var array $dates */
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$spent = [];
$earned = [];
$transferred = [];
$dates = Navigation::blockPeriods($start, $end, $range);
$entries = [];
$spent = [];
$earned = [];
$transferred = [];
// collect all journals in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setTypes($types)->setRange($start, $end);
$genericSet = $collector->getExtractedJournals();
$loops = 0;
$genericSet = $collector->getExtractedJournals();
$loops = 0;
foreach ($dates as $currentDate) {
$title = Navigation::periodShow($currentDate['end'], $currentDate['period']);
@@ -550,14 +551,14 @@ 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),
];
= [
'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),
];
++$loops;
}
@@ -598,7 +599,7 @@ trait PeriodOverview
{
$return = [];
foreach ($set as $entry) {
$found = false;
$found = false;
/** @var array $localTag */
foreach ($entry['tags'] as $localTag) {
@@ -713,13 +714,13 @@ trait PeriodOverview
exit;
}
$currencyId = (int)$journal['currency_id'];
$currencyCode = $journal['currency_code'];
$currencyName = $journal['currency_name'];
$currencySymbol = $journal['currency_symbol'];
$currencyDecimalPlaces = $journal['currency_decimal_places'];
$foreignCurrencyId = $journal['foreign_currency_id'];
$amount = $journal['amount'] ?? '0';
$currencyId = (int)$journal['currency_id'];
$currencyCode = $journal['currency_code'];
$currencyName = $journal['currency_name'];
$currencySymbol = $journal['currency_symbol'];
$currencyDecimalPlaces = $journal['currency_decimal_places'];
$foreignCurrencyId = $journal['foreign_currency_id'];
$amount = $journal['amount'] ?? '0';
if ($this->convertToPrimary && $currencyId !== $this->primaryCurrency->id && $foreignCurrencyId !== $this->primaryCurrency->id) {
$amount = $journal['pc_amount'] ?? '0';

View File

@@ -52,20 +52,20 @@ trait RenderPartialViews
protected function budgetEntry(array $attributes): string // generate view for report.
{
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$popupHelper = app(PopupReportInterface::class);
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budget = $budgetRepository->find((int)$attributes['budgetId']);
$accountRepos = app(AccountRepositoryInterface::class);
$account = $accountRepos->find((int)$attributes['accountId']);
$accountRepos = app(AccountRepositoryInterface::class);
$account = $accountRepos->find((int)$attributes['accountId']);
if (null === $budget || null === $account) {
throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.');
}
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
try {
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
@@ -113,14 +113,14 @@ trait RenderPartialViews
$budgetRepository = app(BudgetRepositoryInterface::class);
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$popupHelper = app(PopupReportInterface::class);
$budget = $budgetRepository->find((int)$attributes['budgetId']);
$budget = $budgetRepository->find((int)$attributes['budgetId']);
if (null === $budget) {
// transactions without a budget.
$budget = new Budget();
}
$journals = $popupHelper->byBudget($budget, $attributes);
$journals = $popupHelper->byBudget($budget, $attributes);
try {
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
@@ -142,7 +142,7 @@ trait RenderPartialViews
protected function categoryEntry(array $attributes): string // generate view for report.
{
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$popupHelper = app(PopupReportInterface::class);
/** @var CategoryRepositoryInterface $categoryRepository */
$categoryRepository = app(CategoryRepositoryInterface::class);
@@ -237,15 +237,15 @@ trait RenderPartialViews
$accountRepository = app(AccountRepositoryInterface::class);
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$popupHelper = app(PopupReportInterface::class);
$account = $accountRepository->find((int)$attributes['accountId']);
$account = $accountRepository->find((int)$attributes['accountId']);
if (null === $account) {
return 'This is an unknown account. Apologies.';
}
$journals = $popupHelper->byExpenses($account, $attributes);
$journals = $popupHelper->byExpenses($account, $attributes);
try {
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
@@ -266,8 +266,8 @@ trait RenderPartialViews
*/
protected function getCurrentActions(Rule $rule): array // get info from object and present.
{
$index = 0;
$actions = [];
$index = 0;
$actions = [];
// must be repos
$currentActions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
@@ -306,8 +306,8 @@ trait RenderPartialViews
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
{
// TODO duplicated code.
$operators = config('search.operators');
$triggers = [];
$operators = config('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));
@@ -325,7 +325,7 @@ trait RenderPartialViews
$count = ($index + 1);
try {
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
if (str_starts_with($rootOperator, '-')) {
$rootOperator = substr($rootOperator, 1);
}
@@ -365,14 +365,14 @@ trait RenderPartialViews
$accountRepository = app(AccountRepositoryInterface::class);
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$account = $accountRepository->find((int)$attributes['accountId']);
$popupHelper = app(PopupReportInterface::class);
$account = $accountRepository->find((int)$attributes['accountId']);
if (null === $account) {
return 'This is an unknown category. Apologies.';
}
$journals = $popupHelper->byIncome($account, $attributes);
$journals = $popupHelper->byIncome($account, $attributes);
try {
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();

View File

@@ -35,6 +35,7 @@ use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route as RouteFacade;
use Illuminate\Support\Facades\Validator;
use function Safe\parse_url;
/**
@@ -100,13 +101,13 @@ trait RequestInformation
$page = $this->getPageName();
$specificPage = $this->getSpecificPageName();
// indicator if user has seen the help for this page ( + special page):
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
$key = sprintf('shown_demo_%s%s', $page, $specificPage);
// is there an intro for this route?
$intro = config(sprintf('intro.%s', $page)) ?? [];
$specialIntro = config(sprintf('intro.%s%s', $page, $specificPage)) ?? [];
// some routes have a "what" parameter, which indicates a special page:
$shownDemo = true;
$shownDemo = true;
// both must be array and either must be > 0
if (count($intro) > 0 || count($specialIntro) > 0) {
$shownDemo = app('preferences')->get($key, false)->data;
@@ -127,7 +128,7 @@ trait RequestInformation
$start = session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
return true;
}
@@ -145,20 +146,20 @@ trait RequestInformation
final protected function parseAttributes(array $attributes): array // parse input + return result
{
$attributes['location'] ??= '';
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
if (!$date instanceof Carbon) {
$date = today(config('app.timezone'));
}
$date->startOfMonth();
$attributes['startDate'] = $date;
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
if (!$date2 instanceof Carbon) {
$date2 = today(config('app.timezone'));
}
$date2->endOfDay();
$attributes['endDate'] = $date2;
$attributes['endDate'] = $date2;
return $attributes;
}

View File

@@ -74,8 +74,8 @@ trait RuleManagement
protected function getPreviousTriggers(Request $request): array
{
// TODO duplicated code.
$operators = config('search.operators');
$triggers = [];
$operators = config('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));
@@ -129,7 +129,7 @@ trait RuleManagement
}
asort($triggers);
$index = 0;
$index = 0;
foreach ($submittedOperators as $operator) {
$rootOperator = OperatorQuerySearch::getRootOperator($operator['type']);
$needsContext = (bool)config(sprintf('search.operators.%s.needs_context', $rootOperator));

View File

@@ -39,14 +39,15 @@ trait TransactionCalculation
*/
protected function getExpensesForOpposing(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([TransactionTypeEnum::WITHDRAWAL->value]);
->setRange($start, $end)
->withAccountInformation()
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
;
return $collector->getExtractedJournals();
}
@@ -60,7 +61,8 @@ trait TransactionCalculation
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value])
->setTags($tags)->withAccountInformation();
->setTags($tags)->withAccountInformation()
;
return $collector->getExtractedJournals();
}
@@ -73,7 +75,8 @@ trait TransactionCalculation
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value])
->setBudgets($budgets)->withAccountInformation();
->setBudgets($budgets)->withAccountInformation()
;
return $collector->getExtractedJournals();
}
@@ -90,7 +93,8 @@ trait TransactionCalculation
->setRange($start, $end)
->setTypes([TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value])
->setCategories($categories)
->withAccountInformation();
->withAccountInformation()
;
return $collector->getExtractedJournals();
}
@@ -103,7 +107,8 @@ trait TransactionCalculation
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->setCategories($categories)->withAccountInformation();
->setCategories($categories)->withAccountInformation()
;
return $collector->getExtractedJournals();
}
@@ -113,7 +118,7 @@ trait TransactionCalculation
*/
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);
@@ -130,7 +135,8 @@ trait TransactionCalculation
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value])
->setTags($tags)->withAccountInformation();
->setTags($tags)->withAccountInformation()
;
return $collector->getExtractedJournals();
}

View File

@@ -69,7 +69,7 @@ trait UserNavigation
final protected function isEditableGroup(TransactionGroup $group): bool
{
/** @var null|TransactionJournal $journal */
$journal = $group->transactionJournals()->first();
$journal = $group->transactionJournals()->first();
if (null === $journal) {
return false;
}
@@ -96,10 +96,10 @@ trait UserNavigation
return redirect(route('index'));
}
$journal = $transaction->transactionJournal;
$journal = $transaction->transactionJournal;
/** @var null|Transaction $other */
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
if (null === $other) {
app('log')->error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id));
session()->flash('error', trans('firefly.cant_find_redirect_account'));
@@ -119,7 +119,7 @@ trait UserNavigation
final protected function redirectGroupToAccount(TransactionGroup $group)
{
/** @var null|TransactionJournal $journal */
$journal = $group->transactionJournals()->first();
$journal = $group->transactionJournals()->first();
if (null === $journal) {
app('log')->error(sprintf('No journals in group #%d', $group->id));