Removed references to components.

This commit is contained in:
James Cole
2014-12-17 21:32:27 +01:00
parent 3c5179f145
commit d49dc599a2
11 changed files with 69 additions and 68 deletions

View File

@@ -251,6 +251,54 @@ class GoogleChartController extends BaseController
} }
/**
* @param Budget $component
* @param $year
*
* @return \Illuminate\Http\JsonResponse
*/
public function budgetsAndSpending(Budget $component, $year)
{
try {
$start = new Carbon('01-01-' . $year);
} catch (Exception $e) {
App::abort(500);
}
/** @var \FireflyIII\Database\Budget\Budget $repos */
$repos = App::make('FireflyIII\Database\Budget\Budget');
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
$chart->addColumn('Month', 'date');
$chart->addColumn('Budgeted', 'number');
$chart->addColumn('Spent', 'number');
$end = clone $start;
$end->endOfYear();
while ($start <= $end) {
$spent = $repos->spentInMonth($component, $start);
$repetition = $repos->repetitionOnStartingOnDate($component, $start);
if ($repetition) {
$budgeted = floatval($repetition->amount);
} else {
$budgeted = null;
}
$chart->addRow(clone $start, $budgeted, $spent);
$start->addMonth();
}
$chart->generate();
return Response::json($chart->getData());
}
/** /**
* @param $year * @param $year
* *
@@ -310,12 +358,12 @@ class GoogleChartController extends BaseController
} }
/** /**
* @param Component $component * @param Category $component
* @param $year * @param $year
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
public function componentsAndSpending(Component $component, $year) public function categoriesAndSpending(Category $component, $year)
{ {
try { try {
$start = new Carbon('01-01-' . $year); $start = new Carbon('01-01-' . $year);
@@ -323,13 +371,8 @@ class GoogleChartController extends BaseController
App::abort(500); App::abort(500);
} }
if ($component->class == 'Budget') { /** @var \FireflyIII\Database\Category\Category $repos */
/** @var \FireflyIII\Database\Budget\Budget $repos */ $repos = App::make('FireflyIII\Database\Category\Category');
$repos = App::make('FireflyIII\Database\Budget\Budget');
} else {
/** @var \FireflyIII\Database\Category\Category $repos */
$repos = App::make('FireflyIII\Database\Category\Category');
}
/** @var \Grumpydictator\Gchart\GChart $chart */ /** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart'); $chart = App::make('gchart');
@@ -341,13 +384,8 @@ class GoogleChartController extends BaseController
$end->endOfYear(); $end->endOfYear();
while ($start <= $end) { while ($start <= $end) {
$spent = $repos->spentInMonth($component, $start); $spent = $repos->spentInMonth($component, $start);
$repetition = $repos->repetitionOnStartingOnDate($component, $start); $budgeted = null;
if ($repetition) {
$budgeted = floatval($repetition->amount);
} else {
$budgeted = null;
}
$chart->addRow(clone $start, $budgeted, $spent); $chart->addRow(clone $start, $budgeted, $spent);

View File

@@ -236,9 +236,9 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
{ {
return \LimitRepetition:: return \LimitRepetition::
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')->leftJoin( leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')->leftJoin(
'components', 'budget_limits.component_id', '=', 'components.id' 'budgets', 'budget_limits.budget_id', '=', 'budgets.id'
)->where('limit_repetitions.startdate', $date->format('Y-m-d'))->where( )->where('limit_repetitions.startdate', $date->format('Y-m-d'))->where(
'components.id', $budget->id 'budgets.id', $budget->id
)->first(['limit_repetitions.*']); )->first(['limit_repetitions.*']);
} }
@@ -254,10 +254,10 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
return $this->getUser()->transactionjournals()->whereNotIn( return $this->getUser()->transactionjournals()->whereNotIn(
'transaction_journals.id', function ($query) use ($start, $end) { 'transaction_journals.id', function ($query) use ($start, $end) {
$query->select('transaction_journals.id')->from('transaction_journals')->leftJoin( $query->select('transaction_journals.id')->from('transaction_journals')->leftJoin(
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' 'budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
)->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->where( )->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id')->where(
'transaction_journals.date', '>=', $start->format('Y-m-d') 'transaction_journals.date', '>=', $start->format('Y-m-d')
)->where('transaction_journals.date', '<=', $end->format('Y-m-d'))->where('components.class', 'Budget'); )->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
} }
)->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->get(); )->before($end)->after($start)->lessThan(0)->transactionTypes(['Withdrawal'])->get();
} }

View File

@@ -117,6 +117,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
\Log::error($model->getErrors()->all()); \Log::error($model->getErrors()->all());
throw new FireflyException('store() transaction journal failed, but it should not!'); throw new FireflyException('store() transaction journal failed, but it should not!');
} }
throw new NotImplementedException('Still have to fix the budget/category change to components.');
$model->save(); $model->save();
/* /*
@@ -147,6 +148,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
/* /*
* Update the budget and the category. * Update the budget and the category.
*/ */
$components = []; $components = [];
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) { if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */ /** @var \FireflyIII\Database\Budget\Budget $budgetRepository */

View File

@@ -63,7 +63,7 @@ class Steam
{ {
$user = \Auth::user(); $user = \Auth::user();
if ($user) { if ($user) {
\BudgetLimit::leftJoin('components', 'components.id', '=', 'budget_limits.component_id')->where('components.user_id', $user->id) \BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')->where('budgets.user_id', $user->id)
->where('budget_limits.amount', 0)->delete(); ->where('budget_limits.amount', 0)->delete();
} }
} }

View File

@@ -13,7 +13,7 @@ class BudgetLimit extends Eloquent
use ValidatingTrait; use ValidatingTrait;
public static $rules public static $rules
= [ = [
'component_id' => 'required|exists:components,id', 'budget_id' => 'required|exists:budgets,id',
'startdate' => 'required|date', 'startdate' => 'required|date',
'amount' => 'numeric|required|min:0.01', 'amount' => 'numeric|required|min:0.01',
'repeats' => 'required|boolean', 'repeats' => 'required|boolean',
@@ -27,7 +27,7 @@ class BudgetLimit extends Eloquent
*/ */
public function budget() public function budget()
{ {
return $this->belongsTo('Budget', 'component_id'); return $this->belongsTo('Budget', 'budget_id');
} }
/** /**

View File

@@ -27,29 +27,6 @@ class Transaction extends Eloquent
return $this->belongsTo('Account'); return $this->belongsTo('Account');
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function budgets()
{
return $this->belongsToMany('Budget', 'component_transaction', 'transaction_id', 'component_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function categories()
{
return $this->belongsToMany('Category', 'component_transaction', 'transaction_id', 'component_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function components()
{
return $this->belongsToMany('Component');
}
/** /**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo * @return \Illuminate\Database\Eloquent\Relations\BelongsTo

View File

@@ -42,13 +42,6 @@ class TransactionJournal extends Eloquent
); );
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function components()
{
return $this->belongsToMany('Component');
}
/** /**
* TODO remove this method in favour of something in the FireflyIII libraries. * TODO remove this method in favour of something in the FireflyIII libraries.
@@ -208,9 +201,7 @@ class TransactionJournal extends Eloquent
$query->with( $query->with(
['transactions' => function ($q) { ['transactions' => function ($q) {
$q->orderBy('amount', 'ASC'); $q->orderBy('amount', 'ASC');
}, 'transactiontype', 'components' => function ($q) { }, 'transactiontype', 'budgets','categories', 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories']
$q->orderBy('class');
}, 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories']
); );
} }

View File

@@ -51,14 +51,6 @@ class User extends Eloquent implements UserInterface, RemindableInterface
return $this->hasMany('Category'); return $this->hasMany('Category');
} }
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function components()
{
return $this->hasMany('Component');
}
/** /**
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/ */

View File

@@ -185,7 +185,8 @@ Route::group(
Route::get('/chart/piggyhistory/{piggybank}', ['uses' => 'GoogleChartController@piggyBankHistory']); Route::get('/chart/piggyhistory/{piggybank}', ['uses' => 'GoogleChartController@piggyBankHistory']);
// google chart for components (categories + budgets combined) // google chart for components (categories + budgets combined)
Route::get('/chart/component/{component}/spending/{year}', ['uses' => 'GoogleChartController@componentsAndSpending']); Route::get('/chart/budget/{budget}/spending/{year}', ['uses' => 'GoogleChartController@budgetsAndSpending']);
Route::get('/chart/category/{category}/spending/{year}', ['uses' => 'GoogleChartController@categoriesAndSpending']);
// help controller // help controller
Route::get('/help/{route}', ['uses' => 'HelpController@show', 'as' => 'help.show']); Route::get('/help/{route}', ['uses' => 'HelpController@show', 'as' => 'help.show']);

View File

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

View File

@@ -1,7 +1,7 @@
$(function () { $(function () {
if (typeof componentID != 'undefined' && typeof repetitionID == 'undefined') { if (typeof componentID != 'undefined' && typeof repetitionID == 'undefined') {
googleColumnChart('chart/component/' + componentID + '/spending/' + year, 'componentOverview'); googleColumnChart('chart/category/' + componentID + '/spending/' + year, 'componentOverview');
} }