From 856c8f24de618128d42df4e3492ceb5fc4c46ee3 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 27 Feb 2015 18:13:24 +0100 Subject: [PATCH] Fix: Bad SEPA xml file creation Conflicts: htdocs/compta/prelevement/class/bonprelevement.class.php --- ChangeLog | 1 + .../class/bonprelevement.class.php | 51 ++++++++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index a38c7751875..ebf41dd0516 100644 --- a/ChangeLog +++ b/ChangeLog @@ -222,6 +222,7 @@ Dolibarr better: - Fix: [ bug #1830 ] Salaries payment only allows checking accounts - Fix: [ bug #1825 ] External agenda: hide/show checkbox doesn't work - Fix: [ bug #1790 ] Email form behaves in an unexpected way when pressing Enter key +- Fix: Bad SEPA xml file creation ***** ChangeLog for 3.6.2 compared to 3.6.1 ***** - Fix: fix ErrorBadValueForParamNotAString error message in price customer multiprice. diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index d8324178f87..63ad32f9bf9 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1249,14 +1249,29 @@ class BonPrelevement extends CommonObject $fileDebiteurSection = ''; $fileEmetteurSection = ''; $i = 0; + $j = 0; $this->total = 0; /* * section Debiteur (sepa Debiteurs bloc lines) */ - $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; - $sql.= " pl.client_nom as name, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; - $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.iban_prefix as iban, rib.bic as bic, rib.datec, rib.rowid as drum"; + + $sql = "SELECT f.facnumber as fac FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."prelevement_facture as pf, ".MAIN_DB_PREFIX."societe as soc, ".MAIN_DB_PREFIX."c_country as p, ".MAIN_DB_PREFIX."societe_rib as rib WHERE pl.fk_prelevement_bons = ".$this->id." AND pl.rowid = pf.fk_prelevement_lignes AND pf.fk_facture = f.rowid AND soc.fk_pays = p.rowid AND soc.rowid = f.fk_soc AND rib.fk_soc = f.fk_soc AND rib.default_rib = 1"; + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + while ($j < $num) + { + $objfac = $this->db->fetch_object($resql); + $ListOfFactures = $ListOfFactures . $objfac->fac . ","; + $j++; + } + } + + $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, soc.datec, p.code as country_code,"; + $sql.= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; + $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum"; $sql.= " FROM"; $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; $sql.= " ".MAIN_DB_PREFIX."facture as f,"; @@ -1279,7 +1294,7 @@ class BonPrelevement extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->name, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->facnumber, $obj->idfac, $obj->iban, $obj->bic, $obj->datec, $obj->drum); + $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $ListOfFactures , $obj->idfac, $obj->iban, $obj->bic, $obj->datec, $obj->drum); $this->total = $this->total + $obj->somme; $i++; } @@ -1314,13 +1329,14 @@ class BonPrelevement extends CommonObject fputs($this->file, ' '.$this->total.''.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$this->raison_sociale.''.$CrLf); -/* fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.$CrLf); - fputs($this->file, ' 0533883248'.$CrLf); - fputs($this->file, ' KBO-BCE'.$CrLf); + fputs($this->file, ' '.$CrLf); + fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); + fputs($this->file, ' '.$conf->global->PRELEVEMENT_ICS.''.$CrLf); + fputs($this->file, ' '.$CrLf); + fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); -*/ fputs($this->file, ' '.$CrLf); + fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); // SEPA File Emetteur if ($result != -2) @@ -1509,19 +1525,19 @@ class BonPrelevement extends CommonObject // Define value for RUM // Example: RUMCustomerCode-CustomerBankAccountId-01424448606 (note: Date is date of creation of CustomerBankAccountId) $Date_Rum = strtotime($row_datec); - $pre = ($date_Rum > 1359673200) ? 'RUM' : '++R'; - $Rum = dol_trunc($pre.$row_code_client.'-'.$row_drum.'-0'.date('U', $Date_Rum), 35, 'right', 'UTF-8', 1); - + $DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d'); + $pre = ($date_Rum > 1359673200) ? 'Rum' : '++R'; + $Rum = $pre.$row_code_client.$row_drum.'-0'.date('U', $Date_Rum); $XML_DEBITOR =''; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.('AS-'.$row_facnumber.'-'.$Rowing).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.round($row_somme, 2).''.$CrLf; + $XML_DEBITOR .=' '.round($row_somme, 2).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$Rum.''.$CrLf; - $XML_DEBITOR .=' '.$row_datec.''.$CrLf; + $XML_DEBITOR .=' '.$DtOfSgntr.''.$CrLf; $XML_DEBITOR .=' false'.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; @@ -1534,17 +1550,18 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .=' '.strtoupper(dol_string_unaccent($row_nom)).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$row_country_code.''.$CrLf; - $XML_DEBITOR .=' '.strtr($row_adr, array(CHR(13) => ", ", CHR(10) => "")).''.$CrLf; + $XML_DEBITOR .=' '.strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")).''.$CrLf; $XML_DEBITOR .=' '.dol_string_unaccent($row_zip.' '.$row_town).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.$row_iban.''.$CrLf; + $XML_DEBITOR .=' '.preg_replace('/\s/', '', $row_iban).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.($row_facnumber.'/'.$Rowing.'/'.$Rum).''.$CrLf; + // $XML_DEBITOR .=' '.($row_facnumber.'/'.$Rowing.'/'.$Rum).''.$CrLf; + $XML_DEBITOR .=' '.$row_facnumber.''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; return $XML_DEBITOR;