From 2b479aa0b42b28e9921e0510f65e38ecf7c7ceef Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 12 Oct 2014 01:04:34 +0200
Subject: [PATCH] Qual: Uniformize translated label of progress on all pages.
 Fix: Color of first line of documents. Fix: The calculated progress was not
 calculated.

---
 htdocs/core/class/html.form.class.php     |  4 +-
 htdocs/core/class/html.formfile.class.php |  4 +-
 htdocs/core/lib/project.lib.php           | 12 +++---
 htdocs/langs/en_US/main.lang              |  1 +
 htdocs/projet/activity/list.php           |  2 +-
 htdocs/projet/class/task.class.php        | 48 +++++++++++++++++++--
 htdocs/projet/tasks.php                   |  2 +-
 htdocs/projet/tasks/task.php              | 20 ++++++---
 htdocs/projet/tasks/time.php              | 52 +++++++++++++++++------
 9 files changed, 112 insertions(+), 33 deletions(-)

diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 51b9c5eff46..d4effca3905 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3987,7 +3987,7 @@ class Form
         {
         	print '<input type="text" size="3" name="'.$prefix.'hour"'.($disabled?' disabled="disabled"':'').' class="flat" value="'.((int) $hourSelected).'">';
         }
-        print $langs->trans('Hours');
+        print ' '.$langs->trans('HourShort');
 
         if ($minunderhours) print '<br>';
         else print "&nbsp;";
@@ -4000,7 +4000,7 @@ class Form
             print '>'.$min.'</option>';
         }
         print "</select>";
-        print $langs->trans('Minutes'). "&nbsp;";
+        print ' '.$langs->trans('MinuteShort'). "&nbsp;";
     }
 
 
diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index e473fdc3d98..8c53356fa67 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -629,7 +629,7 @@ class FormFile
 
 			 	if (count($file_list) == 0 && $headershown)
 	            {
-    	        	$out.='<tr><td colspan="3">'.$langs->trans("None").'</td></tr>';
+    	        	$out.='<tr '.$bc[0].'><td colspan="3">'.$langs->trans("None").'</td></tr>';
         	    }
 
                 $this->numoffiles++;
@@ -1150,7 +1150,7 @@ class FormFile
         $nboflinks = count($links);
         if ($nboflinks > 0) include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
 
