Skip to content

Commit 5fe8a50

Browse files
committed
fix asset model query
1 parent e8cb1be commit 5fe8a50

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

app/Http/Controllers/ViewAssetsController.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

resources/views/account/requestable-assets.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class="table table-striped snipe-table"
135135
@endcan
136136
</td>
137137

138-
<td>{{$requestableModel->assets->where('requestable', '1')->count()}}</td>
138+
<td>{{'requestable '.$requestableModel->assets->where('requestable', '1')->count()}} {{'Unrequestable '.$requestableModel->assets->where('requestable', '0')->count()}}</td>
139139

140140
<td>
141141
<form action="{{ route('account/request-item', ['itemType' => 'asset_model', 'itemId' => $requestableModel->id])}}" method="POST" accept-charset="utf-8">

0 commit comments

Comments
 (0)