box_commandes.php 7.6 KB

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