FIX error management in bank account deletion.

This commit is contained in:
Laurent Destailleur 2017-02-27 11:38:19 +01:00
parent 024cecec29
commit 10838983b5
3 changed files with 71 additions and 30 deletions

View File

@ -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);
if ($result > 0)
{
setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); header("Location: ".DOL_URL_ROOT."/compta/bank/index.php");
exit; exit;
}
else
{
setEventMessages($account->error, $account->errors, 'errors');
$action='';
}
} }

View File

@ -950,29 +950,60 @@ class Account extends CommonObject
{ {
global $conf; global $conf;
$error=0;
$this->db->begin();
// Delete link between tag and bank account
if (! $error)
{
//$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; // No more used
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
$sql.= " WHERE fk_account = ".$this->id;
$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 = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
$sql.= " WHERE rowid = ".$this->rowid; $sql.= " WHERE rowid = ".$this->rowid;
$sql.= " AND entity = ".$conf->entity;
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);
if ($result) { if ($result)
{
// Remove extrafields // Remove extrafields
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{ {
$result=$this->deleteExtraFields(); $result=$this->deleteExtraFields();
if ($result < 0) if ($result < 0)
{ {
$error++;
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
return -1; }
}
}
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;
} }
} }

View File

@ -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)