From e0468571a466142355122eef50ec9d9027f43295 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 8 Aug 2018 17:49:15 +0300 Subject: [PATCH] Added payment terms to API --- app/Models/Account.php | 8 ++++++++ app/Ninja/Transformers/UserAccountTransformer.php | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/Models/Account.php b/app/Models/Account.php index 9aa5c61f716a..76d6f0441114 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -501,6 +501,14 @@ class Account extends Eloquent return $this->hasMany('App\Models\Project', 'account_id', 'id')->withTrashed(); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function custom_payment_terms() + { + return $this->hasMany('App\Models\PaymentTerm', 'account_id', 'id')->withTrashed(); + } + /** * @param $value */ diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php index 57387dab4d8f..7929dca9a79f 100644 --- a/app/Ninja/Transformers/UserAccountTransformer.php +++ b/app/Ninja/Transformers/UserAccountTransformer.php @@ -61,6 +61,7 @@ class UserAccountTransformer extends EntityTransformer 'tax_rates', 'expense_categories', 'account_email_settings', + 'custom_payment_terms', ]; protected $tokenName; @@ -84,6 +85,18 @@ class UserAccountTransformer extends EntityTransformer * * @return \League\Fractal\Resource\Collection */ + public function includeCustomPaymentTerms(User $user) + { + $transformer = new PaymentTermTransformer($this->account, $this->serializer); + + return $this->includeCollection($this->account->custom_payment_terms, $transformer, 'payment_terms'); + } + + /** + * @param Account $account + * + * @return \League\Fractal\Resource\Collection + */ public function includeUsers(User $user) { $transformer = new UserTransformer($this->account, $this->serializer);