box_task.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /**
  19. * \file htdocs/core/boxes/box_task.php
  20. * \ingroup Projet
  21. * \brief Module to Task activity of the current year
  22. */
  23. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  24. require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
  25. /**
  26. * Class to manage the box to show last task
  27. */
  28. class box_task extends ModeleBoxes
  29. {
  30. var $boxcode="projet";
  31. var $boximg="object_projecttask";
  32. var $boxlabel;
  33. //var $depends = array("projet");
  34. var $db;
  35. var $param;
  36. var $enabled = 0; // Disabled because bugged.
  37. var $info_box_head = array();
  38. var $info_box_contents = array();
  39. /**
  40. * Constructor
  41. *
  42. * @param DoliDB $db Database handler
  43. * @param string $param More parameters
  44. */
  45. function __construct($db,$param='')
  46. {
  47. global $user, $langs;
  48. $langs->load("boxes");
  49. $langs->load("projects");
  50. $this->boxlabel="Tasks";
  51. $this->db = $db;
  52. $this->hidden = ! ($user->rights->projet->lire);
  53. }
  54. /**
  55. * Load data for box to show them later
  56. *
  57. * @param int $max Maximum number of records to load
  58. * @return void
  59. */
  60. function loadBox($max=5)
  61. {
  62. global $conf, $user, $langs, $db;
  63. $this->max=$max;
  64. $totalMnt = 0;
  65. $totalnb = 0;
  66. $totalDuree=0;
  67. include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
  68. $taskstatic=new Task($db);
  69. $textHead = $langs->trans("Tasks")."&nbsp;".date("Y");
  70. $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
  71. // list the summary of the orders
  72. if ($user->rights->projet->lire) {
  73. // FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
  74. $sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
  75. $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt";
  76. $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))."'";
  77. $sql.= " AND pt.rowid = ptt.fk_task";
  78. $sql.= " GROUP BY pt.fk_statut ";
  79. $sql.= " ORDER BY pt.fk_statut DESC";
  80. $sql.= $db->plimit($max, 0);
  81. $result = $db->query($sql);
  82. if ($result)
  83. {
  84. $num = $db->num_rows($result);
  85. $i = 0;
  86. while ($i < $num)
  87. {
  88. $objp = $db->fetch_object($result);
  89. $this->info_box_contents[$i][] = array(
  90. 'td' => '',
  91. 'text' =>$langs->trans("Task")." ".$taskstatic->LibStatut($objp->fk_statut,0),
  92. );
  93. $this->info_box_contents[$i][] = array(
  94. 'td' => 'class="right"',
  95. 'text' => $objp->nb."&nbsp;".$langs->trans("Tasks"),
  96. 'url' => DOL_URL_ROOT."/projet/tasks/list.php?leftmenu=projects&viewstatut=".$objp->fk_statut,
  97. );
  98. $totalnb += $objp->nb;
  99. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->plannedtot,'all',25200,5));
  100. $totalplannedtot += $objp->plannedtot;
  101. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => ConvertSecondToTime($objp->durationtot,'all',25200,5));
  102. $totaldurationtot += $objp->durationtot;
  103. $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut,3));
  104. $i++;
  105. }
  106. }
  107. else dol_print_error($this->db);
  108. }
  109. // Add the sum à the bottom of the boxes
  110. $this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => '', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
  111. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ')."&nbsp;".$langs->trans("Tasks"));
  112. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot,'all',25200,5));
  113. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot,'all',25200,5));
  114. $this->info_box_contents[$i][] = array('td' => '', 'text' => "");
  115. }
  116. /**
  117. * Method to show box
  118. *
  119. * @param array $head Array with properties of box title
  120. * @param array $contents Array with properties of box lines
  121. * @param int $nooutput No print, only return string
  122. * @return string
  123. */
  124. function showBox($head = null, $contents = null, $nooutput=0)
  125. {
  126. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  127. }
  128. }