Files
petriandClaude Opus 5.5 f4b58f6b1d Darken the dark canvas, add customer colours, the ongoing status and the board model
- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 /
  primary-100 and TallStackUI's dark labels, hints and checkbox labels are
  lightened so everything stays at 4.5:1.
- Shared HexColor picks white or black text by the higher WCAG contrast; a
  native-dialog colour picker and a large work dialog component.
- Customers get a header colour (customers.header_color), set on the
  customer page.
- New job status Jatkuvat / Kausi (ongoing): open, never late, billed
  monthly like running jobs.
- Kanban model: board columns and views, urgent threshold, per-user board
  preferences (density, column colours and sort), card positions, tasks of
  continuing jobs pinned to the board, MoveBoardCard and board queries with
  logged hours from TimeTracking.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 06:11:49 +02:00

136 lines
5.9 KiB
PHP

<?php
use App\Modules\Jobs\Domain\Entities\CustomerJob;
use App\Modules\Jobs\Domain\Enums\JobKind;
use App\Modules\Jobs\Domain\Enums\JobStatus;
use App\Modules\Jobs\Domain\Enums\Priority;
use App\Modules\Jobs\Domain\Exceptions\DueBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
use App\Modules\Jobs\Domain\Exceptions\InvalidJobLink;
use App\Modules\Jobs\Domain\Exceptions\InvalidTag;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
use App\Modules\Jobs\Domain\ValueObjects\EstimatedHours;
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
use App\Modules\Jobs\Domain\ValueObjects\JobLink;
use App\Modules\Jobs\Domain\ValueObjects\JobName;
use App\Modules\Jobs\Domain\ValueObjects\JobNumber;
use App\Modules\Jobs\Domain\ValueObjects\Tag;
use App\Modules\Shared\Domain\ValueObjects\Money;
/**
* @param array<string, mixed> $overrides
*/
function jobDetails(array $overrides = []): JobDetails
{
return new JobDetails(...array_merge([
'name' => new JobName('Messuvideo'),
'description' => null,
'customerId' => 1,
'serviceUnitIds' => [1],
'startsOn' => null,
'dueOn' => null,
'plannedFrom' => null,
'plannedTo' => null,
'kind' => JobKind::OneOff,
'status' => JobStatus::Tentative,
'priority' => Priority::Normal,
'paymentBasis' => null,
'estimatedHours' => null,
'customerReference' => null,
'instructions' => null,
'responsibleUserId' => 10,
'contactUserId' => null,
'customerContactId' => null,
'billerUserId' => null,
'billingUnitId' => null,
'memberUserIds' => [],
'tags' => [],
'links' => [],
], $overrides));
}
it('formats and parses job numbers', function () {
expect((new JobNumber(2026, 42))->format())->toBe('2026-0042')
->and(JobNumber::fromString('2027-0001')->sequence)->toBe(1);
});
it('accepts estimated hours in quarters only', function () {
expect(EstimatedHours::fromString('7,25')->format())->toBe('7.25')
->and(EstimatedHours::fromString('8')->format())->toBe('8')
->and(fn () => EstimatedHours::fromString('1.1'))->toThrow(InvalidEstimatedHours::class)
->and(fn () => new EstimatedHours(-1))->toThrow(InvalidEstimatedHours::class);
});
it('accepts only http and https links with a title', function () {
expect((new JobLink(' Briiffi ', 'https://drive.example.test/x'))->title)->toBe('Briiffi')
->and(fn () => new JobLink('Tiedosto', 'javascript:alert(1)'))->toThrow(InvalidJobLink::class)
->and(fn () => new JobLink('', 'https://example.test'))->toThrow(InvalidJobLink::class)
->and(fn () => new Tag(str_repeat('a', 51)))->toThrow(InvalidTag::class);
});
it('checks the dates and service units of a job', function (array $overrides, string $exception) {
expect(fn () => jobDetails($overrides))->toThrow($exception);
})->with([
'due before start' => [['startsOn' => new DateTimeImmutable('2026-05-10'), 'dueOn' => new DateTimeImmutable('2026-05-09')], DueBeforeStart::class],
'plan ends before start' => [['plannedFrom' => new DateTimeImmutable('2026-05-10'), 'plannedTo' => new DateTimeImmutable('2026-05-01')], PlanEndsBeforeStart::class],
'no service unit' => [['serviceUnitIds' => []], ServiceUnitRequired::class],
]);
it('removes duplicate tags ignoring case, and sorts ids', function () {
$details = jobDetails(['tags' => [new Tag('Messut'), new Tag('messut'), new Tag('video')], 'memberUserIds' => [3, 1, 3]]);
expect(array_map(fn (Tag $tag) => $tag->value, $details->tags))->toBe(['Messut', 'video'])
->and($details->memberUserIds)->toBe([1, 3])
->and($details->involves(3))->toBeTrue()
->and($details->involves(99))->toBeFalse();
});
it('returns only the fields that changed', function () {
$job = CustomerJob::open(new JobNumber(2026, 1), jobDetails(), 10);
$changes = $job->changeDetails(jobDetails(['priority' => Priority::Urgent, 'tags' => [new Tag('messut')]]));
expect(array_map(fn ($change) => [$change->field, $change->oldValue, $change->newValue], $changes))->toBe([
['priority', 'normal', 'urgent'],
['tags', null, 'messut'],
])
->and($job->changeStatus(JobStatus::Tentative))->toBe([])
->and(JobStatus::kanbanStatuses())->not->toContain(JobStatus::Archived);
});
it('keeps an ongoing job open with tasks and on the Kanban board', function () {
expect(JobStatus::Ongoing->locksTime())->toBeFalse()
->and(JobStatus::Ongoing->isOpen())->toBeTrue()
->and(JobStatus::Ongoing->allowsTasks())->toBeTrue()
->and(JobStatus::Ongoing->isBillingStatus())->toBeFalse()
->and(JobStatus::kanbanStatuses())->toContain(JobStatus::Ongoing)
->and(JobStatus::Billed->unlocksTo(JobStatus::Ongoing))->toBeTrue();
});
it('compares the quoted amount for the history', function () {
$job = CustomerJob::open(new JobNumber(2026, 1), jobDetails(), 10);
$changes = $job->changeDetails(jobDetails(['quotedAmount' => Money::fromCents(450000)]));
expect(array_map(fn ($change) => [$change->field, $change->oldValue, $change->newValue], $changes))->toBe([['quoted_amount', null, '450000']]);
});
it('records the completion time while the job is locked and clears it when opened', function () {
$job = CustomerJob::open(new JobNumber(2026, 1), jobDetails(), 10);
$done = new DateTimeImmutable('2026-11-20 10:00');
$job->recordCompletion($done);
expect($job->completedAt())->toBeNull();
$job->changeStatus(JobStatus::Done);
$job->recordCompletion($done);
$job->changeStatus(JobStatus::Billed);
$job->recordCompletion(new DateTimeImmutable('2026-12-01'));
expect($job->completedAt())->toEqual($done);
$job->changeStatus(JobStatus::InProduction);
$job->recordCompletion(new DateTimeImmutable('2026-12-02'));
expect($job->completedAt())->toBeNull();
});