1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Integrating Expense categories into API

This commit is contained in:
David Bomba 2016-06-13 20:18:30 +10:00
parent 7237f25cba
commit fedbd74319
3 changed files with 15 additions and 2 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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);