diff --git a/app/Helpers/Report/PopupReport.php b/app/Helpers/Report/PopupReport.php index e93ef9f56c..1b8ab5a0f3 100644 --- a/app/Helpers/Report/PopupReport.php +++ b/app/Helpers/Report/PopupReport.php @@ -27,6 +27,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Budget; use FireflyIII\Models\Category; use FireflyIII\Models\TransactionType; +use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Log; @@ -97,11 +98,24 @@ class PopupReport implements PopupReportInterface */ public function byBudget(Budget $budget, array $attributes): array { + // filter by currency, if set. + $currencyId = $attributes['currencyId'] ?? null; + $currency = null; + if (null !== $currencyId) { + /** @var CurrencyRepositoryInterface $repos */ + $repos = app(CurrencyRepositoryInterface::class); + $currency = $repos->find((int)$currencyId); + } + + /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); - $collector->setAccounts($attributes['accounts'])->setRange($attributes['startDate'], $attributes['endDate']); + if (null !== $currency) { + $collector->setCurrency($currency); + } + if (null === $budget->id) { $collector->setTypes([TransactionType::WITHDRAWAL])->withoutBudget(); } @@ -122,12 +136,25 @@ class PopupReport implements PopupReportInterface */ public function byCategory(Category $category, array $attributes): array { + // filter by currency, if set. + $currencyId = $attributes['currencyId'] ?? null; + $currency = null; + if (null !== $currencyId) { + /** @var CurrencyRepositoryInterface $repos */ + $repos = app(CurrencyRepositoryInterface::class); + $currency = $repos->find((int)$currencyId); + } + /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); - $collector->setAccounts($attributes['accounts'])->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]) + $collector->setAccounts($attributes['accounts']) + ->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::DEPOSIT]) ->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation() ->setCategory($category); + if (null !== $currency) { + $collector->setCurrency($currency); + } return $collector->getExtractedJournals(); } @@ -142,6 +169,15 @@ class PopupReport implements PopupReportInterface */ public function byExpenses(Account $account, array $attributes): array { + // filter by currency, if set. + $currencyId = $attributes['currencyId'] ?? null; + $currency = null; + if (null !== $currencyId) { + /** @var CurrencyRepositoryInterface $repos */ + $repos = app(CurrencyRepositoryInterface::class); + $currency = $repos->find((int)$currencyId); + } + /** @var JournalRepositoryInterface $repository */ $repository = app(JournalRepositoryInterface::class); $repository->setUser($account->user); @@ -149,20 +185,15 @@ class PopupReport implements PopupReportInterface /** @var GroupCollectorInterface $collector */ $collector = app(GroupCollectorInterface::class); - $collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate']) + $collector->setAccounts(new Collection([$account])) + ->setRange($attributes['startDate'], $attributes['endDate']) ->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]); - $journals = $collector->getExtractedJournals(); - $report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report - $filtered = []; - // TODO not sure if filter is necessary. - /** @var array $journal */ - foreach ($journals as $journal) { - if (in_array($journal['source_account_id'], $report, true)) { - $filtered[] = $journal; - } + if (null !== $currency) { + $collector->setCurrency($currency); } - return $filtered; + + return $collector->getExtractedJournals(); } /** diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index 15956dd034..22b5c32f40 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -69,9 +69,6 @@ class ReportController extends Controller case 'category-entry': $html = $this->categoryEntry($attributes); break; - case 'balance-amount': - $html = $this->balanceAmount($attributes); - break; } return response()->json(['html' => $html]); diff --git a/app/Http/Controllers/Report/BalanceController.php b/app/Http/Controllers/Report/BalanceController.php index 25ac0f23cf..269cf73685 100644 --- a/app/Http/Controllers/Report/BalanceController.php +++ b/app/Http/Controllers/Report/BalanceController.php @@ -59,13 +59,13 @@ class BalanceController extends Controller $helper = app(BalanceReportHelperInterface::class); $report = $helper->getBalanceReport($accounts, $start, $end); // TODO no budget. -// try { + try { $result = view('reports.partials.balance', compact('report'))->render(); // @codeCoverageIgnoreStart -// } catch (Throwable $e) { -// Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage())); -// $result = 'Could not render view.'; -// } + } catch (Throwable $e) { + Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage())); + $result = 'Could not render view.'; + } // @codeCoverageIgnoreEnd $cache->store($result); diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php index 5a2267d475..b97ce71663 100644 --- a/app/Support/Http/Controllers/RenderPartialViews.php +++ b/app/Support/Http/Controllers/RenderPartialViews.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace FireflyIII\Support\Http\Controllers; -use FireflyIII\Helpers\Collection\BalanceLine; use FireflyIII\Helpers\Report\PopupReportInterface; use FireflyIII\Models\AccountType; use FireflyIII\Models\Budget; @@ -76,56 +75,6 @@ trait RenderPartialViews return $result; } - /** - * View for balance row. - * - * @param array $attributes - * - * @return string - * - * - */ - protected function balanceAmount(array $attributes): string // generate view for report. - { - $role = (int)$attributes['role']; - /** @var BudgetRepositoryInterface $budgetRepository */ - $budgetRepository = app(BudgetRepositoryInterface::class); - - /** @var AccountRepositoryInterface $accountRepository */ - $accountRepository = app(AccountRepositoryInterface::class); - - /** @var PopupReportInterface $popupHelper */ - $popupHelper = app(PopupReportInterface::class); - $budget = $budgetRepository->findNull((int)$attributes['budgetId']); - $account = $accountRepository->findNull((int)$attributes['accountId']); - - - switch (true) { - case BalanceLine::ROLE_DEFAULTROLE === $role && null !== $budget && null !== $account: - // normal row with a budget: - $journals = $popupHelper->balanceForBudget($budget, $account, $attributes); - break; - case BalanceLine::ROLE_DEFAULTROLE === $role && null === $budget && null !== $account: - // normal row without a budget: - $budget = new Budget; - $journals = $popupHelper->balanceForNoBudget($account, $attributes); - $budget->name = (string)trans('firefly.no_budget'); - break; - case BalanceLine::ROLE_TAGROLE === $role: - // row with tag info. - return 'Firefly cannot handle this type of info-button (BalanceLine::TagRole)'; - } - // @codeCoverageIgnoreStart - try { - $view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render(); - } catch (Throwable $e) { - Log::error(sprintf('Could not render: %s', $e->getMessage())); - $view = 'Firefly III could not render the view. Please see the log files.'; - } - // @codeCoverageIgnoreEnd - - return $view; - } /** * Get options for budget report. diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index cc627a797e..8ec753a2b6 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -1029,7 +1029,7 @@ return [ 'fiscal_year' => 'Fiscal year', 'income_entry' => 'Income from account ":name" between :start and :end', 'expense_entry' => 'Expenses to account ":name" between :start and :end', - 'category_entry' => 'Expenses in category ":name" between :start and :end', + 'category_entry' => 'Expenses and income in category ":name" between :start and :end', 'budget_spent_amount' => 'Expenses in budget ":budget" between :start and :end', 'balance_amount' => 'Expenses in budget ":budget" paid from account ":account" between :start and :end', 'no_audit_activity' => 'No activity was recorded on account :account_name between :start and :end.', diff --git a/resources/views/v1/popup/list/journals.twig b/resources/views/v1/popup/list/journals.twig index 42f2a0ea59..14dbcb9d0a 100644 --- a/resources/views/v1/popup/list/journals.twig +++ b/resources/views/v1/popup/list/journals.twig @@ -25,9 +25,12 @@ {# Make sum: #} {% set sum = 0 %} + {% set symbol = '' %} + {% set decimal_places =2 %} {% for transaction in journals %} {# add to sum #} - + {% set symbol = transaction.currency_symbol %} + {% set decimal_places = transaction.currency_decimal_places %} {% if transaction.transaction_type_type == 'Withdrawal' %} @@ -134,8 +137,9 @@ {{ 'sum'|_ }}: - {# TODO avoid using formatAmount #} - {{ sum|formatAmount }} + {% if sum != 0 %} + {{ formatAmountBySymbol(sum, symbol, decimal_places) }} + {% endif %} diff --git a/resources/views/v1/popup/report/budget-spent-amount.twig b/resources/views/v1/popup/report/budget-spent-amount.twig index 79b3fc8156..fa88bae9ae 100644 --- a/resources/views/v1/popup/report/budget-spent-amount.twig +++ b/resources/views/v1/popup/report/budget-spent-amount.twig @@ -9,11 +9,6 @@