Skip to content

Firefly III: a personal finances manager

Layout updates and extensions. Found a problem I need closures for. Yay! [skip ci]

James Coleb0ddc04a0db6
diff --git a/app/config/firefly.php b/app/config/firefly.php
index 5bf8094e5c..65fc90425e 100644
--- a/app/config/firefly.php
+++ b/app/config/firefly.php
@@ -34,6 +34,10 @@ return [
'weekly' => [
'group_date' => 'Y-W',
'display_date' => '\W\e\e\k W, Y'
+ ],
+ 'quarterly' => [
+ 'group_date' => 'Y-m',
+ 'display_date' => '\T\O\D\O \C\L\O\S\U\R\E m-Y'
]
]
];
\ No newline at end of file
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index e4c3714734..b0e1f87b8a 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -14,7 +14,7 @@ class AccountController extends \BaseController
/**
* @param ARI $repository
- * @param AI $accounts
+ * @param AI $accounts
*/
public function __construct(ARI $repository, AI $accounts)
{
@@ -93,7 +93,7 @@ class AccountController extends \BaseController
{
$show = $this->_accounts->show($account, 40);
- return View::make('accounts.show')->with('account', $account)->with('show',$show);
+ return View::make('accounts.show')->with('account', $account)->with('show', $show);
}
/**
diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php
index 518618ba49..0407399f8d 100644
--- a/app/controllers/BudgetController.php
+++ b/app/controllers/BudgetController.php
@@ -13,8 +13,10 @@ class BudgetController extends BaseController
protected $_budgets;
protected $_repository;
+
/**
- * @param BRI $budgets
+ * @param BI $budgets
+ * @param BRI $repository
*/
public function __construct(BI $budgets, BRI $repository)
{
@@ -60,12 +62,52 @@ class BudgetController extends BaseController
}
+ public function edit(Budget $budget)
+ {
+ return View::make('budgets.edit')->with('budget', $budget);
+
+ }
+
+ public function update()
+ {
+ $budget = $this->_repository->update(Input::all());
+ Session::flash('success', 'Budget "' . $budget->name . '" updated.');
+
+ if (Input::get('from') == 'date') {
+ return Redirect::route('budgets.index');
+ } else {
+ return Redirect::route('budgets.index.budget');
+ }
+
+ return Redirect::route('budgets.index');
+ }
+
+ public function delete(Budget $budget)
+ {
+ return View::make('budgets.delete')->with('budget', $budget);
+ }
+
+ public function destroy()
+ {
+ $result = $this->_repository->destroy(Input::get('id'));
+ if ($result === true) {
+ Session::flash('success', 'The budget was deleted.');
+ if (Input::get('from') == 'date') {
+ return Redirect::route('budgets.index');
+ } else {
+ return Redirect::route('budgets.index.budget');
+ }
+ } else {
+ Session::flash('error', 'Could not delete the budget. Check the logs to be sure.');
+ }
+ return Redirect::route('budgets.index');
+
+ }
+
/**
- * TODO actual view, actual content.
- *
- * @param $budgetId
+ * @param Budget $budget
*
- * @return string
+ * @return int
*/
public function show(Budget $budget)
{
diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php
index de0d32730c..12812b8a0c 100644
--- a/app/controllers/ChartController.php
+++ b/app/controllers/ChartController.php
@@ -21,11 +21,11 @@ class ChartController extends BaseController
/**
- * @param ARI $accounts
+ * @param ARI $accounts
* @param TJRI $journals
- * @param PHI $preferences
- * @param tk $toolkit
- * @param BRI $budgets
+ * @param PHI $preferences
+ * @param tk $toolkit
+ * @param BRI $budgets
*/
public function __construct(ARI $accounts, TJRI $journals, PHI $preferences, tk $toolkit, BRI $budgets)
{
diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php
index 9ba298ce3c..dc16d8a5e4 100644
--- a/app/controllers/HomeController.php
+++ b/app/controllers/HomeController.php
@@ -17,11 +17,11 @@ class HomeController extends BaseController
protected $_tk;
/**
- * @param ARI $accounts
- * @param PHI $preferences
- * @param TJRI $journal
+ * @param ARI $accounts
+ * @param PHI $preferences
+ * @param TJRI $journal
* @param Toolkit $toolkit
- * @param BRI $budgets
+ * @param BRI $budgets
*/
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets)
{
diff --git a/app/controllers/LimitController.php b/app/controllers/LimitController.php
index 0413f96c6a..8a299ae748 100644
--- a/app/controllers/LimitController.php
+++ b/app/controllers/LimitController.php
@@ -33,7 +33,7 @@ class LimitController extends BaseController
{
$periods = \Config::get('firefly.periods_to_text');
$prefilled = [
- 'startdate' => Input::get('startdate') ? : date('Y-m-d'),
+ 'startdate' => Input::get('startdate') ? : date('Y-m-d'),
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly'
];
@@ -54,11 +54,11 @@ class LimitController extends BaseController
$budgets = $this->_budgets->getAsSelectList();
$periods = [
- 'weekly' => 'A week',
- 'monthly' => 'A month',
+ 'weekly' => 'A week',
+ 'monthly' => 'A month',
'quarterly' => 'A quarter',
'half-year' => 'Six months',
- 'yearly' => 'A year',
+ 'yearly' => 'A year',
];
diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php
index 9934858679..84ddccae88 100644
--- a/app/controllers/TransactionController.php
+++ b/app/controllers/TransactionController.php
@@ -18,9 +18,9 @@ class TransactionController extends BaseController
protected $_journal;
/**
- * @param ARI $accounts
- * @param Bud $budgets
- * @param Cat $categories
+ * @param ARI $accounts
+ * @param Bud $budgets
+ * @param Cat $categories
* @param TJRI $journal
*/
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $journal)
@@ -167,8 +167,8 @@ class TransactionController extends BaseController
// data to properly display form:
$data = [
- 'date' => $journal->date->format('Y-m-d'),
- 'category' => '',
+ 'date' => $journal->date->format('Y-m-d'),
+ 'category' => '',
'budget_id' => 0
];
$category = $journal->categories()->first();
diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php
index fa4e24ed36..643a022417 100644
--- a/app/controllers/UserController.php
+++ b/app/controllers/UserController.php
@@ -42,7 +42,7 @@ class UserController extends BaseController
{
$rememberMe = Input::get('remember_me') == '1';
$data = [
- 'email' => Input::get('email'),
+ 'email' => Input::get('email'),
'password' => Input::get('password')
];
if (Auth::attempt($data, $rememberMe)) {
diff --git a/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php b/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
index 0a81e83551..0d4fc68d39 100644
--- a/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
+++ b/app/lib/Firefly/Storage/Budget/BudgetRepositoryInterface.php
@@ -21,6 +21,12 @@ interface BudgetRepositoryInterface
*/
public function get();
+ /**
+ * @param $data
+ * @return mixed
+ */
+ public function update($data);
+
/**
* @param $data
*
@@ -28,6 +34,12 @@ interface BudgetRepositoryInterface
*/
public function store($data);
+ /**
+ * @param $data
+ * @return mixed
+ */
+ public function destroy($data);
+
/**
* @param $budgetId
*
diff --git a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
index 26ea2236d3..9b245d1ad3 100644
--- a/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
+++ b/app/lib/Firefly/Storage/Budget/EloquentBudgetRepository.php
@@ -29,7 +29,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
public function get()
{
$set = \Auth::user()->budgets()->with(
- ['limits' => function ($q) {
+ ['limits' => function ($q) {
$q->orderBy('limits.startdate', 'ASC');
}, 'limits.limitrepetitions' => function ($q) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
@@ -46,6 +46,31 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $set;
}
+ /**
+ * @param $data
+ * @return mixed
+ */
+ public function update($data) {
+ $budget = $this->find($data['id']);
+ if ($budget) {
+ // update account accordingly:
+ $budget->name = $data['name'];
+ if ($budget->validate()) {
+ $budget->save();
+ }
+ }
+ return $budget;
+ }
+
+ public function destroy($budgetId) {
+ $budget = $this->find($budgetId);
+ if($budget) {
+ $budget->delete();
+ return true;
+ }
+ return false;
+ }
+
/**
* @return array|mixed
*/
@@ -72,7 +97,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
{
$set = \Auth::user()->budgets()->with(
- ['limits' => function ($q) use ($date) {
+ ['limits' => function ($q) use ($date) {
$q->orderBy('limits.startdate', 'ASC');
}, 'limits.limitrepetitions' => function ($q) use ($date) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
@@ -156,7 +181,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
$limit->save();
}
}
- if($budget->validate()) {
+ if ($budget->validate()) {
$budget->save();
}
return $budget;
diff --git a/app/routes.php b/app/routes.php
index 15c5f10d2d..c65281d2d7 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -54,12 +54,12 @@ Route::group(['before' => 'auth'], function () {
Route::get('/accounts/{account}/delete', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);
// budget controller:
- Route::get('/budget/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
+ Route::get('/budgets/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']);
Route::get('/budgets',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index']);
Route::get('/budgets/budget',['uses' => 'BudgetController@indexByBudget','as' => 'budgets.index.budget']);
- Route::get('/budget/show/{budget}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
- Route::get('/budget/edit/{budget}',['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
- Route::get('/budget/delete/{budget}',['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
+ Route::get('/budgets/show/{budget}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']);
+ Route::get('/budgets/edit/{budget}',['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);
+ Route::get('/budgets/delete/{budget}',['uses' => 'BudgetController@delete', 'as' => 'budgets.delete']);
// limit controller:
Route::get('/budgets/limits/create/{id?}',['uses' => 'LimitController@create','as' => 'budgets.limits.create']);
@@ -89,7 +89,9 @@ Route::group(['before' => 'csrf|auth'], function () {
Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword']);
// budget controller:
- Route::post('/budget/store',['uses' => 'BudgetController@store', 'as' => 'budgets.store']);
+ Route::post('/budgets/store',['uses' => 'BudgetController@store', 'as' => 'budgets.store']);
+ Route::post('/budgets/update', ['uses' => 'BudgetController@update', 'as' => 'budgets.update']);
+ Route::post('/budgets/destroy', ['uses' => 'BudgetController@destroy', 'as' => 'budgets.destroy']);
// migration controller
Route::post('/migrate', ['uses' => 'MigrationController@postIndex']);
diff --git a/app/views/accounts/delete.blade.php b/app/views/accounts/delete.blade.php
index c57a3d9f70..29b4abc27f 100644
--- a/app/views/accounts/delete.blade.php
+++ b/app/views/accounts/delete.blade.php
@@ -11,10 +11,10 @@
</div>
</div>
-{{Form::model($account, ['class' => 'form-horizontal','url' => route('accounts.destroy')])}}
+{{Form::open(['class' => 'form-horizontal','url' => route('accounts.destroy')])}}
{{Form::hidden('id',$account->id)}}
<div class="row">
- <div class="col-lg-6 col-md-6 col-sm-12">
+ <div class="col-lg-12 col-md-12 col-sm-12">
@if($account->transactions()->count() > 0)
<p class="text-info">
diff --git a/app/views/budgets/delete.blade.php b/app/views/budgets/delete.blade.php
new file mode 100644
index 0000000000..b14690b6a6
--- /dev/null
+++ b/app/views/budgets/delete.blade.php
@@ -0,0 +1,51 @@
+@extends('layouts.default')
+@section('content')
+<div class="row">
+ <div class="col-lg-12 col-md-12 col-sm-12">
+ <h1>Firefly
+ <small>Delete "{{{$budget->name}}}"</small>
+ </h1>
+ <p class="lead">
+ Remember that deleting something is permanent.
+ </p>
+ </div>
+</div>
+
+{{Form::open(['class' => 'form-horizontal','url' => route('budgets.destroy')])}}
+{{Form::hidden('id',$budget->id)}}
+{{Form::hidden('from',e(Input::get('from')))}}
+<div class="row">
+ <div class="col-lg-12 col-md-12 col-sm-12">
+ @if($budget->transactionjournals()->count() > 0)
+ <p class="text-info">
+
+ Account "{{{$budget->name}}}" still has {{$budget->transactionjournals()->count()}} transaction(s) associated to it.
+ These will NOT be deleted but will lose their connection to the budget.
+ </p>
+ @endif
+
+ <p class="text-danger">
+ Press "Delete permanently" If you are sure you want to delete "{{{$budget->name}}}".
+ </p>
+ </div>
+
+</div>
+
+<div class="row">
+ <div class="col-lg-6">
+ <div class="form-group">
+ <div class="col-sm-8">
+ <button type="submit" class="btn btn-default btn-danger">Delete permanently</button>
+ @if(Input::get('from') == 'date')
+ <a href="{{route('budgets.index')}}" class="btn-default btn">Cancel</a>
+ @else
+ <a href="{{route('budgets.index.budget')}}" class="btn-default btn">Cancel</a>
+ @endif
+ </div>
+ </div>
+ </div>
+</div>
+
+
+{{Form::close()}}
+@stop
\ No newline at end of file
diff --git a/app/views/budgets/edit.blade.php b/app/views/budgets/edit.blade.php
new file mode 100644
index 0000000000..3e1499bb4f
--- /dev/null
+++ b/app/views/budgets/edit.blade.php
@@ -0,0 +1,51 @@
+@extends('layouts.default')
+@section('content')
+<div class="row">
+ <div class="col-lg-12 col-md-12 col-sm-12">
+ <h1>Firefly
+ <small>Edit budget "{{{$budget->name}}}"</small>
+ </h1>
+ <p class="lead">Use budgets to organize and limit your expenses.</p>
+ </div>
+</div>
+
+{{Form::open(['class' => 'form-horizontal','url' => route('budgets.update')])}}
+
+{{Form::hidden('id',$budget->id)}}
+{{Form::hidden('from',e(Input::get('from')))}}
+
+<div class="row">
+ <div class="col-lg-6 col-md-12 col-sm-6">
+ <h4>Mandatory fields</h4>
+
+ <div class="form-group">
+ <label for="name" class="col-sm-4 control-label">Name</label>
+ <div class="col-sm-8">
+ <input type="text" name="name" class="form-control" id="name" value="{{Input::old('name') ?: $budget->name}}" placeholder="Name">
+ @if($errors->has('name'))
+ <p class="text-danger">{{$errors->first('name')}}</p>
+ @else
+ <span class="help-block">For example: groceries, bills</span>
+ @endif
+ </div>
+ </div>
+
+ </div>
+
+</div>
+
+<div class="row">
+ <div class="col-lg-6 col-md-12 col-sm-6">
+
+ <div class="form-group">
+ <div class="col-sm-offset-4 col-sm-8">
+ <button type="submit" class="btn btn-default btn-success">Update the budget</button>
+ </div>
+ </div>
+ </div>
+</div>
+
+{{Form::close()}}
+
+
+@stop
diff --git a/app/views/budgets/indexByBudget.blade.php b/app/views/budgets/indexByBudget.blade.php
index d0eb199283..585349d6f1 100644
--- a/app/views/budgets/indexByBudget.blade.php
+++ b/app/views/budgets/indexByBudget.blade.php
@@ -74,11 +74,7 @@
</div>
<div class="col-sm-3">
<small>
- @if($limit->repeat_freq == 'monthly')
- {{$rep->startdate->format('F Y')}}
- @else
- NO FORMAT
- @endif
+ CLOSURE TODO
</small>
</div>
@if($limit->repeats == 1)
@@ -104,8 +100,8 @@
</td>
<td>
<div class="btn-group btn-group-sm">
- <a href="#" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
- <a href="#" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
+ <a href="{{route('budgets.edit',$budget->id)}}?from=budget" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
+ <a href="{{route('budgets.delete',$budget->id)}}?from=budget" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
diff --git a/app/views/budgets/indexByDate.blade.php b/app/views/budgets/indexByDate.blade.php
index ac43e3c56b..064e937325 100644
--- a/app/views/budgets/indexByDate.blade.php
+++ b/app/views/budgets/indexByDate.blade.php
@@ -48,8 +48,8 @@
<tr>
<td>
<div class="btn-group">
- <a title="Edit budget {{{$repetition->limit->budget->name}}}" href="{{route('budgets.edit',$repetition->limit->budget->id)}}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
- <a title="Delete budget {{{$repetition->limit->budget->name}}}" href="{{route('budgets.delete',$repetition->limit->budget->id)}}" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
+ <a title="Edit budget {{{$repetition->limit->budget->name}}}" href="{{route('budgets.edit',$repetition->limit->budget->id)}}?from=date" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
+ <a title="Delete budget {{{$repetition->limit->budget->name}}}" href="{{route('budgets.delete',$repetition->limit->budget->id)}}?from=date" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span></a>
</div>
</td>
<td>
diff --git a/ide-helper.bat b/ide-helper.bat
new file mode 100644
index 0000000000..facb4b2977
--- /dev/null
+++ b/ide-helper.bat
@@ -0,0 +1,6 @@
+composer update
+php artisan clear-compiled --env=local
+php artisan ide-helper:generate --env=local
+php artisan ide-helper:models --env=local --write
+php artisan optimize --env=local
+php artisan dump-autoload --env=local
\ No newline at end of file