diff --git a/app/controllers/admin/ConsumablesController.php b/app/controllers/admin/ConsumablesController.php index 05376143b6..19f0786c97 100644 --- a/app/controllers/admin/ConsumablesController.php +++ b/app/controllers/admin/ConsumablesController.php @@ -348,47 +348,57 @@ class ConsumablesController extends AdminController public function getDatatable() { $consumables = Consumable::select(array('id','name','qty')) - ->whereNull('deleted_at') - ->orderBy('created_at', 'DESC'); + ->whereNull('deleted_at'); - $consumables = $consumables->get(); + if (Input::has('search')) { + $consumables = $consumables->TextSearch(Input::get('search')); + } - $actions = new \Chumper\Datatable\Columns\FunctionColumn('actions',function($consumables) - { - return 'numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').''; - }); + $allowed_columns = ['name']; + $order = Input::get('order') === 'asc' ? 'asc' : 'desc'; + $sort = in_array(Input::get('sort'), $allowed_columns) ? Input::get('sort') : 'created_at'; + + $consumables->orderBy($sort, $order); + + $consumCount = $consumables->count(); + $consumables = $consumables->skip(Input::get('offset'))->take(Input::get('limit'))->get(); + + $rows = array(); + + foreach($consumables as $consumable) { + $actions = 'numRemaining() > 0 ) ? '' : ' disabled').'>'.Lang::get('general.checkout').''; + + $rows[] = array( + 'name' => link_to('admin/consumables/'.$consumable->id.'/view', $consumable->name), + 'qty' => $consumable->qty, + 'numRemaining' => $consumable->numRemaining(), + 'actions' => $actions + ); + } + + $data = array('total' => $consumCount, 'rows' => $rows); + + return $data; - return Datatable::collection($consumables) - ->addColumn('name',function($consumables) - { - return link_to('admin/consumables/'.$consumables->id.'/view', $consumables->name); - }) - ->addColumn('qty',function($consumables) - { - return $consumables->qty; - }) - ->addColumn('numRemaining',function($consumables) - { - return $consumables->numRemaining(); - }) - ->addColumn($actions) - ->searchColumns('name','qty','numRemaining','actions') - ->orderColumns('name','qty','numRemaining','actions') - ->make(); } public function getDataView($consumableID) { $consumable = Consumable::find($consumableID); $consumable_users = $consumable->users; + $count = $consumable_users->count(); + $rows = array(); - return Datatable::collection($consumable_users) - ->addColumn('name',function($consumable_users) - { - return link_to('/admin/users/'.$consumable_users->id.'/view', $consumable_users->fullName()); - }) - ->make(); + foreach ($consumable_users as $user) { + $rows[] = array( + 'name' => link_to('/admin/users/'.$user->id.'/view', $user->fullName()) + ); + } + + $data = array('total' => $count, 'rows' => $rows); + + return $data; } } diff --git a/app/models/Accessory.php b/app/models/Accessory.php index d8e9cb7ba7..6d77764e30 100755 --- a/app/models/Accessory.php +++ b/app/models/Accessory.php @@ -68,7 +68,7 @@ class Accessory extends Elegant return $remaining; } - /** + /** * Query builder scope to search on text * * @param Illuminate\Database\Query\Builder $query Query builder instance @@ -78,13 +78,10 @@ class Accessory extends Elegant */ public function scopeTextSearch($query, $search) { - $search = explode('+', $search); return $query->where(function($query) use ($search) { - foreach ($search as $s) { $query->where('name', 'LIKE', '%'.$s.'%'); - } }); } diff --git a/app/models/Consumable.php b/app/models/Consumable.php index 2f6170d2f6..109a58bee0 100644 --- a/app/models/Consumable.php +++ b/app/models/Consumable.php @@ -64,6 +64,22 @@ class Consumable extends Elegant $remaining = $total - $checkedout; return $remaining; } + + /** + * Query builder scope to search on text + * + * @param Illuminate\Database\Query\Builder $query Query builder instance + * @param text $search Search term + * + * @return Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeTextSearch($query, $search) + { + return $query->where(function($query) use ($search) + { + $query->where('name', 'LIKE', '%'.$search.'%'); + }); + } } diff --git a/app/routes.php b/app/routes.php index f5c15445aa..11129bb071 100755 --- a/app/routes.php +++ b/app/routes.php @@ -32,7 +32,7 @@ Route::group(array('prefix' => 'api', 'namespace' => 'Controllers\Admin', 'befor /*---Consumables API---*/ Route::group(array('prefix'=>'consumables'), function () { Route::get('list', array('as'=>'api.consumables.list', 'uses'=>'ConsumablesController@getDatatable')); - Route::get('{accessoryID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView')); + Route::get('{consumableID}/view', array('as'=>'api.consumables.view', 'uses'=>'ConsumablesController@getDataView')); }); /*---Users API---*/ diff --git a/app/views/backend/consumables/index.blade.php b/app/views/backend/consumables/index.blade.php index 70f23c4295..3672d73ae6 100644 --- a/app/views/backend/consumables/index.blade.php +++ b/app/views/backend/consumables/index.blade.php @@ -19,78 +19,15 @@
- {{ Datatable::table() - ->addColumn(Lang::get('admin/consumables/table.title'), - Lang::get('admin/consumables/general.total'), - Lang::get('admin/consumables/general.remaining'), - Lang::get('table.actions')) - ->setOptions( - array( - 'language' => array( - 'search' => Lang::get('general.search'), - 'lengthMenu' => Lang::get('general.page_menu'), - 'loadingRecords' => Lang::get('general.loading'), - 'zeroRecords' => Lang::get('general.no_results'), - 'info' => Lang::get('general.pagination_info'), - 'processing' => ' '.Lang::get('general.processing'), - 'paginate'=> array( - 'first'=>Lang::get('general.first'), - 'previous'=>Lang::get('general.previous'), - 'next'=>Lang::get('general.next'), - 'last'=>Lang::get('general.last'), - ), - ), - 'sAjaxSource'=>route('api.consumables.list'), - 'dom' =>'T<"clear">lfrtip', - 'tableTools' => array( - 'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf', - 'aButtons'=>array( - array( - 'sExtends'=>'copy', - 'sButtonText'=>'Copy', - 'mColumns'=>array(0,1,2), - 'bFooter'=>false, - ), - array( - 'sExtends'=>'print', - 'sButtonText'=>'Print', - 'mColumns'=>array(0,1,2), - 'bShowAll'=>true, - 'bFooter'=>true, - ), - array( - 'sExtends'=>'collection', - 'sButtonText'=>'Export', - 'aButtons'=>array( - array( - 'sExtends'=>'csv', - 'sButtonText'=>'csv', - 'mColumns'=>array(0,1,2), - 'bFooter'=>false, - ), - array( - 'sExtends'=>'xls', - 'sButtonText'=>'XLS', - 'mColumns'=>array(0,1,2), - 'bFooter'=>false, - ), - array( - 'sExtends'=>'pdf', - 'sButtonText'=>'PDF', - 'mColumns'=>array(0,1,2), - 'bFooter'=>false, - ) - ) - ), - ) - ), - 'columnDefs'=> array( - array('bSortable'=>false,'targets'=>array(3)), - ), - 'order'=>array(array(0,'asc')), - ) - ) - ->render() }} + + + + + + + + +
{{Lang::get('admin/consumables/table.title')}}{{Lang::get('admin/consumables/general.total')}}{{Lang::get('admin/consumables/general.remaining')}}
@@ -103,4 +40,34 @@
+ + + @stop diff --git a/app/views/backend/consumables/view.blade.php b/app/views/backend/consumables/view.blade.php index 68243c2699..f994cef8ec 100644 --- a/app/views/backend/consumables/view.blade.php +++ b/app/views/backend/consumables/view.blade.php @@ -31,52 +31,20 @@ @if ($consumable->users->count() > 0) - {{ Datatable::table() - ->addColumn(Lang::get('general.user')) - ->setOptions( - array( - 'sAjaxSource'=>route('api.consumables.view', $consumable->id), - 'dom' =>'T<"clear">lfrtip', - 'tableTools' => array( - 'sSwfPath'=> Config::get('app.url').'/assets/swf/copy_csv_xls_pdf.swf', - 'aButtons'=>array( - array( - 'sExtends'=>'copy', - ), - 'print', - array( - 'sExtends'=>'collection', - 'sButtonText'=>'Export', - 'aButtons'=>array( - array( - 'sExtends'=>'csv', - ), - array( - 'sExtends'=>'xls', - ), - array( - 'sExtends'=>'pdf', - ), - ), - ), - ) - ), - 'columnDefs'=> array( - - array('width'=>'auto','targets'=>array(0)), - ), - 'order'=>array(array(0,'asc')), - ) - ) - ->render() }} - + + + + + + +
{{Lang::get('general.user')}}
@else -
-
- - @lang('general.no_results') +
+
+ + @lang('general.no_results') +
-
@endif
@@ -89,4 +57,33 @@ + + @stop