box_boms.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/boxes/box_boms.php
  22. * \ingroup bom
  23. * \brief Widget for latest modified BOM
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last orders
  28. */
  29. class box_boms extends ModeleBoxes
  30. {
  31. public $boxcode = "lastboms";
  32. public $boximg = "object_bom";
  33. public $boxlabel = "BoxTitleLatestModifiedBoms";
  34. public $depends = array("bom");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $param;
  40. public $info_box_head = array();
  41. public $info_box_contents = array();
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $db Database handler
  46. * @param string $param More parameters
  47. */
  48. public function __construct($db, $param)
  49. {
  50. global $user;
  51. $this->db = $db;
  52. $this->hidden = empty($user->rights->bom->read);
  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. public function loadBox($max = 5)
  61. {
  62. global $user, $langs, $conf;
  63. $this->max = $max;
  64. include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  65. include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  66. $bomstatic = new Bom($this->db);
  67. $productstatic = new Product($this->db);
  68. $userstatic = new User($this->db);
  69. $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max));
  70. if ($user->rights->bom->read) {
  71. $sql = "SELECT p.ref as product_ref";
  72. $sql .= ", p.rowid as productid";
  73. $sql .= ", p.tosell";
  74. $sql .= ", p.tobuy";
  75. $sql .= ", p.tobatch";
  76. $sql .= ", c.rowid";
  77. $sql .= ", c.date_creation";
  78. $sql .= ", c.tms";
  79. $sql .= ", c.ref";
  80. $sql .= ", c.status";
  81. $sql .= ", c.fk_user_valid";
  82. $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
  83. $sql .= ", ".MAIN_DB_PREFIX."bom_bom as c";
  84. $sql .= " WHERE c.fk_product = p.rowid";
  85. $sql .= " AND c.entity = ".$conf->entity;
  86. $sql .= " ORDER BY c.tms DESC, c.ref DESC";
  87. $sql .= $this->db->plimit($max, 0);
  88. $result = $this->db->query($sql);
  89. if ($result) {
  90. $num = $this->db->num_rows($result);
  91. $line = 0;
  92. while ($line < $num) {
  93. $objp = $this->db->fetch_object($result);
  94. $datem = $this->db->jdate($objp->tms);
  95. $bomstatic->id = $objp->rowid;
  96. $bomstatic->ref = $objp->ref;
  97. $bomstatic->status = $objp->status;
  98. $productstatic->id = $objp->productid;
  99. $productstatic->ref = $objp->product_ref;
  100. $productstatic->status = $objp->tosell;
  101. $productstatic->status_buy = $objp->tobuy;
  102. $productstatic->status_batch = $objp->tobatch;
  103. $this->info_box_contents[$line][] = array(
  104. 'td' => 'class="nowraponall"',
  105. 'text' => $bomstatic->getNomUrl(1),
  106. 'asis' => 1,
  107. );
  108. $this->info_box_contents[$line][] = array(
  109. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  110. 'text' => $productstatic->getNomUrl(1),
  111. 'asis' => 1,
  112. );
  113. if (!empty($conf->global->BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER)) {
  114. if ($objp->fk_user_valid > 0) {
  115. $userstatic->fetch($objp->fk_user_valid);
  116. }
  117. $this->info_box_contents[$line][] = array(
  118. 'td' => 'class="right"',
  119. 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
  120. 'asis' => 1,
  121. );
  122. }
  123. $this->info_box_contents[$line][] = array(
  124. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  125. 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
  126. );
  127. $this->info_box_contents[$line][] = array(
  128. 'td' => 'class="right" width="18"',
  129. 'text' => $bomstatic->LibStatut($objp->status, 3),
  130. );
  131. $line++;
  132. }
  133. if ($num == 0) {
  134. $this->info_box_contents[$line][0] = array(
  135. 'td' => 'class="center opacitymedium"',
  136. 'text'=>$langs->trans("NoRecordedOrders")
  137. );
  138. }
  139. $this->db->free($result);
  140. } else {
  141. $this->info_box_contents[0][0] = array(
  142. 'td' => '',
  143. 'maxlength'=>500,
  144. 'text' => ($this->db->error().' sql='.$sql),
  145. );
  146. }
  147. } else {
  148. $this->info_box_contents[0][0] = array(
  149. 'td' => 'class="nohover opacitymedium left"',
  150. 'text' => $langs->trans("ReadPermissionNotAllowed")
  151. );
  152. }
  153. }
  154. /**
  155. * Method to show box
  156. *
  157. * @param array $head Array with properties of box title
  158. * @param array $contents Array with properties of box lines
  159. * @param int $nooutput No print, only return string
  160. * @return string
  161. */
  162. public function showBox($head = null, $contents = null, $nooutput = 0)
  163. {
  164. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  165. }
  166. }