1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 17:31:35 +02:00
invoiceninja/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php

177 lines
3.8 KiB
PHP
Raw Normal View History

2022-08-05 05:45:53 +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\Helpers\Bank\Yodlee\Transformer;
2022-08-08 04:46:41 +02:00
use App\Helpers\Bank\BankRevenueInterface;
2022-09-22 07:54:58 +02:00
use App\Utils\Traits\AppSetup;
use Illuminate\Support\Facades\Cache;
2022-08-05 05:45:53 +02:00
/**
"date": "string",
"sourceId": "string",
"symbol": "string",
"cusipNumber": "string",
"highLevelCategoryId": 0,
"detailCategoryId": 0,
"description": {},
"memo": "string",
"settleDate": "string",
"type": "string",
"intermediary": [],
"baseType": "CREDIT",
"categorySource": "SYSTEM",
"principal": {},
"lastUpdated": "string",
"interest": {},
"price": {},
"commission": {},
"id": 0,
"merchantType": "string",
"amount": {
"amount": 0,
"convertedAmount": 0,
"currency": "USD",
"convertedCurrency": "USD"
},
"checkNumber": "string",
"isPhysical": true,
"quantity": 0,
"valoren": "string",
"isManual": true,
"merchant": {
"website": "string",
"address": {},
"contact": {},
"categoryLabel": [],
"coordinates": {},
"name": "string",
"id": "string",
"source": "YODLEE",
"logoURL": "string"
},
"sedol": "string",
"transactionDate": "string",
"categoryType": "TRANSFER",
"accountId": 0,
"createdDate": "string",
"sourceType": "AGGREGATED",
"CONTAINER": "bank",
"postDate": "string",
"parentCategoryId": 0,
"subType": "OVERDRAFT_CHARGE",
"category": "string",
"runningBalance": {},
"categoryId": 0,
"holdingDescription": "string",
"isin": "string",
"status": "POSTED"
2022-08-08 04:46:41 +02:00
(
[CONTAINER] => bank
[id] => 103953585
[amount] => stdClass Object
(
[amount] => 480.66
[currency] => USD
)
[categoryType] => UNCATEGORIZE
[categoryId] => 1
[category] => Uncategorized
[categorySource] => SYSTEM
[highLevelCategoryId] => 10000017
[createdDate] => 2022-08-04T21:50:17Z
[lastUpdated] => 2022-08-04T21:50:17Z
[description] => stdClass Object
(
[original] => CHEROKEE NATION TAX TA TAHLEQUAH OK
)
[isManual] =>
[sourceType] => AGGREGATED
[date] => 2022-08-03
[transactionDate] => 2022-08-03
[postDate] => 2022-08-03
[status] => POSTED
[accountId] => 12331794
[runningBalance] => stdClass Object
(
[amount] => 480.66
[currency] => USD
)
[checkNumber] => 998
)
*/
2022-08-05 05:45:53 +02:00
2022-08-08 04:46:41 +02:00
class IncomeTransformer implements BankRevenueInterface
2022-08-05 05:45:53 +02:00
{
2022-09-22 07:54:58 +02:00
use AppSetup;
2022-08-05 05:45:53 +02:00
2022-08-08 04:46:41 +02:00
public function transform($transaction)
{
$data = [];
2022-08-11 04:39:43 +02:00
if(!property_exists($transaction, 'transaction'))
2022-08-11 06:19:35 +02:00
return $data;
2022-08-11 04:39:43 +02:00
2022-08-08 04:46:41 +02:00
foreach($transaction->transaction as $transaction)
{
$data[] = $this->transformTransaction($transaction);
}
return $data;
}
public function transformTransaction($transaction)
{
2022-09-21 09:00:49 +02:00
2022-08-08 04:46:41 +02:00
return [
2022-08-12 05:41:55 +02:00
'transaction_id' => $transaction->id,
2022-08-08 04:46:41 +02:00
'amount' => $transaction->amount->amount,
2022-09-22 07:54:58 +02:00
'currency_id' => $this->convertCurrency($transaction->amount->currency),
2022-08-08 04:46:41 +02:00
'account_type' => $transaction->CONTAINER,
2022-09-15 08:15:57 +02:00
'category_id' => $transaction->highLevelCategoryId,
2022-08-08 04:46:41 +02:00
'category_type' => $transaction->categoryType,
'date' => $transaction->date,
2022-08-12 05:41:55 +02:00
'bank_account_id' => $transaction->accountId,
2022-08-08 04:46:41 +02:00
'description' => $transaction->description->original,
2022-09-21 09:00:49 +02:00
'base_type' => property_exists($transaction, 'baseType') ? $transaction->baseType : '',
2022-08-08 04:46:41 +02:00
];
}
2022-09-22 07:54:58 +02:00
private function convertCurrency(string $code)
{
$currencies = Cache::get('currencies');
if (! $currencies) {
$this->buildCache(true);
}
$currency = $currencies->filter(function ($item) use($code){
return $item->code == $code;
})->first();
if($currency)
return $currency->id;
return 1;
}
2022-08-05 05:45:53 +02:00
}