From c3ff64a0e63b106d4aecf856ba40df17b38e88a2 Mon Sep 17 00:00:00 2001 From: paulwer Date: Fri, 15 Dec 2023 16:51:24 +0100 Subject: [PATCH] change debitor to participant --- .../Transformer/TransactionTransformer.php | 106 +++++++++--------- app/Models/BankTransaction.php | 8 +- .../BankTransactionTransformer.php | 4 +- ...3_11_26_082959_add_bank_integration_id.php | 4 +- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php b/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php index bd905bb42eab..05350d87398b 100644 --- a/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php +++ b/app/Helpers/Bank/Nordigen/Transformer/TransactionTransformer.php @@ -64,73 +64,73 @@ use Log; class TransactionTransformer implements BankRevenueInterface { - use AppSetup; + use AppSetup; - public function transform($transactionResponse) - { - $data = []; + public function transform($transactionResponse) + { + $data = []; - if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"])) - throw new \Exception('invalid dataset'); + if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"])) + throw new \Exception('invalid dataset'); - foreach ($transactionResponse["transactions"]["booked"] as $transaction) { - $data[] = $this->transformTransaction($transaction); - } - - return $data; + foreach ($transactionResponse["transactions"]["booked"] as $transaction) { + $data[] = $this->transformTransaction($transaction); } - public function transformTransaction($transaction) - { + return $data; + } - if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction)) - throw new \Exception('invalid dataset'); + public function transformTransaction($transaction) + { - // description could be in varios places - $description = ''; - if (array_key_exists('remittanceInformationStructured', $transaction)) - $description = $transaction["remittanceInformationStructured"]; - else if (array_key_exists('remittanceInformationStructuredArray', $transaction)) - $description = implode(' \r\n', $transaction["remittanceInformationStructuredArray"]); - else if (array_key_exists('remittanceInformationUnstructured', $transaction)) - $description = $transaction["remittanceInformationUnstructured"]; - else - Log::warning("Missing description for the following transaction: " . json_encode($transaction)); + if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction)) + throw new \Exception('invalid dataset'); - return [ - 'transaction_id' => $transaction["transactionId"], - 'amount' => abs((int) $transaction["transactionAmount"]["amount"]), - 'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]), - 'category_id' => 0, // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc - 'category_type' => array_key_exists('additionalInformation', $transaction) ? $transaction["additionalInformation"] : '', // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc - 'date' => $transaction["bookingDate"], - 'description' => $description, - 'debitor' => array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? $transaction['debtorAccount']['iban'] : null, - 'debitor_name' => array_key_exists('debtorName', $transaction) ? $transaction['debtorName'] : null, - 'base_type' => (int) $transaction["transactionAmount"]["amount"] <= 0 ? 'DEBIT' : 'CREDIT', - ]; + // description could be in varios places + $description = ''; + if (array_key_exists('remittanceInformationStructured', $transaction)) + $description = $transaction["remittanceInformationStructured"]; + else if (array_key_exists('remittanceInformationStructuredArray', $transaction)) + $description = implode(' \r\n', $transaction["remittanceInformationStructuredArray"]); + else if (array_key_exists('remittanceInformationUnstructured', $transaction)) + $description = $transaction["remittanceInformationUnstructured"]; + else + Log::warning("Missing description for the following transaction: " . json_encode($transaction)); + return [ + 'transaction_id' => $transaction["transactionId"], + 'amount' => abs((int) $transaction["transactionAmount"]["amount"]), + 'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]), + 'category_id' => 0, // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc + 'category_type' => array_key_exists('additionalInformation', $transaction) ? $transaction["additionalInformation"] : '', // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc + 'date' => $transaction["bookingDate"], + 'description' => $description, + 'participant' => array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? $transaction['debtorAccount']['iban'] : null, + 'participant_name' => array_key_exists('debtorName', $transaction) ? $transaction['debtorName'] : null, + 'base_type' => (int) $transaction["transactionAmount"]["amount"] <= 0 ? 'DEBIT' : 'CREDIT', + ]; + + } + + private function convertCurrency(string $code) + { + + $currencies = Cache::get('currencies'); + + if (!$currencies) { + $this->buildCache(true); } - private function convertCurrency(string $code) - { + $currency = $currencies->filter(function ($item) use ($code) { + return $item->code == $code; + })->first(); - $currencies = Cache::get('currencies'); + if ($currency) + return $currency->id; - if (!$currencies) { - $this->buildCache(true); - } + return 1; - $currency = $currencies->filter(function ($item) use ($code) { - return $item->code == $code; - })->first(); - - if ($currency) - return $currency->id; - - return 1; - - } + } } diff --git a/app/Models/BankTransaction.php b/app/Models/BankTransaction.php index 378945656705..d39c83a62985 100644 --- a/app/Models/BankTransaction.php +++ b/app/Models/BankTransaction.php @@ -34,8 +34,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string|null $date * @property int $bank_account_id * @property string|null $description - * @property string|null $debitor - * @property string|null $debitor_name + * @property string|null $participant + * @property string|null $participant_name * @property string $invoice_ids * @property int|null $expense_id * @property int|null $vendor_id @@ -87,8 +87,8 @@ class BankTransaction extends BaseModel 'expense_id', 'vendor_id', 'amount', - 'debitor', - 'debitor_name' + 'participant', + 'participant_name' ]; diff --git a/app/Transformers/BankTransactionTransformer.php b/app/Transformers/BankTransactionTransformer.php index ca122a183be6..15654f9654e1 100644 --- a/app/Transformers/BankTransactionTransformer.php +++ b/app/Transformers/BankTransactionTransformer.php @@ -63,8 +63,8 @@ class BankTransactionTransformer extends EntityTransformer 'bank_account_id' => (int) $bank_transaction->bank_account_id, 'status_id' => (string) $bank_transaction->status_id, 'description' => (string) $bank_transaction->description ?: '', - 'debitor' => (string) $bank_transaction->debitor ?: '', - 'debitor_name' => (string) $bank_transaction->debitor_name ?: '', + 'participant' => (string) $bank_transaction->participant ?: '', + 'participant_name' => (string) $bank_transaction->participant_name ?: '', 'base_type' => (string) $bank_transaction->base_type ?: '', 'invoice_ids' => (string) $bank_transaction->invoice_ids ?: '', 'expense_id' => (string) $bank_transaction->expense_id ?: '', diff --git a/database/migrations/2023_11_26_082959_add_bank_integration_id.php b/database/migrations/2023_11_26_082959_add_bank_integration_id.php index 3630b4d0d08c..ea3517bcd28f 100644 --- a/database/migrations/2023_11_26_082959_add_bank_integration_id.php +++ b/database/migrations/2023_11_26_082959_add_bank_integration_id.php @@ -28,8 +28,8 @@ return new class extends Migration { // MAYBE migration of account->bank_account_id etc Schema::table('bank_transactions', function (Blueprint $table) { - $table->string('debitor')->nullable(); // iban, credit-card info or else - $table->string('debitor_name')->nullable(); // name + $table->string('participant')->nullable(); // iban, credit-card info or else + $table->string('participant_name')->nullable(); // name }); }