box_factures_fourn_imp.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/boxes/box_factures_fourn_imp.php
  21. * \ingroup fournisseur
  22. * \brief Fichier de gestion d'une box des factures fournisseurs impayees
  23. */
  24. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  25. /**
  26. * Class to manage the box to show not paid suppliers invoices
  27. */
  28. class box_factures_fourn_imp extends ModeleBoxes
  29. {
  30. public $boxcode = "oldestunpaidsupplierbills";
  31. public $boximg = "object_bill";
  32. public $boxlabel = "BoxOldestUnpaidSupplierBills";
  33. public $depends = array("facture", "fournisseur");
  34. /**
  35. * @var DoliDB Database handler.
  36. */
  37. public $db;
  38. public $param;
  39. public $info_box_head = array();
  40. public $info_box_contents = array();
  41. /**
  42. * Constructor
  43. *
  44. * @param DoliDB $db Database handler
  45. * @param string $param More parameters
  46. */
  47. public function __construct($db, $param)
  48. {
  49. global $user;
  50. $this->db = $db;
  51. $this->hidden = empty($user->rights->fournisseur->facture->lire);
  52. }
  53. /**
  54. * Load data into info_box_contents array to show array later.
  55. *
  56. * @param int $max Maximum number of records to load
  57. * @return void
  58. */
  59. public function loadBox($max = 5)
  60. {
  61. global $conf, $user, $langs;
  62. $this->max = $max;
  63. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  64. $facturestatic = new FactureFournisseur($this->db);
  65. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  66. $thirdpartystatic = new Fournisseur($this->db);
  67. $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $max));
  68. if ($user->rights->fournisseur->facture->lire) {
  69. $langs->load("bills");
  70. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
  71. $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
  72. $sql .= ", s.logo, s.email, s.entity";
  73. $sql .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
  74. $sql .= ", f.datef as df";
  75. $sql .= ", f.total_ht as total_ht";
  76. $sql .= ", f.tva as total_tva";
  77. $sql .= ", f.total_ttc";
  78. $sql .= ", f.paye, f.fk_statut as status, f.type";
  79. $sql .= ", f.tms";
  80. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  81. $sql .= ",".MAIN_DB_PREFIX."facture_fourn as f";
  82. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  83. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  84. }
  85. $sql .= " WHERE f.fk_soc = s.rowid";
  86. $sql .= " AND f.entity = ".$conf->entity;
  87. $sql .= " AND f.paye = 0";
  88. $sql .= " AND fk_statut = 1";
  89. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  90. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  91. }
  92. if ($user->socid) {
  93. $sql .= " AND s.rowid = ".((int) $user->socid);
  94. }
  95. $sql .= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
  96. $sql .= $this->db->plimit($max, 0);
  97. $result = $this->db->query($sql);
  98. if ($result) {
  99. $num = $this->db->num_rows($result);
  100. $line = 0;
  101. $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
  102. $facturestatic = new FactureFournisseur($this->db);
  103. while ($line < $num) {
  104. $objp = $this->db->fetch_object($result);
  105. $datelimite = $this->db->jdate($objp->datelimite);
  106. $date = $this->db->jdate($objp->df);
  107. $datem = $this->db->jdate($objp->tms);
  108. $facturestatic->id = $objp->facid;
  109. $facturestatic->ref = $objp->ref;
  110. $facturestatic->total_ht = $objp->total_ht;
  111. $facturestatic->total_tva = $objp->total_tva;
  112. $facturestatic->total_ttc = $objp->total_ttc;
  113. $facturestatic->date_echeance = $datelimite;
  114. $facturestatic->date = $date;
  115. $facturestatic->statut = $objp->status;
  116. $facturestatic->status = $objp->status;
  117. $alreadypaid = $facturestatic->getSommePaiement();
  118. $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
  119. $thirdpartystatic->id = $objp->socid;
  120. $thirdpartystatic->name = $objp->name;
  121. $thirdpartystatic->name_alias = $objp->name_alias;
  122. $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
  123. $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
  124. $thirdpartystatic->fournisseur = $objp->fournisseur;
  125. $thirdpartystatic->logo = $objp->logo;
  126. $thirdpartystatic->email = $objp->email;
  127. $thirdpartystatic->entity = $objp->entity;
  128. $late = '';
  129. if ($facturestatic->hasDelay()) {
  130. $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
  131. }
  132. $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
  133. $this->info_box_contents[$line][] = array(
  134. 'td' => 'class="nowraponall"',
  135. 'text' => $facturestatic->getNomUrl(1),
  136. 'text2'=> $late,
  137. 'asis' => 1
  138. );
  139. $this->info_box_contents[$line][] = array(
  140. 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
  141. 'text' => $thirdpartystatic->getNomUrl(1, '', 40),
  142. 'asis' => 1,
  143. );
  144. $this->info_box_contents[$line][] = array(
  145. 'td' => 'class="nowraponall right amount"',
  146. 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
  147. );
  148. $this->info_box_contents[$line][] = array(
  149. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
  150. 'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
  151. );
  152. $this->info_box_contents[$line][] = array(
  153. 'td' => 'class="right" width="18"',
  154. 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
  155. );
  156. $line++;
  157. }
  158. if ($num == 0) {
  159. $this->info_box_contents[$line][0] = array(
  160. 'td' => 'class="center"',
  161. 'text'=>$langs->trans("NoUnpaidSupplierBills"),
  162. );
  163. }
  164. $this->db->free($result);
  165. } else {
  166. $this->info_box_contents[0][0] = array(
  167. 'td' => '',
  168. 'maxlength'=>500,
  169. 'text' => ($this->db->error().' sql='.$sql),
  170. );
  171. }
  172. } else {
  173. $this->info_box_contents[0][0] = array(
  174. 'td' => 'class="nohover opacitymedium left"',
  175. 'text' => $langs->trans("ReadPermissionNotAllowed")
  176. );
  177. }
  178. }
  179. /**
  180. * Method to show box
  181. *
  182. * @param array $head Array with properties of box title
  183. * @param array $contents Array with properties of box lines
  184. * @param int $nooutput No print, only return string
  185. * @return string
  186. */
  187. public function showBox($head = null, $contents = null, $nooutput = 0)
  188. {
  189. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  190. }
  191. }