diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 3c4568ae70e..464b9bf3127 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -526,7 +526,17 @@ class Categorie extends CommonObject } if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_project"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact"; + $sql .= " WHERE fk_categorie = ".$this->id; + if (!$this->db->query($sql)) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; $sql .= " WHERE fk_categorie = ".$this->id; if (!$this->db->query($sql)) { @@ -535,7 +545,18 @@ class Categorie extends CommonObject $error++; } } - + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; + $sql .= " WHERE fk_categ = ".$this->id; + if (!$this->db->query($sql)) + { + $this->error=$this->db->lasterror(); + dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR); + $error++; + } + } + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang"; 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 63876af6700..be4ec60b7f8 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 @@ -602,6 +602,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); @@ -609,6 +610,8 @@ class Account extends CommonObject if ($accline->insert() < 0) { $error++; + $this->error = $accline->error; + $this->errors = $accline->errors; } if (! $error) @@ -980,29 +983,59 @@ 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."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..073c28be1ca 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -188,29 +188,60 @@ 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."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 link between tag and bank lines + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; + $sql.= " WHERE fk_categ = ".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + // 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); diff --git a/htdocs/install/mysql/tables/llx_bank_class.sql b/htdocs/install/mysql/tables/llx_bank_class.sql index 6a21e7c12c6..7f77756a88a 100644 --- a/htdocs/install/mysql/tables/llx_bank_class.sql +++ b/htdocs/install/mysql/tables/llx_bank_class.sql @@ -1,5 +1,5 @@ -- =================================================================== --- Copyright (C) 2004-2007 Laurent Destailleur +-- Copyright (C) 2004-2017 Laurent Destailleur -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -14,6 +14,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- +-- Table to link bank tag/categories with bank lines -- =================================================================== create table llx_bank_class diff --git a/htdocs/install/mysql/tables/llx_categorie_account.sql b/htdocs/install/mysql/tables/llx_categorie_account.sql index 8bee67b1b40..3105482b01c 100644 --- a/htdocs/install/mysql/tables/llx_categorie_account.sql +++ b/htdocs/install/mysql/tables/llx_categorie_account.sql @@ -15,6 +15,7 @@ -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- +-- Table to link bank tag/categories with bank accounts -- =========================================================================== CREATE TABLE llx_categorie_account diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 2f248488afe..b0708cf47e4 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1502,6 +1502,9 @@ div#login_left, div#login_right { text-align: center; vertical-align: middle; } +div#login_right select#entity { + margin-top: 10px; +} table.login_table tr td table.none tr td { padding: 2px; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index ca1b6d2171c..faeab2a8ef7 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -1508,6 +1508,9 @@ div#login_left, div#login_right { text-align: center; vertical-align: middle; } +div#login_right select#entity { + margin-top: 10px; +} table.login_table tr td table.none tr td { padding: 2px; }