diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index da88631243..08ddca55e8 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -312,7 +312,7 @@ class AccountController extends BaseController default: throw new FireflyException('Cannot handle post_submit_action "' . e($data['post_submit_action']) . '"'); break; - case 'create_another': + case 'return_to_edit': case 'store': $messages = $acct->validate($data); /** @var MessageBag $messages ['errors'] */ diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 54e095461d..6156d76c2d 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -263,7 +263,7 @@ class BudgetController extends BaseController default: throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"'); break; - case 'create_another': + case 'return_to_edit': case 'update': $messages = $repos->validate($data); /** @var MessageBag $messages ['errors'] */ @@ -277,7 +277,7 @@ class BudgetController extends BaseController $repos->update($budget, $data); Session::flash('success', 'Budget updated!'); - if ($data['post_submit_action'] == 'create_another') { + if ($data['post_submit_action'] == 'return_to_edit') { return Redirect::route('budgets.edit', $budget->id); } else { return Redirect::route('budgets.index'); diff --git a/app/controllers/CategoryController.php b/app/controllers/CategoryController.php index 6b1d7a4e44..55a6e629d3 100644 --- a/app/controllers/CategoryController.php +++ b/app/controllers/CategoryController.php @@ -1,26 +1,17 @@ _repository = $repository; - $this->_category = $category; View::share('title', 'Categories'); View::share('mainTitleIcon', 'fa-bar-chart'); } @@ -40,8 +31,7 @@ class CategoryController extends BaseController */ public function delete(Category $category) { - return View::make('categories.delete')->with('category', $category) - ->with('subTitle', 'Delete category "' . $category->name . '"'); + return View::make('categories.delete')->with('category', $category)->with('subTitle', 'Delete category "' . $category->name . '"'); } /** @@ -51,7 +41,10 @@ class CategoryController extends BaseController */ public function destroy(Category $category) { - $this->_repository->destroy($category); + /** @var \FireflyIII\Database\Category $repos */ + $repos = App::make('FireflyIII\Database\Category'); + + $repos->destroy($category); Session::flash('success', 'The category was deleted.'); return Redirect::route('categories.index'); } @@ -72,10 +65,7 @@ class CategoryController extends BaseController */ public function index() { - $categories = $this->_repository->get(); - - return View::make('categories.index')->with('categories', $categories) - ->with('subTitle', 'All your categories'); + return View::make('categories.index'); } /** @@ -124,15 +114,40 @@ class CategoryController extends BaseController */ public function update(Category $category) { - $category = $this->_repository->update($category, Input::all()); - if ($category->validate()) { - Session::flash('success', 'Category "' . $category->name . '" updated.'); + /** @var \FireflyIII\Database\Category $repos */ + $repos = App::make('FireflyIII\Database\Category'); + $data = Input::except('_token'); - return Redirect::route('categories.index'); - } else { - Session::flash('success', 'Could not update category "' . $category->name . '".'); + switch (Input::get('post_submit_action')) { + default: + throw new FireflyException('Cannot handle post_submit_action "' . e(Input::get('post_submit_action')) . '"'); + break; + case 'return_to_edit': + case 'update': + $messages = $repos->validate($data); + /** @var MessageBag $messages ['errors'] */ + if ($messages['errors']->count() > 0) { + Session::flash('warnings', $messages['warnings']); + Session::flash('successes', $messages['successes']); + Session::flash('error', 'Could not save category: ' . $messages['errors']->first()); + return Redirect::route('categories.edit', $category->id)->withInput()->withErrors($messages['errors']); + } + // store! + $repos->update($category, $data); + Session::flash('success', 'Category updated!'); - return Redirect::route('categories.edit')->withErrors($category->errors())->withInput(); + if ($data['post_submit_action'] == 'return_to_edit') { + return Redirect::route('categories.edit', $category->id); + } else { + return Redirect::route('categories.index'); + } + case 'validate_only': + $messageBags = $repos->validate($data); + Session::flash('warnings', $messageBags['warnings']); + Session::flash('successes', $messageBags['successes']); + Session::flash('errors', $messageBags['errors']); + return Redirect::route('categories.edit', $category->id)->withInput(); + break; } diff --git a/app/controllers/GoogleTableController.php b/app/controllers/GoogleTableController.php index 8f51270363..80b652fe4b 100644 --- a/app/controllers/GoogleTableController.php +++ b/app/controllers/GoogleTableController.php @@ -8,6 +8,38 @@ use Firefly\Exception\FireflyException; class GoogleTableController extends BaseController { + /** + * @return \Illuminate\Http\JsonResponse + */ + public function categoryList() + { + + /** @var \FireflyIII\Database\Category $repos */ + $repos = App::make('FireflyIII\Database\Category'); + + /** @var \Grumpydictator\Gchart\GChart $chart */ + $chart = App::make('gchart'); + $chart->addColumn('ID', 'number'); + $chart->addColumn('ID_Edit', 'string'); + $chart->addColumn('ID_Delete', 'string'); + $chart->addColumn('Name_URL', 'string'); + $chart->addColumn('Name', 'string'); + + $list = $repos->get(); + + /** @var Category $entry */ + foreach ($list as $entry) { + $chart->addRow( + $entry->id, route('categories.edit', $entry->id), route('categories.delete', $entry->id), route('categories.show', $entry->id), $entry->name + ); + } + + + $chart->generate(); + return Response::json($chart->getData()); + + } + /** * @param $what * @@ -84,8 +116,8 @@ class GoogleTableController extends BaseController if (is_null($repetition)) { $journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get(); } else { - $journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])-> - after($repetition->startdate)->before($repetition->enddate)->orderBy('date', 'DESC')->get(); + $journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->after($repetition->startdate) + ->before($repetition->enddate)->orderBy('date', 'DESC')->get(); } /** @var TransactionJournal $transaction */ foreach ($journals as $journal) { diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php index ba8d22fcf4..934941adf7 100644 --- a/app/lib/FireflyIII/Database/Budget.php +++ b/app/lib/FireflyIII/Database/Budget.php @@ -9,6 +9,7 @@ use Illuminate\Support\Collection; use FireflyIII\Database\Ifaces\CommonDatabaseCalls; use FireflyIII\Database\Ifaces\CUD; use FireflyIII\Database\Ifaces\BudgetInterface; + /** * Class Budget * @@ -80,11 +81,11 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface $successes = new MessageBag; $errors = new MessageBag; - if(isset($model['name'])) { - if(strlen($model['name']) < 1) { + if (isset($model['name'])) { + if (strlen($model['name']) < 1) { $errors->add('name', 'Name is too short'); } - if(strlen($model['name']) > 200) { + if (strlen($model['name']) > 200) { $errors->add('name', 'Name is too long'); } @@ -98,8 +99,8 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface } - if(!$errors->has('name')) { - $successes->add('name','OK'); + if (!$errors->has('name')) { + $successes->add('name', 'OK'); } return [ @@ -118,7 +119,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface { $data['user_id'] = $this->getUser()->id; - $budget = new \Budget($data); + $budget = new \Budget($data); $budget->class = 'Budget'; if (!$budget->validate()) { @@ -155,10 +156,12 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface /** * @param \Budget $budget - * @param Carbon $date + * @param Carbon $date + * * @return float */ - public function spentInMonth(\Budget $budget, Carbon $date) { + public function spentInMonth(\Budget $budget, Carbon $date) + { $end = clone $date; $date->startOfMonth(); $end->endOfMonth(); @@ -220,7 +223,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface */ public function update(Ardent $model, array $data) { - $model->name = $data['name']; + $model->name = $data['name']; if (!$model->validate()) { var_dump($model->errors()->all()); exit; diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php index 47349ac021..9e9ec6c93b 100644 --- a/app/lib/FireflyIII/Database/Category.php +++ b/app/lib/FireflyIII/Database/Category.php @@ -2,6 +2,7 @@ namespace FireflyIII\Database; use Carbon\Carbon; +use FireflyIII\Exception\NotImplementedException; use Illuminate\Support\MessageBag; use LaravelBook\Ardent\Ardent; use Illuminate\Support\Collection; @@ -33,7 +34,8 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface */ public function destroy(Ardent $model) { - // TODO: Implement destroy() method. + $model->delete(); + return true; } /** @@ -59,7 +61,37 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface */ public function validate(array $model) { - // TODO: Implement validate() method. + $warnings = new MessageBag; + $successes = new MessageBag; + $errors = new MessageBag; + + if (isset($model['name'])) { + if (strlen($model['name']) < 1) { + $errors->add('name', 'Name is too short'); + } + if (strlen($model['name']) > 200) { + $errors->add('name', 'Name is too long'); + + } + } else { + $errors->add('name', 'Name is mandatory'); + } + $validator = \Validator::make($model, \Component::$rules); + + if ($validator->invalid()) { + $errors->merge($validator->errors()); + } + + + if (!$errors->has('name')) { + $successes->add('name', 'OK'); + } + + return [ + 'errors' => $errors, + 'warnings' => $warnings, + 'successes' => $successes + ]; } /** @@ -91,7 +123,7 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface */ public function get() { - // TODO: Implement get() method. + return $this->getUser()->categories()->orderBy('name', 'ASC')->get(); } /** @@ -124,6 +156,15 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface */ public function update(Ardent $model, array $data) { - // TODO: Implement update() method. + $model->name = $data['name']; + if (!$model->validate()) { + var_dump($model->errors()->all()); + exit; + } + + + $model->save(); + + return true; } } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index 4d85b37703..8b804a5d77 100644 --- a/app/routes.php +++ b/app/routes.php @@ -174,6 +174,7 @@ Route::group( // google table controller Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']); Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']); + Route::get('/table/categories', ['uses' => 'GoogleTableController@categoryList']); Route::get('/table/budget/{budget}/{limitrepetition?}/transactions', ['uses' => 'GoogleTableController@transactionsByBudget']); diff --git a/app/views/accounts/edit.blade.php b/app/views/accounts/edit.blade.php index 39e14486ca..47e3ee60c2 100644 --- a/app/views/accounts/edit.blade.php +++ b/app/views/accounts/edit.blade.php @@ -1,13 +1,5 @@ @extends('layouts.default') @section('content') -
-
-

