2019-03-28 22:35:35 +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-28 22:35:35 +01:00
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
2019-11-12 05:41:02 +01:00
|
|
|
use App\Models\Activity;
|
2019-03-28 22:35:35 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\ClientContact;
|
2019-10-25 11:49:38 +02:00
|
|
|
use App\Models\ClientGatewayToken;
|
2020-04-11 13:19:05 +02:00
|
|
|
use App\Models\CompanyLedger;
|
2020-08-06 05:04:09 +02:00
|
|
|
use App\Models\Document;
|
2023-10-18 09:42:16 +02:00
|
|
|
use App\Models\GroupSetting;
|
2020-08-24 04:45:53 +02:00
|
|
|
use App\Models\SystemLog;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-10-28 11:10:49 +01:00
|
|
|
use stdClass;
|
2019-03-28 22:35:35 +01:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02: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-08-26 10:25:05 +02:00
|
|
|
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2019-03-28 22:35:35 +01:00
|
|
|
'contacts',
|
2020-08-06 05:04:09 +02:00
|
|
|
'documents',
|
2020-08-12 00:17:32 +02:00
|
|
|
'gateway_tokens',
|
2019-03-28 22:35:35 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2019-11-12 05:41:02 +01:00
|
|
|
'activities',
|
2020-04-11 13:19:05 +02:00
|
|
|
'ledger',
|
2020-08-24 04:45:53 +02:00
|
|
|
'system_logs',
|
2023-10-18 09:42:16 +02:00
|
|
|
'group_settings',
|
2019-03-28 22:35:35 +01:00
|
|
|
];
|
|
|
|
|
2019-11-12 05:41:02 +01:00
|
|
|
/**
|
|
|
|
* @param Client $client
|
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\Collection
|
2019-11-12 05:41:02 +01:00
|
|
|
*/
|
|
|
|
public function includeActivities(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new ActivityTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($client->activities, $transformer, Activity::class);
|
|
|
|
}
|
|
|
|
|
2020-08-06 05:04:09 +02:00
|
|
|
public function includeDocuments(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new DocumentTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($client->documents, $transformer, Document::class);
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-03-28 22:35:35 +01:00
|
|
|
/**
|
|
|
|
* @param Client $client
|
|
|
|
*
|
2023-07-26 04:59:36 +02:00
|
|
|
* @return \Illuminate\Support\Collection
|
2019-03-28 22:35:35 +01:00
|
|
|
*/
|
|
|
|
public function includeContacts(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new ClientContactTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($client->contacts, $transformer, ClientContact::class);
|
|
|
|
}
|
|
|
|
|
2019-10-25 11:49:38 +02:00
|
|
|
public function includeGatewayTokens(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new ClientGatewayTokenTransformer($this->serializer);
|
2019-03-28 22:35:35 +01:00
|
|
|
|
2019-10-25 11:49:38 +02:00
|
|
|
return $this->includeCollection($client->gateway_tokens, $transformer, ClientGatewayToken::class);
|
|
|
|
}
|
2020-04-11 13:19:05 +02:00
|
|
|
|
|
|
|
public function includeLedger(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyLedgerTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($client->ledger, $transformer, CompanyLedger::class);
|
|
|
|
}
|
2020-08-24 04:45:53 +02:00
|
|
|
|
|
|
|
public function includeSystemLogs(Client $client)
|
|
|
|
{
|
|
|
|
$transformer = new SystemLogTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($client->system_logs, $transformer, SystemLog::class);
|
|
|
|
}
|
|
|
|
|
2023-10-18 09:42:16 +02:00
|
|
|
public function includeGroupSettings(Client $client)
|
|
|
|
{
|
2023-10-26 04:57:44 +02:00
|
|
|
if (!$client->group_settings) {
|
2023-10-18 09:42:16 +02:00
|
|
|
return null;
|
2023-10-26 04:57:44 +02:00
|
|
|
}
|
2023-10-18 09:42:16 +02:00
|
|
|
|
|
|
|
$transformer = new GroupSettingTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($client->group_settings, $transformer, GroupSetting::class);
|
|
|
|
}
|
|
|
|
|
2019-03-28 22:35:35 +01:00
|
|
|
/**
|
|
|
|
* @param Client $client
|
|
|
|
*
|
|
|
|
* @return array
|
2020-10-28 11:10:49 +01:00
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException
|
2019-03-28 22:35:35 +01:00
|
|
|
*/
|
|
|
|
public function transform(Client $client)
|
|
|
|
{
|
|
|
|
return [
|
2019-04-03 02:09:22 +02:00
|
|
|
'id' => $this->encodePrimaryKey($client->id),
|
2019-11-06 23:57:09 +01:00
|
|
|
'user_id' => $this->encodePrimaryKey($client->user_id),
|
|
|
|
'assigned_user_id' => $this->encodePrimaryKey($client->assigned_user_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,
|
2020-09-06 11:38:10 +02:00
|
|
|
'group_settings_id' => isset($client->group_settings_id) ? (string) $this->encodePrimaryKey($client->group_settings_id) : '',
|
2019-10-02 10:38:33 +02:00
|
|
|
'paid_to_date' => (float) $client->paid_to_date,
|
2023-03-09 22:38:02 +01:00
|
|
|
'payment_balance' => (float) $client->payment_balance,
|
2019-12-01 12:23:24 +01:00
|
|
|
'credit_balance' => (float) $client->credit_balance,
|
2020-09-06 11:38:10 +02:00
|
|
|
'last_login' => (int) $client->last_login,
|
|
|
|
'size_id' => (string) $client->size_id,
|
2020-02-26 07:46:27 +01:00
|
|
|
'public_notes' => $client->public_notes ?: '',
|
2022-06-21 11:57:17 +02:00
|
|
|
'client_hash' => (string) $client->client_hash,
|
2019-03-29 05:14:58 +01:00
|
|
|
'address1' => $client->address1 ?: '',
|
|
|
|
'address2' => $client->address2 ?: '',
|
2019-10-25 11:49:38 +02:00
|
|
|
'phone' => $client->phone ?: '',
|
2019-03-29 05:14:58 +01:00
|
|
|
'city' => $client->city ?: '',
|
|
|
|
'state' => $client->state ?: '',
|
|
|
|
'postal_code' => $client->postal_code ?: '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'country_id' => (string) $client->country_id ?: '',
|
|
|
|
'industry_id' => (string) $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 ?: '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'shipping_country_id' => (string) $client->shipping_country_id ?: '',
|
2020-10-28 11:10:49 +01:00
|
|
|
'settings' => $client->settings ?: new stdClass,
|
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 ?: '',
|
2020-09-06 11:38:10 +02:00
|
|
|
'updated_at' => (int) $client->updated_at,
|
|
|
|
'archived_at' => (int) $client->deleted_at,
|
|
|
|
'created_at' => (int) $client->created_at,
|
|
|
|
'display_name' => $client->present()->name(),
|
2021-01-25 11:34:12 +01:00
|
|
|
'number' => (string) $client->number ?: '',
|
2023-03-27 05:47:01 +02:00
|
|
|
'has_valid_vat_number' => (bool) $client->has_valid_vat_number,
|
|
|
|
'is_tax_exempt' => (bool) $client->is_tax_exempt,
|
2023-04-28 03:39:41 +02:00
|
|
|
'routing_id' => (string) $client->routing_id,
|
2023-07-22 08:55:18 +02:00
|
|
|
'tax_info' => $client->tax_data ?: new \stdClass,
|
2023-09-11 03:05:05 +02:00
|
|
|
'classification' => $client->classification ?: '',
|
2019-03-28 22:35:35 +01:00
|
|
|
];
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|