mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
Fix #1564
This commit is contained in:
@@ -160,7 +160,7 @@ class ImportArrayStorage
|
|||||||
$array = $this->importJob->transactions;
|
$array = $this->importJob->transactions;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($array as $index => $transaction) {
|
foreach ($array as $index => $transaction) {
|
||||||
if (strtolower(TransactionType::TRANSFER) === $transaction['type']) {
|
if (strtolower(TransactionType::TRANSFER) === strtolower($transaction['type'])) {
|
||||||
$count++;
|
$count++;
|
||||||
Log::debug(sprintf('Row #%d is a transfer, increase count to %d', $index + 1, $count));
|
Log::debug(sprintf('Row #%d is a transfer, increase count to %d', $index + 1, $count));
|
||||||
}
|
}
|
||||||
@@ -479,7 +479,7 @@ class ImportArrayStorage
|
|||||||
$collection->push($journal);
|
$collection->push($journal);
|
||||||
|
|
||||||
// add to collection of transfers, if necessary:
|
// add to collection of transfers, if necessary:
|
||||||
if ('transfer' === $store['type']) {
|
if ('transfer' === strtolower($store['type'])) {
|
||||||
$transaction = $this->getTransactionFromJournal($journal);
|
$transaction = $this->getTransactionFromJournal($journal);
|
||||||
Log::debug('We just stored a transfer, so add the journal to the list of transfers.');
|
Log::debug('We just stored a transfer, so add the journal to the list of transfers.');
|
||||||
$this->transfers->push($transaction);
|
$this->transfers->push($transaction);
|
||||||
@@ -505,7 +505,7 @@ class ImportArrayStorage
|
|||||||
private function transferExists(array $transaction): bool
|
private function transferExists(array $transaction): bool
|
||||||
{
|
{
|
||||||
Log::debug('Check if is a double transfer.');
|
Log::debug('Check if is a double transfer.');
|
||||||
if (strtolower(TransactionType::TRANSFER) !== $transaction['type']) {
|
if (strtolower(TransactionType::TRANSFER) !== strtolower($transaction['type'])) {
|
||||||
Log::debug(sprintf('Is a %s, not a transfer so no.', $transaction['type']));
|
Log::debug(sprintf('Is a %s, not a transfer so no.', $transaction['type']));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@@ -81,6 +81,17 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
|||||||
$mapping = $data['account_mapping'] ?? [];
|
$mapping = $data['account_mapping'] ?? [];
|
||||||
$applyRules = 1 === (int)$data['apply_rules'];
|
$applyRules = 1 === (int)$data['apply_rules'];
|
||||||
$final = [];
|
$final = [];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* $ibanToAsset is used to map bunq IBAN's to Firefly III asset accounts. The array is structured like this:
|
||||||
|
* 12BUNQ123456.. => 1,
|
||||||
|
* 12BUNQ928811.. => 4,
|
||||||
|
*
|
||||||
|
* And contains the bunq asset account iban (left) and the FF3 asset ID (right).
|
||||||
|
*
|
||||||
|
* This is used to properly map transfers.
|
||||||
|
*/
|
||||||
|
$ibanToAsset = [];
|
||||||
if (0 === \count($accounts)) {
|
if (0 === \count($accounts)) {
|
||||||
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
@@ -97,9 +108,14 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
|||||||
// validate each
|
// validate each
|
||||||
$bunqId = $this->validBunqAccount($bunqId);
|
$bunqId = $this->validBunqAccount($bunqId);
|
||||||
$accountId = $this->validLocalAccount($localId);
|
$accountId = $this->validLocalAccount($localId);
|
||||||
|
$bunqIban = $this->getBunqIban($bunqId);
|
||||||
|
if (null !== $bunqIban) {
|
||||||
|
$ibanToAsset[$bunqIban] = $accountId;
|
||||||
|
}
|
||||||
$final[$bunqId] = $accountId;
|
$final[$bunqId] = $accountId;
|
||||||
}
|
}
|
||||||
$config['mapping'] = $final;
|
$config['mapping'] = $final;
|
||||||
|
$config['bunq-iban'] = $ibanToAsset;
|
||||||
$config['apply-rules'] = $applyRules;
|
$config['apply-rules'] = $applyRules;
|
||||||
$this->repository->setConfiguration($this->importJob, $config);
|
$this->repository->setConfiguration($this->importJob, $config);
|
||||||
|
|
||||||
@@ -169,6 +185,25 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
|||||||
$this->accountRepository->setUser($importJob->user);
|
$this->accountRepository->setUser($importJob->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $bunqId
|
||||||
|
*
|
||||||
|
* @return null|string
|
||||||
|
*/
|
||||||
|
private function getBunqIban(int $bunqId): ?string
|
||||||
|
{
|
||||||
|
$config = $this->repository->getConfiguration($this->importJob);
|
||||||
|
$accounts = $config['accounts'] ?? [];
|
||||||
|
/** @var array $bunqAccount */
|
||||||
|
foreach ($accounts as $bunqAccount) {
|
||||||
|
if ((int)$bunqAccount['id'] === $bunqId) {
|
||||||
|
return $bunqAccount['iban'] ?? null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $currencyId
|
* @param int $currencyId
|
||||||
*
|
*
|
||||||
|
@@ -50,6 +50,8 @@ class StageImportDataHandler
|
|||||||
private $accountRepository;
|
private $accountRepository;
|
||||||
/** @var ImportJob */
|
/** @var ImportJob */
|
||||||
private $importJob;
|
private $importJob;
|
||||||
|
/** @var array */
|
||||||
|
private $jobConfiguration;
|
||||||
/** @var ImportJobRepositoryInterface */
|
/** @var ImportJobRepositoryInterface */
|
||||||
private $repository;
|
private $repository;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
@@ -75,6 +77,7 @@ class StageImportDataHandler
|
|||||||
$accounts = $config['accounts'] ?? [];
|
$accounts = $config['accounts'] ?? [];
|
||||||
$mapping = $config['mapping'] ?? [];
|
$mapping = $config['mapping'] ?? [];
|
||||||
$collection = [[]];
|
$collection = [[]];
|
||||||
|
$this->jobConfiguration = $config;
|
||||||
/** @var array $bunqAccount */
|
/** @var array $bunqAccount */
|
||||||
foreach ($accounts as $bunqAccount) {
|
foreach ($accounts as $bunqAccount) {
|
||||||
$bunqAccountId = $bunqAccount['id'] ?? 0;
|
$bunqAccountId = $bunqAccount['id'] ?? 0;
|
||||||
@@ -192,9 +195,24 @@ class StageImportDataHandler
|
|||||||
*/
|
*/
|
||||||
private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): LocalAccount
|
private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): LocalAccount
|
||||||
{
|
{
|
||||||
Log::debug('in convertToAccount()');
|
|
||||||
|
Log::debug(sprintf('in convertToAccount() with LabelMonetaryAccount: %s', ''));
|
||||||
if (null !== $party->getIban()) {
|
if (null !== $party->getIban()) {
|
||||||
// find opposing party by IBAN first.
|
// find account in 'bunq-iban' array first.
|
||||||
|
$bunqIbans = $this->jobConfiguration['bunq-iban'] ?? [];
|
||||||
|
if (isset($bunqIbans[$party->getIban()])) {
|
||||||
|
$accountId = (int)$bunqIbans[$party->getIban()];
|
||||||
|
$result = $this->accountRepository->findNull($accountId);
|
||||||
|
if (null !== $result) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf('Search for #%s (based on IBAN %s) resulted in account %s (#%d)', $accountId, $party->getIban(), $result->name, $result->id)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find opposing party by IBAN second.
|
||||||
$result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]);
|
$result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]);
|
||||||
if (null !== $result) {
|
if (null !== $result) {
|
||||||
Log::debug(sprintf('Search for %s resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id));
|
Log::debug(sprintf('Search for %s resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id));
|
||||||
|
@@ -150,6 +150,7 @@ class StageNewHandler
|
|||||||
'balance' => $mab->getBalance(),
|
'balance' => $mab->getBalance(),
|
||||||
'status' => $mab->getStatus(),
|
'status' => $mab->getStatus(),
|
||||||
'type' => 'MonetaryAccountBank',
|
'type' => 'MonetaryAccountBank',
|
||||||
|
'iban' => null,
|
||||||
'aliases' => [],
|
'aliases' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -168,6 +169,11 @@ class StageNewHandler
|
|||||||
'name' => $alias->getName(),
|
'name' => $alias->getName(),
|
||||||
'value' => $alias->getValue(),
|
'value' => $alias->getValue(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// store IBAN alias separately:
|
||||||
|
if ('IBAN' === $alias->getType()) {
|
||||||
|
$return['iban'] = $alias->getValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user