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\BankTransaction;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Expense;
|
|
|
|
use App\Models\Invoice;
|
2022-09-21 05:21:52 +02:00
|
|
|
use App\Transformers\VendorTransformer;
|
2022-08-11 08:26:47 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BankTransactionTransformer.
|
|
|
|
*/
|
|
|
|
class BankTransactionTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'company',
|
|
|
|
'account',
|
|
|
|
'expense',
|
2022-09-21 05:21:52 +02:00
|
|
|
'vendor',
|
2022-08-11 08:26:47 +02:00
|
|
|
'bank_account',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param BankTransaction $bank_integration
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(BankTransaction $bank_transaction)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => (string) $this->encodePrimaryKey($bank_transaction->id),
|
2022-09-14 09:40:34 +02:00
|
|
|
'bank_integration_id' => (string) $this->encodePrimaryKey($bank_transaction->bank_integration_id),
|
2022-08-12 03:40:35 +02:00
|
|
|
'transaction_id' => (int) $bank_transaction->transaction_id,
|
|
|
|
'amount' => (float) $bank_transaction->amount ?: 0,
|
2022-09-22 07:54:58 +02:00
|
|
|
'currency_id' => (string) $bank_transaction->currency_id ?: '1',
|
2022-08-12 03:40:35 +02:00
|
|
|
'account_type' => (string) $bank_transaction->account_type ?: '',
|
2022-08-11 08:26:47 +02:00
|
|
|
'category_id' => (int) $bank_transaction->category_id,
|
2022-09-23 04:30:53 +02:00
|
|
|
'ninja_category_id' => (string) $this->encodePrimaryKey($bank_transaction->ninja_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,
|
2022-09-22 07:54:58 +02:00
|
|
|
'status_id' => (string) $bank_transaction->status_id,
|
2022-08-12 03:40:35 +02:00
|
|
|
'description' => (string) $bank_transaction->description ?: '',
|
2022-08-12 05:41:55 +02:00
|
|
|
'base_type' => (string) $bank_transaction->base_type ?: '',
|
2022-09-21 05:21:52 +02:00
|
|
|
'invoice_ids' => (string) $bank_transaction->invoice_ids ?: '',
|
2022-08-12 03:40:35 +02:00
|
|
|
'expense_id'=> (string) $this->encodePrimaryKey($bank_transaction->expense_id) ?: '',
|
2022-09-21 05:21:52 +02:00
|
|
|
'vendor_id'=> (string) $this->encodePrimaryKey($bank_transaction->vendor_id) ?: '',
|
2022-11-23 03:12:35 +01:00
|
|
|
'bank_rule_id' => (string) $this->encodePrimaryKey($bank_transaction->bank_rule_id) ?: '',
|
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);
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
public function includeExpense(BankTransaction $bank_transaction)
|
2022-08-11 08:26:47 +02:00
|
|
|
{
|
2022-09-21 05:21:52 +02:00
|
|
|
$transformer = new ExpenseTransformer($this->serializer);
|
2022-08-11 08:26:47 +02:00
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
return $this->includeItem($bank_transaction->expense, $transformer, Expense::class);
|
2022-08-11 08:26:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
public function includeVendor(BankTransaction $bank_transaction)
|
2022-08-11 08:26:47 +02:00
|
|
|
{
|
2022-09-21 05:21:52 +02:00
|
|
|
$transformer = new VendorTransformer($this->serializer);
|
2022-08-11 08:26:47 +02:00
|
|
|
|
2022-09-21 05:21:52 +02:00
|
|
|
return $this->includeItem($bank_transaction->vendor, $transformer, Vendor::class);
|
2022-08-11 08:26:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|