From 37fefd663ee80054bb49257d1ee1a91e6154837b Mon Sep 17 00:00:00 2001 From: Rene Korss Date: Wed, 2 Sep 2026 16:58:17 +0300 Subject: [PATCH] Add read-only estimate API support --- README.md | 8 +++++ src/Aeglio.php | 6 ++++ src/Entity/Estimate.php | 61 +++++++++++++++++++++++++++++++++++ src/Resource/Estimates.php | 28 ++++++++++++++++ tests/Entity/EstimateTest.php | 45 ++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 src/Entity/Estimate.php create mode 100644 src/Resource/Estimates.php create mode 100644 tests/Entity/EstimateTest.php diff --git a/README.md b/README.md index 5732f21..ef5f8a7 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ $taxRate = $aeglio->taxRates()->create(new TaxRateData( - `expenseCategories()` - `expenses()` - `invoices()` +- `estimates()` ## Public API @@ -243,3 +244,10 @@ Entity helpers: - `$invoice->payments(...)` - `$invoice->send(...)` - `$invoice->downloadPdf()` + +### Estimates + +Estimate endpoints are read-only. Every revision has its own stable `id`; revisions share the commercial `number` and are ordered by `revisionNumber`. + +- `estimates()->list(int $perPage = 50, int $page = 1)` +- `estimates()->find(int $id)` diff --git a/src/Aeglio.php b/src/Aeglio.php index 68d108b..c6b28b0 100644 --- a/src/Aeglio.php +++ b/src/Aeglio.php @@ -8,6 +8,7 @@ use Aeglio\Resource\Clients; use Aeglio\Resource\ExpenseCategories; use Aeglio\Resource\Expenses; +use Aeglio\Resource\Estimates; use Aeglio\Resource\Invoices; use Aeglio\Resource\Projects; use Aeglio\Resource\Suppliers; @@ -67,6 +68,11 @@ public function invoices(): Invoices return new Invoices($this, $this->httpClient); } + public function estimates(): Estimates + { + return new Estimates($this, $this->httpClient); + } + public function projects(): Projects { return new Projects($this, $this->httpClient); diff --git a/src/Entity/Estimate.php b/src/Entity/Estimate.php new file mode 100644 index 0000000..0e71512 --- /dev/null +++ b/src/Entity/Estimate.php @@ -0,0 +1,61 @@ + $data */ + public static function fromArray(array $data): self + { + return new self( + id: (int) $data['id'], + dealId: isset($data['deal_id']) ? (int) $data['deal_id'] : null, + clientId: (int) $data['client_id'], + number: (string) $data['number'], + revisionNumber: (int) ($data['revision_number'] ?? 1), + previousRevisionId: isset($data['previous_revision_id']) ? (int) $data['previous_revision_id'] : null, + title: (string) $data['title'], + state: (string) $data['state'], + currency: (string) $data['currency'], + issuedAt: $data['issued_at'] ?? null, + validUntil: $data['valid_until'] ?? null, + sentAt: $data['sent_at'] ?? null, + acceptedAt: $data['accepted_at'] ?? null, + rejectedAt: $data['rejected_at'] ?? null, + expiredAt: $data['expired_at'] ?? null, + supersededAt: $data['superseded_at'] ?? null, + cancelledAt: $data['cancelled_at'] ?? null, + notes: $data['notes'] ?? null, + terms: $data['terms'] ?? null, + createdAt: $data['created_at'] ?? null, + updatedAt: $data['updated_at'] ?? null, + ); + } +} diff --git a/src/Resource/Estimates.php b/src/Resource/Estimates.php new file mode 100644 index 0000000..20d6253 --- /dev/null +++ b/src/Resource/Estimates.php @@ -0,0 +1,28 @@ + */ + public function list(int $perPage = 50, int $page = 1): PaginatedResult + { + return $this->paginated( + path: 'estimates', + query: ['per_page' => $perPage, 'page' => $page], + mapper: fn (array $item): Estimate => Estimate::fromArray($item), + ); + } + + public function find(int $id): Estimate + { + $response = $this->http->json('GET', 'estimates/'.$id); + + return Estimate::fromArray($response['data']); + } +} diff --git a/tests/Entity/EstimateTest.php b/tests/Entity/EstimateTest.php new file mode 100644 index 0000000..7a1a04b --- /dev/null +++ b/tests/Entity/EstimateTest.php @@ -0,0 +1,45 @@ + 12, + 'deal_id' => 4, + 'client_id' => 7, + 'number' => 'EST-2026-001', + 'revision_number' => 2, + 'previous_revision_id' => 11, + 'title' => 'Website implementation', + 'state' => 'superseded', + 'currency' => 'EUR', + 'issued_at' => '2026-09-01', + 'valid_until' => '2026-10-01', + 'sent_at' => '2026-09-01T10:00:00Z', + 'accepted_at' => null, + 'rejected_at' => null, + 'expired_at' => null, + 'superseded_at' => '2026-09-02T10:00:00Z', + 'cancelled_at' => null, + 'notes' => 'Customer-facing notes', + 'terms' => 'Commercial terms', + 'created_at' => '2026-09-01T09:00:00Z', + 'updated_at' => '2026-09-02T10:00:00Z', + ]); + + self::assertSame(12, $estimate->id); + self::assertSame(2, $estimate->revisionNumber); + self::assertSame(11, $estimate->previousRevisionId); + self::assertSame('superseded', $estimate->state); + self::assertSame('2026-09-02T10:00:00Z', $estimate->supersededAt); + self::assertNull($estimate->cancelledAt); + } +}