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]>
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
use App\Modules\Expenses\Domain\Contracts\ExpenseRepository;
|
|
use App\Modules\Expenses\Domain\Entities\Expense;
|
|
|
|
class InMemoryExpenseRepository implements ExpenseRepository
|
|
{
|
|
/** @var array<int, Expense> */
|
|
public array $items = [];
|
|
|
|
private int $nextId = 1;
|
|
|
|
public function findById(int $id): ?Expense
|
|
{
|
|
return isset($this->items[$id]) ? clone $this->items[$id] : null;
|
|
}
|
|
|
|
public function save(Expense $expense): Expense
|
|
{
|
|
$id = $expense->id() ?? $this->nextId++;
|
|
$this->items[$id] = Expense::reconstitute($id, $expense->jobId(), $expense->userId(), $expense->recordedBy(), $expense->details(), $expense->billingExportId());
|
|
|
|
return clone $this->items[$id];
|
|
}
|
|
|
|
public function delete(Expense $expense): void
|
|
{
|
|
unset($this->items[$expense->id()]);
|
|
}
|
|
|
|
public function markBillableAsBilled(int $jobId, int $billingExportId): array
|
|
{
|
|
$ids = [];
|
|
|
|
foreach ($this->items as $id => $expense) {
|
|
if ($expense->jobId() === $jobId && $expense->details()->isBillable() && ! $expense->isBilled()) {
|
|
$this->items[$id] = Expense::reconstitute($id, $expense->jobId(), $expense->userId(), $expense->recordedBy(), $expense->details(), $billingExportId);
|
|
$ids[] = $id;
|
|
}
|
|
}
|
|
|
|
return $ids;
|
|
}
|
|
}
|