Track machine counters and maintenance with counter and time intervals
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Machines\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Inventory\Application\DTOs\StockUseData;
|
||||
use App\Modules\Inventory\Application\UseCases\RecordStockUse;
|
||||
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
|
||||
use App\Modules\Machines\Application\Contracts\MaintenanceMaterials;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
|
||||
/**
|
||||
* Records stock used at machine maintenance through the Inventory module.
|
||||
* A failure (e.g. the item is out of use) does not undo the maintenance.
|
||||
*/
|
||||
class StockForMachines implements MaintenanceMaterials
|
||||
{
|
||||
public function __construct(private RecordStockUse $recordUse) {}
|
||||
|
||||
public function use(int $stockItemId, int $quantityMilli, int $machineId, int $maintenanceRecordId, int $userId): bool
|
||||
{
|
||||
try {
|
||||
$this->recordUse->execute(new StockUseData(
|
||||
$stockItemId,
|
||||
StockQuantity::inputValue($quantityMilli),
|
||||
machineId: $machineId,
|
||||
maintenanceRecordId: $maintenanceRecordId,
|
||||
), $userId);
|
||||
} catch (DomainException) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user