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,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Inventory\Application\UseCases;
|
||||
|
||||
use App\Modules\Inventory\Domain\Contracts\StockItemRepository;
|
||||
use App\Modules\Inventory\Domain\Exceptions\StockItemNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Takes a stock item out of use, or back. An item out of use cannot be
|
||||
* used, but its movements stay.
|
||||
*/
|
||||
final class SetStockItemActive
|
||||
{
|
||||
public function __construct(
|
||||
private StockItemRepository $items,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws StockItemNotFound
|
||||
*/
|
||||
public function execute(int $itemId, bool $active): void
|
||||
{
|
||||
$this->transactions->run(function () use ($itemId, $active): void {
|
||||
$item = $this->items->findById($itemId) ?? throw new StockItemNotFound;
|
||||
$active ? $item->activate() : $item->deactivate();
|
||||
$this->items->save($item);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user