Skip to content

Commit b8bc236

Browse files
Merge pull request #1029 from firefly-iii/develop
🤖 Automatically merge the PR into the main branch.
2 parents 9bd3956 + a9b77fd commit b8bc236

File tree

19 files changed

+346
-248
lines changed

19 files changed

+346
-248
lines changed

.ci/php-cs-fixer/composer.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Console/AutoImports.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ private function startConversion(Configuration $configuration, string $importabl
389389
$this->conversionErrors = $manager->getAllErrors();
390390
$this->conversionRateLimits = $manager->getAllRateLimits();
391391
}
392+
393+
394+
395+
392396
if (0 === count($transactions)) {
393397
Log::error('[a] Zero transactions!');
394398
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE, $this->identifier);
@@ -520,6 +524,7 @@ private function startImport(Configuration $configuration): void
520524
return;
521525
}
522526

527+
523528
// set done:
524529
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_DONE, $this->identifier);
525530
$this->importMessages = $routine->getAllMessages();

app/Events/CompletedMapping.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Events;
6+
7+
use App\Services\Shared\Configuration\Configuration;
8+
use Illuminate\Broadcasting\Channel;
9+
use Illuminate\Broadcasting\InteractsWithSockets;
10+
use Illuminate\Broadcasting\PrivateChannel;
11+
use Illuminate\Foundation\Events\Dispatchable;
12+
use Illuminate\Queue\SerializesModels;
13+
14+
class CompletedMapping
15+
{
16+
use Dispatchable;
17+
use InteractsWithSockets;
18+
use SerializesModels;
19+
20+
/**
21+
* Create a new event instance.
22+
*/
23+
public function __construct(public Configuration $configuration) {}
24+
25+
/**
26+
* Get the channels the event should broadcast on.
27+
*
28+
* @return array<int, Channel>
29+
*/
30+
public function broadcastOn(): array
31+
{
32+
return [
33+
new PrivateChannel('channel-name'),
34+
];
35+
}
36+
}

app/Handlers/Events/ImportFlowHandler.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
use App\Events\CompletedConfiguration;
2727
use App\Events\CompletedConversion;
28+
use App\Events\CompletedMapping;
2829
use App\Events\DownloadedSimpleFINAccounts;
2930
use App\Events\ProvidedConfigUpload;
3031
use App\Events\ProvidedDataUpload;
@@ -38,17 +39,39 @@ public function handleDownloadedSimpleFINAccounts(DownloadedSimpleFINAccounts $e
3839
public function handleCompletedConversion(CompletedConversion $event): void
3940
{
4041
Log::debug('Set conversion as complete. Forget READY_FOR_CONVERSION.');
42+
Log::debug('Set CONVERSION_COMPLETE_INDICATOR = true');
4143
session()->put(Constants::CONVERSION_COMPLETE_INDICATOR, true);
4244
session()->forget(Constants::READY_FOR_CONVERSION);
4345
}
4446

45-
public function handleCompletedConfiguration(CompletedConfiguration $event): void
47+
public function handleCompletedMapping(CompletedMapping $event): void
4648
{
47-
$configuration = $event->configuration;
48-
session()->put(Constants::CONFIG_COMPLETE_INDICATOR, true);
49+
// set map config as complete.
50+
Log::debug('Set MAPPING_COMPLETE_INDICATOR = true');
51+
session()->put(Constants::MAPPING_COMPLETE_INDICATOR, true);
52+
53+
// if "file", now ready for conversion
54+
if ('file' === $event->configuration->getFlow() || 'simplefin' === $event->configuration->getFlow()) {
55+
Log::debug('Its a file/simplefin, also set READY_FOR_CONVERSION = true.');
56+
session()->put(Constants::READY_FOR_CONVERSION, true);
57+
}
4958

59+
if (
60+
'nordigen' === $event->configuration->getFlow()
61+
|| 'spectre' === $event->configuration->getFlow()
62+
|| 'lunchflow' === $event->configuration->getFlow()
63+
|| 'simplefin' === $event->configuration->getFlow()) {
64+
// if nordigen, spectre, or simplefin, now ready for submission!
65+
// Log::debug('Set READY_FOR_SUBMISSION = true');
66+
// session()->put(Constants::READY_FOR_SUBMISSION, true);
67+
}
5068

69+
}
5170

71+
public function handleCompletedConfiguration(CompletedConfiguration $event): void
72+
{
73+
$configuration = $event->configuration;
74+
session()->put(Constants::CONFIG_COMPLETE_INDICATOR, true);
5275

5376
if ('file' !== $configuration->getFlow()) {
5477
// at this point, lunchbox, nordigen, spectre, and simplefin are ready for data conversion.
@@ -57,8 +80,8 @@ public function handleCompletedConfiguration(CompletedConfiguration $event): voi
5780
}
5881
// if the user does not want to map data, this step is now complete:
5982
if (!$configuration->isMapAllData()) {
60-
Log::debug('Mark MAPPING_COMPLETE_INDICATOR = true');
61-
session()->put(Constants::MAPPING_COMPLETE_INDICATOR, true);
83+
Log::debug('Fire next event.');
84+
event(new CompletedMapping($configuration));
6285
}
6386

6487

app/Http/Controllers/Import/ConversionController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public function start(Request $request): JsonResponse
302302

303303
return response()->json($importJobStatus->toArray());
304304
}
305+
305306
Log::debug(sprintf('Conversion routine "%s" was started successfully.', $flow));
306307
if (0 === count($transactions)) {
307308
// #10590 do not error out if no transactions are found.

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ private function camtIndex(Request $request, Configuration $configuration): View
143143
'explanation' => trans('camt.explain_B'),
144144
'fields' => $this->getFieldsForLevel('B'),
145145
];
146+
// var_dump($levels['B']);
147+
// var_dump($roles);
148+
// exit;
146149
$levels['C'] = [
147150
'title' => trans('camt.level_C'),
148151
'explanation' => trans('camt.explain_C'),
@@ -176,6 +179,7 @@ private function camtIndex(Request $request, Configuration $configuration): View
176179
'fields' => [
177180
// have to collect D by hand because of intermediate sections
178181
'entryDetailAccountServicerReference' => config('camt.fields.entryDetailAccountServicerReference'),
182+
'entryDetailEndToEndId' => config('camt.fields.entryDetailEndToEndId'),
179183
'entryDetailRemittanceInformationUnstructuredBlockMessage' => config('camt.fields.entryDetailRemittanceInformationUnstructuredBlockMessage'),
180184
'entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation' => config('camt.fields.entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation'),
181185
'section_tr' => ['section' => true, 'title' => 'transaction'],
@@ -192,6 +196,7 @@ private function camtIndex(Request $request, Configuration $configuration): View
192196
],
193197
];
194198
}
199+
$levels = $this->mergeLevelsAndRoles($levels, $roles);
195200

