1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Transformers/CompanyTransformer.php

134 lines
3.8 KiB
PHP
Raw Normal View History

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;
use App\Models\CompanyUser;
use App\Models\GroupSetting;
2019-03-28 03:36:36 +01:00
use App\Models\User;
use App\Transformers\CompanyUserTransformer;
use App\Transformers\GroupSettingTransformer;
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
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
'users',
'account',
'clients',
'contacts',
'invoices',
'tax_rates',
'products',
'country',
'timezone',
'language',
'expenses',
'payments',
2019-09-11 01:31:55 +02:00
'company_user',
'groups'
2019-03-27 05:50:13 +01:00
];
/**
* @param Company $company
*
* @return array
*/
public function transform(Company $company)
{
return [
2019-10-03 07:42:58 +02:00
'id' => (string)$this->encodePrimaryKey($company->id),
// 'name' => (string)$company->name ?: '',
// 'website' => (string)$company->website ?: '',
// 'logo_url' => (string)$company->getLogo(),
2019-10-03 07:42:58 +02:00
'company_key' => (string)$company->company_key ?: '',
// 'address1' => (string)$company->address1 ?: '',
// 'address2' => (string)$company->address2 ?: '',
// 'city' => (string)$company->city ?: '',
// 'state' => (string)$company->state ?: '',
// 'postal_code' => (string)$company->postal_code ?: '',
// 'phone' => (string)$company->phone ?: '',
// 'email' => (string)$company->email ?: '',
// 'country_id' => (string) $company->country_id ?: '',
// 'vat_number' => (string)$company->vat_number ?: '',
// 'id_number' => (string)$company->id_number ?: '',
2019-09-27 00:14:02 +02:00
'size_id' => (string) $company->size_id ?: '',
'industry_id' => (string) $company->industry_id ?: '',
'settings' => $company->settings ?: '',
2019-10-03 07:42:58 +02:00
'updated_at' => (int)$company->updated_at,
'deleted_at' => (int)$company->deleted_at,
2019-03-27 05:50:13 +01: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 includeGroups(Company $company)
{
$transformer = new GroupSettingTransformer($this->serializer);
return $this->includeCollection($company->groups, $transformer, GroupSetting::class);
}
2019-03-28 03:36:36 +01:00
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
}