mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 21:54:14 -08:00
Fixes #2906 - adds manufacturer searching to licenses
This commit is contained in:
parent
49ce630bb8
commit
2ddee9b44c
|
@ -954,11 +954,22 @@ class LicensesController extends Controller
|
||||||
$licenses = $licenses->TextSearch(Input::get('search'));
|
$licenses = $licenses->TextSearch(Input::get('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial'];
|
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company'];
|
||||||
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
|
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
|
||||||
|
|
||||||
|
switch ($sort) {
|
||||||
|
case 'manufacturer':
|
||||||
|
$licenses = $licenses->OrderManufacturer($order);
|
||||||
|
break;
|
||||||
|
case 'company':
|
||||||
|
$licenses = $licenses->OrderCompany($order);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
$licenses = $licenses->orderBy($sort, $order);
|
$licenses = $licenses->orderBy($sort, $order);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$licenseCount = $licenses->count();
|
$licenseCount = $licenses->count();
|
||||||
$licenses = $licenses->skip(Input::get('offset'))->take(Input::get('limit'))->get();
|
$licenses = $licenses->skip(Input::get('offset'))->take(Input::get('limit'))->get();
|
||||||
|
@ -1003,7 +1014,7 @@ class LicensesController extends Controller
|
||||||
'order_number' => ($license->order_number) ? e($license->order_number) : '',
|
'order_number' => ($license->order_number) ? e($license->order_number) : '',
|
||||||
'notes' => ($license->notes) ? e($license->notes) : '',
|
'notes' => ($license->notes) ? e($license->notes) : '',
|
||||||
'actions' => $actions,
|
'actions' => $actions,
|
||||||
'companyName' => is_null($license->company) ? '' : e($license->company->name),
|
'company' => is_null($license->company) ? '' : e($license->company->name),
|
||||||
'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : ''
|
'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : ''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,13 +234,51 @@ class License extends Depreciable
|
||||||
|
|
||||||
return $query->where(function ($query) use ($search) {
|
return $query->where(function ($query) use ($search) {
|
||||||
|
|
||||||
$query->where('name', 'LIKE', '%'.$search.'%')
|
$query->where('licenses.name', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('serial', 'LIKE', '%'.$search.'%')
|
->orWhere('licenses.serial', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('notes', 'LIKE', '%'.$search.'%')
|
->orWhere('licenses.notes', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('order_number', 'LIKE', '%'.$search.'%')
|
->orWhere('licenses.order_number', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('purchase_order', 'LIKE', '%'.$search.'%')
|
->orWhere('licenses.purchase_order', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('purchase_date', 'LIKE', '%'.$search.'%')
|
->orWhere('licenses.purchase_date', 'LIKE', '%'.$search.'%')
|
||||||
->orWhere('purchase_cost', 'LIKE', '%'.$search.'%');
|
->orWhere('licenses.purchase_cost', 'LIKE', '%'.$search.'%')
|
||||||
|
->orWhereHas('manufacturer', function ($query) use ($search) {
|
||||||
|
$query->where(function ($query) use ($search) {
|
||||||
|
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
->orWhereHas('company', function ($query) use ($search) {
|
||||||
|
$query->where(function ($query) use ($search) {
|
||||||
|
$query->where('companies.name', 'LIKE', '%'.$search.'%');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to order on manufacturer
|
||||||
|
*
|
||||||
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $order Order
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeOrderManufacturer($query, $order)
|
||||||
|
{
|
||||||
|
return $query->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->select('licenses.*')
|
||||||
|
->orderBy('manufacturers.name', $order);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to order on company
|
||||||
|
*
|
||||||
|
* @param Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $order Order
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeOrderCompany($query, $order)
|
||||||
|
{
|
||||||
|
return $query->leftJoin('companies as companies', 'licenses.company_id', '=', 'companies.id')->select('licenses.*')
|
||||||
|
->orderBy('companies.name', $order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue