Skip to content

Firefly III: a personal finances manager

Removed references to components.

James Coled49dc599a237
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index 6c51ad393c..638da44256 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -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
*
@@ -310,12 +358,12 @@ class GoogleChartController extends BaseController
}
/**
- * @param Component $component
+ * @param Category $component
* @param $year
*
* @return \Illuminate\Http\JsonResponse
*/
- public function componentsAndSpending(Component $component, $year)
+ public function categoriesAndSpending(Category $component, $year)
{
try {
$start = new Carbon('01-01-' . $year);
@@ -323,13 +371,8 @@ class GoogleChartController extends BaseController
App::abort(500);
}
- if ($component->class == 'Budget') {
- /** @var \FireflyIII\Database\Budget\Budget $repos */
- $repos = App::make('FireflyIII\Database\Budget\Budget');
- } else {
- /** @var \FireflyIII\Database\Category\Category $repos */
- $repos = App::make('FireflyIII\Database\Category\Category');
- }
+ /** @var \FireflyIII\Database\Category\Category $repos */
+ $repos = App::make('FireflyIII\Database\Category\Category');
/** @var \Grumpydictator\Gchart\GChart $chart */
$chart = App::make('gchart');
@@ -341,13 +384,8 @@ class GoogleChartController extends BaseController
$end->endOfYear();
while ($start <= $end) {
- $spent = $repos->spentInMonth($component, $start);
- $repetition = $repos->repetitionOnStartingOnDate($component, $start);
- if ($repetition) {
- $budgeted = floatval($repetition->amount);
- } else {
- $budgeted = null;
- }
+ $spent = $repos->spentInMonth($component, $start);
+ $budgeted = null;
$chart->addRow(clone $start, $budgeted, $spent);
diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php
index 36db79efba..dce5882442 100644
--- a/app/lib/FireflyIII/Database/Budget/Budget.php
+++ b/app/lib/FireflyIII/Database/Budget/Budget.php
@@ -236,9 +236,9 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
{
return \LimitRepetition::
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(
- 'components.id', $budget->id
+ 'budgets.id', $budget->id
)->first(['limit_repetitions.*']);
}
@@ -254,10 +254,10 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface
return $this->getUser()->transactionjournals()->whereNotIn(
'transaction_journals.id', function ($query) use ($start, $end) {
$query->select('transaction_journals.id')->from('transaction_journals')->leftJoin(
- 'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
- )->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')->where(
+ 'budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
+ )->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id')->where(
'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();
}
diff --git a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
index e32d1280db..edce5b6e43 100644
--- a/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
+++ b/app/lib/FireflyIII/Database/TransactionJournal/TransactionJournal.php
@@ -117,6 +117,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
\Log::error($model->getErrors()->all());
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();
/*
@@ -147,6 +148,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData
/*
* Update the budget and the category.
*/
+
$components = [];
if (isset($data['budget_id']) && intval($data['budget_id']) > 0) {
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
diff --git a/app/lib/FireflyIII/Shared/Toolkit/Steam.php b/app/lib/FireflyIII/Shared/Toolkit/Steam.php
index d1d0c9e0cd..e47ff266d9 100644
--- a/app/lib/FireflyIII/Shared/Toolkit/Steam.php
+++ b/app/lib/FireflyIII/Shared/Toolkit/Steam.php
@@ -63,7 +63,7 @@ class Steam
{
$user = \Auth::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();
}
}
diff --git a/app/models/BudgetLimit.php b/app/models/BudgetLimit.php
index 148d6e6081..2f260410e6 100644
--- a/app/models/BudgetLimit.php
+++ b/app/models/BudgetLimit.php
@@ -13,7 +13,7 @@ class BudgetLimit extends Eloquent
use ValidatingTrait;
public static $rules
= [
- 'component_id' => 'required|exists:components,id',
+ 'budget_id' => 'required|exists:budgets,id',
'startdate' => 'required|date',
'amount' => 'numeric|required|min:0.01',
'repeats' => 'required|boolean',
@@ -27,7 +27,7 @@ class BudgetLimit extends Eloquent
*/
public function budget()
{
- return $this->belongsTo('Budget', 'component_id');
+ return $this->belongsTo('Budget', 'budget_id');
}
/**
diff --git a/app/models/Transaction.php b/app/models/Transaction.php
index 5ecaa7a2df..5014fd3ce3 100644
--- a/app/models/Transaction.php
+++ b/app/models/Transaction.php
@@ -27,29 +27,6 @@ class Transaction extends Eloquent
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
diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php
index c9c8516224..61b24066ca 100644
--- a/app/models/TransactionJournal.php
+++ b/app/models/TransactionJournal.php
@@ -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.
@@ -208,9 +201,7 @@ class TransactionJournal extends Eloquent
$query->with(
['transactions' => function ($q) {
$q->orderBy('amount', 'ASC');
- }, 'transactiontype', 'components' => function ($q) {
- $q->orderBy('class');
- }, 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories']
+ }, 'transactiontype', 'budgets','categories', 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories']
);
}
diff --git a/app/models/User.php b/app/models/User.php
index 553620bd9a..dc12a264d2 100644
--- a/app/models/User.php
+++ b/app/models/User.php
@@ -51,14 +51,6 @@ class User extends Eloquent implements UserInterface, RemindableInterface
return $this->hasMany('Category');
}
- /**
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- */
- public function components()
- {
- return $this->hasMany('Component');
- }
-
/**
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
diff --git a/app/routes.php b/app/routes.php
index 68b2db35d5..117d272f52 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -185,7 +185,8 @@ Route::group(
Route::get('/chart/piggyhistory/{piggybank}', ['uses' => 'GoogleChartController@piggyBankHistory']);
// 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
Route::get('/help/{route}', ['uses' => 'HelpController@show', 'as' => 'help.show']);
diff --git a/public/assets/javascript/firefly/budgets.js b/public/assets/javascript/firefly/budgets.js
index 5f25805989..968c17c0a8 100644
--- a/public/assets/javascript/firefly/budgets.js
+++ b/public/assets/javascript/firefly/budgets.js
@@ -8,7 +8,7 @@ $(function () {
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') {
googleLineChart('chart/budget/' + componentID + '/' + repetitionID, 'componentOverview');
diff --git a/public/assets/javascript/firefly/categories.js b/public/assets/javascript/firefly/categories.js
index 4827e81307..01cae7033b 100644
--- a/public/assets/javascript/firefly/categories.js
+++ b/public/assets/javascript/firefly/categories.js
@@ -1,7 +1,7 @@
$(function () {
if (typeof componentID != 'undefined' && typeof repetitionID == 'undefined') {
- googleColumnChart('chart/component/' + componentID + '/spending/' + year, 'componentOverview');
+ googleColumnChart('chart/category/' + componentID + '/spending/' + year, 'componentOverview');
}