mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 06:51:08 +00:00
Code for #916
This commit is contained in:
@@ -74,17 +74,17 @@ class BudgetController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function budget(Budget $budget)
|
public function budget(Budget $budget)
|
||||||
{
|
{
|
||||||
$first = $this->repository->firstUseDate($budget);
|
$first = $this->repository->firstUseDate($budget);
|
||||||
$range = Preferences::get('viewRange', '1M')->data;
|
$range = Preferences::get('viewRange', '1M')->data;
|
||||||
$last = session('end', new Carbon);
|
$currentStart = Navigation::startOfPeriod($first, $range);
|
||||||
|
$last = session('end', new Carbon);
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($first);
|
$cache->addProperty($first);
|
||||||
$cache->addProperty($last);
|
$cache->addProperty($last);
|
||||||
$cache->addProperty('chart.budget.budget');
|
$cache->addProperty('chart.budget.budget');
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$final = clone $last;
|
$final = clone $last;
|
||||||
@@ -92,17 +92,16 @@ class BudgetController extends Controller
|
|||||||
$budgetCollection = new Collection([$budget]);
|
$budgetCollection = new Collection([$budget]);
|
||||||
$last = Navigation::endOfX($last, $range, $final); // not to overshoot.
|
$last = Navigation::endOfX($last, $range, $final); // not to overshoot.
|
||||||
$entries = [];
|
$entries = [];
|
||||||
while ($first < $last) {
|
while ($currentStart < $last) {
|
||||||
|
|
||||||
// periodspecific dates:
|
// periodspecific dates:
|
||||||
$currentStart = Navigation::startOfPeriod($first, $range);
|
$currentEnd = Navigation::endOfPeriod($currentStart, $range);
|
||||||
$currentEnd = Navigation::endOfPeriod($first, $range);
|
|
||||||
// sub another day because reasons.
|
// sub another day because reasons.
|
||||||
$currentEnd->subDay();
|
$currentEnd->subDay();
|
||||||
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
|
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
|
||||||
$format = Navigation::periodShow($first, $range);
|
$format = Navigation::periodShow($currentStart, $range);
|
||||||
$entries[$format] = bcmul($spent, '-1');
|
$entries[$format] = bcmul($spent, '-1');
|
||||||
$first = Navigation::addPeriod($first, $range, 0);
|
$currentStart = clone $currentEnd;
|
||||||
|
$currentStart->addDays(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $entries);
|
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $entries);
|
||||||
@@ -244,6 +243,7 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
$data = $this->generator->pieChart($chartData);
|
$data = $this->generator->pieChart($chartData);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -215,14 +215,15 @@ class Navigation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Carbon\Carbon $date
|
* @param \Carbon\Carbon $theDate
|
||||||
* @param $repeatFrequency
|
* @param $repeatFrequency
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function periodShow(Carbon $date, string $repeatFrequency): string
|
public function periodShow(Carbon $theDate, string $repeatFrequency): string
|
||||||
{
|
{
|
||||||
|
$date = clone $theDate;
|
||||||
$formatMap = [
|
$formatMap = [
|
||||||
'1D' => trans('config.specific_day'),
|
'1D' => trans('config.specific_day'),
|
||||||
'daily' => trans('config.specific_day'),
|
'daily' => trans('config.specific_day'),
|
||||||
|
Reference in New Issue
Block a user