Add the unbilled hours report
Hours on customers' billable jobs that no billing material has taken, by job and work type up to a day, valued at the hourly rates for jobs billed by the hour, with a chart by service unit and CSV. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Presentation\Csv;
|
||||
|
||||
use App\Modules\Reports\Domain\Exceptions\InvalidReportPeriod;
|
||||
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Reads the report pages' URL filters from a CSV download's query string.
|
||||
*/
|
||||
final class CsvFilters
|
||||
{
|
||||
/**
|
||||
* @throws InvalidReportPeriod
|
||||
*/
|
||||
public static function period(Request $request): ReportPeriod
|
||||
{
|
||||
return new ReportPeriod(self::text($request, 'alku'), self::text($request, 'loppu'));
|
||||
}
|
||||
|
||||
/**
|
||||
* A single day (Y-m-d).
|
||||
*
|
||||
* @throws InvalidReportPeriod
|
||||
*/
|
||||
public static function day(Request $request, string $key): string
|
||||
{
|
||||
$day = self::text($request, $key);
|
||||
|
||||
return (new ReportPeriod($day, $day))->from;
|
||||
}
|
||||
|
||||
public static function id(Request $request, string $key): ?int
|
||||
{
|
||||
$value = self::text($request, $key);
|
||||
|
||||
return ctype_digit($value) ? (int) $value : null;
|
||||
}
|
||||
|
||||
public static function flag(Request $request, string $key): bool
|
||||
{
|
||||
return self::text($request, $key) === '1';
|
||||
}
|
||||
|
||||
private static function text(Request $request, string $key): string
|
||||
{
|
||||
$value = $request->query($key);
|
||||
|
||||
return is_string($value) ? $value : '';
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
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;
|
||||
|
||||
@@ -14,14 +13,21 @@ class HoursCsv implements ReportCsv
|
||||
{
|
||||
public function __construct(private HoursByPerson $report) {}
|
||||
|
||||
public function fileName(Request $request): string
|
||||
{
|
||||
$period = CsvFilters::period($request);
|
||||
|
||||
return __('reports.hours.file').'-'.$period->from.'-'.$period->to;
|
||||
}
|
||||
|
||||
public function headers(): array
|
||||
{
|
||||
return array_values(__('reports.hours.csv'));
|
||||
}
|
||||
|
||||
public function rows(ReportPeriod $period, Request $request): iterable
|
||||
public function rows(Request $request): iterable
|
||||
{
|
||||
$report = $this->report->execute($period, self::id($request, 'yksikko'), self::id($request, 'asiakas'));
|
||||
$report = $this->report->execute(CsvFilters::period($request), CsvFilters::id($request, 'yksikko'), CsvFilters::id($request, 'asiakas'));
|
||||
|
||||
foreach ($report->lines as $line) {
|
||||
yield [
|
||||
@@ -38,11 +44,4 @@ class HoursCsv implements ReportCsv
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public static function id(Request $request, string $key): ?int
|
||||
{
|
||||
$value = $request->query($key);
|
||||
|
||||
return is_string($value) && ctype_digit($value) ? (int) $value : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,22 @@
|
||||
|
||||
namespace App\Modules\Reports\Presentation\Csv;
|
||||
|
||||
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
||||
use App\Modules\Reports\Domain\Exceptions\InvalidReportPeriod;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* A report as CSV rows, with the filters of the report page read from the
|
||||
* request's query string.
|
||||
* request's query string (see CsvFilters).
|
||||
*/
|
||||
interface ReportCsv
|
||||
{
|
||||
/**
|
||||
* The file name without the extension, e.g. "tunnit-2026-11-01-2026-11-30".
|
||||
*
|
||||
* @throws InvalidReportPeriod
|
||||
*/
|
||||
public function fileName(Request $request): string;
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
@@ -18,6 +25,8 @@ interface ReportCsv
|
||||
|
||||
/**
|
||||
* @return iterable<list<string|int>>
|
||||
*
|
||||
* @throws InvalidReportPeriod
|
||||
*/
|
||||
public function rows(ReportPeriod $period, Request $request): iterable;
|
||||
public function rows(Request $request): iterable;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Presentation\Csv;
|
||||
|
||||
use App\Modules\Reports\Application\UseCases\UnbilledHoursReport;
|
||||
use App\Modules\Reports\Presentation\ReportFormat;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Unbilled hours as CSV: a row per job and work type, values in cents.
|
||||
*/
|
||||
class UnbilledCsv implements ReportCsv
|
||||
{
|
||||
public function __construct(private UnbilledHoursReport $report) {}
|
||||
|
||||
public function fileName(Request $request): string
|
||||
{
|
||||
return __('reports.unbilled.file').'-'.CsvFilters::day($request, 'paiva');
|
||||
}
|
||||
|
||||
public function headers(): array
|
||||
{
|
||||
return array_values(__('reports.unbilled.csv'));
|
||||
}
|
||||
|
||||
public function rows(Request $request): iterable
|
||||
{
|
||||
$report = $this->report->execute(CsvFilters::day($request, 'paiva'), CsvFilters::id($request, 'yksikko'));
|
||||
|
||||
foreach ($report->jobs as $row) {
|
||||
foreach ($row->workTypes as $line) {
|
||||
yield [
|
||||
$row->job->number,
|
||||
$row->job->name,
|
||||
$row->job->customerName,
|
||||
__('jobs.statuses.'.$row->job->status),
|
||||
$row->job->paymentBasis === null ? '' : __('jobs.payment_bases.'.$row->job->paymentBasis),
|
||||
$line->serviceUnitName,
|
||||
$line->name,
|
||||
ReportFormat::csvHours($line->approvedQuarters),
|
||||
ReportFormat::csvHours($line->unapprovedQuarters),
|
||||
$line->rateCents ?? '',
|
||||
$line->valueCents ?? '',
|
||||
$row->oldestDay,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user