mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-19 04:49:30 +00:00
Fix test coverage.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user