2019-03-27 05:50:13 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
namespace App\Transformers;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
use App\Models\Account;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Models\Company;
|
2019-06-25 05:55:02 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Models\User;
|
2021-06-08 13:45:23 +02:00
|
|
|
use App\Utils\Ninja;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AccountTransformer.
|
|
|
|
*/
|
|
|
|
class AccountTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 02:09:22 +02:00
|
|
|
use MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2019-06-25 05:55:02 +02:00
|
|
|
//'default_company',
|
2019-09-12 14:02:25 +02:00
|
|
|
//'user',
|
|
|
|
//'company_users'
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2019-03-27 05:50:13 +01:00
|
|
|
'default_company',
|
2019-06-25 05:55:02 +02:00
|
|
|
'company_users',
|
|
|
|
'companies',
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Account $account)
|
|
|
|
{
|
|
|
|
return [
|
2020-09-06 11:38:10 +02:00
|
|
|
'id' => (string) $this->encodePrimaryKey($account->id),
|
2022-10-06 12:08:15 +02:00
|
|
|
'key' => (string) $account->key,
|
2020-03-16 11:12:10 +01:00
|
|
|
'default_url' => config('ninja.app_url'),
|
2019-09-18 14:43:37 +02:00
|
|
|
'plan' => $account->getPlan(),
|
2023-05-18 00:31:21 +02:00
|
|
|
'plan_term' => (string) $account->plan_term,
|
2020-03-25 03:50:08 +01:00
|
|
|
'plan_started' => (string) $account->plan_started,
|
|
|
|
'plan_paid' => (string) $account->plan_paid,
|
|
|
|
'plan_expires' => (string) $account->plan_expires,
|
|
|
|
'user_agent' => (string) $account->user_agent,
|
2023-07-12 06:06:50 +02:00
|
|
|
'payment_id' => (string) $this->encodePrimaryKey($account->payment_id),
|
2020-03-25 03:50:08 +01:00
|
|
|
'trial_started' => (string) $account->trial_started,
|
|
|
|
'trial_plan' => (string) $account->trial_plan,
|
|
|
|
'plan_price' => (float) $account->plan_price,
|
|
|
|
'num_users' => (int) $account->num_users,
|
|
|
|
'utm_source' => (string) $account->utm_source,
|
|
|
|
'utm_medium' => (string) $account->utm_medium,
|
|
|
|
'utm_content' => (string) $account->utm_content,
|
|
|
|
'utm_term' => (string) $account->utm_term,
|
|
|
|
'referral_code' => (string) $account->referral_code,
|
2020-11-11 01:13:39 +01:00
|
|
|
'latest_version' => (string) trim($account->latest_version),
|
2020-09-06 11:38:10 +02:00
|
|
|
'current_version' => (string) config('ninja.app_version'),
|
|
|
|
'updated_at' => (int) $account->updated_at,
|
|
|
|
'archived_at' => (int) $account->deleted_at,
|
|
|
|
'report_errors' => (bool) $account->report_errors,
|
2021-01-05 05:41:43 +01:00
|
|
|
'debug_enabled' => (bool) config('ninja.debug_enabled'),
|
2021-01-18 21:40:54 +01:00
|
|
|
'is_docker' => (bool) config('ninja.is_docker'),
|
2022-01-03 08:22:10 +01:00
|
|
|
'is_scheduler_running' => Ninja::isHosted() ? (bool) true : (bool) $account->is_scheduler_running, //force true for hosted 03/01/2022
|
2021-02-25 01:09:06 +01:00
|
|
|
'default_company_id' => (string) $this->encodePrimaryKey($account->default_company_id),
|
2021-03-16 22:08:23 +01:00
|
|
|
'disable_auto_update' => (bool) config('ninja.disable_auto_update'),
|
2021-08-10 03:40:58 +02:00
|
|
|
'emails_sent' => (int) $account->emailsSent(),
|
|
|
|
'email_quota' => (int) $account->getDailyEmailLimit(),
|
2021-11-10 19:54:59 +01:00
|
|
|
'is_migrated' => (bool) $account->is_migrated,
|
2022-01-28 00:06:07 +01:00
|
|
|
'hosted_client_count' => (int) $account->hosted_client_count,
|
|
|
|
'hosted_company_count' => (int) $account->hosted_company_count,
|
2022-05-01 23:51:39 +02:00
|
|
|
'is_hosted' => (bool) Ninja::isHosted(),
|
2022-07-11 02:42:05 +02:00
|
|
|
'set_react_as_default_ap' => (bool) $account->set_react_as_default_ap,
|
|
|
|
'trial_days_left' => Ninja::isHosted() ? (int) $account->getTrialDays() : 0,
|
2022-07-27 03:21:12 +02:00
|
|
|
'account_sms_verified' => (bool) $account->account_sms_verified,
|
2023-12-15 18:15:55 +01:00
|
|
|
'has_iap_plan' => (bool) $account->inapp_transaction_id,
|
2023-09-14 08:10:54 +02:00
|
|
|
'tax_api_enabled' => (bool) config('services.tax.zip_tax.key') ? true : false
|
2023-05-18 01:19:01 +02:00
|
|
|
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeCompanyUsers(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyUserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($account->company_users, $transformer, CompanyUser::class);
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeDefaultCompany(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($account->default_company, $transformer, Company::class);
|
|
|
|
}
|
2019-04-18 13:57:22 +02:00
|
|
|
|
|
|
|
public function includeUser(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-09-12 13:46:09 +02:00
|
|
|
return $this->includeItem(auth()->user(), $transformer, User::class);
|
2019-04-18 13:57:22 +02:00
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|