Add stock items, groups and movements at a moving average cost
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Inventory\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Inventory\Domain\Exceptions\StockReasonRequired;
|
||||
|
||||
/**
|
||||
* What stock was used for (spec 19.2): a job's task, a machine, a quick
|
||||
* sale order line or a machine's maintenance, each possibly with a reason.
|
||||
* Use without a target (e.g. a test run) needs a reason.
|
||||
*/
|
||||
final readonly class StockUseTarget
|
||||
{
|
||||
public ?string $reason;
|
||||
|
||||
/**
|
||||
* @throws StockReasonRequired
|
||||
*/
|
||||
public function __construct(
|
||||
public ?int $taskId = null,
|
||||
public ?int $jobId = null,
|
||||
public ?int $machineId = null,
|
||||
public ?int $orderLineId = null,
|
||||
public ?int $maintenanceRecordId = null,
|
||||
?string $reason = null,
|
||||
) {
|
||||
$reason = $reason === null ? null : trim($reason);
|
||||
$this->reason = $reason === '' || $reason === null ? null : mb_substr($reason, 0, 255);
|
||||
|
||||
if ($this->reason === null && $taskId === null && $machineId === null && $orderLineId === null && $maintenanceRecordId === null) {
|
||||
throw new StockReasonRequired;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws StockReasonRequired
|
||||
*/
|
||||
public static function reason(?string $reason): self
|
||||
{
|
||||
return new self(reason: $reason);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user