Expand view of report and make multi currency

This commit is contained in:
James Cole
2019-09-01 15:23:33 +02:00
parent 1e9f354a81
commit ce06fb73b1
13 changed files with 124 additions and 147 deletions

View File

@@ -81,6 +81,16 @@ class PopupReport implements PopupReportInterface
*/
public function balanceForNoBudget(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 GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector
@@ -91,6 +101,10 @@ class PopupReport implements PopupReportInterface
->setRange($attributes['startDate'], $attributes['endDate'])
->withoutBudget();
if (null !== $currency) {
$collector->setCurrency($currency);
}
return $collector->getExtractedJournals();
}
@@ -139,12 +153,12 @@ class PopupReport implements PopupReportInterface
/**
* Collect journals by a category.
*
* @param Category $category
* @param Category|null $category
* @param array $attributes
*
* @return array
*/
public function byCategory(Category $category, array $attributes): array
public function byCategory(?Category $category, array $attributes): array
{
// filter by currency, if set.
$currencyId = $attributes['currencyId'] ?? null;
@@ -163,8 +177,15 @@ class PopupReport implements PopupReportInterface
->withAccountInformation()
->withBudgetInformation()
->withCategoryInformation()
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation()
->setCategory($category);
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation();
if(null!== $category) {
$collector->setCategory($category);
}
if(null === $category) {
$collector->withoutCategory();
}
if (null !== $currency) {
$collector->setCurrency($currency);
}

View File

@@ -32,6 +32,7 @@ use Illuminate\Support\Collection;
*/
interface PopupReportInterface
{
/**
* Get balances for budget.
*
@@ -66,12 +67,12 @@ interface PopupReportInterface
/**
* Group by category.
*
* @param Category $category
* @param Category|null $category
* @param array $attributes
*
* @return array
*/
public function byCategory(Category $category, array $attributes): array;
public function byCategory(?Category $category, array $attributes): array;
/**
* Do something with expense. Sorry, I am not very inspirational here.