From c9114bd687bb0d88a6d0418b684ab23c17f85621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 12:08:09 +0100 Subject: [PATCH 1/7] add parameter for hook --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a96089878c2..7c28fd4dc19 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9364,7 +9364,7 @@ function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, // No need to make a return $head. Var is modified as a reference if (!empty($hookmanager)) { - $parameters = array('object' => $object, 'mode' => $mode, 'head' => &$head); + $parameters = array('object' => $object, 'mode' => $mode, 'head' => &$head, 'filterorigmodule' => $filterorigmodule); $reshook = $hookmanager->executeHooks('completeTabsHead', $parameters); if ($reshook > 0) { // Hook ask to replace completely the array $head = $hookmanager->resArray; From f3aa42d095014592e532540845f1f85e619d1906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 22:03:29 +0100 Subject: [PATCH 2/7] fetch optionals in accountline class https://github.com/Dolibarr/dolibarr/blob/c97c185368e58953c084469ae8ef84a93a00ecc1/htdocs/install/mysql/migration/16.0.0-17.0.0.sql#L148-L156 --- htdocs/compta/bank/class/account.class.php | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 6549809b803..464df7d5fb5 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -852,7 +852,7 @@ class Account extends CommonObject $sql .= ",min_allowed = ".($this->min_allowed != '' ? price2num($this->min_allowed) : "null"); $sql .= ",min_desired = ".($this->min_desired != '' ? price2num($this->min_desired) : "null"); - $sql .= ",comment = '".$this->db->escape($this->comment)."'"; + $sql .= ",comment = '".$this->db->escape($this->comment)."'"; $sql .= ",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) : "null"); $sql .= ",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) : "null"); @@ -1926,18 +1926,18 @@ class AccountLine extends CommonObject $obj = $this->db->fetch_object($result); if ($obj) { $this->id = $obj->rowid; - $this->rowid = $obj->rowid; + $this->rowid = $obj->rowid; $this->ref = $obj->rowid; - $this->datec = $obj->datec; - $this->datev = $obj->datev; - $this->dateo = $obj->dateo; + $this->datec = $obj->datec; + $this->datev = $obj->datev; + $this->dateo = $obj->dateo; $this->amount = $obj->amount; - $this->label = $obj->label; - $this->note = $obj->note; + $this->label = $obj->label; + $this->note = $obj->note; - $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_rappro = $obj->fk_user_rappro; + $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_rappro = $obj->fk_user_rappro; $this->fk_type = $obj->fk_type; // Type of transaction $this->rappro = $obj->rappro; @@ -1948,9 +1948,13 @@ class AccountLine extends CommonObject $this->fk_bordereau = $obj->fk_bordereau; $this->fk_account = $obj->fk_account; - $this->bank_account_ref = $obj->bank_account_ref; + $this->bank_account_ref = $obj->bank_account_ref; $this->bank_account_label = $obj->bank_account_label; + // Retrieve all extrafield + // fetch optionals attributes and labels + $this->fetch_optionals(); + $ret = 1; } $this->db->free($result); From a87078a70ad742c2b8d3bd1d465513eacdb9e33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 22:21:46 +0100 Subject: [PATCH 3/7] Update account.class.php --- htdocs/compta/bank/class/account.class.php | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 464df7d5fb5..ce73d62c0fe 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1971,6 +1971,10 @@ class AccountLine extends CommonObject */ public function insert() { + $error = 0; + + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank ("; $sql .= "datec"; $sql .= ", dateo"; @@ -2006,15 +2010,26 @@ class AccountLine extends CommonObject dol_syslog(get_class($this)."::insert", LOG_DEBUG); $resql = $this->db->query($sql); - - if (!$resql) { + if ($resql) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); + // Actions on extra fields (by external module or standard code) + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } else { + $error++; $this->error = $this->db->lasterror(); - return -1; + dol_print_error($this->db); } - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); - - return $this->id; + if (!$error) { + $this->db->commit(); + return $this->id; + } else { + $this->db->rollback(); + return -1 * $error; + } } /** From 78000c9c4988e6c3e0b5a392f7a5c04b25c6f2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 22:28:11 +0100 Subject: [PATCH 4/7] Update account.class.php --- htdocs/compta/bank/class/account.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index ce73d62c0fe..a73fd2b5f2c 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2016 Ferran Marcet * Copyright (C) 2019 JC Prieto + * Copyright (C) 2022 Frédéric France * * 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 @@ -2083,6 +2084,12 @@ class AccountLine extends CommonObject $nbko++; } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=".(int) $this->rowid; + $result = $this->db->query($sql); + if (!$result) { + $nbko++; + } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".(int) $this->rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); From ab2d65ac778b57a09650d838e8ef67b0164ed2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 22:42:47 +0100 Subject: [PATCH 5/7] Update line.php --- htdocs/compta/bank/line.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index cb10a7310c6..fb36378338d 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -7,7 +7,7 @@ * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Marcos García - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2022 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify @@ -35,6 +35,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; // Load translation files required by the page $langs->loadLangs(array('banks', 'categories', 'compta', 'bills', 'other')); @@ -77,7 +78,7 @@ if (empty($user->rights->banque->lire) && empty($user->rights->banque->consolida } $hookmanager->initHooks(array('bankline')); - +$extrafields = new ExtraFields($db); /* * Actions @@ -302,6 +303,7 @@ if ($result) { $account = $acct->id; $bankline = new AccountLine($db); + $extrafields->fetch_name_optionals_label($bankline->element); $bankline->fetch($rowid, $ref); $links = $acct->get_url($rowid); @@ -601,6 +603,13 @@ if ($result) { print ""; } + // Other attributes + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $bankline, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + if (empty($reshook)) { + print $bankline->showOptionals($extrafields, 'create', $parameters); + } print ""; // Code to adjust value date with plus and less picto using an Ajax call instead of a full reload of page From cb71e479a251435d5aedbd3bd7a55b8b6caa09bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 23:02:27 +0100 Subject: [PATCH 6/7] Update line.php --- htdocs/compta/bank/line.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index fb36378338d..c01ecaf5fca 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -7,7 +7,7 @@ * Copyright (C) 2015-2017 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Marcos García - * Copyright (C) 2018-2022 Frédéric France + * Copyright (C) 2018 Frédéric France * Copyright (C) 2021 Gauthier VERDOL * * This program is free software; you can redistribute it and/or modify @@ -78,7 +78,9 @@ if (empty($user->rights->banque->lire) && empty($user->rights->banque->consolida } $hookmanager->initHooks(array('bankline')); +$object = new AccountLine($db); $extrafields = new ExtraFields($db); +$extrafields->fetch_name_optionals_label($object->element); /* * Actions @@ -126,18 +128,17 @@ if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->ban if ($user->rights->banque->modifier && $action == "update") { $error = 0; - $acline = new AccountLine($db); - $result = $acline->fetch($rowid); + $result = $object->fetch($rowid); if ($result <= 0) { dol_syslog('Failed to read bank line with id '.$rowid, LOG_WARNING); // This happens due to old bug that has set fk_account to null. - $acline->id = $rowid; + $object->id = $rowid; } $acsource = new Account($db); $acsource->fetch($accountoldid); $actarget = new Account($db); - if (GETPOST('accountid', 'int') > 0 && !$acline->rappro && !$acline->getVentilExportCompta()) { // We ask to change bank account + if (GETPOST('accountid', 'int') > 0 && !$object->rappro && !$object->getVentilExportCompta()) { // We ask to change bank account $actarget->fetch(GETPOST('accountid', 'int')); } else { $actarget->fetch($accountoldid); @@ -174,7 +175,7 @@ if ($user->rights->banque->modifier && $action == "update") { $sql .= " emetteur='".$db->escape(GETPOST("emetteur"))."',"; } // Blocked when conciliated - if (!$acline->rappro) { + if (!$object->rappro) { if (GETPOSTISSET('label')) { $sql .= " label = '".$db->escape(GETPOST("label"))."',"; } @@ -189,7 +190,7 @@ if ($user->rights->banque->modifier && $action == "update") { } } $sql .= " fk_account = ".((int) $actarget->id); - $sql .= " WHERE rowid = ".((int) $acline->id); + $sql .= " WHERE rowid = ".((int) $object->id); $result = $db->query($sql); if (!$result) { @@ -303,7 +304,6 @@ if ($result) { $account = $acct->id; $bankline = new AccountLine($db); - $extrafields->fetch_name_optionals_label($bankline->element); $bankline->fetch($rowid, $ref); $links = $acct->get_url($rowid); @@ -608,7 +608,7 @@ if ($result) { $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $bankline, $action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook)) { - print $bankline->showOptionals($extrafields, 'create', $parameters); + print $bankline->showOptionals($extrafields, ($objp->rappro ? 'view' : 'create'), $parameters); } print ""; From 0f4a1ce98ab0ccf31e42197aa9aa011b2cde5a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 23:12:50 +0100 Subject: [PATCH 7/7] Update line.php --- htdocs/compta/bank/line.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index c01ecaf5fca..7c775b6e95c 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -216,6 +216,11 @@ if ($user->rights->banque->modifier && $action == "update") { } } + if (!$error) { + $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); + $object->insertExtraFields(); + } + if (!$error) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $db->commit();