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:
@@ -10,6 +10,7 @@ use App\Modules\Billing\Application\Contracts\BillingJobs;
|
||||
use App\Modules\Billing\Application\DTOs\BillableExpense;
|
||||
use App\Modules\Billing\Application\Services\BillingSnapshot;
|
||||
use App\Modules\Billing\Domain\Contracts\BillingExportRepository;
|
||||
use App\Modules\Billing\Domain\Enums\BillingMode;
|
||||
use App\Modules\Billing\Domain\Enums\NotBillableReason;
|
||||
use App\Modules\Billing\Domain\Exceptions\BillingExportNotFound;
|
||||
use App\Modules\Billing\Domain\Exceptions\ExportEmpty;
|
||||
@@ -22,7 +23,8 @@ use App\Modules\Users\Application\Contracts\Clock;
|
||||
* Creates the billing material from its draft (spec 12), all or nothing:
|
||||
* checks every job again, marks the approved hours and billable expenses
|
||||
* billed, forms the invoice lines from what was marked with the current
|
||||
* prices, and moves the jobs to "Lasku luotu".
|
||||
* prices, and moves the jobs to "Lasku luotu". Monthly fee jobs keep
|
||||
* running, so their status stays.
|
||||
*/
|
||||
final class FinalizeBillingExport
|
||||
{
|
||||
@@ -50,7 +52,7 @@ final class FinalizeBillingExport
|
||||
$export = $this->exports->findById($exportId, lock: true) ?? throw new BillingExportNotFound($exportId);
|
||||
$export->ensureDraft();
|
||||
|
||||
$snapshot = $this->snapshots->load($export->jobIds());
|
||||
$snapshot = $this->snapshots->load($export->period(), $export->jobIds());
|
||||
|
||||
foreach ($export->jobIds() as $jobId) {
|
||||
$job = $snapshot->jobs[$jobId] ?? throw new JobNotBillable($jobId, NotBillableReason::WrongStatus);
|
||||
@@ -72,8 +74,11 @@ final class FinalizeBillingExport
|
||||
fn (BillableExpense $expense): bool => isset($billedExpenseIds[$expense->id]),
|
||||
));
|
||||
|
||||
$linesByJob[$job->id] = $snapshot->rules->lines($job, $draftJob, $billedHours, $billedExpenses, $snapshot->isFixedPriceBilled($job->id), $snapshot->rates, $snapshot->vatBasisPoints);
|
||||
$this->jobs->markInvoiced($job->id, $actorUserId);
|
||||
$linesByJob[$job->id] = $snapshot->linesOf($job, $draftJob, $billedHours, $billedExpenses);
|
||||
|
||||
if ($job->mode !== BillingMode::MonthlyFee) {
|
||||
$this->jobs->markInvoiced($job->id, $actorUserId);
|
||||
}
|
||||
}
|
||||
|
||||
$export->finalize($linesByJob, $actorUserId, $this->clock->now());
|
||||
|
||||
Reference in New Issue
Block a user