From ef463a37d81592eebb750a53e6a02d5f4a44cee8 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Fri, 14 Jan 2022 12:48:33 -0800 Subject: [PATCH] Make 'pending' assets properly requestable; use requestable scope --- app/Http/Controllers/Api/AssetsController.php | 2 +- app/Models/Asset.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index dd99668eac..85373833ae 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -937,7 +937,7 @@ class AssetsController extends Controller $assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets') ->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo', - 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->where('assets.requestable', '=', '1'); + 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->requestableAssets(); $offset = request('offset', 0); $limit = $request->input('limit', 50); diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 3c5ffbb8cb..49f2ca1ff3 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1167,9 +1167,10 @@ class Asset extends Depreciable { return Company::scopeCompanyables($query->where('requestable', '=', 1)) ->whereHas('assetstatus', function ($query) { - $query->where('deployable', '=', 1) - ->where('pending', '=', 0) - ->where('archived', '=', 0); + $query->where(function ($query) { + $query->where('deployable', '=', 1) + ->where('archived', '=', 0); // you definitely can't request something that's archived + })->orWhere('pending', '=', 1); // we've decided that even though an asset may be 'pending', you can still request it }); }