Debug v19

This commit is contained in:
Laurent Destailleur 2023-11-07 15:03:45 +01:00
parent 1e2d06bf80
commit 74ff2acc6c
2 changed files with 69 additions and 35 deletions

View file

@ -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 = "<a href='".DOL_URL_ROOT.'/compta/facture/card.php?facid='.$fac[0]."'>".$fac[9]."</a>";
$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 = "<a href='".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$fac[0]."'>".$fac[9]."</a>";
$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 = "<a href='".DOL_URL_ROOT.'/salaries/card.php?id='.$fac[0]."'>".$fac[0]."</a>";
$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;

View file

@ -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 .= '<span class="warning">'.$val."</span><br>\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 .= '<br>'."\n";
foreach ($bprev->invoice_in_error as $key => $val) {
$mesg .= '<span class="warning">'.$val."</span><br>\n";
if (!empty($bprev->invoice_in_error)) {
$mesg .= '<br>'."\n";
foreach ($bprev->invoice_in_error as $key => $val) {
$mesg .= '<span class="warning">'.$val."</span><br>\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 '</tr>';
print '</table>';
print '</div>';
if ($mesg) {
print $mesg;
}
print '<div class="tabsAction">'."\n";
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
@ -353,7 +378,13 @@ if ($nb) {
print "</form>\n";
print "</div>\n";
print '</form>';
// Show errors or warnings
if ($mesg) {
print $mesg;
print '<br>';
}
print '<br>';
@ -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 '</td>';
}
// BAN
print '<td>';
if ($bac->id > 0) {
@ -594,7 +626,7 @@ if ($resql) {
print '</td>';
// RUM
if (empty($type) || $type == 'direc-debit') {
if (empty($type) || $type == 'direct-debit') {
print '<td>';
$rumtoshow = $thirdpartystatic->display_rib('rum');
if ($rumtoshow) {
@ -610,6 +642,7 @@ if ($resql) {
}
print '</td>';
}
// Amount
print '<td class="right amount">';
print price($obj->amount, 0, $langs, 0, 0, -1, $conf->currency);