dolibarr  9.0.0
box_task.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012-2018 Charlene BENKE <charlie@patas-monkey.com>
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  public $boxcode="projet";
35  public $boximg="object_projecttask";
36  public $boxlabel;
37  //public $depends = array("projet");
38 
42  public $db;
43 
44  public $param;
45  public $enabled = 0; // Disabled because bugged.
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  function __construct($db,$param='')
58  {
59  global $user, $langs;
60 
61  // Load translation files required by the page
62  $langs->loadLangs(array('boxes', 'projects'));
63 
64  $this->boxlabel="Tasks";
65  $this->db = $db;
66 
67  $this->hidden = ! ($user->rights->projet->lire);
68  }
69 
76  function loadBox($max=5)
77  {
78  global $conf, $user, $langs, $db;
79 
80  $this->max=$max;
81 
82  $totalMnt = 0;
83  $totalnb = 0;
84  $totalDuree=0;
85  $totalplannedtot=0;
86  $totaldurationtot=0;
87 
88  include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
89  $taskstatic=new Task($db);
90 
91 
92  $textHead = $langs->trans("Tasks")."&nbsp;".date("Y");
93  $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
94 
95  // list the summary of the orders
96  if ($user->rights->projet->lire) {
97  // FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
98  $sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
99  $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt";
100  $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))."'";
101  $sql.= " AND pt.rowid = ptt.fk_task";
102  $sql.= " GROUP BY pt.fk_statut ";
103  $sql.= " ORDER BY pt.fk_statut DESC";
104  $sql.= $db->plimit($max, 0);
105 
106  $result = $db->query($sql);
107  if ($result)
108  {
109  $num = $db->num_rows($result);
110  $i = 0;
111  while ($i < $num)
112  {
113  $objp = $db->fetch_object($result);
114  $this->info_box_contents[$i][] = array(
115  'td' => '',
116  'text' =>$langs->trans("Task")." ".$taskstatic->LibStatut($objp->fk_statut,0),
117  );
118 
119  $this->info_box_contents[$i][] = array(
120  'td' => 'class="right"',
121  'text' => $objp->nb."&nbsp;".$langs->trans("Tasks"),
122  'url' => DOL_URL_ROOT."/projet/tasks/list.php?leftmenu=projects&viewstatut=".$objp->fk_statut,
123  );
124  $totalnb += $objp->nb;
125  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->plannedtot,'all',25200,5));
126  $totalplannedtot += $objp->plannedtot;
127  $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->durationtot,'all',25200,5));
128  $totaldurationtot += $objp->durationtot;
129 
130  $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut,3));
131 
132  $i++;
133  }
134  }
135  else dol_print_error($this->db);
136  }
137 
138 
139  // Add the sum at the bottom of the boxes
140  $this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => '', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
141  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ')."&nbsp;".$langs->trans("Tasks"));
142  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot,'all',25200,5));
143  $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot,'all',25200,5));
144  $this->info_box_contents[$i][] = array('td' => '', 'text' => "");
145  }
146 
155  function showBox($head = null, $contents = null, $nooutput=0)
156  {
157  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
158  }
159 }
loadBox($max=5)
Load data for box to show them later.
Definition: box_task.php:76
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
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:155
__construct($db, $param='')
Constructor.
Definition: box_task.php:57
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
Class to manage tasks.
Definition: task.class.php:33
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.