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