box_clients.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 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_clients.php
  22. * \ingroup societes
  23. * \brief Module de generation de l'affichage de la box clients
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last thirdparties
  28. */
  29. class box_clients extends ModeleBoxes
  30. {
  31. public $boxcode = "lastcustomers";
  32. public $boximg = "object_company";
  33. public $boxlabel = "BoxLastCustomers";
  34. public $depends = array("societe");
  35. /**
  36. * @var DoliDB Database handler.
  37. */
  38. public $db;
  39. public $enabled = 1;
  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 $conf, $user;
  51. $this->db = $db;
  52. // disable box for such cases
  53. if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled = 0; // disabled by this option
  54. $this->hidden = !($user->rights->societe->lire && empty($user->socid));
  55. }
  56. /**
  57. * Load data for box to show them later
  58. *
  59. * @param int $max Maximum number of records to load
  60. * @return void
  61. */
  62. public function loadBox($max = 5)
  63. {
  64. global $user, $langs, $conf;
  65. $langs->load("boxes");
  66. $this->max = $max;
  67. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  68. $thirdpartystatic = new Societe($this->db);
  69. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers", $max));
  70. if ($user->rights->societe->lire)
  71. {
  72. $sql = "SELECT s.nom as name, s.rowid as socid";
  73. $sql .= ", s.code_client";
  74. $sql .= ", s.client";
  75. $sql .= ", s.code_fournisseur";
  76. $sql .= ", s.fournisseur";
  77. $sql .= ", s.code_compta";
  78. $sql .= ", s.code_compta_fournisseur";
  79. $sql .= ", s.logo";
  80. $sql .= ", s.email";
  81. $sql .= ", s.datec, s.tms, s.status, s.entity";
  82. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  83. if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  84. $sql .= " WHERE s.client IN (1, 3)";
  85. $sql .= " AND s.entity IN (".getEntity('societe').")";
  86. if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
  87. if ($user->socid) $sql .= " AND s.rowid = $user->socid";
  88. $sql .= " ORDER BY s.tms DESC";
  89. $sql .= $this->db->plimit($max, 0);
  90. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  91. $result = $this->db->query($sql);
  92. if ($result)
  93. {
  94. $num = $this->db->num_rows($result);
  95. $line = 0;
  96. while ($line < $num)
  97. {
  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->code_client = $objp->code_client;
  104. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  105. $thirdpartystatic->code_compta = $objp->code_compta;
  106. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  107. $thirdpartystatic->client = $objp->client;
  108. $thirdpartystatic->fournisseur = $objp->fournisseur;
  109. $thirdpartystatic->logo = $objp->logo;
  110. $thirdpartystatic->email = $objp->email;
  111. $thirdpartystatic->entity = $objp->entity;
  112. $this->info_box_contents[$line][] = array(
  113. 'td' => '',
  114. 'text' => $thirdpartystatic->getNomUrl(1),
  115. 'asis' => 1,
  116. );
  117. $this->info_box_contents[$line][] = array(
  118. 'td' => 'class="right"',
  119. 'text' => dol_print_date($datem, "day")
  120. );
  121. $this->info_box_contents[$line][] = array(
  122. 'td' => 'class="right" width="18"',
  123. 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
  124. );
  125. $line++;
  126. }
  127. if ($num == 0) $this->info_box_contents[$line][0] = array(
  128. 'td' => 'class="center opacitymedium"',
  129. 'text'=>$langs->trans("NoRecordedCustomers")
  130. );
  131. $this->db->free($result);
  132. }
  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. }
  141. else {
  142. $this->info_box_contents[0][0] = array(
  143. 'td' => 'class="nohover opacitymedium 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 string
  155. */
  156. public function showBox($head = null, $contents = null, $nooutput = 0)
  157. {
  158. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  159. }
  160. }