1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Transformers/ClientTransformer.php

92 lines
3.0 KiB
PHP
Raw Normal View History

2019-03-28 22:35:35 +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-28 22:35:35 +01:00
namespace App\Transformers;
use App\Models\Client;
use App\Models\ClientContact;
2019-04-03 02:09:22 +02:00
use App\Utils\Traits\MakesHash;
2019-03-28 22:35:35 +01:00
/**
* class ClientTransformer
2019-03-28 22:35:35 +01:00
*/
class ClientTransformer extends EntityTransformer
{
2019-04-03 02:09:22 +02:00
use MakesHash;
2019-03-28 22:35:35 +01:00
protected $defaultIncludes = [
'contacts',
];
/**
* @var array
*/
protected $availableIncludes = [
];
/**
* @param Client $client
*
* @return \League\Fractal\Resource\Collection
*/
public function includeContacts(Client $client)
{
$transformer = new ClientContactTransformer($this->serializer);
return $this->includeCollection($client->contacts, $transformer, ClientContact::class);
}
/**
* @param Client $client
*
* @return array
*/
public function transform(Client $client)
{
return [
2019-04-03 02:09:22 +02:00
'id' => $this->encodePrimaryKey($client->id),
2019-03-28 22:35:35 +01:00
'name' => $client->name ?: '',
2019-03-29 05:14:58 +01:00
'website' => $client->website ?: '',
'private_notes' => $client->private_notes ?: '',
2019-10-02 10:38:33 +02:00
'balance' => (float) $client->balance,
'currency_id' => (string)$client->currency_id ?: '',
2019-10-07 08:16:41 +02:00
'group_settings_id' => (string)$client->group_settings_id ?: '',
2019-10-02 10:38:33 +02:00
'paid_to_date' => (float) $client->paid_to_date,
2019-10-04 13:01:52 +02:00
'last_login' => (int)$client->last_login,
2019-03-29 05:14:58 +01:00
'address1' => $client->address1 ?: '',
'address2' => $client->address2 ?: '',
'city' => $client->city ?: '',
'state' => $client->state ?: '',
'postal_code' => $client->postal_code ?: '',
'country_id' => $client->country_id ?: '',
2019-09-26 15:00:51 +02:00
'industry_id' => $client->industry_id ?: '',
2019-03-29 05:14:58 +01:00
'custom_value1' => $client->custom_value1 ?: '',
'custom_value2' => $client->custom_value2 ?: '',
'custom_value3' => $client->custom_value3 ?: '',
'custom_value4' => $client->custom_value4 ?: '',
'shipping_address1' => $client->shipping_address1 ?: '',
'shipping_address2' => $client->shipping_address2 ?: '',
'shipping_city' => $client->shipping_city ?: '',
'shipping_state' => $client->shipping_state ?: '',
'shipping_postal_code' => $client->shipping_postal_code ?: '',
'shipping_country_id' => $client->shipping_country_id ?: '',
'settings' => $client->settings ?: '',
2019-10-02 10:38:33 +02:00
'is_deleted' => (bool) $client->is_deleted,
2019-03-29 05:14:58 +01:00
'vat_number' => $client->vat_number ?: '',
'id_number' => $client->id_number ?: '',
2019-10-02 11:04:27 +02:00
'updated_at' => $client->updated_at,
'deleted_at' => $client->deleted_at,
2019-10-02 11:44:11 +02:00
'display_name' => $client->present()->name()
2019-03-28 22:35:35 +01:00
];
}
2019-03-29 05:14:58 +01:00
}