From aef4658873cbbf061bd78e5d1ba4333eaaf11b62 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 17 Feb 2016 19:10:33 +1100 Subject: [PATCH] Api work/Bug fixes --- app/Models/Client.php | 4 ++++ app/Models/Invoice.php | 5 +++++ app/Ninja/Transformers/ClientTransformer.php | 8 ++++++++ app/Ninja/Transformers/InvoiceTransformer.php | 10 +++++++++- app/Ninja/Transformers/VendorContactTransformer.php | 1 - 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index eae0eb1c148f..2167af0ddfc6 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -139,6 +139,10 @@ class Client extends EntityModel return $this->hasMany('App\Models\Credit'); } + public function expenses() + { + return $this->hasMany('App\Models\Expense','client_id','id')->withTrashed(); + } public function addContact($data, $isPrimary = false) { diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index e93c8d3b07f5..626f4db6475d 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -197,6 +197,11 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->hasMany('App\Models\Invitation')->orderBy('invitations.contact_id'); } + public function expenses() + { + return $this->hasMany('App\Models\Expense','invoice_id','id')->withTrashed(); + } + public function markInvitationsSent($notify = false) { foreach ($this->invitations as $invitation) { diff --git a/app/Ninja/Transformers/ClientTransformer.php b/app/Ninja/Transformers/ClientTransformer.php index 83ee7e56238b..f7d786a2ee25 100644 --- a/app/Ninja/Transformers/ClientTransformer.php +++ b/app/Ninja/Transformers/ClientTransformer.php @@ -47,6 +47,7 @@ class ClientTransformer extends EntityTransformer protected $availableIncludes = [ 'invoices', 'credits', + 'expenses', ]; public function includeContacts(Client $client) @@ -67,6 +68,13 @@ class ClientTransformer extends EntityTransformer return $this->includeCollection($client->credits, $transformer, ENTITY_CREDIT); } + public function includeExpenses(Client $client) + { + $transformer = new ExpenseTransformer($this->account, $this->serializer); + return $this->includeCollection($client->expenses, $transformer, ENTITY_EXPENSE); + } + + public function transform(Client $client) { return [ diff --git a/app/Ninja/Transformers/InvoiceTransformer.php b/app/Ninja/Transformers/InvoiceTransformer.php index 464fc5e3fad7..b67635386d8e 100644 --- a/app/Ninja/Transformers/InvoiceTransformer.php +++ b/app/Ninja/Transformers/InvoiceTransformer.php @@ -28,6 +28,7 @@ class InvoiceTransformer extends EntityTransformer 'invitations', 'payments', 'client', + 'expenses', ]; public function includeInvoiceItems(Invoice $invoice) @@ -51,9 +52,16 @@ class InvoiceTransformer extends EntityTransformer public function includeClient(Invoice $invoice) { $transformer = new ClientTransformer($this->account, $this->serializer); - return $this->includeItem($invoice->client, $transformer, 'client'); + return $this->includeItem($invoice->client, $transformer, ENTITY_CLIENT); } + public function includeExpenses(Invoice $invoice) + { + $transformer = new ExpenseTransformer($this->account, $this->serializer); + return $this->includeCollection($invoice->expenses, $transformer, ENTITY_EXPENSE); + } + + public function transform(Invoice $invoice) { return [ diff --git a/app/Ninja/Transformers/VendorContactTransformer.php b/app/Ninja/Transformers/VendorContactTransformer.php index 0166883aba4d..3b75aee53a28 100644 --- a/app/Ninja/Transformers/VendorContactTransformer.php +++ b/app/Ninja/Transformers/VendorContactTransformer.php @@ -17,7 +17,6 @@ class VendorContactTransformer extends EntityTransformer 'archived_at' => $this->getTimestamp($contact->deleted_at), 'is_primary' => (bool) $contact->is_primary, 'phone' => $contact->phone, - 'last_login' => $contact->last_login, 'account_key' => $this->account->account_key, ]; }