box_task.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 $langs;
  48. $langs->load("boxes");
  49. $langs->load("projects");
  50. $this->boxlabel="Tasks";
  51. $this->db = $db;
  52. }
  53. /**
  54. * Load data for box to show them later
  55. *
  56. * @param int $max Maximum number of records to load
  57. * @return void
  58. */
  59. function loadBox($max=5)
  60. {
  61. global $conf, $user, $langs, $db;
  62. $this->max=$max;
  63. $totalMnt = 0;
  64. $totalnb = 0;
  65. $totalDuree=0;
  66. include_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
  67. $taskstatic=new Task($db);
  68. $textHead = $langs->trans("Tasks")."&nbsp;".date("Y");
  69. $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
  70. // list the summary of the orders
  71. if ($user->rights->projet->lire) {
  72. // FIXME fk_statut on a task is not be used. We use the percent. This means this box is useless.
  73. $sql = "SELECT pt.fk_statut, count(DISTINCT pt.rowid) as nb, sum(ptt.task_duration) as durationtot, sum(pt.planned_workload) as plannedtot";
  74. $sql.= " FROM ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet_task_time as ptt";
  75. $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))."'";
  76. $sql.= " AND pt.rowid = ptt.fk_task";
  77. $sql.= " GROUP BY pt.fk_statut ";
  78. $sql.= " ORDER BY pt.fk_statut DESC";
  79. $sql.= $db->plimit($max, 0);
  80. $result = $db->query($sql);
  81. if ($result)
  82. {
  83. $num = $db->num_rows($result);
  84. $i = 0;
  85. while ($i < $num)
  86. {
  87. $objp = $db->fetch_object($result);
  88. $this->info_box_contents[$i][] = array(
  89. 'td' => 'align="left"',
  90. 'text' =>$langs->trans("Task")." ".$taskstatic->LibStatut($objp->fk_statut,0),
  91. );
  92. $this->info_box_contents[$i][] = array(
  93. 'td' => 'align="right"',
  94. 'text' => $objp->nb."&nbsp;".$langs->trans("Tasks"),
  95. 'url' => DOL_URL_ROOT."/projet/tasks/list.php?leftmenu=projects&viewstatut=".$objp->fk_statut,
  96. );
  97. $totalnb += $objp->nb;
  98. $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->plannedtot,'all',25200,5));
  99. $totalplannedtot += $objp->plannedtot;
  100. $this->info_box_contents[$i][] = array('td' => 'align="right"', 'text' => ConvertSecondToTime($objp->durationtot,'all',25200,5));
  101. $totaldurationtot += $objp->durationtot;
  102. $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', 'text' => $taskstatic->LibStatut($objp->fk_statut,3));
  103. $i++;
  104. }
  105. }
  106. else dol_print_error($this->db);
  107. }
  108. // Add the sum à the bottom of the boxes
  109. $this->info_box_contents[$i][] = array('tr' => 'class="liste_total"', 'td' => 'align="left"', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
  110. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => number_format($totalnb, 0, ',', ' ')."&nbsp;".$langs->trans("Tasks"));
  111. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totalplannedtot,'all',25200,5));
  112. $this->info_box_contents[$i][] = array('td' => 'align="right" ', 'text' => ConvertSecondToTime($totaldurationtot,'all',25200,5));
  113. $this->info_box_contents[$i][] = array('td' => '', 'text' => "");
  114. }
  115. /**
  116. * Method to show box
  117. *
  118. * @param array $head Array with properties of box title
  119. * @param array $contents Array with properties of box lines
  120. * @param int $nooutput No print, only return string
  121. * @return void
  122. */
  123. function showBox($head = null, $contents = null, $nooutput=0)
  124. {
  125. parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  126. }
  127. }