- Bla text here. -

-
-
- {{Form::model($account, ['class' => 'form-horizontal','url' => route('accounts.update',$account->id)])}}
diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.php index 2410bc6c8e..2f43b6fbe2 100644 --- a/app/views/accounts/index.blade.php +++ b/app/views/accounts/index.blade.php @@ -40,7 +40,4 @@ -@stop - -@section('styles') -@endsection \ No newline at end of file +@stop \ No newline at end of file diff --git a/app/views/categories/delete.blade.php b/app/views/categories/delete.blade.php index 9524245af1..75e2d5929e 100644 --- a/app/views/categories/delete.blade.php +++ b/app/views/categories/delete.blade.php @@ -1,37 +1,31 @@ @extends('layouts.default') @section('content') -
-
-

- Remember that deleting something is permanent. -

-
-
- {{Form::open(['class' => 'form-horizontal','url' => route('categories.destroy',$category->id)])}}
-
- @if($category->transactionjournals()->count() > 0) -

+

+
+
+ Delete category "{{{$category->name}}}" +
+
+

+ Are you sure? +

- Account "{{{$category->name}}}" still has {{$category->transactionjournals()->count()}} transaction(s) associated to it. - These will NOT be deleted but will lose their connection to the category. -

- @endif - -

- Press "Delete permanently" If you are sure you want to delete "{{{$category->name}}}". -

