mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Can now import and handle external ID field.
This commit is contained in:
parent
71b63bd33b
commit
49138eb03a
@ -91,7 +91,7 @@ class TransactionJournalFactory
|
|||||||
|
|
||||||
// store date meta fields (if present):
|
// store date meta fields (if present):
|
||||||
$fields = ['sepa-cc', 'sepa-ct-op', 'sepa-ct-id', 'sepa-db', 'sepa-country', 'sepa-ep', 'sepa-ci', 'interest_date', 'book_date', 'process_date',
|
$fields = ['sepa-cc', 'sepa-ct-op', 'sepa-ct-id', 'sepa-db', 'sepa-country', 'sepa-ep', 'sepa-ci', 'interest_date', 'book_date', 'process_date',
|
||||||
'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'bunq_payment_id','importHash'];
|
'due_date', 'payment_date', 'invoice_date', 'internal_reference', 'bunq_payment_id', 'importHash', 'external_id'];
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$this->storeMeta($journal, $data, $field);
|
$this->storeMeta($journal, $data, $field);
|
||||||
|
@ -158,6 +158,14 @@ class ImportJournal
|
|||||||
return $this->description;
|
return $this->description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getExternalId(): string
|
||||||
|
{
|
||||||
|
return $this->externalId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
@ -231,7 +239,6 @@ class ImportJournal
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $hash
|
* @param string $hash
|
||||||
*/
|
*/
|
||||||
|
@ -199,78 +199,87 @@ class ImportStorage
|
|||||||
|
|
||||||
throw new FireflyException($message);
|
throw new FireflyException($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for journals with the same external ID.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
unset($parameters);
|
unset($parameters);
|
||||||
$this->addStep();
|
$this->addStep();
|
||||||
|
|
||||||
|
$budget = $importJournal->budget->getBudget();
|
||||||
|
$category = $importJournal->category->getCategory();
|
||||||
|
$bill = $importJournal->bill->getBill();
|
||||||
|
$source = $assetAccount;
|
||||||
|
$destination = $opposingAccount;
|
||||||
|
|
||||||
try {
|
// switch account arounds when the transaction type is a deposit.
|
||||||
$budget = $importJournal->budget->getBudget();
|
if ($transactionType === TransactionType::DEPOSIT) {
|
||||||
$category = $importJournal->category->getCategory();
|
[$destination, $source] = [$source, $destination];
|
||||||
$bill = $importJournal->bill->getBill();
|
}
|
||||||
$source = $assetAccount;
|
// switch accounts around when the amount is negative and it's a transfer.
|
||||||
$destination = $opposingAccount;
|
// credits to @NyKoF
|
||||||
|
if ($transactionType === TransactionType::TRANSFER && -1 === bccomp($amount, '0')) {
|
||||||
|
[$destination, $source] = [$source, $destination];
|
||||||
|
}
|
||||||
|
Log::debug(
|
||||||
|
sprintf('Will make #%s (%s) the source and #%s (%s) the destination.', $source->id, $source->name, $destination->id, $destination->name)
|
||||||
|
);
|
||||||
|
|
||||||
// switch account arounds when the transaction type is a deposit.
|
$data = [
|
||||||
if ($transactionType === TransactionType::DEPOSIT) {
|
'user' => $this->job->user_id,
|
||||||
[$destination, $source] = [$source, $destination];
|
'type' => $transactionType,
|
||||||
}
|
'date' => $importJournal->getDate($this->dateFormat),
|
||||||
// switch accounts around when the amount is negative and it's a transfer.
|
'description' => $importJournal->getDescription(),
|
||||||
// credits to @NyKoF
|
'piggy_bank_id' => null,
|
||||||
if($transactionType === TransactionType::TRANSFER && -1 === bccomp($amount, '0')) {
|
'piggy_bank_name' => null,
|
||||||
[$destination, $source] = [$source, $destination];
|
'bill_id' => null === $bill ? null : $bill->id,
|
||||||
}
|
'bill_name' => null,
|
||||||
Log::debug(
|
'tags' => $importJournal->tags,
|
||||||
sprintf('Will make #%s (%s) the source and #%s (%s) the destination.', $source->id, $source->name, $destination->id, $destination->name)
|
'interest_date' => $importJournal->getMetaDate('interest_date'),
|
||||||
);
|
'book_date' => $importJournal->getMetaDate('book_date'),
|
||||||
$data = [
|
'process_date' => $importJournal->getMetaDate('process_date'),
|
||||||
'user' => $this->job->user_id,
|
'due_date' => $importJournal->getMetaDate('due_date'),
|
||||||
'type' => $transactionType,
|
'payment_date' => $importJournal->getMetaDate('payment_date'),
|
||||||
'date' => $importJournal->getDate($this->dateFormat),
|
'invoice_date' => $importJournal->getMetaDate('invoice_date'),
|
||||||
'description' => $importJournal->getDescription(),
|
'internal_reference' => $importJournal->metaFields['internal_reference'] ?? null,
|
||||||
'piggy_bank_id' => null,
|
'notes' => $importJournal->notes,
|
||||||
'piggy_bank_name' => null,
|
'external_id' => $importJournal->getExternalId(),
|
||||||
'bill_id' => null === $bill ? null : $bill->id,
|
'sepa-cc' => $importJournal->getMetaString('sepa-cc'),
|
||||||
'bill_name' => null,
|
'sepa-ct-op' => $importJournal->getMetaString('sepa-ct-op'),
|
||||||
'tags' => $importJournal->tags,
|
'sepa-ct-id' => $importJournal->getMetaString('sepa-ct-id'),
|
||||||
'interest_date' => $importJournal->getMetaDate('interest_date'),
|
'sepa-db' => $importJournal->getMetaString('sepa-db'),
|
||||||
'book_date' => $importJournal->getMetaDate('book_date'),
|
'sepa-country' => $importJournal->getMetaString('sepa-country'),
|
||||||
'process_date' => $importJournal->getMetaDate('process_date'),
|
'sepa-ep' => $importJournal->getMetaString('sepa-ep'),
|
||||||
'due_date' => $importJournal->getMetaDate('due_date'),
|
'sepa-ci' => $importJournal->getMetaString('sepa-ci'),
|
||||||
'payment_date' => $importJournal->getMetaDate('payment_date'),
|
'importHash' => $importJournal->hash,
|
||||||
'invoice_date' => $importJournal->getMetaDate('invoice_date'),
|
'transactions' => [
|
||||||
'internal_reference' => $importJournal->metaFields['internal_reference'] ?? null,
|
// single transaction:
|
||||||
'notes' => $importJournal->notes,
|
[
|
||||||
'sepa-cc' => $importJournal->getMetaString('sepa-cc'),
|
'description' => null,
|
||||||
'sepa-ct-op' => $importJournal->getMetaString('sepa-ct-op'),
|
'amount' => $amount,
|
||||||
'sepa-ct-id' => $importJournal->getMetaString('sepa-ct-id'),
|
'currency_id' => $currencyId,
|
||||||
'sepa-db' => $importJournal->getMetaString('sepa-db'),
|
'currency_code' => null,
|
||||||
'sepa-country' => $importJournal->getMetaString('sepa-country'),
|
'foreign_amount' => $foreignAmount,
|
||||||
'sepa-ep' => $importJournal->getMetaString('sepa-ep'),
|
'foreign_currency_id' => $foreignCurrencyId,
|
||||||
'sepa-ci' => $importJournal->getMetaString('sepa-ci'),
|
'foreign_currency_code' => null,
|
||||||
'importHash' => $importJournal->hash,
|
'budget_id' => null === $budget ? null : $budget->id,
|
||||||
'transactions' => [
|
'budget_name' => null,
|
||||||
// single transaction:
|
'category_id' => null === $category ? null : $category->id,
|
||||||
[
|
'category_name' => null,
|
||||||
'description' => null,
|
'source_id' => $source->id,
|
||||||
'amount' => $amount,
|
'source_name' => null,
|
||||||
'currency_id' => $currencyId,
|
'destination_id' => $destination->id,
|
||||||
'currency_code' => null,
|
'destination_name' => null,
|
||||||
'foreign_amount' => $foreignAmount,
|
'reconciled' => false,
|
||||||
'foreign_currency_id' => $foreignCurrencyId,
|
'identifier' => 0,
|
||||||
'foreign_currency_code' => null,
|
|
||||||
'budget_id' => null === $budget ? null : $budget->id,
|
|
||||||
'budget_name' => null,
|
|
||||||
'category_id' => null === $category ? null : $category->id,
|
|
||||||
'category_name' => null,
|
|
||||||
'source_id' => $source->id,
|
|
||||||
'source_name' => null,
|
|
||||||
'destination_id' => $destination->id,
|
|
||||||
'destination_name' => null,
|
|
||||||
'reconciled' => false,
|
|
||||||
'identifier' => 0,
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
];
|
],
|
||||||
|
];
|
||||||
|
$factoryJournal = null;
|
||||||
|
try {
|
||||||
$factoryJournal = $this->factory->create($data);
|
$factoryJournal = $this->factory->create($data);
|
||||||
$this->journals->push($factoryJournal);
|
$this->journals->push($factoryJournal);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
@ -278,11 +287,12 @@ class ImportStorage
|
|||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// double add step because "match bills" no longer happens.
|
||||||
$this->addStep();
|
$this->addStep();
|
||||||
$this->addStep();
|
$this->addStep();
|
||||||
|
|
||||||
// run rules if config calls for it:
|
// run rules if config calls for it:
|
||||||
if (true === $this->applyRules) {
|
if (true === $this->applyRules && null !== $factoryJournal) {
|
||||||
Log::info('Will apply rules to this journal.');
|
Log::info('Will apply rules to this journal.');
|
||||||
$this->applyRules($factoryJournal);
|
$this->applyRules($factoryJournal);
|
||||||
}
|
}
|
||||||
@ -291,6 +301,8 @@ class ImportStorage
|
|||||||
if (!(true === $this->applyRules)) {
|
if (!(true === $this->applyRules)) {
|
||||||
Log::info('Will NOT apply rules to this journal.');
|
Log::info('Will NOT apply rules to this journal.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// double add step because some other extra thing was removed here.
|
||||||
$this->addStep();
|
$this->addStep();
|
||||||
$this->addStep();
|
$this->addStep();
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ return [
|
|||||||
'sepa-cc' => 'SEPA Clearing Code',
|
'sepa-cc' => 'SEPA Clearing Code',
|
||||||
'sepa-ep' => 'SEPA External Purpose',
|
'sepa-ep' => 'SEPA External Purpose',
|
||||||
'sepa-ci' => 'SEPA Creditor Identifier',
|
'sepa-ci' => 'SEPA Creditor Identifier',
|
||||||
|
'external_id' => 'External ID',
|
||||||
'account_at_bunq' => 'Account with bunq',
|
'account_at_bunq' => 'Account with bunq',
|
||||||
'file_name' => 'File name',
|
'file_name' => 'File name',
|
||||||
'file_size' => 'File size',
|
'file_size' => 'File size',
|
||||||
|
@ -210,7 +210,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{# all other meta values #}
|
{# all other meta values #}
|
||||||
{% for metaField in ['internal_reference','sepa-ct-id','sepa-ct-op','sepa-db','sepa-country','sepa-cc','sepa-ep','sepa-ci'] %}
|
{% for metaField in ['external_id','internal_reference','sepa-ct-id','sepa-ct-op','sepa-db','sepa-country','sepa-cc','sepa-ep','sepa-ci'] %}
|
||||||
{% if journalHasMeta(journal, metaField) %}
|
{% if journalHasMeta(journal, metaField) %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ trans('list.'~metaField) }}</td>
|
<td>{{ trans('list.'~metaField) }}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user