box_shipments.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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) 2019 Alexandre Spangaro <aspangaro@open-dsi.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_shipments.php
  22. * \ingroup shipment
  23. * \brief Module for generating the display of the shipment box
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last shipments
  28. */
  29. class box_shipments extends ModeleBoxes
  30. {
  31. public $boxcode = "lastcustomershipments";
  32. public $boximg = "sending";
  33. public $boxlabel = "BoxLastCustomerShipments";
  34. public $depends = array("expedition");
  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 = !($user->rights->expedition->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. public function loadBox($max = 5)
  61. {
  62. global $user, $langs, $conf;
  63. $langs->loadLangs(array('orders', 'sendings'));
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  66. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  67. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  68. $shipmentstatic = new Expedition($this->db);
  69. $orderstatic = new Commande($this->db);
  70. $societestatic = new Societe($this->db);
  71. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastCustomerShipments", $max));
  72. if ($user->rights->expedition->lire) {
  73. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  74. $sql .= ", s.code_client, s.code_compta, s.client";
  75. $sql .= ", s.logo, s.email, s.entity";
  76. $sql .= ", e.ref, e.tms";
  77. $sql .= ", e.rowid";
  78. $sql .= ", e.ref_customer";
  79. $sql .= ", e.fk_statut";
  80. $sql .= ", e.fk_user_valid";
  81. $sql .= ", c.ref as commande_ref";
  82. $sql .= ", c.rowid as commande_id";
  83. $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
  84. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
  85. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
  86. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
  87. if (!$user->rights->societe->client->voir && !$user->socid) {
  88. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
  89. }
  90. $sql .= " WHERE e.entity IN (".getEntity('expedition').")";
  91. if (!empty($conf->global->ORDER_BOX_LAST_SHIPMENTS_VALIDATED_ONLY)) {
  92. $sql .= " AND e.fk_statut = 1";
  93. }
  94. if ($user->socid > 0) {
  95. $sql.= " AND s.rowid = ".((int) $user->socid);
  96. }
  97. if (!$user->rights->societe->client->voir && !$user->socid) {
  98. $sql .= " AND sc.fk_user = ".((int) $user->id);
  99. } else {
  100. $sql .= " ORDER BY e.date_delivery, e.ref DESC ";
  101. }
  102. $sql .= $this->db->plimit($max, 0);
  103. $result = $this->db->query($sql);
  104. if ($result) {
  105. $num = $this->db->num_rows($result);
  106. $line = 0;
  107. while ($line < $num) {
  108. $objp = $this->db->fetch_object($result);
  109. $shipmentstatic->id = $objp->rowid;
  110. $shipmentstatic->ref = $objp->ref;
  111. $shipmentstatic->ref_customer = $objp->ref_customer;
  112. $orderstatic->id = $objp->commande_id;
  113. $orderstatic->ref = $objp->commande_ref;
  114. $societestatic->id = $objp->socid;
  115. $societestatic->name = $objp->name;
  116. //$societestatic->name_alias = $objp->name_alias;
  117. $societestatic->code_client = $objp->code_client;
  118. $societestatic->code_compta = $objp->code_compta;
  119. $societestatic->client = $objp->client;
  120. $societestatic->logo = $objp->logo;
  121. $societestatic->email = $objp->email;
  122. $societestatic->entity = $objp->entity;
  123. $this->info_box_contents[$line][] = array(
  124. 'td' => 'class="nowraponall"',
  125. 'text' => $shipmentstatic->getNomUrl(1),
  126. 'asis' => 1,
  127. );
  128. $this->info_box_contents[$line][] = array(
  129. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  130. 'text' => $societestatic->getNomUrl(1),
  131. 'asis' => 1,
  132. );
  133. $this->info_box_contents[$line][] = array(
  134. 'td' => 'class="nowraponall"',
  135. 'text' => $orderstatic->getNomUrl(1),
  136. 'asis' => 1,
  137. );
  138. $this->info_box_contents[$line][] = array(
  139. 'td' => 'class="right" width="18"',
  140. 'text' => $shipmentstatic->LibStatut($objp->fk_statut, 3),
  141. );
  142. $line++;
  143. }
  144. if ($num == 0) {
  145. $this->info_box_contents[$line][0] = array(
  146. 'td' => 'class="center opacitymedium"',
  147. 'text'=>$langs->trans("NoRecordedShipments")
  148. );
  149. }
  150. $this->db->free($result);
  151. } else {
  152. $this->info_box_contents[0][0] = array(
  153. 'td' => '',
  154. 'maxlength'=>500,
  155. 'text' => ($this->db->error().' sql='.$sql),
  156. );
  157. }
  158. } else {
  159. $this->info_box_contents[0][0] = array(
  160. 'td' => 'class="nohover opacitymedium left"',
  161. 'text' => $langs->trans("ReadPermissionNotAllowed")
  162. );
  163. }
  164. }
  165. /**
  166. * Method to show box
  167. *
  168. * @param array $head Array with properties of box title
  169. * @param array $contents Array with properties of box lines
  170. * @param int $nooutput No print, only return string
  171. * @return string
  172. */
  173. public function showBox($head = null, $contents = null, $nooutput = 0)
  174. {
  175. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  176. }
  177. }