Skip to content

Commit d7758f9

Browse files
FIX bank payment rejection on SEPA (backport commit 100a657) (#33838)
1 parent 8434e65 commit d7758f9

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

htdocs/compta/prelevement/class/rejetprelevement.class.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,28 @@ public function __construct($db, $user, $type)
7676
}
7777

7878
/**
79-
* Create
79+
* Create a reject
8080
*
8181
* @param User $user User object
8282
* @param int $id Id
8383
* @param string $motif Motif
84-
* @param int $date_rejet Date rejet
84+
* @param int $date_rejet Date reject
8585
* @param int $bonid Bon id
86-
* @param int $facturation Facturation
87-
* @return void
86+
* @param int $facturation 1=Bill the reject
87+
* @return int Return >=0 if OK, <0 if KO
8888
*/
8989
public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0)
9090
{
91-
global $langs, $conf;
91+
global $langs;
9292

9393
$error = 0;
9494
$this->id = $id;
9595
$this->bon_id = $bonid;
9696
$now = dol_now();
9797

98-
dol_syslog("RejetPrelevement::Create id $id");
99-
$bankaccount = ($this->type == 'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
98+
dol_syslog("RejetPrelevement::Create id ".$id);
99+
100+
$bankaccount = ($this->type == 'bank-transfer' ? getDolGlobalString('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalString('PRELEVEMENT_ID_BANKACCOUNT'));
100101
$facs = $this->getListInvoices(1);
101102

102103
require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
@@ -152,17 +153,16 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
152153

153154
$fac->fetch($facs[$i][0]);
154155

155-
// Make a negative payment
156-
//$pai = new Paiement($this->db);
156+
$amountrejected = $facs[$i][1];
157157

158+
// Make a negative payment
159+
// Amount must be an array (id of invoice -> amount)
158160
$pai->amounts = array();
159161

160-
/*
161-
* We replace the comma with a point otherwise some
162-
* PHP installs sends only the part integer negative
163-
*/
162+
//var_dump($this->type);exit;
163+
164+
$pai->amounts[$facs[$i][0]] = price2num($amountrejected * -1); // The payment must be negative because it is a refund
164165

165-
$pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * ($this->type == 'bank-transfer' ? 1 : -1));
166166
$pai->datepaye = $date_rejet;
167167
$pai->paiementid = 3; // type of payment: withdrawal
168168
$pai->num_paiement = $fac->ref;
@@ -175,7 +175,13 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
175175
$error++;
176176
dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
177177
} else {
178-
$result = $pai->addPaymentToBank($user, 'payment', '(InvoiceRefused)', $bankaccount, '', '');
178+
// We record entry into bank
179+
$mode = 'payment';
180+
if ($this->type == 'bank-transfer') {
181+
$mode = 'payment_supplier';
182+
}
183+
184+
$result = $pai->addPaymentToBank($user, $mode, '(InvoiceRefused)', $bankaccount, '', '');
179185
if ($result < 0) {
180186
dol_syslog("RejetPrelevement::Create AddPaymentToBan Error");
181187
$error++;
@@ -200,9 +206,13 @@ public function create($user, $id, $motif, $date_rejet, $bonid, $facturation = 0
200206
if ($error == 0) {
201207
dol_syslog("RejetPrelevement::Create Commit");
202208
$this->db->commit();
209+
210+
return 1;
203211
} else {
204212
dol_syslog("RejetPrelevement::Create Rollback");
205213
$this->db->rollback();
214+
215+
return -1;
206216
}
207217
}
208218

htdocs/compta/prelevement/line.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
if ($action == 'confirm_rejet' && $permissiontoadd) {
8686
if (GETPOST("confirm") == 'yes') {
8787
if (GETPOST('remonth', 'int')) {
88-
$daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
88+
$daterej = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
8989
}
9090

9191
if (empty($daterej)) {

0 commit comments

Comments
 (0)