Skip to content

Commit

Permalink
Get the accessory pivot ID
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Feb 26, 2015
1 parent 21799cc commit 47f1488
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions app/controllers/admin/AccessoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ public function postCheckout($accessoryId)
$logaction->note = e(Input::get('note'));
$log = $logaction->logaction('checkout');

$data['accessory_id'] = $accessory->id;
$accessory_user = DB::table('accessories_users')->where('assigned_to','=',$accessory->assigned_to)->where('accessory_id','=',$accessory->id)->first();

print_r($accessory_user);
//$data['accessory_user_id'] = $accessory_user->id;
$data['eula'] = $accessory->getEula();
$data['first_name'] = $user->first_name;

Expand All @@ -302,14 +305,15 @@ public function postCheckout($accessoryId)
* @param int $accessoryId
* @return View
**/
public function getCheckin($accessoryId)
public function getCheckin($accessoryUserId)
{
// Check if the accessory exists
if (is_null($accessory = Accessory::find($accessoryId))) {
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
// Redirect to the accessory management page with error
return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessories/message.not_found'));
}

$accessory = Accessory::find($accessory_user->accessory_id);
return View::make('backend/accessories/checkin', compact('accessory'));
}

Expand All @@ -320,42 +324,37 @@ public function getCheckin($accessoryId)
* @param int $accessoryId
* @return View
**/
public function postCheckin($accessoryId)
public function postCheckin($accessoryUserId)
{
// Check if the accessory exists
if (is_null($accessory = Accessory::find($accessoryId))) {
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
// Redirect to the accessory management page with error
return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessory/message.not_found'));
}

if (!is_null($accessory->assigned_to)) {
$user = User::find($accessory->assigned_to);
return Redirect::to('admin/accessories')->with('error', Lang::get('admin/accessories/message.not_found'));
}


$accessory = Accessory::find($accessory_user->accessory_id);
$logaction = new Actionlog();
$logaction->checkedout_to = $accessory->assigned_to;

// Update the accessory data to null, since it's being checked in
$accessory->assigned_to = NULL;

// Was the accessory updated?
if($accessory->users()->detach($accessoryId)) {
if(DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {

$logaction->accessory_id = $accessory->id;
$logaction->location_id = NULL;
$logaction->accessory_type = 'accessory';
$logaction->note = e(Input::get('note'));
$logaction->asset_type = 'accessory';
$logaction->user_id = Sentry::getUser()->id;
$log = $logaction->logaction('checkin from');

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

// Redirect to the accessory management page with error
return Redirect::to("admin/accessories")->with('error', Lang::get('admin/accessory/message.checkin.error'));
return Redirect::to("admin/accessories")->with('error', Lang::get('admin/accessories/message.checkin.error'));
}


Expand Down

0 comments on commit 47f1488

Please sign in to comment.