2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Transformers;
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-09 03:10:01 +01:00
|
|
|
use App\Models\Account;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Models\User;
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-09 03:10:01 +01:00
|
|
|
class UserAccountTransformer extends EntityTransformer
|
2015-11-03 15:21:17 +01:00
|
|
|
{
|
2018-07-07 21:13:02 +02:00
|
|
|
/**
|
|
|
|
* @SWG\Property(property="account_key", type="string", example="123456")
|
|
|
|
* @SWG\Property(property="name", type="string", example="John Doe")
|
|
|
|
* @SWG\Property(property="token", type="string", example="Token")
|
|
|
|
* @SWG\Property(property="default_url", type="string", example="http://www.example.com")
|
|
|
|
* @SWG\Property(property="plan", type="string", example="Plan")
|
|
|
|
* @SWG\Property(property="logo", type="string", example="Logo")
|
|
|
|
* @SWG\Property(property="logo_url", type="string", example="http://www.example.com/logo.png")
|
|
|
|
* @SWG\Property(property="currency_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="timezone_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="date_format_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="datetime_format_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="invoice_terms", type="string", example="Terms")
|
|
|
|
* @SWG\Property(property="invoice_taxes", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="invoice_item_taxes", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="invoice_design_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="quote_design_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="language_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="country_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="invoice_footer", type="string", example="Footer")
|
|
|
|
* @SWG\Property(property="invoice_labels", type="string", example="Labels")
|
|
|
|
* @SWG\Property(property="show_item_taxes", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="military_time", type="boolean", example=false)
|
2019-01-30 11:45:46 +01:00
|
|
|
* @SWG\Property(property="fill_products", type="boolean", example=false)
|
2018-07-07 21:13:02 +02:00
|
|
|
* @SWG\Property(property="tax_name1", type="string", example="VAT")
|
|
|
|
* @SWG\Property(property="tax_name2", type="string", example="Upkeep")
|
|
|
|
* @SWG\Property(property="tax_rate1", type="number", format="float", example="17.5")
|
|
|
|
* @SWG\Property(property="tax_rate2", type="number", format="float", example="30.0")
|
|
|
|
* @SWG\Property(property="quote_terms", type="string", example="Labels")
|
|
|
|
* @SWG\Property(property="show_currency_code", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="enable_second_tax_rate", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="start_of_week", type="string", example="Monday")
|
|
|
|
* @SWG\Property(property="financial_year_start", type="string", example="January")
|
|
|
|
* @SWG\Property(property="enabled_modules", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="payment_terms", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="payment_type_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="task_rate", type="number", format="float", example="17.5")
|
|
|
|
* @SWG\Property(property="inclusive_taxes", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="convert_products", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="custom_invoice_taxes1", type="string", example="Value")
|
|
|
|
* @SWG\Property(property="custom_invoice_taxes2", type="string", example="Value")
|
|
|
|
* @SWG\Property(property="custom_fields", type="string", example="Value")
|
|
|
|
*/
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $defaultIncludes = [
|
2017-01-30 20:40:43 +01:00
|
|
|
'user',
|
2015-11-05 09:44:48 +01:00
|
|
|
];
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2018-07-07 21:13:02 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
2018-08-02 21:12:40 +02:00
|
|
|
'users',
|
2018-07-07 21:13:02 +02:00
|
|
|
'tax_rates',
|
|
|
|
'expense_categories',
|
|
|
|
'account_email_settings',
|
2018-08-08 16:49:15 +02:00
|
|
|
'custom_payment_terms',
|
2019-01-30 11:45:46 +01:00
|
|
|
'task_statuses',
|
2018-07-07 21:13:02 +02:00
|
|
|
];
|
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $tokenName;
|
2016-10-21 13:29:01 +02:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
public function __construct(Account $account, $serializer, $tokenName)
|
2015-11-03 15:21:17 +01:00
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
parent::__construct($account, $serializer);
|
2015-11-09 03:10:01 +01:00
|
|
|
|
2015-11-04 16:23:22 +01:00
|
|
|
$this->tokenName = $tokenName;
|
2015-11-03 15:21:17 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
public function includeUser(User $user)
|
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
$transformer = new UserTransformer($this->account, $this->serializer);
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
return $this->includeItem($user, $transformer, 'user');
|
2015-11-05 09:44:48 +01:00
|
|
|
}
|
|
|
|
|
2018-08-02 21:12:40 +02:00
|
|
|
/**
|
|
|
|
* @param Account $account
|
2018-08-08 16:49:15 +02:00
|
|
|
*
|
|
|
|
* @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
|
2018-08-02 21:12:40 +02:00
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeUsers(User $user)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->account, $this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($this->account->users, $transformer, 'users');
|
|
|
|
}
|
|
|
|
|
2019-01-30 11:45:46 +01:00
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeTaskStatuses(User $user)
|
|
|
|
{
|
|
|
|
$transformer = new TaskStatusTransformer($this->account, $this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($this->account->task_statuses, $transformer, 'task_statuses');
|
|
|
|
}
|
|
|
|
|
2018-07-07 21:13:02 +02:00
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeAccountEmailSettings(User $user)
|
|
|
|
{
|
|
|
|
$transformer = new AccountEmailSettingsTransformer($this->account, $this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($this->account->account_email_settings, $transformer, 'account_email_settings');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeExpenseCategories(User $user)
|
|
|
|
{
|
|
|
|
$transformer = new ExpenseCategoryTransformer($this->account, $this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($this->account->expense_categories, $transformer, 'expense_categories');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeTaxRates(User $user)
|
|
|
|
{
|
|
|
|
$transformer = new TaxRateTransformer($this->account, $this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($this->account->tax_rates, $transformer, 'tax_rates');
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:21:17 +01:00
|
|
|
public function transform(User $user)
|
|
|
|
{
|
2018-06-16 20:30:13 +02:00
|
|
|
$account = $user->account;
|
2019-02-17 13:22:00 +01:00
|
|
|
$company = $account->company;
|
2018-06-16 20:30:13 +02:00
|
|
|
|
2015-11-03 15:21:17 +01:00
|
|
|
return [
|
2018-06-16 20:30:13 +02:00
|
|
|
'account_key' => $account->account_key,
|
2018-08-17 07:13:32 +02:00
|
|
|
'user_id' => (int) ($user->public_id + 1),
|
2018-06-28 17:16:11 +02:00
|
|
|
'name' => $account->present()->name ?: '',
|
2018-06-16 20:30:13 +02:00
|
|
|
'token' => $account->getToken($user->id, $this->tokenName),
|
2016-06-21 11:21:50 +02:00
|
|
|
'default_url' => SITE_URL,
|
2019-02-17 12:52:56 +01:00
|
|
|
'plan' => $company->hasActivePlan() && $company->plan ? $company->plan : '',
|
2018-06-28 17:16:11 +02:00
|
|
|
'logo' => $account->logo ?: '',
|
2018-06-28 17:24:20 +02:00
|
|
|
'logo_url' => $account->getLogoURL() ?: '',
|
2018-06-16 20:30:13 +02: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,
|
2018-06-28 17:16:11 +02:00
|
|
|
'invoice_terms' => $account->invoice_terms ?: '',
|
2018-06-16 20:30:13 +02:00
|
|
|
'invoice_taxes' => (bool) $account->invoice_taxes,
|
|
|
|
'invoice_item_taxes' => (bool) $account->invoice_item_taxes,
|
|
|
|
'invoice_design_id' => (int) $account->invoice_design_id,
|
|
|
|
'quote_design_id' => (int) $account->quote_design_id,
|
|
|
|
'language_id' => (int) $account->language_id,
|
2018-07-07 21:13:02 +02:00
|
|
|
'country_id' => (int) $account->country_id,
|
2018-06-28 17:16:11 +02:00
|
|
|
'invoice_footer' => $account->invoice_footer ?: '',
|
|
|
|
'invoice_labels' => $account->invoice_labels ?: '',
|
2018-06-16 20:30:13 +02:00
|
|
|
'show_item_taxes' => (bool) $account->show_item_taxes,
|
|
|
|
'military_time' => (bool) $account->military_time,
|
2019-01-30 11:45:46 +01:00
|
|
|
'fill_products' => (bool) $account->fill_products,
|
2018-06-16 20:30:13 +02:00
|
|
|
'tax_name1' => $account->tax_name1 ?: '',
|
|
|
|
'tax_rate1' => (float) $account->tax_rate1,
|
|
|
|
'tax_name2' => $account->tax_name2 ?: '',
|
|
|
|
'tax_rate2' => (float) $account->tax_rate2,
|
2018-06-28 17:16:11 +02:00
|
|
|
'quote_terms' => $account->quote_terms ?: '',
|
2018-06-16 20:30:13 +02:00
|
|
|
'show_currency_code' => (bool) $account->show_currency_code,
|
|
|
|
'enable_second_tax_rate' => (bool) $account->enable_second_tax_rate,
|
2018-06-28 17:16:11 +02:00
|
|
|
'start_of_week' => (int) $account->start_of_week,
|
2018-09-28 08:51:48 +02:00
|
|
|
'financial_year_start' => (int) $account->financialYearStartMonth(),
|
2018-06-16 20:30:13 +02:00
|
|
|
'enabled_modules' => (int) $account->enabled_modules,
|
|
|
|
'payment_terms' => (int) $account->payment_terms,
|
|
|
|
'payment_type_id' => (int) $account->payment_type_id,
|
|
|
|
'task_rate' => (float) $account->task_rate,
|
2018-07-07 21:13:02 +02:00
|
|
|
'inclusive_taxes' => (bool) $account->inclusive_taxes,
|
2018-06-16 20:30:13 +02:00
|
|
|
'convert_products' => (bool) $account->convert_products,
|
2018-06-28 17:16:11 +02:00
|
|
|
'custom_invoice_taxes1' => (bool) $account->custom_invoice_taxes1,
|
|
|
|
'custom_invoice_taxes2' => (bool) $account->custom_invoice_taxes1,
|
|
|
|
'custom_fields' => $account->custom_fields ?: '',
|
2018-08-11 23:12:21 +02:00
|
|
|
'invoice_fields' => $account->invoice_fields ?: '',
|
|
|
|
'custom_messages' => $account->custom_messages,
|
2018-08-15 13:06:46 +02:00
|
|
|
'email_footer' => $account->getEmailFooter(),
|
|
|
|
'email_subject_invoice' => $account->getEmailSubject(ENTITY_INVOICE),
|
|
|
|
'email_subject_quote' => $account->getEmailSubject(ENTITY_QUOTE),
|
|
|
|
'email_subject_payment' => $account->getEmailSubject(ENTITY_PAYMENT),
|
|
|
|
'email_template_invoice' => $account->getEmailTemplate(ENTITY_INVOICE),
|
|
|
|
'email_template_quote' => $account->getEmailTemplate(ENTITY_QUOTE),
|
|
|
|
'email_template_payment' => $account->getEmailTemplate(ENTITY_PAYMENT),
|
|
|
|
'email_subject_reminder1' => $account->getEmailSubject('reminder1'),
|
|
|
|
'email_subject_reminder2' => $account->getEmailSubject('reminder2'),
|
|
|
|
'email_subject_reminder3' => $account->getEmailSubject('reminder3'),
|
|
|
|
'email_template_reminder1' => $account->getEmailTemplate('reminder1'),
|
|
|
|
'email_template_reminder2' => $account->getEmailTemplate('reminder2'),
|
|
|
|
'email_template_reminder3' => $account->getEmailTemplate('reminder3'),
|
2019-02-17 12:52:56 +01:00
|
|
|
'has_custom_design1' => (bool) $account->custom_design1,
|
|
|
|
'has_custom_design2' => (bool) $account->custom_design2,
|
|
|
|
'has_custom_design3' => (bool) $account->custom_design3,
|
2019-02-19 11:55:39 +01:00
|
|
|
'enable_portal_password' => (bool) $account->enable_portal_password,
|
2015-11-03 15:21:17 +01:00
|
|
|
];
|
|
|
|
}
|
2016-10-21 13:29:01 +02:00
|
|
|
}
|