diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 1036fe9041c..54990330135 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -60,6 +60,7 @@ class BonPrelevement extends CommonObject var $labelstatut=array(); var $invoice_in_error=array(); + var $thirdparty_in_error=array(); /** @@ -756,17 +757,20 @@ class BonPrelevement extends CommonObject * @param int $banque dolibarr mysoc bank * @param int $agence dolibarr mysoc bank office (guichet) * @param string $mode real=do action, simu=test only + * @param string $format FRST, RCUR or ALL * @return int <0 if KO, nbre of invoice withdrawed if OK */ - function Create($banque=0, $agence=0, $mode='real') + function Create($banque=0, $agence=0, $mode='real', $format='ALL') { global $conf,$langs; - dol_syslog(__METHOD__."::Bank=".$banque." Office=".$agence, LOG_DEBUG); + dol_syslog(__METHOD__."::Bank=".$banque." Office=".$agence." mode=".$mode." format=".$format, LOG_DEBUG); require_once (DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once (DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); + if (empty($format)) return 'ErrorBadParametersForDirectDebitFileCreate'; + $error = 0; $datetimeprev = time(); @@ -776,9 +780,10 @@ class BonPrelevement extends CommonObject $puser = new User($this->db, $conf->global->PRELEVEMENT_USER); - /* - * Read invoices - */ + $this->invoice_in_error = array(); + $this->thirdparty_in_error = array(); + + // Read invoices $factures = array(); $factures_prev = array(); $factures_result = array(); @@ -851,6 +856,9 @@ class BonPrelevement extends CommonObject $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $soc->id); + if ($format == 'FRST' && $bac->frstrecur != 'FRST') continue; + if ($format == 'RCUR' && $bac->frstrecur != 'RCUR') continue; + if ($bac->verif() >= 1) { $factures_prev[$i] = $fac; @@ -890,13 +898,13 @@ class BonPrelevement extends CommonObject dol_syslog($out); // Return warning - $i=0; + /*$i=0; foreach ($this->thirdparty_in_error as $key => $val) { if ($i < 10) setEventMessages($val, null, 'warnings'); else setEventMessages('More error were discarded...', null, 'warnings'); $i++; - } + }*/ if (count($factures_prev) > 0) { @@ -1060,7 +1068,7 @@ class BonPrelevement extends CommonObject $this->factures = $factures_prev_id; // Generation of SEPA file $this->filename - $this->generate(); + $this->generate($format); } dol_syslog(__METHOD__."::End withdraw receipt, file ".$this->filename, LOG_DEBUG); } @@ -1255,14 +1263,16 @@ class BonPrelevement extends CommonObject * - Others countries: Warning message * File is generated with name this->filename * - * @return int 0 if OK, <0 if KO + * @param string $format FRST, RCUR or ALL + * @return int 0 if OK, <0 if KO */ - //TODO: Optimize code to read lines in a single function - function generate() + function generate($format='ALL') { - global $conf,$langs,$mysoc; + global $conf,$langs,$mysoc; - $result = 0; + //TODO: Optimize code to read lines in a single function + + $result = 0; dol_syslog(get_class($this)."::generate build file ".$this->filename); @@ -1340,7 +1350,7 @@ class BonPrelevement extends CommonObject // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all DrctDbtTxInf if ($result != -2) { - $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf); + $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format); } else { @@ -1663,9 +1673,10 @@ class BonPrelevement extends CommonObject * @param int $nombre 0 or 1 * @param float $total Total * @param string $CrLf End of line character + * @param string $format FRST or RCUR or ALL * @return string String with SEPA Sender */ - function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n') + function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST') { // SEPA INITIALISATION global $conf; @@ -1706,7 +1717,7 @@ class BonPrelevement extends CommonObject $country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY); $IdBon = sprintf("%05d", $obj->rowid); $RefBon = $obj->ref; - $type = ($nombre == 1) ? 'FRST' : 'RCUR' ; + // SEPA Paiement Information $XML_SEPA_INFO = ''; $XML_SEPA_INFO .= ' '.$CrLf; @@ -1721,7 +1732,7 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' CORE'.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$type.''.$CrLf; + $XML_SEPA_INFO .= ' '.$format.''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 1cdfe8d9a7c..700e587a6a6 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -45,6 +45,8 @@ $result = restrictedArea($user, 'prelevement', '', '', 'bons'); // Get supervariables $action = GETPOST('action','alpha'); +$mode = GETPOST('mode','alpha')?GETPOST('mode','alpha'):'real'; +$format = GETPOST('format','alpha'); /* @@ -63,7 +65,7 @@ if ($action == 'create') { // $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty $bprev = new BonPrelevement($db); - $result=$bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET); + $result=$bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format); if ($result < 0) { setEventMessages($bprev->error, $bprev->errors, 'errors'); @@ -76,7 +78,7 @@ if ($action == 'create') $mesg.='
'."\n"; foreach($bprev->invoice_in_error as $key => $val) { - $mesg.=$val."
\n"; + $mesg.=''.$val."
\n"; } } else @@ -146,8 +148,30 @@ print "
\n"; if ($nb) { - if ($pricetowithdraw) print ''.$langs->trans("CreateAll")."\n"; - else print ''.$langs->trans("CreateAll")."\n"; + if ($pricetowithdraw) + { + if ($mysoc->isInEEC()) + { + print ''.$langs->trans("CreateForSepaFRST")."\n"; + print ''.$langs->trans("CreateForSepaRCUR")."\n"; + } + else + { + print ''.$langs->trans("CreateAll")."\n"; + } + } + else + { + if ($mysoc->isInEEC()) + { + print ''.$langs->trans("CreateForSepaFRST")."\n"; + print ''.$langs->trans("CreateForSepaRCUR")."\n"; + } + else + { + print ''.$langs->trans("CreateAll")."\n"; + } + } } else { @@ -220,6 +244,8 @@ if ($resql) // RUM print ''; print $thirdpartystatic->display_rib('rum'); + $format = $thirdpartystatic->display_rib('format'); + if ($format) print ' ('.$format.')'; print ''; // Amount print ''; diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index 308987575f5..6b1babf9d88 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -55,7 +55,9 @@ StatusMotif5=RIB unusable StatusMotif6=Account without balance StatusMotif7=Judicial Decision StatusMotif8=Other reason -CreateAll=Withdraw all +CreateForSepaFRST=Create direct debit file (SEPA FRST) +CreateForSepaRCUR=Create direct debit file (SEPA RCUR) +CreateAll=Create direct debit file (all) CreateGuichet=Only office CreateBanque=Only bank OrderWaiting=Waiting for treatment diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index b8f54d86984..d1d218a0061 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2254,7 +2254,7 @@ class Societe extends CommonObject /** * Return bank number property of thirdparty (label or rum) * - * @param string $mode 'label' or 'rum' + * @param string $mode 'label' or 'rum' or 'format' * @return string Bank number */ function display_rib($mode='label') @@ -2279,6 +2279,10 @@ class Societe extends CommonObject } return $bac->rum; } + elseif ($mode == 'format') + { + return $bac->frstrecur; + } return 'BadParameterToFunctionDisplayRib'; }