mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
This fixes #422
This commit is contained in:
parent
7852b8a785
commit
b34e4cd31b
@ -26,7 +26,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Navigation;
|
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
|
|
||||||
@ -273,24 +272,33 @@ class CategoryReportController extends Controller
|
|||||||
public function mainChart(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
public function mainChart(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// determin optimal period:
|
// determin optimal period:
|
||||||
$period = '1D';
|
$period = '1D';
|
||||||
$format = 'month_and_day';
|
$format = 'month_and_day';
|
||||||
|
$function = 'endOfDay';
|
||||||
if ($start->diffInMonths($end) > 1) {
|
if ($start->diffInMonths($end) > 1) {
|
||||||
$period = '1M';
|
$period = '1M';
|
||||||
$format = 'month';
|
$format = 'month';
|
||||||
|
$function = 'endOfMonth';
|
||||||
}
|
}
|
||||||
if ($start->diffInMonths($end) > 13) {
|
if ($start->diffInMonths($end) > 13) {
|
||||||
$period = '1Y';
|
$period = '1Y';
|
||||||
$format = 'year';
|
$format = 'year';
|
||||||
|
$function = 'endOfYear';
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('Period is %s', $period));
|
Log::debug(sprintf('Period is %s', $period));
|
||||||
$data = [];
|
$data = [];
|
||||||
$current = clone $start;
|
$currentStart = clone $start;
|
||||||
while ($current < $end) {
|
while ($currentStart < $end) {
|
||||||
$currentEnd = Navigation::endOfPeriod($current, $period);
|
$currentEnd = clone $currentStart;
|
||||||
$expenses = $this->groupByCategory($this->getExpenses($accounts, $categories, $current, $currentEnd));
|
Log::debug(sprintf('Function is %s', $function));
|
||||||
$income = $this->groupByCategory($this->getIncome($accounts, $categories, $current, $currentEnd));
|
$currentEnd = $currentEnd->$function();
|
||||||
$label = $current->formatLocalized(strval(trans('config.' . $format)));
|
//$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] = [
|
$data[$label] = [
|
||||||
'in' => [],
|
'in' => [],
|
||||||
'out' => [],
|
'out' => [],
|
||||||
@ -305,7 +313,8 @@ class CategoryReportController extends Controller
|
|||||||
$data[$label]['out'][$categoryId] = $expenses[$categoryId] ?? '0';
|
$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);
|
$data = $this->generator->mainReportChart($data);
|
||||||
|
Loading…
Reference in New Issue
Block a user