Files
L-Ami-Fiduciaire/app/Http/Controllers/DashboardController.php
Saad Ibn-Ezzoubayr 35545c2a8f feat: L'Ami Fiduciaire V1.0.0 — full codebase with Story 0.1 complete
Initial commit of the L'Ami Fiduciaire SaaS platform built on Laravel 12,
Vue 3, Inertia.js 2, and Tailwind CSS 4.

Story 0.1 (rename folders to declarations in database) is implemented and
code-reviewed: migration, rollback, and 6 Pest tests all passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 23:33:10 +00:00

127 lines
4.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\FolderStatus;
use App\Models\Folder;
use App\Models\Workspace;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class DashboardController extends Controller
{
/**
* Display the dashboard with assigned folders and notifications.
*/
public function __invoke(Request $request): Response
{
$user = $request->user();
$workspaceId = $request->session()->get('current_workspace_id');
$workspace = $workspaceId ? Workspace::query()->find($workspaceId) : null;
$assignedFolders = [];
$notifications = [];
if ($workspace && $user) {
$assignedFolders = $workspace->folders()
->where('assigned_to', $user->id)
->whereNotIn('status', [FolderStatus::Closed, FolderStatus::Cancelled])
->with('client:id,company_name')
->orderByRaw('CASE WHEN due_date IS NULL THEN 1 ELSE 0 END, due_date ASC')
->limit(50)
->get()
->map(fn (Folder $f) => [
'id' => $f->id,
'title' => $f->title,
'type' => $f->type->value,
'client_name' => $f->client->company_name,
'status' => $f->status->value,
'due_date' => $f->due_date?->format('Y-m-d'),
'priority' => $f->priority?->value,
'showUrl' => route('folders.show', $f),
])
->all();
$overdue = $workspace->folders()
->where('assigned_to', $user->id)
->where('due_date', '<', now()->startOfDay())
->whereNotIn('status', [FolderStatus::Closed, FolderStatus::Cancelled])
->with('client:id,company_name')
->orderBy('due_date')
->limit(10)
->get()
->map(fn (Folder $f) => [
'id' => $f->id,
'title' => $f->title,
'client_name' => $f->client->company_name,
'due_date' => $f->due_date?->format('Y-m-d'),
'showUrl' => route('folders.show', $f),
])
->all();
$dueSoon = $workspace->folders()
->where('assigned_to', $user->id)
->whereBetween('due_date', [now()->startOfDay(), now()->addDays(7)->endOfDay()])
->whereNotIn('status', [FolderStatus::Closed, FolderStatus::Cancelled])
->with('client:id,company_name')
->orderBy('due_date')
->limit(10)
->get()
->map(fn (Folder $f) => [
'id' => $f->id,
'title' => $f->title,
'client_name' => $f->client->company_name,
'due_date' => $f->due_date?->format('Y-m-d'),
'showUrl' => route('folders.show', $f),
])
->all();
$documentsReceived = $workspace->folders()
->where('assigned_to', $user->id)
->where('status', FolderStatus::DocumentsReceived)
->with('client:id,company_name')
->orderBy('updated_at', 'desc')
->limit(10)
->get()
->map(fn (Folder $f) => [
'id' => $f->id,
'title' => $f->title,
'client_name' => $f->client->company_name,
'showUrl' => route('folders.show', $f),
])
->all();
$awaitingValidation = $workspace->folders()
->where('assigned_to', $user->id)
->where('status', FolderStatus::WaitingClientValidation)
->with('client:id,company_name')
->orderBy('confirmation_requested_at', 'desc')
->limit(10)
->get()
->map(fn (Folder $f) => [
'id' => $f->id,
'title' => $f->title,
'client_name' => $f->client->company_name,
'showUrl' => route('folders.show', $f),
])
->all();
$notifications = [
'overdue' => $overdue,
'due_soon' => $dueSoon,
'documents_received' => $documentsReceived,
'awaiting_validation' => $awaitingValidation,
];
}
return Inertia::render('Dashboard', [
'assignedFolders' => $assignedFolders,
'notifications' => $notifications,
'workspaceName' => $workspace?->name ?? null,
'foldersUrl' => $workspace ? route('folders.index') : null,
'clientsUrl' => $workspace ? route('clients.index') : null,
]);
}
}