Files
Toiminnanohjaus/app/Modules/Reports/Presentation/ReportFormat.php
T
petriandClaude Sonnet 5.5 64f1e7c54a Add Reports module with the hours by person report
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]>
2026-11-25 08:39:19 +02:00

55 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Modules\Reports\Presentation;
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
use App\Modules\Shared\Domain\ValueObjects\Money;
use DateTimeImmutable;
/**
* Finnish number, money and date formats of the reports, in both UI
* languages. Amounts may be negative (credits, losses), which Money does
* not hold, so the sign is added here.
*/
final class ReportFormat
{
public static function money(int $cents): string
{
return ($cents < 0 ? '-' : '').Money::fromCents(abs($cents))->format();
}
/**
* E.g. 6 quarters → "1,5".
*/
public static function hours(int $quarters): string
{
return rtrim(rtrim(number_format($quarters / 4, 2, ',', "\u{00A0}"), '0'), ',');
}
/**
* Hours for a CSV cell: a decimal comma and no thousands separator.
*/
public static function csvHours(int $quarters): string
{
return rtrim(rtrim(number_format($quarters / 4, 2, ',', ''), '0'), ',');
}
/**
* E.g. 0.256 → "25,6 %".
*/
public static function percent(float $ratio): string
{
return number_format($ratio * 100, 1, ',', "\u{00A0}")."\u{00A0}%";
}
public static function date(string $day): string
{
return (new DateTimeImmutable($day))->format('j.n.Y');
}
public static function period(ReportPeriod $period): string
{
return self::date($period->from).'–'.self::date($period->to);
}
}