From e9f754395d280e614bd8f59f9a16e9055124c137 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 10 Nov 2014 13:09:58 +0100 Subject: [PATCH] Start bank extrafields --- htdocs/compta/bank/class/account.class.php | 61 ++++++++++++++++++- htdocs/core/lib/bank.lib.php | 33 ++++++++++ .../llx_bank_account_extrafields.key.sql | 20 ++++++ .../tables/llx_bank_account_extrafields.sql | 26 ++++++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql create mode 100644 htdocs/install/mysql/tables/llx_bank_account_extrafields.sql diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index e2a039cf2d8..a50a7f448a9 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -343,7 +343,7 @@ class Account extends CommonObject */ function create($user='') { - global $langs,$conf; + global $langs,$conf, $hookmanager; // Clean parameters if (! $this->min_allowed) $this->min_allowed=0; @@ -441,6 +441,23 @@ class Account extends CommonObject $this->error=$this->db->lasterror(); return -3; } + + // Actions on extra fields (by external module or standard code) + $hookmanager->initHooks(array('bankdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + return -4; + } + } + } + else if ($reshook < 0) return -5; } return $this->id; } @@ -466,7 +483,7 @@ class Account extends CommonObject */ function update($user='') { - global $langs,$conf; + global $langs,$conf, $hookmanager; // Clean parameters if (! $this->min_allowed) $this->min_allowed=0; @@ -517,6 +534,25 @@ class Account extends CommonObject $result = $this->db->query($sql); if ($result) { + + // Actions on extra fields (by external module or standard code) + $hookmanager->initHooks(array('bankdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + return -1; + } + } + } + else if ($reshook < 0) return -1; + + return 1; } else @@ -663,6 +699,15 @@ class Account extends CommonObject $this->min_allowed = $obj->min_allowed; $this->min_desired = $obj->min_desired; $this->comment = $obj->comment; + + // Retreive all extrafield for thirdparty + // fetch optionals attributes and labels + require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + + return 1; } else @@ -694,6 +739,18 @@ class Account extends CommonObject 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) + { + return -1; + dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); + } + } + return 1; } else { diff --git a/htdocs/core/lib/bank.lib.php b/htdocs/core/lib/bank.lib.php index 488a4c3a530..e3fb787657b 100644 --- a/htdocs/core/lib/bank.lib.php +++ b/htdocs/core/lib/bank.lib.php @@ -89,6 +89,39 @@ function bank_prepare_head($object) return $head; } +/** + * Prepare array with list of tabs + * + * @param Object $object Object related to tabs + * @return array Array of tabs to shoc + */ +function bank_admin_prepare_head($object) +{ + global $langs, $conf, $user; + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT . '/admin/bank.php'; + $head[$h][1] = $langs->trans("Miscellaneous"); + $head[$h][2] = 'general'; + $h++; + + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin'); + + $head[$h][0] = DOL_URL_ROOT.'/admin/bank_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFields"); + $head[$h][2] = 'attributes'; + $h++; + + complete_head_from_modules($conf, $langs, $object, $head, $h, 'bank_admin', 'remove'); + + return $head; + } /** * Check account number informations for a bank account diff --git a/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql b/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql new file mode 100644 index 00000000000..0f6e8052115 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_bank_account_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2014 Florian Henry +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- =================================================================== + + +ALTER TABLE llx_bank_account_extrafields ADD INDEX idx_bank_account_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql b/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql new file mode 100644 index 00000000000..97b1508237c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_bank_account_extrafields.sql @@ -0,0 +1,26 @@ +-- ======================================================================== +-- Copyright (C) 2014 Florian Henry +-- +-- 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 +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ======================================================================== + +create table llx_bank_account_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=innodb; +