ldc-boutique-cnc-sable/domain/Services/RegateService.php
Jérémy Munsch c8f895c759
refactor: simplify use statements and type hints
- Removed fully qualified names for better readability.
- Streamlined code by using direct class references.
2026-10-29 20:35:35 +01:00

79 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Domain\Services;
use Carbon\CarbonImmutable;
use Domain\Events\Dto\RegateOrderCsvGenerated;
use Domain\Models\ValueObjects\Matricule;
use Domain\Models\ValueObjects\OrderReference;
use Domain\Ports\Services\CsvGenerator;
use Shared\DDD\DomainEventDispatcher;
class RegateService
{
/** @var string[] */
private array $header = [
'CodeArt',
'Client livré code',
'ean13',
'Type de commande',
'Unité Elem. Appro',
'mode de commande',
'Pcb Art',
'Date livraison',
'Qté commandée',
'Num Cde Client',
];
public function __construct(
private readonly CsvGenerator $csvGenerator,
private readonly DomainEventDispatcher $dispatcher
) {
}
/**
* @param \Domain\Events\Dto\OrderPlacedLine[] $lines
*/
public function processOrder(
OrderReference $reference,
Matricule $employeeMatricule,
CarbonImmutable $pickupDay,
array $lines
): void {
$rows = [];
foreach ($lines as $line) {
array_push(
$rows,
[
(string) $line->productIncoId->value,
$employeeMatricule->value,
(string) $line->productIncoId->value,
'commande ferme',
(string) $line->productOrderUnit->value,
$line->productOrderUnit->toRegateCode(),
'',
$pickupDay->format('d/m/Y'),
(string) $line->quantity,
(string) $reference,
]
);
}
$csvContent = $this->csvGenerator->generate($this->header, $rows);
$now = CarbonImmutable::now();
$fileName = sprintf(
'BTQ-%s-%s%s.csv',
$reference,
$now->format('Ymd_His'),
\microtime(true)
);
$this->dispatcher->dispatch(
new RegateOrderCsvGenerated($csvContent, $fileName)
);
}
}