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:
@@ -50,6 +50,14 @@ interface CustomerJobQueries
|
||||
*/
|
||||
public function billingInfoWithStatus(JobStatus $status): array;
|
||||
|
||||
/**
|
||||
* Billing details of the jobs billed by a monthly fee that may be
|
||||
* billed now (ordered, in production, on hold or done), by job number.
|
||||
*
|
||||
* @return list<JobBillingInfo>
|
||||
*/
|
||||
public function billingInfoMonthly(): array;
|
||||
|
||||
/**
|
||||
* Billing details of the given jobs, keyed by id; unknown ids are left out.
|
||||
*
|
||||
|
||||
@@ -42,5 +42,6 @@ final readonly class CustomerJobData
|
||||
public array $links = [],
|
||||
public ?string $quotedAmount = null,
|
||||
public bool $setsQuotedAmount = false,
|
||||
public ?string $monthlyFee = null,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ final readonly class CustomerJobDetails
|
||||
public string $createdAt,
|
||||
public string $createdByName,
|
||||
public ?int $quotedAmountCents = null,
|
||||
public ?int $monthlyFeeCents = null,
|
||||
public ?string $completedAt = null,
|
||||
) {}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
||||
|
||||
/**
|
||||
* A customer job as billing sees it: who is billed, under which billing
|
||||
* unit and reference, and how (payment basis, quoted amount without VAT).
|
||||
* unit and reference, and how (payment basis, quoted amount and monthly
|
||||
* fee without VAT), and for monthly fees the months it runs.
|
||||
*/
|
||||
final readonly class JobBillingInfo
|
||||
{
|
||||
@@ -25,5 +26,10 @@ final readonly class JobBillingInfo
|
||||
public ?string $customerReference,
|
||||
public ?int $billingUnitId,
|
||||
public ?string $billingUnitName,
|
||||
public ?int $monthlyFeeCents = null,
|
||||
public ?string $startsOn = null,
|
||||
public ?string $dueOn = null,
|
||||
public ?string $completedOn = null,
|
||||
public string $createdOn = '',
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidJobReference;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidMonthlyFee;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\EstimatedHours;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\JobLink;
|
||||
@@ -73,9 +74,22 @@ final class JobDetailsFactory
|
||||
tags: array_map(fn (string $tag): Tag => new Tag($tag), $data->tags),
|
||||
links: array_map(fn (array $link): JobLink => new JobLink($link['title'], $link['url']), $data->links),
|
||||
quotedAmount: $data->setsQuotedAmount ? Money::parse((string) $data->quotedAmount) : $current?->quotedAmount,
|
||||
monthlyFee: $data->setsQuotedAmount ? self::monthlyFee($data->monthlyFee) : $current?->monthlyFee,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidMonthlyFee
|
||||
*/
|
||||
private static function monthlyFee(?string $value): ?Money
|
||||
{
|
||||
try {
|
||||
return Money::parse((string) $value);
|
||||
} catch (InvalidMoneyAmount) {
|
||||
throw new InvalidMonthlyFee;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkReferences(CustomerJobData $data, ?JobDetails $current): void
|
||||
{
|
||||
if ($this->customers->findSummary($data->customerId) === null) {
|
||||
|
||||
Reference in New Issue
Block a user