Files
Toiminnanohjaus/app/Modules/Reports/Application/UseCases/StockValueReport.php

30 lines
937 B
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Reports\Application\UseCases;
use App\Modules\Inventory\Application\DTOs\StockValueEntry;
use App\Modules\Reports\Application\Contracts\ReportStock;
use App\Modules\Reports\Application\DTOs\StockValueReportData;
/**
* Stock value (Varaston arvo, spec 19.8): every item's balance and book
* value at the end of a day, the total, and the items to order.
*/
final readonly class StockValueReport
{
public function __construct(private ReportStock $stock) {}
public function execute(string $day): StockValueReportData
{
$items = $this->stock->valueOn($day);
return new StockValueReportData(
$items,
array_sum(array_map(fn (StockValueEntry $item): int => $item->valueCents, $items)),
array_values(array_filter($items, fn (StockValueEntry $item): bool => $item->isActive && $item->needsReorder())),
);
}
}