Management builds the monthly billing material (laskuaineisto) as a draft: done jobs are added as invoices of their own, combined when the customer, billing unit and reference allow it, and their billable hours are set per work type. Creating the material checks the jobs again, marks the approved hours and billable expenses billed, forms invoice lines with price and VAT snapshots and moves the jobs to "Lasku luotu". Fixed price jobs bill their quoted amount once. Billed hours keep their approval and billed expenses can no longer change. The Fennoa export and monthly fee lines come later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
79 lines
3.7 KiB
PHP
79 lines
3.7 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Billing\Infrastructure\Persistence\Eloquent\BillingExportModel;
|
|
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']);
|
|
|
|
$this->exportId = BillingExportModel::query()->create(['status' => 'draft', 'created_by' => $this->manager->id])->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 2: Asiakas Oy')
|
|
->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 2: Asiakas Oy')
|
|
->click('Muodosta aineisto')
|
|
->assertSee('Muodostetaanko laskuaineisto?')
|
|
->assertNoAccessibilityIssues(level: 2)
|
|
->click('#finalize-dialog button:last-child')
|
|
->assertSee('Laskuaineisto muodostettu: 1 laskua.')
|
|
->assertSee('Laskutetut h')
|
|
->assertNoAccessibilityIssues(level: 2);
|
|
|
|
expect($first->refresh()->status)->toBe(JobStatus::Invoiced);
|
|
});
|