diff --git a/banking_orders.install b/banking_orders.install index f5105c32edc747ec28c885beafd9afac1662dc8b..4562b59785e7b5a8a955e4ad8622275b19771a5a 100644 --- a/banking_orders.install +++ b/banking_orders.install @@ -30,3 +30,33 @@ function banking_orders_update_8001(&$sandbox) { \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('order_type', 'bank_order', 'bank_order', $storage_definition); } + +/** + * Add date field to bank order line. + */ +function banking_orders_update_8002(&$sandbox) { + $storage_definition = BaseFieldDefinition::create('datetime') + ->setLabel(t('Execution Date')) + ->setDescription(t('The requested execution date.')) + ->setSettings([ + 'datetime_type' => 'date', + ]) + ->setDefaultValue('') + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], + 'weight' => 4, + ]) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => 4, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition('date', 'bank_order_line', 'bank_order_line', $storage_definition); +} diff --git a/src/Entity/BankOrderLine.php b/src/Entity/BankOrderLine.php index e6c36b15370882366f2984b4ff5776d1828a81a3..87ec6197f69c36609f27f58c9fbc7287623bf53f 100644 --- a/src/Entity/BankOrderLine.php +++ b/src/Entity/BankOrderLine.php @@ -136,7 +136,7 @@ class BankOrderLine extends ContentEntityBase implements BankOrderLineInterface if (!$this->get('extra')->isEmpty()) { $data = $this->get('extra')->first()->getValue(); } - return isset($data[$key]) ? $data[$key] : $default; + return $data[$key] ?? $default; } /** @@ -189,6 +189,28 @@ class BankOrderLine extends ContentEntityBase implements BankOrderLineInterface ->setDisplayConfigurable('view', TRUE) ->setRequired(TRUE); + $fields['date'] = BaseFieldDefinition::create('datetime') + ->setLabel(t('Execution Date')) + ->setDescription(t('The requested execution date.')) + ->setSettings([ + 'datetime_type' => 'date', + ]) + ->setDefaultValue('') + ->setDisplayOptions('view', [ + 'label' => 'above', + 'type' => 'datetime_default', + 'settings' => [ + 'format_type' => 'date', + ], + 'weight' => 4, + ]) + ->setDisplayOptions('form', [ + 'type' => 'string_textfield', + 'weight' => 4, + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + $fields['endtoendid'] = BaseFieldDefinition::create('string') ->setLabel(t('End to End ID')) ->setDescription(t('The End to End ID of the Bank order line entity.')) diff --git a/src/Plugin/BankOrderExportPlugin/SepaSct.php b/src/Plugin/BankOrderExportPlugin/SepaSct.php index 7496ed7fb642e4667f72877d237177a8adf8138e..93c44722a5acb8404067b09b6bb9a327bf8287e4 100644 --- a/src/Plugin/BankOrderExportPlugin/SepaSct.php +++ b/src/Plugin/BankOrderExportPlugin/SepaSct.php @@ -100,20 +100,7 @@ class SepaSct extends PluginBase implements PluginFormInterface, BankOrderExport "{$order->getName()}", $version ); - $context['sandbox']['collection'] = $context['sandbox']['file']->addCollection( - [ - // Required information about the debtor. - // ID of the payment collection. - 'pmtInfId' => "{$order->getName()}", - // Debtor (max 70 characters). - 'dbtr' => $order->get('bank_account')->entity->get('name')->value, - // IBAN of the Debtor. - 'iban' => preg_replace('/\s+/', '', $order->get('bank_account')->entity->get('number')->value), - 'ccy' => 'EUR', - // BatchBooking, only 'true' or 'false'. - 'btchBookg' => 'false', - ] - ); + $context['sandbox']['collections'] = []; } for ($i = 0; $i < 100; $i++) { @@ -138,9 +125,31 @@ class SepaSct extends PluginBase implements PluginFormInterface, BankOrderExport return; } + // Create collection if it doesn't exit yet. + $date = $line->get('date')->value ?: 'asap'; + if (!array_key_exists($date, $context['sandbox']['collections'])) { + $collection_data = [ + // Required information about the debtor. + // ID of the payment collection. + 'pmtInfId' => str_replace('-', ' ', "{$date}"), + // Debtor (max 70 characters). + 'dbtr' => $order->get('bank_account')->entity->get('name')->value, + // IBAN of the Debtor. + 'iban' => preg_replace('/\s+/', '', $order->get('bank_account')->entity->get('number')->value), + 'ccy' => 'EUR', + // BatchBooking, only 'true' or 'false'. + 'btchBookg' => 'false', + ]; + if ($date !== 'none') { + $collection_data['reqdExctnDt'] = $date; + } + $collection = $context['sandbox']['collections'][$date] = $context['sandbox']['file']->addCollection($collection_data); + } + $collection = $context['sandbox']['collections'][$date]; + $pmtId = $line->getData('pmtId'); - $context['sandbox']['collection']->addPayment([ + $collection->addPayment([ // Required information about the creditor. // ID of the payment (EndToEndId). 'pmtId' => $pmtId ? $pmtId : $line->id(),