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]>
90 lines
4.1 KiB
PHP
90 lines
4.1 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Billing\Application\UseCases\OpenBillingDraft;
|
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
|
use App\Modules\Expenses\Infrastructure\Persistence\Eloquent\ExpenseModel;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Eloquent\TimeEntryModel;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->manager = User::factory()->management()->create(['name' => 'Maija Johtaja']);
|
|
$this->actingAs($this->manager);
|
|
|
|
$layout = WorkTypeModel::factory()->create(['name' => 'Taitto', 'hourly_rate_cents' => 8000]);
|
|
$customer = CustomerModel::factory()->company()->create(['name' => 'Asiakas Oy']);
|
|
$this->jobs = [];
|
|
|
|
foreach (['Esite', 'Juliste'] as $name) {
|
|
$job = CustomerJobModel::factory()->create(['name' => $name, 'customer_id' => $customer->id, 'status' => JobStatus::Done, 'payment_basis' => 'hourly']);
|
|
$task = TaskModel::factory()->create(['customer_job_id' => $job->id, 'work_type_id' => $layout->id]);
|
|
TimeEntryModel::factory()->approved()->create(['task_id' => $task->id, 'hours' => 2.5]);
|
|
TimeEntryModel::factory()->create(['task_id' => TaskModel::factory()->create(['customer_job_id' => $job->id, 'work_type_id' => $layout->id])->id, 'hours' => 1]);
|
|
$this->jobs[] = $job;
|
|
}
|
|
|
|
ExpenseModel::factory()->create(['customer_job_id' => $this->jobs[0]->id, 'description' => 'Paperi']);
|
|
|
|
CustomerJobModel::factory()->create([
|
|
'name' => 'Ylläpito',
|
|
'customer_id' => $customer->id,
|
|
'status' => JobStatus::InProduction,
|
|
'payment_basis' => 'monthly_fee',
|
|
'monthly_fee_cents' => 9900,
|
|
'starts_on' => now()->subMonths(2)->toDateString(),
|
|
]);
|
|
|
|
// Opening the draft adds the monthly fee job.
|
|
$this->exportId = app(OpenBillingDraft::class)->execute($this->manager->id);
|
|
});
|
|
|
|
it('has no accessibility issues on the billing pages', function (string $page, string $device, string $colorScheme) {
|
|
$url = $page === 'index' ? route('billing.index') : route('billing.export', $this->exportId);
|
|
|
|
$visit = visit($url);
|
|
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
|
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
|
|
|
$visit->assertSee($page === 'index' ? 'Jatka luonnosta' : 'Esite')
|
|
->assertNoJavaScriptErrors()
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
})->with(['index', 'export'])->with([
|
|
'desktop, light' => ['desktop', 'light'],
|
|
'desktop, dark' => ['desktop', 'dark'],
|
|
'mobile, light' => ['mobile', 'light'],
|
|
'mobile, dark' => ['mobile', 'dark'],
|
|
]);
|
|
|
|
it('adds and combines jobs and creates the material', function () {
|
|
[$first, $second] = $this->jobs;
|
|
|
|
$page = visit(route('billing.export', $this->exportId));
|
|
|
|
$page->click('[wire\\:click="add('.$first->id.')"]')
|
|
->assertSee('lisätty aineistoon')
|
|
->click('[wire\\:click="add('.$second->id.')"]')
|
|
->assertSee('Lasku 3: Asiakas Oy')
|
|
->assertSee('Laskutettavat kuukaudet')
|
|
->assertSee('Hyväksymättömiä tunteja 1 h')
|
|
->assertNoAccessibilityIssues(level: 2)
|
|
->select('[wire\\:model="moveTargets.'.$second->id.'"]', (string) $first->id)
|
|
->click('[wire\\:click="move('.$second->id.')"]')
|
|
->assertSee('siirretty laskulle')
|
|
->assertDontSee('Lasku 3: Asiakas Oy')
|
|
->click('Muodosta aineisto')
|
|
->assertSee('Muodostetaanko laskuaineisto?')
|
|
->assertNoAccessibilityIssues(level: 2)
|
|
->click('#finalize-dialog button:last-child')
|
|
->assertSee('Laskuaineisto muodostettu: 2 laskua.')
|
|
->assertSee('Laskutetut h')
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
|
|
expect($first->refresh()->status)->toBe(JobStatus::Invoiced);
|
|
});
|