Skip to content

Commit

Permalink
Merge pull request #11382 from snipe/fixes/check_for_archived_setting…
Browse files Browse the repository at this point in the history
…_on_counts

Fixes check for archived setting on counts
  • Loading branch information
snipe committed Jun 23, 2022
2 parents c5a6cec + daf6c72 commit 670a46e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
25 changes: 25 additions & 0 deletions app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,31 @@ public function scopeDueOrOverdueForAudit($query, $settings)
}


/**
* Query builder scope for Archived assets counting
*
* This is primarily used for the tab counters so that IF the admin
* has chosen to not display archived assets in their regular lists
* and views, it will return the correct number.
*
* @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
*
Expand Down
2 changes: 1 addition & 1 deletion resources/views/categories/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<li class="active">
<a href="#items" data-toggle="tab" title="{{ trans('general.items') }}"> {{ ucwords($category_type_route) }}
@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
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/companies/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<i class="fas fa-barcode" aria-hidden="true"></i>
</span>
<span class="hidden-xs hidden-sm">{{ trans('general.assets') }}
{!! (($company->assets) && ($company->assets->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($company->assets->count()).'</badge>' : '' !!}
{!! (($company->assets) && ($company->assets()->AssetsForShow()->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($company->assets()->AssetsForShow()->count()).'</badge>' : '' !!}

</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- small box -->
<div class="small-box bg-teal">
<div class="inner">
<h3>{{ number_format($counts['asset']) }}</h3>
<h3>{{ number_format(\App\Models\Asset::AssetsForShow()->count()) }}</h3>
<p>{{ strtolower(trans('general.assets')) }}</p>
</div>
<div class="icon" aria-hidden="true">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/locations/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</span>
<span class="hidden-xs hidden-sm">
{{ 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>
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/manufacturers/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</span>
<span class="hidden-xs hidden-sm">
{{ trans('general.assets') }}
{!! (($manufacturer->assets) && ($manufacturer->assets->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($manufacturer->assets->count()).'</badge>' : '' !!}
{!! (($manufacturer->assets) && ($manufacturer->assets()->AssetsForShow()->count() > 0 )) ? '<badge class="badge badge-secondary">'.number_format($manufacturer->assets()->AssetsForShow()->count()).'</badge>' : '' !!}
</span>

</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/suppliers/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</span>
<span class="hidden-xs hidden-sm">
{{ 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>

</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/users/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<i class="fas fa-barcode fa-2x" aria-hidden="true"></i>
</span>
<span class="hidden-xs hidden-sm">{{ trans('general.assets') }}
{!! ($user->assets->count() > 0 ) ? '<badge class="badge badge-secondary">'.number_format($user->assets->count()).'</badge>' : '' !!}
{!! ($user->assets()->AssetsForShow()->count() > 0 ) ? '<badge class="badge badge-secondary">'.number_format($user->assets()->AssetsForShow()->count()).'</badge>' : '' !!}
</span>
</a>
</li>
Expand Down

0 comments on commit 670a46e

Please sign in to comment.