From c69038d3ae7eeb36c3d3f8552092774bdff5340c Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 9 Jun 2015 02:00:55 -0700 Subject: [PATCH] Fixes #836 --- app/controllers/admin/AssetsController.php | 156 ++++++++++----------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 7ca7278b7a22..4f4b180a4d0e 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -156,7 +156,7 @@ public function postCreate() } else { $asset->rtd_location_id = e(Input::get('rtd_location_id')); } - + $checkModel = Config::get('app.url').'/api/models/'.e(Input::get('model_id')).'/check'; $asset->mac_address = ($checkModel == true) ? e(Input::get('mac_address')) : NULL; @@ -293,7 +293,7 @@ public function postEdit($assetId = null) } else { $asset->rtd_location_id = e(Input::get('rtd_location_id')); } - + $checkModel = Config::get('app.url').'/api/models/'.e(Input::get('model_id')).'/check'; $asset->mac_address = ($checkModel == true) ? e(Input::get('mac_address')) : NULL; @@ -441,20 +441,20 @@ public function postCheckout($assetId) $data['first_name'] = $user->first_name; $data['item_name'] = $asset->showAssetName(); $data['require_acceptance'] = $asset->requireAcceptance(); - + $settings = Setting::getSettings(); - + if ($settings->slack_endpoint) { - + $slack_settings = [ 'username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true ]; - + $client = new \Maknz\Slack\Client($settings->slack_endpoint,$slack_settings); - + try { $client->attach([ 'color' => 'good', @@ -468,13 +468,13 @@ public function postCheckout($assetId) 'value' => e($logaction->note) ], - - + + ] ])->send('Asset Checked Out'); - + } catch (Exception $e) { - + } } @@ -563,18 +563,18 @@ public function postCheckin($assetId = null, $backto = null) $log = $logaction->logaction('checkin from'); $settings = Setting::getSettings(); - + if ($settings->slack_endpoint) { - + $slack_settings = [ 'username' => $settings->botname, 'channel' => $settings->slack_channel, 'link_names' => true ]; - + $client = new \Maknz\Slack\Client($settings->slack_endpoint,$slack_settings); - + try { $client->attach([ 'color' => 'good', @@ -587,16 +587,16 @@ public function postCheckin($assetId = null, $backto = null) 'title' => 'Note:', 'value' => e($logaction->note) ], - + ] ])->send('Asset Checked In'); - + } catch (Exception $e) { - + } } - + if ($backto=='user') { return Redirect::to("admin/users/".$return_to.'/view')->with('success', Lang::get('admin/hardware/message.checkin.success')); } else { @@ -872,51 +872,51 @@ public function displayFile($assetID = null, $fileId = null) **/ public function postBulkEdit($assets = null) { - + if (!Input::has('edit_asset')) { return Redirect::back()->with('error', 'No assets selected'); } else { - $asset_raw_array = Input::get('edit_asset'); + $asset_raw_array = Input::get('edit_asset'); foreach ($asset_raw_array as $asset_id => $value) { - $asset_ids[] = $asset_id; - + $asset_ids[] = $asset_id; + } - + } - + if (Input::has('bulk_actions')) { - - + + // Create labels if (Input::get('bulk_actions')=='labels') { $assets = Asset::find($asset_ids); $assetcount = count($assets); $count = 0; - - $settings = Setting::getSettings(); + + $settings = Setting::getSettings(); return View::make('backend/hardware/labels')->with('assets',$assets)->with('settings',$settings)->with('count',$count); - - // Bulk edit + + // Bulk edit } elseif (Input::get('bulk_actions')=='edit') { - + $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); - + } - + } else { - return Redirect::back()->with('error', 'No action selected'); + return Redirect::back()->with('error', 'No action selected'); } - + } @@ -991,7 +991,7 @@ public function getDatatable($status = null) { $assets = Asset::with('model','assigneduser','assigneduser.userloc','assetstatus','defaultLoc','assetlog','model','model.category')->Hardware()->select(array('id', 'name','model_id','assigned_to','asset_tag','serial','status_id','purchase_date','deleted_at')); - + switch ($status) { case 'Pending': @@ -1015,95 +1015,95 @@ public function getDatatable($status = null) case 'Deleted': $assets->withTrashed()->Deleted(); break; - } - - + } + + $assets = $assets->orderBy('asset_tag', 'ASC')->get(); - - - $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($assets) - { + + + $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($assets) + { if ($assets->deleted_at=='') { return ' '; } elseif ($assets->model->deleted_at=='') { return ''; } - + }); - - $inout = new \Chumper\Datatable\Columns\FunctionColumn('inout', function ($assets) - { + + $inout = new \Chumper\Datatable\Columns\FunctionColumn('inout', function ($assets) + { if (($assets->assigned_to !='') && ($assets->assigned_to > 0)) { return ''.Lang::get('general.checkin').''; } else { return ''.Lang::get('general.checkout').''; } }); - - - + + + return Datatable::collection($assets) ->addColumn('',function($assets) - { - return ''; + { + return ''; }) ->addColumn('name',function($assets) { return ''.$assets->name.''; - }) + }) ->addColumn('asset_tag',function($assets) { return ''.$assets->asset_tag.''; - }) - + }) + ->showColumns('serial') - + ->addColumn('model',function($assets) { return $assets->model->name; }) - + ->addColumn('status',function($assets) - { + { if ($assets->assigned_to!='') { return link_to('../admin/users/'.$assets->assigned_to.'/view', $assets->assigneduser->fullName()); } else { - return $assets->assetstatus->name; + return $assets->assetstatus->name; } - + }) ->addColumn('location',function($assets) { - if ($assets->assigned_to && $assets->assigneduser->userloc) { - return link_to('admin/location/'.$assets->assigneduser->userloc->id.'/edit', $assets->assigneduser->userloc->name); + if ($assets->assigned_to && $assets->assigneduser->userloc) { + return link_to('admin/settings/locations/'.$assets->assigneduser->userloc->id.'/edit', $assets->assigneduser->userloc->name); } elseif ($assets->defaultLoc){ - return link_to('admin/location/'.$assets->defaultLoc->id.'/edit', $assets->defaultLoc->name); + return link_to('admin/settings/locations/'.$assets->defaultLoc->id.'/edit', $assets->defaultLoc->name); } }) ->addColumn('category',function($assets) { return $assets->model->category->name; - }) - + }) + ->addColumn('eol',function($assets) { return $assets->eol_date(); - }) - - + }) + + ->addColumn('checkout_date',function($assets) - { + { if (($assets->assigned_to!='') && ($assets->assetlog->first())) { return $assets->assetlog->first()->created_at->format('Y-m-d'); - } - - }) - ->addColumn($inout) - ->addColumn($actions) + } + + }) + ->addColumn($inout) + ->addColumn($actions) ->searchColumns('name', 'asset_tag', 'serial', 'model', 'status','location','eol','checkout_date', 'inout','category') ->orderColumns('name', 'asset_tag', 'serial', 'model', 'status','location','eol','checkout_date', 'inout') ->make(); - + } }