FIX error management in bank account deletion.
This commit is contained in:
parent
024cecec29
commit
10838983b5
@ -65,7 +65,7 @@ $extralabels=$extrafields->fetch_name_optionals_label($account->table_element);
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($_POST["action"] == 'add')
|
if ($action == 'add')
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ if ($_POST["action"] == 'add')
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
if ($action == 'update' && ! $_POST["cancel"])
|
||||||
{
|
{
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
@ -235,15 +235,24 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
|
if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer)
|
||||||
{
|
{
|
||||||
// Delete
|
// Delete
|
||||||
$account = new Account($db);
|
$account = new Account($db);
|
||||||
$account->fetch($_GET["id"]);
|
$account->fetch($_GET["id"]);
|
||||||
$account->delete();
|
$result = $account->delete($user);
|
||||||
|
|
||||||
header("Location: ".DOL_URL_ROOT."/compta/bank/index.php");
|
if ($result > 0)
|
||||||
exit;
|
{
|
||||||
|
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
|
||||||
|
header("Location: ".DOL_URL_ROOT."/compta/bank/index.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setEventMessages($account->error, $account->errors, 'errors');
|
||||||
|
$action='';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -950,29 +950,60 @@ class Account extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
|
$error=0;
|
||||||
$sql.= " WHERE rowid = ".$this->rowid;
|
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
$this->db->begin();
|
||||||
$result = $this->db->query($sql);
|
|
||||||
if ($result) {
|
|
||||||
|
|
||||||
// Remove extrafields
|
// Delete link between tag and bank account
|
||||||
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
|
if (! $error)
|
||||||
{
|
{
|
||||||
$result=$this->deleteExtraFields();
|
//$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; // No more used
|
||||||
if ($result < 0)
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
|
||||||
{
|
$sql.= " WHERE fk_account = ".$this->id;
|
||||||
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->error = "Error ".$this->db->lasterror();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
|
||||||
|
$sql.= " WHERE rowid = ".$this->rowid;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
// Remove extrafields
|
||||||
|
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
|
||||||
|
{
|
||||||
|
$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;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
dol_print_error($this->db);
|
{
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -199,11 +199,12 @@ class BankCateg // extends CommonObject
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Delete bank class
|
// Delete link between tag and bank account
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class";
|
//$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; // No more used
|
||||||
$sql.= " WHERE fk_categ = ".$this->id;
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
|
||||||
|
$sql.= " WHERE fk_categorie = ".$this->id;
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (!$resql)
|
if (!$resql)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user