2019-03-27 05:50:13 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2019-04-03 03:17:21 +02:00
|
|
|
use App\Models\Company;
|
2019-06-24 02:13:53 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\User;
|
2019-06-24 02:13:53 +02:00
|
|
|
use App\Transformers\CompanyUserTransformer;
|
2019-03-27 05:50:13 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
|
|
|
/**
|
2019-03-28 03:36:36 +01:00
|
|
|
* Class AccountTranCompanyTransformersformer.
|
2019-03-27 05:50:13 +01:00
|
|
|
*/
|
|
|
|
class CompanyTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 03:17:21 +02:00
|
|
|
use MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @SWG\Property(property="account_key", type="string", example="123456")
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'users',
|
|
|
|
'account',
|
|
|
|
'clients',
|
|
|
|
'contacts',
|
|
|
|
'invoices',
|
|
|
|
'tax_rates',
|
|
|
|
'products',
|
|
|
|
'country',
|
|
|
|
'timezone',
|
|
|
|
'language',
|
|
|
|
'expenses',
|
|
|
|
'payments',
|
2019-06-24 02:13:53 +02:00
|
|
|
'company_user'
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Company $company
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Company $company)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->encodePrimaryKey($company->id),
|
|
|
|
'name' => $company->name,
|
2019-06-26 05:25:14 +02:00
|
|
|
'logo' => $company->logo,
|
2019-03-27 05:50:13 +01:00
|
|
|
'company_key' => $company->company_key,
|
|
|
|
'address1' => $company->address1,
|
|
|
|
'address2' => $company->address2,
|
|
|
|
'city' => $company->city,
|
|
|
|
'state' => $company->state,
|
|
|
|
'postal_code' => $company->postal_code,
|
|
|
|
'work_phone' => $company->work_phone,
|
|
|
|
'work_email' => $company->work_email,
|
|
|
|
'country_id' => (int) $company->country_id,
|
|
|
|
'subdomain' => $company->subdomain,
|
|
|
|
'db' => $company->db,
|
|
|
|
'vat_number' => $company->vat_number,
|
|
|
|
'id_number' => $company->id_number,
|
|
|
|
'size_id' => (int) $company->size_id,
|
|
|
|
'industry_id' => (int) $company->industry_id,
|
|
|
|
'settings' => $company->settings,
|
2019-04-03 03:17:21 +02:00
|
|
|
'updated_at' => $company->updated_at,
|
|
|
|
'deleted_at' => $company->deleted_at,
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-06-24 02:13:53 +02:00
|
|
|
public function includeCompanyUser(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyUserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company->company_users->where('user_id', auth()->user()->id)->first(), $transformer, CompanyUser::class);
|
|
|
|
|
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeUsers(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->users, $transformer, User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeClients(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new ClientTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->clients, $transformer, Client::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeInvoices(Company $company)
|
|
|
|
{
|
|
|
|
$transformer = new InvoiceTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($company->invoices, $transformer, Invoice::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeAccount(Company $company)
|
|
|
|
{
|
|
|
|
|
|
|
|
$transformer = new AccountTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company->account, $transformer, Account::class);
|
|
|
|
|
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|