diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index ea4b731d3b..07f04987dc 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -39,9 +39,10 @@ class AssetsController extends AdminController { public function getCreate() { // Grab the dropdown list of models - $model_list = array('0' => 'Select') + Model::lists('name', 'id'); + $model_list = array('' => 'Select') + Model::lists('name', 'id'); $depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id'); - return View::make('backend/assets/create')->with('model_list',$model_list)->with('depreciation_list',$depreciation_list); + + return View::make('backend/assets/edit')->with('model_list',$model_list)->with('depreciation_list',$depreciation_list)->with('asset',new Asset); } @@ -57,7 +58,7 @@ class AssetsController extends AdminController { $rules = array( 'name' => 'required|min:3', 'asset_tag' => 'required|min:3', - 'model_id' => 'required|min:1', + 'model_id' => 'required', 'serial' => 'required|min:3', ); @@ -74,8 +75,7 @@ class AssetsController extends AdminController { // Create a new asset $asset = new Asset; - // Update the asset data - // Update the asset data + // Save the asset data $asset->name = e(Input::get('name')); $asset->serial = e(Input::get('serial')); $asset->model_id = e(Input::get('model_id')); @@ -90,11 +90,11 @@ class AssetsController extends AdminController { // Was the asset created? if($asset->save()) { - // Redirect to the new asset page + // Redirect to the asset listing page return Redirect::to("assets/assets")->with('success', Lang::get('admin/assets/message.create.success')); } - // Redirect to the asset create page + // Redirect to the asset create page with an error return Redirect::to('assets/assets/create')->with('error', Lang::get('admin/assets/message.create.error')); } @@ -109,12 +109,14 @@ class AssetsController extends AdminController { // Check if the asset exists if (is_null($asset = Asset::find($assetId))) { - // Redirect to the blogs management page + // Redirect to the asset management page return Redirect::to('admin/settings/assets')->with('error', Lang::get('admin/assets/message.does_not_exist')); } // Grab the dropdown list of models - $model_list = array('0' => 'Select') + Model::lists('name', 'id'); + $model_list = array('' => 'Select') + Model::lists('name', 'id'); + + // get depreciation list $depreciation_list = array('' => 'Do Not Depreciate') + Depreciation::lists('name', 'id'); return View::make('backend/assets/edit', compact('asset'))->with('model_list',$model_list)->with('depreciation_list',$depreciation_list); } @@ -128,10 +130,10 @@ class AssetsController extends AdminController { */ public function postEdit($assetId = null) { - // Check if the blog post exists + // Check if the asset exists if (is_null($asset = Asset::find($assetId))) { - // Redirect to the blogs management page + // Redirect to the asset management page with error return Redirect::to('admin/assets')->with('error', Lang::get('admin/assets/message.does_not_exist')); } @@ -139,7 +141,7 @@ class AssetsController extends AdminController { $rules = array( 'name' => 'required|min:3', 'asset_tag' => 'required|min:3', - 'model_id' => 'required|min:1', + 'model_id' => 'required', 'serial' => 'required|min:3', ); @@ -171,8 +173,8 @@ class AssetsController extends AdminController { return Redirect::to("assets/assets/$assetId/edit")->with('success', Lang::get('admin/assets/message.update.success')); } - // Redirect to the asset management page - return Redirect::to("assets/assets/$assetID/edit")->with('error', Lang::get('admin/assets/message.update.error')); + // Redirect to the asset management page with error + return Redirect::to("assets/assets/$assetId/edit")->with('error', Lang::get('admin/assets/message.update.error')); } /** @@ -186,14 +188,14 @@ class AssetsController extends AdminController { // Check if the blog post exists if (is_null($asset = Asset::find($assetId))) { - // Redirect to the blogs management page + // Redirect to the asset management page with error return Redirect::to('assets/assets')->with('error', Lang::get('admin/assets/message.not_found')); } - // Delete the blog post + // Delete the asset $asset->delete(); - // Redirect to the blog posts management page + // Redirect to the asset management page return Redirect::to('assets/assets')->with('success', Lang::get('admin/assets/message.delete.success')); } diff --git a/app/controllers/admin/CategoriesController.php b/app/controllers/admin/CategoriesController.php index 0580951591..f8df2844f9 100644 --- a/app/controllers/admin/CategoriesController.php +++ b/app/controllers/admin/CategoriesController.php @@ -38,7 +38,7 @@ class CategoriesController extends AdminController { { // Show the page $category_options = array('0' => 'Top Level') + Category::lists('name', 'id'); - return View::make('backend/categories/create')->with('category_options',$category_options); + return View::make('backend/categories/edit')->with('category_options',$category_options)->with('category',new Category); } diff --git a/app/controllers/admin/DepreciationsController.php b/app/controllers/admin/DepreciationsController.php index 3107922a5a..a72754beed 100644 --- a/app/controllers/admin/DepreciationsController.php +++ b/app/controllers/admin/DepreciationsController.php @@ -38,7 +38,7 @@ class DepreciationsController extends AdminController { { // Show the page $depreciation_options = array('0' => 'Top Level') + Depreciation::lists('name', 'id'); - return View::make('backend/depreciations/create')->with('depreciation_options',$depreciation_options); + return View::make('backend/depreciations/edit')->with('depreciation_options',$depreciation_options)->with('depreciation',new Depreciation); } diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index 993d612850..32349ea993 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -38,7 +38,7 @@ class LicensesController extends AdminController { { // Show the page $license_options = array('0' => 'Top Level') + License::lists('name', 'id'); - return View::make('backend/licenses/create')->with('license_options',$license_options); + return View::make('backend/licenses/edit')->with('license_options',$license_options)->with('license',new License); } @@ -87,7 +87,7 @@ class LicensesController extends AdminController { } // Redirect to the license create page - return Redirect::to('admin/licenses/create')->with('error', Lang::get('admin/licenses/message.create.error')); + return Redirect::to('admin/licenses/edit')->with('error', Lang::get('admin/licenses/message.create.error'))->with('license',new License); } /** @@ -162,7 +162,7 @@ class LicensesController extends AdminController { } // Redirect to the license management page - return Redirect::to("admin/licenses/$licenseID/edit")->with('error', Lang::get('admin/licenses/message.update.error')); + return Redirect::to("admin/licenses/$licenseId/edit")->with('error', Lang::get('admin/licenses/message.update.error')); } /** diff --git a/app/controllers/admin/ManufacturersController.php b/app/controllers/admin/ManufacturersController.php index 760e5338da..a5e35fa6cc 100644 --- a/app/controllers/admin/ManufacturersController.php +++ b/app/controllers/admin/ManufacturersController.php @@ -13,7 +13,7 @@ use View; class ManufacturersController extends AdminController { /** - * Show a list of all the blog posts. + * Show a list of all manufacturers * * @return View */ @@ -36,7 +36,7 @@ class ManufacturersController extends AdminController { { // Show the page $manufacturer_options = array('0' => 'Top Level') + Manufacturer::lists('name', 'id'); - return View::make('backend/manufacturers/create')->with('manufacturer_options',$manufacturer_options); + return View::make('backend/manufacturers/edit')->with('manufacturer_options',$manufacturer_options)->with('manufacturer', new Manufacturer); } @@ -141,7 +141,7 @@ class ManufacturersController extends AdminController { } // Redirect to the manufacturer management page - return Redirect::to("admin/settings/manufacturers/$manufacturerID/edit")->with('error', Lang::get('admin/manufacturers/message.update.error')); + return Redirect::to("admin/settings/manufacturers/$manufacturerId/edit")->with('error', Lang::get('admin/manufacturers/message.update.error')); } /** @@ -159,7 +159,7 @@ class ManufacturersController extends AdminController { return Redirect::to('admin/settings/manufacturers')->with('error', Lang::get('admin/manufacturers/message.not_found')); } - // Delete the blog post + // Delete the manufacturer $manufacturer->delete(); // Redirect to the manufacturers management page diff --git a/app/models/Asset.php b/app/models/Asset.php index b1aceb4c28..7ab94bcdf5 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -19,6 +19,8 @@ class Asset extends Eloquent { public function depreciation() { $depreciation_id = Model::find($this->model_id)->depreciation_id; + + if (isset($depreciation_id)) { $depreciation_term = Depreciation::find($depreciation_id)->months; $purchase_date = strtotime($this->purchase_date); @@ -32,7 +34,10 @@ class Asset extends Eloquent { if ($current_value < 0) { $current_value = 0; } - return $current_value; + return $current_value; + } else { + return $this->purchase_cost; + } } diff --git a/app/models/Model.php b/app/models/Model.php index 9af91b848a..b4c84f1255 100644 --- a/app/models/Model.php +++ b/app/models/Model.php @@ -3,71 +3,15 @@ class Model extends Eloquent { /** - * Deletes a blog post and all the associated comments. + * Deletes the model * * @return bool */ public function delete() { - // Delete the comments - $this->comments()->delete(); - // Delete the blog post + // Delete the model return parent::delete(); } - /** - * Returns a formatted post content entry, this ensures that - * line breaks are returned. - * - * @return string - */ - public function content() - { - return nl2br($this->content); - } - - /** - * Return the post's author. - * - * @return User - */ - public function author() - { - return $this->belongsTo('User', 'user_id'); - } - - /** - * Return how many comments this post has. - * - * @return array - */ - public function comments() - { - return $this->hasMany('Comment'); - } - - /** - * Return the URL to the post. - * - * @return string - */ - public function url() - { - return URL::route('view-post', $this->slug); - } - - /** - * Return the post thumbnail image url. - * - * @return string - */ - public function thumbnail() - { - # you should save the image url on the database - # and return that url here. - - return 'http://lorempixel.com/130/90/business/'; - } - } diff --git a/app/models/User.php b/app/models/User.php index 062e16d342..036d266d75 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -39,10 +39,12 @@ class User extends SentryUserModel { public function numassets() { + /* $assetcount = DB::table('users') ->join('contacts', 'users.id', '=', 'contacts.user_id') ->join('orders', 'users.id', '=', 'orders.user_id') ->select('users.id', 'contacts.phone', 'orders.price'); + */ } } diff --git a/app/routes.php b/app/routes.php index 6e76c6084a..717ba0d964 100755 --- a/app/routes.php +++ b/app/routes.php @@ -110,16 +110,6 @@ Route::group(array('prefix' => 'admin'), function() Route::get('{depreciationId}/delete', array('as' => 'delete/depreciations', 'uses' => 'Controllers\Admin\DepreciationsController@getDelete')); }); - - - - - # Depreciation - Route::group(array('prefix' => 'depreciation'), function() - { - Route::get('/', array('as' => 'depreciation', 'uses' => 'Controllers\Admin\ModelsController@getIndex')); - - }); }); diff --git a/app/views/backend/assets/create.blade.php b/app/views/backend/assets/create.blade.php deleted file mode 100755 index a0f317c003..0000000000 --- a/app/views/backend/assets/create.blade.php +++ /dev/null @@ -1,122 +0,0 @@ -@extends('backend/layouts/default') - -{{-- Page title --}} -@section('title') -Create a New Asset :: -@parent -@stop - -{{-- Page content --}} -@section('content') -