Use scoped query for asset count

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-06-23 13:43:23 -07:00
parent c5a6cec194
commit d45d322b54
5 changed files with 25 additions and 4 deletions

View file

@ -1147,6 +1147,27 @@ class Asset extends Depreciable
} }
/**
* Query builder scope for Archived assets
*
* @param \Illuminate\Database\Query\Builder $query Query builder instance
*
* @return \Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeAssetsForShow($query)
{
if (Setting::getSettings()->show_archived_in_list!=1) {
return $query->whereHas('assetstatus', function ($query) {
$query->where('archived', '=', 0);
});
} else {
return $query;
}
}
/** /**
* Query builder scope for Archived assets * Query builder scope for Archived assets
* *

View file

@ -39,7 +39,7 @@
<li class="active"> <li class="active">
<a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }} <a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }}
@if ($category->category_type=='asset') @if ($category->category_type=='asset')
<badge class="badge badge-secondary"> {{ $category->assets->count() }}</badge> <badge class="badge badge-secondary"> {{ $category->assets()->AssetsForShow()->count() }}</badge>
@endif @endif
</a> </a>
</li> </li>

View file

@ -33,7 +33,7 @@
<!-- small box --> <!-- small box -->
<div class="small-box bg-teal"> <div class="small-box bg-teal">
<div class="inner"> <div class="inner">
<h3>{{ number_format($counts['asset']) }}</h3> <h3>{{ number_format(\App\Models\Asset::AssetsForShow()->count()) }}</h3>
<p>{{ strtolower(trans('general.assets')) }}</p> <p>{{ strtolower(trans('general.assets')) }}</p>
</div> </div>
<div class="icon" aria-hidden="true"> <div class="icon" aria-hidden="true">

View file

@ -38,7 +38,7 @@
</span> </span>
<span class="hidden-xs hidden-sm"> <span class="hidden-xs hidden-sm">
{{ trans('general.assets') }} {{ trans('general.assets') }}
{!! (($location->assets) && ($location->assets->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($location->assets->count()).'</badge>' : '' !!} {!! (($location->assets) && ($location->assets()->AssetsForShow()->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($location->assets()->AssetsForShow()->count()).'</badge>' : '' !!}
</span> </span>
</a> </a>
</li> </li>

View file

@ -35,7 +35,7 @@
</span> </span>
<span class="hidden-xs hidden-sm"> <span class="hidden-xs hidden-sm">
{{ trans('general.assets') }} {{ trans('general.assets') }}
{!! (($supplier->assets) && ($supplier->assets->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($supplier->assets->count()).'</badge>' : '' !!} {!! (($supplier->assets) && ($supplier->assets()->AssetsForShow()->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($supplier->assets()->AssetsForShow()->count()).'</badge>' : '' !!}
</span> </span>
</a> </a>