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

103 lines
3.3 KiB
PHP
Raw Normal View History

2022-08-11 08:26:47 +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\Models\BankTransaction;
use App\Models\Company;
use App\Models\Expense;
use App\Models\Invoice;
use App\Utils\Traits\MakesHash;
/**
* Class BankTransactionTransformer.
*/
class BankTransactionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
'company',
'account',
'invoice',
'expense',
'bank_account',
];
/**
* @param BankTransaction $bank_integration
* @return array
*/
public function transform(BankTransaction $bank_transaction)
{
return [
'id' => (string) $this->encodePrimaryKey($bank_transaction->id),
2022-08-12 03:40:35 +02:00
'transaction_id' => (int) $bank_transaction->transaction_id,
'amount' => (float) $bank_transaction->amount ?: 0,
'currency_code' => (string) $bank_transaction->currency_code ?: '',
'account_type' => (string) $bank_transaction->account_type ?: '',
2022-08-11 08:26:47 +02:00
'category_id' => (int) $bank_transaction->category_id,
2022-08-12 03:40:35 +02:00
'category_type' => (string) $bank_transaction->category_type ?: '',
'date' => (string) $bank_transaction->date ?: '',
'bank_account_id' => (int) $bank_transaction->bank_account_id,
'description' => (string) $bank_transaction->description ?: '',
2022-08-12 05:41:55 +02:00
'base_type' => (string) $bank_transaction->base_type ?: '',
2022-08-12 03:40:35 +02:00
'invoice_id' => (string) $this->encodePrimaryKey($bank_transaction->invoice_id) ?: '',
'expense_id'=> (string) $this->encodePrimaryKey($bank_transaction->expense_id) ?: '',
'is_matched'=> (bool) $bank_transaction->is_matched ?: '',
2022-08-11 09:18:53 +02:00
'is_deleted' => (bool) $bank_transaction->is_deleted,
'created_at' => (int) $bank_transaction->created_at,
'updated_at' => (int) $bank_transaction->updated_at,
'archived_at' => (int) $bank_transaction->deleted_at,
2022-08-11 08:26:47 +02:00
];
}
public function includeAccount(BankTransaction $bank_transaction)
{
$transformer = new AccountTransformer($this->serializer);
return $this->includeItem($bank_transaction->account, $transformer, Account::class);
}
public function includeCompany(BankTransaction $bank_transaction)
{
$transformer = new CompanyTransformer($this->serializer);
return $this->includeItem($bank_transaction->company, $transformer, Company::class);
}
public function includeInvoice(BankTransaction $bank_transaction)
{
$transformer = new InvoiceTransformer($this->serializer);
return $this->includeItem($bank_transaction->invoice, $transformer, Invoice::class);
}
public function includeExpense(BankTransaction $bank_transaction)
{
$transformer = new ExpenseTransformer($this->serializer);
return $this->includeItem($bank_transaction->expense, $transformer, Expense::class);
}
}