Skip to content

Firefly III: a personal finances manager

This fixes #422

James Coleb34e4cd31bec
diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php
index 35b221d76b..5bca2ddbd0 100644
--- a/app/Http/Controllers/Chart/CategoryReportController.php
+++ b/app/Http/Controllers/Chart/CategoryReportController.php
@@ -26,7 +26,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
-use Navigation;
use Response;
@@ -273,24 +272,33 @@ class CategoryReportController extends Controller
public function mainChart(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
// determin optimal period:
- $period = '1D';
- $format = 'month_and_day';
+ $period = '1D';
+ $format = 'month_and_day';
+ $function = 'endOfDay';
if ($start->diffInMonths($end) > 1) {
- $period = '1M';
- $format = 'month';
+ $period = '1M';
+ $format = 'month';
+ $function = 'endOfMonth';
}
if ($start->diffInMonths($end) > 13) {
- $period = '1Y';
- $format = 'year';
+ $period = '1Y';
+ $format = 'year';
+ $function = 'endOfYear';
}
Log::debug(sprintf('Period is %s', $period));
- $data = [];
- $current = clone $start;
- while ($current < $end) {
- $currentEnd = Navigation::endOfPeriod($current, $period);
- $expenses = $this->groupByCategory($this->getExpenses($accounts, $categories, $current, $currentEnd));
- $income = $this->groupByCategory($this->getIncome($accounts, $categories, $current, $currentEnd));
- $label = $current->formatLocalized(strval(trans('config.' . $format)));
+ $data = [];
+ $currentStart = clone $start;
+ while ($currentStart < $end) {
+ $currentEnd = clone $currentStart;
+ Log::debug(sprintf('Function is %s', $function));
+ $currentEnd = $currentEnd->$function();
+ //$currentEnd = Navigation::endOfPeriod($current, $period);
+ $expenses = $this->groupByCategory($this->getExpenses($accounts, $categories, $currentStart, $currentEnd));
+ $income = $this->groupByCategory($this->getIncome($accounts, $categories, $currentStart, $currentEnd));
+ $label = $currentStart->formatLocalized(strval(trans('config.' . $format)));
+
+ Log::debug(sprintf('Now grabbing CMC expenses between %s and %s', $currentStart->format('Y-m-d'), $currentEnd->format('Y-m-d')));
+
$data[$label] = [
'in' => [],
'out' => [],
@@ -305,7 +313,8 @@ class CategoryReportController extends Controller
$data[$label]['out'][$categoryId] = $expenses[$categoryId] ?? '0';
}
- $current = Navigation::addPeriod($current, $period, 0);
+ $currentStart = clone $currentEnd;
+ $currentStart->addDay();// = Navigation::addPeriod($current, $period, 0);
}
$data = $this->generator->mainReportChart($data);