dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
19  */
20 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  var $boxcode="lastsupplierbills";
35  var $boximg="object_bill";
36  var $boxlabel="BoxLastSupplierBills";
37  var $depends = array("facture","fournisseur");
38 
39  var $db;
40  var $param;
41 
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param)
53  {
54  global $user;
55 
56  $this->db=$db;
57 
58  $this->hidden=! ($user->rights->fournisseur->facture->lire);
59  }
60 
67  function loadBox($max=5)
68  {
69  global $conf, $user, $langs, $db;
70 
71  $this->max=$max;
72 
73  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
74  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
75 
76  $facturestatic = new FactureFournisseur($db);
77  $thirdpartytmp = new Fournisseur($db);
78 
79  $this->info_box_head = array(
80  'text' => $langs->trans("BoxTitleLast".($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE?"":"Modified")."SupplierBills",$max)
81  );
82 
83  if ($user->rights->fournisseur->facture->lire)
84  {
85  $sql = "SELECT s.nom as name, s.rowid as socid,";
86  $sql.= " s.code_fournisseur,";
87  $sql.= " s.logo,";
88  $sql.= " f.rowid as facid, f.ref, f.ref_supplier,";
89  $sql.= " f.total_ht,";
90  $sql.= " f.total_tva,";
91  $sql.= " f.total_ttc,";
92  $sql.= " f.paye, f.fk_statut,";
93  $sql.= ' f.datef as df,';
94  $sql.= ' f.datec as datec,';
95  $sql.= ' f.date_lim_reglement as datelimite, f.tms, f.type';
96  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
97  $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
98  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99  $sql.= " WHERE f.fk_soc = s.rowid";
100  $sql.= " AND f.entity = ".$conf->entity;
101  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
102  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
103  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.ref DESC ";
104  else $sql.= " ORDER BY f.tms DESC, f.ref DESC ";
105  $sql.= $db->plimit($max, 0);
106 
107  $result = $db->query($sql);
108  if ($result)
109  {
110  $num = $db->num_rows($result);
111 
112  $line = 0;
113  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
114 
115  while ($line < $num) {
116  $objp = $db->fetch_object($result);
117  $datelimite=$db->jdate($objp->datelimite);
118  $date=$db->jdate($objp->df);
119  $datem=$db->jdate($objp->tms);
120 
121  $facturestatic->id = $objp->facid;
122  $facturestatic->ref = $objp->ref;
123  $facturestatic->total_ht = $objp->total_ht;
124  $facturestatic->total_tva = $objp->total_tva;
125  $facturestatic->total_ttc = $objp->total_ttc;
126  $facturestatic->date_echeance = $datelimite;
127  $facturestatic->statut = $objp->fk_statut;
128  $facturestatic->ref_supplier = $objp->ref_supplier;
129 
130  $thirdpartytmp->id = $objp->socid;
131  $thirdpartytmp->name = $objp->name;
132  $thirdpartytmp->fournisseur = 1;
133  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
134  $thirdpartytmp->logo = $objp->logo;
135 
136  $late = '';
137 
138  if ($facturestatic->hasDelay()) {
139  $late=img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day')));
140  }
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => '',
144  'text' => $facturestatic->getNomUrl(1),
145  'text2'=> $late,
146  'asis' => 1,
147  );
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="tdoverflowmax50"',
151  'text' => $objp->ref_supplier,
152  'tooltip' => $langs->trans('SupplierInvoice').': '.($objp->ref?$objp->ref:$objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier,
153  'url' => DOL_URL_ROOT."/fourn/facture/card.php?facid=".$objp->facid,
154  );
155 
156  $this->info_box_contents[$line][] = array(
157  'td' => 'class="tdoverflowmax50"',
158  'text' => $thirdpartytmp->getNomUrl(1, 'supplier'),
159  'asis' => 1,
160  );
161 
162  $this->info_box_contents[$line][] = array(
163  'td' => 'class="right"',
164  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
165  );
166 
167  $this->info_box_contents[$line][] = array(
168  'td' => 'class="right"',
169  'text' => dol_print_date($date,'day'),
170  );
171 
172  $fac = new FactureFournisseur($db);
173  $fac->fetch($objp->facid);
174  $alreadypaid=$fac->getSommePaiement();
175  $this->info_box_contents[$line][] = array(
176  'td' => 'align="right" width="18"',
177  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3,$alreadypaid,$objp->type),
178  );
179 
180  $line++;
181  }
182 
183  if ($num==0)
184  $this->info_box_contents[$line][0] = array(
185  'td' => 'align="center"',
186  'text'=>$langs->trans("NoModifiedSupplierBills"),
187  );
188 
189  $db->free($result);
190  } else {
191  $this->info_box_contents[0][0] = array(
192  'td' => '',
193  'maxlength'=>500,
194  'text' => ($db->error().' sql='.$sql),
195  );
196  }
197  } else {
198  $this->info_box_contents[0][0] = array(
199  'td' => 'align="left" class="nohover opacitymedium"',
200  'text' => $langs->transnoentities("ReadPermissionNotAllowed")
201  );
202  }
203  }
204 
213  function showBox($head = null, $contents = null, $nooutput=0)
214  {
215  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
216  }
217 
218 }
219 
Class to manage suppliers invoices.
Class ModeleBoxes.
Class to manage suppliers.
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
Class to manage the box to show last supplier invoices.
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='tzserver', $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.