From d4ac4ff01a7ecfbcc746e437054f5a2a511893d9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Mar 2026 13:39:50 +0100 Subject: [PATCH] Fix error management on generation of direct debit or cedit transfer payment. --- htdocs/compta/prelevement/card.php | 2 +- .../class/bonprelevement.class.php | 18 ++++------- htdocs/compta/prelevement/create.php | 31 ++++++------------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 3195c78645d..ae4d0a38258 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -163,7 +163,7 @@ if (empty($reshook)) { if ($action == 'setinfocredit' && $permissiontocreditdebit) { $dt = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')); - if (($object->type != 'bank-transfer' && $object->statut == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) { + if (($object->type != 'bank-transfer' && $object->status == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) { $error = 1; setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors'); } else { diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 2f12a5a3ba7..6a743f67b96 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1158,7 +1158,7 @@ class BonPrelevement extends CommonObject if ($obj) { $thirdpartyBANId = $obj->fk_societe_rib; - dol_syslog(__METHOD__ . " Found an BAN ID to use: ".$thirdpartyBANId); + dol_syslog(__METHOD__ . " Found a BAN ID to use: ".$thirdpartyBANId); } $this->db->free($resql); @@ -1285,13 +1285,15 @@ class BonPrelevement extends CommonObject if (count($factures) > 0) { foreach ($factures as $key => $fac) { + //var_dump($type, $format, $fac[8], $fac[12]); + // Check if $fac[8] s.nom is null if ($fac[8] != null) { if ($type != 'bank-transfer') { - if ($format == 'FRST' && $fac[12] != 'FRST') { + if ($format == 'FRST' && $fac[12] && $fac[12] != 'FRST') { continue; } - if ($format == 'RCUR' && $fac[12] != 'RCUR') { + if ($format == 'RCUR' && $fac[12] && $fac[12] != 'RCUR') { continue; } } @@ -1373,17 +1375,9 @@ class BonPrelevement extends CommonObject // Withdraw invoices in factures_prev array $out = count($factures_prev) . " invoices or salaries will be included."; - //print $out."\n"; dol_syslog($out); - // Return warning - /*$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++; - }*/ + //var_dump($factures_prev, $this->invoice_in_error, $this->thirdparty_in_error);exit; if (count($factures_prev) > 0) { if ($mode == 'real') { diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 6c0dc5d1dc4..eee39608272 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -111,7 +111,7 @@ if ($reshook < 0) { } if (empty($reshook)) { - if ($action == 'create' && $permissiontocreate) { + if ($action == 'create' && $permissiontocreate && GETPOSTISSET('createtransferrequest')) { $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT'); //var_dump($default_account);var_dump(getDolGlobalString($default_account));var_dump($id_bankaccount);exit; @@ -144,6 +144,7 @@ if (empty($reshook)) { if (!$error) { // getDolGlobalString('PRELEVEMENT_CODE_BANQUE') and getDolGlobalString('PRELEVEMENT_CODE_GUICHET') should be empty (we don't use them anymore) $result = $bprev->create(getDolGlobalString('PRELEVEMENT_CODE_BANQUE'), getDolGlobalString('PRELEVEMENT_CODE_GUICHET'), $mode, $format, $executiondate, 0, $type, $toselect, 0, $sourcetype); + if ($result < 0) { $mesg = ''; @@ -299,13 +300,15 @@ print '
'; print dol_get_fiche_end(); -print '
'."\n"; print '
'; print ''; print ''; print ''; print ''; +//print ''; + +print '
'."\n"; if ($nb) { if ($pricetowithdraw) { @@ -349,14 +352,14 @@ if ($nb) { print ''; print ''; } - print ''; + print ''; } else { $title = $langs->trans("CreateAll"); if ($type == 'bank-transfer') { $title = $langs->trans("CreateFileForPaymentByBankTransfer"); } print ''."\n"; - print ''."\n"; + print ''."\n"; } } else { if ($mysoc->isInSEPA()) { @@ -390,22 +393,6 @@ if ($nb) { print "\n"; } -print "\n"; - -// Send selected lines to build the transfer file -print ''; - print "
\n"; // Show errors or warnings @@ -502,8 +489,8 @@ if ($resql) { $param .= "&option=".urlencode($option); } - print '
'; - print ''; + //print ''; + //print ''; print ''; if (!empty($limit)) { print '';