Management's reports (spec 13) get their own module that reads the other modules through ports. The first report sums hours by person in a period, narrowed by service unit or customer, with breakdowns, a chart and CSV. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Reports\Presentation\Csv;
|
|
|
|
use App\Modules\Reports\Application\UseCases\HoursByPerson;
|
|
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
|
use App\Modules\Reports\Presentation\ReportFormat;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Hours by person as CSV: a row per person, job and work type.
|
|
*/
|
|
class HoursCsv implements ReportCsv
|
|
{
|
|
public function __construct(private HoursByPerson $report) {}
|
|
|
|
public function headers(): array
|
|
{
|
|
return array_values(__('reports.hours.csv'));
|
|
}
|
|
|
|
public function rows(ReportPeriod $period, Request $request): iterable
|
|
{
|
|
$report = $this->report->execute($period, self::id($request, 'yksikko'), self::id($request, 'asiakas'));
|
|
|
|
foreach ($report->lines as $line) {
|
|
yield [
|
|
$line->userName,
|
|
$line->jobNumber,
|
|
$line->jobName,
|
|
$line->customerName,
|
|
__($line->isInternal ? 'reports.yes' : 'reports.no'),
|
|
$line->serviceUnitName,
|
|
$line->workTypeName,
|
|
ReportFormat::csvHours($line->quarters),
|
|
ReportFormat::csvHours($line->unapprovedQuarters),
|
|
ReportFormat::csvHours($line->billedQuarters),
|
|
];
|
|
}
|
|
}
|
|
|
|
public static function id(Request $request, string $key): ?int
|
|
{
|
|
$value = $request->query($key);
|
|
|
|
return is_string($value) && ctype_digit($value) ? (int) $value : null;
|
|
}
|
|
}
|