Skip to content

Commit

Permalink
Merge pull request #12499 from altatof/updtask
Browse files Browse the repository at this point in the history
NEW : allow time consumed to be linked to another task
  • Loading branch information
eldy committed Jan 26, 2020
2 parents 17ceeb6 + eddc38e commit 2177116
Showing 1 changed file with 82 additions and 37 deletions.
119 changes: 82 additions & 37 deletions htdocs/projet/tasks/time.php
Expand Up @@ -4,7 +4,8 @@
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019 Christophe Battarel <christophe@altairis.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 @@ -225,34 +226,71 @@

if (!$error)
{
$object->fetch($id, $ref);
// TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))

$object->timespent_id = $_POST["lineid"];
$object->timespent_note = $_POST["timespent_note_line"];
$object->timespent_old_duration = $_POST["old_duration"];
$object->timespent_duration = $_POST["new_durationhour"] * 60 * 60; // We store duration in seconds
$object->timespent_duration += $_POST["new_durationmin"] * 60; // We store duration in seconds
if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
if ($_POST['taskid'] != $id)
{
$object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
$object->timespent_withhour = 1;
}
else
{
$object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
}
$object->timespent_fk_user = $_POST["userid_line"];
$id = $_POST['taskid'];

$result = $object->updateTimeSpent($user);
if ($result >= 0)
{
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
$object->fetchTimeSpent(GETPOST('lineid', 'int'));
// TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))
$result = $object->delTimeSpent($user);

$object->fetch($id, $ref);
$object->timespent_note = $_POST["timespent_note_line"];
$object->timespent_old_duration = $_POST["old_duration"];
$object->timespent_duration = $_POST["new_durationhour"] * 60 * 60; // We store duration in seconds
$object->timespent_duration += ($_POST["new_durationmin"] ? $_POST["new_durationmin"] : 0) * 60; // We store duration in seconds
if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
{
$object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
$object->timespent_withhour = 1;
}
else
{
$object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
}
$object->timespent_fk_user = $_POST["userid_line"];
$result = $object->addTimeSpent($user);
if ($result >= 0)
{
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
}
else
{
setEventMessages($langs->trans($object->error), null, 'errors');
$error++;
}
}
else
{
setEventMessages($langs->trans($object->error), null, 'errors');
$error++;
$object->fetch($id, $ref);
// TODO Check that ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids))

$object->timespent_id = $_POST["lineid"];
$object->timespent_note = $_POST["timespent_note_line"];
$object->timespent_old_duration = $_POST["old_duration"];
$object->timespent_duration = $_POST["new_durationhour"] * 60 * 60; // We store duration in seconds
$object->timespent_duration += $_POST["new_durationmin"] * 60; // We store duration in seconds
if (GETPOST("timelinehour") != '' && GETPOST("timelinehour") >= 0) // If hour was entered
{
$object->timespent_date = dol_mktime(GETPOST("timelinehour"), GETPOST("timelinemin"), 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
$object->timespent_withhour = 1;
}
else
{
$object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear"));
}
$object->timespent_fk_user = $_POST["userid_line"];

$result = $object->updateTimeSpent($user);
if ($result >= 0)
{
setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
}
else
{
setEventMessages($langs->trans($object->error), null, 'errors');
$error++;
}
}
}
else
Expand Down Expand Up @@ -1301,19 +1339,26 @@
}

// Task ref
if (!empty($arrayfields['t.task_ref']['checked']))
{
if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
{
print '<td class="nowrap">';
$tasktmp->id = $task_time->fk_task;
$tasktmp->ref = $task_time->ref;
$tasktmp->label = $task_time->label;
print $tasktmp->getNomUrl(1, 'withproject', 'time');
print '</td>';
if (!$i) $totalarray['nbfield']++;
}
}
if (!empty($arrayfields['t.task_ref']['checked']))
{
if ((empty($id) && empty($ref)) || !empty($projectidforalltimes)) // Not a dedicated task
{
print '<td class="nowrap">';
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
$formproject->selectTasks(-1, GETPOST('taskid', 'int')?GETPOST('taskid', 'int'):$task_time->fk_task, 'taskid', 0, 0, 1, 1, 0, 0, 'maxwidth300', $projectstatic->id, '');
}
else
{
$tasktmp->id = $task_time->fk_task;
$tasktmp->ref = $task_time->ref;
$tasktmp->label = $task_time->label;
print $tasktmp->getNomUrl(1, 'withproject', 'time');
}
print '</td>';
if (!$i) $totalarray['nbfield']++;
}
}

// Task label
if (!empty($arrayfields['t.task_label']['checked']))
Expand Down

0 comments on commit 2177116

Please sign in to comment.