Make quick sale products on machines as orders paid when ready
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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'] ?? []),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user