mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Updated chart, closed magic number issue.
This commit is contained in:
@@ -277,19 +277,12 @@ class GoogleChartController extends BaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param $year
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @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 */
|
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
|
||||||
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
|
$budgetRepository = App::make('FireflyIII\Database\Budget\Budget');
|
||||||
|
|
||||||
@@ -297,9 +290,23 @@ class GoogleChartController extends BaseController
|
|||||||
$this->_chart->addColumn('Budgeted', 'number');
|
$this->_chart->addColumn('Budgeted', 'number');
|
||||||
$this->_chart->addColumn('Spent', 'number');
|
$this->_chart->addColumn('Spent', 'number');
|
||||||
|
|
||||||
$start = new Carbon('01-01-' . $year);
|
// grab the first budgetlimit ever:
|
||||||
$end = clone $start;
|
$firstLimit = $budget->budgetlimits()->orderBy('startdate', 'ASC')->first();
|
||||||
$end->endOfYear();
|
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) {
|
while ($start <= $end) {
|
||||||
$spent = $budgetRepository->spentInMonth($budget, $start);
|
$spent = $budgetRepository->spentInMonth($budget, $start);
|
||||||
$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
|
$repetition = $budgetRepository->repetitionOnStartingOnDate($budget, $start);
|
||||||
|
@@ -170,7 +170,7 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||||
->where(
|
->where(
|
||||||
function (QueryBuilder $q) use ($model) {
|
function (QueryBuilder $q) use ($model) {
|
||||||
$q->where('id', $model->id);
|
$q->where('accounts.id', $model->id);
|
||||||
$q->orWhere(
|
$q->orWhere(
|
||||||
function (QueryBuilder $q) use ($model) {
|
function (QueryBuilder $q) use ($model) {
|
||||||
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
$q->where('accounts.name', 'LIKE', '%' . $model->name . '%');
|
||||||
|
@@ -222,11 +222,12 @@ Route::group(
|
|||||||
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
|
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
|
||||||
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
|
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
|
||||||
Route::get('/chart/bills/{bill}', ['uses' => 'GoogleChartController@billOverview']);
|
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']);
|
Route::get('/chart/piggy_history/{piggyBank}', ['uses' => 'GoogleChartController@piggyBankHistory']);
|
||||||
|
|
||||||
// google chart for components (categories + budgets combined)
|
// 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']);
|
Route::get('/chart/category/{category}/spending/{year}', ['uses' => 'GoogleChartController@categoriesAndSpending']);
|
||||||
|
|
||||||
// help controller
|
// help controller
|
||||||
|
@@ -8,7 +8,7 @@ $(function () {
|
|||||||
|
|
||||||
|
|
||||||
if (typeof budgetID != 'undefined' && typeof repetitionID == 'undefined') {
|
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') {
|
if (typeof budgetID != 'undefined' && typeof repetitionID != 'undefined') {
|
||||||
googleLineChart('chart/budget/' + budgetID + '/' + repetitionID, 'budgetOverview');
|
googleLineChart('chart/budget/' + budgetID + '/' + repetitionID, 'budgetOverview');
|
||||||
|
@@ -108,23 +108,11 @@ class GoogleChartControllerCest
|
|||||||
*/
|
*/
|
||||||
public function budgetsAndSpending(FunctionalTester $I)
|
public function budgetsAndSpending(FunctionalTester $I)
|
||||||
{
|
{
|
||||||
$year = date('Y');
|
|
||||||
$I->wantTo('see the chart for a budget in a specific year');
|
$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);
|
$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
|
* @param FunctionalTester $I
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user