Skip to content

Commit cc22fbc

Browse files
committed
Merge branch 'release/0.1.0'
2 parents eee4cf5 + f1b0fb0 commit cc22fbc

67 files changed

Lines changed: 2927 additions & 444 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Http/Controllers/Import/AuthenticateController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public function index(Request $request)
5656
$flow = $request->cookie(Constants::FLOW_COOKIE);
5757

5858
if ('spectre' === $flow) {
59-
die('TODO '. __METHOD__);
6059
$subTitle = 'Spectre';
6160
$validator = new SpectreValidator;
6261
$result = $validator->validate();

app/Http/Controllers/Import/CSV/RoleController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function index(Request $request)
8282
}
8383

8484
// get columns from file
85-
$content = StorageService::getContent(session()->get(Constants::UPLOAD_CSV_FILE));
85+
$content = StorageService::getContent(session()->get(Constants::UPLOAD_CSV_FILE),$configuration->isConversion());
8686
$columns = RoleService::getColumns($content, $configuration);
8787
$examples = RoleService::getExampleData($content, $configuration);
8888

app/Http/Controllers/Import/ConfigurationController.php

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
use App\Services\Nordigen\Services\AccountInformationCollector;
3939
use App\Services\Nordigen\TokenManager;
4040
use App\Services\Session\Constants;
41+
use App\Services\Spectre\Model\Account as SpectreAccount;
42+
use App\Services\Spectre\Request\GetAccountsRequest as SpectreGetAccountsRequest;
43+
use App\Services\Spectre\Response\GetAccountsResponse as SpectreGetAccountsResponse;
4144
use App\Services\Storage\StorageService;
4245
use App\Support\Token;
4346
use Cache;
@@ -75,7 +78,7 @@ public function index(Request $request)
7578
{
7679
Log::debug(sprintf('Now at %s', __METHOD__));
7780
$mainTitle = 'Configuration';
78-
$subTitle = 'Configure your TODO file import';
81+
$subTitle = 'Configure your import';
7982
$accounts = [];
8083
$flow = $request->cookie(Constants::FLOW_COOKIE);
8184

@@ -123,20 +126,28 @@ public function index(Request $request)
123126
}
124127

125128
// also get the nordigen / spectre accounts
126-
$nordigenAccounts = [];
129+
$importerAccounts = [];
127130
if ('nordigen' === $flow) {
128131
// list all accounts in Nordigen:
129132
$reference = $configuration->getRequisition(session()->get(Constants::REQUISITION_REFERENCE));
130-
$nordigenAccounts = $this->getNordigenAccounts($reference);
131-
$nordigenAccounts = $this->mergeAccountLists($nordigenAccounts, $accounts);
133+
$importerAccounts = $this->getNordigenAccounts($reference);
134+
$importerAccounts = $this->mergeNordigenAccountLists($importerAccounts, $accounts);
132135
}
136+
133137
if ('spectre' === $flow) {
134-
die('grab config for spectre.');
138+
// get the accounts over at Spectre.
139+
$url = config('spectre.url');
140+
$appId = config('spectre.app_id');
141+
$secret = config('spectre.secret');
142+
$spectreList = new SpectreGetAccountsRequest($url, $appId, $secret);
143+
$spectreList->connection = $configuration->getConnection();
144+
$spectreAccounts = $spectreList->get();
145+
$importerAccounts = $this->mergeSpectreAccountLists($spectreAccounts, $accounts);
135146
}
136147

137148
return view(
138149
'import.004-configure.index',
139-
compact('mainTitle', 'subTitle', 'accounts', 'configuration', 'flow', 'nordigenAccounts')
150+
compact('mainTitle', 'subTitle', 'accounts', 'configuration', 'flow', 'importerAccounts')
140151
);
141152
}
142153

@@ -171,6 +182,7 @@ public function postIndex(ConfigurationPostRequest $request): RedirectResponse
171182
$configuration->setFlow($request->cookie(Constants::FLOW_COOKIE));
172183

173184
// TODO are all fields actually in the config?
185+
174186
// loop accounts:
175187
$accounts = [];
176188
foreach (array_keys($fromRequest['do_import']) as $identifier) {
@@ -193,9 +205,14 @@ public function postIndex(ConfigurationPostRequest $request): RedirectResponse
193205

194206
session()->put(Constants::CONFIGURATION, $configuration->toSessionArray());
195207

208+
209+
Log::debug(sprintf('Configuration debug: Connection ID is "%s"', $configuration->getConnection()));
196210
// set config as complete.
197211
session()->put(Constants::CONFIG_COMPLETE_INDICATOR, true);
198-
212+
if ('nordigen' === $configuration->getFlow() || 'spectre' === $configuration->getFlow()) {
213+
// at this point, nordigen is ready for data conversion.
214+
session()->put(Constants::READY_FOR_CONVERSION, true);
215+
}
199216
// always redirect to roles, even if this isn't the step yet
200217
// for nordigen and spectre, roles will be skipped right away.
201218
return redirect(route('005-roles.index'));
@@ -245,25 +262,75 @@ private function getNordigenAccounts(string $identifier): array
245262
return $return;
246263
}
247264

