Skip to content

Commit

Permalink
Better detail for time elapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jul 16, 2018
1 parent 89cc048 commit d3cc2c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
12 changes: 12 additions & 0 deletions htdocs/core/lib/functions.lib.php
Expand Up @@ -7637,3 +7637,15 @@ function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal
if (! $menuentry['perms']) return 2; // No permissions and user is external
return 1;
}

/**
* Round to next multiple.
*
* @param double $n Number to round up
* @param integer $x Multiple. For example 60 to round up to nearest exact minute for a date with seconds.
* @return integer Value rounded.
*/
function roundUpToNextMultiple($n, $x=5)
{
return (ceil($n)%$x === 0) ? ceil($n) : round(($n+$x/2)/$x)*$x;
}
3 changes: 2 additions & 1 deletion htdocs/langs/en_US/ticket.lang
Expand Up @@ -198,7 +198,8 @@ TicketMessageMailSignatureLabelAdmin=Signature of response email
TicketMessageMailSignatureHelpAdmin=This text will be inserted after the response message.
TicketMessageHelp=Only this text will be saved in the message list on ticket card.
TicketMessageSubstitutionReplacedByGenericValues=Substitutions variables are replaced by generic values.
TicketTimeToRead=Time elapsed before ticket read
TimeElapsedSince=Time elapsed since
TicketTimeToRead=Time elapsed before read
TicketContacts=Contacts ticket
TicketDocumentsLinked=Documents linked to ticket
ConfirmReOpenTicket=Confirm reopen this ticket ?
Expand Down
60 changes: 31 additions & 29 deletions htdocs/ticket/card.php
Expand Up @@ -82,6 +82,8 @@

$actionobject = new ActionsTicket($db);

$now = dol_now();


/*
* Actions
Expand Down Expand Up @@ -364,26 +366,23 @@
// Creation date
print '<tr><td>' . $langs->trans("DateCreation") . '</td><td>';
print dol_print_date($object->datec, 'dayhour');
print ' - '.$langs->trans("TimeElapsedSince").': '.'<i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->datec, 60)).'</i>';
print '</td></tr>';

// Read date
print '<tr><td>' . $langs->trans("TicketReadOn") . '</td><td>';
if (!empty($object->date_read)) {
print '<tr><td>' . $langs->trans("TicketReadOn") . '</td><td>';
print dol_print_date($object->date_read, 'dayhour');
print '</td></tr>';

print '<tr><td>' . $langs->trans("TicketTimeToRead") . '</td><td>';
print '<strong>' . convertSecondToTime($object->date_read - $object->datec) . '</strong>';
print '</td></tr>';
print dol_print_date($object->date_read, 'dayhour');
print ' - '.$langs->trans("TicketTimeToRead").': <i>'.convertSecondToTime(roundUpToNextMultiple($object->date_read - $object->datec, 60)).'</i>';
print ' - '.$langs->trans("TimeElapsedSince").': '.'<i>'.convertSecondToTime(roundUpToNextMultiple($now - $object->date_read, 60)).'</i>';
}
print '</td></tr>';

// Close date
print '<tr><td>' . $langs->trans("TicketCloseOn") . '</td><td>';
if (!empty($object->date_close)) {
print '<tr><td>' . $langs->trans("TicketCloseOn") . '</td><td>';
print dol_print_date($object->date_close, 'dayhour');
print '</td></tr>';
print dol_print_date($object->date_close, 'dayhour');
}

print '</td></tr>';

// Thirdparty
Expand Down Expand Up @@ -453,25 +452,28 @@
print '</td>';
print '</tr>';

// Timing (Duration sum of linked fichinter
$object->fetchObjectLinked();
$num = count($object->linkedObjects);
$timing = 0;
if ($num) {
foreach ($object->linkedObjects as $objecttype => $objects) {
if ($objecttype = "fichinter") {
foreach ($objects as $fichinter) {
$timing += $fichinter->duration;
}
}
}
}
print '<tr><td valign="top">';
// Timing (Duration sum of linked fichinter)
if ($conf->fichinter->enabled)
{
$object->fetchObjectLinked();
$num = count($object->linkedObjects);
$timing = 0;
if ($num) {
foreach ($object->linkedObjects as $objecttype => $objects) {
if ($objecttype = "fichinter") {
foreach ($objects as $fichinter) {
$timing += $fichinter->duration;
}
}
}
}
print '<tr><td valign="top">';

print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
print '</td><td>';
print convertSecondToTime($timing, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
print '</td></tr>';
print $form->textwithpicto($langs->trans("TicketDurationAuto"), $langs->trans("TicketDurationAutoInfos"), 1);
print '</td><td>';
print convertSecondToTime($timing, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY);
print '</td></tr>';
}

// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
Expand Down

0 comments on commit d3cc2c8

Please sign in to comment.