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:
@@ -22,6 +22,7 @@ beforeEach(function () {
|
||||
'priority' => 'immediate',
|
||||
'due_on' => now()->subDay()->toDateString(),
|
||||
'instructions' => 'Kuvaus klo 9.',
|
||||
'quoted_amount_cents' => 450000,
|
||||
]);
|
||||
DB::table('customer_job_links')->insert(['customer_job_id' => $this->job->id, 'title' => 'Briiffi', 'url' => 'https://drive.example.test/b', 'sort_order' => 1]);
|
||||
});
|
||||
|
||||
@@ -32,7 +32,7 @@ class InMemoryCustomerJobRepository implements CustomerJobRepository, JobNumberS
|
||||
public function save(CustomerJob $job): CustomerJob
|
||||
{
|
||||
$id = $job->id() ?? $this->nextId++;
|
||||
$this->jobs[$id] = CustomerJob::reconstitute($id, $job->number(), $job->details(), $job->createdBy());
|
||||
$this->jobs[$id] = CustomerJob::reconstitute($id, $job->number(), $job->details(), $job->createdBy(), $job->completedAt());
|
||||
|
||||
return clone $this->jobs[$id];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->job = CustomerJobModel::factory()->quoted(450000)->create(['name' => 'Messuvideo', 'status' => JobStatus::Order]);
|
||||
});
|
||||
|
||||
it('lets management set the quoted amount and see it with its history', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
|
||||
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||
->assertSet('form.quoted_amount', '4500,00')
|
||||
->set('form.quoted_amount', '5200,50')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($this->job->refresh()->quoted_amount_cents)->toBe(520050);
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))
|
||||
->assertSee('Budjetti / tarjoussumma')
|
||||
->assertSee("5\u{00A0}200,50\u{00A0}€", false)
|
||||
->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
||||
});
|
||||
|
||||
it('rejects an invalid quoted amount with a Finnish field error', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
|
||||
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||
->set('form.quoted_amount', '12,345')
|
||||
->call('save')
|
||||
->assertHasErrors(['form.quoted_amount' => [__('jobs.errors.invalid_amount')]]);
|
||||
});
|
||||
|
||||
it('hides the quoted amount from employees without the quotes permission and keeps it when they save', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.quoted_amount', '5000')->call('save');
|
||||
|
||||
$this->actingAs(User::factory()->employee()->create());
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))
|
||||
->assertOk()
|
||||
->assertDontSee('Budjetti / tarjoussumma')
|
||||
->assertDontSee("5\u{00A0}000,00\u{00A0}€", false);
|
||||
|
||||
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||
->assertSet('form.quoted_amount', '')
|
||||
->assertDontSee('Budjetti / tarjoussumma')
|
||||
->set('form.quoted_amount', '1')
|
||||
->set('form.name', 'Messuvideo 2')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($this->job->refresh()->quoted_amount_cents)->toBe(500000)
|
||||
->and($this->job->name)->toBe('Messuvideo 2');
|
||||
});
|
||||
|
||||
it('shows the quoted amount to an employee with the quotes permission', function () {
|
||||
$this->actingAs(User::factory()->employee()->withMoneyPermissions(MoneyPermission::Quotes)->create());
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee("4\u{00A0}500,00\u{00A0}€", false);
|
||||
|
||||
Livewire::test('jobs::form', ['job' => $this->job->id])
|
||||
->set('form.quoted_amount', '')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($this->job->refresh()->quoted_amount_cents)->toBeNull();
|
||||
});
|
||||
|
||||
it('records when a job is done and clears it when management opens the lock', function () {
|
||||
$this->actingAs(User::factory()->management()->create());
|
||||
|
||||
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'done');
|
||||
$completedAt = $this->job->refresh()->completed_at;
|
||||
|
||||
expect($completedAt)->not->toBeNull();
|
||||
|
||||
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'invoiced');
|
||||
expect($this->job->refresh()->completed_at?->equalTo($completedAt))->toBeTrue();
|
||||
|
||||
$this->get(route('jobs.show', $this->job->id))->assertSee('Valmistunut');
|
||||
|
||||
Livewire::test('jobs::board')->set('mine', false)->call('moveJob', $this->job->id, 'in_production');
|
||||
expect($this->job->refresh()->completed_at)->toBeNull();
|
||||
});
|
||||
@@ -34,8 +34,8 @@ beforeEach(function () {
|
||||
|
||||
$factory = new JobDetailsFactory($this->customers, $this->catalog, $this->users);
|
||||
$this->create = new CreateCustomerJob($this->jobs, $this->jobs, $factory, $transactions, $this->clock);
|
||||
$this->update = new UpdateCustomerJob($this->jobs, $factory, $transactions);
|
||||
$this->changeStatus = new ChangeJobStatus($this->jobs, $transactions);
|
||||
$this->update = new UpdateCustomerJob($this->jobs, $factory, $transactions, $this->clock);
|
||||
$this->changeStatus = new ChangeJobStatus($this->jobs, $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ beforeEach(function () {
|
||||
$this->changeTaskStatus = new ChangeTaskStatus($this->tasks, $transactions);
|
||||
$this->usage = new FakeTaskUsage;
|
||||
$this->removeTask = new RemoveTask($this->tasks, $this->usage, $transactions);
|
||||
$this->changeJobStatus = new ChangeJobStatus($this->jobs, $transactions);
|
||||
$this->changeJobStatus = new ChangeJobStatus($this->jobs, $transactions, new FakeClock(new DateTimeImmutable('2026-05-01')));
|
||||
});
|
||||
|
||||
it('allows tasks from a quote request on, not before and not when archived', function () {
|
||||
|
||||
@@ -16,6 +16,7 @@ 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
|
||||
@@ -97,3 +98,29 @@ it('returns only the fields that changed', function () {
|
||||
->and($job->changeStatus(JobStatus::Tentative))->toBe([])
|
||||
->and(JobStatus::kanbanStatuses())->not->toContain(JobStatus::Archived);
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user