Start of better budget charts.

This commit is contained in:
James Cole
2016-04-24 20:00:20 +02:00
parent 93421b50f9
commit 2cfbfd8649
9 changed files with 59 additions and 80 deletions

View File

@@ -36,55 +36,6 @@ 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->budget($entries);
$cache->store($data);
return Response::json($data);
}
/**
* Shows the amount left in a specific budget limit.
*

View File

@@ -9,8 +9,6 @@ use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
@@ -313,6 +311,9 @@ class ReportController extends Controller
$expenses = $this->helper->getExpenseReport($start, $end, $accounts);
$tags = $this->helper->tagReport($start, $end, $accounts);
// find the budgets we've spent money on this period with these accounts:
$budgets = $this->budgetHelper->getBudgetsWithExpenses($start, $end, $accounts);
Session::flash('gaEventCategory', 'report');
Session::flash('gaEventAction', 'year');
Session::flash('gaEventLabel', $start->format('Y'));
@@ -329,7 +330,7 @@ class ReportController extends Controller
'reports.default.year',
compact(
'start', 'accountReport', 'incomes', 'reportType', 'accountIds', 'end',
'expenses', 'incomeTopLength', 'expenseTopLength', 'tags'
'expenses', 'incomeTopLength', 'expenseTopLength', 'tags', 'budgets'
)
);
}

View File

@@ -200,9 +200,7 @@ Route::group(
Route::get('/chart/budget/frontpage', ['uses' => 'Chart\BudgetController@frontpage']);
// this chart is used in reports:
Route::get('/chart/budget/year/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\BudgetController@year']);
Route::get('/chart/budget/multi-year/{reportType}/{start_date}/{end_date}/{accountList}/{budgetList}', ['uses' => 'Chart\BudgetController@multiYear']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'Chart\BudgetController@budgetLimit']);
Route::get('/chart/budget/{budget}', ['uses' => 'Chart\BudgetController@budget']);