Fixes #3836 - Adds supplier to licenses column

This commit is contained in:
snipe 2017-08-10 14:38:04 -07:00
parent ac8f46c93c
commit 56f88d2c22
3 changed files with 34 additions and 4 deletions

View file

@ -59,6 +59,10 @@ class LicensesController extends Controller
$licenses->where('manufacturer_id','=',$request->input('manufacturer_id'));
}
if ($request->has('supplier_id')) {
$licenses->where('supplier_id','=',$request->input('supplier_id'));
}
if ($request->has('depreciation_id')) {
$licenses->where('depreciation_id','=',$request->input('depreciation_id'));
}
@ -69,22 +73,26 @@ class LicensesController extends Controller
$offset = request('offset', 0);
$limit = request('limit', 50);
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company','license_name','license_email'];
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
switch ($sort) {
switch ($request->input('sort')) {
case 'manufacturer':
$licenses = $licenses->OrderManufacturer($order);
break;
case 'supplier':
$licenses = $licenses->OrderSupplier($order);
break;
case 'company':
$licenses = $licenses->OrderCompany($order);
break;
default:
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','company','license_name','license_email'];
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
$licenses = $licenses->orderBy($sort, $order);
break;
}
$total = $licenses->count();
$licenses = $licenses->skip($offset)->take($limit)->get();

View file

@ -401,6 +401,20 @@ class License extends Depreciable
->orderBy('manufacturers.name', $order);
}
/**
* Query builder scope to order on supplier
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderSupplier($query, $order)
{
return $query->leftJoin('suppliers', 'licenses.supplier_id', '=', 'suppliers.id')->select('licenses.*')
->orderBy('suppliers.name', $order);
}
/**
* Query builder scope to order on company
*

View file

@ -61,6 +61,14 @@ class LicensePresenter extends Presenter
"searchable" => true,
"sortable" => true,
"title" => trans('admin/licenses/form.to_name'),
], [
"field" => "supplier",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('general.supplier'),
"visible" => false,
"formatter" => "suppliersLinkObjFormatter"
], [
"field" => "manufacturer",
"searchable" => true,