$tenantId, 'legal_entity_id' => $legalEntityId, 'invoice_number' => $number, 'payer_type' => 'legal', 'payer_name' => 'ООО Клиент', 'payer_inn' => '5000000000', 'amount_net' => $amount, 'amount_total' => $amount, 'status' => $status, 'issued_at' => now(), 'expires_at' => now()->addDays(5), ]); } it('GET /api/admin/invoices отдаёт выставленные счета с пагинацией', function () { $tenant = Tenant::factory()->create(); $le = LegalEntity::create(['code' => 'al_'.uniqid(), 'name' => 'ИП', 'legal_form' => 'IP', 'inn' => '770000000010', 'is_default' => true]); adminSeedInvoice($tenant->id, $le->id, 'issued', '100.00', 'СЧ-2026-01001'); adminSeedInvoice($tenant->id, $le->id, 'issued', '200.00', 'СЧ-2026-01002'); adminSeedInvoice($tenant->id, $le->id, 'paid', '300.00', 'СЧ-2026-01003'); $this->getJson('/api/admin/invoices?status=issued') ->assertOk() ->assertJsonStructure(['data' => [['id', 'invoice_number', 'amount_total', 'status', 'tenant_id']], 'meta' => ['total']]) ->assertJsonPath('meta.total', 2); }); it('POST /api/admin/invoices/{id}/mark-paid зачисляет баланс и ставит paid', function () { Storage::fake('local'); $tenant = Tenant::factory()->create(['balance_rub' => '0.00']); User::factory()->create(['tenant_id' => $tenant->id]); $le = LegalEntity::create(['code' => 'al2_'.uniqid(), 'name' => 'ИП', 'legal_form' => 'IP', 'inn' => '770000000011', 'is_default' => true]); $invoice = adminSeedInvoice($tenant->id, $le->id, 'issued', '700.00', 'СЧ-2026-01010'); $this->postJson("/api/admin/invoices/{$invoice->id}/mark-paid")->assertOk(); expect((string) $tenant->fresh()->balance_rub)->toBe('700.00') ->and(SaasInvoice::find($invoice->id)->status)->toBe('paid'); });