+

+ + Cancel +

+
+
-
- - Cancel +
diff --git a/app/views/categories/edit.blade.php b/app/views/categories/edit.blade.php index d747576b34..bf4fcaf6ff 100644 --- a/app/views/categories/edit.blade.php +++ b/app/views/categories/edit.blade.php @@ -1,46 +1,37 @@ @extends('layouts.default') @section('content') +{{Form::model($category, ['class' => 'form-horizontal','url' => route('categories.update',$category->id)])}}
-
-

Use categories to group your expenses

+
+
+
+ Mandatory fields +
+
+ {{Form::ffText('name')}} +
+
+

+ +

-
- -{{Form::open(['class' => 'form-horizontal','url' => route('categories.update',$category->id)])}} +
-
-
-

Mandatory fields

- -
- -
- - @if($errors->has('name')) -

{{$errors->first('name')}}

- @else - For example: bike, utilities, daily groceries - @endif + +
+
+ Options +
+
+ {{Form::ffOptionsList('update','category')}}
- -
- -
-
- -
-
- -
-
-
{{Form::close()}} - - -@stop +@stop \ No newline at end of file diff --git a/app/views/categories/index.blade.php b/app/views/categories/index.blade.php index 78a2451a1f..86cb093906 100644 --- a/app/views/categories/index.blade.php +++ b/app/views/categories/index.blade.php @@ -2,37 +2,38 @@ @section('content')
-

Use categories to group your expenses

-

- Use categories to group expenses by hobby, for certain types of groceries or what bills are for. - Expenses grouped in categories do not have to reoccur every month or every week, like budgets. -

-

- Create a new category -

