Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CBIBdySDDReq_00_01_00 SEPA format #664

Merged
merged 9 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CRM/Admin/Form/Setting/SepaSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function buildQuickForm( ) {
$this->addElement('text', 'addcreditor_account_holder', E::ts("Account Holder"));
$this->addElement('text', 'addcreditor_bic', E::ts("BIC"));
$this->addElement('text', 'addcreditor_iban', E::ts("IBAN"), array('size' => 30));
$this->addElement('text', 'addcreditor_cuc', E::ts("CUC"));
$this->addElement('select', 'addcreditor_currency', E::ts("Currency"), $currencies);
$this->addElement('select', 'addcreditor_type', E::ts("Type"), $creditor_types);
$this->addElement('select', 'addcreditor_pain_version', E::ts("PAIN Version"), array('' => E::ts('- select -')) + CRM_Core_OptionGroup::values('sepa_file_format'));
Expand Down
1 change: 1 addition & 0 deletions CRM/Sepa/BAO/SEPACreditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static function addDefaultCreditorIfMissing() {
'sepa_file_format_id' => 1,
'pi_ooff' => "{$classic_payment_instrument_ids['OOFF']}",
'pi_rcur' => "{$classic_payment_instrument_ids['FRST']}-{$classic_payment_instrument_ids['RCUR']}",
'cuc' => 'SEPATEST',
]);
} catch (Exception $ex) {
throw new Exception("Couldn't create default creditor: " . $ex->getMessage());
Expand Down
21 changes: 21 additions & 0 deletions CRM/Sepa/DAO/SEPACreditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ class CRM_Sepa_DAO_SEPACreditor extends CRM_Core_DAO {
*/
public $bic;

/**
* CUC of the creditor
*
* @var string
*/
public $cuc;

/**
* prefix for mandate identifiers
*
Expand Down Expand Up @@ -536,6 +543,20 @@ public static function &fields() {
'localizable' => 0,
'add' => NULL,
],
'cuc' => [
'name' => 'cuc',
'type' => CRM_Utils_Type::T_STRING,
'title' => E::ts('CUC'),
'description' => E::ts('CUC of the creditor'),
'maxlength' => 8,
'size' => CRM_Utils_Type::EIGHT,
'where' => 'civicrm_sdd_creditor.cuc',
'table_name' => 'civicrm_sdd_creditor',
'entity' => 'SEPACreditor',
'bao' => 'CRM_Sepa_DAO_SEPACreditor',
'localizable' => 0,
'add' => null,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
22 changes: 21 additions & 1 deletion CRM/Sepa/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,5 +459,25 @@ public function upgrade_1701() {
}
return TRUE;
}
}

/**
* Add new file format CBIBdySDDReq.00.01.00
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_1702() {
$dsn = DB::parseDSN(CIVICRM_DSN);
$this->ctx->log->info("Adding new 'SDD - CBIBdySDDReq.00.01.00");
$customData = new CRM_Sepa_CustomData('org.project60.sepa');
$customData->syncOptionGroup(E::path('resources/formats_option_group.json'));

// add currency
$this->ctx->log->info('Adding CUC ("Codice Univoco CBI" for CBIBdySDDReq.00.01.00 standard');
$cuc = CRM_Core_DAO::singleValueQuery("SHOW COLUMNS FROM `civicrm_sdd_creditor` LIKE 'cuc';");
if (!$cuc) {
$this->executeSql("ALTER TABLE civicrm_sdd_creditor ADD COLUMN `cuc` varchar(8) COMMENT 'CUC of the creditor (Codice Univoco CBI)';");
}
return TRUE;
}
}
2 changes: 2 additions & 0 deletions js/SepaSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function fetchCreditor(id, isCopy) {
cj("#addcreditor_currency").val(data['currency']);
cj("#addcreditor_type").val(data['creditor_type']);
cj("#addcreditor_uses_bic").prop("checked", (data['uses_bic'] == "1"));
cj("#addcreditor_cuc").val(data['cuc']);
cj("#is_test_creditor").prop("checked", (data['category'] == "TEST"));
cj('#addcreditor').show(500);

Expand Down Expand Up @@ -222,6 +223,7 @@ function updateCreditor() {
"addcreditor_type": "creditor_type",
"addcreditor_creditor_id": "creditor_id",
"addcreditor_uses_bic": "uses_bic",
"addcreditor_cuc": "cuc",
"custom_txmsg": "custom_txmsg"};

// update creditor information
Expand Down
9 changes: 9 additions & 0 deletions resources/formats_option_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
"filter": "0",
"is_reserved": "1",
"is_active": "1"
},
{
"_lookup": ["value"],
"_translate": ["label"],
"label": "SDD - CBIBdySDDReq.00.01.00",
"name": "CBIBdySDDReq_00_01_00",
"filter": "0",
"is_reserved": "1",
"is_active": "1"
}
]
}
1 change: 1 addition & 0 deletions sql/sepa.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS `civicrm_sdd_creditor`(
`pi_ooff` varchar(64) COMMENT 'payment instruments, comma separated, to be used for one-off collections',
`pi_rcur` varchar(64) COMMENT 'payment instruments, comma separated, to be used for recurring collections',
`uses_bic` tinyint COMMENT 'If true, BICs are not used for this creditor',
`cuc` varchar(8) COMMENT 'CUC of the creditor (Codice Univoco CBI)',
PRIMARY KEY ( `id` ),
CONSTRAINT FK_civicrm_sdd_creditor_creditor_id FOREIGN KEY (`creditor_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL,
CONSTRAINT FK_civicrm_sdd_creditor_country_id FOREIGN KEY (`country_id`) REFERENCES `civicrm_country`(`id`) ON DELETE SET NULL
Expand Down
5 changes: 5 additions & 0 deletions templates/CRM/Admin/Form/Setting/SepaSettings.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,9 @@
<p>{ts}If you leave this empty, no (new) one-off mandates can be created any more.{/ts}</p>
<p>{ts}<strong>Caution:</strong> Be sure you know what you're doing before changing these settings.{/ts}</p>
{/htxt}

{htxt id='id-cuc'}
<p>{ts}"Codice Univoco CBI" (CUC) of the financial institution of the creditor.{/ts}</p>
<p>{ts}<strong>Be careful when changing this!</strong>{/ts}</p>
{/htxt}
{/crmScope}
6 changes: 6 additions & 0 deletions templates/CRM/Admin/Form/Setting/SepaSettings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ div.sdd-add-creditor {
{$form.addcreditor_bic.html}
</td>
</tr>
<tr>
<td class="label">{$form.addcreditor_cuc.label} <a onclick='CRM.help("{ts}CUC{/ts}", {literal}{"id":"id-cuc","file":"CRM\/Admin\/Form\/Setting\/SepaSettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon">&nbsp;</a></td>
<td>
{$form.addcreditor_cuc.html}
</td>
</tr>
<tr>
<td class="label">{$form.addcreditor_pain_version.label} <a onclick='CRM.help("{ts}PAIN Version{/ts}", {literal}{"id":"id-pain","file":"CRM\/Admin\/Form\/Setting\/SepaSettings"}{/literal}); return false;' href="#" title="{ts}Help{/ts}" class="helpicon">&nbsp;</a></td>
<td>
Expand Down
19 changes: 19 additions & 0 deletions templates/Sepa/Formats/CBIBdySDDReq_00_01_00/Format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*-------------------------------------------------------+
| Project 60 - SEPA direct debit |
| Copyright (C) 2016-2018 |
| Author: @scardinius |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/

class CRM_Sepa_Logic_Format_CBIBdySDDReq_00_01_00 extends CRM_Sepa_Logic_Format {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<PMRQ:PmtInf xmlns:PMRQ="urn:CBI:xsd:CBISDDReqLogMsg.00.01.00">
<PMRQ:PmtInfId>{$group.reference}</PMRQ:PmtInfId>
<PMRQ:PmtMtd>DD</PMRQ:PmtMtd>
<PMRQ:PmtTpInf>
<PMRQ:SvcLvl>
<PMRQ:Cd>SEPA</PMRQ:Cd>
</PMRQ:SvcLvl>
<PMRQ:LclInstrm>
<PMRQ:Cd>CORE</PMRQ:Cd>
</PMRQ:LclInstrm>
<PMRQ:SeqTp>{$group.type}</PMRQ:SeqTp>
<PMRQ:CtgyPurp>
<PMRQ:Cd>OTHR</PMRQ:Cd>
</PMRQ:CtgyPurp>
</PMRQ:PmtTpInf>
<PMRQ:ReqdColltnDt>{$group.collection_date|crmDate:"%Y-%m-%d"}</PMRQ:ReqdColltnDt>
<PMRQ:Cdtr>
<PMRQ:Nm>{$creditor.name}</PMRQ:Nm>
</PMRQ:Cdtr>
<PMRQ:CdtrAcct>
<PMRQ:Id>
<PMRQ:IBAN>{$creditor.iban}</PMRQ:IBAN>
</PMRQ:Id>
</PMRQ:CdtrAcct>
<PMRQ:CdtrAgt>
<PMRQ:FinInstnId>
<PMRQ:ClrSysMmbId>
<PMRQ:MmbId>{$creditor.iban|regex_replace:'/[A-Z][A-Z][0-9][0-9][A-Z]/':""|truncate:5:""}</PMRQ:MmbId>
</PMRQ:ClrSysMmbId>
</PMRQ:FinInstnId>
</PMRQ:CdtrAgt>
<PMRQ:CdtrSchmeId>
<PMRQ:Nm>{$creditor.name}</PMRQ:Nm>
<PMRQ:Id>
<PMRQ:PrvtId>
<PMRQ:Othr>
<PMRQ:Id>{$creditor.identifier}</PMRQ:Id>
</PMRQ:Othr>
</PMRQ:PrvtId>
</PMRQ:Id>
</PMRQ:CdtrSchmeId>

{foreach from=$contributions item="contribution"}
<PMRQ:DrctDbtTxInf xmlns:PMRQ="urn:CBI:xsd:CBISDDReqLogMsg.00.01.00">
<PMRQ:PmtId>
<PMRQ:InstrId>INSTRID-{$contribution.end2endID}</PMRQ:InstrId>
<PMRQ:EndToEndId>{$contribution.end2endID}</PMRQ:EndToEndId>
</PMRQ:PmtId>
<PMRQ:InstdAmt Ccy="{$contribution.currency}">{$contribution.total_amount}</PMRQ:InstdAmt>
<PMRQ:DrctDbtTx>
<PMRQ:MndtRltdInf>
<PMRQ:MndtId>{$contribution.reference}</PMRQ:MndtId>
<PMRQ:DtOfSgntr>{$contribution.date|crmDate:"%Y-%m-%d"}</PMRQ:DtOfSgntr>
</PMRQ:MndtRltdInf>
</PMRQ:DrctDbtTx>
<PMRQ:Dbtr>
<PMRQ:Nm>{$contribution.display_name}</PMRQ:Nm>
</PMRQ:Dbtr>
<PMRQ:DbtrAcct>
<PMRQ:Id>
<PMRQ:IBAN>{$contribution.iban}</PMRQ:IBAN>
</PMRQ:Id>
</PMRQ:DbtrAcct>
<PMRQ:RmtInf>
<PMRQ:Ustrd>{$contribution.message}</PMRQ:Ustrd>
</PMRQ:RmtInf>
</PMRQ:DrctDbtTxInf>
{/foreach}

</PMRQ:PmtInf>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
</BODY:CBISDDReqLogMsg>
</BODY:CBIEnvelSDDReqLogMsg>
</BODY:CBIBdySDDReq>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" standalone="yes"?>
<BODY:CBIBdySDDReq xmlns:PMRQ="urn:CBI:xsd:CBISDDReqLogMsg.00.01.00" xmlns:BODY="urn:CBI:xsd:CBIBdySDDReq.00.01.00" xmlns:SGNT="urn:CBI:xsd:CBISgnInf.001.04">
<BODY:PhyMsgInf>
<BODY:PhyMsgTpCd>INC-SDDC-01</BODY:PhyMsgTpCd>
<BODY:NbOfLogMsg>1</BODY:NbOfLogMsg>
</BODY:PhyMsgInf>
<BODY:CBIEnvelSDDReqLogMsg>
<BODY:CBISDDReqLogMsg xmlns:BODY="urn:CBI:xsd:CBIBdySDDReq.00.01.00">
<PMRQ:GrpHdr xmlns:PMRQ="urn:CBI:xsd:CBISDDReqLogMsg.00.01.00">
<PMRQ:MsgId>{$file.reference}</PMRQ:MsgId>
{* for some reason, the seconds (%s) in the following line will not be converted correctly, hence 42 *}
<PMRQ:CreDtTm>{$file.created_date|crmDate:"%Y-%m-%dT%H:%i:42"}</PMRQ:CreDtTm>
<PMRQ:NbOfTxs>{$nbtransactions}</PMRQ:NbOfTxs>
<PMRQ:CtrlSum>{$total}</PMRQ:CtrlSum>
<PMRQ:InitgPty>
<PMRQ:Nm>{$creditor.name}</PMRQ:Nm>
<PMRQ:Id>
<PMRQ:OrgId>
<PMRQ:Othr>
<PMRQ:Id>{$creditor.cuc}</PMRQ:Id>
<PMRQ:Issr>CBI</PMRQ:Issr>
</PMRQ:Othr>
</PMRQ:OrgId>
</PMRQ:Id>
</PMRQ:InitgPty>
</PMRQ:GrpHdr>
7 changes: 7 additions & 0 deletions xml/schema/CRM/Sepa/Creditor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,11 @@
<comment>If true, BICs are not used for this creditor</comment>
</field>

<field>
<name>cuc</name>
<title>CUC</title>
<type>varchar</type>
<length>8</length>
<comment>CUC of the creditor</comment>
</field>
</table>