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]>
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\TimeTracking\Application\UseCases;
|
|
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
use App\Modules\TimeTracking\Domain\Contracts\TimeEntryRepository;
|
|
|
|
/**
|
|
* Marks a job's approved, unbilled hours billed on a billing material, so
|
|
* they are never billed twice. Hours waiting for approval are left as they
|
|
* are. The caller (billing) checks who may do this.
|
|
*/
|
|
final class MarkJobHoursBilled
|
|
{
|
|
public function __construct(
|
|
private TimeEntryRepository $entries,
|
|
private TransactionManager $transactions,
|
|
) {}
|
|
|
|
/**
|
|
* @return array<int, int> The quarters marked billed, keyed by work type id.
|
|
*/
|
|
public function execute(int $jobId, int $billingExportId): array
|
|
{
|
|
return $this->transactions->run(function () use ($jobId, $billingExportId): array {
|
|
$quarters = [];
|
|
|
|
foreach ($this->entries->approvedUnbilledForJob($jobId) as $entry) {
|
|
$entry->markBilled($billingExportId);
|
|
$this->entries->save($entry);
|
|
$quarters[$entry->workTypeId()] = ($quarters[$entry->workTypeId()] ?? 0) + $entry->hours()->quarters;
|
|
}
|
|
|
|
return $quarters;
|
|
});
|
|
}
|
|
}
|