Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Reinstated a chart.
James Cole51d97cdca505
diff --git a/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php b/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.phpindex 0d4e056673..fa418d3fd6 100644--- a/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php+++ b/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php@@ -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 $entriesdiff --git a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.phpindex 7da18e57ac..9d4adf812d 100644--- a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php+++ b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php@@ -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' => [],diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex e4fca45a10..dbabcbae5c 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -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.*