This commit is contained in:
lubiana 2025-06-08 13:58:51 +02:00
parent 837cfb6d43
commit 939840a3ac
Signed by: lubiana
SSH key fingerprint: SHA256:vW1EA0fRR3Fw+dD/sM0K+x3Il2gSry6YRYHqOeQwrfk
76 changed files with 6636 additions and 83 deletions

View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace App\ValueObject;
use App\Entity\InventoryRecord;
use App\Enum\StockState;
final readonly class DrinkStock
{
public function __construct(
public InventoryRecord $record,
public StockState $stock,
) {}
public static function fromInventoryRecord(InventoryRecord $record, float $lowStockMultiplier): self
{
if ($record->getQuantity() === 0 && $record->getDrinkType()->getDesiredStock() > 0) {
return new self($record, StockState::CRITICAL);
}
if ($record->getQuantity() < ($record->getDrinkType()->getDesiredStock() * $lowStockMultiplier)) {
return new self($record, StockState::LOW);
}
if ($record->getQuantity() > $record->getDrinkType()->getDesiredStock()) {
return new self($record, StockState::HIGH);
}
return new self($record, StockState::NORMAL);
}
}