Browse Source

Make sure all roles are in sync

pull/373/head
James Cole 2 years ago
parent
commit
fa76d83b35
  1. 404
      app/Http/Controllers/Import/File/RoleController.php
  2. 76
      app/Services/CSV/Roles/RoleService.php
  3. 3
      app/Services/Camt/Transaction.php
  4. 2
      resources/lang/en/camt.php
  5. 18
      resources/views/import/005-roles/index-camt.twig

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

@ -242,339 +242,71 @@ class RoleController extends Controller
$doMapping = $configuration->getDoMapping();
// four levels in a CAMT file, level A B C D. Each level has a pre-defined set of
// available fields and information.
// TODO should not be a big array right here maybe.
$levels = [
'A' => [
'title' => trans('camt.level_A'),
'explanation' => trans('camt.explain_A'),
'fields' => [
// TODO replace me with info from config.
[
'section' => false,
'title' => 'messageId',
'roles' => config('camt.roles.level_a'),
'mappable' => false,
'selected_role' => $roles['messageId'] ?? 'note', // todo from config
'example_data' => $examples['messageId'],
],
],
],
'B' => [
'title' => trans('camt.level_B'),
'explanation' => trans('camt.explain_B'),
'fields' => [
// TODO replace me with info from config.
[
'section' => false,
'title' => 'statementCreationDate',
'roles' => config('camt.roles.dates'),
'mappable' => false,
'selected_role' => $roles['statementCreationDate'] ?? 'date_process',
'example_data' => $examples['statementCreationDate'],
],
[
'section' => false,
'title' => 'statementAccountIban',
'selected_role' => $roles['statementAccountIban'] ?? 'account-iban',
'roles' => config('camt.roles.iban'),
'mappable' => true,
'do_mapping' => $doMapping['statementAccountIban'] ?? false,
'example_data' => $examples['statementAccountIban'],
],
[
'section' => false,
'title' => 'statementAccountNumber',
'selected_role' => $roles['statementAccountNumber'] ?? 'account-number',
'roles' => config('camt.roles.account_number'),
'mappable' => true,
'do_mapping' => $doMapping['statementAccountNumber'] ?? false,
'example_data' => $examples['statementAccountNumber'],
],
],
],
'C' => [
'title' => trans('camt.level_C'),
'explanation' => trans('camt.explain_C'),
'fields' => [
// TODO replace me with info from config.
[
'section' => false,
'title' => 'entryDate',
'selected_role' => $roles['entryDate'] ?? 'date_transaction',
'roles' => config('camt.roles.dates'),
'mappable' => false,
'example_data' => $examples['entryDate'],
],
[
'section' => false,
'title' => 'entryAccountServicerReference',
'selected_role' => $roles['entryAccountServicerReference'] ?? 'external-id',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryAccountServicerReference'],
],
[
'section' => false,
'title' => 'entryReference',
'selected_role' => $roles['entryReference'] ?? 'internal_reference',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryReference'],
],
[
'section' => false,
'title' => 'entryAdditionalInfo',
'selected_role' => $roles['entryAdditionalInfo'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryAdditionalInfo'],
],
//
[
'section' => true,
'title' => 'transaction',
],
// entryAmount
// TODO replace me with info from config.
[
'section' => false,
'title' => 'entryAmount',
'selected_role' => $roles['entryAmount'] ?? 'amount',
'roles' => config('camt.roles.amount'),
'mappable' => false,
'example_data' => $examples['entryAmount'],
],
// entryAmountCurrency
[
'section' => false,
'title' => 'entryAmountCurrency',
'selected_role' => $roles['entryAmountCurrency'] ?? 'currency-code',
'roles' => config('camt.roles.currency'),
'mappable' => true,
'do_mapping' => $doMapping['entryAmountCurrency'] ?? false,
'example_data' => $examples['entryAmountCurrency'],
],
// entryValueDate
[
'section' => false,
'title' => 'entryValueDate',
'selected_role' => $roles['entryValueDate'] ?? 'date_payment',
'roles' => config('camt.roles.dates'),
'mappable' => false,
'example_data' => $examples['entryValueDate'],
],
// entryBookingDate
[
'section' => false,
'title' => 'entryBookingDate',
'selected_role' => $roles['entryBookingDate'] ?? 'date_book',
'roles' => config('camt.roles.dates'),
'mappable' => false,
'example_data' => $examples['entryBookingDate'],
],
[
'section' => true,
'title' => 'Btc',
],
// entryBtcDomainCode
[
'section' => false,
'title' => 'entryBtcDomainCode',
'selected_role' => $roles['entryBtcDomainCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryBtcDomainCode'],
],
// entryBtcFamilyCode
[
'section' => false,
'title' => 'entryBtcFamilyCode',
'selected_role' => $roles['entryBtcFamilyCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryBtcFamilyCode'],
],
// entryBtcSubFamilyCode
[
'section' => false,
'title' => 'entryBtcSubFamilyCode',
'selected_role' => $roles['entryBtcSubFamilyCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryBtcSubFamilyCode'],
],
[
'section' => true,
'title' => 'opposingPart',
],
// entryDetailOpposingAccountIban
[
'section' => false,
'title' => 'entryOpposingAccountIban',
'selected_role' => $roles['entryOpposingAccountIban'] ?? 'opposing-iban',
'roles' => config('camt.roles.iban'),
'mappable' => true,
'do_mapping' => $doMapping['entryOpposingAccountIban'] ?? false,
'example_data' => $examples['entryDetailOpposingAccountIban'],
],
// entryDetailOpposingAccountNumber
[
'section' => false,
'title' => 'entryOpposingAccountNumber',
'selected_role' => $roles['entryOpposingAccountNumber'] ?? 'opposing-number',
'roles' => config('camt.roles.account_number'),
'mappable' => true,
'do_mapping' => $doMapping['entryOpposingAccountNumber'] ?? false,
'example_data' => $examples['entryOpposingAccountNumber'],
],
// entryDetailOpposingName
[
'section' => false,
'title' => 'entryOpposingName',
'selected_role' => $roles['entryOpposingName'] ?? 'opposing-name',
'roles' => config('camt.roles.account_name'),
'mappable' => true,
'do_mapping' => $doMapping['entryOpposingName'] ?? false,
'example_data' => $examples['entryOpposingName'],
],
],
$levels = [];
$levels['A'] = [
'title' => trans('camt.level_A'),
'explanation' => trans('camt.explain_A'),
'fields' => $this->getFieldsForLevel('A'),
];
$levels['B'] = [
'title' => trans('camt.level_B'),
'explanation' => trans('camt.explain_B'),
'fields' => $this->getFieldsForLevel('B'),
];
$levels['C'] = [
'title' => trans('camt.level_C'),
'explanation' => trans('camt.explain_C'),
'fields' => [
// have to collect C by hand because of intermediate sections
'entryDate' => config('camt.fields.entryDate'),
'entryAccountServicerReference' => config('camt.fields.entryAccountServicerReference'),
'entryReference' => config('camt.fields.entryReference'),
'entryAdditionalInfo' => config('camt.fields.entryAdditionalInfo'),
'section_transaction' => ['section' => true, 'title' => 'transaction',],
'entryAmount' => config('camt.fields.entryAmount'),
'entryAmountCurrency' => config('camt.fields.entryAmountCurrency'),
'entryValueDate' => config('camt.fields.entryValueDate'),
'entryBookingDate' => config('camt.fields.entryBookingDate'),
'section_btc' => ['section' => true, 'title' => 'Btc',],
'entryBtcDomainCode' => config('camt.fields.entryBtcDomainCode'),
'entryBtcFamilyCode' => config('camt.fields.entryBtcFamilyCode'),
'entryBtcSubFamilyCode' => config('camt.fields.entryBtcSubFamilyCode'),
'section_opposing' => ['section' => true, 'title' => 'opposingPart',],
'entryDetailOpposingAccountIban' => config('camt.fields.entryDetailOpposingAccountIban'),
'entryDetailOpposingAccountNumber' => config('camt.fields.entryDetailOpposingAccountNumber'),
'entryDetailOpposingName' => config('camt.fields.entryDetailOpposingName'),
],
'D' => [
'title' => trans('camt.level_D'),
'explanation' => trans('camt.explain_D'),
'fields' => [
// TODO replace me with info from config.
// entryDetailAccountServicerReference
[
'section' => false,
'title' => 'entryDetailAccountServicerReference',
'selected_role' => $roles['entryDetailAccountServicerReference'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailAccountServicerReference'],
],
// entryDetailRemittanceInformationUnstructuredBlockMessage
[
'section' => false,
'title' => 'entryDetailRemittanceInformationUnstructuredBlockMessage',
'selected_role' => $roles['entryDetailRemittanceInformationUnstructuredBlockMessage'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailRemittanceInformationUnstructuredBlockMessage'],
],
// entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation
[
'section' => false,
'title' => 'entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation',
'selected_role' => $roles['entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation'],
],
// section_transaction
[
'section' => true,
'title' => 'transaction',
],
// entryDetailAmount
[
'section' => false,
'title' => 'entryDetailAmount',
'selected_role' => $roles['entryDetailAmount'] ?? 'amount',
'roles' => config('camt.roles.amount'),
'mappable' => false,
'example_data' => $examples['entryDetailAmount'],
],
// entryDetailAmountCurrency
[
'section' => false,
'title' => 'entryDetailAmountCurrency',
'selected_role' => $roles['entryDetailAmountCurrency'] ?? 'currency-code',
'roles' => config('camt.roles.currency'),
'mappable' => true,
'do_mapping' => $doMapping['entryDetailAmountCurrency'] ?? false,
'example_data' => $examples['entryDetailAmountCurrency'],
],
// section_Btc
[
'section' => true,
'title' => 'Btc',
],
// entryDetailBtcDomainCode
[
'section' => false,
'title' => 'entryDetailBtcDomainCode',
'selected_role' => $roles['entryDetailBtcDomainCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailBtcDomainCode'],
],
// entryDetailBtcFamilyCode
[
'section' => false,
'title' => 'entryDetailBtcFamilyCode',
'selected_role' => $roles['entryDetailBtcFamilyCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailBtcFamilyCode'],
],
// entryDetailBtcSubFamilyCode
[
'section' => false,
'title' => 'entryDetailBtcSubFamilyCode',
'selected_role' => $roles['entryDetailBtcSubFamilyCode'] ?? 'note',
'roles' => config('camt.roles.meta'),
'mappable' => false,
'example_data' => $examples['entryDetailBtcSubFamilyCode'],
],
// section_opposingPart
[
'section' => true,
'title' => 'opposingPart',
],
// entryDetailOpposingAccountIban
[
'section' => false,
'title' => 'entryDetailOpposingAccountIban',
'selected_role' => $roles['entryDetailOpposingAccountIban'] ?? 'opposing-iban',
'roles' => config('camt.roles.iban'),
'mappable' => true,
'do_mapping' => $doMapping['entryDetailOpposingAccountIban'] ?? false,
'example_data' => $examples['entryDetailOpposingAccountIban'],
],
// entryDetailOpposingAccountNumber
[
'section' => false,
'title' => 'entryDetailOpposingAccountNumber',
'selected_role' => $roles['entryDetailOpposingAccountNumber'] ?? 'opposing-number',
'roles' => config('camt.roles.account_number'),
'mappable' => true,
'do_mapping' => $doMapping['entryDetailOpposingAccountNumber'] ?? false,
'example_data' => $examples['entryDetailOpposingAccountNumber'],
],
// entryDetailOpposingName
[
'section' => false,
'title' => 'entryDetailOpposingName',
'selected_role' => $roles['entryDetailOpposingName'] ?? 'opposing-name',
'roles' => config('camt.roles.account_name'),
'mappable' => true,
'do_mapping' => $doMapping['entryDetailOpposingName'] ?? false,
'example_data' => $examples['entryDetailOpposingName'],
],
],
];
$levels['D'] = [
'title' => trans('camt.level_D'),
'explanation' => trans('camt.explain_D'),
'fields' => [
// have to collect D by hand because of intermediate sections
'entryDetailAccountServicerReference' => config('camt.fields.entryDetailAccountServicerReference'),
'entryDetailRemittanceInformationUnstructuredBlockMessage' => config(
'camt.fields.entryDetailRemittanceInformationUnstructuredBlockMessage'
),
'entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation' => config(
'camt.fields.entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation'
),
'section_tr' => ['section' => true, 'title' => 'transaction',],
'entryDetailAmount' => config('camt.fields.entryDetailAmount'),
'entryDetailAmountCurrency' => config('camt.fields.entryDetailAmountCurrency'),
'section_btc' => ['section' => true, 'title' => 'Btc',],
'entryDetailBtcDomainCode' => config('camt.fields.entryDetailBtcDomainCode'),
'entryDetailBtcFamilyCode' => config('camt.fields.entryDetailBtcFamilyCode'),
'entryDetailBtcSubFamilyCode' => config('camt.fields.entryDetailBtcSubFamilyCode'),
'section_opposing' => ['section' => true, 'title' => 'opposingPart',],
'entryDetailOpposingAccountIban' => config('camt.fields.entryDetailOpposingAccountIban'),
'entryDetailOpposingAccountNumber' => config('camt.fields.entryDetailOpposingAccountNumber'),
'entryDetailOpposingName' => config('camt.fields.entryDetailOpposingName'),
],
];
return view(
'import.005-roles.index-camt',
compact('mainTitle', 'configuration', 'subTitle', 'levels')
compact('mainTitle', 'configuration', 'subTitle', 'levels', 'doMapping', 'examples', 'roles')
);
}
@ -620,4 +352,22 @@ class RoleController extends Controller
return redirect()->route('007-convert.index');
}
/**
* @param string $level
*
* @return array
*/
private function getFieldsForLevel(string $level): array
{
$allFields = config('camt.fields');
$return = [];
foreach ($allFields as $title => $field) {
if ($level === $field['level']) {
$return[$title] = $field;
}
}
return $return;
}
}

76
app/Services/CSV/Roles/RoleService.php

@ -135,34 +135,11 @@ class RoleService
$camtReader = new CamtReader(Config::getDefault());
$camtMessage = $camtReader->readString(StorageService::getContent(session()->get(Constants::UPLOAD_DATA_FILE))); // -> Level A
$transactions = [];
$examples = [
'messageId' => [],
'messageCreationDate' => [],
'statementId' => [],
'statementAccountIban' => [],
'statementAccountNumber' => [],
'statementCreationDate' => [],
'entryDate' => [],
'entryAccountServicerReference' => [],
'entryReference' => [],
'entryAdditionalInfo' => [],
'entryAmount' => [],
'entryAmountCurrency' => [],
'entryValueDate' => [],
'entryBookingDate' => [],
'entryBtcDomainCode' => [],
'entryBtcFamilyCode' => [],
'entryBtcSubFamilyCode' => [],
'entryDetailOpposingAccountIban' => [],
'entryDetailOpposingAccountNumber' => [],
'entryDetailOpposingName' => [],
'entryDetailAmount' => [],
'entryDetailAmountCurrency' => [],
'entryDetailAccountServicerReference' => [],
'entryDetailRemittanceInformationUnstructuredBlockMessage' => [],
'entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation' => [],
];
$statements = $camtMessage->getRecords();
$fieldNames = array_keys(config('camt.fields'));
foreach ($fieldNames as $name) {
$examples[$name] = [];
}
$statements = $camtMessage->getRecords();
/** @var CamtStatement $statement */
foreach ($statements as $statement) { // -> Level B
$entries = $statement->getEntries();
@ -186,49 +163,18 @@ class RoleService
if (5 === $count) {
break;
}
$examples['messageId'][] = $transaction->getField('messageId');
$examples['messageCreationDate'][] = $transaction->getField('messageCreationDate');
$examples['statementId'][] = $transaction->getField('statementId');
$examples['statementAccountIban'][] = $transaction->getField('statementAccountIban');
$examples['statementAccountNumber'][] = $transaction->getField('statementAccountNumber');
$examples['statementCreationDate'][] = $transaction->getField('statementCreationDate');
$examples ['entryDate'][] = $transaction->getField('entryDate');
$examples ['entryAccountServicerReference'][] = $transaction->getField(
'entryAccountServicerReference'
);
$examples ['entryReference'][] = $transaction->getField('entryReference');
$examples['entryAdditionalInfo'][] = $transaction->getField('entryAdditionalInfo');
$examples['entryAmount'][] = $transaction->getField('entryAmount');
$examples['entryAmountCurrency'][] = $transaction->getField('entryAmountCurrency');
$examples['entryValueDate'][] = $transaction->getField('entryValueDate');
$examples['entryBookingDate'][] = $transaction->getField('entryBookingDate');
$examples['entryBtcDomainCode'][] = $transaction->getField('entryBtcDomainCode');
$examples['entryBtcFamilyCode'][] = $transaction->getField('entryBtcFamilyCode');
$examples['entryBtcSubFamilyCode'][] = $transaction->getField('entryBtcSubFamilyCode');
$examples['entryDetailOpposingAccountIban'][] = $transaction->getField(
'entryDetailOpposingAccountIban'
);
$examples['entryDetailOpposingAccountNumber'][] = $transaction->getField(
'entryDetailOpposingAccountNumber'
);
$examples['entryDetailOpposingName'][] = $transaction->getField('entryDetailOpposingName');
$examples['entryDetailAmount'][] = $transaction->getField('entryDetailAmount');
$examples['entryDetailAmountCurrency'][] = $transaction->getField('entryDetailAmountCurrency');
$examples['entryDetailAccountServicerReference'][] = $transaction->getField(
'entryDetailAccountServicerReference'
);
$examples['entryDetailRemittanceInformationUnstructuredBlockMessage'][] = $transaction->getField(
'entryDetailRemittanceInformationUnstructuredBlockMessage'
);
$examples['entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation'][] = $transaction->getField('entryDetailRemittanceInformationStructuredBlockAdditionalRemittanceInformation');
foreach ($fieldNames as $name) {
$examples[$name][] = $transaction->getField($name);
}
$count++;
}
foreach($examples as $key => $list) {
foreach ($examples as $key => $list) {
$examples[$key] = array_unique($list);
$examples[$key] = array_filter($examples[$key], function(string $value) {
$examples[$key] = array_filter($examples[$key], function (string $value) {
return '' !== $value;
});
}
return $examples;
}

3
app/Services/Camt/Transaction.php

@ -101,10 +101,13 @@ class Transaction
return (string)$this->levelB->getCreatedOn()->format(self::TIME_FORMAT);
case 'entryBookingDate':
return (string)$this->levelC->getBookingDate()->format(self::TIME_FORMAT);
case 'entryDetailBtcDomainCode':
case 'entryBtcDomainCode':
return (string)$this->levelC->getBankTransactionCode()->getDomain()->getCode();
case 'entryDetailBtcFamilyCode':
case 'entryBtcFamilyCode':
return (string)$this->levelC->getBankTransactionCode()->getDomain()->getFamily()->getCode();
case 'entryDetailBtcSubFamilyCode':
case 'entryBtcSubFamilyCode':
return (string)$this->levelC->getBankTransactionCode()->getDomain()->getFamily()->getSubFamilyCode();
case 'entryOpposingAccountIban':

2
resources/lang/en/camt.php

@ -58,7 +58,9 @@ return [
'section_opposingPart' => 'Opposing Part',
'field_entryBtcDomainCode' => 'Domain Code',
'field_entryBtcFamilyCode' => 'Family Code',
'field_entryDetailBtcFamilyCode' => 'Family Code',
'field_entryBtcSubFamilyCode' => 'SubFamily Code',
'field_entryDetailBtcSubFamilyCode' => 'SubFamily Code',
'field_entryDetailOpposingAccountIban' => 'Opposing Account IBAN',
'field_entryDetailOpposingAccountNumber' => 'Opposing Account Number',
'field_entryDetailOpposingName' => 'Opposing Name',

18
resources/views/import/005-roles/index-camt.twig

@ -83,24 +83,26 @@
{% endif %}
</td>
<td>
{% if 0 == field.example_data|length %}
{% if 0 == examples[field.title]|length %}
<small class="text-muted"><em>(no example data)</em></small>
{% endif %}
{% if 0 != field.example_data|length %}
{% for example in field.example_data %}
{% if 0 != examples[field.title]|length %}
{% for example in examples[field.title] %}
<code>{{ example }}</code><br>
{% endfor %}
{% endif %}
</td>
<td>
{% if 0 == field.roles|length %}
{% if 0 == config('camt.roles.'~field.roles)|length %}
<small class="text-muted"><em>(no roles available)</em></small>
{% endif %}
{% if 0 != field.roles|length %}
{% if 0 != config('camt.roles.'~field.roles)|length %}
<select name="roles[{{ field.title }}]" id="roles_{{ field.title }}" class="form-control">
{% for roleKey, role in field.roles %}
{% for roleKey, role in config('camt.roles.'~field.roles) %}
<option value="{{ roleKey }}" label="{{ trans('import.column_'~roleKey) }}"
{% if field.selected_role == roleKey %}selected="selected"{% endif %}>
{% if field.default_role == roleKey %}selected="selected"{% endif %}
{% if field.default_role != roleKey and roles[field.title] == roleKey %}selected="selected"{% endif %}
>
{{ trans('import.column_'~roleKey) }}
</option>
{% endfor %}
@ -111,7 +113,7 @@
{% if true == field.mappable %}
<label for="do_mapping_{{ field.title }}">
<input type="checkbox" name="do_mapping[{{ field.title }}]" id="do_mapping_{{ field.title }}"
{% if field.do_mapping %}checked="checked"{% endif %}
{% if doMapping[field.title] %}checked="checked"{% endif %}
value="1"/>
</label>
{% endif %}

Loading…
Cancel
Save