mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added ability to search by company_id and location_id
This commit is contained in:
parent
dd6a477355
commit
4cf01e4f48
|
@ -96,6 +96,14 @@ class AssetsController extends Controller
|
||||||
$assets->InCategory($request->input('category_id'));
|
$assets->InCategory($request->input('category_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->has('location_id')) {
|
||||||
|
$assets->ByLocationId($request->input('location_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('company_id')) {
|
||||||
|
$assets->where('company_id','=',$request->input('company_id'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->has('manufacturer_id')) {
|
if ($request->has('manufacturer_id')) {
|
||||||
$assets->ByManufacturer($request->input('manufacturer_id'));
|
$assets->ByManufacturer($request->input('manufacturer_id'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ class AssetsTransformer
|
||||||
'order_number' => $asset->order_number,
|
'order_number' => $asset->order_number,
|
||||||
'company' => ($asset->company) ? ['id' => $asset->company->id,'name'=> e($asset->company->name)] : null,
|
'company' => ($asset->company) ? ['id' => $asset->company->id,'name'=> e($asset->company->name)] : null,
|
||||||
'location' => ($asset->assetLoc) ? ['id' => $asset->assetLoc->id,'name'=> e($asset->assetLoc->name)] : null,
|
'location' => ($asset->assetLoc) ? ['id' => $asset->assetLoc->id,'name'=> e($asset->assetLoc->name)] : null,
|
||||||
|
'rtd_location' => ($asset->defaultLoc) ? ['id' => $asset->defaultLoc->id,'name'=> e($asset->defaultLoc->name)] : null,
|
||||||
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
'image' => ($asset->getImageUrl()) ? $asset->getImageUrl() : null,
|
||||||
'assigned_to' => ($asset->assigneduser) ? (new UsersTransformer)->transformUser($asset->assigneduser) : null,
|
'assigned_to' => ($asset->assigneduser) ? (new UsersTransformer)->transformUser($asset->assigneduser) : null,
|
||||||
'warranty' => ($asset->warranty_months > 0) ? e($asset->warranty_months).' '.trans('admin/hardware/form.months') : null,
|
'warranty' => ($asset->warranty_months > 0) ? e($asset->warranty_months).' '.trans('admin/hardware/form.months') : null,
|
||||||
|
|
|
@ -246,15 +246,17 @@ class Asset extends Depreciable
|
||||||
**/
|
**/
|
||||||
public function assetLoc()
|
public function assetLoc()
|
||||||
{
|
{
|
||||||
|
if($this->assignedTo) {
|
||||||
|
return $this->assignedTo->userLoc();
|
||||||
|
}
|
||||||
|
|
||||||
if(!empty($this->assignedType())) {
|
if(!empty($this->assignedType())) {
|
||||||
if ($this->assignedType() == self::ASSET) {
|
if ($this->assignedType() == self::ASSET) {
|
||||||
return $this->assignedTo->assetloc(); // Recurse until we have a final location
|
return $this->assignedTo->assetloc(); // Recurse until we have a final location
|
||||||
} elseif ($this->assignedType() == self::LOCATION) {
|
} elseif ($this->assignedType() == self::LOCATION) {
|
||||||
return $this->assignedTo();
|
return $this->assignedTo();
|
||||||
}
|
}
|
||||||
if($this->assignedTo) {
|
|
||||||
return $this->assignedTo->userLoc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->defaultLoc();
|
return $this->defaultLoc();
|
||||||
}
|
}
|
||||||
|
@ -902,4 +904,29 @@ class Asset extends Depreciable
|
||||||
{
|
{
|
||||||
return $query->join('locations', 'locations.id', '=', 'assets.rtd_location_id')->orderBy('locations.name', $order);
|
return $query->join('locations', 'locations.id', '=', 'assets.rtd_location_id')->orderBy('locations.name', $order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query builder scope to search on location ID
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Query\Builder $query Query builder instance
|
||||||
|
* @param text $search Search term
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Database\Query\Builder Modified query builder
|
||||||
|
*/
|
||||||
|
public function scopeByLocationId($query, $search)
|
||||||
|
{
|
||||||
|
|
||||||
|
return $query->where(function ($query) use ($search) {
|
||||||
|
$query->whereHas('defaultLoc', function ($query) use ($search) {
|
||||||
|
$query->where('locations.id', '=', $search);
|
||||||
|
})->whereNull('assigned_to');
|
||||||
|
})->orWhere(function ($query) use ($search) {
|
||||||
|
$query->whereHas('assigneduser', function ($query) use ($search) {
|
||||||
|
$query->whereHas('userloc', function ($query) use ($search) {
|
||||||
|
$query->where('locations.id', '=', $search);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue