@@ -155,7 +155,30 @@ public function getIndex(Request $request) : View | RedirectResponse
155155 public function getRequestableIndex () : View
156156 {
157157 $ assets = Asset::with ('model ' , 'defaultLoc ' , 'location ' , 'assignedTo ' , 'requests ' )->Hardware ()->RequestableAssets ();
158- $ models = AssetModel::with ('category ' , 'requests ' , 'assets ' )->RequestableModels ()->get ();
158+ $ onlyUnassignedDeployable = Setting::getSettings ()->request_unassigned_deployable ;
159+ $ models = AssetModel::with ([
160+ 'category ' ,
161+ 'requests ' ,
162+ 'assets ' => function ($ q ) use ($ onlyUnassignedDeployable ) {
163+ if ($ onlyUnassignedDeployable ) {
164+ // Unassigned + deployable (not archived)
165+ $ q ->whereNull ('assets.assigned_to ' )
166+ ->whereHas ('assetstatus ' , function ($ s ) {
167+ $ s ->where ('deployable ' , 1 );
168+ });
169+ } else {
170+ // Requestable + (deployable OR pending) but never archived
171+ $ q ->where ('requestable ' , 1 )
172+ ->whereHas ('assetstatus ' , function ($ s ) {
173+ $ s ->where ('archived ' , 0 )
174+ ->where (function ($ s ) {
175+ $ s ->where ('deployable ' , 1 )
176+ ->orWhere ('pending ' , 1 );
177+ });
178+ });
179+ }
180+ },
181+ ])->RequestableModels ()->get ();
159182
160183 return view ('account/requestable-assets ' , compact ('assets ' , 'models ' ));
161184 }
0 commit comments