46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Sales\Domain\ValueObjects;
|
|
|
|
/**
|
|
* A production step copied to an order line when the order is sent (spec
|
|
* 19.7): the machine (null: by hand), the duration and materials per
|
|
* piece and the work type the hours go to. Later changes to the product's
|
|
* process do not touch the copy.
|
|
*/
|
|
final readonly class OrderStep
|
|
{
|
|
/**
|
|
* @param list<array{stockItemId: int, quantityMilli: int}> $materials
|
|
*/
|
|
public function __construct(
|
|
public ?int $machineId,
|
|
public int $durationQuarters,
|
|
public int $workTypeId,
|
|
public array $materials = [],
|
|
) {}
|
|
|
|
/**
|
|
* @return array{machineId: ?int, durationQuarters: int, workTypeId: int, materials: list<array{stockItemId: int, quantityMilli: int}>}
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return ['machineId' => $this->machineId, 'durationQuarters' => $this->durationQuarters, 'workTypeId' => $this->workTypeId, 'materials' => $this->materials];
|
|
}
|
|
|
|
/**
|
|
* @param array{machineId?: ?int, durationQuarters?: int, workTypeId?: int, materials?: list<array{stockItemId: int, quantityMilli: int}>} $data
|
|
*/
|
|
public static function fromArray(array $data): self
|
|
{
|
|
return new self(
|
|
isset($data['machineId']) ? (int) $data['machineId'] : null,
|
|
(int) ($data['durationQuarters'] ?? 0),
|
|
(int) ($data['workTypeId'] ?? 0),
|
|
array_map(fn (array $material): array => ['stockItemId' => (int) $material['stockItemId'], 'quantityMilli' => (int) $material['quantityMilli']], $data['materials'] ?? []),
|
|
);
|
|
}
|
|
}
|