mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Reinstated a chart.
This commit is contained in:
parent
2cd593157f
commit
51d97cdca5
@ -22,10 +22,11 @@ interface BudgetChartGeneratorInterface
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
* @param string $dateFormat
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function budgetLimit(Collection $entries): array;
|
||||
public function budgetLimit(Collection $entries, string $dateFormat): array;
|
||||
|
||||
/**
|
||||
* @param Collection $entries
|
||||
|
@ -18,13 +18,14 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
|
||||
/**
|
||||
*
|
||||
* @param Collection $entries
|
||||
* @param string $dateFormat
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function budgetLimit(Collection $entries): array
|
||||
public function budgetLimit(Collection $entries, string $dateFormat = 'monthAndDay'): array
|
||||
{
|
||||
$language = Preferences::get('language', env('DEFAULT_LANGUAGE', 'en_US'))->data;
|
||||
$format = Config::get('firefly.monthAndDay.' . $language);
|
||||
$format = Config::get('firefly.' . $dateFormat . '.' . $language);
|
||||
|
||||
$data = [
|
||||
'labels' => [],
|
||||
|
@ -37,6 +37,55 @@ class BudgetController extends Controller
|
||||
$this->generator = app('FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function budget(BudgetRepositoryInterface $repository, Budget $budget)
|
||||
{
|
||||
|
||||
// dates and times
|
||||
$first = $repository->getFirstBudgetLimitDate($budget);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$last = session('end', new Carbon);
|
||||
|
||||
// chart properties for cache:
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($first);
|
||||
$cache->addProperty($last);
|
||||
$cache->addProperty('budget');
|
||||
if ($cache->has()) {
|
||||
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$final = clone $last;
|
||||
$final->addYears(2);
|
||||
$last = Navigation::endOfX($last, $range, $final);
|
||||
$entries = new Collection;
|
||||
// get all expenses:
|
||||
$spentArray = $repository->spentPerDay($budget, $first, $last);
|
||||
|
||||
while ($first < $last) {
|
||||
|
||||
// periodspecific dates:
|
||||
$currentStart = Navigation::startOfPeriod($first, $range);
|
||||
$currentEnd = Navigation::endOfPeriod($first, $range);
|
||||
$spent = $this->getSumOfRange($currentStart, $currentEnd, $spentArray);
|
||||
$entry = [$first, ($spent * -1)];
|
||||
|
||||
$entries->push($entry);
|
||||
$first = Navigation::addPeriod($first, $range, 0);
|
||||
}
|
||||
|
||||
$data = $this->generator->budgetLimit($entries, 'month');
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the amount left in a specific budget limit.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user