mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 00:44:35 -04:00
change debitor to participant
This commit is contained in:
parent
1e36551917
commit
c3ff64a0e6
@ -64,73 +64,73 @@ use Log;
|
|||||||
|
|
||||||
class TransactionTransformer implements BankRevenueInterface
|
class TransactionTransformer implements BankRevenueInterface
|
||||||
{
|
{
|
||||||
use AppSetup;
|
use AppSetup;
|
||||||
|
|
||||||
public function transform($transactionResponse)
|
public function transform($transactionResponse)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"]))
|
if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"]))
|
||||||
throw new \Exception('invalid dataset');
|
throw new \Exception('invalid dataset');
|
||||||
|
|
||||||
foreach ($transactionResponse["transactions"]["booked"] as $transaction) {
|
foreach ($transactionResponse["transactions"]["booked"] as $transaction) {
|
||||||
$data[] = $this->transformTransaction($transaction);
|
$data[] = $this->transformTransaction($transaction);
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function transformTransaction($transaction)
|
return $data;
|
||||||
{
|
}
|
||||||
|
|
||||||
if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction))
|
public function transformTransaction($transaction)
|
||||||
throw new \Exception('invalid dataset');
|
{
|
||||||
|
|
||||||
// description could be in varios places
|
if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction))
|
||||||
$description = '';
|
throw new \Exception('invalid dataset');
|
||||||
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 [
|
// description could be in varios places
|
||||||
'transaction_id' => $transaction["transactionId"],
|
$description = '';
|
||||||
'amount' => abs((int) $transaction["transactionAmount"]["amount"]),
|
if (array_key_exists('remittanceInformationStructured', $transaction))
|
||||||
'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]),
|
$description = $transaction["remittanceInformationStructured"];
|
||||||
'category_id' => 0, // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
else if (array_key_exists('remittanceInformationStructuredArray', $transaction))
|
||||||
'category_type' => array_key_exists('additionalInformation', $transaction) ? $transaction["additionalInformation"] : '', // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
$description = implode(' \r\n', $transaction["remittanceInformationStructuredArray"]);
|
||||||
'date' => $transaction["bookingDate"],
|
else if (array_key_exists('remittanceInformationUnstructured', $transaction))
|
||||||
'description' => $description,
|
$description = $transaction["remittanceInformationUnstructured"];
|
||||||
'debitor' => array_key_exists('debtorAccount', $transaction) && array_key_exists('iban', $transaction["debtorAccount"]) ? $transaction['debtorAccount']['iban'] : null,
|
else
|
||||||
'debitor_name' => array_key_exists('debtorName', $transaction) ? $transaction['debtorName'] : null,
|
Log::warning("Missing description for the following transaction: " . json_encode($transaction));
|
||||||
'base_type' => (int) $transaction["transactionAmount"]["amount"] <= 0 ? 'DEBIT' : 'CREDIT',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
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) {
|
return 1;
|
||||||
$this->buildCache(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
$currency = $currencies->filter(function ($item) use ($code) {
|
}
|
||||||
return $item->code == $code;
|
|
||||||
})->first();
|
|
||||||
|
|
||||||
if ($currency)
|
|
||||||
return $currency->id;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
|||||||
* @property string|null $date
|
* @property string|null $date
|
||||||
* @property int $bank_account_id
|
* @property int $bank_account_id
|
||||||
* @property string|null $description
|
* @property string|null $description
|
||||||
* @property string|null $debitor
|
* @property string|null $participant
|
||||||
* @property string|null $debitor_name
|
* @property string|null $participant_name
|
||||||
* @property string $invoice_ids
|
* @property string $invoice_ids
|
||||||
* @property int|null $expense_id
|
* @property int|null $expense_id
|
||||||
* @property int|null $vendor_id
|
* @property int|null $vendor_id
|
||||||
@ -87,8 +87,8 @@ class BankTransaction extends BaseModel
|
|||||||
'expense_id',
|
'expense_id',
|
||||||
'vendor_id',
|
'vendor_id',
|
||||||
'amount',
|
'amount',
|
||||||
'debitor',
|
'participant',
|
||||||
'debitor_name'
|
'participant_name'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ class BankTransactionTransformer extends EntityTransformer
|
|||||||
'bank_account_id' => (int) $bank_transaction->bank_account_id,
|
'bank_account_id' => (int) $bank_transaction->bank_account_id,
|
||||||
'status_id' => (string) $bank_transaction->status_id,
|
'status_id' => (string) $bank_transaction->status_id,
|
||||||
'description' => (string) $bank_transaction->description ?: '',
|
'description' => (string) $bank_transaction->description ?: '',
|
||||||
'debitor' => (string) $bank_transaction->debitor ?: '',
|
'participant' => (string) $bank_transaction->participant ?: '',
|
||||||
'debitor_name' => (string) $bank_transaction->debitor_name ?: '',
|
'participant_name' => (string) $bank_transaction->participant_name ?: '',
|
||||||
'base_type' => (string) $bank_transaction->base_type ?: '',
|
'base_type' => (string) $bank_transaction->base_type ?: '',
|
||||||
'invoice_ids' => (string) $bank_transaction->invoice_ids ?: '',
|
'invoice_ids' => (string) $bank_transaction->invoice_ids ?: '',
|
||||||
'expense_id' => (string) $bank_transaction->expense_id ?: '',
|
'expense_id' => (string) $bank_transaction->expense_id ?: '',
|
||||||
|
@ -28,8 +28,8 @@ return new class extends Migration {
|
|||||||
|
|
||||||
// MAYBE migration of account->bank_account_id etc
|
// MAYBE migration of account->bank_account_id etc
|
||||||
Schema::table('bank_transactions', function (Blueprint $table) {
|
Schema::table('bank_transactions', function (Blueprint $table) {
|
||||||
$table->string('debitor')->nullable(); // iban, credit-card info or else
|
$table->string('participant')->nullable(); // iban, credit-card info or else
|
||||||
$table->string('debitor_name')->nullable(); // name
|
$table->string('participant_name')->nullable(); // name
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user