WIP Work on split of timespent

This commit is contained in:
ldestailleur 2019-01-04 16:24:56 +01:00
parent b928a49b1b
commit 5094b6bcfc

View File

@ -191,7 +191,7 @@ if ($action == 'addtimespent' && $user->rights->projet->lire)
}
}
if ($action == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->lire)
if (($action == 'updateline' || $action == 'updatesplitline') && ! $_POST["cancel"] && $user->rights->projet->lire)
{
$error=0;
@ -318,6 +318,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
}
$userWrite = $projectstatic->restrictedProjectArea($user,'write');
$linktocreatetime = '';
if ($projectstatic->id > 0)
{
@ -425,6 +426,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
dol_fiche_end();
print '<br>';
}
// Link to create time
//if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes))
@ -436,12 +438,12 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
if (! empty($projectidforalltimes)) // We are on tab 'Time Spent' of project
{
$backtourl = $_SERVER['PHP_SELF'].'?projectid='.$projectstatic->id.($withproject?'&withproject=1':'');
$linktocreatetime = '<a class="butActionNew" href="'.$_SERVER['PHP_SELF'].'?withproject=1&projectid='.$projectstatic->id.'&action=createtime'.$param.'&backtopage='.urlencode($backtourl).'">'.$langs->trans('AddTimeSpent').'<span class="fa fa-plus-circle valignmiddle"></span></a>';
$linktocreatetime = '<a class="butActionNew" href="'.$_SERVER['PHP_SELF'].'?'.($withproject?'withproject=1':'').'&projectid='.$projectstatic->id.'&action=createtime'.$param.'&backtopage='.urlencode($backtourl).'">'.$langs->trans('AddTimeSpent').'<span class="fa fa-plus-circle valignmiddle"></span></a>';
}
else // We are on tab 'Time Spent' of task
{
$backtourl = $_SERVER['PHP_SELF'].'?id='.$object->id.($withproject?'&withproject=1':'');
$linktocreatetime = '<a class="butActionNew" href="'.$_SERVER['PHP_SELF'].'?withproject=1'.($object->id > 0 ? '&id='.$object->id : '&projectid='.$projectstatic->id).'&action=createtime'.$param.'&backtopage='.urlencode($backtourl).'">'.$langs->trans('AddTimeSpent').'<span class="fa fa-plus-circle valignmiddle"></span></a>';
$linktocreatetime = '<a class="butActionNew" href="'.$_SERVER['PHP_SELF'].'?'.($withproject?'withproject=1':'').($object->id > 0 ? '&id='.$object->id : '&projectid='.$projectstatic->id).'&action=createtime'.$param.'&backtopage='.urlencode($backtourl).'">'.$langs->trans('AddTimeSpent').'<span class="fa fa-plus-circle valignmiddle"></span></a>';
}
}
else
@ -454,7 +456,6 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
$linktocreatetime = '<a class="butActionNewRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTime').'<span class="fa fa-plus-circle valignmiddle"></span></a>';
}
//}
}
}
if (empty($projectidforalltimes))
@ -859,6 +860,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
if ($action == 'editline') print '<input type="hidden" name="action" value="updateline">';
elseif ($action == 'splitline') print '<input type="hidden" name="action" value="updatesplitline">';
else print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
@ -972,7 +974,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
if (! empty($arrayfields['t.task_date']['checked']))
{
print '<td class="nowrap">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($task_time->task_date_withhour))
{
@ -1019,7 +1021,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
if (! empty($arrayfields['author']['checked']))
{
print '<td>';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($object->id)) $object->fetch($id);
$contactsoftask=$object->getListContactId('internal');
@ -1050,7 +1052,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
if (! empty($arrayfields['t.note']['checked']))
{
print '<td align="left">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
}
@ -1061,12 +1063,16 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
print '</td>';
if (! $i) $totalarray['nbfield']++;
}
elseif ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
}
// Time spent
if (! empty($arrayfields['t.task_duration']['checked']))
{
print '<td align="right">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
print $form->select_duration('new_duration',$task_time->task_duration,0,'text');
@ -1117,7 +1123,7 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
// Action column
print '<td class="center nowraponall">';
if ($action == 'editline' && $_GET['lineid'] == $task_time->rowid)
if (($action == 'editline' || $action == 'splitline') && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
@ -1128,8 +1134,15 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
{
if ($task_time->fk_user == $user->id || in_array($task_time->fk_user, $childids) || $user->rights->projet->all->creer)
{
//$param = ($projectidforalltimes?'projectid='.$projectidforalltimes.'&amp;':'').'.($withproject?'&amp;withproject=1':'');
print '&nbsp;';
if ($conf->MAIN_FEATURES_LEVEL >= 2)
{
print '&nbsp;';
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&amp;action=splitline&amp;lineid='.$task_time->rowid.$param.'">';
print img_split();
print '</a>';
}
print '&nbsp;';
print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$task_time->fk_task.'&amp;action=editline&amp;lineid='.$task_time->rowid.$param.'">';
print img_edit();
print '</a>';
@ -1145,6 +1158,304 @@ if (($id > 0 || ! empty($ref)) || $projectidforalltimes > 0)
print "</tr>\n";
// Add line to split
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<tr class="oddeven">';
// Date
if (! empty($arrayfields['t.task_date']['checked']))
{
print '<td class="nowrap">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($task_time->task_date_withhour))
{
print $form->selectDate(($date2?$date2:$date1), 'timeline', 3, 3, 2, "timespent_date", 1, 0);
}
else print $form->selectDate(($date2?$date2:$date1), 'timeline', 1, 1, 2, "timespent_date", 1, 0);
}
else
{
print dol_print_date(($date2?$date2:$date1),($task_time->task_date_withhour?'dayhour':'day'));
}
print '</td>';
}
// 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>';
}
}
// Task label
if (! empty($arrayfields['t.task_label']['checked']))
{
if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
{
print '<td class="nowrap">';
print $task_time->label;
print '</td>';
}
}
// User
if (! empty($arrayfields['author']['checked']))
{
print '<td>';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($object->id)) $object->fetch($id);
$contactsoftask=$object->getListContactId('internal');
if (!in_array($task_time->fk_user,$contactsoftask)) {
$contactsoftask[]=$task_time->fk_user;
}
if (count($contactsoftask)>0) {
print img_object('','user','class="hideonsmartphone"');
print $form->select_dolusers($task_time->fk_user,'userid_line',0,'',0,'',$contactsoftask);
}else {
print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
}
}
else
{
$userstatic->id = $task_time->fk_user;
$userstatic->lastname = $task_time->lastname;
$userstatic->firstname = $task_time->firstname;
$userstatic->photo = $task_time->photo;
$userstatic->statut = $task_time->user_status;
print $userstatic->getNomUrl(-1);
}
print '</td>';
}
// Note
if (! empty($arrayfields['t.note']['checked']))
{
print '<td align="left">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<textarea name="timespent_note_line" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
}
else
{
print dol_nl2br($task_time->note);
}
print '</td>';
}
elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="timespent_note_line" value="'.$task_time->note.'">';
}
// Time spent
if (! empty($arrayfields['t.task_duration']['checked']))
{
print '<td align="right">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
print $form->select_duration('new_duration',$task_time->task_duration,0,'text');
}
else
{
print convertSecondToTime($task_time->task_duration,'allhourmin');
}
print '</td>';
}
// Value spent
if (! empty($arrayfields['value']['checked']))
{
print '<td align="right">';
$value = price2num($task_time->thm * $task_time->task_duration / 3600);
print price($value, 1, $langs, 1, -1, -1, $conf->currency);
print '</td>';
}
// Value billed
if (! empty($arrayfields['valuebilled']['checked']))
{
print '<td align="right">';
$valuebilled = price2num($task_time->total_ht);
if (isset($task_time->total_ht)) print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
print '</td>';
}
/*
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
*/
// Fields from hook
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Action column
print '<td class="center nowraponall">';
print '</td>';
print "</tr>\n";
// Line for second dispatching
print '<tr class="oddeven">';
// Date
if (! empty($arrayfields['t.task_date']['checked']))
{
print '<td class="nowrap">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($task_time->task_date_withhour))
{
print $form->selectDate(($date2?$date2:$date1), 'timeline_2', 3, 3, 2, "timespent_date", 1, 0);
}
else print $form->selectDate(($date2?$date2:$date1), 'timeline_2', 1, 1, 2, "timespent_date", 1, 0);
}
else
{
print dol_print_date(($date2?$date2:$date1),($task_time->task_date_withhour?'dayhour':'day'));
}
print '</td>';
}
// 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>';
}
}
// Task label
if (! empty($arrayfields['t.task_label']['checked']))
{
if ((empty($id) && empty($ref)) || ! empty($projectidforalltimes)) // Not a dedicated task
{
print '<td class="nowrap">';
print $task_time->label;
print '</td>';
}
}
// User
if (! empty($arrayfields['author']['checked']))
{
print '<td>';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
if (empty($object->id)) $object->fetch($id);
$contactsoftask=$object->getListContactId('internal');
if (!in_array($task_time->fk_user,$contactsoftask)) {
$contactsoftask[]=$task_time->fk_user;
}
if (count($contactsoftask)>0) {
print img_object('','user','class="hideonsmartphone"');
print $form->select_dolusers($task_time->fk_user,'userid_line_2',0,'',0,'',$contactsoftask);
}else {
print img_error($langs->trans('FirstAddRessourceToAllocateTime')).$langs->trans('FirstAddRessourceToAllocateTime');
}
}
else
{
$userstatic->id = $task_time->fk_user;
$userstatic->lastname = $task_time->lastname;
$userstatic->firstname = $task_time->firstname;
$userstatic->photo = $task_time->photo;
$userstatic->statut = $task_time->user_status;
print $userstatic->getNomUrl(-1);
}
print '</td>';
}
// Note
if (! empty($arrayfields['t.note']['checked']))
{
print '<td align="left">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<textarea name="timespent_note_line_2" width="95%" rows="'.ROWS_2.'">'.$task_time->note.'</textarea>';
}
else
{
print dol_nl2br($task_time->note);
}
print '</td>';
}
elseif ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="timespent_note_line_2" value="'.$task_time->note.'">';
}
// Time spent
if (! empty($arrayfields['t.task_duration']['checked']))
{
print '<td align="right">';
if ($action == 'splitline' && $_GET['lineid'] == $task_time->rowid)
{
print '<input type="hidden" name="old_duration_2" value="0">';
print $form->select_duration('new_duration_2',0,0,'text');
}
else
{
print convertSecondToTime($task_time->task_duration,'allhourmin');
}
print '</td>';
}
// Value spent
if (! empty($arrayfields['value']['checked']))
{
print '<td align="right">';
$value = 0;
print price($value, 1, $langs, 1, -1, -1, $conf->currency);
print '</td>';
}
// Value billed
if (! empty($arrayfields['valuebilled']['checked']))
{
print '<td align="right">';
$valuebilled = price2num($task_time->total_ht);
if (isset($task_time->total_ht)) print price($valuebilled, 1, $langs, 1, -1, -1, $conf->currency);
print '</td>';
}
/*
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
*/
// Fields from hook
$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$task_time);
$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
// Action column
print '<td class="center nowraponall">';
print '</td>';
print "</tr>\n";
}
$i++;
}