diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index acdd4ae2ebf..fbaa3b6baa4 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -13,7 +13,7 @@ * Copyright (C) 2016 Raphaël Doursenaud * Copyright (C) 2019-2025 Frédéric France * Copyright (C) 2020-2022 Open-Dsi - * Copyright (C) 2024 Charlene Benke + * Copyright (C) 2024-2025 Charlene Benke * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -707,6 +707,7 @@ if ($id == DICT_TYPE_CONTACT) { 'agenda' => img_picto('', 'action', 'class="pictofixedwidth"').$langs->trans('Agenda'), 'dolresource' => img_picto('', 'resource', 'class="pictofixedwidth"').$langs->trans('Resource'), 'societe' => img_picto('', 'company', 'class="pictofixedwidth"').$langs->trans('ThirdParty'), + 'product' => img_picto('', 'product', 'class="pictofixedwidth"').$langs->trans('Product'), // 'proposal' => $langs->trans('Proposal'), // 'order' => $langs->trans('Order'), // 'invoice' => $langs->trans('Bill'), diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 3db8392b363..73f05ff68d7 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -163,7 +163,21 @@ function product_prepare_head($object) $h++; } } - + if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) { + $objectsrc = $object; + if ($object->origin == 'product' && $object->origin_id > 0) { + $objectsrc = new Product($db); + $objectsrc->fetch($object->origin_id); + } + $nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external')); + $head[$h][0] = DOL_URL_ROOT."/product/contact.php?id=".$object->id; + $head[$h][1] = $langs->trans("ContactsAddresses"); + if ($nbContact > 0) { + $head[$h][1] .= ''.$nbContact.''; + } + $head[$h][2] = 'contact'; + $h++; + } $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/product/stats/facture.php', ['showmessage' => 1, 'id' => $object->id]); $head[$h][1] = $langs->trans('Referers'); $head[$h][2] = 'referers'; diff --git a/htdocs/install/mysql/data/llx_c_type_contact.sql b/htdocs/install/mysql/data/llx_c_type_contact.sql index 6611bd3b5aa..e062b86345a 100644 --- a/htdocs/install/mysql/data/llx_c_type_contact.sql +++ b/htdocs/install/mysql/data/llx_c_type_contact.sql @@ -103,6 +103,12 @@ insert into llx_c_type_contact (element, source, code, libelle, active, module) insert into llx_c_type_contact (element, source, code, libelle, active, module) values ('ticket', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1, NULL); insert into llx_c_type_contact (element, source, code, libelle, active, module) values ('ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1, NULL); +-- Product / Service +insert into llx_c_type_contact (element, source, code, libelle, active ) values ('product', 'internal', 'SALESREPFOLL', 'Responsable produit', 1); +insert into llx_c_type_contact (element, source, code, libelle, active ) values ('product', 'internal', 'BILLING', 'Responsable production', 1); +insert into llx_c_type_contact (element, source, code, libelle, active ) values ('product', 'external', 'CUSTOMER', 'Contact fournisseur', 1); +insert into llx_c_type_contact (element, source, code, libelle, active ) values ('product', 'external', 'SHIPPING', 'Contact sous-traitance', 1); + -- Projects / Projet - All project code can start with 'PROJECT' insert into llx_c_type_contact (element, source, code, libelle, active ) values ('project', 'internal', 'PROJECTLEADER', 'Chef de Projet', 1); insert into llx_c_type_contact (element, source, code, libelle, active ) values ('project', 'internal', 'PROJECTCONTRIBUTOR', 'Intervenant', 1); diff --git a/htdocs/product/contact.php b/htdocs/product/contact.php new file mode 100644 index 00000000000..3ba20613263 --- /dev/null +++ b/htdocs/product/contact.php @@ -0,0 +1,187 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2024 Frédéric France + * Copyright (C) 2025 MDW + * Copyright (C) 2025 Charlene Benke + + * + * 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/fichinter/contact.php + * \ingroup fichinter + * \brief Onglet de gestion des contacts de produits + */ + +// Load Dolibarr environment +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; + +/** + * @var Conf $conf + * @var DoliDB $db + * @var HookManager $hookmanager + * @var Translate $langs + * @var User $user + */ + +// Load translation files required by the page +$langs->loadLangs(array('products')); + +$id = GETPOSTINT('id'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action', 'aZ09'); + +$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); +$fieldtype = (!empty($ref) ? 'ref' : 'rowid'); +if ($user->socid) { + $socid = $user->socid; +} + +$object = new Product($db); +$result = $object->fetch($id, $ref); +if (!$result) { + print 'Record not found'; + exit; +} + +if ($object->id > 0) { + if ($object->type == $object::TYPE_PRODUCT) { + restrictedArea($user, 'product', $id, 'product&product', '', ''); + } + if ($object->type == $object::TYPE_SERVICE) { + restrictedArea($user, 'service', $id, 'product&product', '', ''); + } +} else { + restrictedArea($user, 'product|service', $fieldvalue, 'product&product', '', '', $fieldtype); +} + + +$usercancreate = ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')); + +/* + * Adding a new contact + */ + +if ($action == 'addcontact' && $usercancreate) { + if ($result > 0 && $id > 0) { + $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid')); + $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); + $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); + } + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + } else { + $mesg = $object->error; + } + + setEventMessages($mesg, null, 'errors'); + } +} elseif ($action == 'swapstatut' && $usercancreate) { + // Toggle the status of a contact + $result = $object->swapContactStatus(GETPOSTINT('ligne')); +} elseif ($action == 'deletecontact' && $usercancreate) { + // Deletes a contact + $result = $object->delete_contact(GETPOSTINT('lineid')); + + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } else { + dol_print_error($db); + } +} + + +/* + * View + */ + +$form = new Form($db); +$formcompany = new FormCompany($db); +$contactstatic = new Contact($db); +$userstatic = new User($db); + +$title = $langs->trans('ProductServiceCard'); +$help_url = ""; +$shortlabel = dol_trunc($object->label, 16); +if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) { + $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Notes'); + $help_url = 'EN:Module_Products|FR:Module_Produits|ES:Módulo_Productos|DE:Modul_Produkte'; +} +if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) { + $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Notes'); + $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:Módulo_Servicios|DE:Modul_Leistungen'; +} + +llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-card_note'); + +// Mode vue et edition + +if ($id > 0 || !empty($ref)) { + $object->fetch_thirdparty(); + + $head = product_prepare_head($object); + $titre = $langs->trans("CardProduct".$object->type); + $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); + + print dol_get_fiche_head($head, 'contact', $titre, -1, $picto); + + + $linkback = ''.$langs->trans("BackToList").''; + $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")"; + + $shownav = 1; + if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) { + $shownav = 0; + } + + dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref'); + + print dol_get_fiche_end(); + + print '
'; + + if (getDolGlobalString('PRODUCT_HIDE_ADD_CONTACT_USER')) { + $hideaddcontactforuser = 1; + } + if (getDolGlobalString('PRODUCT_HIDE_ADD_CONTACT_THIPARTY')) { + $hideaddcontactforthirdparty = 1; + } + + // Contacts lines (modules that overwrite templates must declare this into descriptor) + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); + foreach ($dirtpls as $reldir) { + $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); + if ($res) { + break; + } + } +} + + +llxFooter(); +$db->close();