diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php index b2522a8a59..c4058f79ca 100644 --- a/app/Http/Controllers/Api/StatuslabelsController.php +++ b/app/Http/Controllers/Api/StatuslabelsController.php @@ -9,6 +9,8 @@ use App\Http\Transformers\StatuslabelsTransformer; use App\Models\Asset; use App\Models\Statuslabel; use Illuminate\Http\Request; +use App\Http\Transformers\PieChartTransformer; +use Illuminate\Support\Arr; class StatuslabelsController extends Controller { @@ -188,43 +190,54 @@ class StatuslabelsController extends Controller * * @author [A. Gianotto] [] * @since [v3.0] - * @return \Illuminate\Http\Response + * @return array */ public function getAssetCountByStatuslabel() { $this->authorize('view', Statuslabel::class); - $statuslabels = Statuslabel::withCount('assets')->get(); - $labels = []; - $points = []; - $default_color_count = 0; - $colors_array = []; - foreach ($statuslabels as $statuslabel) { - if ($statuslabel->assets_count > 0) { - $labels[] = $statuslabel->name.' ('.number_format($statuslabel->assets_count).')'; - $points[] = $statuslabel->assets_count; - if ($statuslabel->color != '') { - $colors_array[] = $statuslabel->color; - } else { - $colors_array[] = Helper::defaultChartColors($default_color_count); - } - $default_color_count++; + $total[$statuslabel->name]['label'] = $statuslabel->name; + $total[$statuslabel->name]['count'] = $statuslabel->assets_count; + + if ($statuslabel->color != '') { + $total[$statuslabel->name]['color'] = $statuslabel->color; } } - $result = [ - 'labels' => $labels, - 'datasets' => [[ - 'data' => $points, - 'backgroundColor' => $colors_array, - 'hoverBackgroundColor' => $colors_array, - ]], - ]; + return (new PieChartTransformer())->transformPieChartDate($total); - return $result; + } + + /** + * Show a count of assets by meta status type for pie chart + * + * @author [A. Gianotto] [] + * @since [v6.0.11] + * @return array + */ + public function getAssetCountByMetaStatus() + { + $this->authorize('view', Statuslabel::class); + + $total['rtd']['label'] = trans('general.ready_to_deploy'); + $total['rtd']['count'] = Asset::RTD()->count(); + + $total['deployed']['label'] = trans('general.deployed'); + $total['deployed']['count'] = Asset::Deployed()->count(); + + $total['archived']['label'] = trans('general.archived'); + $total['archived']['count'] = Asset::Archived()->count(); + + $total['pending']['label'] = trans('general.pending'); + $total['pending']['count'] = Asset::Pending()->count(); + + $total['undeployable']['label'] = trans('general.undeployable'); + $total['undeployable']['count'] = Asset::Undeployable()->count(); + + return (new PieChartTransformer())->transformPieChartDate($total); } /** diff --git a/app/Http/Transformers/PieChartTransformer.php b/app/Http/Transformers/PieChartTransformer.php new file mode 100644 index 0000000000..855a125113 --- /dev/null +++ b/app/Http/Transformers/PieChartTransformer.php @@ -0,0 +1,54 @@ +] + */ +class PieChartTransformer +{ + public function transformPieChartDate($totals) + { + + $labels = []; + $counts = []; + $default_color_count = 0; + $colors_array = []; + + foreach ($totals as $total) { + + if ($total['count'] > 0) { + + $labels[] = $total['label']; + $counts[] = $total['count']; + + if (isset($total['color'])) { + $colors_array[] = $total['color']; + } else { + $colors_array[] = Helper::defaultChartColors($default_color_count); + $default_color_count++; + } + } + } + + $results = [ + 'labels' => $labels, + 'datasets' => [[ + 'data' => $counts, + 'backgroundColor' => $colors_array, + 'hoverBackgroundColor' => $colors_array, + ]], + ]; + + + return $results; + } +} diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 029b74d195..d4db6b2b82 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -373,6 +373,8 @@ return [ 'bulk_checkin_success' => 'The items for the selected users have been checked in.', 'set_to_null' => 'Delete values for this asset|Delete values for all :asset_count assets ', 'na_no_purchase_date' => 'N/A - No purchase date provided', + 'assets_by_status' => 'Assets by Status', + 'assets_by_status_type' => 'Assets by Status Type', ]; \ No newline at end of file diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 241ec597b3..ff95530002 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -248,7 +248,7 @@
-

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

+

{{ trans('general.assets_by_status_type') }}