Skip to content

Commit

Permalink
Fixes #875 - allow user to decline asset and check asset back in if d…
Browse files Browse the repository at this point in the history
…eclined
  • Loading branch information
snipe committed Jul 27, 2015
1 parent a099d16 commit a901a64
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 62 deletions.
100 changes: 59 additions & 41 deletions app/controllers/account/ViewAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ');
}









}




Expand Down
3 changes: 3 additions & 0 deletions app/lang/en/admin/users/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
57 changes: 38 additions & 19 deletions app/views/frontend/account/accept-asset.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,59 @@

{{-- Page title --}}
@section('title')

@parent
@stop

{{-- Page content --}}
@section('content')

<style>
.form-horizontal .control-label, .form-horizontal .radio, .form-horizontal .checkbox, .form-horizontal .radio-inline, .form-horizontal .checkbox-inline {
padding-top: 17px;
padding-right: 10px;
}
.radio input[type="radio"], .radio-inline input[type="radio"], .checkbox input[type="checkbox"], .checkbox-inline input[type="checkbox"] {
margin-left: -40px;
}
</style>
<div class="row header">
<div class="col-md-12">
<a href="{{ URL::previous() }}" class="btn-flat gray pull-right"><i class="fa fa-arrow-circle-left icon-white"></i> @lang('general.back')</a>

<h3>
Accept {{{ $item->name }}}</h3>
</div>
</div>


<div class="col-md-9 bio">

<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="logId" value="{{ $findlog->id }}" />

<!-- Form actions -->
<div class="form-group">

<div class="col-md-7 col-md-offset-3">
<a class="btn btn-link" href="{{ route('account') }}">@lang('button.cancel')</a>
<button type="submit" class="btn btn-success"><i class="fa fa-check icon-white"></i> Accept </button>
</div>
</div>
</form>
</div>
<div class="col-md-12">
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="logId" value="{{ $findlog->id }}" />

<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="accepted" value="accepted"> I accept
</label>
</div>

<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="declined" value="declined"> I decline
</label>
</div>


<!-- Form actions -->
<div class="form-group">
<div class="col-md-7 col-md-offset-3">
<button type="submit" class="btn btn-success">Submit </button>
</div>
</div>
</form>
</div>
</div>

@stop

0 comments on commit a901a64

Please sign in to comment.