';
$thirdpartystatic = new Societe($db);
-$invoicestatic = new Facture($db);
+$invoicestatic = new FactureFournisseur($db);
$bprev = new BonPrelevement($db);
print '
';
diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php
index 743c1e47c2e..4ec2b5d3443 100644
--- a/htdocs/compta/prelevement/card.php
+++ b/htdocs/compta/prelevement/card.php
@@ -146,11 +146,9 @@ if (empty($reshook))
$dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
$error = $object->set_infocredit($user, $dt);
-
if ($error)
{
- header("Location: card.php?id=".$id."&error=$error");
- exit;
+ setEventMessages($object->error, $object->errors, 'errors');
}
}
}
diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php
index 1ac0926792e..1bea234abfc 100644
--- a/htdocs/compta/prelevement/class/bonprelevement.class.php
+++ b/htdocs/compta/prelevement/class/bonprelevement.class.php
@@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
+require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
@@ -67,6 +68,9 @@ class BonPrelevement extends CommonObject
public $emetteur_bic;
public $emetteur_ics;
+ public $date_trans;
+ public $user_trans;
+
public $total;
public $fetched;
public $statut; // 0-Wait, 1-Trans, 2-Done
@@ -405,7 +409,7 @@ class BonPrelevement extends CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Set direct debit order to "credited" status.
+ * Set direct debit or credit transfer order to "paid" status.
*
* @param User $user Id of user
* @param int $date date of action
@@ -420,118 +424,151 @@ class BonPrelevement extends CommonObject
if ($this->fetched == 1)
{
- if ($date >= $this->date_trans)
+ if ($date < $this->date_trans)
{
- if ($this->db->begin())
+ $this->error = 'DateOfMovementLowerThanDateOfFileTransmission';
+ dol_syslog("bon-prelevment::set_infocredit 1027 ".$this->error);
+ return -1027;
+ }
+
+ $this->db->begin();
+
+ $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
+ $sql .= " SET fk_user_credit = ".$user->id;
+ $sql .= ", statut = ".self::STATUS_CREDITED;
+ $sql .= ", date_credit = '".$this->db->idate($date)."'";
+ $sql .= " WHERE rowid=".$this->id;
+ $sql .= " AND entity = ".$conf->entity;
+ $sql .= " AND statut = ".self::STATUS_TRANSFERED;
+
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $langs->load('withdrawals');
+ $subject = $langs->trans("InfoCreditSubject", $this->ref);
+ $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
+
+ //Add payment of withdrawal into bank
+ $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
+ $facs = array();
+ $amounts = array();
+ $amountsperthirdparty = array();
+
+ $facs = $this->getListInvoices(1);
+
+ // Loop on each invoice. $facs=array(0=>id, 1=>amount requested)
+ $num = count($facs);
+ for ($i = 0; $i < $num; $i++)
{
- $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
- $sql .= " SET fk_user_credit = ".$user->id;
- $sql .= ", statut = ".self::STATUS_CREDITED;
- $sql .= ", date_credit = '".$this->db->idate($date)."'";
- $sql .= " WHERE rowid=".$this->id;
- $sql .= " AND entity = ".$conf->entity;
- $sql .= " AND statut = ".self::STATUS_TRANSFERED;
-
- if ($this->db->query($sql))
- {
- $langs->load('withdrawals');
- $subject = $langs->trans("InfoCreditSubject", $this->ref);
- $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
-
- //Add payment of withdrawal into bank
- $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
- $facs = array();
- $amounts = array();
- $amountsperthirdparty = array();
-
- $facs = $this->getListInvoices(1);
-
- // Loop on each invoice. $facs=array(0=>id, 1=>amount requested)
- $num = count($facs);
- for ($i = 0; $i < $num; $i++)
- {
- $fac = new Facture($this->db);
- $fac->fetch($facs[$i][0]);
- $amounts[$fac->id] = $facs[$i][1];
- $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
-
- $totalpaye = $fac->getSommePaiement();
- $totalcreditnotes = $fac->getSumCreditNotesUsed();
- $totaldeposits = $fac->getSumDepositsUsed();
- $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
-
- if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) {
- $result = $fac->set_paid($user);
- }
- }
-
- // Make one payment per customer
- foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts)
- {
- $paiement = new Paiement($this->db);
- $paiement->datepaye = $date;
- $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice
- $paiement->paiementid = 3; //
- $paiement->num_payment = $this->ref; // Set ref of direct debit note
- $paiement->num_paiement = $this->ref; // For backward compatibility
- $paiement->id_prelevement = $this->id;
-
- $paiement_id = $paiement->create($user);
- if ($paiement_id < 0)
- {
- dol_syslog(get_class($this)."::set_infocredit AddPayment Error");
- $error++;
- } else {
- $result = $paiement->addPaymentToBank($user, 'payment', '(WithdrawalPayment)', $bankaccount, '', '');
- if ($result < 0)
- {
- dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error");
- $error++;
- }
- }
- //var_dump($paiement->amounts);
- //var_dump($thirdpartyid);
- //var_dump($cursoramounts);
- }
-
- // Update withdrawal line
- // TODO: Translate to ligneprelevement.class.php
- $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
- $sql .= " SET statut = 2";
- $sql .= " WHERE fk_prelevement_bons = ".$this->id;
-
- if (!$this->db->query($sql))
- {
- dol_syslog(get_class($this)."::set_infocredit Update lines Error");
- $error++;
- }
+ if ($this->type == 'bank-transfer') {
+ $fac = new FactureFournisseur($this->db);
} else {
- dol_syslog(get_class($this)."::set_infocredit Update Bons Error");
+ $fac = new Facture($this->db);
+ }
+
+ $result = $fac->fetch($facs[$i][0]);
+
+ $amounts[$fac->id] = $facs[$i][1];
+ $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
+
+ $totalpaye = $fac->getSommePaiement();
+ $totalcreditnotes = $fac->getSumCreditNotesUsed();
+ $totaldeposits = $fac->getSumDepositsUsed();
+ $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
+
+ // @TODO Move this after creation of payment
+ if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) {
+ $result = $fac->set_paid($user);
+ if ($result < 0) {
+ $this->error = $fac->error;
+ $this->errors = $fac->errors;
+ }
+ }
+ }
+ //var_dump($amountsperthirdparty);exit;
+
+ // Make one payment per customer
+ foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts)
+ {
+ if ($this->type == 'bank-transfer') {
+ $paiement = new PaiementFourn($this->db);
+ } else {
+ $paiement = new Paiement($this->db);
+ }
+ $paiement->datepaye = $date;
+ $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice
+
+ if ($this->type == 'bank-transfer') {
+ $paiement->paiementid = 2;
+ $paiement->paiementcode = 'VIR';
+ } else {
+ $paiement->paiementid = 3;
+ $paiement->paiementcode = 'PRE';
+ }
+
+ $paiement->num_payment = $this->ref; // Set ref of direct debit note
+ $paiement->num_paiement = $this->ref; // For backward compatibility
+ $paiement->id_prelevement = $this->id;
+
+ $paiement_id = $paiement->create($user); // This use ->paiementid, that is ID of payment mode
+ if ($paiement_id < 0)
+ {
+ $error++;
+ $this->error = $paiement->error;
+ $this->errors = $paiement->errors;
+ dol_syslog(get_class($this)."::set_infocredit AddPayment Error ".$this->error);
+ } else {
+ if ($this->type == 'bank-transfer') {
+ $modeforaddpayment = 'payment_supplier';
+ } else {
+ $modeforaddpayment = 'payment';
+ }
+
+ $result = $paiement->addPaymentToBank($user, $modeforaddpayment, '(WithdrawalPayment)', $bankaccount, '', '');
+ if ($result < 0)
+ {
+ $error++;
+ $this->error = $paiement->error;
+ $this->errors = $paiement->errors;
+ dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error ".$this->error);
+ }
+ }
+ //var_dump($paiement->amounts);
+ //var_dump($thirdpartyid);
+ //var_dump($cursoramounts);
+ }
+
+ // Update withdrawal line
+ // TODO: Translate to ligneprelevement.class.php
+ if (! $error) {
+ $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
+ $sql .= " SET statut = 2";
+ $sql .= " WHERE fk_prelevement_bons = ".$this->id;
+
+ if (!$this->db->query($sql)) {
+ dol_syslog(get_class($this)."::set_infocredit Update lines Error");
$error++;
}
-
- /*
- * End of procedure
- */
- if ($error == 0)
- {
- $this->date_credit = $date;
- $this->statut = self::STATUS_CREDITED;
-
- $this->db->commit();
- return 0;
- } else {
- $this->db->rollback();
- dol_syslog("bon-prelevment::set_infocredit ROLLBACK ");
- return -1;
- }
- } else {
- dol_syslog(get_class($this)."::set_infocredit 1025 Open SQL transaction impossible ");
- return -1025;
}
} else {
- dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans ");
- return -1027;
+ $this->error = $this->db->lasterror();
+ dol_syslog(get_class($this)."::set_infocredit Update Bons Error");
+ $error++;
+ }
+
+ /*
+ * End of procedure
+ */
+ if ($error == 0)
+ {
+ $this->date_credit = $date;
+ $this->statut = self::STATUS_CREDITED;
+
+ $this->db->commit();
+ return 0;
+ } else {
+ $this->db->rollback();
+ return -1;
}
} else {
return -1026;
@@ -561,7 +598,7 @@ class BonPrelevement extends CommonObject
$sql .= " SET fk_user_trans = ".$user->id;
$sql .= " , date_trans = '".$this->db->idate($date)."'";
$sql .= " , method_trans = ".$method;
- $sql .= " , statut = 1";
+ $sql .= " , statut = ".self::STATUS_TRANSFERED;
$sql .= " WHERE rowid = ".$this->id;
$sql .= " AND entity = ".$conf->entity;
$sql .= " AND statut = 0";
@@ -583,6 +620,7 @@ class BonPrelevement extends CommonObject
{
$this->date_trans = $date;
$this->statut = 1;
+ $this->user_trans = $user->id;
$this->db->commit();
return 0;
@@ -613,7 +651,12 @@ class BonPrelevement extends CommonObject
/*
* Returns all invoices presented within same order
*/
- $sql = "SELECT fk_facture";
+ $sql = "SELECT ";
+ if ($this->type == 'bank-transfer') {
+ $sql .= " pf.fk_facture_fourn";
+ } else {
+ $sql .= " pf.fk_facture";
+ }
if ($amounts) $sql .= ", SUM(pl.amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
@@ -622,7 +665,13 @@ class BonPrelevement extends CommonObject
$sql .= " AND pl.fk_prelevement_bons = p.rowid";
$sql .= " AND p.rowid = ".$this->id;
$sql .= " AND p.entity = ".$conf->entity;
- if ($amounts) $sql .= " GROUP BY fk_facture";
+ if ($amounts) {
+ if ($this->type == 'bank-transfer') {
+ $sql .= " GROUP BY fk_facture_fourn";
+ } else {
+ $sql .= " GROUP BY fk_facture";
+ }
+ }
$resql = $this->db->query($sql);
if ($resql)
@@ -835,14 +884,11 @@ class BonPrelevement extends CommonObject
$sql .= " AND f.rowid = pfd.fk_facture_fourn";
}
$sql .= " AND s.rowid = f.fk_soc";
- //if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc";
- $sql .= " AND f.fk_statut = 1";
+ $sql .= " AND f.fk_statut = 1"; // Invoice validated
$sql .= " AND f.paye = 0";
$sql .= " AND pfd.traite = 0";
$sql .= " AND f.total_ttc > 0";
$sql .= " AND pfd.ext_payment_id IS NULL";
- //if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
- //if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
dol_syslog(__METHOD__."::Read invoices, sql=".$sql, LOG_DEBUG);
@@ -951,15 +997,13 @@ class BonPrelevement extends CommonObject
if (count($factures_prev) > 0)
{
- if ($mode == 'real')
- {
+ if ($mode == 'real') {
$ok = 1;
} else {
- print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n";
+ print $langs->trans("ModeWarning"); // "Option for real mode was not set, we stop after this simulation\n";
}
}
-
if ($ok)
{
/*
@@ -1002,7 +1046,7 @@ class BonPrelevement extends CommonObject
// Create withdraw receipt in database
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (";
- $sql .= " ref, entity, datec, type";
+ $sql .= "ref, entity, datec, type";
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($ref)."'";
$sql .= ", ".$conf->entity;
@@ -1028,6 +1072,12 @@ class BonPrelevement extends CommonObject
if (!$error)
{
+ if ($type != 'bank-transfer') {
+ $fact = new Facture($this->db);
+ } else {
+ $fact = new FactureFournisseur($this->db);
+ }
+
/*
* Create withdrawal receipt in database
*/
@@ -1036,11 +1086,14 @@ class BonPrelevement extends CommonObject
foreach ($factures_prev as $fac) // Add a link in database for each invoice
{
// Fetch invoice
- $fact = new Facture($this->db);
- $fact->fetch($fac[0]);
+ $result = $fact->fetch($fac[0]);
+ if ($result < 0) {
+ $this->error = 'ERRORBONPRELEVEMENT Failed to load invoice with id '.$fac[0];
+ break;
+ }
/*
- * Add standing order
+ * Add standing order. This add record into llx_prelevement_lignes
*
* $fac[0] : invoice_id
* $fac[1] : ???
@@ -1051,9 +1104,7 @@ class BonPrelevement extends CommonObject
* $fac[6] : cle rib
* $fac[7] : amount
* $fac[8] : client nom
- * $fac[2] : client id
*/
-
$ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type);
if ($ri <> 0)
{
@@ -1068,7 +1119,6 @@ class BonPrelevement extends CommonObject
$sql .= " WHERE rowid = ".$fac[1];
$resql = $this->db->query($sql);
-
if (!$resql)
{
$error++;
@@ -1081,7 +1131,7 @@ class BonPrelevement extends CommonObject
if (!$error)
{
/*
- * Create file of direct debit order or credit transfer into a XML file
+ * Create file of type='direct-debit' for direct debit order or type='bank-transfer' for credit transfer into a XML file
*/
dol_syslog(__METHOD__."::Init direct debit or credit transfer file for ".count($factures_prev)." invoices", LOG_DEBUG);
@@ -1092,6 +1142,9 @@ class BonPrelevement extends CommonObject
$this->reference_remise = $ref;
$id = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
+ if ($type == 'bank-transfer') {
+ $id = $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT;
+ }
$account = new Account($this->db);
if ($account->fetch($id) > 0)
{
@@ -1113,24 +1166,31 @@ class BonPrelevement extends CommonObject
// Generation of direct debit or credti transfer file $this->filename (May be a SEPA file for european countries)
// 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); */
+ $error++;
+ }
}
dol_syslog(__METHOD__."::End withdraw receipt, file ".$this->filename, LOG_DEBUG);
}
- //var_dump($factures_prev);exit;
+ //var_dump($this->total);exit;
/*
* Update total defined after generation of file
*/
- $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
- $sql .= " SET amount = ".price2num($this->total);
- $sql .= " WHERE rowid = ".$this->id;
- $sql .= " AND entity = ".$conf->entity;
+ if (! $error) {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
+ $sql .= " SET amount = ".price2num($this->total);
+ $sql .= " WHERE rowid = ".$this->id;
+ $sql .= " AND entity = ".$conf->entity;
- $resql = $this->db->query($sql);
- if (!$resql)
- {
- $error++;
- dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR);
+ $resql = $this->db->query($sql);
+ if (!$resql)
+ {
+ $error++;
+ dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR);
+ }
}
if (!$error && !$notrigger)
@@ -1149,11 +1209,11 @@ class BonPrelevement extends CommonObject
if (!$error)
{
$this->db->commit();
+ return count($factures_prev);
} else {
$this->db->rollback();
+ return -1;
}
-
- return count($factures_prev);
} else {
return 0;
}
@@ -1399,7 +1459,7 @@ class BonPrelevement extends CommonObject
*
* @param string $format FRST, RCUR or ALL
* @param string $executiondate Date to execute transfer
- * @param string $type 'direct-debit' or 'credit-transfer'
+ * @param string $type 'direct-debit' or 'bank-transfer'
* @return int >=0 if OK, <0 if KO
*/
public function generate($format = 'ALL', $executiondate = '', $type = 'direct-debit')
@@ -1427,112 +1487,9 @@ class BonPrelevement extends CommonObject
{
$found++;
- if ($type == 'bank-transfer') {
+ if ($type != 'bank-transfer') {
/**
- * SECTION CREATION FICHIER SEPA - CREDIT TRANSFER
- */
- // SEPA Initialisation
- $CrLf = "\n";
-
- $now = dol_now();
-
- $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
-
- $date_actu = $now;
- if (!empty($executiondate)) $date_actu = $executiondate;
-
- $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
- $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
- $fileCrediteurSection = '';
- $fileEmetteurSection = '';
- $i = 0;
-
- /*
- * Section Creditor (sepa Crediteurs 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 nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
- $sql .= " f.ref as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
- $sql .= " FROM";
- $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
- $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,";
- $sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf,";
- $sql .= " ".MAIN_DB_PREFIX."societe as soc,";
- $sql .= " ".MAIN_DB_PREFIX."c_country as c,";
- $sql .= " ".MAIN_DB_PREFIX."societe_rib as rib";
- $sql .= " WHERE pl.fk_prelevement_bons = ".$this->id;
- $sql .= " AND pl.rowid = pf.fk_prelevement_lignes";
- $sql .= " AND pf.fk_facture_fourn = f.rowid";
- $sql .= " AND soc.fk_pays = c.rowid";
- $sql .= " AND soc.rowid = f.fk_soc";
- $sql .= " AND rib.fk_soc = f.fk_soc";
- $sql .= " AND rib.default_rib = 1";
- $sql .= " AND rib.type = 'ban'";
- //print $sql;
-
- // Define $fileCrediteurSection. One section DrctDbtTxInf per invoice.
- $resql = $this->db->query($sql);
- if ($resql)
- {
- $num = $this->db->num_rows($resql);
- while ($i < $num)
- {
- $obj = $this->db->fetch_object($resql);
- $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
- $fileCrediteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum);
- $this->total = $this->total + $obj->somme;
- $i++;
- }
- $nbtotalDrctDbtTxInf = $i;
- } else {
- fputs($this->file, 'ERROR CREDITOR '.$sql.$CrLf); // CREDITORS = Suppliers
- $result = -2;
- }
-
- // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf
- if ($result != -2)
- {
- $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format);
- }
-
- /**
- * SECTION CREATION SEPA FILE - CREDTI TRANSFER - ISO200022
- */
- // SEPA File Header
- fputs($this->file, '<'.'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'>'.$CrLf);
- fputs($this->file, '
'.$CrLf);
- fputs($this->file, ' '.$CrLf);
- // SEPA Group header
- fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.('CREDTRANS'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf);
- fputs($this->file, ' '.$dateTime_ECMA.''.$CrLf);
- fputs($this->file, ' '.$i.''.$CrLf);
- fputs($this->file, ' '.$this->total.''.$CrLf);
- fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$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);
- // SEPA File Emetteur (mycompany)
- if ($result != -2)
- { fputs($this-> file, $fileEmetteurSection); }
- // SEPA File Creditors
- if ($result != -2)
- { fputs($this-> file, $fileCrediteurSection); }
- // SEPA FILE FOOTER
- fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.$CrLf);
- fputs($this->file, ''.$CrLf);
- } else {
- /**
- * SECTION CREATION FICHIER SEPA
+ * SECTION CREATION FICHIER SEPA - DIRECT DEBIT
*/
// SEPA Initialisation
$CrLf = "\n";
@@ -1554,9 +1511,10 @@ class BonPrelevement extends CommonObject
* Section Debitor (sepa Debiteurs bloc lines)
*/
- $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
+ $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.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.ref as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
+ $sql .= " f.ref as fac, pf.fk_facture as idfac,";
+ $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
$sql .= " FROM";
$sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
$sql .= " ".MAIN_DB_PREFIX."facture as f,";
@@ -1567,28 +1525,39 @@ class BonPrelevement extends CommonObject
$sql .= " WHERE pl.fk_prelevement_bons = ".$this->id;
$sql .= " AND pl.rowid = pf.fk_prelevement_lignes";
$sql .= " AND pf.fk_facture = f.rowid";
+ $sql .= " AND f.fk_soc = soc.rowid";
$sql .= " AND soc.fk_pays = c.rowid";
- $sql .= " AND soc.rowid = f.fk_soc";
$sql .= " AND rib.fk_soc = f.fk_soc";
$sql .= " AND rib.default_rib = 1";
$sql .= " AND rib.type = 'ban'";
- //print $sql;
// Define $fileDebiteurSection. One section DrctDbtTxInf per invoice.
$resql = $this->db->query($sql);
if ($resql)
{
+ $cachearraytotestduplicate = array();
+
$num = $this->db->num_rows($resql);
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
+
+ if (! empty($cachearraytotestduplicate[$obj->idfac])) {
+ $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
+ $this->invoice_in_error[$obj->idfac] = $this->error;
+ $result = -2;
+ break;
+ }
+ $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
+
$daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
- $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum);
+ $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
$this->total = $this->total + $obj->somme;
$i++;
}
$nbtotalDrctDbtTxInf = $i;
} else {
+ $this->error = $this->db->lasterror();
fputs($this->file, 'ERROR DEBITOR '.$sql.$CrLf); // DEBITOR = Customers
$result = -2;
}
@@ -1596,7 +1565,7 @@ class BonPrelevement extends CommonObject
// Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf
if ($result != -2)
{
- $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format);
+ $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
}
/**
@@ -1608,7 +1577,7 @@ class BonPrelevement extends CommonObject
fputs($this->file, '
'.$CrLf);
// SEPA Group header
fputs($this->file, ' '.$CrLf);
- fputs($this->file, ' '.('PREL'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf);
+ fputs($this->file, ' '.('DD/'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf);
fputs($this->file, ' '.$dateTime_ECMA.''.$CrLf);
fputs($this->file, ' '.$i.''.$CrLf);
fputs($this->file, ' '.$this->total.''.$CrLf);
@@ -1633,21 +1602,135 @@ class BonPrelevement extends CommonObject
fputs($this->file, ' '.$CrLf);
fputs($this->file, ' '.$CrLf);
fputs($this->file, ''.$CrLf);
+ } else {
+ /**
+ * SECTION CREATION FICHIER SEPA - CREDIT TRANSFER
+ */
+ // SEPA Initialisation
+ $CrLf = "\n";
+
+ $now = dol_now();
+
+ $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
+
+ $date_actu = $now;
+ if (!empty($executiondate)) $date_actu = $executiondate;
+
+ $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
+ $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
+ $fileCrediteurSection = '';
+ $fileEmetteurSection = '';
+ $i = 0;
+
+ /*
+ * Section Creditor (sepa Crediteurs bloc lines)
+ */
+
+ $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.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.ref as fac, pf.fk_facture_fourn as idfac,";
+ $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
+ $sql .= " FROM";
+ $sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
+ $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,";
+ $sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf,";
+ $sql .= " ".MAIN_DB_PREFIX."societe as soc,";
+ $sql .= " ".MAIN_DB_PREFIX."c_country as c,";
+ $sql .= " ".MAIN_DB_PREFIX."societe_rib as rib";
+ $sql .= " WHERE pl.fk_prelevement_bons = ".$this->id;
+ $sql .= " AND pl.rowid = pf.fk_prelevement_lignes";
+ $sql .= " AND pf.fk_facture_fourn = f.rowid";
+ $sql .= " AND f.fk_soc = soc.rowid";
+ $sql .= " AND soc.fk_pays = c.rowid";
+ $sql .= " AND rib.fk_soc = f.fk_soc";
+ $sql .= " AND rib.default_rib = 1";
+ $sql .= " AND rib.type = 'ban'";
+
+ // Define $fileCrediteurSection. One section DrctDbtTxInf per invoice.
+ $resql = $this->db->query($sql);
+ if ($resql)
+ {
+ $cachearraytotestduplicate = array();
+
+ $num = $this->db->num_rows($resql);
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ if (! empty($cachearraytotestduplicate[$obj->idfac])) {
+ $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
+ $this->invoice_in_error[$obj->idfac] = $this->error;
+ $result = -2;
+ break;
+ }
+ $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
+
+ $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
+ $fileCrediteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
+ $this->total = $this->total + $obj->somme;
+ $i++;
+ }
+ $nbtotalDrctDbtTxInf = $i;
+ } else {
+ $this->error = $this->db->lasterror();
+ fputs($this->file, 'ERROR CREDITOR '.$sql.$CrLf); // CREDITORS = Suppliers
+ $result = -2;
+ }
+
+ // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all $nbtotalDrctDbtTxInf
+ if ($result != -2) {
+ $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
+ }
+
+ /**
+ * SECTION CREATION SEPA FILE - CREDIT TRANSFER - ISO200022
+ */
+ // SEPA File Header
+ fputs($this->file, '<'.'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'>'.$CrLf);
+ fputs($this->file, '
'.$CrLf);
+ fputs($this->file, ' '.$CrLf);
+ // SEPA Group header
+ fputs($this->file, ' '.$CrLf);
+ fputs($this->file, ' '.('TRF/'.$dateTime_YMD.'/REF'.$this->id).''.$CrLf);
+ fputs($this->file, ' '.$dateTime_ECMA.''.$CrLf);
+ fputs($this->file, ' '.$i.''.$CrLf);
+ fputs($this->file, ' '.$this->total.''.$CrLf);
+ fputs($this->file, ' '.$CrLf);
+ fputs($this->file, ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$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);
+ // SEPA File Emetteur (mycompany)
+ if ($result != -2)
+ { fputs($this-> file, $fileEmetteurSection); }
+ // SEPA File Creditors
+ if ($result != -2)
+ { fputs($this-> file, $fileCrediteurSection); }
+ // SEPA FILE FOOTER
+ fputs($this->file, ' '.$CrLf);
+ fputs($this->file, ' '.$CrLf);
+ fputs($this->file, ''.$CrLf);
}
}
// Build file for Other Countries with unknow format
if (!$found)
{
- if ($type == 'bank-transfer') {
+ if ($type != 'bank-transfer') {
$sql = "SELECT pl.amount";
$sql .= " FROM";
$sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
- $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,";
+ $sql .= " ".MAIN_DB_PREFIX."facture as f,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf";
$sql .= " WHERE pl.fk_prelevement_bons = ".$this->id;
$sql .= " AND pl.rowid = pf.fk_prelevement_lignes";
- $sql .= " AND pf.fk_facture_fourn = f.rowid";
+ $sql .= " AND pf.fk_facture = f.rowid";
// Lines
$i = 0;
@@ -1671,11 +1754,11 @@ class BonPrelevement extends CommonObject
$sql = "SELECT pl.amount";
$sql .= " FROM";
$sql .= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
- $sql .= " ".MAIN_DB_PREFIX."facture as f,";
+ $sql .= " ".MAIN_DB_PREFIX."facture_fourn as f,";
$sql .= " ".MAIN_DB_PREFIX."prelevement_facture as pf";
$sql .= " WHERE pl.fk_prelevement_bons = ".$this->id;
$sql .= " AND pl.rowid = pf.fk_prelevement_lignes";
- $sql .= " AND pf.fk_facture = f.rowid";
+ $sql .= " AND pf.fk_facture_fourn = f.rowid";
// Lines
$i = 0;
@@ -1712,6 +1795,22 @@ class BonPrelevement extends CommonObject
}
+ /**
+ * Generate dynamically a RUM number for a customer bank account
+ *
+ * @param string $row_code_client Customer code (soc.code_client)
+ * @param int $row_datec Creation date of bank account (rib.datec)
+ * @param string $row_drum Id of customer bank account (rib.rowid)
+ * @return string RUM number
+ */
+ public static function buildRumNumber($row_code_client, $row_datec, $row_drum)
+ {
+ global $langs;
+ $pre = substr(dol_string_nospecial(dol_string_unaccent($langs->transnoentitiesnoconv('RUM'))), 0, 3); // Must always be on 3 char ('RUM' or 'UMR'. This is a protection against bad translation)
+ return $pre.'-'.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec);
+ }
+
+
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Write recipient of request (customer)
@@ -1725,9 +1824,11 @@ class BonPrelevement extends CommonObject
* @param string $ref ref of invoice
* @param int $facid id of invoice
* @param string $rib_dom rib domiciliation
+ * @param string $type 'direct-debit' or 'bank-transfer'
* @return void
+ * @see EnregDestinataireSEPA()
*/
- public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom = '')
+ public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom = '', $type = 'direct-debit')
{
// phpcs:enable
fputs($this->file, "06");
@@ -1784,22 +1885,6 @@ class BonPrelevement extends CommonObject
fputs($this->file, "\n");
}
-
- /**
- * Build RUM number for a customer bank account
- *
- * @param string $row_code_client Customer code (soc.code_client)
- * @param int $row_datec Creation date of bank account (rib.datec)
- * @param string $row_drum Id of customer bank account (rib.rowid)
- * @return string RUM number
- */
- public static function buildRumNumber($row_code_client, $row_datec, $row_drum)
- {
- global $langs;
- $pre = substr(dol_string_nospecial(dol_string_unaccent($langs->transnoentitiesnoconv('RUM'))), 0, 3); // Must always be on 3 char ('RUM' or 'UMR'. This is a protection against bad translation)
- return $pre.'-'.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec);
- }
-
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Write recipient of request (customer)
@@ -1821,9 +1906,11 @@ class BonPrelevement extends CommonObject
* @param string $row_datec rib.datec,
* @param string $row_drum rib.rowid used to generate rum
* @param string $row_rum rib.rum Rum defined on company bank account
+ * @param string $type 'direct-debit' or 'bank-transfer'
* @return string Return string with SEPA part DrctDbtTxInf
+ * @see EnregDestinataire()
*/
- public function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum)
+ public function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type = 'direct-debit')
{
// phpcs:enable
global $conf;
@@ -1831,7 +1918,7 @@ class BonPrelevement extends CommonObject
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$CrLf = "\n";
- $Rowing = sprintf("%06d", $row_idfac);
+ $Rowing = sprintf("%010d", $row_idfac);
// Define value for RUM
// Example: RUMCustomerCode-CustomerBankAccountId-01424448606 (note: Date is date of creation of CustomerBankAccountId)
@@ -1840,57 +1927,108 @@ class BonPrelevement extends CommonObject
// Define date of RUM signature
$DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d');
- $XML_DEBITOR = '';
- $XML_DEBITOR .= '
'.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- // $XML_DEBITOR .=' '.('AS-'.dol_trunc($row_ref,20).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
- $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.round($row_somme, 2).''.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$Rum.''.$CrLf;
- $XML_DEBITOR .= ' '.$DtOfSgntr.''.$CrLf;
- $XML_DEBITOR .= ' false'.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$row_bic.''.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$row_country_code.''.$CrLf;
- $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
- $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
- if (trim($addressline1)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf;
- if (trim($addressline2)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- // $XML_DEBITOR .=' '.($row_ref.'/'.$Rowing.'/'.$Rum).''.$CrLf;
- // $XML_DEBITOR .=' '.dol_trunc($row_ref, 135).''.$CrLf; // 140 max
- $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max
- $XML_DEBITOR .= ' '.$CrLf;
- $XML_DEBITOR .= ' '.$CrLf;
- return $XML_DEBITOR;
+ if ($type != 'bank-transfer') {
+ // SEPA Paiement Information of buyer for Direct debit
+ $XML_DEBITOR = '';
+ $XML_DEBITOR .= '
'.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ // Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum)
+ $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_END_TO_END != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.round($row_somme, 2).''.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$Rum.''.$CrLf;
+ $XML_DEBITOR .= ' '.$DtOfSgntr.''.$CrLf;
+ $XML_DEBITOR .= ' false'.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$row_bic.''.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$row_country_code.''.$CrLf;
+ $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
+ $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
+ if (trim($addressline1)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf;
+ if (trim($addressline2)) $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ // A string with some information on payment - 140 max
+ $XML_DEBITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max
+ $XML_DEBITOR .= ' '.$CrLf;
+ $XML_DEBITOR .= ' '.$CrLf;
+ return $XML_DEBITOR;
+ } else {
+ // SEPA Paiement Information of seller for Credit Transfer
+ $XML_CREDITOR = '';
+ $XML_CREDITOR .= '
'.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ // 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 : ('AS-'.dol_trunc($row_ref, 20)).'-'.$Rowing).''.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.round($row_somme, 2).''.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ /*
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$Rum.''.$CrLf;
+ $XML_CREDITOR .= ' '.$DtOfSgntr.''.$CrLf;
+ $XML_CREDITOR .= ' false'.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ */
+ //$XML_CREDITOR .= ' SLEV'.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$row_bic.''.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$row_country_code.''.$CrLf;
+ $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
+ $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
+ if (trim($addressline1)) $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', true)).''.$CrLf;
+ if (trim($addressline2)) $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', true)).''.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.preg_replace('/\s/', '', $row_iban).''.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ // A string with some information on payment - 140 max
+ $XML_CREDITOR .= ' '.(($conf->global->PRELEVEMENT_USTRD != "") ? $conf->global->PRELEVEMENT_USTRD : dol_trunc($row_ref, 135)).''.$CrLf; // 140 max
+ $XML_CREDITOR .= ' '.$CrLf;
+ $XML_CREDITOR .= ' '.$CrLf;
+ return $XML_CREDITOR;
+ }
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Write sender of request (me)
+ * Write sender of request (me).
*
+ * @param string $type 'direct-debit' or 'bank-transfer'
* @return void
+ * @see EnregEmetteurSEPA()
*/
- public function EnregEmetteur()
+ public function EnregEmetteur($type = 'direct-debit')
{
// phpcs:enable
fputs($this->file, "03");
@@ -1962,9 +2100,11 @@ class BonPrelevement extends CommonObject
* @param float $total Total
* @param string $CrLf End of line character
* @param string $format FRST or RCUR or ALL
+ * @param string $type 'direct-debit' or 'bank-transfer'
* @return string String with SEPA Sender
+ * @see EnregEmetteur()
*/
- public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf = '\n', $format = 'FRST')
+ public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf = '\n', $format = 'FRST', $type = 'direct-debit')
{
// phpcs:enable
// SEPA INITIALISATION
@@ -1991,7 +2131,7 @@ class BonPrelevement extends CommonObject
$this->raison_sociale = $account->proprio;
}
- // Récupération info demandeur
+ // Get pending payments
$sql = "SELECT rowid, ref";
$sql .= " FROM";
$sql .= " ".MAIN_DB_PREFIX."prelevement_bons as pb";
@@ -2002,72 +2142,134 @@ class BonPrelevement extends CommonObject
{
$obj = $this->db->fetch_object($resql);
- // DONNEES BRUTES : par la suite Rows['XXX'] de la requete au dessus
$country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
$IdBon = sprintf("%05d", $obj->rowid);
$RefBon = $obj->ref;
- // SEPA Paiement Information
- $XML_SEPA_INFO = '';
- $XML_SEPA_INFO .= '
'.$CrLf;
- $XML_SEPA_INFO .= ' '.('PREL'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf;
- $XML_SEPA_INFO .= ' DD'.$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 .= ' CORE'.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$format.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
- $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
- $addressline2 = dol_string_unaccent(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 .= ' '.$addressline1.''.$CrLf;
- if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- /* $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
- $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$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;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' SEPA'.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
- $XML_SEPA_INFO .= ' '.$CrLf;
+ if ($type != 'bank-transfer') {
+ // 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;
+ $XML_SEPA_INFO .= ' DD'.$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 .= ' CORE'.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$format.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
+ $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
+ $addressline2 = dol_string_unaccent(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 .= ' '.$addressline1.''.$CrLf;
+ if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ /* $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$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
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' SEPA'.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ } else {
+ // SEPA Paiement Information of my company for Credit Transfer
+ $XML_SEPA_INFO = '';
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.('TRF/'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).''.$CrLf;
+ $XML_SEPA_INFO .= ' TRF'.$CrLf;
+ //$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;
+ */
+ $XML_SEPA_INFO .= ' '.dol_print_date($dateTime_ETAD, 'dayrfc').''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.strtoupper(dol_string_unaccent($this->raison_sociale)).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
+ $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
+ $addressline2 = dol_string_unaccent(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 .= ' '.$addressline1.''.$CrLf;
+ if ($addressline2) $XML_SEPA_INFO .= ' '.$addressline2.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.preg_replace('/\s/', '', $this->emetteur_iban).''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->emetteur_bic.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ /* $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$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
+ /*$XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$this->emetteur_ics.''.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' SEPA'.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;
+ $XML_SEPA_INFO .= ' '.$CrLf;*/
+ }
} else {
fputs($this->file, 'INCORRECT EMETTEUR '.$XML_SEPA_INFO.$CrLf);
- $result = -2;
}
return $XML_SEPA_INFO;
}
diff --git a/htdocs/compta/prelevement/class/ligneprelevement.class.php b/htdocs/compta/prelevement/class/ligneprelevement.class.php
index 78e364c1abc..a645d2bb078 100644
--- a/htdocs/compta/prelevement/class/ligneprelevement.class.php
+++ b/htdocs/compta/prelevement/class/ligneprelevement.class.php
@@ -59,7 +59,7 @@ class LignePrelevement
$langs->load("withdrawals");
$this->statuts[0] = $langs->trans("StatusWaiting");
- $this->statuts[2] = $langs->trans("StatusCredited");
+ $this->statuts[2] = $langs->trans("StatusPaid");
$this->statuts[3] = $langs->trans("StatusRefused");
}
diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php
index 0be8dfc9e52..f8d67de48c2 100644
--- a/htdocs/compta/prelevement/create.php
+++ b/htdocs/compta/prelevement/create.php
@@ -88,11 +88,9 @@ if (empty($reshook))
// $conf->global->PRELEVEMENT_CODE_BANQUE and $conf->global->PRELEVEMENT_CODE_GUICHET should be empty (we don't use them anymore)
$result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET, $mode, $format, $executiondate, 0, $type);
- if ($result < 0)
- {
+ if ($result < 0) {
setEventMessages($bprev->error, $bprev->errors, 'errors');
- } elseif ($result == 0)
- {
+ } elseif ($result == 0) {
$mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format);
setEventMessages($mesg, null, 'errors');
$mesg .= '
'."\n";
@@ -370,10 +368,15 @@ if ($resql)
// RUM
print '';
- print $thirdpartystatic->display_rib('rum');
- $format = $thirdpartystatic->display_rib('format');
- if ($type != 'bank-transfer') {
- if ($format) print ' ('.$format.')';
+ $rumtoshow = $thirdpartystatic->display_rib('rum');
+ if ($rumtoshow) {
+ print $rumtoshow;
+ $format = $thirdpartystatic->display_rib('format');
+ if ($type != 'bank-transfer') {
+ if ($format) print ' ('.$format.')';
+ }
+ } else {
+ print img_warning($langs->trans("NoBankAccount"));
}
print ' | ';
// Amount
diff --git a/htdocs/compta/prelevement/demandes.php b/htdocs/compta/prelevement/demandes.php
index feda7f0771d..53934deaac1 100644
--- a/htdocs/compta/prelevement/demandes.php
+++ b/htdocs/compta/prelevement/demandes.php
@@ -105,14 +105,17 @@ if ($type != 'bank-transfer') {
llxHeader('', $title);
$thirdpartystatic = new Societe($db);
-$invoicestatic = new Facture($db);
+if ($type == 'bank-transfer') {
+ $invoicestatic = new FactureFournisseur($db);
+} else {
+ $invoicestatic = new Facture($db);
+}
// List of requests
$sql = "SELECT f.ref, f.rowid, f.total_ttc,";
$sql .= " s.nom as name, s.rowid as socid,";
-$sql .= " pfd.date_demande as date_demande,";
-$sql .= " pfd.fk_user_demande";
+$sql .= " pfd.date_demande as date_demande, pfd.amount, pfd.fk_user_demande";
if ($type != 'bank-transfer') {
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f,";
} else {
@@ -126,6 +129,7 @@ $sql .= " AND f.entity IN (".getEntity('invoice').")";
if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
if ($socid) $sql .= " AND f.fk_soc = ".$socid;
if (!$status) $sql .= " AND pfd.traite = 0";
+$sql .= " AND pfd.ext_payment_id IS NULL";
if ($status) $sql .= " AND pfd.traite = ".$status;
$sql .= " AND f.total_ttc > 0";
if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS))
@@ -141,7 +145,6 @@ if ($search_facture) $sql .= natural_search("f.ref", $search_facture);
if ($search_societe) $sql .= natural_search("s.nom", $search_societe);
$sql .= $db->order($sortfield, $sortorder);
-
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -173,9 +176,9 @@ if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
-$newcardbutton = ''.$langs->trans("Back").'';
+$newcardbutton = ''.$langs->trans("Back").'';
if ($type == 'bank-transfer') {
- $newcardbutton = ''.$langs->trans("Back").'';
+ $newcardbutton = ''.$langs->trans("Back").'';
}
print '