-
-
+
+
+ Categories -
-
- - - - - @foreach($categories as $category) - - - - - @endforeach -
- {{{$category->name}}} - -
- - + +
+
+ +
-
+
+ + +
+
+
+
+
+@stop +@section('scripts') + + +{{HTML::script('assets/javascript/firefly/gcharts.options.js')}} +{{HTML::script('assets/javascript/firefly/gcharts.js')}} + + + @stop \ No newline at end of file diff --git a/public/assets/javascript/firefly/categories.js b/public/assets/javascript/firefly/categories.js index b81fff48d1..4b959ed181 100644 --- a/public/assets/javascript/firefly/categories.js +++ b/public/assets/javascript/firefly/categories.js @@ -1,90 +1,94 @@ $(function () { -if($('#chart').length == 1) { - /** - * get data from controller for home charts: - */ - $.getJSON('chart/categories/show/' + categoryID).success(function (data) { - var options = { - chart: { - renderTo: 'chart', - type: 'column' - }, - series: [data.series], - title: { - text: data.chart_title - }, - yAxis: { - formatter: function () { - return '$' + Highcharts.numberFormat(this.y, 0); - } - }, - subtitle: { - text: data.subtitle, - useHTML: true - }, - xAxis: { - floor: 0, - type: 'category', - title: { - text: 'Period' - } - }, - tooltip: { - shared: true, - crosshairs: false, - formatter: function () { - var str = '' + Highcharts.dateFormat("%A, %e %B", this.x) + '
'; - for (x in this.points) { - var point = this.points[x]; - var colour = point.point.pointAttr[''].fill; - str += '' + point.series.name + ': \u20AC ' + Highcharts.numberFormat(point.y, 2) + '
'; - } - //console.log(); - return str; - return '' + this.series.name + ' on ' + Highcharts.dateFormat("%e %B", this.x) + ':
\u20AC ' + Highcharts.numberFormat(this.y, 2); - } - }, - plotOptions: { - line: { - shadow: true + if (typeof googleTable == 'function') { + googleTable('table/categories', 'category-list'); + } + + if ($('#chart').length == 1) { + /** + * get data from controller for home charts: + */ + $.getJSON('chart/categories/show/' + categoryID).success(function (data) { + var options = { + chart: { + renderTo: 'chart', + type: 'column' }, - series: { - cursor: 'pointer', - negativeColor: '#FF0000', - threshold: 0, - lineWidth: 1, - marker: { - radius: 2 + series: [data.series], + title: { + text: data.chart_title + }, + yAxis: { + formatter: function () { + return '$' + Highcharts.numberFormat(this.y, 0); + } + }, + subtitle: { + text: data.subtitle, + useHTML: true + }, + + xAxis: { + floor: 0, + type: 'category', + title: { + text: 'Period' + } + }, + tooltip: { + shared: true, + crosshairs: false, + formatter: function () { + var str = '' + Highcharts.dateFormat("%A, %e %B", this.x) + '
'; + for (x in this.points) { + var point = this.points[x]; + var colour = point.point.pointAttr[''].fill; + str += '' + point.series.name + ': \u20AC ' + Highcharts.numberFormat(point.y, 2) + '
'; + } + //console.log(); + return str; + return '' + this.series.name + ' on ' + Highcharts.dateFormat("%e %B", this.x) + ':
\u20AC ' + Highcharts.numberFormat(this.y, 2); + } + }, + plotOptions: { + line: { + shadow: true }, - point: { - events: { - click: function (e) { - hs.htmlExpand(null, { - src: 'chart/home/info/' + this.series.name + '/' + Highcharts.dateFormat("%d/%m/%Y", this.x), - pageOrigin: { - x: e.pageX, - y: e.pageY - }, - objectType: 'ajax', - headingText: '' + this.series.name + '', - width: 250 - } - ) - ; + series: { + cursor: 'pointer', + negativeColor: '#FF0000', + threshold: 0, + lineWidth: 1, + marker: { + radius: 2 + }, + point: { + events: { + click: function (e) { + hs.htmlExpand(null, { + src: 'chart/home/info/' + this.series.name + '/' + Highcharts.dateFormat("%d/%m/%Y", this.x), + pageOrigin: { + x: e.pageX, + y: e.pageY + }, + objectType: 'ajax', + headingText: '' + this.series.name + '', + width: 250 + } + ) + ; + } } } } + }, + credits: { + enabled: false } - }, - credits: { - enabled: false - } - }; - $('#chart').highcharts(options); - }); -} - + }; + $('#chart').highcharts(options); + }); + } }); \ No newline at end of file