Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some work on the category controller.
James Cole04a9ada6824e
diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.phpindex bc0cd92052..787835a4ad 100644--- a/app/controllers/CategoryController.php+++ b/app/controllers/CategoryController.php@@ -1,29 +1,47 @@<?php-class ComponentsController extends BaseController+use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;++/**+ * Class CategoryController+ */+class CategoryController extends BaseController{+ protected $_repository;++ public function __construct(CRI $repository)+ {+ $this->_repository = $repository;+ View::share('menu', 'categories');+ }+public function create(){}- public function delete()+ public function delete(Category $category){+ return View::make('categories.delete')->with('category',$category);}public function destroy(){}- public function edit()+ public function edit(Category $category){+ return View::make('categories.edit')->with('category',$category);}public function index(){+ $categories = $this->_repository->get();+ return View::make('categories.index')->with('categories',$categories);}- public function show()+ public function show(Category $category){+ return View::make('categories.show')->with('category',$category);}public function store()diff --git a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.phpindex f432d58d0e..d3b727edff 100644--- a/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php+++ b/app/lib/Firefly/Storage/Category/EloquentCategoryRepository.php@@ -14,7 +14,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface*/public function get(){- return \Auth::user()->categories()->get();+ return \Auth::user()->categories()->orderBy('name','ASC')->get();}/**diff --git a/app/models/Account.php b/app/models/Account.phpindex 35cc3684ce..93b7dbaaa9 100644--- a/app/models/Account.php+++ b/app/models/Account.php@@ -4,15 +4,15 @@ use LaravelBook\Ardent\Ardent as Ardent;/*** Account*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property integer $user_id- * @property integer $account_type_id- * @property string $name- * @property boolean $active- * @property-read \AccountType $accountType- * @property-read \User $user+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property integer $user_id+ * @property integer $account_type_id+ * @property string $name+ * @property boolean $active+ * @property-read \AccountType $accountType+ * @property-read \User $user* @property-read \Illuminate\Database\Eloquent\Collection|\Transaction[] $transactions* @method static \Illuminate\Database\Query\Builder|\Account whereId($value)* @method static \Illuminate\Database\Query\Builder|\Account whereCreatedAt($value)@@ -92,7 +92,8 @@ class Account extends Ardent);}- public function predict(\Carbon\Carbon $date) {+ public function predict(\Carbon\Carbon $date)+ {return null;}diff --git a/app/models/AccountType.php b/app/models/AccountType.phpindex 9a317c8315..1f0607bcbc 100644--- a/app/models/AccountType.php+++ b/app/models/AccountType.php@@ -4,10 +4,10 @@/*** AccountType*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property string $description+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property string $description* @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts* @method static \Illuminate\Database\Query\Builder|\AccountType whereId($value)* @method static \Illuminate\Database\Query\Builder|\AccountType whereCreatedAt($value)diff --git a/app/models/Budget.php b/app/models/Budget.phpindex c52404af0d..d93b88d909 100644--- a/app/models/Budget.php+++ b/app/models/Budget.php@@ -18,7 +18,7 @@* @method static \Illuminate\Database\Query\Builder|\Budget whereName($value)* @method static \Illuminate\Database\Query\Builder|\Budget whereUserId($value)* @method static \Illuminate\Database\Query\Builder|\Budget whereClass($value)- * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits+ * @property-read \Illuminate\Database\Eloquent\Collection|\Limit[] $limits*/class Budget extends Component{@@ -35,8 +35,9 @@ class Budget extends Componentreturn $this->hasMany('Limit', 'component_id');}- public function transactionjournals() {- return $this->belongsToMany('TransactionJournal','component_transaction_journal','component_id');+ public function transactionjournals()+ {+ return $this->belongsToMany('TransactionJournal', 'component_transaction_journal', 'component_id');}}\ No newline at end of filediff --git a/app/models/Category.php b/app/models/Category.phpindex aeae8392b1..545f2b9ad8 100644--- a/app/models/Category.php+++ b/app/models/Category.php@@ -18,7 +18,7 @@* @method static \Illuminate\Database\Query\Builder|\Category whereName($value)* @method static \Illuminate\Database\Query\Builder|\Category whereUserId($value)* @method static \Illuminate\Database\Query\Builder|\Category whereClass($value)- * @property-read \Limit $limits+ * @property-read \Limit $limits*/class Category extends Component{diff --git a/app/models/Component.php b/app/models/Component.phpindex 09069f3ef3..cc8ddf4900 100644--- a/app/models/Component.php+++ b/app/models/Component.php@@ -19,7 +19,7 @@* @method static \Illuminate\Database\Query\Builder|\Component whereName($value)* @method static \Illuminate\Database\Query\Builder|\Component whereUserId($value)* @method static \Illuminate\Database\Query\Builder|\Component whereClass($value)- * @property-read \Limit $limits+ * @property-read \Limit $limits*/class Component extends Firefly\Database\SingleTableInheritanceEntity{diff --git a/app/models/LimitRepetition.php b/app/models/LimitRepetition.phpindex 5b0c2ff4ba..04ce8ac329 100644--- a/app/models/LimitRepetition.php+++ b/app/models/LimitRepetition.php@@ -98,10 +98,10 @@ class LimitRepetition extends Ardent. '"!');break;case 'daily':- return $this->startdate->format('Ymd').'-5';+ return $this->startdate->format('Ymd') . '-5';break;case 'weekly':- return $this->startdate->format('Ymd').'4';+ return $this->startdate->format('Ymd') . '4';break;case 'monthly':return $this->startdate->format('Ymd') . '-3';@@ -113,7 +113,7 @@ class LimitRepetition extends Ardentreturn $this->startdate->format('Ymd') . '-1';break;case 'yearly':- return $this->startdate->format('Ymd').'-0';+ return $this->startdate->format('Ymd') . '-0';break;}}diff --git a/app/models/Preference.php b/app/models/Preference.phpindex b06ddd7771..7baffdd543 100644--- a/app/models/Preference.php+++ b/app/models/Preference.php@@ -6,13 +6,13 @@ use LaravelBook\Ardent\Ardent;/*** Preference*- * @property integer $id+ * @property integer $id* @property \Carbon\Carbon $created_at* @property \Carbon\Carbon $updated_at- * @property integer $user_id- * @property string $name- * @property string $data- * @property-read \User $user+ * @property integer $user_id+ * @property string $name+ * @property string $data+ * @property-read \User $user* @method static \Illuminate\Database\Query\Builder|\Preference whereId($value)* @method static \Illuminate\Database\Query\Builder|\Preference whereCreatedAt($value)* @method static \Illuminate\Database\Query\Builder|\Preference whereUpdatedAt($value)diff --git a/app/models/Transaction.php b/app/models/Transaction.phpindex 1f44f6c7ad..f7a892ede0 100644--- a/app/models/Transaction.php+++ b/app/models/Transaction.php@@ -6,18 +6,18 @@ use LaravelBook\Ardent\Ardent;/*** Transaction*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property integer $account_id- * @property integer $transaction_journal_id- * @property string $description- * @property float $amount- * @property-read \Account $account- * @property-read \TransactionJournal $transactionJournal+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property integer $account_id+ * @property integer $transaction_journal_id+ * @property string $description+ * @property float $amount+ * @property-read \Account $account+ * @property-read \TransactionJournal $transactionJournal* @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components- * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets- * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories+ * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets+ * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories* @method static \Illuminate\Database\Query\Builder|\Transaction whereId($value)* @method static \Illuminate\Database\Query\Builder|\Transaction whereCreatedAt($value)* @method static \Illuminate\Database\Query\Builder|\Transaction whereUpdatedAt($value)@@ -61,11 +61,11 @@ class Transaction extends Ardentpublic function budgets(){- return $this->belongsToMany('Budget','component_transaction','transaction_id','component_id');+ return $this->belongsToMany('Budget', 'component_transaction', 'transaction_id', 'component_id');}public function categories(){- return $this->belongsToMany('Category','component_transaction','transaction_id','component_id');+ return $this->belongsToMany('Category', 'component_transaction', 'transaction_id', 'component_id');}}\ No newline at end of filediff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.phpindex 4b5873c697..826517d009 100644--- a/app/models/TransactionCurrency.php+++ b/app/models/TransactionCurrency.php@@ -4,10 +4,10 @@/*** TransactionCurrency*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property string $code+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property string $code* @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionJournals* @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereId($value)* @method static \Illuminate\Database\Query\Builder|\TransactionCurrency whereCreatedAt($value)diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.phpindex bc2b39c799..fb5d474bdd 100644--- a/app/models/TransactionJournal.php+++ b/app/models/TransactionJournal.php@@ -63,6 +63,7 @@ class TransactionJournal extends Ardentpublic static function factory(){$date = new \Carbon\Carbon;+return ['transaction_type_id' => 'factory|TransactionType','transaction_currency_id' => 'factory|TransactionCurrency',diff --git a/app/models/TransactionType.php b/app/models/TransactionType.phpindex 77b1bd2b7f..95893dd6d0 100644--- a/app/models/TransactionType.php+++ b/app/models/TransactionType.php@@ -4,23 +4,26 @@/*** TransactionType*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property string $type+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property string $type* @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionJournals* @method static \Illuminate\Database\Query\Builder|\TransactionType whereId($value)* @method static \Illuminate\Database\Query\Builder|\TransactionType whereCreatedAt($value)* @method static \Illuminate\Database\Query\Builder|\TransactionType whereUpdatedAt($value)* @method static \Illuminate\Database\Query\Builder|\TransactionType whereType($value)*/-class TransactionType extends Eloquent {- public function transactionJournals() {+class TransactionType extends Eloquent+{+ public function transactionJournals()+ {return $this->hasMany('TransactionJournal');}- public static $factory = [- 'type' => 'string'- ];+ public static $factory+ = [+ 'type' => 'string'+ ];}\ No newline at end of filediff --git a/app/models/User.php b/app/models/User.phpindex 333bfc4143..51b6854ddf 100644--- a/app/models/User.php+++ b/app/models/User.php@@ -10,19 +10,19 @@ use LaravelBook\Ardent\Ardent;/*** User*- * @property integer $id- * @property \Carbon\Carbon $created_at- * @property \Carbon\Carbon $updated_at- * @property string $email- * @property string $password- * @property string $reset- * @property string $remember_token- * @property boolean $migrated- * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts- * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences- * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components- * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets- * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories+ * @property integer $id+ * @property \Carbon\Carbon $created_at+ * @property \Carbon\Carbon $updated_at+ * @property string $email+ * @property string $password+ * @property string $reset+ * @property string $remember_token+ * @property boolean $migrated+ * @property-read \Illuminate\Database\Eloquent\Collection|\Account[] $accounts+ * @property-read \Illuminate\Database\Eloquent\Collection|\Preference[] $preferences+ * @property-read \Illuminate\Database\Eloquent\Collection|\Component[] $components+ * @property-read \Illuminate\Database\Eloquent\Collection|\Budget[] $budgets+ * @property-read \Illuminate\Database\Eloquent\Collection|\Category[] $categories* @method static \Illuminate\Database\Query\Builder|\User whereId($value)* @method static \Illuminate\Database\Query\Builder|\User whereCreatedAt($value)* @method static \Illuminate\Database\Query\Builder|\User whereUpdatedAt($value)@@ -92,7 +92,8 @@ class User extends Ardent implements UserInterface, RemindableInterfacereturn $this->hasMany('Category');}- public function transactionjournals() {+ public function transactionjournals()+ {return $this->hasMany('TransactionJournal');}diff --git a/app/routes.php b/app/routes.phpindex 49d5962f03..680485e96f 100644--- a/app/routes.php+++ b/app/routes.php@@ -35,6 +35,13 @@ Route::group(['before' => 'auth'], function () {Route::get('/chart/home/budgets', ['uses' => 'ChartController@homeBudgets', 'as' => 'chart.budgets']);Route::get('/chart/home/info/{accountname}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);+ // Categories controller:+ Route::get('/categories',['uses' => 'CategoryController@index','as' => 'categories.index']);+ Route::get('/categories/create',['uses' => 'CategoryController@create','as' => 'categories.create']);+ Route::get('/categories/show/{category}',['uses' => 'CategoryController@show','as' => 'categories.show']);+ Route::get('/categories/edit/{category}',['uses' => 'CategoryController@edit','as' => 'categories.edit']);+ Route::get('/categories/delete/{category}',['uses' => 'CategoryController@delete','as' => 'categories.delete']);+// preferences controllerRoute::get('/preferences', ['uses' => 'PreferencesController@index', 'as' => 'preferences']);@@ -54,8 +61,8 @@ Route::group(['before' => 'auth'], function () {Route::get('/accounts/{account}/delete', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);// budget controller:- Route::get('/budgets/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']);Route::get('/budgets',['uses' => 'BudgetController@indexByDate','as' => 'budgets.index']);+ Route::get('/budgets/create',['uses' => 'BudgetController@create', 'as' => 'budgets.create']);Route::get('/budgets/budget',['uses' => 'BudgetController@indexByBudget','as' => 'budgets.index.budget']);Route::get('/budgets/show/{budget}',['uses' => 'BudgetController@show', 'as' => 'budgets.show']);Route::get('/budgets/edit/{budget}',['uses' => 'BudgetController@edit', 'as' => 'budgets.edit']);diff --git a/app/views/categories/index.blade.php b/app/views/categories/index.blade.phpnew file mode 100644index 0000000000..a99f39d25f--- /dev/null+++ b/app/views/categories/index.blade.php@@ -0,0 +1,34 @@+@extends('layouts.default')+@section('content')+<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <h1>Firefly+ <small>Categories</small>+ </h1>+ <p class="lead">Use categories to group your expenses</p>+ </div>+</div>++<div class="row">+ <div class="col-lg-12 col-md-12 col-sm-12">+ <table class="table table-striped">+ <tr>++ </tr>+ @foreach($categories as $category)+ <tr>+ <td>+ <a href="{{route('categories.show',$category->id)}}">{{{$category->name}}}</a>+ </td>+ <td>+ <div class="btn-group btn-group-xs">+ <a href="{{route('categories.edit',$category->id)}}" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></a>+ <a href="{{route('categories.delete',$category->id)}}" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a>+ </div>+ </td>+ </tr>+ @endforeach+ </table>+ </div>+</div>+@stop\ No newline at end of filediff --git a/app/views/partials/menu/categories.blade.php b/app/views/partials/menu/categories.blade.phpnew file mode 100644index 0000000000..4a3591418c--- /dev/null+++ b/app/views/partials/menu/categories.blade.php@@ -0,0 +1,27 @@+<?php+$r = Route::current()->getName();+?>+<nav class="navbar navbar-default" role="navigation">+ <div class="container-fluid">+ <!-- Brand and toggle get grouped for better mobile display -->+ <div class="navbar-header">+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">+ <span class="sr-only">Toggle navigation</span>+ <span class="icon-bar"></span>+ <span class="icon-bar"></span>+ <span class="icon-bar"></span>+ </button>+ <a class="navbar-brand" href="{{route('index')}}">Firefly III</a>+ </div>++ <!-- Collect the nav links, forms, and other content for toggling -->+ <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">+ <ul class="nav navbar-nav">+ <li @if($r=='index')class="active"@endif><a href="{{route('index')}}">Home</a></li>+ <li @if($r=='categories.index')class="active"@endif><a href="{{route('categories.index')}}">Categories</a></li>+ <li @if($r=='categories.create')class="active"@endif><a href="{{route('categories.create')}}"><span class="glyphicon glyphicon-plus"></span> Create category</a></li>+ </ul>+ @include('partials.menu.shared')+ </div><!-- /.navbar-collapse -->+ </div><!-- /.container-fluid -->+</nav>\ No newline at end of filediff --git a/app/views/partials/menu/home.blade.php b/app/views/partials/menu/home.blade.phpindex af66198e65..0c2e69b5ee 100644--- a/app/views/partials/menu/home.blade.php+++ b/app/views/partials/menu/home.blade.php@@ -23,6 +23,7 @@ $r = Route::current()->getName();<ul class="dropdown-menu" role="menu"><li><a href="{{route('accounts.index')}}"><span class="glyphicon glyphicon-inbox"></span> Accounts</a></li><li><a href="{{route('budgets.index')}}"><span class="glyphicon glyphicon-euro"></span> Budgets</a></li>+ <li><a href="{{route('categories.index')}}"><span class="glyphicon glyphicon-tags"></span> Categories</a></li><li><a href="{{route('transactions.index')}}"><span class="glyphicon glyphicon-list-alt"></span> Transactions</a></li><li class="divider"></li><li><a href="#">Separated link</a></li>