Kanban / timesheet update

This commit is contained in:
2026-11-30 06:56:14 +02:00
parent 6332ff0fa9
commit a4dbe8ce09
46 changed files with 8091 additions and 331 deletions
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Modules\TimeTracking\Domain\Contracts;
use DateTimeImmutable;
/**
* Tasks each user has pinned to the "Lukitut työt" part of their time sheet.
*/
interface PinnedTaskRepository
{
public function pin(int $userId, int $taskId, DateTimeImmutable $at): void;
public function unpin(int $userId, int $taskId): void;
/**
* @return int how many pins were removed
*/
public function unpinAll(int $userId): int;
/**
* @return list<int>
*/
public function pinnedTaskIds(int $userId): array;
}
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Modules\TimeTracking\Domain\Entities;
use App\Modules\TimeTracking\Domain\Enums\EntryBillingModel;
use App\Modules\TimeTracking\Domain\Exceptions\TimeApproved;
use App\Modules\TimeTracking\Domain\ValueObjects\WorkedHours;
use DateTimeImmutable;
@@ -28,6 +29,8 @@ final class TimeEntry
private ?int $approvedBy = null,
private ?DateTimeImmutable $approvedAt = null,
private ?int $billingExportId = null,
private ?EntryBillingModel $billingModel = null,
private ?string $internalComment = null,
) {}
public static function create(int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note = null): self
@@ -35,9 +38,39 @@ final class TimeEntry
return new self(null, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, self::text($note));
}
public static function reconstitute(int $id, int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note, ?int $approvedBy = null, ?DateTimeImmutable $approvedAt = null, ?int $billingExportId = null): self
public static function reconstitute(int $id, int $userId, int $taskId, int $jobId, int $workTypeId, DateTimeImmutable $workedOn, WorkedHours $hours, ?string $note, ?int $approvedBy = null, ?DateTimeImmutable $approvedAt = null, ?int $billingExportId = null, ?EntryBillingModel $billingModel = null, ?string $internalComment = null): self
{
return new self($id, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, $note, $approvedBy, $approvedAt, $billingExportId);
return new self($id, $userId, $taskId, $jobId, $workTypeId, $workedOn, $hours, $note, $approvedBy, $approvedAt, $billingExportId, $billingModel, $internalComment);
}
/**
* The entry's laskutusperuste, billing note (shown to the customer or in
* fixed-price follow-up, required before the week is approved) and
* internal comment. A null billing model follows the job.
*
* @throws TimeApproved
*/
public function describe(?EntryBillingModel $billingModel, ?string $billingNote, ?string $internalComment): void
{
$this->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;
}
/**
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\Modules\TimeTracking\Domain\Enums;
/**
* Laskutusperuste of a time entry (docs/ui-timesheet.md 5.2): within a
* fixed price (K), billed by the hour (€) or not billable (•). It is
* tracking only: billing still follows the job's payment basis.
*/
enum EntryBillingModel: string
{
case Fixed = 'fixed';
case Hourly = 'hourly';
case NonBillable = 'non_billable';
/**
* The default of an entry, from its job's payment basis (a Jobs
* PaymentBasis value).
*/
public static function forPaymentBasis(?string $paymentBasis): self
{
return match ($paymentBasis) {
'fixed_quote', 'price_list', 'monthly_fee' => self::Fixed,
'not_billable' => self::NonBillable,
default => self::Hourly,
};
}
public function symbol(): string
{
return match ($this) {
self::Fixed => 'K',
self::Hourly => '€',
self::NonBillable => '•',
};
}
/**
* Billed or within a fixed price, against internal work.
*/
public function isBillable(): bool
{
return $this !== self::NonBillable;
}
}
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace App\Modules\TimeTracking\Domain\Exceptions;
use App\Modules\Shared\Domain\Exceptions\DomainException;
/**
* A week cannot be approved while any of its entries lacks a billing note
* (docs/ui-timesheet.md 6).
*/
final class BillingNotesMissing extends DomainException
{
/**
* @param list<int> $entryIds
*/
public function __construct(public readonly array $entryIds)
{
parent::__construct(count($entryIds).' time entries have no billing note.');
}
}
@@ -51,6 +51,47 @@ final readonly class WorkedHours
return new self((int) round($quarters));
}
/**
* Parses what the time sheet's cell accepts (docs/ui-timesheet.md 5.1):
* "1:30" (hours and minutes), "1,5" or "1.5" (hours), a whole number up
* to 24 as hours ("2") and above it as minutes ("90"). Null for an empty
* value or zero. Always whole quarter hours.
*
* @throws InvalidWorkedHours
*/
public static function parseFlexible(string $value): ?self
{
$value = trim($value);
if ($value === '' || preg_match('/^0+([:.,]0+)?$/', $value) === 1) {
return null;
}
if (preg_match('/^(\d{1,2}):([0-5]\d)$/', $value, $matches) === 1) {
$minutes = (int) $matches[1] * 60 + (int) $matches[2];
} elseif (preg_match('/^\d+$/', $value) === 1 && (int) $value > 24) {
$minutes = (int) $value;
} else {
return self::parse($value);
}
if ($minutes % 15 !== 0) {
throw new InvalidWorkedHours;
}
return new self(intdiv($minutes, 15));
}
/**
* Hours and minutes, "1:30" or "0:00".
*/
public static function formatClock(int $quarters): string
{
$minutes = $quarters * 15;
return intdiv($minutes, 60).':'.str_pad((string) ($minutes % 60), 2, '0', STR_PAD_LEFT);
}
public static function fromDecimal(float $hours): self
{
return new self((int) round($hours * 4));