box_commandes.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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@capnetworks.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. var $db;
  36. var $param;
  37. var $info_box_head = array();
  38. var $info_box_contents = array();
  39. /**
  40. * Load data for box to show them later
  41. *
  42. * @param int $max Maximum number of records to load
  43. * @return void
  44. */
  45. function loadBox($max=5)
  46. {
  47. global $user, $langs, $db, $conf;
  48. $this->max = $max;
  49. include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  50. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  51. $commandestatic = new Commande($db);
  52. $societestatic = new Societe($db);
  53. $userstatic = new User($db);
  54. $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."CustomerOrders",$max));
  55. if ($user->rights->commande->lire)
  56. {
  57. $sql = "SELECT s.nom as name";
  58. $sql.= ", s.rowid as socid";
  59. $sql.= ", s.code_client";
  60. $sql.= ", s.logo";
  61. $sql.= ", c.ref, c.tms";
  62. $sql.= ", c.rowid";
  63. $sql.= ", c.date_commande";
  64. $sql.= ", c.ref_client";
  65. $sql.= ", c.fk_statut";
  66. $sql.= ", c.fk_user_valid";
  67. $sql.= ", c.facture";
  68. $sql.= ", c.total_ht";
  69. $sql.= ", c.tva as total_tva";
  70. $sql.= ", c.total_ttc";
  71. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  72. $sql.= ", ".MAIN_DB_PREFIX."commande as c";
  73. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  74. $sql.= " WHERE c.fk_soc = s.rowid";
  75. $sql.= " AND c.entity = ".$conf->entity;
  76. if (! empty($conf->global->ORDER_BOX_LAST_ORDERS_VALIDATED_ONLY)) $sql.=" AND c.fk_statut = 1";
  77. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  78. if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
  79. if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY c.date_commande DESC, c.ref DESC ";
  80. else $sql.= " ORDER BY c.tms DESC, c.ref DESC ";
  81. $sql.= $db->plimit($max, 0);
  82. $result = $db->query($sql);
  83. if ($result) {
  84. $num = $db->num_rows($result);
  85. $line = 0;
  86. while ($line < $num) {
  87. $objp = $db->fetch_object($result);
  88. $date=$db->jdate($objp->date_commande);
  89. $datem=$db->jdate($objp->tms);
  90. $commandestatic->id = $objp->rowid;
  91. $commandestatic->ref = $objp->ref;
  92. $commandestatic->ref_client = $objp->ref_client;
  93. $commandestatic->total_ht = $objp->total_ht;
  94. $commandestatic->total_tva = $objp->total_tva;
  95. $commandestatic->total_ttc = $objp->total_ttc;
  96. $societestatic->id = $objp->socid;
  97. $societestatic->name = $objp->name;
  98. $societestatic->code_client = $objp->code_client;
  99. $societestatic->logo = $objp->logo;
  100. $this->info_box_contents[$line][] = array(
  101. 'td' => 'align="left"',
  102. 'text' => $commandestatic->getNomUrl(1),
  103. 'asis' => 1,
  104. );
  105. $this->info_box_contents[$line][] = array(
  106. 'td' => 'align="left"',
  107. 'text' => $societestatic->getNomUrl(1),
  108. 'asis' => 1,
  109. );
  110. $this->info_box_contents[$line][] = array(
  111. 'td' => 'align="right"',
  112. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  113. );
  114. if (! empty($conf->global->ORDER_BOX_LAST_ORDERS_SHOW_VALIDATE_USER)) {
  115. if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
  116. $this->info_box_contents[$line][] = array(
  117. 'td' => 'align="right"',
  118. 'text' => (($objp->fk_user_valid > 0)?$userstatic->getNomUrl(1):''),
  119. 'asis' => 1,
  120. );
  121. }
  122. $this->info_box_contents[$line][] = array(
  123. 'td' => 'align="right"',
  124. 'text' => dol_print_date($date,'day'),
  125. );
  126. $this->info_box_contents[$line][] = array(
  127. 'td' => 'align="right" width="18"',
  128. 'text' => $commandestatic->LibStatut($objp->fk_statut,$objp->facture,3),
  129. );
  130. $line++;
  131. }
  132. if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedOrders"));
  133. $db->free($result);
  134. } else {
  135. $this->info_box_contents[0][0] = array(
  136. 'td' => 'align="left"',
  137. 'maxlength'=>500,
  138. 'text' => ($db->error().' sql='.$sql),
  139. );
  140. }
  141. } else {
  142. $this->info_box_contents[0][0] = array(
  143. 'align' => 'left',
  144. 'text' => $langs->trans("ReadPermissionNotAllowed"),
  145. );
  146. }
  147. }
  148. /**
  149. * Method to show box
  150. *
  151. * @param array $head Array with properties of box title
  152. * @param array $contents Array with properties of box lines
  153. * @param int $nooutput No print, only return string
  154. * @return void
  155. */
  156. function showBox($head = null, $contents = null, $nooutput=0)
  157. {
  158. parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  159. }
  160. }