Files
Toiminnanohjaus/app/Modules/Billing/Presentation/Livewire/Concerns/FormatsBilling.php
T
petriandClaude Opus 5.5 97bd23bed5 Add the billing material with drafts, combined invoices and billed marks
Management builds the monthly billing material (laskuaineisto) as a
draft: done jobs are added as invoices of their own, combined when the
customer, billing unit and reference allow it, and their billable hours
are set per work type. Creating the material checks the jobs again,
marks the approved hours and billable expenses billed, forms invoice
lines with price and VAT snapshots and moves the jobs to "Lasku luotu".
Fixed price jobs bill their quoted amount once. Billed hours keep their
approval and billed expenses can no longer change. The Fennoa export
and monthly fee lines come later.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 13:08:24 +02:00

53 lines
1.5 KiB
PHP

<?php
namespace App\Modules\Billing\Presentation\Livewire\Concerns;
use App\Modules\Billing\Domain\Enums\BillingMode;
use App\Modules\Billing\Domain\Enums\NotBillableReason;
use App\Modules\Shared\Domain\ValueObjects\Money;
use App\Modules\Shared\Domain\ValueObjects\VatPercentage;
use Carbon\CarbonImmutable;
use DateTimeInterface;
/**
* Formatting shared by the billing pages.
*/
trait FormatsBilling
{
public function money(int $cents): string
{
return ($cents < 0 ? '-' : '').Money::fromCents(abs($cents))->format();
}
public function vatRate(int $basisPoints): string
{
return (new VatPercentage($basisPoints))->format();
}
public function hours(int $quarters): string
{
return rtrim(rtrim(number_format($quarters / 4, 2, ',', ''), '0'), ',');
}
/**
* E.g. "24.11.2026 klo 14.05" in the business time zone.
*/
public function timeLabel(DateTimeInterface $at): string
{
return CarbonImmutable::instance($at)->setTimezone((string) config('app.business_timezone'))->format('j.n.Y \k\l\o H.i');
}
public function modeLabel(?BillingMode $mode): string
{
return __('billing.modes.'.($mode->value ?? 'none'));
}
/**
* @param list<string> $missingRateNames
*/
public function reasonText(NotBillableReason $reason, array $missingRateNames = []): string
{
return __('billing.reasons.'.$reason->value, ['names' => implode(', ', $missingRateNames)]);
}
}