diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index e49e6af739..ca33e3815d 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -7,6 +7,7 @@ use Asset; use User; use Redirect; use DB; +use Actionlog; use Model; use Depreciation; use Sentry; @@ -29,6 +30,12 @@ class AssetsController extends AdminController { return View::make('backend/assets/index', compact('assets')); } + public function getReports() + { + // Grab all the assets + $assets = Asset::orderBy('created_at', 'DESC')->get(); + return View::make('backend/reports/index', compact('assets')); + } /** * Asset create. @@ -91,7 +98,6 @@ class AssetsController extends AdminController { return Redirect::back()->withInput()->withErrors($errors); } - // Redirect to the asset create page with an error return Redirect::to('assets/create')->with('error', Lang::get('admin/assets/message.create.error')); @@ -238,7 +244,6 @@ class AssetsController extends AdminController { $assigned_to = e(Input::get('assigned_to')); - // Declare the rules for the form validation $rules = array( 'assigned_to' => 'required|min:1' @@ -265,10 +270,18 @@ class AssetsController extends AdminController { // Update the asset data $asset->assigned_to = e(Input::get('assigned_to')); - // Was the asset updated? if($asset->save()) { + $logaction = new Actionlog(); + $logaction->asset_id = $asset->id; + $logaction->checkedout_to = $asset->assigned_to; + $logaction->location_id = $assigned_to->location_id; + $logaction->user_id = Sentry::getUser()->id; + $log = $logaction->logaction('checkout'); + + + // Redirect to the new asset page return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkout.success')); } @@ -279,6 +292,9 @@ class AssetsController extends AdminController { /** * Check in the item so that it can be checked out again to someone else + * + * @param int $assetId + * @return View **/ public function postCheckin($assetId) { @@ -289,12 +305,26 @@ class AssetsController extends AdminController { return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found')); } - // Update the asset data + if (!is_null($asset->assigned_to)) { + $user = User::find($asset->assigned_to); + } + + $logaction = new Actionlog(); + $logaction->checkedout_to = $asset->assigned_to; + + // Update the asset data to null, since it's being checked in $asset->assigned_to = ''; // Was the asset updated? if($asset->save()) { + + $logaction->asset_id = $asset->id; + + $logaction->location_id = NULL; + $logaction->user_id = Sentry::getUser()->id; + $log = $logaction->logaction('checkin from'); + // Redirect to the new asset page return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkin.success')); } @@ -304,7 +334,28 @@ class AssetsController extends AdminController { } + /** + * Get the asset information to present to the asset view page + * + * @param int $assetId + * @return View + **/ + public function getView($assetId = null) + { + $asset = Asset::find($assetId); + if (isset($asset->id)) { + return View::make('backend/assets/view', compact('asset')); + } else { + // Prepare the error message + $error = Lang::get('admin/assets/message.does_not_exist', compact('id' )); + + // Redirect to the user management page + return Redirect::route('assets')->with('error', $error); + } + + + } diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index d10b44d2ce..4a3d7c7148 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -6,6 +6,7 @@ use Lang; use License; use Asset; use User; +use Actionlog; use DB; use Redirect; use Sentry; @@ -261,6 +262,13 @@ class LicensesController extends AdminController { // Was the asset updated? if($license->save()) { + $logaction = new Actionlog(); + $logaction->asset_id = $license->id; + $logaction->checkedout_to = $license->assigned_to; + $logaction->location_id = $assigned_to->location_id; + $logaction->user_id = Sentry::getUser()->id; + $log = $logaction->logaction('checkout'); + // Redirect to the new asset page return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success')); } @@ -281,18 +289,50 @@ class LicensesController extends AdminController { return Redirect::to('admin/licenses')->with('error', Lang::get('admin/assets/message.not_found')); } + $logaction = new Actionlog(); + $logaction->checkedout_to = $license->assigned_to; + // Update the asset data $license->assigned_to = ''; // Was the asset updated? if($license->save()) { + $logaction->asset_id = $license->id; + + $logaction->location_id = NULL; + $logaction->user_id = Sentry::getUser()->id; + $log = $logaction->logaction('checkin from'); + // Redirect to the new asset page - return Redirect::to("admin/licenses")->with('success', Lang::get('admin/assets/message.checkout.success')); + return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkout.success')); } // Redirect to the asset management page with error - return Redirect::to("admin/licenses")->with('error', Lang::get('admin/assets/message.checkout.error')); + return Redirect::to("admin/licenses")->with('error', Lang::get('admin/licenses/message.checkout.error')); + } + + /** + * Get the asset information to present to the asset view page + * + * @param int $assetId + * @return View + **/ + public function getView($licenseId = null) + { + $license = Asset::find($licenseId); + + if (isset($license->id)) { + return View::make('backend/licenses/view', compact('license')); + } else { + // Prepare the error message + $error = Lang::get('admin/licenses/message.does_not_exist', compact('id' )); + + // Redirect to the user management page + return Redirect::route('licenses')->with('error', $error); + } + + } diff --git a/app/controllers/admin/UsersController.php b/app/controllers/admin/UsersController.php index fc813617ca..0849f72a97 100755 --- a/app/controllers/admin/UsersController.php +++ b/app/controllers/admin/UsersController.php @@ -11,6 +11,7 @@ use Input; use User; use Asset; use Lang; +use Actionlog; use Location; use Redirect; use Sentry; @@ -410,15 +411,27 @@ class UsersController extends AdminController { } - + /** + * Get user info for user view + * + * @param int $userId + * @return View + */ public function getView($userId = null) { - $user = User::find($userId); - // Show the page - return View::make('backend/users/view', compact('user')); + + $user = Sentry::getUserProvider()->createModel()->withTrashed()->find($userId); + + if (isset($user->id)) { + return View::make('backend/users/view', compact('user')); + } else { + // Prepare the error message + $error = Lang::get('admin/users/message.user_not_found', compact('id' )); + + // Redirect to the user management page + return Redirect::route('users')->with('error', $error); + } + } - - - } diff --git a/app/database/migrations/2013_11_19_013337_create_asset_logs_table.php b/app/database/migrations/2013_11_19_013337_create_asset_logs_table.php new file mode 100644 index 0000000000..7178add61b --- /dev/null +++ b/app/database/migrations/2013_11_19_013337_create_asset_logs_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->integer('user_id'); + $table->string('action_type'); + $table->integer('asset_id'); + $table->integer('checkedout_to')->nullable; + $table->integer('location_id')->nullable; + $table->timestamp('added_on'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('asset_logs'); + } + +} \ No newline at end of file diff --git a/app/database/migrations/2013_11_19_061409_edit_added_on_asset_logs_table.php b/app/database/migrations/2013_11_19_061409_edit_added_on_asset_logs_table.php new file mode 100644 index 0000000000..8a9fd1e896 --- /dev/null +++ b/app/database/migrations/2013_11_19_061409_edit_added_on_asset_logs_table.php @@ -0,0 +1,28 @@ +belongsTo('Asset','asset_id'); + } + + public function adminlog() { + return $this->belongsTo('User','user_id'); + } + + public function userlog() { + return $this->belongsTo('User','checkedout_to'); + } + + + /** + * Get the parent category name + */ + public function logaction($actiontype) + { + $this->action_type = $actiontype; + + if($this->save()) + { + return true; + } else { + return false; + } + } + + + + +} diff --git a/app/models/Asset.php b/app/models/Asset.php index eb95826b9c..6c5413cb88 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -49,10 +49,30 @@ class Asset extends Elegant { return $this->belongsTo('User', 'assigned_to'); } - public function assetloc($locationId) + /** + * Get the asset's location based on the assigned user + **/ + public function assetloc() { - return Location::find($locationId); - + return $this->assigneduser->hasOne('Location'); } + /** + * Get action logs for this asset + */ + public function assetlog() + { + return $this->hasMany('Actionlog','asset_id')->orderBy('added_on', 'desc'); + } + + /** + * Get action logs for this asset + */ + public function adminuser() + { + return $this->belongsTo('User','id'); + } + + + } diff --git a/app/models/License.php b/app/models/License.php index 134ee1a5df..fcad687647 100644 --- a/app/models/License.php +++ b/app/models/License.php @@ -21,6 +21,29 @@ class License extends Elegant { return $this->belongsTo('User', 'assigned_to'); } + /** + * Get the asset's location based on the assigned user + **/ + public function assetloc() + { + return $this->assigneduser->hasOne('Location'); + } + + /** + * Get action logs for this asset + */ + public function assetlog() + { + return $this->hasMany('Actionlog','asset_id')->orderBy('added_on', 'desc'); + } + + /** + * Get action logs for this asset + */ + public function adminuser() + { + return $this->belongsTo('User','id'); + } } diff --git a/app/models/User.php b/app/models/User.php index 7177e152f6..05c1734e6f 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -39,9 +39,24 @@ class User extends SentryUserModel { public function assets() { return $this->hasMany('Asset', 'assigned_to'); - } + /** + * Get action logs for this user + */ + public function userlog() + { + return $this->hasMany('Actionlog','checkedout_to'); + } + + + /** + * Get the asset's location based on the assigned user + **/ + public function userloc() + { + return $this->hasOne('Location','id'); + } } diff --git a/app/routes.php b/app/routes.php index 582bb04619..2512d19b2d 100755 --- a/app/routes.php +++ b/app/routes.php @@ -14,20 +14,6 @@ Route::group(array('prefix' => 'assets'), function() { - Route::get('/', array('as' => 'assets', 'uses' => 'Controllers\Admin\AssetsController@getIndex')); - Route::get('assets', array('as' => 'assets', 'uses' => 'Controllers\Admin\AssetsController@getIndex')); - Route::get('create', array('as' => 'create/asset', 'uses' => 'Controllers\Admin\AssetsController@getCreate')); - Route::post('create', 'Controllers\Admin\AssetsController@postCreate'); - Route::get('{assetId}/edit', array('as' => 'update/asset', 'uses' => 'Controllers\Admin\AssetsController@getEdit')); - Route::post('{assetId}/edit', 'Controllers\Admin\AssetsController@postEdit'); - Route::get('{assetId}/delete', array('as' => 'delete/asset', 'uses' => 'Controllers\Admin\AssetsController@getDelete')); - Route::get('{assetId}/checkout', array('as' => 'checkout/asset', 'uses' => 'Controllers\Admin\AssetsController@getCheckout')); - Route::post('{assetId}/checkout', 'Controllers\Admin\AssetsController@postCheckout'); - Route::get('{assetId}/checkin', array('as' => 'checkin/asset', 'uses' => 'Controllers\Admin\AssetsController@postCheckin')); - - - - # Asset Model Management Route::group(array('prefix' => 'models'), function() { @@ -39,6 +25,17 @@ Route::group(array('prefix' => 'assets'), function() Route::get('{modelId}/delete', array('as' => 'delete/model', 'uses' => 'Controllers\Admin\ModelsController@getDelete')); }); + Route::get('/', array('as' => 'assets', 'uses' => 'Controllers\Admin\AssetsController@getIndex')); + Route::get('create', array('as' => 'create/asset', 'uses' => 'Controllers\Admin\AssetsController@getCreate')); + Route::post('create', 'Controllers\Admin\AssetsController@postCreate'); + Route::get('{assetId}/edit', array('as' => 'update/asset', 'uses' => 'Controllers\Admin\AssetsController@getEdit')); + Route::post('{assetId}/edit', 'Controllers\Admin\AssetsController@postEdit'); + Route::get('{assetId}/delete', array('as' => 'delete/asset', 'uses' => 'Controllers\Admin\AssetsController@getDelete')); + Route::get('{assetId}/checkout', array('as' => 'checkout/asset', 'uses' => 'Controllers\Admin\AssetsController@getCheckout')); + Route::post('{assetId}/checkout', 'Controllers\Admin\AssetsController@postCheckout'); + Route::get('{assetId}/checkin', array('as' => 'checkin/asset', 'uses' => 'Controllers\Admin\AssetsController@postCheckin')); + Route::get('{assetId}/view', array('as' => 'view/asset', 'uses' => 'Controllers\Admin\AssetsController@getView')); + @@ -57,20 +54,6 @@ Route::group(array('prefix' => 'assets'), function() Route::group(array('prefix' => 'admin'), function() { - - # Blog Management - Route::group(array('prefix' => 'blogs'), function() - { - Route::get('/', array('as' => 'blogs', 'uses' => 'Controllers\Admin\BlogsController@getIndex')); - Route::get('create', array('as' => 'create/blog', 'uses' => 'Controllers\Admin\BlogsController@getCreate')); - Route::post('create', 'Controllers\Admin\BlogsController@postCreate'); - Route::get('{blogId}/edit', array('as' => 'update/blog', 'uses' => 'Controllers\Admin\BlogsController@getEdit')); - Route::post('{blogId}/edit', 'Controllers\Admin\BlogsController@postEdit'); - Route::get('{blogId}/delete', array('as' => 'delete/blog', 'uses' => 'Controllers\Admin\BlogsController@getDelete')); - Route::get('{blogId}/restore', array('as' => 'restore/blog', 'uses' => 'Controllers\Admin\BlogsController@getRestore')); - }); - - # Licenses Route::group(array('prefix' => 'licenses'), function() { @@ -83,6 +66,7 @@ Route::group(array('prefix' => 'admin'), function() Route::get('{licenseId}/checkout', array('as' => 'checkout/license', 'uses' => 'Controllers\Admin\LicensesController@getCheckout')); Route::post('{licenseId}/checkout', 'Controllers\Admin\LicensesController@postCheckout'); Route::get('{licenseId}/checkin', array('as' => 'checkin/license', 'uses' => 'Controllers\Admin\LicensesController@postCheckin')); + Route::get('{licenseId}/view', array('as' => 'view/license', 'uses' => 'Controllers\Admin\LicensesController@getView')); }); @@ -248,3 +232,5 @@ Route::group(array('prefix' => 'account'), function() */ Route::get('/', array('as' => 'home', 'uses' => 'Controllers\Admin\AssetsController@getIndex')); +Route::get('reports', array('as' => 'reports', 'uses' => 'Controllers\Admin\AssetsController@getReports')); + diff --git a/app/views/backend/assets/index.blade.php b/app/views/backend/assets/index.blade.php index c38dd38068..b33e14b8e2 100755 --- a/app/views/backend/assets/index.blade.php +++ b/app/views/backend/assets/index.blade.php @@ -8,6 +8,8 @@ Assets :: {{-- Page content --}} @section('content') + +