mirror of https://github.com/Lukibeg/OmniBoard.git
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Inertia\Inertia;
|
|
use App\Models\User;
|
|
use App\Models\Queue;
|
|
use App\Models\Agent; // <--- Importante: Adicionamos o Model de Agente
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Carbon\Carbon;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$user = Auth::user();
|
|
|
|
// --- 1. BUSCA DE FILAS (MANTENDO SUA LÓGICA) ---
|
|
$query = Queue::where('tenant_id', $user->tenant_id)
|
|
->with(['waitingList', 'dailyMetrics' => function($q) {
|
|
// Otimização: Traz apenas as métricas de HOJE para não carregar histórico antigo
|
|
$q->whereDate('date', Carbon::today());
|
|
}]);
|
|
|
|
// Aplica o filtro de setor do supervisor, se existir
|
|
if (!empty($user->allowed_sector)) {
|
|
$query->where('sector', $user->allowed_sector);
|
|
}
|
|
|
|
$queues = $query->get();
|
|
|
|
// --- 2. BUSCA DE AGENTES (NOVO) ---
|
|
// Aqui pegamos todos os agentes do Tenant.
|
|
// Usamos orderByRaw para mostrar quem está FALANDO primeiro, depois PAUSADO.
|
|
$agents = Agent::where('tenant_id', $user->tenant_id)
|
|
->orderByRaw("FIELD(status, 'talking', 'paused', 'available', 'offline')")
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
// 3. Entrega tudo para o Vue
|
|
return Inertia::render('Dashboard', [
|
|
'queues' => $queues,
|
|
'agents' => $agents // <--- Agora o Dashboard recebe os agentes
|
|
]);
|
|
}
|
|
} |