box_factures.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2009 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_factures.php
  22. * \ingroup factures
  23. * \brief Module de generation de l'affichage de la box factures
  24. */
  25. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  26. /**
  27. * Class to manage the box to show last invoices
  28. */
  29. class box_factures extends ModeleBoxes
  30. {
  31. public $boxcode = "lastcustomerbills";
  32. public $boximg = "object_bill";
  33. public $boxlabel = "BoxLastCustomerBills";
  34. public $depends = array("facture");
  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 = empty($user->rights->facture->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. $this->max = $max;
  64. include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  65. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  66. $facturestatic = new Facture($this->db);
  67. $societestatic = new Societe($this->db);
  68. $langs->load("bills");
  69. $text = $langs->trans("BoxTitleLast".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."CustomerBills", $max);
  70. $this->info_box_head = array(
  71. 'text' => $text,
  72. 'limit'=> dol_strlen($text)
  73. );
  74. if ($user->rights->facture->lire) {
  75. $sql = "SELECT f.rowid as facid";
  76. $sql .= ", f.ref, f.type, f.total_ht";
  77. $sql .= ", f.total_tva";
  78. $sql .= ", f.total_ttc";
  79. $sql .= ", f.datef as date";
  80. $sql .= ", f.paye, f.fk_statut as status, f.datec, f.tms";
  81. $sql .= ", f.date_lim_reglement as datelimite";
  82. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  83. $sql .= ", s.code_client, s.code_compta, s.client";
  84. $sql .= ", s.logo, s.email, s.entity";
  85. $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
  86. $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
  87. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  88. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  89. }
  90. $sql .= " WHERE f.fk_soc = s.rowid";
  91. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  92. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  93. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  94. }
  95. if ($user->socid) {
  96. $sql .= " AND s.rowid = ".((int) $user->socid);
  97. }
  98. if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
  99. $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
  100. } else {
  101. $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
  102. }
  103. $sql .= $this->db->plimit($max, 0);
  104. $result = $this->db->query($sql);
  105. if ($result) {
  106. $num = $this->db->num_rows($result);
  107. $now = dol_now();
  108. $line = 0;
  109. $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
  110. while ($line < $num) {
  111. $objp = $this->db->fetch_object($result);
  112. $datelimite = $this->db->jdate($objp->datelimite);
  113. $date = $this->db->jdate($objp->date);
  114. $datem = $this->db->jdate($objp->tms);
  115. $facturestatic->id = $objp->facid;
  116. $facturestatic->ref = $objp->ref;
  117. $facturestatic->type = $objp->type;
  118. $facturestatic->total_ht = $objp->total_ht;
  119. $facturestatic->total_tva = $objp->total_tva;
  120. $facturestatic->total_ttc = $objp->total_ttc;
  121. $facturestatic->statut = $objp->status;
  122. $facturestatic->status = $objp->status;
  123. $facturestatic->date = $this->db->jdate($objp->date);
  124. $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
  125. $facturestatic->alreadypaid = $objp->paye;
  126. $societestatic->id = $objp->socid;
  127. $societestatic->name = $objp->name;
  128. //$societestatic->name_alias = $objp->name_alias;
  129. $societestatic->code_client = $objp->code_client;
  130. $societestatic->code_compta = $objp->code_compta;
  131. $societestatic->client = $objp->client;
  132. $societestatic->logo = $objp->logo;
  133. $societestatic->email = $objp->email;
  134. $societestatic->entity = $objp->entity;
  135. $societestatic->tva_intra = $objp->tva_intra;
  136. $societestatic->idprof1 = $objp->idprof1;
  137. $societestatic->idprof2 = $objp->idprof2;
  138. $societestatic->idprof3 = $objp->idprof3;
  139. $societestatic->idprof4 = $objp->idprof4;
  140. $societestatic->idprof5 = $objp->idprof5;
  141. $societestatic->idprof6 = $objp->idprof6;
  142. $late = '';
  143. if ($facturestatic->hasDelay()) {
  144. $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
  145. }
  146. $this->info_box_contents[$line][] = array(
  147. 'td' => 'class="nowraponall"',
  148. 'text' => $facturestatic->getNomUrl(1),
  149. 'text2'=> $late,
  150. 'asis' => 1,
  151. );
  152. $this->info_box_contents[$line][] = array(
  153. 'td' => 'class="tdoverflowmax200"',
  154. 'text' => $societestatic->getNomUrl(1, '', 40),
  155. 'asis' => 1,
  156. );
  157. $this->info_box_contents[$line][] = array(
  158. 'td' => 'class="right nowraponall amount"',
  159. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  160. );
  161. $this->info_box_contents[$line][] = array(
  162. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  163. 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
  164. );
  165. $this->info_box_contents[$line][] = array(
  166. 'td' => 'class="right" width="18"',
  167. 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->paye),
  168. );
  169. $line++;
  170. }
  171. if ($num == 0) {
  172. $this->info_box_contents[$line][0] = array(
  173. 'td' => 'class="center"',
  174. 'text'=>$langs->trans("NoRecordedInvoices"),
  175. );
  176. }
  177. $this->db->free($result);
  178. } else {
  179. $this->info_box_contents[0][0] = array(
  180. 'td' => '',
  181. 'maxlength'=>500,
  182. 'text' => ($this->db->error().' sql='.$sql),
  183. );
  184. }
  185. } else {
  186. $this->info_box_contents[0][0] = array(
  187. 'td' => 'class="nohover opacitymedium left"',
  188. 'text' => $langs->trans("ReadPermissionNotAllowed")
  189. );
  190. }
  191. }
  192. /**
  193. * Method to show box
  194. *
  195. * @param array $head Array with properties of box title
  196. * @param array $contents Array with properties of box lines
  197. * @param int $nooutput No print, only return string
  198. * @return string
  199. */
  200. public function showBox($head = null, $contents = null, $nooutput = 0)
  201. {
  202. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  203. }
  204. }