From d799ab2a9c1bd520b510340939ba7ae2bc4ff0ce Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 11 Mar 2017 02:49:24 -0800 Subject: [PATCH] Narrowed down the accessories, consumables, etc APIs for manufacturer filtering --- .../Controllers/Api/AccessoriesController.php | 8 ++ .../Controllers/Api/ConsumablesController.php | 12 +++ .../Controllers/Api/LicensesController.php | 13 ++++ .../Transformers/AccessoriesTransformer.php | 10 +-- resources/views/manufacturers/view.blade.php | 77 +++++++++---------- 5 files changed, 75 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index f642903455..1eabd54b41 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -29,6 +29,14 @@ class AccessoriesController extends Controller $accessories = $accessories->TextSearch($request->input('search')); } + if ($request->has('company_id')) { + $accessories->where('company_id','=',$request->input('company_id')); + } + + if ($request->has('manufacturer_id')) { + $accessories->where('manufacturer_id','=',$request->input('manufacturer_id')); + } + $offset = $request->input('offset', 0); $limit = $request->input('limit', 50); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index 24584193e2..ac95e951d7 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -32,12 +32,22 @@ class ConsumablesController extends Controller $consumables = $consumables->TextSearch(e($request->input('search'))); } + if ($request->has('company_id')) { + $consumables->where('company_id','=',$request->input('company_id')); + } + + if ($request->has('manufacturer_id')) { + $consumables->where('manufacturer_id','=',$request->input('manufacturer_id')); + } + + $offset = request('offset', 0); $limit = request('limit', 50); $allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','company','category','model_number', 'item_no', 'manufacturer','location','qty']; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at'; + switch ($sort) { case 'category': $consumables = $consumables->OrderCategory($order); @@ -56,6 +66,8 @@ class ConsumablesController extends Controller break; } + + $total = $consumables->count(); $consumables = $consumables->skip($offset)->take($limit)->get(); return (new ConsumablesTransformer)->transformConsumables($consumables, $total); diff --git a/app/Http/Controllers/Api/LicensesController.php b/app/Http/Controllers/Api/LicensesController.php index 928433f2a8..d0155c960f 100644 --- a/app/Http/Controllers/Api/LicensesController.php +++ b/app/Http/Controllers/Api/LicensesController.php @@ -26,6 +26,19 @@ class LicensesController extends Controller if ($request->has('search')) { $licenses = $licenses->TextSearch($request->input('search')); } + + if ($request->has('company_id')) { + $licenses->where('company_id','=',$request->input('company_id')); + } + + if ($request->has('manufacturer_id')) { + $licenses->where('manufacturer_id','=',$request->input('manufacturer_id')); + } + + if ($request->has('supplier_id')) { + $licenses->where('supplier_id','=',$request->input('supplier_id')); + } + $offset = request('offset', 0); $limit = request('limit', 50); diff --git a/app/Http/Transformers/AccessoriesTransformer.php b/app/Http/Transformers/AccessoriesTransformer.php index 0f025fe883..8eadedd407 100644 --- a/app/Http/Transformers/AccessoriesTransformer.php +++ b/app/Http/Transformers/AccessoriesTransformer.php @@ -23,14 +23,14 @@ class AccessoriesTransformer $array = [ 'id' => $accessory->id, 'name' => e($accessory->name), - 'company' => ($accessory->company) ? $accessory->company : null, - 'manufacturer' => ($accessory->manufacturer_id) ? $accessory->manufacturer : null, + 'company' => ($accessory->company) ? ['id' => $accessory->company->id,'name'=> e($accessory->company->name)] : '', + 'manufacturer' => ($accessory->manufacturer) ? ['id' => $accessory->manufacturer->id,'name'=> e($accessory->manufacturer->name)] : '', 'model_number' => ($accessory->model_number) ? e($accessory->model_number) : null, - 'category' => ($accessory->category_id) ? $accessory->category : null, - 'location' => ($accessory->location) ? $accessory->location : null, + 'category' => ($accessory->category) ? ['id' => $accessory->category->id,'name'=> e($accessory->category->name)] : '', + 'location' => ($accessory->location) ? ['id' => $accessory->location->id,'name'=> e($accessory->location->name)] : '', 'notes' => ($accessory->notes) ? e($accessory->notes) : null, 'qty' => ($accessory->qty) ? e($accessory->qty) : null, - 'purchase_date' => ($accessory->purchase_date) ? e($accessory->purchase_date) : null, + 'purchase_date' => ($accessory->purchase_date) ? Helper::getFormattedDateObject($accessory->purchase_date, 'date') : null, 'purchase_cost' => ($accessory->purchase_cost) ? e($accessory->purchase_cost) : null, 'order_number' => ($accessory->order_number) ? e($accessory->order_number) : null, 'min_qty' => ($accessory->min_amt) ? e($accessory->min_amt) : null, diff --git a/resources/views/manufacturers/view.blade.php b/resources/views/manufacturers/view.blade.php index 0becfa1aa2..e62e4a08cb 100644 --- a/resources/views/manufacturers/view.blade.php +++ b/resources/views/manufacturers/view.blade.php @@ -76,28 +76,27 @@ name="manufacturer_licenses" class="table table-striped bootstrap-table snipe-table" id="licenses-table" - data-url="{{ route('api.manufacturers.show', ['manufacturerId' => $manufacturer->id, 'itemtype' => 'licenses']) }}" + data-url="{{ route('api.licenses.index', ['manufacturer_id' => $manufacturer->id]) }}" data-cookie="true" data-click-to-select="true" - data-cookie-id-table="maufacturerLicensesTable-{{config('version.hash_version') }}" - > + data-cookie-id-table="maufacturerLicensesTable-{{config('version.hash_version') }}"> {{ trans('general.id') }} - {{ trans('general.company') }} - {{ trans('admin/licenses/table.title') }} - {{ trans('general.manufacturer') }} - {{ trans('admin/licenses/table.serial') }} + {{ trans('general.company') }} + {{ trans('admin/licenses/table.title') }} + {{ trans('general.manufacturer') }} + {{ trans('admin/licenses/table.serial') }} {{ trans('admin/licenses/form.to_name') }} {{ trans('admin/licenses/form.to_email') }} - {{ trans('admin/licenses/form.seats') }} - {{ trans('admin/licenses/form.remaining_seats') }} - {{ trans('admin/licenses/table.purchase_date') }} + {{ trans('admin/licenses/form.seats') }} + {{ trans('admin/licenses/form.remaining_seats') }} + {{ trans('admin/licenses/table.purchase_date') }} {{ trans('general.purchase_cost') }} {{ trans('admin/licenses/form.purchase_order') }} - {{ trans('admin/licenses/form.expiration') }} - {{ trans('admin/licenses/form.notes') }} - {{ trans('table.actions') }} + {{ trans('admin/licenses/form.expiration') }} + {{ trans('general.notes') }} + {{ trans('table.actions') }} @@ -105,28 +104,27 @@
+ data-cookie-id-table="manufacturerAccessoriesTable-{{config('version.hash_version') }}"> - - - - - + + + + + - + - - - - + + + +
{{ trans('admin/companies/table.title') }}{{ trans('admin/accessories/table.title') }}{{ trans('admin/accessories/general.accessory_category') }}{{ trans('general.manufacturer') }}{{ trans('general.location') }}{{ trans('admin/companies/table.title') }}{{ trans('admin/accessories/table.title') }}{{ trans('admin/accessories/general.accessory_category') }}{{ trans('general.manufacturer') }}{{ trans('general.location') }} {{ trans('admin/accessories/general.total') }}{{ trans('admin/accessories/general.date') }}{{ trans('general.purchase_date') }} {{ trans('general.purchase_cost') }}{{ trans('admin/accessories/general.order') }}{{ trans('general.min_amt') }}{{ trans('admin/accessories/general.remaining') }}{{ trans('table.actions') }}{{ trans('general.order_number') }}{{ trans('general.min_amt') }}{{ trans('admin/accessories/general.remaining') }}{{ trans('table.actions') }}
@@ -134,31 +132,30 @@
+ data-cookie-id-table="maufacturerConsumablesTable-{{config('version.hash_version') }}"> - - - - + + + + - + - + - - + + - +
{{ trans('general.id') }}{{ trans('admin/companies/table.title') }}{{ trans('admin/consumables/table.title') }}{{ trans('general.location') }}{{ trans('general.category') }}{{ trans('admin/companies/table.title') }}{{ trans('admin/consumables/table.title') }}{{ trans('general.location') }}{{ trans('general.category') }} {{ trans('admin/consumables/general.total') }} {{ trans('admin/consumables/general.remaining') }} {{ trans('admin/consumables/general.remaining') }} {{ trans('general.min_amt') }}{{ trans('general.manufacturer') }}{{ trans('general.manufacturer') }} {{ trans('general.model_no') }} {{ trans('admin/consumables/general.item_no') }}{{ trans('admin/consumables/general.order') }}{{ trans('admin/consumables/general.date') }}{{ trans('general.order_number') }}{{ trans('general.purchase_date') }} {{ trans('general.purchase_cost') }} {{ trans('table.actions') }} {{ trans('table.actions') }}