box_commandes.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_commandes.php
  22. * \ingroup commande
  23. * \brief Widget for latest sale orders
  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_commandes extends ModeleBoxes
  30. {
  31. public $boxcode = "lastcustomerorders";
  32. public $boximg = "object_order";
  33. public $boxlabel = "BoxLastCustomerOrders";
  34. public $depends = array("commande");
  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->commande->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->load('orders');
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  66. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  67. $commandestatic = new Commande($this->db);
  68. $societestatic = new Societe($this->db);
  69. $userstatic = new User($this->db);
  70. $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ? "" : "Modified")."CustomerOrders", $max));
  71. if ($user->rights->commande->lire)
  72. {
  73. $sql = "SELECT s.nom as name";
  74. $sql .= ", s.rowid as socid";
  75. $sql .= ", s.code_client";
  76. $sql .= ", s.logo, s.email";
  77. $sql .= ", c.ref, c.tms";
  78. $sql .= ", c.rowid";
  79. $sql .= ", c.date_commande";
  80. $sql .= ", c.ref_client";
  81. $sql .= ", c.fk_statut";
  82. $sql .= ", c.fk_user_valid";
  83. $sql .= ", c.facture";
  84. $sql .= ", c.total_ht";
  85. $sql .= ", c.tva as total_tva";
  86. $sql .= ", c.total_ttc";
  87. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  88. $sql .= ", ".MAIN_DB_PREFIX."commande as c";
  89. if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  90. $sql .= " WHERE c.fk_soc = s.rowid";
  91. $sql .= " AND c.entity = ".$conf->entity;
  92. if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) $sql .= " AND c.fk_statut = 1";
  93. if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  94. if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
  95. if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
  96. else $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
  97. $sql .= $this->db->plimit($max, 0);
  98. $result = $this->db->query($sql);
  99. if ($result) {
  100. $num = $this->db->num_rows($result);
  101. $line = 0;
  102. while ($line < $num) {
  103. $objp = $this->db->fetch_object($result);
  104. $date = $this->db->jdate($objp->date_commande);
  105. $datem = $this->db->jdate($objp->tms);
  106. $commandestatic->id = $objp->rowid;
  107. $commandestatic->ref = $objp->ref;
  108. $commandestatic->ref_client = $objp->ref_client;
  109. $commandestatic->total_ht = $objp->total_ht;
  110. $commandestatic->total_tva = $objp->total_tva;
  111. $commandestatic->total_ttc = $objp->total_ttc;
  112. $societestatic->id = $objp->socid;
  113. $societestatic->name = $objp->name;
  114. $societestatic->email = $objp->email;
  115. $societestatic->code_client = $objp->code_client;
  116. $societestatic->logo = $objp->logo;
  117. $this->info_box_contents[$line][] = array(
  118. 'td' => 'class="nowraponall"',
  119. 'text' => $commandestatic->getNomUrl(1),
  120. 'asis' => 1,
  121. );
  122. $this->info_box_contents[$line][] = array(
  123. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  124. 'text' => $societestatic->getNomUrl(1),
  125. 'asis' => 1,
  126. );
  127. $this->info_box_contents[$line][] = array(
  128. 'td' => 'class="nowraponall right"',
  129. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  130. );
  131. if (!empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
  132. if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
  133. $this->info_box_contents[$line][] = array(
  134. 'td' => 'class="right"',
  135. 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
  136. 'asis' => 1,
  137. );
  138. }
  139. $this->info_box_contents[$line][] = array(
  140. 'td' => 'class="right"',
  141. 'text' => dol_print_date($date, 'day'),
  142. );
  143. $this->info_box_contents[$line][] = array(
  144. 'td' => 'class="right" width="18"',
  145. 'text' => $commandestatic->LibStatut($objp->fk_statut, $objp->facture, 3),
  146. );
  147. $line++;
  148. }
  149. if ($num == 0) $this->info_box_contents[$line][0] = array(
  150. 'td' => 'class="center opacitymedium"',
  151. 'text'=>$langs->trans("NoRecordedOrders")
  152. );
  153. $this->db->free($result);
  154. } else {
  155. $this->info_box_contents[0][0] = array(
  156. 'td' => '',
  157. 'maxlength'=>500,
  158. 'text' => ($this->db->error().' sql='.$sql),
  159. );
  160. }
  161. } else {
  162. $this->info_box_contents[0][0] = array(
  163. 'td' => 'class="nohover opacitymedium left"',
  164. 'text' => $langs->trans("ReadPermissionNotAllowed")
  165. );
  166. }
  167. }
  168. /**
  169. * Method to show box
  170. *
  171. * @param array $head Array with properties of box title
  172. * @param array $contents Array with properties of box lines
  173. * @param int $nooutput No print, only return string
  174. * @return string
  175. */
  176. public function showBox($head = null, $contents = null, $nooutput = 0)
  177. {
  178. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  179. }
  180. }