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 '