Skip to content

Commit

Permalink
#364 [Hook] fix: dolibarr type need specific
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Jul 10, 2023
1 parent 0051b06 commit 82bc964
Showing 1 changed file with 48 additions and 11 deletions.
59 changes: 48 additions & 11 deletions class/actions_dolisirh.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -821,6 +835,8 @@ function getDiffTimestampEvent() {
if (preg_match('/categoryindex/', $parameters['context'])) {
print '<script src="../custom/dolisirh/js/dolisirh.js"></script>';
} 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');

Expand All @@ -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;
Expand All @@ -859,7 +896,7 @@ function getDiffTimestampEvent() {

$out .= '<table class="noborder centpercent">';
$out .= '<tr class="liste_titre"><td>';
$out .= $langs->trans("Add". ucfirst($type) . "IntoCategory") . ' ';
$out .= $langs->trans('AddObjectIntoCategory') . ' ';
$out .= $form::selectarray('element_id', $array, '', 1);
$out .= '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
$out .= '</tr>';
Expand Down

0 comments on commit 82bc964

Please sign in to comment.