Updated chart, closed magic number issue.

This commit is contained in:
James Cole 2015-01-24 08:43:35 +01:00
parent 4ad67a87f1
commit f231263085
5 changed files with 25 additions and 29 deletions

View File

@ -277,19 +277,12 @@ class GoogleChartController extends BaseController
/**
*
* @param Budget $budget
* @param $year
* @param Budget $budget
*
* @return \Illuminate\Http\JsonResponse
*/
public function budgetsAndSpending(Budget $budget, $year)
public function budgetsAndSpending(Budget $budget)
{
try {
new Carbon('01-01-' . $year);
} catch (Exception $e) {
return View::make('error')->with('message', 'Invalid year.');
}
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
@ -297,9 +290,23 @@ class GoogleChartController extends BaseController
$this->_chart->addColumn('Budgeted', 'number');
$this->_chart->addColumn('Spent', 'number');
$start = new Carbon('01-01-' . $year);
$end = clone $start;
$end->endOfYear();
// grab the first budgetlimit ever:
$firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first();
if ($firstLimit) {
$start = new Carbon($firstLimit->startdate);
} else {
$start = Carbon::now()->startOfYear();
}
// grab the last budget limit ever:
$lastLimit = $budget->budgetlimits()->orderBy('startdate', 'DESC')->first();
if ($lastLimit) {
$end = new Carbon($lastLimit->startdate);
} else {
$end = Carbon::now()->endOfYear();
}
while ($start <= $end) {
$spent = $budgetRepository->spentInMonth($budget, $start);
$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);

View File

@ -170,7 +170,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where(
function (QueryBuilder $q) use ($model) {
$q->where('id', $model->id);
$q->where('accounts.id', $model->id);
$q->orWhere(
function (QueryBuilder $q) use ($model) {
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');

View File

@ -222,11 +222,12 @@ Route::group(
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
Route::get('/chart/bills/{bill}', ['uses' => 'GoogleChartController@billOverview']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']);
Route::get('/chart/piggy_history/{piggyBank}', ['uses' => 'GoogleChartController@piggyBankHistory']);
// google chart for components (categories + budgets combined)
Route::get('/chart/budget/{budget}/spending/{year}', ['uses' => 'GoogleChartController@budgetsAndSpending']);
Route::get('/chart/budget/{budget}/spending', ['uses' => 'GoogleChartController@budgetsAndSpending']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']);
Route::get('/chart/category/{category}/spending/{year}', ['uses' => 'GoogleChartController@categoriesAndSpending']);
// help controller

View File

@ -8,7 +8,7 @@ $(function () {
if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') {
googleColumnChart('chart/budget/' + budgetID + '/spending/' + year, 'budgetOverview');
googleColumnChart('chart/budget/' + budgetID + '/spending', 'budgetOverview');
}
if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') {
googleLineChart('chart/budget/' + budgetID + '/' + repetitionID, 'budgetOverview');

View File

@ -108,23 +108,11 @@ class GoogleChartControllerCest
*/
public function budgetsAndSpending(FunctionalTester $I)
{
$year = date('Y');
$I->wantTo('see the chart for a budget in a specific year');
$I->amOnPage('/chart/budget/1/spending/'.$year);
$I->amOnPage('/chart/budget/1/spending');
$I->seeResponseCodeIs(200);
}
/**
* @param FunctionalTester $I
*/
public function budgetsAndSpendingInvalidYear(FunctionalTester $I)
{
$I->wantTo('see the chart for a budget in an invalid year');
$I->amOnPage('/chart/budget/1/spending/XXXX');
$I->seeResponseCodeIs(200);
$I->see('Invalid year');
}
/**
* @param FunctionalTester $I
*/