Checkout/checkin functionality for assets

Need to refactor a bit and add to licenses as well
This commit is contained in:
snipe
2013-11-17 20:36:54 -05:00
parent a7281ef5b5
commit 343e13efee
4 changed files with 67 additions and 12 deletions
+62 -10
View File
@@ -213,15 +213,17 @@ class AssetsController extends AdminController {
}
// Get the dropdown of users and then pass it to the checkout view
$users = DB::table('users')->select(DB::raw('concat (first_name," ",last_name) as full_name,id'))->lists('full_name', 'id');
return View::make('backend/assets/checkout', compact('asset'))->with('users',$users);
$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);
}
/**
* Check out the asset to a person
**/
public function postCheckout($assetId,$userId)
public function postCheckout($assetId)
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId)))
@@ -230,19 +232,69 @@ class AssetsController extends AdminController {
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.not_found'));
}
$user_id = e(Input::get('user_id'));
// Check if the asset exists
if (is_null($user = User::find($userId)))
if (is_null($user = User::find($user_id)))
{
// Redirect to the asset management page with error
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.does_not_exist'));
return Redirect::to('admin')->with('error', Lang::get('admin/assets/message.user_does_not_exist'));
}
echo 'bar';
// Delete the asset
//$asset->delete();
// Declare the rules for the form validation
$rules = array(
'user_id' => 'required'
);
// Redirect to the asset management page
//return Redirect::to('admin')->with('success', Lang::get('admin/assets/message.checkout.success'));
// 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);
}
// Update the asset data
$asset->assigned_to = e(Input::get('user_id'));
// Was the asset updated?
if($asset->save())
{
// Redirect to the new asset page
return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkout.success'));
}
// Redirect to the asset management page with error
return Redirect::to("assets/$assetId/checkout")->with('error', Lang::get('admin/assets/message.checkout.error'));
}
/**
* Check out the asset to a person
**/
public function postCheckin($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'));
}
// Update the asset data
$asset->assigned_to = '';
// Was the asset updated?
if($asset->save())
{
// Redirect to the new asset page
return Redirect::to("admin")->with('success', Lang::get('admin/assets/message.checkout.success'));
}
// Redirect to the asset management page with error
return Redirect::to("admin")->with('error', Lang::get('admin/assets/message.checkout.error'));
}
+2
View File
@@ -23,6 +23,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'));
+1 -2
View File
@@ -56,12 +56,11 @@
<div class="control-group {{ $errors->has('user_id') ? 'error' : '' }}">
<label class="control-label" for="parent">Checkout to</label>
<div class="controls">
{{ Form::select('user_id', $users , Input::old('user_id', $asset->user_id)) }}
{{ Form::select('user_id', $users_list , Input::old('user_id', $asset->assigned_to)) }}
{{ $errors->first('user_id', '<span class="help-inline">:message</span>') }}
</div>
</div>
</div>
<!-- Form actions -->
+2
View File
@@ -44,6 +44,7 @@ Assets ::
@if ($asset->assigned_to != 0)
{{ $asset->assigned_to }}
<a href="{{ route('checkin/asset', $asset->id) }}" class="btn btn-mini">Checkin</a>
@else
<a href="{{ route('checkout/asset', $asset->id) }}" class="btn btn-mini">Checkout</a>
@endif
@@ -56,6 +57,7 @@ Assets ::
<td>
<a href="{{ route('update/asset', $asset->id) }}" class="btn btn-mini">@lang('button.edit')</a>
<a href="{{ route('delete/asset', $asset->id) }}" class="btn btn-mini btn-danger">@lang('button.delete')</a>
</td>
</tr>
@endforeach