Skip to content

Firefly III: a personal finances manager

Select the matching bunq account from the import. Fixes #1398

Paul Sohierf140d2f37a73
diff --git a/app/Support/Import/Configuration/Bunq/HaveAccounts.php b/app/Support/Import/Configuration/Bunq/HaveAccounts.php
index 3291c843e8..cf69af821f 100644
--- a/app/Support/Import/Configuration/Bunq/HaveAccounts.php
+++ b/app/Support/Import/Configuration/Bunq/HaveAccounts.php
@@ -29,7 +29,6 @@ use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
-use Illuminate\Support\Collection;
/**
* Class HaveAccounts
@@ -74,10 +73,10 @@ class HaveAccounts implements ConfigurationInterface
// find accounts with currency code
$code = $bunqAccount['currency'];
$selection = $this->filterAccounts($dbAccounts, $code);
- $config['accounts'][$index]['options'] = app('expandedform')->makeSelectList($selection);
+ $config['accounts'][$index]['iban'] = $this->getIban($bunqAccount);
+ $config['accounts'][$index]['options'] = $selection;
}
-
return [
'config' => $config,
];
@@ -136,17 +135,38 @@ class HaveAccounts implements ConfigurationInterface
* @param array $dbAccounts
* @param string $code
*
- * @return Collection
+ * @return array
*/
- private function filterAccounts(array $dbAccounts, string $code): Collection
+ private function filterAccounts(array $dbAccounts, string $code): array
{
- $collection = new Collection;
+ $account = [];
foreach ($dbAccounts as $accountId => $data) {
if ($data['currency']->code === $code) {
- $collection->push($data['account']);
+ $account[$accountId] = [
+ 'name' => $data['account']['name'],
+ 'iban' => $data['account']['iban'],
+ ];
}
}
- return $collection;
+ return $account;
+ }
+
+ /**
+ * @param array $bunqAccount
+ *
+ * @return string
+ */
+ private function getIban(array $bunqAccount)
+ {
+ $iban = '';
+ if (count($bunqAccount['alias'])) {
+ foreach ($bunqAccount['alias'] as $alias) {
+ if ($alias['type'] === 'IBAN') {
+ $iban = $alias['value'];
+ }
+ }
+ }
+ return $iban;
}
}
diff --git a/resources/views/import/bunq/accounts.twig b/resources/views/import/bunq/accounts.twig
index 734de2893b..9556218302 100644
--- a/resources/views/import/bunq/accounts.twig
+++ b/resources/views/import/bunq/accounts.twig
@@ -47,7 +47,7 @@
<td>
<select class="form-control" name="import[{{ account.id }}]">
{% for id,name in account.options %}
- <option value="{{ id }}" label="{{ name }}">{{ name }}</option>
+ <option value="{{ id }}" label="{{ name.name }}"{% if account.iban == name.iban %} selected="selected"{% endif %}>{{ name.name }}</option>
{% endfor %}
</select>
</td>