From ba2f87d307c4cb52091acc5e64a5d5ce93f22517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 2 Feb 2023 21:57:34 +0100 Subject: [PATCH] add ajax tooltip on contract --- htdocs/bom/class/bom.class.php | 2 +- htdocs/contrat/class/contrat.class.php | 90 +++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 2bbd1759453..d96274ede59 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1074,7 +1074,7 @@ class BOM extends CommonObject { global $conf, $langs, $user; - $langs->load('mrp'); + $langs->loadLangs(['product', 'mrp']); $datas = []; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index ad2cbcea84b..66b7bd083bf 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2018-2021 Frédéric France + * Copyright (C) 2018-2023 Frédéric France * Copyright (C) 2015-2018 Ferran Marcet * * This program is free software; you can redistribute it and/or modify @@ -185,6 +185,7 @@ class Contrat extends CommonObject public $nbofserviceswait; public $nbofservicesopened; public $nbofservicesexpired; + public $nbofservicesclosed; //public $lower_planned_end_date; //public $higher_planner_end_date; @@ -1981,6 +1982,42 @@ class Contrat extends CommonObject } } + /** + * getTooltipContentArray + * @param array $params params to construct tooltip data + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $conf, $langs, $user; + + $datas = []; + + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { + return ['optimize' => $langs->trans("ShowContract")]; + } + if ($user->hasRight('contrat', 'lire')) { + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Contract").''; + /* Status of a contract is status of all services, so disabled + if (isset($this->statut)) { + $label .= ' '.$this->getLibStatut(5); + }*/ + $datas['ref'] = '
'.$langs->trans('Ref').': '.($this->ref ? $this->ref : $this->id); + $datas['refcustomer'] = '
'.$langs->trans('RefCustomer').': '. $this->ref_customer; + $datas['refsupplier'] = '
'.$langs->trans('RefSupplier').': '.$this->ref_supplier; + if (!empty($this->total_ht)) { + $datas['amountht'] = '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); + } + if (!empty($this->total_tva)) { + $datas['vatamount'] = '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); + } + if (!empty($this->total_ttc)) { + $datas['amounttc'] = '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); + } + } + return $datas; + } /** * Return clicable name (with picto eventually) @@ -2013,7 +2050,7 @@ class Contrat extends CommonObject $label = ''; - if ($user->rights->contrat->lire) { + if ($user->hasRight('contrat', 'lire')) { $label = img_picto('', $this->picto).' '.$langs->trans("Contract").''; /* Status of a contract is status of all services, so disabled if (isset($this->statut)) { @@ -2037,11 +2074,20 @@ class Contrat extends CommonObject $linkclose = ''; if (empty($notooltip) && $user->rights->contrat->lire) { if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { - $label = $langs->trans("ShowOrder"); + $label = $langs->trans("ShowContract"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + ]; + $linkclose .= '" data-params='.json_encode($params).' id="' . uniqid('contract') . '" title="' . $langs->trans('Loading') . '"'; + $linkclose .= ' class="classforajaxtooltip"'; + } else { + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; + } } $linkstart = 'trans("ShowContractOfService").': '.$this->label; + if (empty($datas['label'])) { + $datas['label'] = $this->description; + } + + return $datas; + } + + /** + * Return clicable name (with picto eventually) for ContratLigne * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param int $maxlength Max length @@ -3087,8 +3152,17 @@ class ContratLigne extends CommonObjectLine if (empty($label)) { $label = $this->description; } - - $link = ''; + $link = ''; + } $linkend = ''; $picto = 'service';