196201
return view('import.005-roles.index-camt', compact('mainTitle', 'configuration', 'subTitle', 'levels', 'doMapping', 'examples', 'roles'));
197202
}
@@ -234,13 +239,16 @@ private function processPostIndex(RolesPostRequest $request, Configuration $conf
234239

235240
// set role config as complete.
236241
session()->put(Constants::ROLES_COMPLETE_INDICATOR, true);
237-
242+
Log::debug('Set ROLES_COMPLETE_INDICATOR = true');
238243
// redirect to mapping thing.
239244
if (true === $needsMapping) {
245+
Log::debug('Redirect to mapping, because $needsMapping is true.');
246+
240247
return redirect()->route('006-mapping.index');
241248
}
242249
// otherwise, store empty mapping, and continue:
243250
// set map config as complete.
251+
Log::debug('Set READY_FOR_CONVERSION = true + redirect to conversion, because $needsMapping is false.');
244252
session()->put(Constants::READY_FOR_CONVERSION, true);
245253

246254
return redirect()->route('007-convert.index');
@@ -260,4 +268,31 @@ private function needMapping(array $array): bool
260268

261269
return $need;
262270
}
271+
272+
private function mergeLevelsAndRoles(array $levels, array $roles): array
273+
{
274+
foreach ($levels as $letter => $info) {
275+
foreach ($info['fields'] as $index => $field) {
276+
$title = $field['title'];
277+
$selected = $field['default_role'] ?? '_impossible';
278+
Log::debug(sprintf('Analysing level %s field "%s"', $letter, $title));
279+
if (array_key_exists($title, $roles)) {
280+
if ('_ignore' === $roles[$title]) {
281+
$selected = '_ignore';
282+
Log::debug(sprintf('Make default role "_ignore" for level %s field "%s"', $letter, $title));
283+
}
284+
if ($roles[$title] === $field['default_role']) {
285+
// $selected = $field['default_role'];
286+
Log::debug(sprintf('User has selected role "%s" for level %s field "%s"', $roles[$title], $letter, $title));
287+
}
288+
}
289+
if (!array_key_exists($title, $roles)) {
290+
Log::debug(sprintf('User has no role pre-selected for level %s field "%s"', $letter, $title));
291+
}
292+
$levels[$letter]['fields'][$index]['selected'] = $selected;
293+
}
294+
}
295+
296+
return $levels;
297+
}
263298
}

app/Http/Controllers/Import/MapController.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace App\Http\Controllers\Import;
2626

27+
use App\Events\CompletedMapping;
2728
use App\Exceptions\ImporterErrorException;
2829
use App\Http\Controllers\Controller;
2930
use App\Http\Middleware\MapControllerMiddleware;
@@ -96,14 +97,7 @@ public function index()
9697

9798
// if nothing to map, just set mappable to true and go to the next step:
9899
if (0 === count($data)) {
99-
// set map config as complete.
100-
session()->put(Constants::MAPPING_COMPLETE_INDICATOR, true);
101-
102-
// if "file", now ready for conversion
103-
if ('file' === $configuration->getFlow() || 'simplefin' === $configuration->getFlow()) {
104-
Log::debug('Its a file/simplefin, also set ready for conversion.');
105-
session()->put(Constants::READY_FOR_CONVERSION, true);
106-
}
100+
event(new CompletedMapping($configuration));
107101

108102
return redirect()->route('007-convert.index');
109103
}
@@ -542,16 +536,12 @@ public function postIndex(Request $request): RedirectResponse
542536
Log::debug(sprintf('New configuration is stored under key "%s".', session()->get(Constants::UPLOAD_CONFIG_FILE)));
543537

544538
// set map config as complete.
545-
session()->put(Constants::MAPPING_COMPLETE_INDICATOR, true);
546-
session()->put(Constants::READY_FOR_CONVERSION, true);
539+
event(new CompletedMapping($configuration));
547540
if (
548541
'nordigen' === $configuration->getFlow()
549542
|| 'spectre' === $configuration->getFlow()
550543
|| 'lunchflow' === $configuration->getFlow()
551544
|| 'simplefin' === $configuration->getFlow()) {
552-
// if nordigen, spectre, or simplefin, now ready for submission!
553-
session()->put(Constants::READY_FOR_SUBMISSION, true);
554-
555545
return redirect()->route('008-submit.index');
556546
}
557547

0 commit comments

Comments
 (0)