-        $var = true;
+        $var = false;
         foreach ($links as $link)
         {
             $var =! $var;
diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php
index d8ecc52f6d9..98a2b111c6f 100644
--- a/htdocs/core/lib/project.lib.php
+++ b/htdocs/core/lib/project.lib.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2006-2013 Laurent Destailleur  <eldy@users.sourceforge.net>
+/* Copyright (C) 2006-2014 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2010      Regis Houssin        <regis.houssin@capnetworks.com>
  * Copyright (C) 2011      Juanjo Menent        <jmenent@2byte.es>
  *
@@ -455,12 +455,14 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
  */
 function projectLinesb(&$inc, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask=0)
 {
-	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
-
 	global $db, $user, $bc, $langs;
-	global $form, $projectstatic, $taskstatic;
+	global $form, $formother, $projectstatic, $taskstatic;
 
-	$formother = new FormOther($db);
+	if (! is_object($formother)) 
+	{
+		require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
+		$formother = new FormOther($db);
+	}
 
 	$lastprojectid=0;
 
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 1256dd533e3..7663f520667 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -266,6 +266,7 @@ Afternoon=Afternoon
 Quadri=Quadri
 MonthOfDay=Month of the day
 HourShort=H
+MinuteShort=mn
 Rate=Rate
 UseLocalTax=Include tax
 Bytes=Bytes
diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php
index e83fe30e865..0c2cebc2e27 100644
--- a/htdocs/projet/activity/list.php
+++ b/htdocs/projet/activity/list.php
@@ -179,7 +179,7 @@ print '<td>'.$langs->trans("LabelTask").'</td>';
 print '<td align="center">'.$langs->trans("DateStart").'</td>';
 print '<td align="center">'.$langs->trans("DateEnd").'</td>';
 print '<td align="right">'.$langs->trans("PlannedWorkload").'</td>';
-print '<td align="right">'.$langs->trans("Progress").'</td>';
+print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
 print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
 print '<td colspan="2">'.$langs->trans("AddDuration").'</td>';
 print "</tr>\n";
diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php
index ad3736d3abe..2449d638405 100644
--- a/htdocs/projet/class/task.class.php
+++ b/htdocs/projet/class/task.class.php
@@ -1,5 +1,5 @@
 <?php
-/* Copyright (C) 2008-2012	Laurent Destailleur	<eldy@users.sourceforge.net>
+/* Copyright (C) 2008-2014	Laurent Destailleur	<eldy@users.sourceforge.net>
  * Copyright (C) 2010-2012	Regis Houssin		<regis.houssin@capnetworks.com>
  * Copyright (C) 2014       Marcos GarcĂ­a       <marcosgdf@gmail.com>
  *
@@ -141,8 +141,9 @@ class Task extends CommonObject
             }
         }
 
-        //Update extrafield
-        if (!$error) {
+        // Update extrafield
+        if (! $error) 
+        {
         	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
         	{
         		$result=$this->insertExtraFields();
@@ -816,6 +817,47 @@ class Task extends CommonObject
         return $ret;
     }
 
+    /**
+     *  Calculate total of time spent for task
+     *
+     *  @param	int		$id 		Id of object (here task)
+     *  @return array		        Array of info for task array('min_date', 'max_date', 'total_duration')
+     */
+    function getSummaryOfTimeSpent($id='')
+    {
+        global $langs;
+
+        if (empty($id)) $id=$this->id;
+        
+        $result=array();
+        
+        $sql = "SELECT";
+        $sql.= " MIN(t.task_datehour) as min_date,";
+        $sql.= " MAX(t.task_datehour) as max_date,";
+        $sql.= " SUM(t.task_duration) as total_duration";
+        $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
+        $sql.= " WHERE t.fk_task = ".$id;
+
+        dol_syslog(get_class($this)."::getSummaryOfTimeSpent", LOG_DEBUG);
+        $resql=$this->db->query($sql);
+        if ($resql)
+        {
+            $obj = $this->db->fetch_object($resql);
+
+            $result['min_date'] = $obj->min_date;
+            $result['max_date'] = $obj->max_date;
+            $result['total_duration'] = $obj->total_duration;
+
+            $this->db->free($resql);
+            return $result;
+        }
+        else
+        {
+            dol_print_error($this->db);
+            return $result;
+        }
+    }
+
     /**
      *  Load object in memory from database
      *
diff --git a/htdocs/projet/tasks.php b/htdocs/projet/tasks.php
index 7aea9314e5a..eaec5ae0816 100644
--- a/htdocs/projet/tasks.php
+++ b/htdocs/projet/tasks.php
@@ -320,7 +320,7 @@ if ($action == 'create' && $user->rights->projet->creer && (empty($object->third
 	print '</td></tr>';
 
 	// Progress
-	print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
+	print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
 	print $formother->select_percent($progress,'progress');
 	print '</td></tr>';
 
diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php
index da200d565b6..ac6c72ec44c 100644
--- a/htdocs/projet/tasks/task.php
+++ b/htdocs/projet/tasks/task.php
@@ -351,8 +351,8 @@ if ($id > 0 || ! empty($ref))
 			print $form->select_duration('planned_workload',$object->planned_workload,0,'text');
 			print '</td></tr>';
 
-			// Progress
-			print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
+			// Progress declared
+			print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
 			print $formother->select_percent($object->progress,'progress');
 			print '</td></tr>';
 
@@ -383,7 +383,7 @@ if ($id > 0 || ! empty($ref))
 		{
 			/*
 			 * Fiche tache en mode visu
-			*/
+			 */
 			$param=($withproject?'&withproject=1':'');
 			$linkback=$withproject?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>':'';
 
@@ -440,14 +440,20 @@ if ($id > 0 || ! empty($ref))
 			print convertSecondToTime($object->planned_workload,'allhourmin');
 			print '</td></tr>';
 
-			// Progress
+			// Progress declared
 			print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
 			print $object->progress.' %';
 			print '</td></tr>';
 
-			// Progress
+			// Progress calculated
 			print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td colspan="3">';
-			print $object->progress.' %';
+			if ($object->planned_workload)
+			{
+				$tmparray=$object->getSummaryOfTimeSpent();
+				if ($tmparray['total_duration'] > 0) print round($tmparray['total_duration']/$object->planned_workload*100, 2).' %';
+				else print '0 %';
+			}
+			else print '';
 			print '</td></tr>';
 
 			// Description
@@ -504,7 +510,7 @@ if ($id > 0 || ! empty($ref))
 
 			/*
 			 * Documents generes
-			*/
+			 */
 			$filename=dol_sanitizeFileName($projectstatic->ref). "/". dol_sanitizeFileName($object->ref);
 			$filedir=$conf->projet->dir_output . "/" . dol_sanitizeFileName($projectstatic->ref). "/" .dol_sanitizeFileName($object->ref);
 			$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php
index eff94d532e5..f7b9f28e16a 100644
--- a/htdocs/projet/tasks/time.php
+++ b/htdocs/projet/tasks/time.php
@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2005		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
- * Copyright (C) 2006-2013	Laurent Destailleur		<eldy@users.sourceforge.net>
+ * Copyright (C) 2006-2014	Laurent Destailleur		<eldy@users.sourceforge.net>
  * Copyright (C) 2010-2012	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2011		Juanjo Menent			<jmenent@2byte.es>
  *
@@ -181,7 +181,7 @@ if (! empty($project_ref) && ! empty($withproject))
 
 /*
  * View
-*/
+ */
 
 llxHeader("",$langs->trans("Task"));
 
@@ -193,7 +193,7 @@ if ($id > 0 || ! empty($ref))
 {
 	/*
 	 * Fiche projet en mode visu
-	*/
+ 	 */
 	if ($object->fetch($id) >= 0)
 	{
 		$result=$projectstatic->fetch($object->fk_project);
@@ -292,9 +292,37 @@ if ($id > 0 || ! empty($ref))
 		// Label
 		print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$object->label.'</td></tr>';
 
-		// Planned workload
-		print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td colspan="3">'.convertSecondToTime($object->planned_workload,'allhourmin').'</td></tr>';
-
+		// Date start
+		print '<tr><td>'.$langs->trans("DateStart").'</td><td colspan="3">';
+		print dol_print_date($object->date_start,'dayhour');
+		print '</td></tr>';
+		
+		// Date end
+		print '<tr><td>'.$langs->trans("DateEnd").'</td><td colspan="3">';
+		print dol_print_date($object->date_end,'dayhour');
+		print '</td></tr>';
+		
+		// Planned workload
+		print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td colspan="3">';
+		print convertSecondToTime($object->planned_workload,'allhourmin');
+		print '</td></tr>';
+		
+		// Progress declared
+		print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
+		print $object->progress.' %';
+		print '</td></tr>';
+		
+		// Progress calculated
+		print '<tr><td>'.$langs->trans("ProgressCalculated").'</td><td colspan="3">';
+		if ($object->planned_workload)
+		{
+			$tmparray=$object->getSummaryOfTimeSpent();
+			if ($tmparray['total_duration'] > 0) print round($tmparray['total_duration']/$object->planned_workload*100, 2).' %';
+			else print '0 %';
+		}
+		else print '';
+		print '</td></tr>';
+		
 		// Project
 		if (empty($withproject))
 		{
@@ -316,7 +344,7 @@ if ($id > 0 || ! empty($ref))
 
 		/*
 		 * Add time spent
-		*/
+		 */
 		if ($user->rights->projet->creer)
 		{
 			print '<br>';
@@ -333,7 +361,7 @@ if ($id > 0 || ! empty($ref))
 			print '<td width="100">'.$langs->trans("Date").'</td>';
 			print '<td>'.$langs->trans("By").'</td>';
 			print '<td>'.$langs->trans("Note").'</td>';
-			print '<td>'.$langs->trans("Progress").'</td>';
+			print '<td>'.$langs->trans("ProgressDeclared").'</td>';
 			print '<td align="right">'.$langs->trans("Duration").'</td>';
 			print '<td width="80">&nbsp;</td>';
 			print "</tr>\n";
@@ -363,14 +391,14 @@ if ($id > 0 || ! empty($ref))
 			print '<textarea name="timespent_note" cols="80" rows="'.ROWS_3.'">'.($_POST['timespent_note']?$_POST['timespent_note']:'').'</textarea>';
 			print '</td>';
 
-			// Progress
+			// Progress declared
 			print '<td class="nowrap">';
-			print $formother->select_percent($object->progress,'progress');
+			print $formother->select_percent(GETPOST('progress')?GETPOST('progress'):$object->progress,'progress');
 			print '</td>';
 
 			// Duration
 			print '<td class="nowrap" align="right">';
-			print $form->select_duration('timespent_duration',($_POST['timespent_duration']?$_POST['timespent_duration']:''),0,'text');
+			print $form->select_duration('timespent_duration', ($_POST['timespent_duration']?$_POST['timespent_duration']:''), 0, 'text');
 			print '</td>';
 
 			print '<td align="center">';
@@ -384,7 +412,7 @@ if ($id > 0 || ! empty($ref))
 
 		/*
 		 *  List of time spent
-		*/
+		 */
 		$sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note";
 		$sql.= ", u.lastname, u.firstname";
 		$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
-- 
GitLab