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,22 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
/**
* A purchase (hankinta) as entered: the day (Y-m-d), the quantity, and the
* price without VAT either in total or per unit (the other left empty).
*/
final readonly class PurchaseData
{
public function __construct(
public int $itemId,
public string $occurredOn,
public string $quantity,
public string $totalPrice = '',
public string $unitPrice = '',
public ?string $supplier = null,
public ?string $documentNumber = null,
) {}
}
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
final readonly class StockGroupSummary
{
public function __construct(
public int $id,
public string $name,
public bool $isActive,
public int $itemCount = 0,
) {}
}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
/**
* A stock item's details as entered: the unit key and the reorder level
* as typed ("2,5"; empty for none).
*/
final readonly class StockItemData
{
public function __construct(
public int $groupId,
public string $name,
public string $unit,
public ?string $code = null,
public ?string $supplier = null,
public string $reorderLevel = '',
) {}
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
use App\Modules\Inventory\Domain\Enums\StockUnit;
/**
* A stock item with its balance (in thousandths), moving average cost (in
* hundredths of a cent per unit) and stock value (in cents). Costs and
* values are shown only to those who may see them.
*/
final readonly class StockItemSummary
{
public function __construct(
public int $id,
public int $groupId,
public string $groupName,
public string $name,
public StockUnit $unit,
public ?string $code,
public ?string $supplier,
public ?int $reorderLevelMilli,
public int $balanceMilli,
public int $averageCostHundredths,
public int $valueCents,
public bool $hasImage,
public bool $isActive,
) {}
/**
* At or below the reorder level: to be ordered (tilattava).
*/
public function needsReorder(): bool
{
return $this->reorderLevelMilli !== null && $this->balanceMilli <= $this->reorderLevelMilli;
}
public function isNegative(): bool
{
return $this->balanceMilli < 0;
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
use App\Modules\Inventory\Domain\Enums\StockMovementKind;
/**
* A stock movement in an item's history: signed quantity and the balance
* after it (in thousandths), its value in cents, when and by whom, and
* what it was for. $recordedAt is "Y-m-d H:i" in the company's time zone.
*/
final readonly class StockMovementSummary
{
public function __construct(
public int $id,
public int $itemId,
public StockMovementKind $kind,
public int $quantityMilli,
public int $balanceAfterMilli,
public int $valueCents,
public string $occurredOn,
public string $recordedAt,
public int $userId,
public string $userName,
public ?int $taskId,
public ?int $jobId,
public ?int $machineId,
public ?int $orderLineId,
public ?int $maintenanceRecordId,
public ?int $inventoryCountId,
public ?string $reason,
public ?string $supplier,
public ?string $documentNumber,
public ?int $reversesMovementId,
public ?int $reversedByMovementId,
) {}
public function canBeReversed(): bool
{
return $this->reversedByMovementId === null
&& $this->kind !== StockMovementKind::Reversal
&& $this->kind !== StockMovementKind::Adjustment;
}
}
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
/**
* Stock used (käyttö) as entered: the quantity as typed and what it was
* used for; use without a target needs a reason.
*/
final readonly class StockUseData
{
public function __construct(
public int $itemId,
public string $quantity,
public ?int $taskId = null,
public ?int $jobId = null,
public ?int $machineId = null,
public ?int $orderLineId = null,
public ?int $maintenanceRecordId = null,
public ?string $reason = null,
) {}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App\Modules\Inventory\Application\DTOs;
/**
* Recorded use or write-off: the movement, the item's name, the quantity
* taken and the item's new balance (in thousandths).
*/
final readonly class StockUseResult
{
public function __construct(
public int $movementId,
public string $itemName,
public int $quantityMilli,
public int $balanceMilli,
) {}
}