From 5c099008e85041e9ef53f96a2b1fdc852d9260c0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 1 Sep 2019 16:52:49 +0200 Subject: [PATCH] Make report budget charts multi-currency --- .../Standard/MultiYearReportGenerator.php | 2 +- .../Controllers/Chart/BudgetController.php | 103 +++++++---- .../Controllers/Chart/CategoryController.php | 16 +- .../Controllers/Chart/ReportController.php | 167 ++++++++---------- .../Budget/NoBudgetRepository.php | 43 +++++ .../Budget/NoBudgetRepositoryInterface.php | 13 ++ .../Budget/OperationsRepositoryInterface.php | 2 - .../Http/Controllers/ChartGeneration.php | 60 ------- public/v1/js/ff/reports/all.js | 3 +- public/v1/js/ff/reports/default/multi-year.js | 3 +- public/v1/js/ff/reports/default/year.js | 3 +- resources/lang/en_US/firefly.php | 1 + .../views/v1/reports/default/multi-year.twig | 13 +- resources/views/v1/reports/default/year.twig | 13 +- routes/web.php | 5 +- 15 files changed, 211 insertions(+), 236 deletions(-) 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 . */ -/** global: budgetPeriodReportUri, categoryExpenseUri, categoryIncomeUri, netWorthUri, opChartUri, sumChartUri */ +/** global: budgetPeriodReportUri, categoryExpenseUri, categoryIncomeUri, netWorthUri, opChartUri */ $(function () { "use strict"; lineChart(netWorthUri, 'net-worth'); columnChartCustomColours(opChartUri, 'income-expenses-chart'); - columnChartCustomColours(sumChartUri, 'income-expenses-sum-chart'); loadAjaxPartial('budgetPeriodReport', budgetPeriodReportUri); loadAjaxPartial('categoryExpense', categoryExpenseUri); diff --git a/public/v1/js/ff/reports/default/year.js b/public/v1/js/ff/reports/default/year.js index 4504d3d810..3745ad9fbc 100644 --- a/public/v1/js/ff/reports/default/year.js +++ b/public/v1/js/ff/reports/default/year.js @@ -18,13 +18,12 @@ * along with Firefly III. If not, see . */ -/** global: budgetPeriodReportUri, categoryExpenseUri, categoryIncomeUri, netWorthUri, opChartUri, sumChartUri */ +/** global: budgetPeriodReportUri, categoryExpenseUri, categoryIncomeUri, netWorthUri, opChartUri */ $(function () { "use strict"; lineChart(netWorthUri, 'net-worth'); columnChartCustomColours(opChartUri, 'income-expenses-chart'); - columnChartCustomColours(sumChartUri, 'income-expenses-sum-chart'); loadAjaxPartial('budgetPeriodReport', budgetPeriodReportUri); loadAjaxPartial('categoryExpense', categoryExpenseUri); diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 26a530d184..c04e921911 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -1434,6 +1434,7 @@ return [ 'box_balance_in_currency' => 'Balance (:currency)', 'box_spent_in_currency' => 'Spent (:currency)', 'box_earned_in_currency' => 'Earned (:currency)', + 'box_budgeted_in_currency' => 'Budgeted (:currency)', 'box_sum_in_currency' => 'Sum (:currency)', 'box_bill_paid_in_currency' => 'Bills paid (:currency)', 'box_bill_unpaid_in_currency' => 'Bills unpaid (:currency)', diff --git a/resources/views/v1/reports/default/multi-year.twig b/resources/views/v1/reports/default/multi-year.twig index 1e842aca29..f8d6adf47e 100644 --- a/resources/views/v1/reports/default/multi-year.twig +++ b/resources/views/v1/reports/default/multi-year.twig @@ -8,7 +8,7 @@ {# charts #}
-
+

{{ 'incomeVsExpenses'|_ }}

@@ -18,16 +18,6 @@
-
-
-
-

{{ 'incomeVsExpenses'|_ }}

-
-
- -
-
-
{# balances and income vs. expense. #} @@ -214,7 +204,6 @@ // report uri's var opChartUri = '{{ route('chart.report.operations', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; - var sumChartUri = '{{ route('chart.report.sum', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; var netWorthUri = '{{ route('chart.report.net-worth', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; // data uri's diff --git a/resources/views/v1/reports/default/year.twig b/resources/views/v1/reports/default/year.twig index 7801cdc3ed..1c4bb2a288 100644 --- a/resources/views/v1/reports/default/year.twig +++ b/resources/views/v1/reports/default/year.twig @@ -8,7 +8,7 @@ {# charts #}
-
+

{{ 'incomeVsExpenses'|_ }}

@@ -18,16 +18,6 @@
-
-
-
-

{{ 'incomeVsExpenses'|_ }}

-
-
- -
-
-
{# balances and inc vs exp #} @@ -208,7 +198,6 @@ // report uri's var opChartUri = '{{ route('chart.report.operations', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; - var sumChartUri = '{{ route('chart.report.sum', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; var netWorthUri = '{{ route('chart.report.net-worth', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}'; // data uri's diff --git a/routes/web.php b/routes/web.php index 3cedcbd4e1..9f77bcdddb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -356,8 +356,8 @@ Route::group( ['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Chart', 'prefix' => 'chart/budget', 'as' => 'chart.budget.'], function () { Route::get('frontpage', ['uses' => 'BudgetController@frontpage', 'as' => 'frontpage']); - Route::get('period/0/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@periodNoBudget', 'as' => 'period.no-budget']); - Route::get('period/{budget}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@period', 'as' => 'period']); + Route::get('period/0/{currency}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@periodNoBudget', 'as' => 'period.no-budget']); + Route::get('period/{budget}/{currency}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@period', 'as' => 'period']); Route::get('budget/{budget}/{budgetLimit}', ['uses' => 'BudgetController@budgetLimit', 'as' => 'budget-limit']); Route::get('budget/{budget}', ['uses' => 'BudgetController@budget', 'as' => 'budget']); @@ -498,7 +498,6 @@ Route::group( Route::group( ['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Chart', 'prefix' => 'chart/report', 'as' => 'chart.report.'], function () { Route::get('operations/{accountList}/{start_date}/{end_date}', ['uses' => 'ReportController@operations', 'as' => 'operations']); - Route::get('operations-sum/{accountList}/{start_date}/{end_date}/', ['uses' => 'ReportController@sum', 'as' => 'sum']); Route::get('net-worth/{accountList}/{start_date}/{end_date}/', ['uses' => 'ReportController@netWorth', 'as' => 'net-worth']); }