From 04a9ada6824eecd867b8d3f5fb2b7c8aefc480d1 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 30 Jul 2014 07:14:00 +0200 Subject: [PATCH] Some work on the category controller. --- app/controllers/CategoryController.php | 26 +++++++++++--- .../Category/EloquentCategoryRepository.php | 2 +- app/models/Account.php | 21 ++++++------ app/models/AccountType.php | 8 ++--- app/models/Budget.php | 7 ++-- app/models/Category.php | 2 +- app/models/Component.php | 2 +- app/models/LimitRepetition.php | 6 ++-- app/models/Preference.php | 10 +++--- app/models/Transaction.php | 26 +++++++------- app/models/TransactionCurrency.php | 8 ++--- app/models/TransactionJournal.php | 1 + app/models/TransactionType.php | 21 +++++++----- app/models/User.php | 29 ++++++++-------- app/routes.php | 9 ++++- app/views/categories/index.blade.php | 34 +++++++++++++++++++ app/views/partials/menu/categories.blade.php | 27 +++++++++++++++ app/views/partials/menu/home.blade.php | 1 + 18 files changed, 167 insertions(+), 73 deletions(-) create mode 100644 app/views/categories/index.blade.php create mode 100644 app/views/partials/menu/categories.blade.php diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php index bc0cd92052..787835a4ad 100644 --- a/app/controllers/CategoryController.php +++ b/app/controllers/CategoryController.php @@ -1,29 +1,47 @@ _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.php index 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.php index 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.php index 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.php index 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 Component return $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 file diff --git a/app/models/Category.php b/app/models/Category.php index 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.php index 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.php index 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 Ardent return $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.php index 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.php index 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 Ardent public 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 file diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.php index 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.php index bc2b39c799..fb5d474bdd 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -63,6 +63,7 @@ class TransactionJournal extends Ardent public 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.php index 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 file diff --git a/app/models/User.php b/app/models/User.php index 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, RemindableInterface return $this->hasMany('Category'); } - public function transactionjournals() { + public function transactionjournals() + { return $this->hasMany('TransactionJournal'); } diff --git a/app/routes.php b/app/routes.php index 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 controller Route::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.php new file mode 100644 index 0000000000..a99f39d25f --- /dev/null +++ b/app/views/categories/index.blade.php @@ -0,0 +1,34 @@ +@extends('layouts.default') +@section('content') +
+
+

Firefly + Categories +

+

Use categories to group your expenses

+
+
+ +
+
+ + + + + @foreach($categories as $category) + + + + + @endforeach +
+ {{{$category->name}}} + +
+ + +
+
+
+
+@stop \ No newline at end of file diff --git a/app/views/partials/menu/categories.blade.php b/app/views/partials/menu/categories.blade.php new file mode 100644 index 0000000000..4a3591418c --- /dev/null +++ b/app/views/partials/menu/categories.blade.php @@ -0,0 +1,27 @@ +getName(); +?> + \ No newline at end of file diff --git a/app/views/partials/menu/home.blade.php b/app/views/partials/menu/home.blade.php index 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();