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]>
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?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, 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,
|
||
) {}
|
||
|
||
/**
|
||
* 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);
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|