diff --git a/app/Generator/Report/Standard/MultiYearReportGenerator.php b/app/Generator/Report/Standard/MultiYearReportGenerator.php
index b92b31322f..abd0ba750e 100644
--- a/app/Generator/Report/Standard/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Standard/MultiYearReportGenerator.php
@@ -60,7 +60,7 @@ class MultiYearReportGenerator implements ReportGeneratorInterface
)->with('start', $this->start)->with('end', $this->end)->render();
} catch (Throwable $e) {
Log::error(sprintf('Cannot render reports.default.multi-year: %s', $e->getMessage()));
- $result = 'Could not render report view.';
+ $result = sprintf('Could not render report view: %s', $e->getMessage());
}
return $result;
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index c1eacec02d..0b58a4a137 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -29,6 +29,7 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
+use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -388,16 +389,15 @@ class BudgetController extends Controller
/**
* Shows a budget overview chart (spent and budgeted).
*
- * TODO this chart is not multi-currency aware.
- *
- * @param Budget $budget
- * @param Carbon $start
- * @param Carbon $end
- * @param Collection $accounts
+ * @param Budget $budget
+ * @param TransactionCurrency $currency
+ * @param Collection $accounts
+ * @param Carbon $start
+ * @param Carbon $end
*
* @return JsonResponse
*/
- public function period(Budget $budget, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
+ public function period(Budget $budget, TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
@@ -405,27 +405,52 @@ class BudgetController extends Controller
$cache->addProperty($end);
$cache->addProperty($accounts);
$cache->addProperty($budget->id);
+ $cache->addProperty($currency->id);
$cache->addProperty('chart.budget.period');
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ // return response()->json($cache->get()); // @codeCoverageIgnore
}
- $periods = app('navigation')->listOfPeriods($start, $end);
- $entries = $this->opsRepository->getBudgetPeriodReport(new Collection([$budget]), $accounts, $start, $end); // get the expenses
- $budgeted = $this->getBudgetedInPeriod($budget, $start, $end);
-
- // join them into one set of data:
- $chartData = [
- ['label' => (string)trans('firefly.spent'), 'type' => 'bar', 'entries' => []],
- ['label' => (string)trans('firefly.budgeted'), 'type' => 'bar', 'entries' => []],
+ $titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $chartData = [
+ [
+ 'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
+ 'type' => 'bar',
+ 'entries' => [],
+ 'currency_symbol' => $currency->symbol,
+ ],
+ [
+ 'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
+ 'type' => 'bar',
+ 'currency_symbol' => $currency->symbol,
+ 'entries' => [],
+ ],
];
- foreach (array_keys($periods) as $period) {
- $label = $periods[$period];
- $spent = $entries[$budget->id]['entries'][$period] ?? '0';
- $limit = (int)($budgeted[$period] ?? 0);
- $chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
- $chartData[1]['entries'][$label] = $limit;
+
+ $currentStart = clone $start;
+ while ($currentStart <= $end) {
+ $title = $currentStart->formatLocalized($titleFormat);
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
+
+ // default limit is no limit:
+ $chartData[0]['entries'][$title] = 0;
+ $chartData[1]['entries'][$title] = 0;
+
+
+ // get budget limit in this period for this currency.
+ $limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
+ if (null !== $limit) {
+ $chartData[1]['entries'][$title] = round($limit->amount, $currency->decimal_places);
+ }
+
+ // get spent amount in this period for this currency.
+ $sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency);
+ $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
+ $chartData[0]['entries'][$title] = round($amount, $currency->decimal_places);
+
+ $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
}
+
$data = $this->generator->multiSet($chartData);
$cache->store($data);
@@ -436,37 +461,39 @@ class BudgetController extends Controller
/**
* Shows a chart for transactions without a budget.
*
- * TODO this chart is not multi-currency aware.
- *
- * @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
+ * @param TransactionCurrency $currency
+ * @param Collection $accounts
+ * @param Carbon $start
+ * @param Carbon $end
*
* @return JsonResponse
*/
- public function periodNoBudget(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
+ public function periodNoBudget(TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
+ $cache->addProperty($currency->id);
$cache->addProperty('chart.budget.no-budget');
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ return response()->json($cache->get()); // @codeCoverageIgnore
}
// the expenses:
- $periods = app('navigation')->listOfPeriods($start, $end);
- $entries = $this->nbRepository->getNoBudgetPeriodReport($accounts, $start, $end);
- $chartData = [];
-
- // join them:
- foreach (array_keys($periods) as $period) {
- $label = $periods[$period];
- $spent = $entries['entries'][$period] ?? '0';
- $chartData[$label] = bcmul($spent, '-1');
+ $titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $chartData = [];
+ $currentStart = clone $start;
+ while ($currentStart <= $end) {
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
+ $title = $currentStart->formatLocalized($titleFormat);
+ $sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency);
+ $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
+ $chartData[$title] = round($amount, $currency->decimal_places);
+ $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
}
+
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$cache->store($data);
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 403eec24f3..49ef05285d 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -39,7 +39,6 @@ use FireflyIII\Support\Http\Controllers\ChartGeneration;
use FireflyIII\Support\Http\Controllers\DateCalculation;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
-use Log;
/**
* Class CategoryController.
@@ -275,16 +274,19 @@ class CategoryController extends Controller
// loop income and expenses for this category.:
$outSet = $expenses[$currencyId]['categories'][$category->id] ?? ['transaction_journals' => []];
foreach ($outSet['transaction_journals'] as $journal) {
+ $amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->formatLocalized($format);
$chartData[$outKey]['entries'][$date] = $chartData[$outKey]['entries'][$date] ?? '0';
- $chartData[$outKey]['entries'][$date] = bcadd($journal['amount'], $chartData[$outKey]['entries'][$date]);
+
+ $chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
}
$inSet = $income[$currencyId]['categories'][$category->id] ?? ['transaction_journals' => []];
foreach ($inSet['transaction_journals'] as $journal) {
+ $amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->formatLocalized($format);
$chartData[$inKey]['entries'][$date] = $chartData[$inKey]['entries'][$date] ?? '0';
- $chartData[$inKey]['entries'][$date] = bcadd($journal['amount'], $chartData[$inKey]['entries'][$date]);
+ $chartData[$inKey]['entries'][$date] = bcadd($amount, $chartData[$inKey]['entries'][$date]);
}
}
@@ -313,7 +315,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.period.no-cat');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ //return response()->json($cache->get()); // @codeCoverageIgnore
}
/** @var NoCategoryRepositoryInterface $noCatRepository */
@@ -358,16 +360,18 @@ class CategoryController extends Controller
// loop income and expenses:
$outSet = $expenses[$currencyId] ?? ['transaction_journals' => []];
foreach ($outSet['transaction_journals'] as $journal) {
+ $amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->formatLocalized($format);
$chartData[$outKey]['entries'][$date] = $chartData[$outKey]['entries'][$date] ?? '0';
- $chartData[$outKey]['entries'][$date] = bcadd($journal['amount'], $chartData[$outKey]['entries'][$date]);
+ $chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
}
$inSet = $income[$currencyId] ?? ['transaction_journals' => []];
foreach ($inSet['transaction_journals'] as $journal) {
+ $amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->formatLocalized($format);
$chartData[$inKey]['entries'][$date] = $chartData[$inKey]['entries'][$date] ?? '0';
- $chartData[$inKey]['entries'][$date] = bcadd($journal['amount'], $chartData[$inKey]['entries'][$date]);
+ $chartData[$inKey]['entries'][$date] = bcadd($amount, $chartData[$inKey]['entries'][$date]);
}
}
$data = $this->generator->multiSet($chartData);
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index efd50c17da..25d09ff330 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -24,9 +24,11 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
+use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
@@ -46,6 +48,7 @@ class ReportController extends Controller
/**
* ReportController constructor.
+ *
* @codeCoverageIgnore
*/
public function __construct()
@@ -131,8 +134,6 @@ class ReportController extends Controller
/**
* Shows income and expense, debit/credit: operations.
*
- * TODO this chart is not multi-currency aware.
- *
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
@@ -151,112 +152,84 @@ class ReportController extends Controller
return response()->json($cache->get()); // @codeCoverageIgnore
}
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
- $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
- $source = $this->getChartData($accounts, $start, $end);
- $chartData = [
- [
- 'label' => (string)trans('firefly.income'),
+ $format = app('navigation')->preferredCarbonFormat($start, $end);
+ $titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
+ $ids = $accounts->pluck('id')->toArray();
+
+ // get journals for entire period:
+ $data = [];
+ $chartData = [];
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->setRange($start, $end)->setAccounts($accounts)->withAccountInformation();
+ $journals = $collector->getExtractedJournals();
+
+ // loop. group by currency and by period.
+ /** @var array $journal */
+ foreach ($journals as $journal) {
+ $period = $journal['date']->format($format);
+ $currencyId = (int)$journal['currency_id'];
+ $data[$currencyId] = $data[$currencyId] ?? [
+ 'currency_id' => $currencyId,
+ 'currency_symbol' => $journal['currency_symbol'],
+ 'currency_code' => $journal['currency_symbol'],
+ 'currency_name' => $journal['currency_name'],
+ 'currency_decimal_places' => $journal['currency_decimal_places'],
+ ];
+ $data[$currencyId][$period] = $data[$currencyId][$period] ?? [
+ 'period' => $period,
+ 'spent' => '0',
+ 'earned' => '0',
+ ];
+ // in our outgoing?
+ $key = 'spent';
+ $amount = app('steam')->positive($journal['amount']);
+ if (TransactionType::DEPOSIT === $journal['transaction_type_type']
+ || (TransactionType::TRANSFER === $journal['transaction_type_type']
+ && in_array(
+ $journal['destination_id'], $ids, true
+ ))) {
+ $key = 'earned';
+ }
+ $data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);
+ }
+
+ // loop this data, make chart bars for each currency:
+ /** @var array $currency */
+ foreach ($data as $currency) {
+ $income = [
+ 'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
+ 'currency_id' => $currency['currency_id'],
+ 'currency_symbol' => $currency['currency_symbol'],
'entries' => [],
- ],
- [
- 'label' => (string)trans('firefly.expenses'),
+ ];
+ $expense = [
+ 'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
+ 'currency_id' => $currency['currency_id'],
+ 'currency_symbol' => $currency['currency_symbol'],
'entries' => [],
- ],
- ];
- foreach ($source['earned'] as $date => $amount) {
- $carbon = new Carbon($date);
- $label = $carbon->formatLocalized($format);
- $earned = $chartData[0]['entries'][$label] ?? '0';
- $amount = bcmul($amount, '-1');
- $chartData[0]['entries'][$label] = bcadd($earned, $amount);
- }
- foreach ($source['spent'] as $date => $amount) {
- $carbon = new Carbon($date);
- $label = $carbon->formatLocalized($format);
- $spent = $chartData[1]['entries'][$label] ?? '0';
- $chartData[1]['entries'][$label] = bcadd($spent, $amount);
- }
- $data = $this->generator->multiSet($chartData);
- $cache->store($data);
+ ];
+ // loop all possible periods between $start and $end
+ $currentStart = clone $start;
+ while ($currentStart <= $end) {
+ $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
+ $key = $currentStart->format($format);
+ $title = $currentStart->formatLocalized($titleFormat);
+ $income['entries'][$title] = round($currency[$key]['earned'] ?? '0', $currency['currency_decimal_places']);
+ $expense['entries'][$title] = round($currency[$key]['spent'] ?? '0', $currency['currency_decimal_places']);
- return response()->json($data);
- }
+ $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
+ }
- /**
- * Shows sum income and expense, debit/credit: operations.
- *
- * TODO this chart is not multi-currency aware.
- *
- * @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return \Illuminate\Http\JsonResponse
- *
- */
- public function sum(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
- {
- // chart properties for cache:
- $cache = new CacheProperties;
- $cache->addProperty('chart.report.sum');
- $cache->addProperty($start);
- $cache->addProperty($end);
- $cache->addProperty($accounts);
- if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ $chartData[] = $income;
+ $chartData[] = $expense;
}
- $source = $this->getChartData($accounts, $start, $end);
- $numbers = [
- 'sum_earned' => '0',
- 'avg_earned' => '0',
- 'count_earned' => 0,
- 'sum_spent' => '0',
- 'avg_spent' => '0',
- 'count_spent' => 0,
- ];
- foreach ($source['earned'] as $amount) {
- $amount = bcmul($amount, '-1');
- $numbers['sum_earned'] = bcadd($amount, $numbers['sum_earned']);
- ++$numbers['count_earned'];
- }
- if ($numbers['count_earned'] > 0) {
- $numbers['avg_earned'] = $numbers['sum_earned'] / $numbers['count_earned'];
- }
- foreach ($source['spent'] as $amount) {
- $numbers['sum_spent'] = bcadd($amount, $numbers['sum_spent']);
- ++$numbers['count_spent'];
- }
- if ($numbers['count_spent'] > 0) {
- $numbers['avg_spent'] = $numbers['sum_spent'] / $numbers['count_spent'];
- }
-
- $chartData = [
- [
- 'label' => (string)trans('firefly.income'),
- 'type' => 'bar',
- 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
- 'entries' => [
- (string)trans('firefly.sum_of_period') => $numbers['sum_earned'],
- (string)trans('firefly.average_in_period') => $numbers['avg_earned'],
- ],
- ],
- [
- 'label' => (string)trans('firefly.expenses'),
- 'type' => 'bar',
- 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
- 'entries' => [
- (string)trans('firefly.sum_of_period') => $numbers['sum_spent'],
- (string)trans('firefly.average_in_period') => $numbers['avg_spent'],
- ],
- ],
- ];
-
$data = $this->generator->multiSet($chartData);
$cache->store($data);
diff --git a/app/Repositories/Budget/NoBudgetRepository.php b/app/Repositories/Budget/NoBudgetRepository.php
index 28edbcc594..ec3bddbbb7 100644
--- a/app/Repositories/Budget/NoBudgetRepository.php
+++ b/app/Repositories/Budget/NoBudgetRepository.php
@@ -157,4 +157,47 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
return $return;
}
+
+ /** @noinspection MoreThanThreeArgumentsInspection */
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection|null $accounts
+ * @param TransactionCurrency|null $currency
+ *
+ * @return array
+ */
+ public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array
+ {
+
+ /** @var GroupCollectorInterface $collector */
+ $collector = app(GroupCollectorInterface::class);
+ $collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
+
+ if (null !== $accounts && $accounts->count() > 0) {
+ $collector->setAccounts($accounts);
+ }
+ if (null !== $currency) {
+ $collector->setCurrency($currency);
+ }
+ $collector->withoutBudget();
+ $collector->withBudgetInformation();
+ $journals = $collector->getExtractedJournals();
+ $array = [];
+
+ foreach ($journals as $journal) {
+ $currencyId = (int)$journal['currency_id'];
+ $array[$currencyId] = $array[$currencyId] ?? [
+ 'sum' => '0',
+ 'currency_id' => $currencyId,
+ 'currency_name' => $journal['currency_name'],
+ 'currency_symbol' => $journal['currency_symbol'],
+ 'currency_code' => $journal['currency_code'],
+ 'currency_decimal_places' => $journal['currency_decimal_places'],
+ ];
+ $array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
+ }
+
+ return $array;
+ }
}
\ No newline at end of file
diff --git a/app/Repositories/Budget/NoBudgetRepositoryInterface.php b/app/Repositories/Budget/NoBudgetRepositoryInterface.php
index 0fec42f2df..2c96c43c9e 100644
--- a/app/Repositories/Budget/NoBudgetRepositoryInterface.php
+++ b/app/Repositories/Budget/NoBudgetRepositoryInterface.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon;
+use FireflyIII\Models\TransactionCurrency;
use FireflyIII\User;
use Illuminate\Support\Collection;
@@ -57,4 +58,16 @@ interface NoBudgetRepositoryInterface
* @deprecated
*/
public function spentInPeriodWoBudgetMc(Collection $accounts, Carbon $start, Carbon $end): array;
+
+ /** @noinspection MoreThanThreeArgumentsInspection */
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection|null $accounts
+ * @param TransactionCurrency|null $currency
+ *
+ * @return array
+ */
+ public function sumExpenses(Carbon $start, Carbon $end, ?Collection $accounts = null, ?TransactionCurrency $currency = null): array;
+
}
\ No newline at end of file
diff --git a/app/Repositories/Budget/OperationsRepositoryInterface.php b/app/Repositories/Budget/OperationsRepositoryInterface.php
index e66d5c8809..0e24ab7e2b 100644
--- a/app/Repositories/Budget/OperationsRepositoryInterface.php
+++ b/app/Repositories/Budget/OperationsRepositoryInterface.php
@@ -44,8 +44,6 @@ interface OperationsRepositoryInterface
*/
public function budgetedPerDay(Budget $budget): string;
-
-
/**
* This method collects various info on budgets, used on the budget page and on the index.
*
diff --git a/app/Support/Http/Controllers/ChartGeneration.php b/app/Support/Http/Controllers/ChartGeneration.php
index 7a8bf436c7..3931e9870c 100644
--- a/app/Support/Http/Controllers/ChartGeneration.php
+++ b/app/Support/Http/Controllers/ChartGeneration.php
@@ -102,64 +102,4 @@ trait ChartGeneration
return $data;
}
-
- /**
- * Collects the incomes and expenses for the given periods, grouped per month. Will cache its results.
- *
- * @param Collection $accounts
- * @param Carbon $start
- * @param Carbon $end
- *
- * @return array
- */
- protected function getChartData(Collection $accounts, Carbon $start, Carbon $end): array // chart helper function
- {
- $cache = new CacheProperties;
- $cache->addProperty('chart.report.get-chart-data');
- $cache->addProperty($start);
- $cache->addProperty($accounts);
- $cache->addProperty($end);
- if ($cache->has()) {
- return $cache->get(); // @codeCoverageIgnore
- }
-
- $currentStart = clone $start;
- $spentArray = [];
- $earnedArray = [];
-
- /** @var AccountTaskerInterface $tasker */
- $tasker = app(AccountTaskerInterface::class);
-
- while ($currentStart <= $end) {
- $currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
- $earned = (string)array_sum(
- array_map(
- static function ($item) {
- return $item['sum'];
- },
- $tasker->getIncomeReport($currentStart, $currentEnd, $accounts)['accounts']
- )
- );
- $spent = (string)array_sum(
- array_map(
- static function ($item) {
- return $item['sum'];
- },
- $tasker->getExpenseReport($currentStart, $currentEnd, $accounts)['accounts']
- )
- );
-
- $label = $currentStart->format('Y-m') . '-01';
- $spentArray[$label] = bcmul($spent, '-1');
- $earnedArray[$label] = bcmul($earned, '-1');
- $currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
- }
- $result = [
- 'spent' => $spentArray,
- 'earned' => $earnedArray,
- ];
- $cache->store($result);
-
- return $result;
- }
}
diff --git a/public/v1/js/ff/reports/all.js b/public/v1/js/ff/reports/all.js
index 912539796c..45154d3a18 100644
--- a/public/v1/js/ff/reports/all.js
+++ b/public/v1/js/ff/reports/all.js
@@ -147,9 +147,10 @@ function clickBudgetChart(e) {
"use strict";
var link = $(e.target);
var budgetId = link.data('budget');
+ var currencyId = parseInt(link.data('currency'));
$('#budget_help').remove();
- var URL = 'chart/budget/period/' + budgetId + '/' + accountIds + '/' + startDate + '/' + endDate;
+ var URL = 'chart/budget/period/' + budgetId + '/' + currencyId + '/' + accountIds + '/' + startDate + '/' + endDate;
var container = 'budget_chart';
columnChart(URL, container);
return false;
diff --git a/public/v1/js/ff/reports/default/multi-year.js b/public/v1/js/ff/reports/default/multi-year.js
index 67dc295242..b0793174bf 100644
--- a/public/v1/js/ff/reports/default/multi-year.js
+++ b/public/v1/js/ff/reports/default/multi-year.js
@@ -18,13 +18,12 @@
* along with Firefly III. If not, see