nre layouts
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace Modules\Platform\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
use Modules\Platform\app\Models\Company;
|
||||
use Modules\Platform\app\Models\LicenseKey;
|
||||
use Modules\Platform\app\Models\Payment;
|
||||
@@ -14,17 +16,112 @@ class PlatformDashboardController extends Controller
|
||||
/**
|
||||
* Show the platform administration dashboard.
|
||||
*/
|
||||
public function __invoke()
|
||||
public function __invoke(): View
|
||||
{
|
||||
$companies = Company::withCount(['users', 'warehouses', 'licenseKeys'])
|
||||
->latest()
|
||||
->limit(8)
|
||||
->get();
|
||||
|
||||
$companiesCount = Company::count();
|
||||
$activeCompaniesCount = Company::where('status', 'active')->count();
|
||||
$licensesCount = LicenseKey::count();
|
||||
$warehousesCount = Warehouse::count();
|
||||
$pricesCount = PlatformPrice::count();
|
||||
|
||||
return view('platform::dashboard.index', [
|
||||
'companiesCount' => Company::count(),
|
||||
'activeCompaniesCount' => Company::where('status', 'active')->count(),
|
||||
'licensesCount' => LicenseKey::count(),
|
||||
'companiesCount' => $companiesCount,
|
||||
'activeCompaniesCount' => $activeCompaniesCount,
|
||||
'licensesCount' => $licensesCount,
|
||||
'paymentsTotal' => Payment::where('status', 'paid')->sum('amount'),
|
||||
'warehousesCount' => Warehouse::count(),
|
||||
'pricesCount' => PlatformPrice::count(),
|
||||
'warehousesCount' => $warehousesCount,
|
||||
'pricesCount' => $pricesCount,
|
||||
'prices' => PlatformPrice::query()->ordered()->limit(3)->get(),
|
||||
'companies' => Company::withCount(['users', 'warehouses', 'licenseKeys'])->latest()->limit(8)->get(),
|
||||
'companies' => $companies,
|
||||
|
||||
'companyUsageChartLabels' => $companies->isNotEmpty()
|
||||
? $companies->pluck('name')->values()->all()
|
||||
: ['MPBA', 'Abbott Demo', 'North Hub', 'South Hub'],
|
||||
|
||||
'companyUsageChartSeries' => $companies->isNotEmpty()
|
||||
? $this->companyUsageChartSeries($companies)
|
||||
: $this->exampleCompanyUsageChartSeries(),
|
||||
|
||||
'platformMixChartLabels' => ['Companies', 'Warehouses', 'Prices', 'Licences'],
|
||||
|
||||
'platformMixChartValues' => $this->hasPlatformMixData(
|
||||
$companiesCount,
|
||||
$warehousesCount,
|
||||
$pricesCount,
|
||||
$licensesCount
|
||||
)
|
||||
? [$companiesCount, $warehousesCount, $pricesCount, $licensesCount]
|
||||
: [4, 11, 4, 9],
|
||||
|
||||
'companyStatusChartLabels' => ['Active', 'Inactive'],
|
||||
|
||||
'companyStatusChartValues' => $companiesCount > 0
|
||||
? [$activeCompaniesCount, max($companiesCount - $activeCompaniesCount, 0)]
|
||||
: [3, 1],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the company usage chart series.
|
||||
*
|
||||
* @param Collection<int, Company> $companies
|
||||
* @return array<int, array{label: string, data: array<int, int>}>
|
||||
*/
|
||||
private function companyUsageChartSeries(Collection $companies): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'label' => 'Users',
|
||||
'data' => $companies->pluck('users_count')->values()->all(),
|
||||
],
|
||||
[
|
||||
'label' => 'Warehouses',
|
||||
'data' => $companies->pluck('warehouses_count')->values()->all(),
|
||||
],
|
||||
[
|
||||
'label' => 'Licences',
|
||||
'data' => $companies->pluck('license_keys_count')->values()->all(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Build example company usage chart series for an empty platform.
|
||||
*
|
||||
* @return array<int, array{label: string, data: array<int, int>}>
|
||||
*/
|
||||
private function exampleCompanyUsageChartSeries(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'label' => 'Users',
|
||||
'data' => [14, 9, 6, 4],
|
||||
],
|
||||
[
|
||||
'label' => 'Warehouses',
|
||||
'data' => [5, 3, 2, 1],
|
||||
],
|
||||
[
|
||||
'label' => 'Licences',
|
||||
'data' => [4, 2, 2, 1],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the platform mix chart has real data.
|
||||
*/
|
||||
private function hasPlatformMixData(
|
||||
int $companiesCount,
|
||||
int $warehousesCount,
|
||||
int $pricesCount,
|
||||
int $licensesCount
|
||||
): bool {
|
||||
return ($companiesCount + $warehousesCount + $pricesCount + $licensesCount) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user