2022-08-05 06:25:06 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @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)
|
2022-08-05 06:25:06 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\BankIntegration;
|
2023-08-08 12:39:46 +02:00
|
|
|
use App\Models\BankTransaction;
|
2023-10-26 04:57:44 +02:00
|
|
|
use App\Models\Company;
|
2022-08-05 06:25:06 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BankIntegrationTransformer.
|
|
|
|
*/
|
|
|
|
class BankIntegrationTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2022-08-05 06:25:06 +02:00
|
|
|
//'default_company',
|
|
|
|
//'user',
|
|
|
|
//'company_users'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2022-08-05 06:25:06 +02:00
|
|
|
'company',
|
|
|
|
'account',
|
2022-08-12 03:40:35 +02:00
|
|
|
'bank_transactions',
|
2022-08-05 06:25:06 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2022-08-11 03:49:39 +02:00
|
|
|
* @param BankIntegration $bank_integration
|
2022-08-05 06:25:06 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(BankIntegration $bank_integration)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => (string) $this->encodePrimaryKey($bank_integration->id),
|
2022-08-11 06:19:35 +02:00
|
|
|
'provider_name' => (string)$bank_integration->provider_name ?: '',
|
2022-08-11 03:49:39 +02:00
|
|
|
'provider_id' => (int) $bank_integration->provider_id ?: 0,
|
|
|
|
'bank_account_id' => (int) $bank_integration->bank_account_id ?: 0,
|
|
|
|
'bank_account_name' => (string) $bank_integration->bank_account_name ?: '',
|
|
|
|
'bank_account_number' => (string) $bank_integration->bank_account_number ?: '',
|
|
|
|
'bank_account_status' => (string)$bank_integration->bank_account_status ?: '',
|
|
|
|
'bank_account_type' => (string)$bank_integration->bank_account_type ?: '',
|
2022-08-05 06:25:06 +02:00
|
|
|
'balance' => (float)$bank_integration->balance ?: 0,
|
2022-08-11 03:49:39 +02:00
|
|
|
'currency' => (string)$bank_integration->currency ?: '',
|
|
|
|
'nickname' => (string)$bank_integration->nickname ?: '',
|
2022-08-12 03:40:35 +02:00
|
|
|
'from_date' => (string)$bank_integration->from_date ?: '',
|
2022-08-11 06:19:35 +02:00
|
|
|
'is_deleted' => (bool) $bank_integration->is_deleted,
|
2022-11-04 02:55:17 +01:00
|
|
|
'disabled_upstream' => (bool) $bank_integration->disabled_upstream,
|
2022-11-08 11:48:29 +01:00
|
|
|
'auto_sync' => (bool)$bank_integration->auto_sync,
|
2022-08-11 06:19:35 +02:00
|
|
|
'created_at' => (int) $bank_integration->created_at,
|
|
|
|
'updated_at' => (int) $bank_integration->updated_at,
|
|
|
|
'archived_at' => (int) $bank_integration->deleted_at,
|
2022-08-05 06:25:06 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeAccount(BankIntegration $bank_integration)
|
|
|
|
{
|
|
|
|
$transformer = new AccountTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($bank_integration->account, $transformer, Account::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeCompany(BankIntegration $bank_integration)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($bank_integration->company, $transformer, Company::class);
|
|
|
|
}
|
|
|
|
|
2022-08-12 03:40:35 +02:00
|
|
|
public function includeBankTransactions(BankIntegration $bank_integration)
|
|
|
|
{
|
|
|
|
$transformer = new BankTransactionTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($bank_integration->transactions, $transformer, BankTransaction::class);
|
|
|
|
}
|
2022-08-05 06:25:06 +02:00
|
|
|
}
|