1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00
invoiceninja/app/Ninja/Transformers/AccountTransformer.php

146 lines
5.0 KiB
PHP
Raw Normal View History

2015-11-01 23:10:20 +01:00
<?php namespace App\Ninja\Transformers;
use App\Models\Account;
/**
* Class AccountTransformer
*/
2015-11-27 13:55:28 +01:00
class AccountTransformer extends EntityTransformer
2015-11-01 23:10:20 +01:00
{
/**
* @var array
*/
2015-11-01 23:10:20 +01:00
protected $defaultIncludes = [
2015-11-03 03:02:15 +01:00
'users',
2015-11-19 12:50:35 +01:00
'products',
2016-02-17 11:50:52 +01:00
'taxRates',
'expense_categories'
2016-02-17 11:50:52 +01:00
];
/**
* @var array
*/
2016-02-17 11:50:52 +01:00
protected $availableIncludes = [
'clients',
'invoices',
2016-05-03 18:06:38 +02:00
'payments',
2015-11-01 23:10:20 +01:00
];
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
public function includeExpenseCategories(Account $account)
{
2016-06-13 12:29:43 +02:00
$transformer = new ExpenseCategoryTransformer($account, $this->serializer);
return $this->includeCollection($account->expenseCategories, $transformer, ENTITY_EXPENSE_CATEGORIES);
}
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2015-11-08 22:12:50 +01:00
public function includeUsers(Account $account)
2015-11-01 23:10:20 +01:00
{
2015-11-27 13:55:28 +01:00
$transformer = new UserTransformer($account, $this->serializer);
return $this->includeCollection($account->users, $transformer, 'users');
2015-11-03 15:21:17 +01:00
}
2015-11-01 23:10:20 +01:00
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2015-11-08 22:12:50 +01:00
public function includeClients(Account $account)
2015-11-03 15:21:17 +01:00
{
2015-11-27 13:55:28 +01:00
$transformer = new ClientTransformer($account, $this->serializer);
return $this->includeCollection($account->clients, $transformer, 'clients');
2015-11-01 23:10:20 +01:00
}
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2015-11-15 11:43:32 +01:00
public function includeInvoices(Account $account)
{
2015-11-27 13:55:28 +01:00
$transformer = new InvoiceTransformer($account, $this->serializer);
return $this->includeCollection($account->invoices, $transformer, 'invoices');
2015-11-15 11:43:32 +01:00
}
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2015-11-19 12:50:35 +01:00
public function includeProducts(Account $account)
{
2015-11-27 13:55:28 +01:00
$transformer = new ProductTransformer($account, $this->serializer);
return $this->includeCollection($account->products, $transformer, 'products');
2015-11-19 12:50:35 +01:00
}
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2015-12-21 08:36:29 +01:00
public function includeTaxRates(Account $account)
{
$transformer = new TaxRateTransformer($account, $this->serializer);
return $this->includeCollection($account->tax_rates, $transformer, 'taxRates');
}
/**
* @param Account $account
* @return \League\Fractal\Resource\Collection
*/
2016-02-17 11:50:52 +01:00
public function includePayments(Account $account)
{
$transformer = new PaymentTransformer($account, $this->serializer);
return $this->includeCollection($account->payments, $transformer, 'payments');
}
/**
* @param Account $account
* @return array
* @throws \Laracasts\Presenter\Exceptions\PresenterException
*/
2015-11-01 23:10:20 +01:00
public function transform(Account $account)
{
return [
2015-11-05 09:50:35 +01:00
'account_key' => $account->account_key,
2015-11-06 11:59:53 +01:00
'name' => $account->present()->name,
2015-11-07 13:15:37 +01:00
'currency_id' => (int) $account->currency_id,
'timezone_id' => (int) $account->timezone_id,
'date_format_id' => (int) $account->date_format_id,
'datetime_format_id' => (int) $account->datetime_format_id,
2015-12-27 12:08:58 +01:00
'updated_at' => $this->getTimestamp($account->updated_at),
'archived_at' => $this->getTimestamp($account->deleted_at),
2015-11-07 13:15:37 +01:00
'address1' => $account->address1,
'address2' => $account->address2,
'city' => $account->city,
'state' => $account->state,
'postal_code' => $account->postal_code,
'country_id' => (int) $account->country_id,
'invoice_terms' => $account->invoice_terms,
'email_footer' => $account->email_footer,
'industry_id' => (int) $account->industry_id,
'size_id' => (int) $account->size_id,
'invoice_taxes' => (bool) $account->invoice_taxes,
'invoice_item_taxes' => (bool) $account->invoice_item_taxes,
'invoice_design_id' => (int) $account->invoice_design_id,
'client_view_css' => (string) $account->client_view_css,
2015-11-07 13:15:37 +01:00
'work_phone' => $account->work_phone,
'work_email' => $account->work_email,
'language_id' => (int) $account->language_id,
'fill_products' => (bool) $account->fill_products,
'update_products' => (bool) $account->update_products,
2015-12-04 00:00:39 +01:00
'vat_number' => $account->vat_number,
'custom_invoice_label1' => $account->custom_invoice_label1,
'custom_invoice_label2' => $account->custom_invoice_label2,
'custom_invoice_taxes1' => $account->custom_invoice_taxes1,
'custom_invoice_taxes2' => $account->custom_invoice_taxes1,
'custom_label1' => $account->custom_label1,
'custom_label2' => $account->custom_label2,
'custom_value1' => $account->custom_value1,
2016-06-18 09:56:09 +02:00
'custom_value2' => $account->custom_value2,
'logo' => $account->logo,
2015-11-01 23:10:20 +01:00
];
}
}