box_propales.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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->propal->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."propal as p, ".MAIN_DB_PREFIX."societe as s";
  76. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  77. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  78. }
  79. $sql .= " WHERE p.fk_soc = s.rowid";
  80. $sql .= " AND p.entity IN (".getEntity('propal').")";
  81. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  82. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  83. }
  84. if ($user->socid) {
  85. $sql .= " AND s.rowid = ".((int) $user->socid);
  86. }
  87. if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
  88. $sql .= " ORDER BY p.datep DESC, p.ref DESC ";
  89. } else {
  90. $sql .= " ORDER BY p.tms DESC, p.ref DESC ";
  91. }
  92. $sql .= $this->db->plimit($max, 0);
  93. $result = $this->db->query($sql);
  94. if ($result) {
  95. $num = $this->db->num_rows($result);
  96. $now = dol_now();
  97. $line = 0;
  98. while ($line < $num) {
  99. $objp = $this->db->fetch_object($result);
  100. $date = $this->db->jdate($objp->dp);
  101. $datec = $this->db->jdate($objp->datec);
  102. $datem = $this->db->jdate($objp->tms);
  103. $dateterm = $this->db->jdate($objp->fin_validite);
  104. $dateclose = $this->db->jdate($objp->date_cloture);
  105. $propalstatic->id = $objp->rowid;
  106. $propalstatic->ref = $objp->ref;
  107. $propalstatic->total_ht = $objp->total_ht;
  108. $propalstatic->total_tva = $objp->total_tva;
  109. $propalstatic->total_ttc = $objp->total_ttc;
  110. $propalstatic->statut = $objp->status;
  111. $propalstatic->status = $objp->status;
  112. $propalstatic->date = $date;
  113. $societestatic->id = $objp->socid;
  114. $societestatic->name = $objp->name;
  115. //$societestatic->name_alias = $objp->name_alias;
  116. $societestatic->code_client = $objp->code_client;
  117. $societestatic->code_compta = $objp->code_compta;
  118. $societestatic->client = $objp->client;
  119. $societestatic->logo = $objp->logo;
  120. $societestatic->email = $objp->email;
  121. $societestatic->entity = $objp->entity;
  122. $late = '';
  123. if ($objp->status == 1 && $dateterm < ($now - $conf->propal->cloture->warning_delay)) {
  124. $late = img_warning($langs->trans("Late"));
  125. }
  126. $this->info_box_contents[$line][] = array(
  127. 'td' => 'class="nowraponall"',
  128. 'text' => $propalstatic->getNomUrl(1),
  129. 'text2'=> $late,
  130. 'asis' => 1,
  131. );
  132. $this->info_box_contents[$line][] = array(
  133. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  134. 'text' => $societestatic->getNomUrl(1),
  135. 'asis' => 1,
  136. );
  137. $this->info_box_contents[$line][] = array(
  138. 'td' => 'class="nowraponall right amount"',
  139. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  140. );
  141. $this->info_box_contents[$line][] = array(
  142. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  143. 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
  144. );
  145. $this->info_box_contents[$line][] = array(
  146. 'td' => 'class="right" width="18"',
  147. 'text' => $propalstatic->LibStatut($objp->status, 3),
  148. );
  149. $line++;
  150. }
  151. if ($num == 0) {
  152. $this->info_box_contents[$line][0] = array(
  153. 'td' => 'class="center"',
  154. 'text'=>$langs->trans("NoRecordedProposals"),
  155. );
  156. }
  157. $this->db->free($result);
  158. } else {
  159. $this->info_box_contents[0][0] = array(
  160. 'td' => '',
  161. 'maxlength'=>500,
  162. 'text' => ($this->db->error().' sql='.$sql),
  163. );
  164. }
  165. } else {
  166. $this->info_box_contents[0][0] = array(
  167. 'td' => 'class="nohover opacitymedium left"',
  168. 'text' => $langs->trans("ReadPermissionNotAllowed")
  169. );
  170. }
  171. }
  172. /**
  173. * Method to show box
  174. *
  175. * @param array $head Array with properties of box title
  176. * @param array $contents Array with properties of box lines
  177. * @param int $nooutput No print, only return string
  178. * @return string
  179. */
  180. public function showBox($head = null, $contents = null, $nooutput = 0)
  181. {
  182. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  183. }
  184. }