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,21 +36,36 @@ 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"];
$result=$task->addTimeSpent($user);
if ($result >= 0)
{
$task->addTimeSpent($user);
} }
else else
{ {
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($task->error).'</div>'; $mesg='<div class="error">'.$langs->trans($task->error).'</div>';
}
}
else
{
$_POST["action"]=''; $_POST["action"]='';
} }
} }
@ -136,6 +152,7 @@ if ($_GET["id"] > 0)
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
/* /*
@ -143,6 +160,8 @@ if ($_GET["id"] > 0)
*/ */
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">';
@ -151,35 +170,39 @@ if ($_GET["id"] > 0)
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 // Date
print '<td nowrap="nowrap" width="50%">'; print '<td nowrap="nowrap">';
print '<textarea name="timespent_note" cols="80" rows="4"></textarea>'; $newdate=dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
print $html->select_date($newdate,'time','','','',"timespent_date");
print '</td>'; print '</td>';
// Contributor // Contributor
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
print '&nbsp;'; // TODO ajout liste deroulante des participants // 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>';
// Date // Note
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
print $html->select_date('','time','','','',"timespent_date"); print '<textarea name="timespent_note" cols="80" rows="'.ROWS_3.'">'.($_POST['timespent_note']?$_POST['timespent_note']:'').'</textarea>';
print '</td>'; print '</td>';
// Duration // Duration
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap" align="right">';
print '<input size="4" type="text" class="flat" name="timespent_duration" value="">'; print $html->select_duree('timespent_duration');
//print '<input size="4" type="text" class="flat" name="timespent_duration" value="">';
print '</td>'; print '</td>';
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>';
@ -226,11 +249,11 @@ if ($_GET["id"] > 0)
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)
@ -238,15 +261,15 @@ if ($_GET["id"] > 0)
$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) if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{ {
print '<textarea name="timespent_note" cols="80" rows="4">'.$task_time->note.'</textarea>'; print $html->select_date($db->jdate($task_time->task_date),'timeline','','','',"timespent_date");
} }
else else
{ {
print dol_nl2br($task_time->note); print dol_print_date($db->jdate($task_time->task_date),'day');
} }
print '</td>'; print '</td>';
@ -256,15 +279,15 @@ if ($_GET["id"] > 0)
$user->prenom = $task_time->firstname; $user->prenom = $task_time->firstname;
print '<td>'.$user->getNomUrl(1).'</td>'; print '<td>'.$user->getNomUrl(1).'</td>';
// Date // Note
print '<td>'; print '<td align="left">';
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
{ {
print $html->select_date($task_time->task_date,'timeline','','','',"timespent_date"); print '<textarea name="timespent_note" cols="80" rows="4">'.$task_time->note.'</textarea>';
} }
else else
{ {
print dol_print_date($db->jdate($task_time->task_date),'%A').' '.dol_print_date($db->jdate($task_time->task_date),'daytext'); print dol_nl2br($task_time->note);
} }
print '</td>'; print '</td>';
@ -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").'">';