vibe
This commit is contained in:
parent
837cfb6d43
commit
939840a3ac
76 changed files with 6636 additions and 83 deletions
31
src/ValueObject/DrinkStock.php
Normal file
31
src/ValueObject/DrinkStock.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue