Skip to content

Commit

Permalink
Merge pull request #5 from Net-Logic/dev
Browse files Browse the repository at this point in the history
add service duration
  • Loading branch information
frederic34 authored Jan 11, 2024
2 parents 97c1ed0 + 7d073b4 commit 824a4b5
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion class/actions_easytooltip.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2023 Frédéric France <frederic@francefrederic.onmicrosoft.com>
/* Copyright (C) 2023 Frédéric France <frederic.france@netlogic.fr>
*
* 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
Expand Down Expand Up @@ -100,6 +100,18 @@ public function getTooltipContent($parameters, &$object, &$action, $hookmanager)
} elseif (in_array('productdao', $contexts)) {
/** @var Product $object */
$found = true;
// ADDING DURATION IF NOT PRESENT
if ($object->type == Product::TYPE_SERVICE && empty($parameters['tooltipcontentarray']['duration']) && !empty($object->duration_value)) {
// Duration
$tooltip = '<br><b>' . $langs->trans("Duration") . ':</b> ' . $object->duration_value;
if ($object->duration_value > 1) {
$dur = ["i" => $langs->trans("Minutes"), "h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years")];
} elseif ($object->duration_value > 0) {
$dur = ["i" => $langs->trans("Minute"), "h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year")];
}
$tooltip .= (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? "&nbsp;" . $langs->trans($dur[$object->duration_unit]) : '');
self::arraySpliceAssoc($parameters['tooltipcontentarray'], 4, 0, ['duration' => $tooltip]);
}
// ADDING LAST CUSTOMER ORDER
if ($object->type == Product::TYPE_PRODUCT || ($object->type == Product::TYPE_SERVICE && getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
$sql = 'SELECT c.rowid as id, c.fk_soc, cd.qty FROM ' . MAIN_DB_PREFIX . 'commandedet as cd';
Expand Down Expand Up @@ -273,4 +285,27 @@ public function getTooltipContent($parameters, &$object, &$action, $hookmanager)

return 0;
}

/**
* arraySpliceAssoc
*
* @param mixed $input
* @param mixed $offset
* @param mixed $length
* @param mixed $replacement
* @return void
*/
private function arraySpliceAssoc(&$input, $offset, $length, $replacement)
{
$replacement = (array) $replacement;
$key_indices = array_flip(array_keys($input));
if (isset($input[$offset]) && is_string($offset)) {
$offset = $key_indices[$offset];
}
if (isset($input[$length]) && is_string($length)) {
$length = $key_indices[$length] - $offset;
}

$input = array_slice($input, 0, $offset, true) + $replacement + array_slice($input, $offset + $length, null, true);
}
}

0 comments on commit 824a4b5

Please sign in to comment.