box_fournisseurs.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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) 2015-2019 Frederic France <frederic.france@free.fr>
  5. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  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_fournisseurs.php
  22. * \ingroup fournisseurs
  23. * \brief Module to generate box of suppliers
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last suppliers
  28. */
  29. class box_fournisseurs extends ModeleBoxes
  30. {
  31. public $boxcode = "lastsuppliers";
  32. public $boximg = "object_company";
  33. public $boxlabel = "BoxLastSuppliers";
  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->societe->lire && empty($user->socid));
  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, $hookmanager;
  63. $langs->load("boxes");
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  66. $thirdpartystatic = new Fournisseur($this->db);
  67. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedSuppliers", $max));
  68. if ($user->rights->societe->lire) {
  69. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  70. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  71. $sql .= ", s.logo, s.email, s.entity";
  72. $sql .= ", s.datec, s.tms, s.status";
  73. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  74. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  75. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  76. }
  77. $sql .= " WHERE s.fournisseur = 1";
  78. $sql .= " AND s.entity IN (".getEntity('societe').")";
  79. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  80. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  81. }
  82. // Add where from hooks
  83. $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
  84. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
  85. if (empty($reshook)) {
  86. if ($user->socid > 0) {
  87. $sql .= " AND s.rowid = ".((int) $user->socid);
  88. }
  89. }
  90. $sql .= $hookmanager->resPrint;
  91. $sql .= " ORDER BY s.tms DESC ";
  92. $sql .= $this->db->plimit($max, 0);
  93. $result = $this->db->query($sql);
  94. if ($result) {
  95. $num = $this->db->num_rows($result);
  96. $line = 0;
  97. while ($line < $num) {
  98. $objp = $this->db->fetch_object($result);
  99. $datec = $this->db->jdate($objp->datec);
  100. $datem = $this->db->jdate($objp->tms);
  101. $thirdpartystatic->id = $objp->socid;
  102. $thirdpartystatic->name = $objp->name;
  103. $thirdpartystatic->name_alias = $objp->name_alias;
  104. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  105. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  106. $thirdpartystatic->fournisseur = $objp->fournisseur;
  107. $thirdpartystatic->logo = $objp->logo;
  108. $thirdpartystatic->email = $objp->email;
  109. $thirdpartystatic->entity = $objp->entity;
  110. $this->info_box_contents[$line][] = array(
  111. 'td' => '',
  112. 'text' => $thirdpartystatic->getNomUrl(1, '', 40),
  113. 'asis' => 1,
  114. );
  115. $this->info_box_contents[$line][] = array(
  116. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  117. 'text' => dol_print_date($datem, "day", 'tzuserrel'),
  118. );
  119. $this->info_box_contents[$line][] = array(
  120. 'td' => 'class="right" width="18"',
  121. 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
  122. );
  123. $line++;
  124. }
  125. if ($num == 0) {
  126. $langs->load("suppliers");
  127. $this->info_box_contents[$line][0] = array(
  128. 'td' => 'class="center opacitymedium"',
  129. 'text'=>$langs->trans("NoRecordedSuppliers"),
  130. );
  131. }
  132. $this->db->free($result);
  133. } else {
  134. $this->info_box_contents[0][0] = array(
  135. 'td' => '',
  136. 'maxlength'=>500,
  137. 'text' => ($this->db->error().' sql='.$sql),
  138. );
  139. }
  140. } else {
  141. $this->info_box_contents[0][0] = array(
  142. 'td' => 'class="nohover opacitymedium left"',
  143. 'text' => $langs->trans("ReadPermissionNotAllowed")
  144. );
  145. }
  146. }
  147. /**
  148. * Method to show box
  149. *
  150. * @param array $head Array with properties of box title
  151. * @param array $contents Array with properties of box lines
  152. * @param int $nooutput No print, only return string
  153. * @return string
  154. */
  155. public function showBox($head = null, $contents = null, $nooutput = 0)
  156. {
  157. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  158. }
  159. }