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:
2026-11-26 16:18:59 +02:00
co-authored by Claude Sonnet 5.5
parent 361a2974cf
commit 30132deb0e
81 changed files with 4968 additions and 115 deletions
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\UseCases;
use App\Modules\Inventory\Domain\Contracts\StockItemGroupRepository;
use App\Modules\Inventory\Domain\Entities\StockItemGroup;
use App\Modules\Inventory\Domain\Exceptions\InvalidStockName;
use App\Modules\Inventory\Domain\Exceptions\StockNameTaken;
use App\Modules\Inventory\Domain\ValueObjects\StockName;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Adds a stock item group last in order.
*/
final class AddStockItemGroup
{
public function __construct(
private StockItemGroupRepository $groups,
private TransactionManager $transactions,
) {}
/**
* @throws InvalidStockName
* @throws StockNameTaken
*/
public function execute(string $name): int
{
$name = new StockName($name);
return $this->transactions->run(function () use ($name): int {
if ($this->groups->isNameTaken($name->value)) {
throw new StockNameTaken;
}
return (int) $this->groups->save(StockItemGroup::create($name, $this->groups->nextSortOrder()))->id();
});
}
}