From f6aa3340d7142b86825303a8f2793a4807c36b77 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Jun 2016 12:47:26 +1000 Subject: [PATCH 1/7] Expense Categories Model --- app/Models/ExpenseCategory.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/Models/ExpenseCategory.php diff --git a/app/Models/ExpenseCategory.php b/app/Models/ExpenseCategory.php new file mode 100644 index 0000000000..9c65353ce6 --- /dev/null +++ b/app/Models/ExpenseCategory.php @@ -0,0 +1,20 @@ +belongsTo('App\Models\Expense'); + } + +} \ No newline at end of file From 7237f25cbaca222b99fd457658ba70af268e2e99 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 Jun 2016 20:05:28 +1000 Subject: [PATCH 2/7] Expense Category Transformer --- .../ExpenseCategoryTransformer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/Ninja/Transformers/ExpenseCategoryTransformer.php diff --git a/app/Ninja/Transformers/ExpenseCategoryTransformer.php b/app/Ninja/Transformers/ExpenseCategoryTransformer.php new file mode 100644 index 0000000000..6ad6e743a3 --- /dev/null +++ b/app/Ninja/Transformers/ExpenseCategoryTransformer.php @@ -0,0 +1,18 @@ +getDefaults($expenseCategory), [ + 'id' => (int) $expenseCategory->public_id, + 'name' => $expenseCategory->name, + 'updated_at' => $this->getTimestamp($expenseCategory->updated_at), + 'archived_at' => $this->getTimestamp($expenseCategory->deleted_at), + ]); + } +} \ No newline at end of file From fedbd743194b49b9f525326d8857a6f63eff9312 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 Jun 2016 20:18:30 +1000 Subject: [PATCH 3/7] Integrating Expense categories into API --- app/Http/routes.php | 1 + app/Models/Account.php | 8 ++++++-- app/Ninja/Transformers/AccountTransformer.php | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/Http/routes.php b/app/Http/routes.php index ab1bd91d32..e9c0c14e0d 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -365,6 +365,7 @@ if (!defined('CONTACT_EMAIL')) { define('ENTITY_EXPENSE_ACTIVITY', 'expense_activity'); define('ENTITY_BANK_ACCOUNT', 'bank_account'); define('ENTITY_BANK_SUBACCOUNT', 'bank_subaccount'); + define('ENTITY_EXPENSE_CATEGORIES', 'expense_categories'); define('INVOICE_TYPE_STANDARD', 1); define('INVOICE_TYPE_QUOTE', 2); diff --git a/app/Models/Account.php b/app/Models/Account.php index 7df9218438..fcc195bede 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -198,6 +198,11 @@ class Account extends Eloquent return $this->belongsTo('App\Models\Company'); } + public function expenseCategories() + { + $this->hasMany('App\Models\ExpenseCategories','account_id','id')->withTrashed(); + } + public function setIndustryIdAttribute($value) { $this->attributes['industry_id'] = $value ?: null; @@ -213,8 +218,6 @@ class Account extends Eloquent $this->attributes['size_id'] = $value ?: null; } - - public function isGatewayConfigured($gatewayId = 0) { if ( ! $this->relationLoaded('account_gateways')) { @@ -729,6 +732,7 @@ class Account extends Eloquent 'tax_rates' => [], 'expenses' => ['client', 'invoice', 'vendor'], 'payments' => ['invoice'], + 'expenseCategories' => [], ]; foreach ($map as $key => $values) { diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index f56635bad2..9637efb4ea 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -7,6 +7,7 @@ use App\Models\Product; use App\Models\TaxRate; use League\Fractal; use League\Fractal\TransformerAbstract; +use App\Models\ExpenseCategory; class AccountTransformer extends EntityTransformer { @@ -14,6 +15,7 @@ class AccountTransformer extends EntityTransformer 'users', 'products', 'taxRates', + 'expense_categories' ]; protected $availableIncludes = [ @@ -22,6 +24,12 @@ class AccountTransformer extends EntityTransformer 'payments', ]; + public function includeExpenseCategories(Account $account) + { + $transformer = new ExpenseTransformer($account, $this->serializer); + return $this->includeCollection($account->expenseCategories, $transformer, ENTITY_EXPENSE_CATEGORIES); + } + public function includeUsers(Account $account) { $transformer = new UserTransformer($account, $this->serializer); From 369b696297d300c07ff2338c8e132bf7e8a4eeaa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 Jun 2016 20:23:14 +1000 Subject: [PATCH 4/7] typo --- app/Models/Account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index fcc195bede..4ee18e9c6c 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -200,7 +200,7 @@ class Account extends Eloquent public function expenseCategories() { - $this->hasMany('App\Models\ExpenseCategories','account_id','id')->withTrashed(); + $this->hasMany('App\Models\ExpenseCategory','account_id','id')->withTrashed(); } public function setIndustryIdAttribute($value) From 6e57976075119967a297d26219df22d6985e0338 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 Jun 2016 20:26:47 +1000 Subject: [PATCH 5/7] typo --- app/Models/Account.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Account.php b/app/Models/Account.php index 4ee18e9c6c..6eb3990a49 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -200,7 +200,7 @@ class Account extends Eloquent public function expenseCategories() { - $this->hasMany('App\Models\ExpenseCategory','account_id','id')->withTrashed(); + return $this->hasMany('App\Models\ExpenseCategory','account_id','id')->withTrashed(); } public function setIndustryIdAttribute($value) From abafc4ce6fc19d060de61868cf297ff9f286b5a2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 13 Jun 2016 20:29:43 +1000 Subject: [PATCH 6/7] typo --- app/Ninja/Transformers/AccountTransformer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 9637efb4ea..148e7df212 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -26,7 +26,7 @@ class AccountTransformer extends EntityTransformer public function includeExpenseCategories(Account $account) { - $transformer = new ExpenseTransformer($account, $this->serializer); + $transformer = new ExpenseCategoryTransformer($account, $this->serializer); return $this->includeCollection($account->expenseCategories, $transformer, ENTITY_EXPENSE_CATEGORIES); } From 5fdfa8c466d56662b9e6d94afa4dca7fd4aff90d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 18 Jun 2016 17:56:09 +1000 Subject: [PATCH 7/7] Add logo into Transformer --- app/Ninja/Transformers/AccountTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 148e7df212..bab26f79a3 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -104,7 +104,8 @@ class AccountTransformer extends EntityTransformer 'custom_label1' => $account->custom_label1, 'custom_label2' => $account->custom_label2, 'custom_value1' => $account->custom_value1, - 'custom_value2' => $account->custom_value2 + 'custom_value2' => $account->custom_value2, + 'logo' => $account->logo, ]; } } \ No newline at end of file