dolibarr  7.0.0-beta
box_task.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
3  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php");
26 require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
27 
28 
32 class box_task extends ModeleBoxes
33 {
34  var $boxcode="projet";
35  var $boximg="object_projecttask";
36  var $boxlabel;
37  //var $depends = array("projet");
38  var $db;
39  var $param;
40  var $enabled = 0; // Disabled because bugged.
41 
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param='')
53  {
54  global $user, $langs;
55  $langs->load("boxes");
56  $langs->load("projects");
57  $this->boxlabel="Tasks";
58  $this->db = $db;
59 
60  $this->hidden = ! ($user->rights->projet->lire);
61  }
62 
69  function loadBox($max=5)
70  {
71  global $conf, $user, $langs, $db;
72 
73  $this->max=$max;
74 
75  $totalMnt = 0;
76  $totalnb = 0;
77  $totalDuree=0;
78  include_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
79  $taskstatic=new Task($db);
80 
81 
82  $textHead = $langs->trans("Tasks")."&nbsp;".date("Y");
83  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
84 
85  // list the summary of the orders
86  if ($user->rights->projet->lire) {
87  // FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
88  $sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
89  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt";
90  $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))."'";
91  $sql.= " AND pt.rowid = ptt.fk_task";
92  $sql.= " GROUP BY pt.fk_statut ";
93  $sql.= " ORDER BY pt.fk_statut DESC";
94  $sql.= $db->plimit($max, 0);
95 
96  $result = $db->query($sql);
97  if ($result)
98  {
99  $num = $db->num_rows($result);
100  $i = 0;
101  while ($i < $num)
102  {
103  $objp = $db->fetch_object($result);
104  $this->info_box_contents[$i][] = array(
105  'td' => '',
106  'text' =>$langs->trans("Task")." ".$taskstatic->LibStatut($objp->fk_statut,0),
107  );
108 
109  $this->info_box_contents[$i][] = array(
110  'td' => 'class="right"',
111  'text' => $objp->nb."&nbsp;".$langs->trans("Tasks"),
112  'url' => DOL_URL_ROOT."/projet/tasks/list.php?leftmenu=projects&viewstatut=".$objp->fk_statut,
113  );
114  $totalnb += $objp->nb;
115  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->plannedtot,'all',25200,5));
116  $totalplannedtot += $objp->plannedtot;
117  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->durationtot,'all',25200,5));
118  $totaldurationtot += $objp->durationtot;
119 
120  $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut,3));
121 
122  $i++;
123  }
124  }
125  else dol_print_error($this->db);
126  }
127 
128 
129  // Add the sum à the bottom of the boxes
130  $this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => '', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
131  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ')."&nbsp;".$langs->trans("Tasks"));
132  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot,'all',25200,5));
133  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot,'all',25200,5));
134  $this->info_box_contents[$i][] = array('td' => '', 'text' => "");
135 
136  }
137 
146  function showBox($head = null, $contents = null, $nooutput=0)
147  {
148  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
149  }
150 }
loadBox($max=5)
Load data for box to show them later.
Definition: box_task.php:69
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class ModeleBoxes.
Class to manage the box to show last task.
Definition: box_task.php:32
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_task.php:146
__construct($db, $param='')
Constructor.
Definition: box_task.php:52
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
Class to manage tasks.
Definition: task.class.php:32
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.