diff --git a/README.md b/README.md index ef5f8a7..3c6d02b 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,17 @@ Entity helpers: - `invoices()->list(?array $state = null, int $perPage = 50, int $page = 1)` - `invoices()->find(int $id)` - `invoices()->create(InvoiceData $data)` +- Automatic payment references are an opt-in team setting. Omit `referenceNumber` + when creating an invoice to let Aeglio assign it (Estonian numeric or ISO 11649 + `RF`, according to the issuer's settings). Read `$invoice->referenceNumber` + from the returned invoice. An explicit nonblank value remains manual. Generated + references cannot be directly changed or cleared; attempts return a validation error. + Teams can assign references per invoice (default) or reuse one per client. + Updating `clientId` on a client-based invoice automatically replaces its reference + with the destination client's reference, using the invoice's stored format. + Omit `referenceNumber` on this update and read the new value from the response. + Manual and per-invoice references remain unchanged when changing the client. + Updating an existing invoice never automatically fills a blank reference. - `invoices()->update(int $id, UpdateInvoiceData $data)` - `invoices()->delete(int $id)` - `invoices()->addPayment(int $invoiceId, InvoicePaymentData $data)` diff --git a/tests/Entity/InvoiceTest.php b/tests/Entity/InvoiceTest.php index 8b9c31e..6d4bc3d 100644 --- a/tests/Entity/InvoiceTest.php +++ b/tests/Entity/InvoiceTest.php @@ -10,6 +10,25 @@ final class InvoiceTest extends TestCase { + public function test_client_only_update_omits_reference_so_server_can_assign_it(): void + { + $data = new \Aeglio\Dto\UpdateInvoiceData(clientId: 42); + self::assertSame(['client_id' => 42], $data->toArray()); + } + + public function test_generated_references_remain_strings(): void + { + foreach (['10003', 'RF671000'] as $reference) { + $invoice = Invoice::fromArray(new Aeglio(token: 'test-token'), [ + 'id' => 1, 'number' => 'INV-1', 'reference_number' => $reference, + 'client_id' => 1, 'state' => 'draft', 'issued_at' => '2026-10-06', + 'due_at' => '2026-10-20', 'has_tax' => false, 'subtotal' => 0, + 'tax' => 0, 'total' => 0, 'payments_total' => 0, 'total_to_pay' => 0, + ]); + self::assertSame($reference, $invoice->referenceNumber); + } + } + public function test_from_array_maps_rows_and_payments(): void { $invoice = Invoice::fromArray(