From a901a648af4c383281ca6f36b5887f49604cf917 Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 26 Jul 2015 22:53:48 -0700 Subject: [PATCH] Fixes #875 - allow user to decline asset and check asset back in if declined --- .../account/ViewAssetsController.php | 100 +++++++++++------- app/lang/en/admin/users/message.php | 3 + app/routes.php | 3 +- .../frontend/account/accept-asset.blade.php | 57 ++++++---- 4 files changed, 101 insertions(+), 62 deletions(-) diff --git a/app/controllers/account/ViewAssetsController.php b/app/controllers/account/ViewAssetsController.php index d208cef47e37..9fb5d127fe8f 100755 --- a/app/controllers/account/ViewAssetsController.php +++ b/app/controllers/account/ViewAssetsController.php @@ -59,105 +59,123 @@ public function getRequestAsset($assetId = null) { } - - - + + + // Get the acceptance screen public function getAcceptAsset($logID = null) { - + if (is_null($findlog = Actionlog::find($logID))) { // Redirect to the asset management page return Redirect::to('account')->with('error', Lang::get('admin/hardware/message.does_not_exist')); } - + // Asset if (($findlog->asset_id!='') && ($findlog->asset_type=='hardware')) { $item = Asset::find($findlog->asset_id); - - // software - } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { + + // software + } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { $item = License::find($findlog->asset_id); - // accessories + // accessories } elseif ($findlog->accessory_id!='') { - $item = Accessory::find($findlog->accessory_id); + $item = Accessory::find($findlog->accessory_id); } - + // Check if the asset exists if (is_null($item)) { // Redirect to the asset management page return Redirect::to('account')->with('error', Lang::get('admin/hardware/message.does_not_exist')); } - + return View::make('frontend/account/accept-asset', compact('item'))->with('findlog', $findlog); - - - + + + } - + // Save the acceptance public function postAcceptAsset($logID = null) { - - + + // Check if the asset exists if (is_null($findlog = Actionlog::find($logID))) { // Redirect to the asset management page return Redirect::to('account/view-assets')->with('error', Lang::get('admin/hardware/message.does_not_exist')); } - - + + if ($findlog->accepted_id!='') { // Redirect to the asset management page return Redirect::to('account/view-assets')->with('error', Lang::get('admin/users/message.error.asset_already_accepted')); } - + + if (!Input::has('asset_acceptance')) { + return Redirect::to('account/view-assets')->with('error', Lang::get('admin/users/message.error.accept_or_decline')); + } + $user = Sentry::getUser(); $logaction = new Actionlog(); - + + if (Input::get('asset_acceptance')=='accepted') { + $logaction_msg = 'User accepted'; + $return_msg = Lang::get('admin/users/message.accepted'); + } else { + $logaction_msg = 'User declined'; + $return_msg = Lang::get('admin/users/message.declined'); + } + // Asset if (($findlog->asset_id!='') && ($findlog->asset_type=='hardware')) { $logaction->asset_id = $findlog->asset_id; $logaction->accessory_id = NULL; $logaction->asset_type = 'hardware'; - - // software - } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { + + if (Input::get('asset_acceptance')!='accepted') { + DB::table('assets') + ->where('id', $findlog->asset_id) + ->update(array('assigned_to' => null)); + } + + + // software + } elseif (($findlog->asset_id!='') && ($findlog->asset_type=='software')) { $logaction->asset_id = $findlog->asset_id; $logaction->accessory_id = NULL; $logaction->asset_type = 'software'; - - // accessories + + // accessories } elseif ($findlog->accessory_id!='') { $logaction->asset_id = NULL; $logaction->accessory_id = $findlog->accessory_id; - $logaction->asset_type = 'accessory'; + $logaction->asset_type = 'accessory'; } - + $logaction->checkedout_to = $findlog->checkedout_to; - + $logaction->note = e(Input::get('note')); $logaction->user_id = $user->id; $logaction->accepted_at = date("Y-m-d h:i:s"); - $log = $logaction->logaction('accepted'); - - + $log = $logaction->logaction($logaction_msg); + $update_checkout = DB::table('asset_logs') ->where('id',$findlog->id) ->update(array('accepted_id' => $logaction->id)); - + if ($update_checkout ) { - return Redirect::to('account/view-assets')->with('success', 'You have successfully accept this asset.'); - + return Redirect::to('account/view-assets')->with('success', $return_msg); + } else { return Redirect::to('account/view-assets')->with('error', 'Something went wrong '); } - - - - + + + + } - + diff --git a/app/lang/en/admin/users/message.php b/app/lang/en/admin/users/message.php index 38257ce86a44..926327c902c1 100755 --- a/app/lang/en/admin/users/message.php +++ b/app/lang/en/admin/users/message.php @@ -2,6 +2,8 @@ return array( + 'accepted' => 'You have successfully accepted this asset.', + 'declined' => 'You have successfully declined this asset.', 'user_exists' => 'User already exists!', 'user_not_found' => 'User [:id] does not exist.', 'user_login_required' => 'The login field is required', @@ -29,6 +31,7 @@ 'unsuspend' => 'There was an issue unsuspending the user. Please try again.', 'import' => 'There was an issue importing users. Please try again.', 'asset_already_accepted' => 'This asset has already been accepted.', + 'accept_or_decline' => 'You must either accept or decline this asset.', ), 'deletefile' => array( diff --git a/app/routes.php b/app/routes.php index e4734a666427..d4de0421613f 100755 --- a/app/routes.php +++ b/app/routes.php @@ -437,8 +437,7 @@ [ 'as' => 'account/accept-assets', 'uses' => 'ViewAssetsController@getAcceptAsset' ] ); Route::post( 'accept-asset/{logID}', [ 'as' => 'account/asset-accepted', 'uses' => 'ViewAssetsController@postAcceptAsset' ] ); - Route::get( 'decline-asset/{logID}', - [ 'as' => 'account/decline-assets', 'uses' => 'ViewAssetsController@getDeclineAsset' ] ); + # Profile Route::get( 'requestable-assets', diff --git a/app/views/frontend/account/accept-asset.blade.php b/app/views/frontend/account/accept-asset.blade.php index 239c2eda8c03..4b6e13287af7 100644 --- a/app/views/frontend/account/accept-asset.blade.php +++ b/app/views/frontend/account/accept-asset.blade.php @@ -2,40 +2,59 @@ {{-- Page title --}} @section('title') - + @parent @stop {{-- Page content --}} @section('content') +
- @lang('general.back') +

Accept {{{ $item->name }}}

-
- -
- - - - - -
- -
- @lang('button.cancel') - -
-
-
-
+
+
+ + + + +
+ +
+ +
+ +
+ + + +
+
+ +
+
+
+
@stop