Add the quoted amount and completion time to customer jobs
- Jobs get a budget / quoted amount (cents, VAT 0). Only users who may see quotes see and edit it on the job form and page, and only they see its changes in the history. Others' saves keep the stored amount: the server decides whether the amount is set, not the browser. - Jobs record when they were done: set when a job first reaches a status that locks its hours, kept through the billing statuses, cleared when management opens the lock. The billing export will use it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -8,10 +8,13 @@ use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\FieldChange;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
|
||||
use DateTimeImmutable;
|
||||
|
||||
/**
|
||||
* A customer job (asiakastyö): the work done for a customer, which tasks,
|
||||
* time entries and invoices are attached to.
|
||||
* time entries and invoices are attached to. It knows when it was done:
|
||||
* reaching a status that locks hours sets the time, and opening the lock
|
||||
* clears it.
|
||||
*/
|
||||
final class CustomerJob
|
||||
{
|
||||
@@ -20,6 +23,7 @@ final class CustomerJob
|
||||
private JobNumber $number,
|
||||
private JobDetails $details,
|
||||
private int $createdBy,
|
||||
private ?DateTimeImmutable $completedAt = null,
|
||||
) {}
|
||||
|
||||
public static function open(JobNumber $number, JobDetails $details, int $createdBy): self
|
||||
@@ -27,9 +31,30 @@ final class CustomerJob
|
||||
return new self(null, $number, $details, $createdBy);
|
||||
}
|
||||
|
||||
public static function reconstitute(int $id, JobNumber $number, JobDetails $details, int $createdBy): self
|
||||
public static function reconstitute(int $id, JobNumber $number, JobDetails $details, int $createdBy, ?DateTimeImmutable $completedAt = null): self
|
||||
{
|
||||
return new self($id, $number, $details, $createdBy);
|
||||
return new self($id, $number, $details, $createdBy, $completedAt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps the completion time in step with the status: set when the job
|
||||
* first reaches a locking status, kept while it stays locked, cleared
|
||||
* when the lock is opened.
|
||||
*/
|
||||
public function recordCompletion(DateTimeImmutable $now): void
|
||||
{
|
||||
if (! $this->details->status->locksTime()) {
|
||||
$this->completedAt = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->completedAt ??= $now;
|
||||
}
|
||||
|
||||
public function completedAt(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->completedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user