mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 13:14:07 -08:00
Added count of checkins, checkouts, requests (#5314)
* Added count of checkins, checkouts, requests * Removed old commented items * Use actionlog instead of redefining the relationship
This commit is contained in:
parent
1d0f8f01f2
commit
bbc0695a8f
|
@ -77,6 +77,9 @@ class AssetsController extends Controller
|
|||
'last_audit_date',
|
||||
'next_audit_date',
|
||||
'warranty_months',
|
||||
'checkouts_count',
|
||||
'checkins_count',
|
||||
'user_requests_count',
|
||||
];
|
||||
|
||||
$filter = array();
|
||||
|
@ -92,7 +95,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');
|
||||
'model.category', 'model.manufacturer', 'model.fieldset','supplier')->withCount('checkins', 'checkouts', 'userRequests');
|
||||
|
||||
|
||||
// These are used by the API to query against specific ID numbers.
|
||||
|
@ -116,7 +119,6 @@ class AssetsController extends Controller
|
|||
|
||||
if ($request->has('location_id')) {
|
||||
$assets->where('assets.location_id', '=', $request->input('location_id'));
|
||||
// dd($assets->toSql());
|
||||
}
|
||||
|
||||
if ($request->has('supplier_id')) {
|
||||
|
@ -322,7 +324,7 @@ class AssetsController extends Controller
|
|||
*/
|
||||
public function show($id)
|
||||
{
|
||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()->findOrFail($id)) {
|
||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()->withCount('checkins', 'checkouts', 'userRequests')->findOrFail($id)) {
|
||||
$this->authorize('view', $asset);
|
||||
return (new AssetsTransformer)->transformAsset($asset);
|
||||
}
|
||||
|
|
|
@ -77,6 +77,9 @@ class AssetsTransformer
|
|||
'last_checkout' => Helper::getFormattedDateObject($asset->last_checkout, 'datetime'),
|
||||
'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'),
|
||||
'purchase_cost' => Helper::formatCurrencyOutput($asset->purchase_cost),
|
||||
'checkins_count' => (int) $asset->checkins_count,
|
||||
'checkouts_count' => (int) $asset->checkouts_count,
|
||||
'user_requests_count' => (int) $asset->user_requests_count,
|
||||
'user_can_checkout' => (bool) $asset->availableForCheckout(),
|
||||
];
|
||||
|
||||
|
|
|
@ -350,6 +350,38 @@ class Asset extends Depreciable
|
|||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get checkouts
|
||||
*/
|
||||
public function checkouts()
|
||||
{
|
||||
return $this->assetlog()->where('action_type', '=', 'checkout')
|
||||
->orderBy('created_at', 'desc')
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get checkins
|
||||
*/
|
||||
public function checkins()
|
||||
{
|
||||
return $this->assetlog()
|
||||
->where('action_type', '=', 'checkin from')
|
||||
->orderBy('created_at', 'desc')
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user requests
|
||||
*/
|
||||
public function userRequests()
|
||||
{
|
||||
return $this->assetlog()
|
||||
->where('action_type', '=', 'requested')
|
||||
->orderBy('created_at', 'desc')
|
||||
->withTrashed();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* assetmaintenances
|
||||
|
|
|
@ -181,6 +181,27 @@ class AssetPresenter extends Presenter
|
|||
"visible" => false,
|
||||
"title" => trans('general.notes'),
|
||||
|
||||
], [
|
||||
"field" => "checkouts_count",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.checkouts_count')
|
||||
|
||||
],[
|
||||
"field" => "checkins_count",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.checkins_count')
|
||||
|
||||
], [
|
||||
"field" => "user_requests_count",
|
||||
"searchable" => false,
|
||||
"sortable" => true,
|
||||
"visible" => false,
|
||||
"title" => trans('general.user_requests_count')
|
||||
|
||||
], [
|
||||
"field" => "created_at",
|
||||
"searchable" => false,
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
'checkin' => 'Checkin',
|
||||
'checkin_from' => 'Checkin from',
|
||||
'checkout' => 'Checkout',
|
||||
'checkouts_count' => 'Checkouts',
|
||||
'checkins_count' => 'Checkins',
|
||||
'user_requests_count' => 'Requests',
|
||||
'city' => 'City',
|
||||
'click_here' => 'Click here',
|
||||
'clear_selection' => 'Clear Selection',
|
||||
|
|
|
@ -465,6 +465,28 @@
|
|||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
|
||||
<tr>
|
||||
<td>{{ trans('general.checkouts_count') }}</td>
|
||||
<td>
|
||||
{{ ($asset->checkouts) ? (int) $asset->checkouts->count() : '0' }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>{{ trans('general.checkins_count') }}</td>
|
||||
<td>
|
||||
{{ ($asset->checkins) ? (int) $asset->checkins->count() : '0' }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>{{ trans('general.user_requests_count') }}</td>
|
||||
<td>
|
||||
{{ ($asset->userRequests) ? (int) $asset->userRequests->count() : '0' }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- /table-responsive -->
|
||||
|
|
Loading…
Reference in a new issue