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]>
76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Expenses\Domain\Entities;
|
|
|
|
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. A billed expense (on a
|
|
* billing material) can no longer be changed or removed.
|
|
*/
|
|
final class Expense
|
|
{
|
|
private function __construct(
|
|
private ?int $id,
|
|
private int $jobId,
|
|
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
|
|
{
|
|
return new self(null, $jobId, $userId, $recordedBy, $details);
|
|
}
|
|
|
|
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, $billingExportId);
|
|
}
|
|
|
|
public function isBilled(): bool
|
|
{
|
|
return $this->billingExportId !== null;
|
|
}
|
|
|
|
public function billingExportId(): ?int
|
|
{
|
|
return $this->billingExportId;
|
|
}
|
|
|
|
public function change(int $userId, ExpenseDetails $details): void
|
|
{
|
|
$this->userId = $userId;
|
|
$this->details = $details;
|
|
}
|
|
|
|
public function id(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function jobId(): int
|
|
{
|
|
return $this->jobId;
|
|
}
|
|
|
|
public function userId(): int
|
|
{
|
|
return $this->userId;
|
|
}
|
|
|
|
public function recordedBy(): int
|
|
{
|
|
return $this->recordedBy;
|
|
}
|
|
|
|
public function details(): ExpenseDetails
|
|
{
|
|
return $this->details;
|
|
}
|
|
}
|