47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Reports\Presentation\Csv;
|
|
|
|
use App\Modules\Inventory\Domain\ValueObjects\StockQuantity;
|
|
use App\Modules\Reports\Application\UseCases\StockUsageReport;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Stock usage as CSV: a row per item, quantities with a decimal comma and
|
|
* values in cents (VAT 0).
|
|
*/
|
|
class StockUsageCsv implements ReportCsv
|
|
{
|
|
public function __construct(private StockUsageReport $report) {}
|
|
|
|
public function fileName(Request $request): string
|
|
{
|
|
$period = CsvFilters::period($request);
|
|
|
|
return __('reports.stock_usage.file').'-'.$period->from.'-'.$period->to;
|
|
}
|
|
|
|
public function headers(): array
|
|
{
|
|
return array_values(__('reports.stock_usage.csv'));
|
|
}
|
|
|
|
public function rows(Request $request): iterable
|
|
{
|
|
foreach ($this->report->execute(CsvFilters::period($request))->items as $row) {
|
|
yield [
|
|
$row->label,
|
|
(string) $row->group,
|
|
__('inventory.units.'.$row->unit),
|
|
StockQuantity::inputValue($row->usedMilli),
|
|
$row->usedCents,
|
|
StockQuantity::inputValue($row->writtenOffMilli),
|
|
$row->writtenOffCents,
|
|
StockQuantity::inputValue($row->adjustedMilli),
|
|
$row->adjustedCents,
|
|
$row->totalCents(),
|
|
];
|
|
}
|
|
}
|
|
}
|