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

This commit is contained in:
Paul Sohier 2018-04-29 16:26:19 +02:00
parent 49138eb03a
commit f140d2f37a
2 changed files with 29 additions and 9 deletions

View File

@ -29,7 +29,6 @@ use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\Import\Configuration\ConfigurationInterface; use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
use Illuminate\Support\Collection;
/** /**
* Class HaveAccounts * Class HaveAccounts
@ -74,10 +73,10 @@ class HaveAccounts implements ConfigurationInterface
// find accounts with currency code // find accounts with currency code
$code = $bunqAccount['currency']; $code = $bunqAccount['currency'];
$selection = $this->filterAccounts($dbAccounts, $code); $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 [ return [
'config' => $config, 'config' => $config,
]; ];
@ -136,17 +135,38 @@ class HaveAccounts implements ConfigurationInterface
* @param array $dbAccounts * @param array $dbAccounts
* @param string $code * @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) { foreach ($dbAccounts as $accountId => $data) {
if ($data['currency']->code === $code) { 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;
} }
} }

View File

@ -47,7 +47,7 @@
<td> <td>
<select class="form-control" name="import[{{ account.id }}]"> <select class="form-control" name="import[{{ account.id }}]">
{% for id,name in account.options %} {% 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 %} {% endfor %}
</select> </select>
</td> </td>