ensureNotApproved(); $this->billingModel = $billingModel; $this->note = self::text($billingNote); $this->internalComment = self::text($internalComment); } public function hasBillingNote(): bool { return $this->note !== null; } public function billingModel(): ?EntryBillingModel { return $this->billingModel; } public function internalComment(): ?string { return $this->internalComment; } /** * @throws TimeApproved */ public function changeHours(WorkedHours $hours, ?string $note): void { $this->ensureNotApproved(); $this->hours = $hours; $this->note = self::text($note); } /** * Adds more hours to the day's entry; a new note continues the old one. */ public function addHours(WorkedHours $hours, ?string $note): void { $this->ensureNotApproved(); $this->hours = $this->hours->plus($hours); $note = self::text($note); if ($note !== null) { $this->note = $this->note === null ? $note : $this->note."\n".$note; } } /** * Approves the entry; an approved entry keeps its first approval. */ public function approve(int $approvedBy, DateTimeImmutable $approvedAt): void { if ($this->isApproved()) { return; } $this->approvedBy = $approvedBy; $this->approvedAt = $approvedAt; } /** * Cancels the approval, unless the hours are billed. */ public function cancelApproval(): void { if ($this->isBilled()) { return; } $this->approvedBy = null; $this->approvedAt = null; } /** * Marks approved hours billed on the given billing material. */ public function markBilled(int $billingExportId): void { if ($this->isApproved() && ! $this->isBilled()) { $this->billingExportId = $billingExportId; } } public function isBilled(): bool { return $this->billingExportId !== null; } public function billingExportId(): ?int { return $this->billingExportId; } public function isApproved(): bool { return $this->approvedAt !== null; } /** * @throws TimeApproved */ public function ensureNotApproved(): void { if ($this->isApproved()) { throw new TimeApproved; } } public function approvedBy(): ?int { return $this->approvedBy; } public function approvedAt(): ?DateTimeImmutable { return $this->approvedAt; } public function id(): ?int { return $this->id; } public function userId(): int { return $this->userId; } public function taskId(): int { return $this->taskId; } public function jobId(): int { return $this->jobId; } public function workTypeId(): int { return $this->workTypeId; } public function workedOn(): DateTimeImmutable { return $this->workedOn; } public function hours(): WorkedHours { return $this->hours; } public function note(): ?string { return $this->note; } private static function text(?string $value): ?string { $value = $value === null ? '' : trim($value); return $value === '' ? null : $value; } }