Skip to content

Commit

Permalink
Fixes #596 - better routes for checking in multiple items from user
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Mar 4, 2015
1 parent 4ae624a commit 1c333e4
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 96 deletions.
4 changes: 2 additions & 2 deletions app/config/version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return array (
'app_version' => 'v1.2.6-15',
'hash_version' => 'v1.2.6-15-g2d196b1',
'app_version' => 'v1.2.6-16',
'hash_version' => 'v1.2.6-16-g2540e90',
);
109 changes: 59 additions & 50 deletions app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,21 +450,21 @@ public function postCheckout($assetId)
$logaction->user_id = Sentry::getUser()->id;
$logaction->note = e(Input::get('note'));
$log = $logaction->logaction('checkout');

$data['log_id'] = $logaction->id;
$data['eula'] = $asset->getEula();
$data['first_name'] = $user->first_name;
$data['item_name'] = $asset->name;
$data['require_acceptance'] = $asset->requireAcceptance();


if (($asset->requireAcceptance()=='1') || ($asset->getEula())) {

Mail::send('emails.accept-asset', $data, function ($m) use ($user) {
$m->to($user->email, $user->first_name . ' ' . $user->last_name);
$m->subject('Confirm asset delivery');
});
}
}

// Redirect to the new asset page
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkout.success'));
Expand All @@ -481,15 +481,15 @@ public function postCheckout($assetId)
* @param int $assetId
* @return View
**/
public function getCheckin($assetId)
public function getCheckin($assetId, $backto = null)
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
// Redirect to the asset management page with error
return Redirect::to('hardware')->with('error', Lang::get('admin/hardware/message.not_found'));
}

return View::make('backend/hardware/checkin', compact('asset'));
return View::make('backend/hardware/checkin', compact('asset'))->with('backto', $backto);
}


Expand All @@ -499,7 +499,7 @@ public function getCheckin($assetId)
* @param int $assetId
* @return View
**/
public function postCheckin($assetId)
public function postCheckin($assetId = null, $backto = null)
{
// Check if the asset exists
if (is_null($asset = Asset::find($assetId))) {
Expand All @@ -511,12 +511,16 @@ public function postCheckin($assetId)
$user = User::find($asset->assigned_to);
}

// This is just used for the redirect
$return_to = $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 = NULL;


// Was the asset updated?
if($asset->save()) {

Expand All @@ -527,8 +531,13 @@ public function postCheckin($assetId)
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkin from');

// Redirect to the new asset page
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkin.success'));

if ($backto=='user') {
return Redirect::to("admin/users/".$return_to.'/view')->with('success', Lang::get('admin/hardware/message.checkin.success'));
} else {
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.checkin.success'));
}

}

// Redirect to the asset management page with error
Expand Down Expand Up @@ -578,7 +587,7 @@ public function getQrCode($assetId = null)

if ($settings->qr_code == '1') {
$asset = Asset::find($assetId);

if (isset($asset->id,$asset->asset_tag)) {

$content = DNS2D::getBarcodePNG(route('view/hardware', $asset->id), "QRCODE",
Expand Down Expand Up @@ -657,8 +666,8 @@ public function getRestore($assetId = null)
}

}


/**
* Upload the file to the server
*
Expand Down Expand Up @@ -788,10 +797,10 @@ public function displayFile($assetID = null, $fileId = null)
return Redirect::route('hardware')->with('error', $error);
}
}




/**
* Display bulk edit screen
*
Expand All @@ -801,20 +810,20 @@ public function postBulkEdit($assets = null)
{

if (Input::has('edit_asset')) {

$assets = Input::get('edit_asset');

$supplier_list = array('' => '') + Supplier::orderBy('name', 'asc')->lists('name', 'id');
$statuslabel_list = array('' => '') + Statuslabel::lists('name', 'id');
$location_list = array('' => '') + Location::lists('name', 'id');
}

return View::make('backend/hardware/bulk')->with('assets',$assets)->with('supplier_list',$supplier_list)->with('statuslabel_list',$statuslabel_list)->with('location_list',$location_list);

}



/**
* Save bulk edits
*
Expand All @@ -824,63 +833,63 @@ public function postBulkSave($assets = null)
{

if (Input::has('bulk_edit')) {

$assets = Input::get('bulk_edit');

if ( (Input::has('purchase_date')) || (Input::has('rtd_location_id')) || (Input::has('status_id')) ) {

foreach ($assets as $key => $value) {

$update_array = array();
if (Input::has('purchase_date')) {

if (Input::has('purchase_date')) {
$update_array['purchase_date'] = e(Input::get('purchase_date'));
}
if (Input::has('rtd_location_id')) {

if (Input::has('rtd_location_id')) {
$update_array['rtd_location_id'] = e(Input::get('rtd_location_id'));
}
if (Input::has('status_id')) {

if (Input::has('status_id')) {
$update_array['status_id'] = e(Input::get('status_id'));
}


if (DB::table('assets')
->where('id', $key)
->update($update_array)) {
->update($update_array)) {

$logaction = new Actionlog();
$logaction->asset_id = $key;
$logaction->asset_type = 'hardware';
$logaction->created_at = date("Y-m-d h:i:s");
if (Input::has('rtd_location_id')) {

if (Input::has('rtd_location_id')) {
$logaction->location_id = e(Input::get('rtd_location_id'));
}
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('update');

}

} // endforeach

return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.update.success'));

// no values given, nothing to update
// no values given, nothing to update
} else {
return Redirect::to("hardware")->with('info',Lang::get('admin/hardware/message.update.nothing_updated'));

}


} // endif

return Redirect::to("hardware");
return Redirect::to("hardware");

}




}
16 changes: 10 additions & 6 deletions app/controllers/admin/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,14 @@ public function postCheckout($seatId)
/**
* Check the license back into inventory
**/
public function getCheckin($seatId)
public function getCheckin($seatId = null, $backto = null)
{
// 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'));
return View::make('backend/licenses/checkin', compact('licenseseat'))->with('backto',$backto);

}

Expand All @@ -552,7 +552,7 @@ public function getCheckin($seatId)
/**
* Check in the item so that it can be checked out again to someone else
**/
public function postCheckin($seatId)
public function postCheckin($seatId = null, $backto = null)
{
// Check if the asset exists
if (is_null($licenseseat = LicenseSeat::find($seatId))) {
Expand All @@ -574,7 +574,7 @@ public function postCheckin($seatId)
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}

$return_to = $licenseseat->assigned_to;
$logaction = new Actionlog();
$logaction->checkedout_to = $licenseseat->assigned_to;

Expand All @@ -591,8 +591,12 @@ public function postCheckin($seatId)
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkin from');

// Redirect to the license page
return Redirect::to("admin/licenses")->with('success', Lang::get('admin/licenses/message.checkin.success'));
if ($backto=='user') {
return Redirect::to("admin/users/".$return_to.'/view')->with('success', Lang::get('admin/licenses/message.checkin.success'));
} else {
return Redirect::to("admin/licenses/".$licenseseat->license_id."/view")->with('success', Lang::get('admin/licenses/message.checkin.success'));
}

}

// Redirect to the license page with error
Expand Down
Loading

0 comments on commit 1c333e4

Please sign in to comment.