mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
ba75a44eb8
* Adopt Laravel coding style The Laravel framework adopts the PSR-2 coding style with some additions. Laravel apps *should* adopt this coding style as well. However, Shift allows you to customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config to your project. You may use [Shift's .php_cs][2] file as a base. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 * Shift bindings PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser. * Shift core files * Shift to Throwable * Add laravel/ui dependency * Unindent vendor mail templates * Shift config files * Default config files In an effort to make upgrading the constantly changing config files easier, Shift defaulted them so you can review the commit diff for changes. Moving forward, you should use ENV variables or create a separate config file to allow the core config files to remain automatically upgradeable. * Shift Laravel dependencies * Shift cleanup * Upgrade to Laravel 7 Co-authored-by: Laravel Shift <shift@laravelshift.com>
155 lines
5.2 KiB
PHP
155 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\Activity;
|
|
use App\Models\Client;
|
|
use App\Models\ClientContact;
|
|
use App\Models\ClientGatewayToken;
|
|
use App\Models\CompanyLedger;
|
|
use App\Models\Document;
|
|
use App\Models\SystemLog;
|
|
use App\Transformers\ActivityTransformer;
|
|
use App\Transformers\ClientGatewayTokenTransformer;
|
|
use App\Transformers\CompanyLedgerTransformer;
|
|
use App\Transformers\DocumentTransformer;
|
|
use App\Transformers\SystemLogTransformer;
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
/**
|
|
* class ClientTransformer.
|
|
*/
|
|
class ClientTransformer extends EntityTransformer
|
|
{
|
|
use MakesHash;
|
|
|
|
protected $defaultIncludes = [
|
|
'contacts',
|
|
'documents',
|
|
'gateway_tokens',
|
|
];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $availableIncludes = [
|
|
'documents',
|
|
'gateway_tokens',
|
|
'activities',
|
|
'ledger',
|
|
'system_logs',
|
|
];
|
|
|
|
/**
|
|
* @param Client $client
|
|
*
|
|
* @return \League\Fractal\Resource\Collection
|
|
*/
|
|
public function includeActivities(Client $client)
|
|
{
|
|
$transformer = new ActivityTransformer($this->serializer);
|
|
|
|
return $this->includeCollection($client->activities, $transformer, Activity::class);
|
|
}
|
|
|
|
public function includeDocuments(Client $client)
|
|
{
|
|
$transformer = new DocumentTransformer($this->serializer);
|
|
|
|
return $this->includeCollection($client->documents, $transformer, Document::class);
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
}
|
|
|
|
public function includeGatewayTokens(Client $client)
|
|
{
|
|
$transformer = new ClientGatewayTokenTransformer($this->serializer);
|
|
|
|
return $this->includeCollection($client->gateway_tokens, $transformer, ClientGatewayToken::class);
|
|
}
|
|
|
|
public function includeLedger(Client $client)
|
|
{
|
|
$transformer = new CompanyLedgerTransformer($this->serializer);
|
|
|
|
return $this->includeCollection($client->ledger, $transformer, CompanyLedger::class);
|
|
}
|
|
|
|
public function includeSystemLogs(Client $client)
|
|
{
|
|
$transformer = new SystemLogTransformer($this->serializer);
|
|
|
|
return $this->includeCollection($client->system_logs, $transformer, SystemLog::class);
|
|
}
|
|
|
|
/**
|
|
* @param Client $client
|
|
*
|
|
* @return array
|
|
*/
|
|
public function transform(Client $client)
|
|
{
|
|
return [
|
|
'id' => $this->encodePrimaryKey($client->id),
|
|
'user_id' => $this->encodePrimaryKey($client->user_id),
|
|
'assigned_user_id' => $this->encodePrimaryKey($client->assigned_user_id),
|
|
'name' => $client->name ?: '',
|
|
'website' => $client->website ?: '',
|
|
'private_notes' => $client->private_notes ?: '',
|
|
'balance' => (float) $client->balance,
|
|
'group_settings_id' => isset($client->group_settings_id) ? (string) $this->encodePrimaryKey($client->group_settings_id) : '',
|
|
'paid_to_date' => (float) $client->paid_to_date,
|
|
'credit_balance' => (float) $client->credit_balance,
|
|
'last_login' => (int) $client->last_login,
|
|
'size_id' => (string) $client->size_id,
|
|
'public_notes' => $client->public_notes ?: '',
|
|
// 'currency_id' => (string)$client->currency_id,
|
|
'address1' => $client->address1 ?: '',
|
|
'address2' => $client->address2 ?: '',
|
|
'phone' => $client->phone ?: '',
|
|
'city' => $client->city ?: '',
|
|
'state' => $client->state ?: '',
|
|
'postal_code' => $client->postal_code ?: '',
|
|
'country_id' => (string) $client->country_id ?: '',
|
|
'industry_id' => (string) $client->industry_id ?: '',
|
|
'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' => (string) $client->shipping_country_id ?: '',
|
|
'settings' => $client->settings ?: new \stdClass,
|
|
'is_deleted' => (bool) $client->is_deleted,
|
|
'vat_number' => $client->vat_number ?: '',
|
|
'id_number' => $client->id_number ?: '',
|
|
'updated_at' => (int) $client->updated_at,
|
|
'archived_at' => (int) $client->deleted_at,
|
|
'created_at' => (int) $client->created_at,
|
|
'display_name' => $client->present()->name(),
|
|
];
|
|
}
|
|
}
|