48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Reports\Infrastructure\Adapters;
|
|
|
|
use App\Modules\Inventory\Application\Contracts\StockReportQueries;
|
|
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
|
use App\Modules\Reports\Application\Contracts\ReportStock;
|
|
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
|
|
|
/**
|
|
* Stock for reports through the Inventory and Machines modules.
|
|
*/
|
|
class StockForReports implements ReportStock
|
|
{
|
|
public function __construct(
|
|
private StockReportQueries $stock,
|
|
private MachineQueries $machines,
|
|
) {}
|
|
|
|
public function usage(ReportPeriod $period): array
|
|
{
|
|
return $this->stock->usage($period->from, $period->to);
|
|
}
|
|
|
|
public function valueOn(string $day): array
|
|
{
|
|
return $this->stock->valueOn($day);
|
|
}
|
|
|
|
public function materialCostsByJob(ReportPeriod $period): array
|
|
{
|
|
return $this->stock->materialCostsByJob($period->from, $period->to);
|
|
}
|
|
|
|
public function machineNames(array $ids): array
|
|
{
|
|
$names = [];
|
|
|
|
foreach ($this->machines->machines(includeInactive: true) as $machine) {
|
|
if (in_array($machine->id, $ids, true)) {
|
|
$names[$machine->id] = $machine->name;
|
|
}
|
|
}
|
|
|
|
return $names;
|
|
}
|
|
}
|