seed(RolesAndPermissionsSeeder::class); $admin = User::factory()->create(['is_active' => true]); $admin->assignRole('admin'); $this->actingAs($admin); }); test('admin sees legacy invoice archive overview with filters and mapping hints', function () { $customer = User::factory()->create([ 'is_active' => true, 'name' => 'Archiv Kunde', 'email' => 'archiv@example.com', ]); LegacyInvoice::query()->create([ 'legacy_portal' => 'presseecho', 'legacy_id' => 2001, 'user_id' => $customer->id, 'legacy_user_id' => 501, 'number' => 'PE-2001', 'amount_cents' => 4900, 'total_cents' => 4900, 'status' => 'paid', 'invoice_date' => now()->subMonth(), 'paid_at' => now()->subMonth()->addDays(2), 'imported_at' => now(), ]); LegacyInvoice::query()->create([ 'legacy_portal' => 'businessportal24', 'legacy_id' => 2002, 'user_id' => null, 'legacy_user_id' => 999, 'number' => 'BP-2002', 'amount_cents' => 11900, 'total_cents' => 11900, 'status' => 'open', 'invoice_date' => now()->subWeeks(2), 'imported_at' => now(), ]); LivewireVolt::test('admin.invoices.index') ->assertSee('Legacy-Rechnungsarchiv') ->assertSee('PE-2001') ->assertSee('BP-2002') ->assertSee('Ohne Zuordnung') ->assertSee('Archiv Kunde') ->set('mappingFilter', 'unmapped') ->assertSee('BP-2002') ->assertDontSee('PE-2001') ->set('mappingFilter', 'all') ->set('portalFilter', 'presseecho') ->assertSee('PE-2001') ->assertDontSee('BP-2002') ->call('resetFilters') ->assertSee('PE-2001') ->assertSee('BP-2002'); }); test('admin opens generated legacy invoice pdf inline', function () { /** @var TestCase $this */ $invoice = LegacyInvoice::query()->create([ 'legacy_portal' => 'presseecho', 'legacy_id' => 2003, 'user_id' => null, 'legacy_user_id' => 503, 'number' => 'PE-2003', 'amount_cents' => 9900, 'total_cents' => 9900, 'status' => 'paid', 'invoice_date' => now()->subMonth(), 'paid_at' => now()->subMonth()->addDays(2), 'payment_method' => 'SPK_Berlin', 'raw_snapshot' => [ 'number' => 'PE-2003', 'service_period_begin_date' => now()->subYear()->toDateString(), 'service_period_end_date' => now()->toDateString(), ], 'pdf_payload' => [ 'billing_address' => [ 'name' => 'Admin Archiv GmbH', 'address' => 'Archivstrasse 1', 'postal_code' => '10115', 'city' => 'Berlin', 'country_name' => 'Deutschland', ], ], 'imported_at' => now(), ]); LivewireVolt::test('admin.invoices.index') ->assertSee('Öffnen'); $response = $this->get(route('admin.legacy-invoices.pdf', $invoice)); $response ->assertSuccessful() ->assertHeader('content-type', 'application/pdf') ->assertHeader('content-disposition', 'inline; filename="Presseecho-RNr-PE-2003.pdf"'); expect($response->content()) ->toContain('adametz.media') ->toContain('Rechnungsbetrag') ->toContain('/F2 21 Tf'); expect($invoice->refresh()->pdf_generated_at)->not->toBeNull(); }); test('admin opens legacy invoice pdf with stern layout for non media invoices', function () { /** @var TestCase $this */ $invoice = LegacyInvoice::query()->create([ 'legacy_portal' => 'businessportal24', 'legacy_id' => 2004, 'user_id' => null, 'legacy_user_id' => 504, 'number' => 'BP-2004', 'amount_cents' => 11900, 'total_cents' => 11900, 'status' => 'open', 'invoice_date' => now()->subMonth(), 'due_date' => now()->addDays(14), 'payment_method' => 'invoice', 'raw_snapshot' => [ 'number' => 'BP-2004', 'is_media' => false, 'service_period_begin_date' => now()->subYear()->toDateString(), 'service_period_end_date' => now()->toDateString(), ], 'pdf_payload' => [ 'invoice' => [ 'is_media' => false, 'service_period_begin_date' => now()->subYear()->toDateString(), 'service_period_end_date' => now()->toDateString(), ], 'billing_address' => [ 'name' => 'Stern Archiv GmbH', 'address' => 'Archivstrasse 2', 'postal_code' => '10719', 'city' => 'Berlin', 'country_name' => 'Deutschland', ], 'payment_option_translation' => [ 'name' => 'Legacy Pressepaket', ], ], 'imported_at' => now(), ]); $response = $this->get(route('admin.legacy-invoices.pdf', $invoice)); $response ->assertSuccessful() ->assertHeader('content-type', 'application/pdf') ->assertHeader('content-disposition', 'inline; filename="Businessportal24-RNr-BP-2004.pdf"'); expect($response->content()) ->toContain('Stern Consulting GmbH') ->toContain('Hypo Vereinsbank') ->toContain('/F2 19 Tf'); });