diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index ba83802acf..0c2fbf4d9f 100644 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -278,9 +278,6 @@ class AssetsController extends AdminController { // Get the dropdown of users and then pass it to the checkout view $users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat(first_name," ",last_name) as full_name, id'))->lists('full_name', 'id'); - - - //print_r($users); return View::make('backend/assets/checkout', compact('asset'))->with('users_list',$users_list); @@ -303,7 +300,8 @@ class AssetsController extends AdminController { // Declare the rules for the form validation $rules = array( - 'assigned_to' => 'required|min:1' + 'assigned_to' => 'required|min:1', + 'note' => 'alpha_space', ); // Create a new validator instance from our validation rules @@ -336,10 +334,9 @@ class AssetsController extends AdminController { $logaction->asset_type = 'hardware'; $logaction->location_id = $assigned_to->location_id; $logaction->user_id = Sentry::getUser()->id; + $logaction->note = e(Input::get('note')); $log = $logaction->logaction('checkout'); - - // Redirect to the new asset page return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkout.success')); } @@ -348,6 +345,26 @@ class AssetsController extends AdminController { return Redirect::to("assets/$assetId/checkout")->with('error', Lang::get('admin/assets/message.checkout.error')); } + + /** + * Check the asset back into inventory + * + * @param int $assetId + * @return View + **/ + public function getCheckin($assetId) + { + // Check if the asset exists + if (is_null($asset = Asset::find($assetId))) + { + // Redirect to the asset management page with error + return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found')); + } + + return View::make('backend/assets/checkin', compact('asset')); + } + + /** * Check in the item so that it can be checked out again to someone else * @@ -371,16 +388,16 @@ class AssetsController extends AdminController { $logaction->checkedout_to = $asset->assigned_to; // Update the asset data to null, since it's being checked in - $asset->assigned_to = ''; + $asset->assigned_to = '0'; // Was the asset updated? if($asset->save()) { $logaction->asset_id = $asset->id; - $logaction->location_id = NULL; $logaction->asset_type = 'hardware'; + $logaction->note = e(Input::get('note')); $logaction->user_id = Sentry::getUser()->id; $log = $logaction->logaction('checkin from'); diff --git a/app/controllers/admin/LicensesController.php b/app/controllers/admin/LicensesController.php index b022ba3be7..c6dcd6f453 100644 --- a/app/controllers/admin/LicensesController.php +++ b/app/controllers/admin/LicensesController.php @@ -258,7 +258,8 @@ class LicensesController extends AdminController { // Declare the rules for the form validation $rules = array( - 'assigned_to' => 'required|integer|min:1' + 'assigned_to' => 'required|integer|min:1', + 'note' => 'alpha_space', ); // Create a new validator instance from our validation rules @@ -293,6 +294,7 @@ class LicensesController extends AdminController { $logaction->location_id = $assigned_to->location_id; $logaction->asset_type = 'software'; $logaction->user_id = Sentry::getUser()->id; + $logaction->note = e(Input::get('note')); $log = $logaction->logaction('checkout'); // Redirect to the new asset page @@ -303,6 +305,24 @@ class LicensesController extends AdminController { return Redirect::to('admin/licenses/$assetId/checkout')->with('error', Lang::get('admin/licenses/message.create.error'))->with('license',new License); } + + /** + * Check the license back into inventory + **/ + public function getCheckin($seatId) + { + // Check if the asset exists + if (is_null($licenseseat = LicenseSeat::find($seatId))) + { + // Redirect to the asset management page with error + return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found')); + } + return View::make('backend/licenses/checkin', compact('licenseseat')); + + } + + + /** * Check in the item so that it can be checked out again to someone else **/ @@ -315,11 +335,26 @@ class LicensesController extends AdminController { return Redirect::to('admin/licenses')->with('error', Lang::get('admin/licenses/message.not_found')); } + // Declare the rules for the form validation + $rules = array( + 'note' => 'alpha_space', + ); + + // Create a new validator instance from our validation rules + $validator = Validator::make(Input::all(), $rules); + + // If validation fails, we'll exit the operation now. + if ($validator->fails()) + { + // Ooops.. something went wrong + return Redirect::back()->withInput()->withErrors($validator); + } + $logaction = new Actionlog(); $logaction->checkedout_to = $licenseseat->assigned_to; // Update the asset data - $licenseseat->assigned_to = ''; + $licenseseat->assigned_to = '0'; // Was the asset updated? if($licenseseat->save()) @@ -327,14 +362,15 @@ class LicensesController extends AdminController { $logaction->asset_id = $licenseseat->id; $logaction->location_id = NULL; $logaction->asset_type = 'software'; + $logaction->note = e(Input::get('note')); $logaction->user_id = Sentry::getUser()->id; $log = $logaction->logaction('checkin from'); - // Redirect to the new asset page + // Redirect to the license page return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkin.success')); } - // Redirect to the asset management page with error + // Redirect to the license page with error return Redirect::to("admin/licenses")->with('error', Lang::get('admin/licenses/message.checkin.error')); } @@ -357,10 +393,7 @@ class LicensesController extends AdminController { // Redirect to the user management page return Redirect::route('licenses')->with('error', $error); } - - } - } diff --git a/app/database/migrations/2013_11_27_062510_add_note_to_asset_logs_table.php b/app/database/migrations/2013_11_27_062510_add_note_to_asset_logs_table.php new file mode 100644 index 0000000000..5e5c398bb3 --- /dev/null +++ b/app/database/migrations/2013_11_27_062510_add_note_to_asset_logs_table.php @@ -0,0 +1,36 @@ +text('note')->nullable(); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + Schema::table('asset_logs', function($table) + { + $table->dropColumn('note'); + }); + } + +} \ No newline at end of file diff --git a/app/database/seeds/ActionlogSeeder.php b/app/database/seeds/ActionlogSeeder.php index 443a438004..12293429d8 100644 --- a/app/database/seeds/ActionlogSeeder.php +++ b/app/database/seeds/ActionlogSeeder.php @@ -13,46 +13,50 @@ class ActionlogSeeder extends Seeder { // Pending (status_id is null, assigned_to = 0) $assetlog[] = array( - 'user_id' => '1', + 'user_id' => '1', 'action_type' => 'checkout', - 'asset_id' => '1', - 'checkedout_to' => '3', - 'location_id' => '3', - 'added_on' => $date->modify('-10 day'), - 'asset_type' => 'hardware', + 'asset_id' => '1', + 'checkedout_to' => '3', + 'location_id' => '3', + 'added_on' => $date->modify('-10 day'), + 'asset_type' => 'hardware', + 'note' => NULL, ); // Pending (status_id is null, assigned_to = 0) $assetlog[] = array( - 'user_id' => '1', + 'user_id' => '1', 'action_type' => 'checkin from', - 'asset_id' => '1', - 'checkedout_to' => '3', - 'location_id' => NULL, - 'added_on' => $date->modify('-10 day'), - 'asset_type' => 'hardware', + 'asset_id' => '1', + 'checkedout_to' => '3', + 'location_id' => NULL, + 'added_on' => $date->modify('-10 day'), + 'asset_type' => 'hardware', + 'note' => NULL, ); // Pending (status_id is null, assigned_to = 0) $assetlog[] = array( - 'user_id' => '1', + 'user_id' => '1', 'action_type' => 'checkout', - 'asset_id' => '1', - 'checkedout_to' => '3', - 'location_id' => '3', - 'added_on' => $date->modify('-10 day'), - 'asset_type' => 'software', + 'asset_id' => '1', + 'checkedout_to' => '3', + 'location_id' => '3', + 'added_on' => $date->modify('-10 day'), + 'asset_type' => 'software', + 'note' => NULL, ); // Pending (status_id is null, assigned_to = 0) $assetlog[] = array( - 'user_id' => '1', + 'user_id' => '1', 'action_type' => 'checkin from', - 'asset_id' => '1', - 'checkedout_to' => '3', - 'location_id' => NULL, - 'added_on' => $date->modify('-10 day'), - 'asset_type' => 'software', + 'asset_id' => '1', + 'checkedout_to' => '3', + 'location_id' => NULL, + 'added_on' => $date->modify('-10 day'), + 'asset_type' => 'software', + 'note' => NULL, ); diff --git a/app/lang/en/general.php b/app/lang/en/general.php index 4494daefdd..eeb0dbd10f 100755 --- a/app/lang/en/general.php +++ b/app/lang/en/general.php @@ -7,6 +7,7 @@ return array( 'currency' => '$', 'save' => 'Save', 'checkout' => 'Checkout', + 'checkin' => 'Checkin', 'cancel' => 'Cancel' ); diff --git a/app/models/Asset.php b/app/models/Asset.php index db01fba4e5..d156a403c5 100644 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -10,6 +10,7 @@ class Asset extends Elegant { 'model_id' => 'required', 'serial' => 'required|alpha_dash|min:3', 'warranty_months' => 'integer|min:1', + 'note' => 'alpha_space', ); diff --git a/app/models/License.php b/app/models/License.php index 3cbc405303..8a6e7a1aef 100644 --- a/app/models/License.php +++ b/app/models/License.php @@ -16,6 +16,7 @@ class License extends Elegant { 'serial' => 'required|alpha_dash|min:5', 'seats' => 'required|min:1|integer', 'license_email' => 'email', + 'note' => 'alpha_space', ); public function assignedusers() diff --git a/app/routes.php b/app/routes.php index befc84b117..af222ba1ce 100755 --- a/app/routes.php +++ b/app/routes.php @@ -37,7 +37,8 @@ Route::group(array('prefix' => 'assets'), function() 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}/checkin', array('as' => 'checkin/asset', 'uses' => 'Controllers\Admin\AssetsController@getCheckin')); + Route::post('{assetId}/checkin', 'Controllers\Admin\AssetsController@postCheckin'); Route::get('{assetId}/view', array('as' => 'view/asset', 'uses' => 'Controllers\Admin\AssetsController@getView')); @@ -70,7 +71,8 @@ Route::group(array('prefix' => 'admin'), function() Route::get('{licenseId}/delete', array('as' => 'delete/license', 'uses' => 'Controllers\Admin\LicensesController@getDelete')); 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}/checkin', array('as' => 'checkin/license', 'uses' => 'Controllers\Admin\LicensesController@getCheckin')); + Route::post('{licenseId}/checkin', 'Controllers\Admin\LicensesController@postCheckin'); Route::get('{licenseId}/view', array('as' => 'view/license', 'uses' => 'Controllers\Admin\LicensesController@getView')); }); diff --git a/app/validators.php b/app/validators.php index 8b53512d3e..2232752018 100644 --- a/app/validators.php +++ b/app/validators.php @@ -2,5 +2,5 @@ Validator::extend('alpha_space', function($attribute,$value,$parameters) { - return preg_match("/^[-_,. a-zA-Z0-9]+$/",$value); + return preg_match("/^[-_,!. a-zA-Z0-9]+$/",$value); }); diff --git a/app/views/backend/assets/checkin.blade.php b/app/views/backend/assets/checkin.blade.php new file mode 100644 index 0000000000..6b0a19e4e0 --- /dev/null +++ b/app/views/backend/assets/checkin.blade.php @@ -0,0 +1,66 @@ +@extends('backend/layouts/default') + +{{-- Page title --}} +@section('title') + @if ($asset->id) + Checkin Asset :: + @else + Checkin Asset :: + @endif +@parent +@stop + +{{-- Page content --}} +@section('content') +