change debitor to participant

This commit is contained in:
paulwer 2023-12-15 16:51:24 +01:00
parent 1e36551917
commit c3ff64a0e6
4 changed files with 61 additions and 61 deletions

View File

@ -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;
}
}
}

View File

@ -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'
];

View File

@ -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 ?: '',

View File

@ -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
});
}