Files
Toiminnanohjaus/app/Modules/Inventory/Application/UseCases/ReverseMaintenanceStockUse.php
petriandClaude Sonnet 5.5 ef400054b0 Return stock of cancelled maintenance, throttle the PIN page's password
Cancelling a maintenance record now reverses the stock it used, through
Inventory's new ReverseMaintenanceStockUse behind the MaintenanceMaterials
port, in the same transaction as the cancellation.

The PIN page allows 5 wrong current passwords a minute per user, as the
login form does, so a signed-in session cannot be used to guess the
password.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-29 10:10:18 +02:00

47 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\UseCases;
use App\Modules\Inventory\Domain\Contracts\StockMovementRepository;
use App\Modules\Inventory\Domain\Exceptions\StockMovementAlreadyReversed;
use App\Modules\Inventory\Domain\Exceptions\StockMovementNotFound;
use App\Modules\Inventory\Domain\Exceptions\StockMovementNotReversible;
use App\Modules\Inventory\Domain\Exceptions\StockReversalNotAllowed;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Returns the stock a cancelled maintenance record used (spec 19.5): each
* of its use movements not yet reversed gets a reversal, recorded today.
*/
final class ReverseMaintenanceStockUse
{
public function __construct(
private StockMovementRepository $movements,
private ReverseStockMovement $reverse,
private TransactionManager $transactions,
) {}
/**
* @return int How many movements were reversed.
*
* @throws StockMovementNotFound
* @throws StockMovementNotReversible
* @throws StockMovementAlreadyReversed
* @throws StockReversalNotAllowed
*/
public function execute(int $maintenanceRecordId, int $actorUserId): int
{
return $this->transactions->run(function () use ($maintenanceRecordId, $actorUserId): int {
$movementIds = $this->movements->unreversedUseOfMaintenance($maintenanceRecordId);
foreach ($movementIds as $movementId) {
$this->reverse->execute($movementId, $actorUserId, true);
}
return count($movementIds);
});
}
}