We store duration of time spent in seconds as this is a more "universal" format.

Fix some bugs.
This commit is contained in:
Laurent Destailleur 2010-02-28 01:33:12 +00:00
parent 0686579e30
commit 677b831b24
5 changed files with 115 additions and 99 deletions

View File

@ -389,11 +389,11 @@ function PLineSelect(&$inc, $parent, $lines, $level=0, $selected=0)
print $langs->trans("Project").' '.$lines[$i]->projectref; print $langs->trans("Project").' '.$lines[$i]->projectref;
if (empty($lines[$i]->public)) if (empty($lines[$i]->public))
{ {
print ' ('.$langs->trans("PrivateProject").')'; print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
} }
else else
{ {
print ' ('.$langs->trans("SharedProject").')'; print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
} }
if ($lines[$i]->id) print ' > '; if ($lines[$i]->id) print ' > ';
for ($k = 0 ; $k < $level ; $k++) for ($k = 0 ; $k < $level ; $k++)

View File

@ -101,16 +101,16 @@ function task_prepare_head($object)
$head[$h][2] = 'task'; $head[$h][2] = 'task';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id;
$head[$h][1] = $langs->trans("TimeSpent");
$head[$h][2] = 'time';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id;
$head[$h][1] = $langs->trans("Affectations"); $head[$h][1] = $langs->trans("Affectations");
$head[$h][2] = 'contact'; $head[$h][2] = 'contact';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id;
$head[$h][1] = $langs->trans("TimeSpent");
$head[$h][2] = 'time';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id; $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id;
$head[$h][1] = $langs->trans('Notes'); $head[$h][1] = $langs->trans('Notes');
$head[$h][2] = 'note'; $head[$h][2] = 'note';
@ -478,8 +478,8 @@ function clean_orphelins($db)
// There is orphelins. We clean that // There is orphelins. We clean that
$listofid=array(); $listofid=array();
// Get list of id in array listofid
$sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task'; $sql='SELECT rowid FROM '.MAIN_DB_PREFIX.'projet_task';
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
@ -500,7 +500,8 @@ function clean_orphelins($db)
if (sizeof($listofid)) if (sizeof($listofid))
{ {
// Removed orphelins records // Removed orphelins records
print 'Some orphelins were found and restored to be parents so records are visible again.'; print 'Some orphelins were found and restored to be parents so records are visible again: ';
print join(',',$listofid);
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET fk_task_parent = 0"; $sql.= " SET fk_task_parent = 0";

View File

@ -289,7 +289,7 @@ else
print '</div>'; print '</div>';
// Test if database is clean. If not we clean it. // Test if database is clean. If not we clean it.
//print '$nboftaskshown='.$nboftaskshown.' sizeof($tasksarray)='.sizeof($tasksarray).' sizeof($tasksrole)='.sizeof($tasksrole).'<br>'; //print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' sizeof($tasksarray)='.sizeof($tasksarray).' sizeof($tasksrole)='.sizeof($tasksrole).'<br>';
if ($_REQUEST["mode"]=='mine') if ($_REQUEST["mode"]=='mine')
{ {
if ($nboftaskshown < sizeof($tasksrole)) clean_orphelins($db); if ($nboftaskshown < sizeof($tasksrole)) clean_orphelins($db);

View File

@ -595,7 +595,7 @@ class Task extends CommonObject
*/ */
function addTimeSpent($user, $notrigger=0) function addTimeSpent($user, $notrigger=0)
{ {
$result = 0; $ret = 0;
// Clean parameters // Clean parameters
$this->timespent_duration = intval($this->timespent_duration)+(($this->timespent_duration-intval($this->timespent_duration))*(1+2/3)); $this->timespent_duration = intval($this->timespent_duration)+(($this->timespent_duration-intval($this->timespent_duration))*(1+2/3));
@ -612,15 +612,15 @@ class Task extends CommonObject
$sql.= $this->id; $sql.= $this->id;
$sql.= ", '".$this->db->idate($this->timespent_date)."'"; $sql.= ", '".$this->db->idate($this->timespent_date)."'";
$sql.= ", ".$this->timespent_duration; $sql.= ", ".$this->timespent_duration;
$sql.= ", ".$user->id; $sql.= ", ".$this->timespent_fk_user;
$sql.= ", ".(isset($this->timespent_note)?"'".addslashes($this->timespent_note)."'":"null"); $sql.= ", ".(isset($this->timespent_note)?"'".addslashes($this->timespent_note)."'":"null");
$sql.= ")"; $sql.= ")";
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task"); $task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_time");
$result = 0; $ret = $task_id;
if (! $notrigger) if (! $notrigger)
{ {
@ -635,30 +635,26 @@ class Task extends CommonObject
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error,LOG_ERR); dol_syslog(get_class($this)."::addTimeSpent error -1 ".$this->error,LOG_ERR);
$result = -2; $ret = -1;
} }
if ($result == 0) if ($ret >= 0)
{ {
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'"; $sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'";
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG); dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) ) if (! $this->db->query($sql) )
{
$result = 0;
}
else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::addTimeSpent error -3 ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR);
$result = -2; $ret = -2;
} }
} }
return $result; return $ret;
} }
/** /**

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2010 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -19,14 +19,15 @@
*/ */
/** /**
* \file htdocs/projet/tasks/task.php * \file htdocs/projet/tasks/time.php
* \ingroup projet * \ingroup projet
* \brief Fiche taches d'un projet * \brief Page to add new time spent on a task
* \version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
if (!$user->rights->projet->lire) accessforbidden(); if (!$user->rights->projet->lire) accessforbidden();
@ -35,28 +36,43 @@ if (!$user->rights->projet->lire) accessforbidden();
*/ */
if ($_POST["action"] == 'addtimespent' && $user->rights->projet->creer) if ($_POST["action"] == 'addtimespent' && $user->rights->projet->creer)
{ {
if ($_POST["timespent_note"] && $_POST["timespent_duration"]) $error=0;
if (empty($_POST["timespent_durationhour"]) && empty($_POST["timespent_durationmin"]))
{
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'</div>';
$error++;
}
if (! $error)
{ {
$task = new Task($db); $task = new Task($db);
$task->fetch($_POST["id"]); $task->fetch($_POST["id"]);
$task->timespent_note = $_POST["timespent_note"]; $task->timespent_note = $_POST["timespent_note"];
$task->timespent_duration = $_POST["timespent_duration"]; $task->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds
$task->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]); $task->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
$task->timespent_fk_user = $_POST["userid"];
$task->addTimeSpent($user);
$result=$task->addTimeSpent($user);
if ($result >= 0)
{
}
else
{
$mesg='<div class="error">'.$langs->trans($task->error).'</div>';
}
} }
else else
{ {
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($task->error).'</div>';
$_POST["action"]=''; $_POST["action"]='';
} }
} }
if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->creer) if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->creer)
{ {
} }
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer) if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer)
@ -96,7 +112,7 @@ if ($_GET["id"] > 0)
{ {
$result=$projectstatic->fetch($task->fk_project); $result=$projectstatic->fetch($task->fk_project);
if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid); if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
// To verify role of users // To verify role of users
$userAccess = $projectstatic->restrictedProjectArea($user); $userAccess = $projectstatic->restrictedProjectArea($user);
@ -105,7 +121,7 @@ if ($_GET["id"] > 0)
dol_fiche_head($head, 'time', $langs->trans("Task"),0,'projecttask'); dol_fiche_head($head, 'time', $langs->trans("Task"),0,'projecttask');
if ($mesg) print $mesg.'<br>'; if ($mesg) print $mesg.'<br>';
if ($_GET["action"] == 'deleteline') if ($_GET["action"] == 'deleteline')
{ {
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"].'&lineid='.$_GET["lineid"],$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1); $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"].'&lineid='.$_GET["lineid"],$langs->trans("DeleteATimeSpent"),$langs->trans("ConfirmDeleteATimeSpent"),"confirm_delete",'','',1);
@ -136,58 +152,65 @@ if ($_GET["id"] > 0)
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
/* /*
* Add time spent * Add time spent
*/ */
if ($user->rights->projet->creer && $userAccess) if ($user->rights->projet->creer && $userAccess)
{ {
print '<br>';
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addtimespent">'; print '<input type="hidden" name="action" value="addtimespent">';
print '<input type="hidden" name="id" value="'.$task->id.'">'; print '<input type="hidden" name="id" value="'.$task->id.'">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="50%">'.$langs->trans("Note").'</td>'; print '<td width="100">'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("By").'</td>'; print '<td>'.$langs->trans("By").'</td>';
print '<td>'.$langs->trans("Date").'</td>'; print '<td>'.$langs->trans("Note").'</td>';
print '<td colspan="2">'.$langs->trans("Duration").'</td>'; print '<td align="right">'.$langs->trans("Duration").'</td>';
print '<td width="80">&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
print '<tr>'; print '<tr '.$bc[false].'>';
// Note
print '<td nowrap="nowrap" width="50%">';
print '<textarea name="timespent_note" cols="80" rows="4"></textarea>';
print '</td>';
// Contributor
print '<td nowrap="nowrap">';
print '&nbsp;'; // TODO ajout liste deroulante des participants
print '</td>';
// Date // Date
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
print $html->select_date('','time','','','',"timespent_date"); $newdate=dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
print $html->select_date($newdate,'time','','','',"timespent_date");
print '</td>'; print '</td>';
// Duration // Contributor
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
print '<input size="4" type="text" class="flat" name="timespent_duration" value="">'; // TODO We should use here a combo list with contacts affected to task only
print $html->select_users($_POST["userid"]?$_POST["userid"]:$user->id,'userid');
print '</td>'; print '</td>';
print '<td>'; // Note
print '<td nowrap="nowrap">';
print '<textarea name="timespent_note" cols="80" rows="'.ROWS_3.'">'.($_POST['timespent_note']?$_POST['timespent_note']:'').'</textarea>';
print '</td>';
// Duration
print '<td nowrap="nowrap" align="right">';
print $html->select_duree('timespent_duration');
//print '<input size="4" type="text" class="flat" name="timespent_duration" value="">';
print '</td>';
print '<td align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">'; print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
print '</td></tr>'; print '</td></tr>';
print '</table></form>'; print '</table></form>';
} }
print '<br>'; print '<br>';
/* /*
* List of time spent * List of time spent
*/ */
@ -218,28 +241,46 @@ if ($_GET["id"] > 0)
{ {
dol_print_error($db); dol_print_error($db);
} }
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">'; print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="updateline">'; print '<input type="hidden" name="action" value="updateline">';
print '<input type="hidden" name="id" value="'.$task->id.'">'; print '<input type="hidden" name="id" value="'.$task->id.'">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td width="50%">'.$langs->trans("Note").'</td>'; print '<td width="100">'.$langs->trans("Date").'</td>';
print '<td>'.$langs->trans("By").'</td>'; print '<td>'.$langs->trans("By").'</td>';
print '<td>'.$langs->trans("Date").'</td>'; print '<td align="left">'.$langs->trans("Note").'</td>';
print '<td align="right">'.$langs->trans("Duration").'</td>'; print '<td align="right">'.$langs->trans("Duration").'</td>';
print '<td colspan="2">&nbsp;</td>'; print '<td>&nbsp;</td>';
print "</tr>\n"; print "</tr>\n";
foreach ($tasks as $task_time) foreach ($tasks as $task_time)
{ {
$var=!$var; $var=!$var;
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
// Note // Date
print '<td width="50%">'; print '<td>';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
print $html->select_date($db->jdate($task_time->task_date),'timeline','','','',"timespent_date");
}
else
{
print dol_print_date($db->jdate($task_time->task_date),'day');
}
print '</td>';
// User
$user->id = $task_time->fk_user;
$user->nom = $task_time->name;
$user->prenom = $task_time->firstname;
print '<td>'.$user->getNomUrl(1).'</td>';
// Note
print '<td align="left">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{ {
print '<textarea name="timespent_note" cols="80" rows="4">'.$task_time->note.'</textarea>'; print '<textarea name="timespent_note" cols="80" rows="4">'.$task_time->note.'</textarea>';
@ -249,25 +290,7 @@ if ($_GET["id"] > 0)
print dol_nl2br($task_time->note); print dol_nl2br($task_time->note);
} }
print '</td>'; print '</td>';
// User
$user->id = $task_time->fk_user;
$user->nom = $task_time->name;
$user->prenom = $task_time->firstname;
print '<td>'.$user->getNomUrl(1).'</td>';
// Date
print '<td>';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{
print $html->select_date($task_time->task_date,'timeline','','','',"timespent_date");
}
else
{
print dol_print_date($db->jdate($task_time->task_date),'%A').' '.dol_print_date($db->jdate($task_time->task_date),'daytext');
}
print '</td>';
// Time spent // Time spent
print '<td align="right">'; print '<td align="right">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
@ -276,16 +299,12 @@ if ($_GET["id"] > 0)
} }
else else
{ {
// TODO add function print ConvertSecondToTime($task_time->task_duration,'all');
$hour = intval($task_time->task_duration);
$minutes = round((($task_time->task_duration - $hour) * 60),0);
$minutes = substr("00"."$minutes", -2);
print $hour."&nbsp;h&nbsp;".$minutes;
} }
print '</td>'; print '</td>';
// Edit and delete icon // Edit and delete icon
print '<td align="center" valign="middle">'; print '<td align="center" valign="middle" width="80">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{ {
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">'; print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
@ -298,14 +317,14 @@ if ($_GET["id"] > 0)
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=editline&amp;lineid='.$task_time->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=editline&amp;lineid='.$task_time->rowid.'">';
print img_edit(); print img_edit();
print '</a>'; print '</a>';
print '&nbsp;'; print '&nbsp;';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=deleteline&amp;lineid='.$task_time->rowid.'">'; print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=deleteline&amp;lineid='.$task_time->rowid.'">';
print img_delete(); print img_delete();
print '</a>'; print '</a>';
} }
print '</td>'; print '</td>';
print "</tr>\n"; print "</tr>\n";
} }