Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
19 changes: 19 additions & 0 deletions tests/Entity/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down