From 82bc964f9fb04c0b7d8088515236f470729e7de2 Mon Sep 17 00:00:00 2001 From: Nicolas Domenech Date: Mon, 10 Jul 2023 18:27:21 +0200 Subject: [PATCH] #364 [Hook] fix: dolibarr type need specific --- class/actions_dolisirh.class.php | 59 ++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/class/actions_dolisirh.class.php b/class/actions_dolisirh.class.php index f0922e4..45bf802 100644 --- a/class/actions_dolisirh.class.php +++ b/class/actions_dolisirh.class.php @@ -502,11 +502,25 @@ public function addMoreActionsButtons(array $parameters, $object): int $id = GETPOST('id'); $elementId = GETPOST('element_id'); $type = GETPOST('type'); - if ($id > 0 && $elementId > 0 && ($type == 'timesheet' || $type == 'certificate') && $user->rights->dolisirh->$type->write) { - require_once __DIR__ . '/' . $type . '.class.php'; - - $classname = ucfirst($type); - $newobject = new $classname($this->db); + if ($id > 0 && $elementId > 0 && ($type == 'timesheet' || $type == 'certificate' || $type == 'invoice' || $type == 'invoicerec') && ($user->rights->dolisirh->$type->write || $user->rights->facture->creer)) { + switch ($type) { + case 'invoice' : + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + + $newobject = new Facture($this->db); + break; + case 'invoicerec' : + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture-rec.class.php'; + + $newobject = new FactureRec($this->db); + break; + default : + require_once __DIR__ . '/' . $type . '.class.php'; + + $classname = ucfirst($type); + $newobject = new $classname($this->db); + break; + } $newobject->fetch($elementId); @@ -821,6 +835,8 @@ function getDiffTimestampEvent() { if (preg_match('/categoryindex/', $parameters['context'])) { print ''; } elseif (preg_match('/categorycard/', $parameters['context']) && preg_match('/viewcat.php/', $_SERVER["PHP_SELF"])) { + require_once __DIR__ . '/../../saturne/lib/object.lib.php'; + $id = GETPOST('id'); $type = GETPOST('type'); @@ -834,13 +850,34 @@ function getDiffTimestampEvent() { } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action $offset = $limit * $page; - if ($type == 'timesheet' || $type == 'certificate') { - require_once __DIR__ . '/' . $type . '.class.php'; + if ($type == 'timesheet' || $type == 'certificate' || $type == 'invoice' || $type == 'invoicerec') { + switch ($type) { + case 'invoice' : + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + + $classname = 'Facture'; + $object = new $classname($this->db); + + $arrayObjects = saturne_fetch_all_object_type($classname); + break; + case 'invoicerec' : + require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture-rec.class.php'; - $classname = ucfirst($type); - $object = new $classname($this->db); + $classname = 'FactureRec'; + $object = new $classname($this->db); + + $arrayObjects = saturne_fetch_all_object_type($classname); + break; + default : + require_once __DIR__ . '/' . $type . '.class.php'; + + $classname = ucfirst($type); + $object = new $classname($this->db); + + $arrayObjects = $object->fetchAll(); + break; + } - $arrayObjects = $object->fetchAll(); if (is_array($arrayObjects) && !empty($arrayObjects)) { foreach ($arrayObjects as $objectsingle) { $array[$objectsingle->id] = $objectsingle->ref; @@ -859,7 +896,7 @@ function getDiffTimestampEvent() { $out .= ''; $out .= ''; $out .= '';
'; - $out .= $langs->trans("Add". ucfirst($type) . "IntoCategory") . ' '; + $out .= $langs->trans('AddObjectIntoCategory') . ' '; $out .= $form::selectarray('element_id', $array, '', 1); $out .= '