diff --git a/app/Http/Controllers/Api/AccessoriesController.php b/app/Http/Controllers/Api/AccessoriesController.php index f386c8e720..a894dc3760 100644 --- a/app/Http/Controllers/Api/AccessoriesController.php +++ b/app/Http/Controllers/Api/AccessoriesController.php @@ -27,8 +27,7 @@ class AccessoriesController extends Controller public function index(Request $request) { $this->authorize('view', Accessory::class); - $allowed_columns = ['id', 'name', 'model_number', 'eol', 'notes', 'created_at', 'min_amt', 'company_id']; - + // This array is what determines which fields should be allowed to be sorted on ON the table itself, no relations // Relations will be handled in query scopes a little further down. $allowed_columns = diff --git a/app/Http/Controllers/Api/AssetMaintenancesController.php b/app/Http/Controllers/Api/AssetMaintenancesController.php index 904ac80792..e38d5382fa 100644 --- a/app/Http/Controllers/Api/AssetMaintenancesController.php +++ b/app/Http/Controllers/Api/AssetMaintenancesController.php @@ -35,7 +35,8 @@ class AssetMaintenancesController extends Controller public function index(Request $request) { $this->authorize('view', Asset::class); - $maintenances = AssetMaintenance::with('asset', 'asset.model', 'asset.location', 'supplier', 'asset.company', 'admin'); + + $maintenances = AssetMaintenance::select('asset_maintenances.*')->with('asset', 'asset.model', 'asset.location', 'supplier', 'asset.company', 'admin'); if ($request->filled('search')) { $maintenances = $maintenances->TextSearch($request->input('search')); @@ -45,6 +46,15 @@ class AssetMaintenancesController extends Controller $maintenances->where('asset_id', '=', $request->input('asset_id')); } + if ($request->filled('supplier_id')) { + $maintenances->where('supplier_id', '=', $request->input('supplier_id')); + } + + if ($request->filled('asset_maintenance_type')) { + $maintenances->where('asset_maintenance_type', '=', $request->input('asset_maintenance_type')); + } + + // Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which // case we override with the actual count, so we should return 0 items. $offset = (($maintenances) && ($request->get('offset') > $maintenances->count())) ? $maintenances->count() : $request->get('offset', 0); @@ -64,6 +74,7 @@ class AssetMaintenancesController extends Controller 'asset_tag', 'asset_name', 'user_id', + 'supplier' ]; $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; $sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at'; @@ -72,6 +83,9 @@ class AssetMaintenancesController extends Controller case 'user_id': $maintenances = $maintenances->OrderAdmin($order); break; + case 'supplier': + $maintenances = $maintenances->OrderBySupplier($order); + break; case 'asset_tag': $maintenances = $maintenances->OrderByTag($order); break; diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 27273eefc4..3f2c43ad61 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -162,6 +162,20 @@ class AssetMaintenance extends Model implements ICompanyableChild * ----------------------------------------------- **/ + /** + * Query builder scope to order on a supplier + * + * @param \Illuminate\Database\Query\Builder $query Query builder instance + * @param string $order Order + * + * @return \Illuminate\Database\Query\Builder Modified query builder + */ + public function scopeOrderBySupplier($query, $order) + { + return $query->leftJoin('suppliers as suppliers_maintenances', 'asset_maintenances.supplier_id', '=', 'suppliers_maintenances.id') + ->orderBy('suppliers_maintenances.name', $order); + } + /** * Query builder scope to order on admin user * diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index c8c9618d8b..393e7ddb29 100755 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -184,7 +184,7 @@ class Supplier extends SnipeModel */ public function addhttp($url) { - if (! preg_match('~^(?:f|ht)tps?://~i', $url)) { + if (($url!='') && (! preg_match('~^(?:f|ht)tps?://~i', $url))) { $url = 'http://'.$url; } diff --git a/resources/views/manufacturers/view.blade.php b/resources/views/manufacturers/view.blade.php index dc1d71f8a3..d7725bc492 100644 --- a/resources/views/manufacturers/view.blade.php +++ b/resources/views/manufacturers/view.blade.php @@ -9,6 +9,10 @@ @stop @section('header_right') + + {{ trans('general.back') }} + +