Jobs billed by a fixed monthly fee get a monthly fee field, kept behind the quotes permission like the quoted amount. A billing material now has a billing month: a new draft adds every monthly fee job with something to bill, each on an invoice of its own, and bills one line for every unbilled month from the job's start up to the billing month (or its end or completion), so skipped months are caught up and no month is billed twice. Their expenses are billed alongside, their hours are covered by the fee and marked billed, and the job keeps running. Co-Authored-By: Claude Opus 5.5 <[email protected]>
123 lines
4.8 KiB
PHP
123 lines
4.8 KiB
PHP
<?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();
|
|
});
|
|
|
|
it('keeps the monthly fee of a monthly fee job with its history, behind the quotes permission', function () {
|
|
$this->actingAs(User::factory()->management()->create());
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])
|
|
->assertDontSee('Kuukausihinta (€, ALV 0)')
|
|
->set('form.payment_basis', 'monthly_fee')
|
|
->assertSee('Kuukausihinta (€, ALV 0)')
|
|
->set('form.monthly_fee', '12,345')
|
|
->call('save')
|
|
->assertHasErrors(['form.monthly_fee' => [__('jobs.errors.invalid_amount')]])
|
|
->set('form.monthly_fee', '99,90')
|
|
->call('save')
|
|
->assertHasNoErrors();
|
|
|
|
expect($this->job->refresh()->monthly_fee_cents)->toBe(9990);
|
|
|
|
$this->get(route('jobs.show', $this->job->id))
|
|
->assertSee('Kuukausihinta')
|
|
->assertSee("99,90\u{00A0}€", false);
|
|
|
|
$this->actingAs(User::factory()->employee()->create());
|
|
|
|
$this->get(route('jobs.show', $this->job->id))->assertDontSee('Kuukausihinta');
|
|
|
|
Livewire::test('jobs::form', ['job' => $this->job->id])->set('form.name', 'Ylläpito')->call('save')->assertHasNoErrors();
|
|
|
|
expect($this->job->refresh()->monthly_fee_cents)->toBe(9990);
|
|
});
|