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

109 lines
4.0 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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-08-11 08:26:47 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Transformers;
2023-10-26 04:57:44 +02:00
use App\Models\BankTransaction;
2022-08-11 08:26:47 +02:00
use App\Models\Company;
use App\Models\Expense;
2023-08-08 11:44:52 +02:00
use App\Models\Payment;
2023-10-26 04:57:44 +02:00
use App\Models\Vendor;
2022-08-11 08:26:47 +02:00
use App\Utils\Traits\MakesHash;
/**
* Class BankTransactionTransformer.
*/
class BankTransactionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
2023-08-21 03:29:31 +02:00
protected array $defaultIncludes = [
2022-08-11 08:26:47 +02:00
];
/**
* @var array
*/
2023-08-21 03:29:31 +02:00
protected array $availableIncludes = [
2022-08-11 08:26:47 +02:00
'company',
2023-04-06 03:38:29 +02:00
// 'expense',
'payment',
2022-09-21 05:21:52 +02:00
'vendor',
2022-08-11 08:26:47 +02:00
'bank_account',
];
/**
* @param BankTransaction $bank_transaction
2022-08-11 08:26:47 +02:00
* @return array
*/
public function transform(BankTransaction $bank_transaction)
{
return [
'id' => (string) $this->encodePrimaryKey($bank_transaction->id),
2023-02-28 11:42:22 +01:00
'user_id' => (string) $this->encodePrimaryKey($bank_transaction->user_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,
'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 ?: '',
2023-12-15 16:51:24 +01:00
'participant' => (string) $bank_transaction->participant ?: '',
'participant_name' => (string) $bank_transaction->participant_name ?: '',
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 ?: '',
2023-12-13 17:01:34 +01:00
'expense_id' => (string) $bank_transaction->expense_id ?: '',
'payment_id' => (string) $this->encodePrimaryKey($bank_transaction->payment_id) ?: '',
'vendor_id' => (string) $this->encodePrimaryKey($bank_transaction->vendor_id) ?: '',
2022-11-24 21:07:12 +01:00
'bank_transaction_rule_id' => (string) $this->encodePrimaryKey($bank_transaction->bank_transaction_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 includeCompany(BankTransaction $bank_transaction)
{
$transformer = new CompanyTransformer($this->serializer);
return $this->includeItem($bank_transaction->company, $transformer, Company::class);
}
2023-04-06 03:38:29 +02:00
// public function includeExpense(BankTransaction $bank_transaction)
// {
// $transformer = new ExpenseTransformer($this->serializer);
2022-08-11 08:26:47 +02:00
2023-04-06 03:38:29 +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
}
public function includePayment(BankTransaction $bank_transaction)
{
$transformer = new PaymentTransformer($this->serializer);
return $this->includeItem($bank_transaction->payment, $transformer, Payment::class);
}
2022-08-11 08:26:47 +02:00
}