Add the billing material with drafts, combined invoices and billed marks
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]>
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Modules\TimeTracking\Application\Contracts;
|
||||
|
||||
use App\Modules\TimeTracking\Application\DTOs\ApprovalWeek;
|
||||
use App\Modules\TimeTracking\Application\DTOs\JobBillingHours;
|
||||
use App\Modules\TimeTracking\Application\DTOs\TimeEntrySummary;
|
||||
use App\Modules\TimeTracking\Application\DTOs\WeekSheet;
|
||||
|
||||
@@ -41,4 +42,14 @@ interface TimeEntryQueries
|
||||
* @return list<ApprovalWeek>
|
||||
*/
|
||||
public function approvedWeeks(string $sinceMonday): array;
|
||||
|
||||
/**
|
||||
* Unbilled hours of the jobs for billing: approved hours by work type,
|
||||
* and the hours still waiting for approval. Keyed by job id; every job
|
||||
* asked for is included.
|
||||
*
|
||||
* @param list<int> $jobIds
|
||||
* @return array<int, JobBillingHours>
|
||||
*/
|
||||
public function billingHours(array $jobIds): array;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\TimeTracking\Application\DTOs;
|
||||
|
||||
/**
|
||||
* A job's unbilled hours for billing, in quarters of an hour.
|
||||
*/
|
||||
final readonly class JobBillingHours
|
||||
{
|
||||
/**
|
||||
* @param array<int, int> $approvedQuartersByWorkType Approved, unbilled hours keyed by work type id.
|
||||
* @param int $unapprovedQuarters Hours still waiting for approval.
|
||||
*/
|
||||
public function __construct(
|
||||
public int $jobId,
|
||||
public array $approvedQuartersByWorkType,
|
||||
public int $unapprovedQuarters,
|
||||
) {}
|
||||
}
|
||||
@@ -10,7 +10,8 @@ use App\Modules\TimeTracking\Domain\Contracts\TimeEntryRepository;
|
||||
|
||||
/**
|
||||
* Cancels the approval of a user's week so the hours can be corrected.
|
||||
* Only management may do this; the caller checks it.
|
||||
* Billed hours keep their approval. Only management may do this; the
|
||||
* caller checks it.
|
||||
*/
|
||||
final class CancelWeekApproval
|
||||
{
|
||||
@@ -31,7 +32,7 @@ final class CancelWeekApproval
|
||||
$cancelled = 0;
|
||||
|
||||
foreach ($this->entries->forUserBetween($userId, $start, $start->modify('+6 days')) as $entry) {
|
||||
if (! $entry->isApproved()) {
|
||||
if (! $entry->isApproved() || $entry->isBilled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user