box_propales.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
  6. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/boxes/box_propales.php
  23. * \ingroup propales
  24. * \brief Module de generation de l'affichage de la box propales
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  27. /**
  28. * Class to manage the box to show last proposals
  29. */
  30. class box_propales extends ModeleBoxes
  31. {
  32. public $boxcode = "lastpropals";
  33. public $boximg = "object_propal";
  34. public $boxlabel = "BoxLastProposals";
  35. public $depends = array("propal"); // conf->propal->enabled
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  40. public $param;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. * @param string $param More parameters
  48. */
  49. public function __construct($db, $param)
  50. {
  51. global $user;
  52. $this->db = $db;
  53. $this->hidden = !($user->hasRight('propal', 'read'));
  54. }
  55. /**
  56. * Load data into info_box_contents array to show array later.
  57. *
  58. * @param int $max Maximum number of records to load
  59. * @return void
  60. */
  61. public function loadBox($max = 5)
  62. {
  63. global $user, $langs, $conf;
  64. $this->max = $max;
  65. include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  66. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  67. $propalstatic = new Propal($this->db);
  68. $societestatic = new Societe($this->db);
  69. $this->info_box_head = array('text' => $langs->trans("BoxTitleLast".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."Propals", $max));
  70. if ($user->rights->propale->lire) {
  71. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  72. $sql .= ", s.code_client, s.code_compta, s.client";
  73. $sql .= ", s.logo, s.email, s.entity";
  74. $sql .= ", p.rowid, p.ref, p.fk_statut as status, p.datep as dp, p.datec, p.fin_validite, p.date_cloture, p.total_ht, p.total_tva, p.total_ttc, p.tms";
  75. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  76. $sql .= ", ".MAIN_DB_PREFIX."propal as p";
  77. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  78. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  79. }
  80. $sql .= " WHERE p.fk_soc = s.rowid";
  81. $sql .= " AND p.entity IN (".getEntity('propal').")";
  82. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  83. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  84. }
  85. if ($user->socid) {
  86. $sql .= " AND s.rowid = ".((int) $user->socid);
  87. }
  88. if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
  89. $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
  90. } else {
  91. $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
  92. }
  93. $sql .= $this->db->plimit($max, 0);
  94. $result = $this->db->query($sql);
  95. if ($result) {
  96. $num = $this->db->num_rows($result);
  97. $now = dol_now();
  98. $line = 0;
  99. while ($line < $num) {
  100. $objp = $this->db->fetch_object($result);
  101. $date = $this->db->jdate($objp->dp);
  102. $datec = $this->db->jdate($objp->datec);
  103. $datem = $this->db->jdate($objp->tms);
  104. $dateterm = $this->db->jdate($objp->fin_validite);
  105. $dateclose = $this->db->jdate($objp->date_cloture);
  106. $propalstatic->id = $objp->rowid;
  107. $propalstatic->ref = $objp->ref;
  108. $propalstatic->total_ht = $objp->total_ht;
  109. $propalstatic->total_tva = $objp->total_tva;
  110. $propalstatic->total_ttc = $objp->total_ttc;
  111. $propalstatic->statut = $objp->status;
  112. $propalstatic->status = $objp->status;
  113. $propalstatic->date = $date;
  114. $societestatic->id = $objp->socid;
  115. $societestatic->name = $objp->name;
  116. //$societestatic->name_alias = $objp->name_alias;
  117. $societestatic->code_client = $objp->code_client;
  118. $societestatic->code_compta = $objp->code_compta;
  119. $societestatic->client = $objp->client;
  120. $societestatic->logo = $objp->logo;
  121. $societestatic->email = $objp->email;
  122. $societestatic->entity = $objp->entity;
  123. $late = '';
  124. if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
  125. $late = img_warning($langs->trans("Late"));
  126. }
  127. $this->info_box_contents[$line][] = array(
  128. 'td' => 'class="nowraponall"',
  129. 'text' => $propalstatic->getNomUrl(1),
  130. 'text2'=> $late,
  131. 'asis' => 1,
  132. );
  133. $this->info_box_contents[$line][] = array(
  134. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  135. 'text' => $societestatic->getNomUrl(1),
  136. 'asis' => 1,
  137. );
  138. $this->info_box_contents[$line][] = array(
  139. 'td' => 'class="nowraponall right amount"',
  140. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  141. );
  142. $this->info_box_contents[$line][] = array(
  143. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  144. 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
  145. );
  146. $this->info_box_contents[$line][] = array(
  147. 'td' => 'class="right" width="18"',
  148. 'text' => $propalstatic->LibStatut($objp->status, 3),
  149. );
  150. $line++;
  151. }
  152. if ($num == 0) {
  153. $this->info_box_contents[$line][0] = array(
  154. 'td' => 'class="center"',
  155. 'text'=>$langs->trans("NoRecordedProposals"),
  156. );
  157. }
  158. $this->db->free($result);
  159. } else {
  160. $this->info_box_contents[0][0] = array(
  161. 'td' => '',
  162. 'maxlength'=>500,
  163. 'text' => ($this->db->error().' sql='.$sql),
  164. );
  165. }
  166. } else {
  167. $this->info_box_contents[0][0] = array(
  168. 'td' => 'class="nohover opacitymedium left"',
  169. 'text' => $langs->trans("ReadPermissionNotAllowed")
  170. );
  171. }
  172. }
  173. /**
  174. * Method to show box
  175. *
  176. * @param array $head Array with properties of box title
  177. * @param array $contents Array with properties of box lines
  178. * @param int $nooutput No print, only return string
  179. * @return string
  180. */
  181. public function showBox($head = null, $contents = null, $nooutput = 0)
  182. {
  183. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  184. }
  185. }