From 74ff2acc6cb22660a1d7baab98c8e82ff4500ca3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 7 Nov 2023 15:03:45 +0100 Subject: [PATCH] Debug v19 --- .../class/bonprelevement.class.php | 31 ++++---- htdocs/compta/prelevement/create.php | 73 ++++++++++++++----- 2 files changed, 69 insertions(+), 35 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index ceb20ccacc4..03560536038 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -1035,6 +1035,7 @@ class BonPrelevement extends CommonObject } if (!$error) { + // Make some checks require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; @@ -1086,14 +1087,20 @@ class BonPrelevement extends CommonObject //dol_syslog(__METHOD__."::RIB is ok", LOG_DEBUG); } else { if ($type != 'bank-transfer') { + $tmpsoc->id = $fac[2]; + $tmpsoc->name = $fac[8]; $invoice_url = "".$fac[9].""; - $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); - $this->thirdparty_in_error[$soc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $error++; } if ($type == 'bank-transfer' && $sourcetype != 'salary') { + $tmpsoc->id = $fac[2]; + $tmpsoc->name = $fac[8]; $invoice_url = "".$fac[9].""; - $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); - $this->thirdparty_in_error[$soc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $soc->getNomUrl(0); + $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0); + $error++; } if ($type == 'bank-transfer' && $sourcetype == 'salary') { $tmpuser->id = $fac[2]; @@ -1101,8 +1108,9 @@ class BonPrelevement extends CommonObject $salary_url = "".$fac[0].""; $this->invoice_in_error[$fac[0]] = "Error on default bank number IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0); $this->thirdparty_in_error[$tmpuser->id] = "Error on default bank number IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0); + $error++; } - dol_syslog(__METHOD__ . " Check BAN Error on default bank number IBAN/BIC reported by verif(): " . join(', ', $fac) . " - " . $soc->name, LOG_WARNING); + dol_syslog(__METHOD__ . " Check BAN Error on default bank number IBAN/BIC reported by verif(): " . join(', ', $fac), LOG_WARNING); } } else { dol_syslog(__METHOD__ . " Check BAN Failed to read company", LOG_WARNING); @@ -1220,18 +1228,11 @@ class BonPrelevement extends CommonObject dol_syslog(__METHOD__." Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR); } } - if (!$error) { - /* - if ($type != 'bank-transfer') { - $fact = new Facture($this->db); - } else { - $fact = new FactureFournisseur($this->db); - } - */ + if (!$error) { // Add lines for the bon if (count($factures_prev) > 0) { - foreach ($factures_prev as $fac) { // Add a link in database for each invoice + foreach ($factures_prev as $fac) { // Add a link in database for each invoice ro salary // Fetch invoice /* $result = $fact->fetch($fac[0]); @@ -1357,7 +1358,7 @@ class BonPrelevement extends CommonObject if (!$error) { $this->db->commit(); - return count($factures_prev); + return count($factures_prev); // The error of failed lines are into $this->invoice_in_error and $this->thirdparty_in_error } else { $this->db->rollback(); return -1; diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index aca57a79b1f..36b48ef5bde 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -70,10 +70,17 @@ if ($user->socid) { } if ($type == 'bank-transfer') { $result = restrictedArea($user, 'paymentbybanktransfer', '', '', ''); + + $permissiontoread = $user->hasRight('paymentbybanktransfer', 'read'); + $permissiontocreate = $user->hasRight('paymentbybanktransfer', 'create'); } else { $result = restrictedArea($user, 'prelevement', '', '', 'bons'); + + $permissiontoread = $user->hasRight('prelevement', 'bons', 'lire'); + $permissiontocreate = $user->hasRight('prelevement', 'bons', 'creer'); } + $error = 0; $option = ""; $mesg = ''; @@ -95,12 +102,14 @@ if ($reshook < 0) { if (empty($reshook)) { // Change customer bank information to withdraw + /* if ($action == 'modify') { for ($i = 1; $i < 9; $i++) { dolibarr_set_const($db, GETPOST("nom".$i), GETPOST("value".$i), 'chaine', 0, '', $conf->entity); } } - if ($action == 'create') { + */ + if ($action == 'create' && $permissiontocreate) { $default_account = ($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT'); //var_dump($default_account);var_dump($conf->global->$default_account);var_dump($id_bankaccount);exit; @@ -129,22 +138,41 @@ if (empty($reshook)) { // 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, 0, 0, $sourcetype); if ($result < 0) { - setEventMessages($bprev->error, $bprev->errors, 'errors'); - } elseif ($result == 0) { $mesg = ''; - if ($type != 'bank-transfer') { - $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format); + + if ($bprev->error || !empty($bprev->errors)) { + setEventMessages($bprev->error, $bprev->errors, 'errors'); + } else { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorsOnXLines", count($bprev->invoice_in_error)), null, 'warnings'); } - if ($type == 'bank-transfer' && $sourcetype != 'salary') { - $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format); + + if (!empty($bprev->invoice_in_error)) { + foreach ($bprev->invoice_in_error as $key => $val) { + $mesg .= ''.$val."
\n"; + } } - if ($type == 'bank-transfer' && $sourcetype == 'salary') { - $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format); + } elseif ($result == 0 || !empty($bprev->invoice_in_error)) { + $mesg = ''; + + if ($result == 0) { + if ($type != 'bank-transfer') { + $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format); + } + if ($type == 'bank-transfer' && $sourcetype != 'salary') { + $mesg = $langs->trans("NoInvoiceCouldBeWithdrawedSupplier", $format); + } + if ($type == 'bank-transfer' && $sourcetype == 'salary') { + $mesg = $langs->trans("NoSalariesCouldBeWithdrawed", $format); + } + setEventMessages($mesg, null, 'errors'); } - setEventMessages($mesg, null, 'errors'); - $mesg .= '
'."\n"; - foreach ($bprev->invoice_in_error as $key => $val) { - $mesg .= ''.$val."
\n"; + + if (!empty($bprev->invoice_in_error)) { + $mesg .= '
'."\n"; + foreach ($bprev->invoice_in_error as $key => $val) { + $mesg .= ''.$val."
\n"; + } } } else { if ($type != 'bank-transfer') { @@ -162,6 +190,7 @@ if (empty($reshook)) { } } } + $objectclass = "BonPrelevement"; if ($type == 'bank-transfer') { $uploaddir = $conf->paymentbybanktransfer->dir_output; @@ -255,10 +284,6 @@ print ''; print ''; print ''; -if ($mesg) { - print $mesg; -} - print '
'."\n"; print '
'; @@ -353,7 +378,13 @@ if ($nb) { print "
\n"; print "
\n"; -print ''; + +// Show errors or warnings +if ($mesg) { + print $mesg; + print '
'; +} + print '
'; @@ -530,7 +561,7 @@ if ($resql) { $invoicestatic->ref_supplier = $obj->ref_supplier; } else { $bac = new UserBankAccount($db); - $bac->fetch(0, '', $obj->fk_user); + $bac->fetch(0, '', $obj->uid); $salary = new Salary($db); $salary->fetch($obj->rowid); @@ -577,6 +608,7 @@ if ($resql) { print $user->getNomUrl(-1); print ''; } + // BAN print ''; if ($bac->id > 0) { @@ -594,7 +626,7 @@ if ($resql) { print ''; // RUM - if (empty($type) || $type == 'direc-debit') { + if (empty($type) || $type == 'direct-debit') { print ''; $rumtoshow = $thirdpartystatic->display_rib('rum'); if ($rumtoshow) { @@ -610,6 +642,7 @@ if ($resql) { } print ''; } + // Amount print ''; print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);