From c513007b36b2bb8d6d09c9a25fbbf5e3ac71760c Mon Sep 17 00:00:00 2001 From: madd15 Date: Thu, 30 Jul 2015 13:44:32 +0930 Subject: [PATCH 1/4] Add sort to table, missing most columns still --- app/controllers/admin/AssetsController.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index cbb88ff4e218..c71911e7d2ff 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -1089,17 +1089,32 @@ public function getDatatable($status = null) $assets->where('order_number','=',e(Input::get('order_number'))); } - $assets = $assets->orderBy('asset_tag', 'ASC'); - if (Input::has('search')) { $assets = $assets->TextSearch(Input::get('search')); } + + if (Input::has('sort') && Input::has('order')){ + $order = Input::get('order'); + $sort = Input::get('sort'); + + switch ($sort) + { + case 'model': + $assets = $assets->OrderModels($order); + break; + default: + $assets = $assets->orderBy($sort, $order); + break; + } + } else { + $assets = $assets->orderBy('asset_tag', 'ASC'); + } + $assetCount = $assets->count(); $assets = $assets->skip(Input::get('offset'))->take(Input::get('limit'))->get(); $rows = array(); - $i=0; foreach ($assets as $asset) { if ($asset->deleted_at=='') { $actions = '
'; @@ -1133,7 +1148,6 @@ public function getDatatable($status = null) 'change' => $inout, 'actions' => $actions ); - $i++; } $data = array('total'=>$assetCount, 'rows'=>$rows); From e66ea4dcd1d00419f33d08aacb58f9aa6a63834d Mon Sep 17 00:00:00 2001 From: madd15 Date: Thu, 30 Jul 2015 13:45:46 +0930 Subject: [PATCH 2/4] Build out search and add Model order scope --- app/models/Asset.php | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/app/models/Asset.php b/app/models/Asset.php index dda08ac1ffe9..9fcad6f461c8 100755 --- a/app/models/Asset.php +++ b/app/models/Asset.php @@ -391,8 +391,7 @@ public function scopeDeleted($query) { return $query->whereNotNull('deleted_at'); } - - + /** * Query builder scope to search on text * @@ -402,18 +401,50 @@ public function scopeDeleted($query) * @return Illuminate\Database\Query\Builder Modified query builder */ public function scopeTextSearch($query, $search) - { - - - return $query->where(function($query) use ($search) - { + { + $search = explode('+', $search); - $query->where('name','LIKE','%'.$search.'%') + return $query->where(function($query) use ($search) + { + foreach ($search as $search) { + $query->whereHas('model', function($query) use ($search) { + $query->join('categories','models.category_id','=','categories.id') + ->where('categories.name','LIKE','%'.$search.'%') + ->orWhere('models.name','LIKE','%'.$search.'%'); + })->orWhere(function($query) use ($search) { + $query->whereHas('assetstatus', function($query) use ($search) { + $query->where('name','LIKE','%'.$search.'%'); + }); + })->orWhere(function($query) use ($search) { + $query->whereHas('defaultLoc', function($query) use ($search) { + $query->where('name','LIKE','%'.$search.'%'); + }); + })->orWhere(function($query) use ($search) { + $query->whereHas('assigneduser', function($query) use ($search) { + $query->where('first_name','LIKE','%'.$search.'%') + ->orWhere('last_name','LIKE','%'.$search.'%'); + }); + })->orWhere('name','LIKE','%'.$search.'%') ->orWhere('asset_tag','LIKE','%'.$search.'%') - ->orWhere('serial','LIKE','%'.$search.'%'); - }); - - } - + ->orWhere('serial','LIKE','%'.$search.'%') + ->orWhere('order_number','LIKE','%'.$search.'%'); + } + }); + } + /** + * Query builder scope to order on model + * + * @param Illuminate\Database\Query\Builder $query Query builder instance + * @param text $order Order + * + * @return Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderModels($query, $order) + { + return $query->where(function($query) use ($order) + { + $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.name', $order); + }); + } } From f152841e817ab6e9571eaad56d30fd5fc7e2715a Mon Sep 17 00:00:00 2001 From: madd15 Date: Thu, 30 Jul 2015 13:46:59 +0930 Subject: [PATCH 3/4] quick fix $inout/$action issue --- app/controllers/admin/AssetsController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index c71911e7d2ff..8fb42f7d2b62 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -1116,6 +1116,8 @@ public function getDatatable($status = null) $rows = array(); foreach ($assets as $asset) { + $inout = ''; + $actions = ''; if ($asset->deleted_at=='') { $actions = '
'; } elseif ($asset->model->deleted_at=='') { From 032d79593aac47c1516061e30882784fd64fd342 Mon Sep 17 00:00:00 2001 From: madd15 Date: Thu, 30 Jul 2015 13:47:43 +0930 Subject: [PATCH 4/4] quick fix $inout/$action issue --- app/controllers/admin/AssetsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/AssetsController.php b/app/controllers/admin/AssetsController.php index 8fb42f7d2b62..24bd76ea828c 100755 --- a/app/controllers/admin/AssetsController.php +++ b/app/controllers/admin/AssetsController.php @@ -1147,8 +1147,8 @@ public function getDatatable($status = null) 'notes' => $asset->notes, 'order' => ($asset->order_number) ? ''.$asset->order_number.'' : '', 'checkout_date' => (($asset->assigned_to!='')&&($asset->assetlog->first())) ? $asset->assetlog->first()->created_at->format('Y-m-d') : '', - 'change' => $inout, - 'actions' => $actions + 'change' => ($inout) ? $inout : '', + 'actions' => ($actions) ? $actions : '' ); }