This commit is contained in:
James Cole 2016-11-25 16:52:43 +01:00
parent 7852b8a785
commit b34e4cd31b

View File

@ -26,7 +26,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Navigation;
use Response;
@ -275,22 +274,31 @@ class CategoryReportController extends Controller
// determin optimal period:
$period = '1D';
$format = 'month_and_day';
$function = 'endOfDay';
if ($start->diffInMonths($end) > 1) {
$period = '1M';
$format = 'month';
$function = 'endOfMonth';
}
if ($start->diffInMonths($end) > 13) {
$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)));
$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);