From 79d8351dda16bf83a7aece6683238cc6d056ccb5 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Wed, 17 Jul 2019 14:09:25 +0200 Subject: [PATCH] NEW Extrafields on salaries --- htdocs/admin/salaries_extrafields.php | 117 ++++++++++++++++++ htdocs/core/lib/salaries.lib.php | 78 ++++++++---- htdocs/core/modules/modSalaries.class.php | 5 +- .../llx_payment_salary_extrafields.key.sql | 23 ++++ .../tables/llx_payment_salary_extrafields.sql | 27 ++++ 5 files changed, 225 insertions(+), 25 deletions(-) create mode 100644 htdocs/admin/salaries_extrafields.php create mode 100644 htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql create mode 100644 htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql diff --git a/htdocs/admin/salaries_extrafields.php b/htdocs/admin/salaries_extrafields.php new file mode 100644 index 00000000000..180e695407f --- /dev/null +++ b/htdocs/admin/salaries_extrafields.php @@ -0,0 +1,117 @@ + + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2019 Alexandre Spangaro + * + * 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 . + */ + +/** + * \file htdocs/admin/salaries_extrafields.php + * \ingroup member + * \brief Page to setup extra fields of salaries + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array("admin","salaries")); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label=ExtraFields::$type2label; +$type2label=array(''); +foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val); + +$action=GETPOST('action', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='adherent'; //Must be the $table_element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$textobject = $langs->transnoentitiesnoconv("Members"); + +$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros'; +llxHeader('', $langs->trans("MembersSetup"), $help_url); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("MembersSetup"), $linkback, 'title_setup'); + + +$head = member_admin_prepare_head(); + +dol_fiche_head($head, 'attributes', $langs->trans("Members"), -1, 'user'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print ''; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation of an optional field */ +/* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print '

'; + print load_fiche_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* ************************************************************************** */ +/* */ +/* Edition of an optional field */ +/* */ +/* ************************************************************************** */ +if ($action == 'edit' && ! empty($attrname)) +{ + print '

'; + print load_fiche_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php'; +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/core/lib/salaries.lib.php b/htdocs/core/lib/salaries.lib.php index 126063dce4d..418bc8bfaa4 100644 --- a/htdocs/core/lib/salaries.lib.php +++ b/htdocs/core/lib/salaries.lib.php @@ -1,6 +1,7 @@ + * Copyright (C) 2015 Charlie BENKE + * Copyright (C) 2019 Alexandre Spangaro * * 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 @@ -27,15 +28,15 @@ function salaries_prepare_head($object) { - global $db, $langs, $conf; + global $db, $langs, $conf; - $h = 0; - $head = array(); + $h = 0; + $head = array(); - $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/card.php?id='.$object->id; - $head[$h][1] = $langs->trans("Card"); - $head[$h][2] = 'card'; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/card.php?id='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'card'; + $h++; // Show more tabs from modules // Entries must be declared in modules descriptor with line @@ -43,23 +44,56 @@ function salaries_prepare_head($object) // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries'); - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->salaries->dir_output . "/" . dol_sanitizeFileName($object->ref); - $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); + $upload_dir = $conf->salaries->dir_output . "/" . dol_sanitizeFileName($object->ref); + $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); $nbLinks=Link::count($db, $object->element, $object->id); - $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/document.php?id='.$object->id; - $head[$h][1] = $langs->trans('Documents'); - if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' '.($nbFiles+$nbLinks).''; - $head[$h][2] = 'documents'; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/document.php?id='.$object->id; + $head[$h][1] = $langs->trans('Documents'); + if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' '.($nbFiles+$nbLinks).''; + $head[$h][2] = 'documents'; + $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/info.php?id='.$object->id; - $head[$h][1] = $langs->trans("Info"); - $head[$h][2] = 'info'; - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/info.php?id='.$object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; - complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries', 'remove'); + complete_head_from_modules($conf, $langs, $object, $head, $h, 'salaries', 'remove'); - return $head; + return $head; +} + +/** + * Return array head with list of tabs to view object informations + * + * @return array head + */ +function salaries_admin_prepare_head() +{ + global $langs, $conf, $user; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/admin/salaries.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:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab + complete_head_from_modules($conf, $langs, '', $head, $h, 'salaries_admin'); + + $head[$h][0] = DOL_URL_ROOT.'/admin/salaries_extrafields.php'; + $head[$h][1] = $langs->trans("ExtraFieldsSalaries"); + $head[$h][2] = 'attributes'; + $h++; + + complete_head_from_modules($conf, $langs, '', $head, $h, 'salaries_admin', 'remove'); + + return $head; } diff --git a/htdocs/core/modules/modSalaries.class.php b/htdocs/core/modules/modSalaries.class.php index ed3aec4a48b..d68c6a36308 100644 --- a/htdocs/core/modules/modSalaries.class.php +++ b/htdocs/core/modules/modSalaries.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2014 Alexandre Spangaro + * Copyright (C) 2014-2019 Alexandre Spangaro * * 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 @@ -68,8 +68,7 @@ class modSalaries extends DolibarrModules $this->dirs = array("/salaries/temp"); // Config pages - //$this->config_page_url = array('salaries.php'); - $this->config_page_url = array(); + $this->config_page_url = array('salaries.php'); // Dependencies $this->hidden = false; // A condition to hide module diff --git a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql b/htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql new file mode 100644 index 00000000000..6989d271ccc --- /dev/null +++ b/htdocs/install/mysql/tables/llx_payment_salary_extrafields.key.sql @@ -0,0 +1,23 @@ +-- =================================================================== +-- Copyright (C) 2002-2003 Rodolphe Quiedeville +-- Copyright (C) 2002-2003 Jean-Louis Bergamo +-- Copyright (C) 2009 Regis Houssin +-- Copyright (C) 2011 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 +-- 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_adherent_extrafields ADD INDEX idx_adherent_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql b/htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql new file mode 100644 index 00000000000..3ad91052c24 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_payment_salary_extrafields.sql @@ -0,0 +1,27 @@ +-- =================================================================== +-- Copyright (C) 2002-2003 Rodolphe Quiedeville +-- Copyright (C) 2002-2003 Jean-Louis Bergamo +-- Copyright (C) 2009 Regis Houssin +-- +-- 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_adherent_extrafields +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, -- member id + import_key varchar(14) -- import key +)ENGINE=innodb;