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]>
This commit is contained in:
2026-11-24 13:08:24 +02:00
co-authored by Claude Opus 5.5
parent 6de5d9bef1
commit 97bd23bed5
98 changed files with 4887 additions and 22 deletions
@@ -16,4 +16,11 @@ interface ExpenseRepository
public function save(Expense $expense): Expense;
public function delete(Expense $expense): void;
/**
* Marks the job's billable, unbilled expenses billed on a billing material.
*
* @return list<int> Ids of the expenses marked.
*/
public function markBillableAsBilled(int $jobId, int $billingExportId): array;
}
@@ -8,7 +8,8 @@ use App\Modules\Expenses\Domain\ValueObjects\ExpenseDetails;
/**
* An expense on a customer job: whose it is, who recorded it (management
* records subcontractors' expenses) and what it is.
* records subcontractors' expenses) and what it is. A billed expense (on a
* billing material) can no longer be changed or removed.
*/
final class Expense
{
@@ -18,6 +19,7 @@ final class Expense
private int $userId,
private int $recordedBy,
private ExpenseDetails $details,
private ?int $billingExportId = null,
) {}
public static function record(int $jobId, int $userId, int $recordedBy, ExpenseDetails $details): self
@@ -25,9 +27,19 @@ final class Expense
return new self(null, $jobId, $userId, $recordedBy, $details);
}
public static function reconstitute(int $id, int $jobId, int $userId, int $recordedBy, ExpenseDetails $details): self
public static function reconstitute(int $id, int $jobId, int $userId, int $recordedBy, ExpenseDetails $details, ?int $billingExportId = null): self
{
return new self($id, $jobId, $userId, $recordedBy, $details);
return new self($id, $jobId, $userId, $recordedBy, $details, $billingExportId);
}
public function isBilled(): bool
{
return $this->billingExportId !== null;
}
public function billingExportId(): ?int
{
return $this->billingExportId;
}
public function change(int $userId, ExpenseDetails $details): void