dolibarr/htdocs/core/boxes/box_task.php

151 lines
5.4 KiB
PHP
Raw Normal View History

2014-06-18 21:34:18 +02:00
<?php
/* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
2015-01-25 01:20:58 +01:00
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
2015-01-06 17:54:36 +01:00
*
2014-06-18 21:34:18 +02:00
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
2015-01-06 17:54:36 +01:00
* \file htdocs/core/boxes/box_task.php
* \ingroup Projet
* \brief Module to Task activity of the current year
2014-06-18 21:34:18 +02:00
*/
include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
2015-12-24 11:38:30 +01:00
2014-06-20 23:17:26 +02:00
/**
* Class to manage the box to show last task
*/
2014-06-20 23:56:03 +02:00
class box_task extends ModeleBoxes
2014-06-20 23:17:26 +02:00
{
2015-01-06 17:54:36 +01:00
var $boxcode="projet";
var $boximg="object_projecttask";
var $boxlabel;
//var $depends = array("projet");
var $db;
var $param;
2015-12-24 11:38:30 +01:00
var $enabled = 0; // Disabled because bugged.
2015-01-06 17:54:36 +01:00
var $info_box_head = array();
var $info_box_contents = array();
2017-06-12 14:09:00 +02:00
2015-01-06 17:54:36 +01:00
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param string $param More parameters
*/
function __construct($db,$param='')
{
2017-06-12 14:09:00 +02:00
global $user, $langs;
2015-01-06 17:54:36 +01:00
$langs->load("boxes");
$langs->load("projects");
$this->boxlabel="Tasks";
$this->db = $db;
2017-06-12 14:09:00 +02:00
$this->hidden = ! ($user->rights->projet->lire);
2015-01-06 17:54:36 +01:00
}
2014-07-08 01:02:30 +02:00
2014-06-20 23:56:03 +02:00
/**
* Load data for box to show them later
*
2015-01-06 17:54:36 +01:00
* @param int $max Maximum number of records to load
* @return void
2014-06-20 23:56:03 +02:00
*/
2014-06-18 21:34:18 +02:00
function loadBox($max=5)
{
global $conf, $user, $langs, $db;
2014-07-08 01:02:30 +02:00
2014-06-18 21:34:18 +02:00
$this->max=$max;
2014-07-08 01:02:30 +02:00
2014-06-18 21:34:18 +02:00
$totalMnt = 0;
$totalnb = 0;
$totalDuree=0;
include_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
$taskstatic=new Task($db);
2014-07-08 01:02:30 +02:00
2014-06-18 21:34:18 +02:00
$textHead = $langs->trans("Tasks")."&nbsp;".date("Y");
$this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
// list the summary of the orders
2015-01-06 17:54:36 +01:00
if ($user->rights->projet->lire) {
2015-12-24 11:38:30 +01:00
// FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
$sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
2014-06-18 21:50:17 +02:00
$sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt";
2015-10-27 19:26:33 +01:00
$sql.= " WHERE pt.datec BETWEEN '".$this->db->idate(dol_get_first_day(date("Y"), 1))."' AND '".$this->db->idate(dol_get_last_day(date("Y"), 12))."'";
2014-06-18 21:50:17 +02:00
$sql.= " AND pt.rowid = ptt.fk_task";
2014-06-18 21:34:18 +02:00
$sql.= " GROUP BY pt.fk_statut ";
$sql.= " ORDER BY pt.fk_statut DESC";
$sql.= $db->plimit($max, 0);
$result = $db->query($sql);
2016-06-27 13:57:10 +02:00
if ($result)
2015-10-27 19:26:33 +01:00
{
2014-06-18 21:34:18 +02:00
$num = $db->num_rows($result);
$i = 0;
2016-06-27 13:57:10 +02:00
while ($i < $num)
2015-10-27 19:26:33 +01:00
{
2015-01-06 17:54:36 +01:00
$objp = $db->fetch_object($result);
2015-10-27 19:26:33 +01:00
$this->info_box_contents[$i][] = array(
2017-03-10 11:22:27 +01:00
'td' => '',
2015-10-27 19:26:33 +01:00
'text' =>$langs->trans("Task")." ".$taskstatic->LibStatut($objp->fk_statut,0),
2015-01-06 17:54:36 +01:00
);
2015-10-27 19:26:33 +01:00
$this->info_box_contents[$i][] = array(
2017-03-10 11:22:27 +01:00
'td' => 'class="right"',
2015-01-06 17:54:36 +01:00
'text' => $objp->nb."&nbsp;".$langs->trans("Tasks"),
2015-12-04 15:37:28 +01:00
'url' => DOL_URL_ROOT."/projet/tasks/list.php?leftmenu=projects&viewstatut=".$objp->fk_statut,
2015-01-06 17:54:36 +01:00
);
2014-06-18 21:34:18 +02:00
$totalnb += $objp->nb;
2017-03-10 11:22:27 +01:00
$this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->plannedtot,'all',25200,5));
2014-06-18 21:50:17 +02:00
$totalplannedtot += $objp->plannedtot;
2017-03-10 11:22:27 +01:00
$this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->durationtot,'all',25200,5));
2014-06-18 21:50:17 +02:00
$totaldurationtot += $objp->durationtot;
2014-07-08 01:02:30 +02:00
2015-10-27 19:26:33 +01:00
$this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut,3));
2014-06-18 21:34:18 +02:00
$i++;
}
}
2015-10-27 19:26:33 +01:00
else dol_print_error($this->db);
2014-06-18 21:34:18 +02:00
}
// Add the sum à the bottom of the boxes
2017-03-10 11:22:27 +01:00
$this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => '', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
2015-10-27 19:26:33 +01:00
$this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ')."&nbsp;".$langs->trans("Tasks"));
$this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot,'all',25200,5));
$this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot,'all',25200,5));
$this->info_box_contents[$i][] = array('td' => '', 'text' => "");
2014-12-05 17:44:47 +01:00
2014-06-18 21:34:18 +02:00
}
2014-06-20 23:39:43 +02:00
/**
* Method to show box
*
* @param array $head Array with properties of box title
* @param array $contents Array with properties of box lines
2016-06-27 13:57:10 +02:00
* @param int $nooutput No print, only return string
2017-06-12 14:09:00 +02:00
* @return string
2014-06-20 23:39:43 +02:00
*/
2016-06-27 13:57:10 +02:00
function showBox($head = null, $contents = null, $nooutput=0)
2014-06-18 21:34:18 +02:00
{
2017-06-12 14:09:00 +02:00
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
2014-06-18 21:34:18 +02:00
}
}