diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php
index fcf13fe8c0e..8cfdcf7e02b 100644
--- a/htdocs/compta/prelevement/class/bonprelevement.class.php
+++ b/htdocs/compta/prelevement/class/bonprelevement.class.php
@@ -64,6 +64,7 @@ class BonPrelevement extends CommonObject
public $emetteur_numero_compte;
public $emetteur_code_banque;
public $emetteur_number_key;
+ public $sepa_xml_pti_in_ctti;
public $emetteur_iban;
public $emetteur_bic;
@@ -77,6 +78,8 @@ class BonPrelevement extends CommonObject
public $statut; // 0-Wait, 1-Trans, 2-Done
public $labelStatus = array();
+ public $factures = array();
+
public $invoice_in_error = array();
public $thirdparty_in_error = array();
@@ -107,6 +110,7 @@ class BonPrelevement extends CommonObject
$this->emetteur_numero_compte = "";
$this->emetteur_code_banque = "";
$this->emetteur_number_key = "";
+ $this->sepa_xml_pti_in_ctti = false;
$this->emetteur_iban = "";
$this->emetteur_bic = "";
@@ -392,10 +396,10 @@ class BonPrelevement extends CommonObject
$amounts[$fac->id] = $facs[$i][1];
$amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
- $totalpaye = $fac->getSommePaiement();
+ $totalpaid = $fac->getSommePaiement();
$totalcreditnotes = $fac->getSumCreditNotesUsed();
$totaldeposits = $fac->getSumDepositsUsed();
- $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
+ $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
// @TODO Move this after creation of payment
if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) {
@@ -911,6 +915,7 @@ class BonPrelevement extends CommonObject
$this->db->begin();
$now = dol_now();
+ $ref = '';
/*
* Process order generation
@@ -1044,10 +1049,11 @@ class BonPrelevement extends CommonObject
}
$account = new Account($this->db);
if ($account->fetch($id) > 0) {
- $this->emetteur_code_banque = $account->code_banque;
+ $this->emetteur_code_banque = $account->code_banque;
$this->emetteur_code_guichet = $account->code_guichet;
$this->emetteur_numero_compte = $account->number;
- $this->emetteur_number_key = $account->cle_rib;
+ $this->emetteur_number_key = $account->cle_rib;
+ $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
$this->emetteur_iban = $account->iban;
$this->emetteur_bic = $account->bic;
@@ -1063,8 +1069,8 @@ class BonPrelevement extends CommonObject
// This also set the property $this->total with amount that is included into file
$result = $this->generate($format, $executiondate, $type);
if ($result < 0) {
- /*var_dump($this->error);
- var_dump($this->invoice_in_error); */
+ //var_dump($this->error);
+ //var_dump($this->invoice_in_error);
$error++;
}
}
@@ -1240,13 +1246,6 @@ class BonPrelevement extends CommonObject
}
$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
-
- /*
- $hookmanager->initHooks(array('myobjectdao'));
- $parameters=array('id'=>$this->id);
- $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
- if ($reshook > 0) $linkclose = $hookmanager->resPrint;
- */
} else {
$linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
}
@@ -1266,7 +1265,7 @@ class BonPrelevement extends CommonObject
global $action, $hookmanager;
$hookmanager->initHooks(array('banktransferdao'));
- $parameters = array('id'=>$this->id, 'getnomurl'=>$result);
+ $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
$result = $hookmanager->resPrint;
@@ -1489,7 +1488,7 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' '.$i.''.$CrLf);
fputs($this->file, ' '.$this->total.''.$CrLf);
fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf);
+ fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ''))).''.$CrLf);
fputs($this->file, ' '.$CrLf);
fputs($this->file, ' '.$CrLf);
fputs($this->file, ' '.$CrLf);
@@ -1605,7 +1604,7 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' '.$i.''.$CrLf);
fputs($this->file, ' '.$this->total.''.$CrLf);
fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf);
+ fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ''))).''.$CrLf);
fputs($this->file, ' '.$CrLf);
fputs($this->file, ' '.$CrLf);
fputs($this->file, ' '.$CrLf);
@@ -1834,7 +1833,7 @@ class BonPrelevement extends CommonObject
$DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d');
if ($type != 'bank-transfer') {
- // SEPA Paiement Information of buyer for Direct debit
+ // SEPA Paiement Information of buyer for Direct Debit
$XML_DEBITOR = '';
$XML_DEBITOR .= ' '.$CrLf;
$XML_DEBITOR .= ' '.$CrLf;
@@ -1855,16 +1854,16 @@ class BonPrelevement extends CommonObject
$XML_DEBITOR .= ' '.$CrLf;
$XML_DEBITOR .= ' '.$CrLf;
$XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($row_nom)))).''.$CrLf;
+ $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($row_nom), ''))).''.$CrLf;
$XML_DEBITOR .= ' '.$CrLf;
$XML_DEBITOR .= ' '.$row_country_code.''.$CrLf;
$addressline1 = strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""));
$addressline2 = strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => ""));
if (trim($addressline1)) {
- $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
if (trim($addressline2)) {
- $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
$XML_DEBITOR .= ' '.$CrLf;
$XML_DEBITOR .= ' '.$CrLf;
@@ -1887,6 +1886,24 @@ class BonPrelevement extends CommonObject
// Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum)
$XML_CREDITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('CT-'.dol_trunc($row_idfac.'-'.$row_ref, 20, 'right', 'UTF-8', 1)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
$XML_CREDITOR .= ' '.$CrLf;
+ if (!empty($this->sepa_xml_pti_in_ctti)) {
+ $XML_CREDITOR .= ' ' . $CrLf;
+
+ // Can be 'NORM' for normal or 'HIGH' for high priority level
+ if (!empty($conf->global->PAYMENTBYBANKTRANSFER_FORCE_HIGH_PRIORITY)) {
+ $instrprty = 'HIGH';
+ } else {
+ $instrprty = 'NORM';
+ }
+ $XML_CREDITOR .= ' '.$instrprty.'' . $CrLf;
+ $XML_CREDITOR .= ' ' . $CrLf;
+ $XML_CREDITOR .= ' SEPA' . $CrLf;
+ $XML_CREDITOR .= ' ' . $CrLf;
+ $XML_CREDITOR .= ' ' . $CrLf;
+ $XML_CREDITOR .= ' CORE' . $CrLf;
+ $XML_CREDITOR .= ' ' . $CrLf;
+ $XML_CREDITOR .= ' ' . $CrLf;
+ }
$XML_CREDITOR .= ' '.$CrLf;
$XML_CREDITOR .= ' '.round($row_somme, 2).''.$CrLf;
$XML_CREDITOR .= ' '.$CrLf;
@@ -1912,10 +1929,10 @@ class BonPrelevement extends CommonObject
$addressline1 = strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""));
$addressline2 = strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => ""));
if (trim($addressline1)) {
- $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
if (trim($addressline2)) {
- $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
$XML_CREDITOR .= ' '.$CrLf;
$XML_CREDITOR .= ' '.$CrLf;
@@ -2037,6 +2054,7 @@ class BonPrelevement extends CommonObject
$this->emetteur_code_guichet = $account->code_guichet;
$this->emetteur_numero_compte = $account->number;
$this->emetteur_number_key = $account->cle_rib;
+ $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
$this->emetteur_iban = $account->iban;
$this->emetteur_bic = $account->bic;
@@ -2060,7 +2078,7 @@ class BonPrelevement extends CommonObject
$RefBon = $obj->ref;
if ($type != 'bank-transfer') {
- // SEPA Paiement Information of my company for Direct debit
+ // SEPA Paiement Information of my company for Direct Debit
$XML_SEPA_INFO = '';
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.('DD/'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf;
@@ -2078,16 +2096,16 @@ class BonPrelevement extends CommonObject
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ''))).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
$addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => ""));
$addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => ""));
if ($addressline1) {
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
if ($addressline2) {
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
@@ -2105,8 +2123,8 @@ class BonPrelevement extends CommonObject
$XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS))).''.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), '')).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), '')).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;*/
$XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV
@@ -2131,29 +2149,29 @@ class BonPrelevement extends CommonObject
//$XML_SEPA_INFO .= ' False'.$CrLf;
$XML_SEPA_INFO .= ' '.$nombre.''.$CrLf;
$XML_SEPA_INFO .= ' '.$total.''.$CrLf;
- /*
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' SEPA'.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' TRF'.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' SECU'.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- */
+ if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) { // @TODO Using $format (FRST ou RCUR) in a section for a Credit Transfer looks strange.
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ $XML_SEPA_INFO .= ' SEPA' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ $XML_SEPA_INFO .= ' CORE' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $format . '' . $CrLf;
+ $XML_SEPA_INFO .= ' ' . $CrLf;
+ }
$XML_SEPA_INFO .= ' '.dol_print_date($dateTime_ETAD, 'dayrfc').''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ''))).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
$addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => ""));
$addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => ""));
if ($addressline1) {
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
if ($addressline2) {
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2)), 70, 'right', 'UTF-8', 1)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline2), ''), 70, 'right', 'UTF-8', 1)).''.$CrLf;
}
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
@@ -2171,8 +2189,8 @@ class BonPrelevement extends CommonObject
$XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale)))).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS))).''.$CrLf;
- $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS), '')).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_nospecial(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN), '')).''.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;
$XML_SEPA_INFO .= ' '.$CrLf;*/
$XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV