1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Transformers/BankIntegrationTransformer.php

93 lines
3.1 KiB
PHP
Raw Normal View History

2022-08-05 06:25:06 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Transformers;
use App\Models\Account;
use App\Models\BankIntegration;
use App\Utils\Traits\MakesHash;
/**
* Class BankIntegrationTransformer.
*/
class BankIntegrationTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
//'default_company',
//'user',
//'company_users'
];
/**
* @var array
*/
protected $availableIncludes = [
'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,
'disabled_upstream' => (bool) $bank_integration->disabled_upstream,
'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
}