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
@@ -25,4 +25,12 @@ interface ExpenseQueries
public function forUserInMonth(int $userId, string $month): array;
public function find(int $id): ?ExpenseSummary;
/**
* The jobs' billable expenses that are not billed yet, oldest first.
*
* @param list<int> $jobIds
* @return list<ExpenseSummary>
*/
public function unbilledBillable(array $jobIds): array;
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Modules\Expenses\Application\UseCases;
use App\Modules\Expenses\Domain\Contracts\ExpenseRepository;
use App\Modules\Shared\Application\Contracts\TransactionManager;
/**
* Marks a job's billable, unbilled expenses billed on a billing material,
* so they are never billed twice and can no longer be changed. The caller
* (billing) checks who may do this.
*/
final class MarkJobExpensesBilled
{
public function __construct(
private ExpenseRepository $expenses,
private TransactionManager $transactions,
) {}
/**
* @return list<int> Ids of the expenses marked billed.
*/
public function execute(int $jobId, int $billingExportId): array
{
return $this->transactions->run(fn (): array => $this->expenses->markBillableAsBilled($jobId, $billingExportId));
}
}
@@ -30,7 +30,7 @@ final class RemoveExpense
$this->transactions->run(function () use ($expenseId): void {
$expense = $this->expenses->findById($expenseId) ?? throw new ExpenseNotFound($expenseId);
if ($this->jobs->find($expense->jobId())->isLocked ?? true) {
if ($expense->isBilled() || ($this->jobs->find($expense->jobId())->isLocked ?? true)) {
throw new ExpenseLocked;
}
@@ -36,7 +36,7 @@ final class UpdateExpense
$this->transactions->run(function () use ($expenseId, $data, $details): void {
$expense = $this->expenses->findById($expenseId) ?? throw new ExpenseNotFound($expenseId);
if ($this->jobs->find($expense->jobId())->isLocked ?? true) {
if ($expense->isBilled() || ($this->jobs->find($expense->jobId())->isLocked ?? true)) {
throw new ExpenseLocked;
}