mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #9304 from paulwer/feat-translations-for-nordigen-transaction-transformer
Feat: translations for nordigen transaction transformer - exchange rate
This commit is contained in:
commit
8bbccdc964
@ -19,6 +19,7 @@
|
||||
|
||||
namespace App\Helpers\Bank\Nordigen;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Services\Email\Email;
|
||||
use App\Models\BankIntegration;
|
||||
use App\Services\Email\EmailObject;
|
||||
@ -138,11 +139,11 @@ class Nordigen
|
||||
* @param string $dateFrom
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(string $accountId, string $dateFrom = null): array
|
||||
public function getTransactions(Company $company, string $accountId, string $dateFrom = null): array
|
||||
{
|
||||
$transactionResponse = $this->client->account($accountId)->getAccountTransactions($dateFrom);
|
||||
|
||||
$it = new TransactionTransformer();
|
||||
$it = new TransactionTransformer($company);
|
||||
return $it->transform($transactionResponse);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,10 @@
|
||||
namespace App\Helpers\Bank\Nordigen\Transformer;
|
||||
|
||||
use App\Helpers\Bank\BankRevenueInterface;
|
||||
use App\Models\BankIntegration;
|
||||
use App\Models\Company;
|
||||
use App\Models\DateFormat;
|
||||
use App\Models\Timezone;
|
||||
use Carbon\Carbon;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Log;
|
||||
@ -66,6 +69,13 @@ class TransactionTransformer implements BankRevenueInterface
|
||||
{
|
||||
use AppSetup;
|
||||
|
||||
private Company $company;
|
||||
|
||||
function __construct(Company $company)
|
||||
{
|
||||
$this->company = $company;
|
||||
}
|
||||
|
||||
public function transform($transactionResponse)
|
||||
{
|
||||
$data = [];
|
||||
@ -112,8 +122,8 @@ class TransactionTransformer implements BankRevenueInterface
|
||||
// enrich description with currencyExchange informations
|
||||
if (isset($transaction['currencyExchange'])) {
|
||||
foreach ($transaction["currencyExchange"] as $exchangeRate) {
|
||||
$targetAmount = round($amount * (float) ($exchangeRate["exchangeRate"] ?? 1) , 2);
|
||||
$description .= '\nexchangeRate: ' . $amount . " " . ($exchangeRate["sourceCurrency"] ?? '?') . " = " . $targetAmount . " " . ($exchangeRate["targetCurrency"] ?? '?') . " (" . ($exchangeRate["quotationDate"] ?? '?') . ")";
|
||||
$targetAmount = round($amount * (float) ($exchangeRate["exchangeRate"] ?? 1), 2);
|
||||
$description .= '\n' . ctrans('texts.exchange_rate') . ' : ' . $amount . " " . ($exchangeRate["sourceCurrency"] ?? '?') . " = " . $targetAmount . " " . ($exchangeRate["targetCurrency"] ?? '?') . " (" . (isset($exchangeRate["quotationDate"]) ? $this->formatDate($exchangeRate["quotationDate"]) : '?') . ")";
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,4 +174,24 @@ class TransactionTransformer implements BankRevenueInterface
|
||||
|
||||
}
|
||||
|
||||
private function formatDate(string $input)
|
||||
{
|
||||
$timezone = Timezone::find($this->company->settings->timezone_id);
|
||||
$timezone_name = 'US/Eastern';
|
||||
|
||||
if ($timezone) {
|
||||
$timezone_name = $timezone->name;
|
||||
}
|
||||
|
||||
$date_format_default = 'Y-m-d';
|
||||
|
||||
$date_format = DateFormat::find($this->company->settings->date_format_id);
|
||||
|
||||
if ($date_format) {
|
||||
$date_format_default = $date_format->format;
|
||||
}
|
||||
|
||||
return Carbon::createFromFormat("d-m-Y", $input)->setTimezone($timezone_name)->format($date_format_default) ?? $input;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
|
||||
private function processTransactions()
|
||||
{
|
||||
//Get transaction count object
|
||||
$transactions = $this->nordigen->getTransactions($this->bank_integration->nordigen_account_id, $this->from_date);
|
||||
$transactions = $this->nordigen->getTransactions($this->company, $this->bank_integration->nordigen_account_id, $this->from_date);
|
||||
|
||||
//if no transactions, update the from_date and move on
|
||||
if (count($transactions) == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user