Show a monthly fee job's billed periods on a page of its own
The new billing::job-months page lists the months that created billing materials have billed for a monthly fee job, with links to the materials and the total, and the months still to bill up to the current month, counted the same way as a new material counts them. The job page links to it next to the payment basis for those who manage billing. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Billing\Application\UseCases\FinalizeBillingExport;
|
||||
use App\Modules\Billing\Application\UseCases\OpenBillingDraft;
|
||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
@@ -31,7 +32,7 @@ beforeEach(function () {
|
||||
|
||||
ExpenseModel::factory()->create(['customer_job_id' => $this->jobs[0]->id, 'description' => 'Paperi']);
|
||||
|
||||
CustomerJobModel::factory()->create([
|
||||
$this->monthly = CustomerJobModel::factory()->create([
|
||||
'name' => 'Ylläpito',
|
||||
'customer_id' => $customer->id,
|
||||
'status' => JobStatus::InProduction,
|
||||
@@ -61,6 +62,25 @@ it('has no accessibility issues on the billing pages', function (string $page, s
|
||||
'mobile, dark' => ['mobile', 'dark'],
|
||||
]);
|
||||
|
||||
it('has no accessibility issues on the billed periods page', function (string $device, string $colorScheme) {
|
||||
// The draft holds only the monthly fee job, so creating it bills the job's months up to now.
|
||||
app(FinalizeBillingExport::class)->execute($this->exportId, $this->manager->id);
|
||||
|
||||
$visit = visit(route('billing.job-months', $this->monthly->id));
|
||||
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
|
||||
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
|
||||
|
||||
$visit->assertSee('Laskutetut kuukaudet (3)')
|
||||
->assertSee('Aineisto 1')
|
||||
->assertNoJavaScriptErrors()
|
||||
->assertNoAccessibilityIssues(level: 2);
|
||||
})->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;
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Billing\Domain\Enums\ExportStatus;
|
||||
use App\Modules\Billing\Infrastructure\Persistence\Eloquent\BillingExportModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->manager = User::factory()->management()->create();
|
||||
$this->actingAs($this->manager);
|
||||
$this->travelTo(now()->setDate(2026, 11, 20)->setTime(12, 0));
|
||||
|
||||
$this->maintenance = CustomerJobModel::factory()->create([
|
||||
'name' => 'Somen ylläpito',
|
||||
'customer_id' => CustomerModel::factory()->company()->create(['name' => 'Kahvila Oy'])->id,
|
||||
'status' => JobStatus::InProduction,
|
||||
'payment_basis' => 'monthly_fee',
|
||||
'monthly_fee_cents' => 39000,
|
||||
'starts_on' => '2026-09-10',
|
||||
]);
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a billing material whose billing month is the given month, with the monthly fee jobs on it.
|
||||
*/
|
||||
function createMonthlyMaterial(string $period): void
|
||||
{
|
||||
Livewire::test('billing::index')->call('openDraftNow');
|
||||
$exportId = (int) BillingExportModel::query()->where('status', ExportStatus::Draft)->value('id');
|
||||
|
||||
Livewire::test('billing::export', ['export' => $exportId])
|
||||
->call('savePeriod', $period)
|
||||
->call('finalize')
|
||||
->assertSet('errorMessage', '');
|
||||
}
|
||||
|
||||
it('lists the billed months with their billing material and the months still to bill', function () {
|
||||
createMonthlyMaterial('2026-10');
|
||||
$this->travelTo(now()->setDate(2026, 12, 5));
|
||||
|
||||
Livewire::test('billing::job-months', ['job' => $this->maintenance->id])
|
||||
->assertSeeInOrder(['Laskutetut kuukaudet (2)', '9/2026', 'Aineisto 1', '390,00', '10/2026', 'Aineisto 1', 'Laskutettu yhteensä 780,00'])
|
||||
->assertSeeInOrder(['Laskuttamatta kuukauteen 12/2026 mennessä', '11/2026', '12/2026']);
|
||||
});
|
||||
|
||||
it('shows a job with every month billed and one with none billed', function () {
|
||||
Livewire::test('billing::job-months', ['job' => $this->maintenance->id])
|
||||
->assertSee('Mitään kuukautta ei ole vielä laskutettu.')
|
||||
->assertSeeInOrder(['9/2026', '10/2026', '11/2026']);
|
||||
|
||||
createMonthlyMaterial('2026-11');
|
||||
|
||||
Livewire::test('billing::job-months', ['job' => $this->maintenance->id])
|
||||
->assertSee('Kaikki kuukaudet tähän kuukauteen asti on laskutettu.');
|
||||
});
|
||||
|
||||
it('links a monthly fee job to its billed periods for management only', function () {
|
||||
$hourly = CustomerJobModel::factory()->create(['payment_basis' => 'hourly']);
|
||||
$link = route('billing.job-months', $this->maintenance->id);
|
||||
|
||||
$this->get(route('jobs.show', $this->maintenance))->assertSee($link, false)->assertSee('Laskutetut kaudet');
|
||||
$this->get(route('jobs.show', $hourly))->assertDontSee('Laskutetut kaudet');
|
||||
|
||||
$this->actingAs(User::factory()->employee()->create());
|
||||
$this->get(route('jobs.show', $this->maintenance))->assertOk()->assertDontSee($link, false);
|
||||
$this->get($link)->assertForbidden();
|
||||
});
|
||||
|
||||
it('has no billed periods page for a job that is not billed by a monthly fee', function () {
|
||||
$hourly = CustomerJobModel::factory()->create(['payment_basis' => 'hourly']);
|
||||
|
||||
$this->get(route('billing.job-months', $hourly))->assertNotFound();
|
||||
$this->get(route('billing.job-months', 999999))->assertNotFound();
|
||||
});
|
||||
Reference in New Issue
Block a user