feat: Implement sale management features including controllers, services, resources, and routes; add PDF generation for sales and modifications

This commit is contained in:
2026-08-04 11:44:13 -03:00
parent 3f9bcd84c4
commit 1de08c1ca4
22 changed files with 700 additions and 104 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Domains\Sale\Resources\AdminApp;
use App\Domains\Logging\Models\ValueChange;
use App\Domains\Purchase\Models\Purchase;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin ValueChange */
class SaleModificationResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
/** @var Purchase|null $sale */
$sale = $this->whenLoaded('trackable');
$user = $this->whenLoaded('user');
return [
'id' => $this->id,
'sale_id' => $this->trackable_id,
'attribute' => $this->attribute,
'old_value' => $this->old_value,
'new_value' => $this->new_value,
'date' => $this->changed_at->format('Y-m-d'),
'time' => $this->changed_at->format('H:i:s'),
'actor_type' => $this->actor_type->value,
'sale' => $sale instanceof Purchase ? [
'id' => $sale->id,
'customer_name' => $sale->nombre_apellido,
'status' => $sale->status,
] : null,
'modified_by' => $user ? [
'id' => $user->id,
'name' => $user->nombre_apellido,
'email' => $user->email,
] : null,
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Domains\Sale\Resources\AdminApp;
use App\Domains\Purchase\Models\Purchase;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin Purchase */
class SaleResource extends JsonResource
{
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
$ticketsCount = (int) ($this->tickets_count ?? 0);
return [
'id' => $this->id,
'created_at' => $this->created_at,
'customer_name' => $this->nombre_apellido,
'quantity' => (int) ($this->quantity ?? 0),
'status' => $this->status,
'total' => number_format((float) $this->total, 2, '.', ''),
'tickets_count' => $ticketsCount,
'has_generated_tickets' => $ticketsCount > 0,
];
}
}