feat: Initialize core application structure including authentication, role-based dashboards, service task management, and integration workflows.
This commit is contained in:
99
app/Http/Controllers/IntegrationController.php
Normal file
99
app/Http/Controllers/IntegrationController.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Integration\CreateIntegrationAction;
|
||||
use App\Models\IntegrationRequest;
|
||||
use App\Models\IntegrationTemplate;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class IntegrationController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('Integration/Index', [
|
||||
'integrations' => IntegrationRequest::with(['agent', 'template'])->latest()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return Inertia::render('Integration/Create', [
|
||||
'templates' => IntegrationTemplate::where('is_active', true)->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request, CreateIntegrationAction $action)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'first_name' => 'required|string|max:255',
|
||||
'last_name' => 'required|string|max:255',
|
||||
'email' => 'required|email|unique:agents,email',
|
||||
'position' => 'required|string|max:255',
|
||||
'department' => 'required|string|max:255',
|
||||
'arrival_date' => 'required|date',
|
||||
'template_id' => 'nullable|exists:integration_templates,id',
|
||||
]);
|
||||
|
||||
$integration = $action->execute($validated);
|
||||
|
||||
return redirect()->route('integrations.show', $integration);
|
||||
}
|
||||
|
||||
public function show(IntegrationRequest $integration)
|
||||
{
|
||||
$integration->load([
|
||||
'agent',
|
||||
'template',
|
||||
'serviceTasks.service',
|
||||
'serviceTasks.taskItems',
|
||||
'serviceTasks.comments.user',
|
||||
'serviceTasks.attachments',
|
||||
'activities.causer',
|
||||
'comments.user'
|
||||
]);
|
||||
|
||||
$taskActivities = \Spatie\Activitylog\Models\Activity::where('subject_type', \App\Models\ServiceTask::class)
|
||||
->whereIn('subject_id', $integration->serviceTasks->pluck('id'))
|
||||
->with('causer')
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return Inertia::render('Integration/Show', [
|
||||
'integration' => $integration,
|
||||
'activities' => $integration->activities->merge($taskActivities)->sortByDesc('created_at')->values(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function validateRH(IntegrationRequest $integration, \App\Services\IntegrationService $service)
|
||||
{
|
||||
$this->authorize('update', $integration);
|
||||
|
||||
$service->validateRH($integration);
|
||||
|
||||
return back()->with('success', 'Intégration validée par les RH. Les services ont été notifiés.');
|
||||
}
|
||||
|
||||
public function downloadPdf(IntegrationRequest $integration)
|
||||
{
|
||||
// Load relationships needed for the PDF
|
||||
$integration->load([
|
||||
'agent',
|
||||
'template',
|
||||
'serviceTasks.service',
|
||||
'serviceTasks.taskItems.completedBy'
|
||||
]);
|
||||
|
||||
$pdf = \Barryvdh\DomPDF\Facade\Pdf::loadView('pdf.integration', [
|
||||
'integration' => $integration,
|
||||
'agent' => $integration->agent,
|
||||
'date' => now()->format('d/m/Y'),
|
||||
]);
|
||||
|
||||
// Define paper size and orientation if needed, e.g., A4 portrait
|
||||
$pdf->setPaper('a4', 'portrait');
|
||||
|
||||
return $pdf->download("Fiche_Agent_{$integration->agent->last_name}_{$integration->agent->first_name}.pdf");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user