Files
Toiminnanohjaus/app/Modules/Billing/Domain/ValueObjects/InvoiceLine.php
T
petriandClaude Opus 5.5 5f9423a3c3 Add monthly fee billing lines to the billing material
Jobs billed by a fixed monthly fee get a monthly fee field, kept behind
the quotes permission like the quoted amount. A billing material now has
a billing month: a new draft adds every monthly fee job with something
to bill, each on an invoice of its own, and bills one line for every
unbilled month from the job's start up to the billing month (or its end
or completion), so skipped months are caught up and no month is billed
twice. Their expenses are billed alongside, their hours are covered by
the fee and marked billed, and the job keeps running.

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

68 lines
2.3 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
declare(strict_types=1);
namespace App\Modules\Billing\Domain\ValueObjects;
use App\Modules\Billing\Domain\Enums\LineKind;
/**
* A line of an invoice, without VAT: a work type's billable hours at its
* hourly rate, a job's fixed price, a month's fee, or an expense. Prices and descriptions
* are snapshots taken when the material is formed.
*/
final readonly class InvoiceLine
{
public function __construct(
public int $jobId,
public LineKind $kind,
public ?int $workTypeId,
public ?int $expenseId,
public string $description,
public ?int $recordedQuarters,
public ?int $quantityQuarters,
public int $unitPriceCents,
public int $vatBasisPoints,
public int $netCents,
public ?string $period = null,
) {}
/**
* Billable hours × the hourly rate, rounded half up to the cent. The
* approved (recorded) hours are kept beside them for reports.
*/
public static function hours(int $jobId, int $workTypeId, string $workTypeName, int $recordedQuarters, int $billableQuarters, int $hourlyRateCents, int $vatBasisPoints): self
{
return new self(
$jobId,
LineKind::Hours,
$workTypeId,
null,
$workTypeName,
$recordedQuarters,
$billableQuarters,
$hourlyRateCents,
$vatBasisPoints,
intdiv($billableQuarters * $hourlyRateCents * 2 + 4, 8),
);
}
public static function fixedPrice(int $jobId, string $description, int $amountCents, int $vatBasisPoints): self
{
return new self($jobId, LineKind::FixedPrice, null, null, $description, null, null, $amountCents, $vatBasisPoints, $amountCents);
}
/**
* The fee of one month (Y-m).
*/
public static function monthlyFee(int $jobId, string $period, string $description, int $amountCents, int $vatBasisPoints): self
{
return new self($jobId, LineKind::MonthlyFee, null, null, $description, null, null, $amountCents, $vatBasisPoints, $amountCents, $period);
}
public static function expense(int $jobId, int $expenseId, string $description, int $amountCents, int $vatBasisPoints): self
{
return new self($jobId, LineKind::Expense, null, $expenseId, $description, null, null, $amountCents, $vatBasisPoints, $amountCents);
}
}