Debug v17

This commit is contained in:
Laurent Destailleur 2023-01-14 13:06:13 +01:00
parent b7c56f5680
commit f0f3deb619
4 changed files with 95 additions and 67 deletions

View File

@ -1077,8 +1077,6 @@ class Account extends CommonObject
*/ */
public function delete(User $user = null) public function delete(User $user = null)
{ {
global $conf;
$error = 0; $error = 0;
$this->db->begin(); $this->db->begin();
@ -1096,8 +1094,8 @@ class Account extends CommonObject
} }
if (!$error) { if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " WHERE rowid = ".((int) $this->rowid); $sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);

View File

@ -25,7 +25,7 @@
/** /**
* \file htdocs/user/bank.php * \file htdocs/user/bank.php
* \ingroup HRM * \ingroup HRM
* \brief Tab for HRM * \brief Tab for HR and bank
*/ */
// Load Dolibarr environment // Load Dolibarr environment
@ -79,7 +79,6 @@ if (empty($account->userid)) {
$account->userid = $object->id; $account->userid = $object->id;
} }
// Define value to know what current user can do on users // Define value to know what current user can do on users
$canadduser = (!empty($user->admin) || $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write); $canadduser = (!empty($user->admin) || $user->rights->user->user->creer || $user->rights->hrm->write_personal_information->write);
$canreaduser = (!empty($user->admin) || $user->rights->user->user->lire || $user->rights->hrm->read_personal_information->read); $canreaduser = (!empty($user->admin) || $user->rights->user->user->lire || $user->rights->hrm->read_personal_information->read);
@ -143,49 +142,6 @@ if ($action == 'add' && !$cancel && $permissiontoaddbankaccount) {
if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) { if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) {
$account->userid = $object->id; $account->userid = $object->id;
/*
if ($action == 'update' && !$cancel)
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
if ($canedituser) // Case we can edit all field
{
$error = 0;
if (!$error)
{
$objectuser->fetch($id);
$objectuser->oldcopy = dol_clone($objectuser);
$db->begin();
$objectuser->default_range = GETPOST('default_range');
$objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat');
if (!$error) {
$ret = $objectuser->update($user);
if ($ret < 0) {
$error++;
if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
$langs->load("errors");
setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors');
} else {
setEventMessages($objectuser->error, $objectuser->errors, 'errors');
}
}
}
if (!$error && !count($objectuser->errors)) {
setEventMessages($langs->trans("UserModified"), null, 'mesgs');
$db->commit();
} else {
$db->rollback();
}
}
}
}*/
$account->bank = GETPOST('bank', 'alpha'); $account->bank = GETPOST('bank', 'alpha');
$account->label = GETPOST('label', 'alpha'); $account->label = GETPOST('label', 'alpha');
$account->courant = GETPOST('courant', 'alpha'); $account->courant = GETPOST('courant', 'alpha');
@ -214,6 +170,18 @@ if ($action == 'update' && !$cancel && $permissiontoaddbankaccount) {
} }
} }
if ($action == 'delete_confirmed' && !$cancel && $permissiontoaddbankaccount) {
$result = $account->delete($user);
if ($result < 0) {
setEventMessages($account->error, $account->errors, 'errors');
} else {
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT.'/user/bank.php?id='.$object->id);
exit;
}
$action = '';
}
// update birth // update birth
if ($action == 'setbirth' && $canadduser && !$cancel) { if ($action == 'setbirth' && $canadduser && !$cancel) {
$object->birth = dol_mktime(0, 0, 0, GETPOST('birthmonth', 'int'), GETPOST('birthday', 'int'), GETPOST('birthyear', 'int')); $object->birth = dol_mktime(0, 0, 0, GETPOST('birthmonth', 'int'), GETPOST('birthday', 'int'), GETPOST('birthyear', 'int'));
@ -819,32 +787,32 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac
if ($account->id > 0) { if ($account->id > 0) {
print '<tr class="oddeven">'; print '<tr class="oddeven">';
// Label // Label
print '<td>'.$account->label.'</td>'; print '<td>'.dol_escape_htmltag($account->label).'</td>';
// Bank name // Bank name
print '<td>'.$account->bank.'</td>'; print '<td>'.dol_escape_htmltag($account->bank).'</td>';
// Account number // Account number
print '<td>'; print '<td>';
$string = ''; $stringescaped = '';
foreach ($account->getFieldsToShow() as $val) { foreach ($account->getFieldsToShow() as $val) {
if ($val == 'BankCode') { if ($val == 'BankCode') {
$string .= $account->code_banque.' '; $stringescaped .= dol_escape_htmltag($account->code_banque).' ';
} elseif ($val == 'BankAccountNumber') { } elseif ($val == 'BankAccountNumber') {
$string .= $account->number.' '; $stringescaped .= dol_escape_htmltag($account->number).' ';
} elseif ($val == 'DeskCode') { } elseif ($val == 'DeskCode') {
$string .= $account->code_guichet.' '; $stringescaped .= dol_escape_htmltag($account->code_guichet).' ';
} elseif ($val == 'BankAccountNumberKey') { } elseif ($val == 'BankAccountNumberKey') {
$string .= $account->cle_rib.' '; $stringescaped .= dol_escape_htmltag($account->cle_rib).' ';
} }
} }
if (!empty($account->label) && $account->number) { if (!empty($account->label) && $account->number) {
if (!checkBanForAccount($account)) { if (!checkBanForAccount($account)) {
$string .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning'); $stringescaped .= ' '.img_picto($langs->trans("ValueIsNotValid"), 'warning');
} else { } else {
$string .= ' '.img_picto($langs->trans("ValueIsValid"), 'info'); $stringescaped .= ' '.img_picto($langs->trans("ValueIsValid"), 'info');
} }
} }
print $string; print $stringescaped;
print '</td>'; print '</td>';
// IBAN // IBAN
print '<td>'.getIbanHumanReadable($account); print '<td>'.getIbanHumanReadable($account);
@ -855,7 +823,8 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac
} }
print '</td>'; print '</td>';
// BIC // BIC
print '<td>'.$account->bic; print '<td>';
print dol_escape_htmltag($account->bic);
if (!empty($account->bic)) { if (!empty($account->bic)) {
if (!checkSwiftForAccount($account)) { if (!checkSwiftForAccount($account)) {
print ' '.img_picto($langs->trans("SwiftNotValid"), 'warning'); print ' '.img_picto($langs->trans("SwiftNotValid"), 'warning');
@ -869,9 +838,13 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac
// Edit/Delete // Edit/Delete
print '<td class="right nowraponall">'; print '<td class="right nowraponall">';
if ($permissiontoaddbankaccount) { if ($permissiontoaddbankaccount) {
print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&bankid='.$account->id.'&action=edit&token='.newToken().'">'; print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&bankid='.$account->id.'&action=edit&token='.newToken().'">';
print img_picto($langs->trans("Modify"), 'edit'); print img_picto($langs->trans("Modify"), 'edit');
print '</a>'; print '</a>';
print '<a class="editfielda marginleftonly marginrightonly reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&bankid='.$account->id.'&action=delete_confirmed&token='.newToken().'">';
print img_picto($langs->trans("Delete"), 'delete');
print '</a>';
} }
print '</td>'; print '</td>';
@ -880,7 +853,7 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac
if ($account->id == 0) { if ($account->id == 0) {
$colspan = 6; $colspan = 7;
print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>'; print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoBANRecord").'</span></td></tr>';
} }

View File

@ -117,8 +117,6 @@ class UserBankAccount extends Account
*/ */
public function update(User $user = null, $notrigger = 0) public function update(User $user = null, $notrigger = 0)
{ {
global $conf;
if (!$this->id) { if (!$this->id) {
$this->create(); $this->create();
} }
@ -193,7 +191,7 @@ class UserBankAccount extends Account
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->userid = $obj->fk_soc; $this->userid = $obj->fk_user;
$this->bank = $obj->bank; $this->bank = $obj->bank;
$this->code_banque = $obj->code_banque; $this->code_banque = $obj->code_banque;
$this->code_guichet = $obj->code_guichet; $this->code_guichet = $obj->code_guichet;
@ -226,6 +224,63 @@ class UserBankAccount extends Account
} }
} }
/**
* Delete user bank account from database
*
* @param User $user User deleting
* @return int <0 if KO, >0 if OK
*/
public function delete(User $user = null)
{
$error = 0;
$this->db->begin();
// Delete link between tag and bank account
/*
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
$sql .= " WHERE fk_account = ".((int) $this->id);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->error = "Error ".$this->db->lasterror();
}
}
*/
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
$sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
// Remove extrafields
/*
if (!$error) {
$result = $this->deleteExtraFields();
if ($result < 0) {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}*/
} else {
$error++;
$this->error = "Error ".$this->db->lasterror();
}
}
if (!$error) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
}
}
/** /**
* Return RIB * Return RIB
* *

View File

@ -332,7 +332,8 @@ if ($result > 0) {
$userstatic->email = $obj->email; $userstatic->email = $obj->email;
$userstatic->statut = $obj->status; $userstatic->statut = $obj->status;
print '<tr class="oddeven"><td>'.$userstatic->getNomUrl(1); print '<tr class="oddeven">';
print '<td>'.$userstatic->getNomUrl(1);
if ($obj->type == 'email') { if ($obj->type == 'email') {
if (isValidEmail($obj->email)) { if (isValidEmail($obj->email)) {
print ' &lt;'.$obj->email.'&gt;'; print ' &lt;'.$obj->email.'&gt;';
@ -359,8 +360,9 @@ if ($result > 0) {
$i++; $i++;
} }
$db->free($resql); $db->free($resql);
} else {
print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
} }
// List of notifications enabled for fixed email // List of notifications enabled for fixed email
/* /*
foreach($conf->global as $key => $val) { foreach($conf->global as $key => $val) {