Implémantation de la gestion des Services pouvant avoir des taches
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\ServiceTask;
|
||||
use App\Enums\IntegrationStatus;
|
||||
use App\Enums\ServiceTaskStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DashboardController extends Controller
|
||||
@@ -24,7 +25,7 @@ class DashboardController extends Controller
|
||||
}
|
||||
|
||||
// If user has a service role
|
||||
$serviceRoles = ['DSI', 'Batiment', 'Parc Auto'];
|
||||
$serviceRoles = \App\Models\Service::pluck('name')->toArray();
|
||||
foreach ($serviceRoles as $role) {
|
||||
if ($user->hasRole($role)) {
|
||||
return $this->serviceDashboard($role);
|
||||
@@ -40,9 +41,17 @@ class DashboardController extends Controller
|
||||
|
||||
protected function adminDashboard()
|
||||
{
|
||||
$driver = DB::connection()->getDriverName();
|
||||
$diffQuery = 'TIMESTAMPDIFF(DAY, created_at, completed_at)';
|
||||
if ($driver === 'pgsql') {
|
||||
$diffQuery = 'EXTRACT(EPOCH FROM (completed_at - created_at)) / 86400';
|
||||
} elseif ($driver === 'sqlite') {
|
||||
$diffQuery = 'CAST(julianday(completed_at) - julianday(created_at) AS INTEGER)';
|
||||
}
|
||||
|
||||
$avgCompletionTime = IntegrationRequest::where('status', IntegrationStatus::Completed)
|
||||
->whereNotNull('completed_at')
|
||||
->selectRaw('AVG(TIMESTAMPDIFF(DAY, created_at, completed_at)) as avg_days')
|
||||
->selectRaw("AVG({$diffQuery}) as avg_days")
|
||||
->value('avg_days') ?? 0;
|
||||
|
||||
$serviceDistribution = \App\Models\Service::withCount('serviceTasks')->get()->map(function ($service) {
|
||||
|
||||
Reference in New Issue
Block a user