265+
266+
/**
267+
* @param SpectreGetAccountsResponse $spectre
268+
* @param array $firefly
269+
*
270+
* TODO should be a helper
271+
*/
272+
private function mergeSpectreAccountLists(SpectreGetAccountsResponse $spectre, array $firefly): array
273+
{
274+
$return = [];
275+
Log::debug('Now creating Spectre account lists.');
276+
277+
/** @var SpectreAccount $spectreAccount */
278+
foreach ($spectre as $spectreAccount) {
279+
Log::debug(sprintf('Now working on Spectre account "%s": "%s"', $spectreAccount->name, $spectreAccount->id));
280+
$iban = $spectreAccount->iban;
281+
$currency = $spectreAccount->currencyCode;
282+
$entry = [
283+
'import_service' => $spectreAccount,
284+
'firefly' => [],
285+
];
286+
287+
// only iban?
288+
$filteredByIban = $this->filterByIban($firefly, $iban);
289+
290+
if (1 === count($filteredByIban)) {
291+
Log::debug(sprintf('This account (%s) has a single Firefly III counter part (#%d, "%s", same IBAN), so will use that one.', $iban, $filteredByIban[0]->id, $filteredByIban[0]->name));
292+
$entry['firefly'] = $filteredByIban;
293+
$return[] = $entry;
294+
continue;
295+
}
296+
Log::debug(sprintf('Found %d accounts with the same IBAN ("%s")', count($filteredByIban), $iban));
297+
298+
// only currency?
299+
$filteredByCurrency = $this->filterByCurrency($firefly, $currency);
300+
301+
if (count($filteredByCurrency) > 0) {
302+
Log::debug(sprintf('This account (%s) has some Firefly III counter parts with the same currency so will only use those.', $currency));
303+
$entry['firefly'] = $filteredByCurrency;
304+
$return[] = $entry;
305+
continue;
306+
}
307+
Log::debug('No special filtering on the Firefly III account list.');
308+
$entry['firefly'] = $firefly;
309+
$return[] = $entry;
310+
}
311+
return $return;
312+
}
313+
314+
248315
/**
249316
* @param array $nordigen
250317
* @param array $firefly
251318
* @return array
252319
*
253320
* TODO move to some helper.
254321
*/
255-
private function mergeAccountLists(array $nordigen, array $firefly): array
322+
private function mergeNordigenAccountLists(array $nordigen, array $firefly): array
256323
{
257-
Log::debug('Now creating account lists.');
324+
Log::debug('Now creating Nordigen account lists.');
258325
$return = [];
259326
/** @var NordigenAccount $nordigenAccount */
260327
foreach ($nordigen as $nordigenAccount) {
261328
Log::debug(sprintf('Now working on account "%s": "%s"', $nordigenAccount->getName(), $nordigenAccount->getIdentifier()));
262329
$iban = $nordigenAccount->getIban();
263330
$currency = $nordigenAccount->getCurrency();
264331
$entry = [
265-
'nordigen' => $nordigenAccount,
266-
'firefly' => [],
332+
'import_service' => $nordigenAccount,
333+
'firefly' => [],
267334
];
268335

269336
// only iban?

app/Http/Controllers/Import/ConversionController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use App\Services\CSV\Configuration\Configuration;
3232
use App\Services\CSV\Conversion\RoutineManager as CSVRoutineManager;
3333
use App\Services\Nordigen\Conversion\RoutineManager as NordigenRoutineManager;
34+
use App\Services\Spectre\Conversion\RoutineManager as SpectreRoutineManager;
3435
use App\Services\Session\Constants;
3536
use App\Services\Shared\Conversion\ConversionStatus;
3637
use App\Services\Shared\Conversion\RoutineManagerInterface;
@@ -79,6 +80,7 @@ public function index()
7980
$configuration->setMapping($diskConfig->getMapping());
8081
}
8182

83+
8284
Log::debug('Will now verify configuration content.');
8385
$jobBackUrl = route('back.mapping');
8486
if (empty($configuration->getDoMapping())) {
@@ -112,7 +114,7 @@ public function index()
112114
$routine = new NordigenRoutineManager($identifier);
113115
}
114116
if ('spectre' === $flow) {
115-
throw new ImporterErrorException('Cannot handle. :(');
117+
$routine = new SpectreRoutineManager($identifier);
116118
}
117119
if ($configuration->isMapAllData() && in_array($flow, ['spectre', 'nordigen'], true)) {
118120
$nextUrl = route('006-mapping.index');
@@ -168,7 +170,7 @@ public function start(Request $request): JsonResponse
168170
$routine = new NordigenRoutineManager($identifier);
169171
}
170172
if ('spectre' === $flow) {
171-
throw new ImporterErrorException('Cannot handle. :(');
173+
$routine = new SpectreRoutineManager($identifier);
172174
}
173175

174176
$importJobStatus = RoutineStatusManager::startOrFindConversion($identifier);

0 commit comments

Comments
 (0)