Initial commit: Import existing Laravel project

This commit is contained in:
jeremy bayse
2026-06-15 08:12:33 +02:00
parent 7420d1b466
commit 030d76af53
143 changed files with 21885 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class AttachmentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'order_id' => $this->order_id,
'file_name' => $this->file_name,
'file_type' => $this->file_type,
'url' => $this->url,
'created_at' => $this->created_at?->format('d/m/Y H:i'),
];
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class HardwareResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'type' => $this->type,
'brand' => $this->brand,
'model' => $this->model,
'serial_number' => $this->serial_number,
'status' => $this->status,
// Format brut pour les inputs date HTML (YYYY-MM-DD)
'purchase_date' => $this->purchase_date?->format('Y-m-d'),
'commissioning_date' => $this->commissioning_date?->format('Y-m-d'),
'warranty_expiration_date' => $this->warranty_expiration_date?->format('Y-m-d'),
// Format français pour l'affichage (DD/MM/YYYY)
'purchase_date_formatted' => $this->purchase_date?->format('d/m/Y') ?? 'Non spécifiée',
'commissioning_date_formatted' => $this->commissioning_date?->format('d/m/Y') ?? 'Non spécifiée',
'warranty_expiration_date_formatted' => $this->warranty_expiration_date?->format('d/m/Y') ?? 'Non spécifiée',
'location' => $this->location,
'ip_address' => $this->ip_address,
'order_id' => $this->order_id,
// Relation éventuelle avec la commande
'order' => $this->relationLoaded('order') && $this->order ? [
'id' => $this->order->id,
'number' => $this->order->number,
'label' => $this->order->label,
] : null,
'notes' => $this->notes,
// Propriétés calculées
'is_under_warranty' => $this->is_under_warranty,
'warranty_status_label' => $this->warranty_status_label,
'warranty_remaining_days' => $this->warranty_remaining_days,
'created_at' => $this->created_at?->format('d/m/Y H:i'),
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$now = now()->startOfDay();
$deadline = $this->delivery_deadline ? \Carbon\Carbon::parse($this->delivery_deadline)->startOfDay() : null;
$isOverdue = $deadline && $deadline->lt($now) && !in_array($this->status, ['delivered', 'closed']);
return [
'id' => $this->id,
'number' => $this->number,
'label' => $this->label,
'type' => $this->type,
'supplier' => $this->supplier,
'quote_number' => $this->quote_number,
'amount_ht' => (float) $this->amount_ht,
'amount_ttc' => (float) $this->amount_ttc,
'exclude_vat' => (bool) $this->exclude_vat,
'requested_by' => $this->requested_by,
'prescriber' => $this->prescriber,
'delivery_deadline' => $this->delivery_deadline?->format('Y-m-d'),
'delivery_deadline_formatted' => $this->delivery_deadline?->format('d/m/Y'),
'status' => $this->status,
'notes' => $this->notes,
'is_overdue' => $isOverdue,
'created_at' => $this->created_at?->format('d/m/Y H:i'),
'attachments' => AttachmentResource::collection($this->whenLoaded('attachments')),
'status_logs' => OrderStatusLogResource::collection($this->whenLoaded('statusLogs')),
'can' => [
'update' => $request->user()?->can('update', $this->resource),
'delete' => $request->user()?->can('delete', $this->resource),
],
'can_transition_to' => [
'validated' => $this->status === 'draft' && ($request->user()?->can('transition', [$this->resource, 'validated']) ?? false),
'ordered' => $this->status === 'validated' && ($request->user()?->can('transition', [$this->resource, 'ordered']) ?? false),
'delivered' => $this->status === 'ordered' && ($request->user()?->can('transition', [$this->resource, 'delivered']) ?? false),
'closed' => $this->status === 'delivered' && ($request->user()?->can('transition', [$this->resource, 'closed']) ?? false),
],
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderStatusLogResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'order_id' => $this->order_id,
'user' => [
'id' => $this->user?->id,
'name' => $this->user?->name,
'role' => $this->user?->role,
],
'old_status' => $this->old_status,
'new_status' => $this->new_status,
'changed_at' => $this->changed_at?->format('d/m/Y H:i'),
];
}
}