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:
2026-11-26 17:11:54 +02:00
co-authored by Claude Sonnet 5.5
parent 920fecdeb2
commit 38b8075a9c
58 changed files with 3435 additions and 26 deletions
@@ -0,0 +1,29 @@
<?php
namespace App\Modules\Sales\Infrastructure\Adapters;
use App\Modules\Machines\Application\Contracts\ProductionProcessQueries;
use App\Modules\Machines\Application\DTOs\ProductionStepSummary;
use App\Modules\Sales\Application\Contracts\ProductionProcesses;
use App\Modules\Sales\Domain\ValueObjects\OrderStep;
/**
* Production processes of products from the Machines module.
*/
class ProcessesFromMachines implements ProductionProcesses
{
public function __construct(private ProductionProcessQueries $processes) {}
public function stepsOf(array $productIds): array
{
return array_map(
fn (array $steps): array => array_map(fn (ProductionStepSummary $step): OrderStep => new OrderStep(
$step->machineId,
$step->durationQuarters,
$step->workTypeId,
array_map(fn (array $material): array => ['stockItemId' => $material['stockItemId'], 'quantityMilli' => $material['quantityMilli']], $step->materials),
), $steps),
$this->processes->processesOf($productIds),
);
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Modules\Sales\Infrastructure\Adapters;
use App\Modules\Machines\Application\UseCases\MachineWorkList;
use App\Modules\Sales\Application\Contracts\ProductionQueue;
use DateTimeImmutable;
/**
* Order lines on machines' work lists through the Machines module.
*/
class QueueOnMachines implements ProductionQueue
{
public function __construct(private MachineWorkList $workList) {}
public function enqueue(int $orderLineId, int $stepPosition, int $machineId, DateTimeImmutable $day): void
{
$this->workList->enqueueOrderStep($orderLineId, $stepPosition, $machineId, $day);
}
public function complete(int $orderLineId, int $userId): void
{
$this->workList->completeOrderLine($orderLineId, $userId);
}
public function remove(int $orderLineId): void
{
$this->workList->removeOrderLine($orderLineId);
}
}
@@ -0,0 +1,50 @@
<?php
namespace App\Modules\Sales\Infrastructure\Adapters;
use App\Modules\Inventory\Application\DTOs\StockUseData;
use App\Modules\Inventory\Application\UseCases\RecordStockUse;
use App\Modules\Inventory\Application\UseCases\RecordStockWriteOff;
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
use App\Modules\Sales\Application\Contracts\OrderMaterials;
use App\Modules\Shared\Domain\Exceptions\DomainException;
/**
* Stock used in making quick sale orders, through the Inventory module.
* Reasons are stored in Finnish, like the rest of the business records.
*/
class StockForOrders implements OrderMaterials
{
public function __construct(
private RecordStockUse $recordUse,
private RecordStockWriteOff $recordWriteOff,
) {}
public function use(int $stockItemId, int $quantityMilli, int $orderLineId, ?int $machineId, int $userId): bool
{
try {
$this->recordUse->execute(new StockUseData($stockItemId, StockQuantity::inputValue($quantityMilli), machineId: $machineId, orderLineId: $orderLineId), $userId);
} catch (DomainException) {
return false;
}
return true;
}
public function writeOff(int $stockItemId, int $quantityMilli, int $orderLineId, ?int $machineId, int $userId, string $reason): bool
{
try {
$this->recordWriteOff->execute(new StockUseData(
$stockItemId,
StockQuantity::inputValue($quantityMilli),
machineId: $machineId,
orderLineId: $orderLineId,
reason: __('sales.orders.reasons.'.$reason, [], 'fi'),
), $userId);
} catch (DomainException) {
return false;
}
return true;
}
}