dolibarr  17.0.4
box_factures_fourn_imp.php
Go to the documentation of this file.
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 
25 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26 
27 
32 {
33  public $boxcode = "oldestunpaidsupplierbills";
34  public $boximg = "object_bill";
35  public $boxlabel = "BoxOldestUnpaidSupplierBills";
36  public $depends = array("facture", "fournisseur");
37 
41  public $db;
42 
43  public $param;
44 
45  public $info_box_head = array();
46  public $info_box_contents = array();
47 
48 
55  public function __construct($db, $param)
56  {
57  global $user;
58 
59  $this->db = $db;
60 
61  $this->hidden = !($user->hasRight('fournisseur', 'facture', 'lire'));
62  }
63 
70  public function loadBox($max = 5)
71  {
72  global $conf, $user, $langs;
73 
74  $this->max = $max;
75 
76  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
77  $facturestatic = new FactureFournisseur($this->db);
78  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
79  $thirdpartystatic = new Fournisseur($this->db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $max));
82 
83  if ($user->rights->fournisseur->facture->lire) {
84  $langs->load("bills");
85 
86  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
87  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
88  $sql .= ", s.logo, s.email, s.entity";
89  $sql .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
90  $sql .= ", f.datef as df";
91  $sql .= ", f.total_ht as total_ht";
92  $sql .= ", f.tva as total_tva";
93  $sql .= ", f.total_ttc";
94  $sql .= ", f.paye, f.fk_statut as status, f.type";
95  $sql .= ", f.tms";
96  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
97  $sql .= ",".MAIN_DB_PREFIX."facture_fourn as f";
98  if (empty($user->rights->societe->client->voir) && !$user->socid) {
99  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
100  }
101  $sql .= " WHERE f.fk_soc = s.rowid";
102  $sql .= " AND f.entity = ".$conf->entity;
103  $sql .= " AND f.paye = 0";
104  $sql .= " AND fk_statut = 1";
105  if (empty($user->rights->societe->client->voir) && !$user->socid) {
106  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107  }
108  if ($user->socid) {
109  $sql .= " AND s.rowid = ".((int) $user->socid);
110  }
111  $sql .= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
112  $sql .= $this->db->plimit($max, 0);
113 
114  $result = $this->db->query($sql);
115  if ($result) {
116  $num = $this->db->num_rows($result);
117 
118  $line = 0;
119  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
120 
121  $facturestatic = new FactureFournisseur($this->db);
122 
123  while ($line < $num) {
124  $objp = $this->db->fetch_object($result);
125  $datelimite = $this->db->jdate($objp->datelimite);
126  $date = $this->db->jdate($objp->df);
127  $datem = $this->db->jdate($objp->tms);
128 
129  $facturestatic->id = $objp->facid;
130  $facturestatic->ref = $objp->ref;
131  $facturestatic->total_ht = $objp->total_ht;
132  $facturestatic->total_tva = $objp->total_tva;
133  $facturestatic->total_ttc = $objp->total_ttc;
134  $facturestatic->date_echeance = $datelimite;
135  $facturestatic->date = $date;
136  $facturestatic->statut = $objp->status;
137  $facturestatic->status = $objp->status;
138 
139  $alreadypaid = $facturestatic->getSommePaiement();
140 
141  $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
142 
143  $thirdpartystatic->id = $objp->socid;
144  $thirdpartystatic->name = $objp->name;
145  $thirdpartystatic->name_alias = $objp->name_alias;
146  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
147  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
148  $thirdpartystatic->fournisseur = $objp->fournisseur;
149  $thirdpartystatic->logo = $objp->logo;
150  $thirdpartystatic->email = $objp->email;
151  $thirdpartystatic->entity = $objp->entity;
152 
153  $late = '';
154  if ($facturestatic->hasDelay()) {
155  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
156  }
157 
158  $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
159 
160  $this->info_box_contents[$line][] = array(
161  'td' => 'class="nowraponall"',
162  'text' => $facturestatic->getNomUrl(1),
163  'text2'=> $late,
164  'asis' => 1
165  );
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
169  'text' => $thirdpartystatic->getNomUrl(1, '', 40),
170  'asis' => 1,
171  );
172 
173  $this->info_box_contents[$line][] = array(
174  'td' => 'class="nowraponall right amount"',
175  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
176  );
177 
178  $this->info_box_contents[$line][] = array(
179  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
180  'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
181  );
182 
183  $this->info_box_contents[$line][] = array(
184  'td' => 'class="right" width="18"',
185  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
186  );
187 
188  $line++;
189  }
190 
191  if ($num == 0) {
192  $this->info_box_contents[$line][0] = array(
193  'td' => 'class="center"',
194  'text'=>$langs->trans("NoUnpaidSupplierBills"),
195  );
196  }
197 
198  $this->db->free($result);
199  } else {
200  $this->info_box_contents[0][0] = array(
201  'td' => '',
202  'maxlength'=>500,
203  'text' => ($this->db->error().' sql='.$sql),
204  );
205  }
206  } else {
207  $this->info_box_contents[0][0] = array(
208  'td' => 'class="nohover opacitymedium left"',
209  'text' => $langs->trans("ReadPermissionNotAllowed")
210  );
211  }
212  }
213 
222  public function showBox($head = null, $contents = null, $nooutput = 0)
223  {
224  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
225  }
226 }
Class to manage suppliers invoices.
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show not paid suppliers invoices.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
$conf db
API class for accounts.
Definition: inc.php:41