diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 0bbb06aa131f..14613149a129 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -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 * diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.php index b32bb8df068d..6e33594b176d 100644 --- a/resources/views/categories/view.blade.php +++ b/resources/views/categories/view.blade.php @@ -39,7 +39,7 @@
  • {{ ucwords($category_type_route) }} @if ($category->category_type=='asset') - {{ $category->assets->count() }} + {{ $category->assets()->AssetsForShow()->count() }} @endif
  • diff --git a/resources/views/companies/view.blade.php b/resources/views/companies/view.blade.php index 19a27c68bae4..4324f3f78eda 100644 --- a/resources/views/companies/view.blade.php +++ b/resources/views/companies/view.blade.php @@ -21,7 +21,7 @@ diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index dab2e1dbdc99..f4e8cc714a21 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -33,7 +33,7 @@
    -

    {{ number_format($counts['asset']) }}

    +

    {{ number_format(\App\Models\Asset::AssetsForShow()->count()) }}

    {{ strtolower(trans('general.assets')) }}