diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index baf2f3e26b1..dcc0fc85ecc 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -62,6 +62,7 @@ $extrafields = new ExtraFields($db); $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + /* * Actions */ @@ -152,6 +153,7 @@ if ($action == 'add') else { $error++; setEventMessages($object->error, $object->errors, 'errors'); + $action='create'; // Force chargement page en mode creation } } @@ -247,15 +249,24 @@ if ($action == 'update') } } -if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) +if ($action == 'confirm_delete' && $_POST["confirm"] == "yes" && $user->rights->banque->configurer) { // Delete $object = new Account($db); $object->fetch(GETPOST("id","int")); - $object->delete(); + $result = $object->delete($user); - header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); - exit; + if ($result > 0) + { + setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); + header("Location: ".DOL_URL_ROOT."/compta/bank/index.php"); + exit; + } + else + { + setEventMessages($account->error, $account->errors, 'errors'); + $action=''; + } } diff --git a/htdocs/compta/bank/categ.php b/htdocs/compta/bank/categ.php index 48e8e738fef..51030242fce 100644 --- a/htdocs/compta/bank/categ.php +++ b/htdocs/compta/bank/categ.php @@ -72,6 +72,7 @@ if ($categid) { } } + /* * View */ diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 0e9b25c39a8..586b39318be 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -385,7 +385,7 @@ class Account extends CommonObject /** * Add an entry into table ".MAIN_DB_PREFIX."bank * - * @param int $date Date operation + * @param int $date Date operation * @param string $oper 1,2,3,4... (deprecated) or TYP,VIR,PRE,LIQ,VAD,CB,CHQ... * @param string $label Descripton * @param float $amount Amount @@ -604,6 +604,7 @@ class Account extends CommonObject $accline->datec = $this->db->idate($now); $accline->label = '('.$langs->trans("InitialBankBalance").')'; $accline->amount = price2num($this->solde); + $accline->fk_user_author = $user->id; $accline->fk_account = $this->id; $accline->datev = $this->db->idate($this->date_solde); $accline->dateo = $this->db->idate($this->date_solde); @@ -611,6 +612,8 @@ class Account extends CommonObject if ($accline->insert() < 0) { $error++; + $this->error = $accline->error; + $this->errors = $accline->errors; } if (! $error) @@ -982,29 +985,60 @@ class Account extends CommonObject { global $conf; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; - $sql.= " WHERE rowid = ".$this->rowid; - $sql.= " AND entity = ".$conf->entity; - - 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) - { - dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); - return -1; - } - } - + $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.= " 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; } - else { - dol_print_error($this->db); + else + { + $this->db->rollback(); return -1; } } diff --git a/htdocs/compta/bank/class/bankcateg.class.php b/htdocs/compta/bank/class/bankcateg.class.php index 7487e4a9f48..02d80d7429c 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -188,29 +188,47 @@ class BankCateg // extends CommonObject /** * Delete object in database * - * @param User $user User that delete - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, >0 if OK + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = 0) { global $conf; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; - $sql .= " WHERE rowid=".$this->id; - $sql .= " AND entity = ".$conf->entity; - $this->db->begin(); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); + // 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_categorie = ".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } } - - // Commit or rollback + + // Delete bank categ + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; + $sql .= " WHERE rowid=".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);