Add monthly fee billing lines to the billing material
Jobs billed by a fixed monthly fee get a monthly fee field, kept behind the quotes permission like the quoted amount. A billing material now has a billing month: a new draft adds every monthly fee job with something to bill, each on an invoice of its own, and bills one line for every unbilled month from the job's start up to the billing month (or its end or completion), so skipped months are caught up and no month is billed twice. Their expenses are billed alongside, their hours are covered by the fee and marked billed, and the job keeps running. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -8,9 +8,11 @@ use App\Modules\Billing\Domain\Enums\ExportStatus;
|
||||
use App\Modules\Billing\Domain\Exceptions\ExportEmpty;
|
||||
use App\Modules\Billing\Domain\Exceptions\ExportNotDraft;
|
||||
use App\Modules\Billing\Domain\Exceptions\InvalidBillableHours;
|
||||
use App\Modules\Billing\Domain\Exceptions\InvalidBillingPeriod;
|
||||
use App\Modules\Billing\Domain\Exceptions\InvoicesCannotMerge;
|
||||
use App\Modules\Billing\Domain\Exceptions\JobAlreadyInDraft;
|
||||
use App\Modules\Billing\Domain\Exceptions\JobNotInDraft;
|
||||
use App\Modules\Billing\Domain\ValueObjects\BillingMonths;
|
||||
use App\Modules\Billing\Domain\ValueObjects\DraftJob;
|
||||
use App\Modules\Billing\Domain\ValueObjects\InvoiceLine;
|
||||
use DateTimeImmutable;
|
||||
@@ -29,6 +31,7 @@ final class BillingExport
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private ExportStatus $status,
|
||||
private string $period,
|
||||
private int $createdBy,
|
||||
private DateTimeImmutable $createdAt,
|
||||
private ?int $finalizedBy,
|
||||
@@ -36,17 +39,37 @@ final class BillingExport
|
||||
private array $invoices,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* A new draft billing monthly fees up to the current month.
|
||||
*/
|
||||
public static function startDraft(int $createdBy, DateTimeImmutable $now): self
|
||||
{
|
||||
return new self(null, ExportStatus::Draft, $createdBy, $now, null, null, []);
|
||||
return new self(null, ExportStatus::Draft, $now->format('Y-m'), $createdBy, $now, null, null, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<BillingInvoice> $invoices
|
||||
*/
|
||||
public static function reconstitute(int $id, ExportStatus $status, int $createdBy, DateTimeImmutable $createdAt, ?int $finalizedBy, ?DateTimeImmutable $finalizedAt, array $invoices): self
|
||||
public static function reconstitute(int $id, ExportStatus $status, string $period, int $createdBy, DateTimeImmutable $createdAt, ?int $finalizedBy, ?DateTimeImmutable $finalizedAt, array $invoices): self
|
||||
{
|
||||
return new self($id, $status, $createdBy, $createdAt, $finalizedBy, $finalizedAt, $invoices);
|
||||
return new self($id, $status, $period, $createdBy, $createdAt, $finalizedBy, $finalizedAt, $invoices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the month (Y-m) up to which monthly fees are billed.
|
||||
*
|
||||
* @throws ExportNotDraft
|
||||
* @throws InvalidBillingPeriod
|
||||
*/
|
||||
public function changePeriod(string $period): void
|
||||
{
|
||||
$this->ensureDraft();
|
||||
$this->period = BillingMonths::ensureValid($period);
|
||||
}
|
||||
|
||||
public function period(): string
|
||||
{
|
||||
return $this->period;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user