box_supplier_orders.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. /* Copyright (C) 2004-2006 Destailleur Laurent <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2012 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  5. * Copyright (C) 2015-2019 Frederic France <frederic.france@netlogic.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_supplier_orders.php
  22. * \ingroup fournisseurs
  23. * \brief Module that generates the latest supplier orders box
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class that manages the box showing latest supplier orders
  28. */
  29. class box_supplier_orders extends ModeleBoxes
  30. {
  31. public $boxcode = "latestsupplierorders";
  32. public $boximg = "object_order";
  33. public $boxlabel = "BoxLatestSupplierOrders";
  34. public $depends = array("fournisseur");
  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->fournisseur->commande->lire);
  53. }
  54. /**
  55. * Load data into info_box_contents array to show array 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 $conf, $user, $langs;
  63. $langs->load("boxes");
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  66. $supplierorderstatic = new CommandeFournisseur($this->db);
  67. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  68. $thirdpartystatic = new Fournisseur($this->db);
  69. $this->info_box_head = array('text' => $langs->trans("BoxTitleLatest".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."SupplierOrders", $max));
  70. if ($user->rights->fournisseur->commande->lire) {
  71. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  72. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  73. $sql .= ", s.logo, s.email, s.entity";
  74. $sql .= ", c.rowid, c.ref, c.tms, c.date_commande";
  75. $sql .= ", c.total_ht";
  76. $sql .= ", c.total_tva";
  77. $sql .= ", c.total_ttc";
  78. $sql .= ", c.fk_statut as status";
  79. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  80. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
  81. if (!$user->rights->societe->client->voir && !$user->socid) {
  82. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  83. }
  84. $sql .= " WHERE c.fk_soc = s.rowid";
  85. $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
  86. if (!$user->rights->societe->client->voir && !$user->socid) {
  87. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  88. }
  89. if ($user->socid) {
  90. $sql .= " AND s.rowid = ".((int) $user->socid);
  91. }
  92. if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
  93. $sql .= " ORDER BY c.date_commande DESC, c.ref DESC ";
  94. } else {
  95. $sql .= " ORDER BY c.tms DESC, c.ref DESC ";
  96. }
  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. $supplierorderstatic->id = $objp->rowid;
  107. $supplierorderstatic->ref = $objp->ref;
  108. $supplierorderstatic->statut = $objp->status;
  109. $thirdpartystatic->id = $objp->socid;
  110. $thirdpartystatic->name = $objp->name;
  111. //$thirdpartystatic->name_alias = $objp->name_alias;
  112. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  113. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  114. $thirdpartystatic->fournisseur = $objp->fournisseur;
  115. $thirdpartystatic->logo = $objp->logo;
  116. $thirdpartystatic->email = $objp->email;
  117. $thirdpartystatic->entity = $objp->entity;
  118. $this->info_box_contents[$line][] = array(
  119. 'td' => 'class="nowraponall"',
  120. 'text' => $supplierorderstatic->getNomUrl(1),
  121. 'asis' => 1
  122. );
  123. $this->info_box_contents[$line][] = array(
  124. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  125. 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
  126. 'asis' => 1,
  127. );
  128. $this->info_box_contents[$line][] = array(
  129. 'td' => 'class="right nowraponall"',
  130. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  131. );
  132. $this->info_box_contents[$line][] = array(
  133. 'td' => 'class="right"',
  134. 'text' => dol_print_date($date, 'day', 'tzuserrel'),
  135. );
  136. $this->info_box_contents[$line][] = array(
  137. 'td' => 'class="right" width="18"',
  138. 'text' => $supplierorderstatic->LibStatut($objp->status, 3),
  139. );
  140. $line++;
  141. }
  142. if ($num == 0) {
  143. $this->info_box_contents[$line][] = array(
  144. 'td' => 'class="center"',
  145. 'text' => $langs->trans("NoSupplierOrder"),
  146. );
  147. }
  148. $this->db->free($result);
  149. } else {
  150. $this->info_box_contents[0][] = array(
  151. 'td' => '',
  152. 'maxlength'=>500,
  153. 'text' => ($this->db->error().' sql='.$sql),
  154. );
  155. }
  156. } else {
  157. $this->info_box_contents[0][] = array(
  158. 'td' => 'class="nohover left"',
  159. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  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. public function showBox($head = null, $contents = null, $nooutput = 0)
  172. {
  173. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  174. }
  175. }