diff --git a/htdocs/accountancy/admin/fiscalyear.php b/htdocs/accountancy/admin/fiscalyear.php index 27226d388f6..270d0f732e6 100644 --- a/htdocs/accountancy/admin/fiscalyear.php +++ b/htdocs/accountancy/admin/fiscalyear.php @@ -97,7 +97,7 @@ $help_url = "EN:Module_Double_Entry_Accounting"; llxHeader('', $title, $help_url); -$sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut, f.entity"; +$sql = "SELECT f.rowid, f.label, f.date_start, f.date_end, f.statut as status, f.entity"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear as f"; $sql .= " WHERE f.entity = ".$conf->entity; $sql .= $db->order($sortfield, $sortorder); @@ -137,7 +137,7 @@ if ($result) { print ''.$langs->trans("DateEnd").''; print ''.$langs->trans("NumberOfAccountancyEntries").''; print ''.$langs->trans("NumberOfAccountancyMovements").''; - print ''.$langs->trans("Statut").''; + print ''.$langs->trans("Status").''; print ''; if ($num) { @@ -145,6 +145,9 @@ if ($result) { $obj = $db->fetch_object($result); $fiscalyearstatic->id = $obj->rowid; + $fiscalyearstatic->date_start = $obj->date_start; + $fiscalyearstatic->date_end = $obj->date_end; + $fiscalyearstatic->status = $obj->status; print ''; print ''; @@ -155,7 +158,7 @@ if ($result) { print ''.dol_print_date($db->jdate($obj->date_end), 'day').''; print ''.$object->getAccountancyEntriesByFiscalYear($obj->date_start, $obj->date_end).''; print ''.$object->getAccountancyMovementsByFiscalYear($obj->date_start, $obj->date_end).''; - print ''.$fiscalyearstatic->LibStatut($obj->statut, 5).''; + print ''.$fiscalyearstatic->LibStatut($obj->status, 5).''; print ''; $i++; } diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 101f5995e6c..cfc0c02f19e 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2020 OScss-Shop - * + * Copyright (C) 2023 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 @@ -92,7 +92,17 @@ class Fiscalyear extends CommonObject */ public $datec; - public $statut; // 0=open, 1=closed + /** + * @var int status 0=open, 1=closed + * @deprecated + * @see $status + */ + public $statut; + + /** + * @var int status 0=open, 1=closed + */ + public $status; /** * @var int Entity @@ -102,6 +112,9 @@ class Fiscalyear extends CommonObject public $statuts = array(); public $statuts_short = array(); + const STATUS_OPEN = 0; + const STATUS_CLOSED = 1; + /** * Constructor @@ -220,7 +233,7 @@ class Fiscalyear extends CommonObject */ public function fetch($id) { - $sql = "SELECT rowid, label, date_start, date_end, statut"; + $sql = "SELECT rowid, label, date_start, date_end, statut as status"; $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " WHERE rowid = ".((int) $id); @@ -234,7 +247,8 @@ class Fiscalyear extends CommonObject $this->date_start = $this->db->jdate($obj->date_start); $this->date_end = $this->db->jdate($obj->date_end); $this->label = $obj->label; - $this->statut = $obj->statut; + $this->statut = $obj->status; + $this->status = $obj->status; return 1; } else { @@ -267,6 +281,35 @@ class Fiscalyear extends CommonObject } } + /** + * getTooltipContentArray + * + * @param array $params ex option, infologin + * @since v18 + * @return array + */ + public function getTooltipContentArray($params) + { + global $langs; + + $langs->load('compta'); + + $datas = []; + $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("FiscalPeriod").''; + if (isset($this->status)) { + $datas['picto'] .= ' '.$this->getLibStatut(5); + } + $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; + if (isset($this->date_start)) { + $datas['date_start'] .= '
'.$langs->trans('DateStart').': '.dol_print_date($this->date_start, 'day'); + } + if (isset($this->date_start)) { + $datas['date_end'] .= '
'.$langs->trans('DateEnd').': '.dol_print_date($this->date_end, 'day');; + } + + return $datas; + } + /** * Return clicable link of object (with eventually picto) * @@ -286,14 +329,27 @@ class Fiscalyear extends CommonObject if (!empty($conf->dol_no_mouse_hover)) { $notooltip = 1; // Force disable tooltips } - - $result = ''; - - $url = DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?id='.$this->id; - - if (empty($user->rights->accounting->fiscalyear->write)) { + $option = ''; + if (!$user->hasRight('accounting', 'fiscalyear', 'write')) { $option = 'nolink'; } + $result = ''; + $params = [ + 'id' => $this->id, + 'objecttype' => $this->element, + 'option', $option, + 'nofetch' => 1, + ]; + $classfortooltip = 'classfortooltip'; + $dataparams = ''; + if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + $classfortooltip = 'classforajaxtooltip'; + $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; + $label = 'ToComplete'; + } else { + $label = implode($this->getTooltipContentArray($params)); + } + $url = DOL_URL_ROOT.'/accountancy/admin/fiscalyear_card.php?id='.$this->id; if ($option !== 'nolink') { // Add param to save lastsearch_values or not @@ -306,28 +362,14 @@ class Fiscalyear extends CommonObject } } - if ($short) { - return $url; - } - - $label = ''; - - if ($user->rights->accounting->fiscalyear->write) { - $label = ''.$langs->trans("FiscalPeriod").''; - $label .= '
'.$langs->trans('Ref').': '.$this->id; - if (isset($this->statut)) { - $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); - } - } - $linkclose = ''; - if (empty($notooltip) && $user->rights->accounting->fiscalyear->write) { + if (empty($notooltip) && $user->hasRight('accounting', 'fiscalyear', 'write')) { if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("FiscalYear"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; + $linkclose .= $dataparams.' class="'.$classfortooltip.'"'; } $linkstart = 'picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1); } if ($withpicto != 2) { $result .= $this->ref; @@ -359,7 +401,7 @@ class Fiscalyear extends CommonObject */ public function getLibStatut($mode = 0) { - return $this->LibStatut($this->statut, $mode); + return $this->LibStatut($this->status, $mode); } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index db6cbaf72f8..b770c71f839 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11414,6 +11414,10 @@ function getElementProperties($element_type) $classname = 'Websitepage'; $module = 'website'; $subelement = 'websitepage'; + } elseif ($element_type == 'fiscalyear') { + $classpath = 'core/class'; + $module = 'accounting'; + $subelement = 'fiscalyear'; } if (empty($classfile)) { diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 023f8ebafba..0d283ea623d 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -509,6 +509,11 @@ function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', if ($subfeature == 'user' && $user->id == $objectid) { continue; // A user can always read its own card } + if ($subfeature == 'fiscalyear' && $user->hasRight('accounting', 'fiscalyear', 'write')) { + // only one right for fiscalyear + $tmpreadok = 1; + continue; + } if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) { $tmpreadok = 0; } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {