box_factures_fourn.php 7.8 KB

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