From c01988ba438e1e74f6b88b8a1d4929682ab728a5 Mon Sep 17 00:00:00 2001 From: gauthier Date: Thu, 9 Feb 2017 17:28:37 +0100 Subject: [PATCH 1/5] FIX : delete bank class lines when we delete bank_categ --- htdocs/compta/bank/categ.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/compta/bank/categ.php b/htdocs/compta/bank/categ.php index 00755959ab9..176f8d6101b 100644 --- a/htdocs/compta/bank/categ.php +++ b/htdocs/compta/bank/categ.php @@ -87,6 +87,17 @@ if ($action == 'delete') { if (GETPOST('categid')) { + // Delete bank class + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; + $sql.= " WHERE fk_categ = '".GETPOST('categid')."'"; + + $result = $db->query($sql); + if (!$result) + { + dol_print_error($db); + } + + // Delete bank categ $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; $sql.= " WHERE rowid = '".GETPOST('categid')."'"; $sql.= " AND entity = ".$conf->entity; From 08915d88d02a5e283fe743037d353692e01954bf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 11 Feb 2017 15:40:25 +0100 Subject: [PATCH 2/5] FIX the dolCopyDir fails if target dir does not exists. --- htdocs/core/lib/files.lib.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 21803bc3ad4..f0cab58bb09 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -868,13 +868,23 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists) $result=0; - dol_syslog("files.lib.php::dolCopyr srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); + dol_syslog("files.lib.php::dolCopyDir srcfile=".$srcfile." destfile=".$destfile." newmask=".$newmask." overwriteifexists=".$overwriteifexists); if (empty($srcfile) || empty($destfile)) return -1; $destexists=dol_is_dir($destfile); if (! $overwriteifexists && $destexists) return 0; - + + if (! $destexists) + { + // We must set mask just before creating dir, becaause it can be set differently by dol_copy + umask(0); + $dirmaskdec=octdec($newmask); + if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); + $dirmaskdec |= octdec('0200'); // Set w bit required to be able to create content for recursive subdirs files + dol_mkdir($destfile."/".$file, '', decoct($dirmaskdec)); + } + $srcfile=dol_osencode($srcfile); $destfile=dol_osencode($destfile); @@ -891,6 +901,7 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists) { if (!is_dir($destfile."/".$file)) { + // We must set mask just before creating dir, becaause it can be set differently by dol_copy umask(0); $dirmaskdec=octdec($newmask); if (empty($newmask) && ! empty($conf->global->MAIN_UMASK)) $dirmaskdec=octdec($conf->global->MAIN_UMASK); From 0f8a8869cb8ebeedee490bae478dee7509affcc2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Feb 2017 11:15:59 +0100 Subject: [PATCH 3/5] FIX Error management during bank account creation --- htdocs/compta/bank/class/account.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index eaa57b1ca30..393cf619e81 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -380,7 +380,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 @@ -596,12 +596,15 @@ 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); $accline->fk_type = 'SOLD'; if ($accline->insert() < 0) { + $this->error = $accline->error; + $this->errors = $accline->errors; return -3; } From 024cecec29465e12c7967860f469cee3a83adc1e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Feb 2017 11:16:46 +0100 Subject: [PATCH 4/5] FIX Error management during bank account creation --- htdocs/compta/bank/card.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index a29a0d768bd..3977c208cce 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -60,9 +60,11 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($account->table_element); + /* * Actions */ + if ($_POST["action"] == 'add') { $error=0; @@ -129,6 +131,8 @@ if ($_POST["action"] == 'add') if (! $error) { + $db->begin(); + $id = $account->create($user); if ($id > 0) { @@ -137,8 +141,13 @@ if ($_POST["action"] == 'add') $account->setCategories($categories); $_GET["id"]=$id; // Force chargement page en mode visu + $action=''; + + $db->commit(); } else { + $db->rollback(); + setEventMessages($account->error, $account->errors, 'errors'); $action='create'; // Force chargement page en mode creation } From 10838983b50ad51afc0bb9dfb4ae32d91eb2ec74 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 Feb 2017 11:38:19 +0100 Subject: [PATCH 5/5] FIX error management in bank account deletion. --- htdocs/compta/bank/card.php | 21 ++++-- htdocs/compta/bank/class/account.class.php | 73 ++++++++++++++------ htdocs/compta/bank/class/bankcateg.class.php | 7 +- 3 files changed, 71 insertions(+), 30 deletions(-) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 3977c208cce..b3bdde6d555 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -65,7 +65,7 @@ $extralabels=$extrafields->fetch_name_optionals_label($account->table_element); * Actions */ -if ($_POST["action"] == 'add') +if ($action == 'add') { $error=0; @@ -154,7 +154,7 @@ if ($_POST["action"] == 'add') } } -if ($_POST["action"] == 'update' && ! $_POST["cancel"]) +if ($action == 'update' && ! $_POST["cancel"]) { $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 $account = new Account($db); $account->fetch($_GET["id"]); - $account->delete(); + $result = $account->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/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 393cf619e81..96661f4074a 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -950,29 +950,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 4f254282bb5..02d80d7429c 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -199,11 +199,12 @@ class BankCateg // extends CommonObject $this->db->begin(); - // Delete bank class + // Delete link between tag and bank account if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; - $sql.= " WHERE fk_categ = ".$this->id; + //$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)