dolibarr  9.0.0
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 <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 
42  public $db;
43 
44  var $param;
45 
46  var $info_box_head = array();
47  var $info_box_contents = array();
48 
49 
56  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  function loadBox($max=5)
72  {
73  global $conf, $user, $langs, $db;
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($db);
81  $thirdpartytmp = new Fournisseur($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  $sql = "SELECT s.nom as name, s.rowid as socid,";
90  $sql.= " s.code_fournisseur,";
91  $sql.= " s.logo,";
92  $sql.= " f.rowid as facid, f.ref, f.ref_supplier,";
93  $sql.= " f.total_ht,";
94  $sql.= " f.total_tva,";
95  $sql.= " f.total_ttc,";
96  $sql.= " f.paye, f.fk_statut,";
97  $sql.= ' f.datef as df,';
98  $sql.= ' f.datec as datec,';
99  $sql.= ' f.date_lim_reglement as datelimite, f.tms, f.type';
100  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
101  $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f";
102  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
103  $sql.= " WHERE f.fk_soc = s.rowid";
104  $sql.= " AND f.entity = ".$conf->entity;
105  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
106  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
107  if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) $sql.= " ORDER BY f.datef DESC, f.ref DESC ";
108  else $sql.= " ORDER BY f.tms DESC, f.ref DESC ";
109  $sql.= $db->plimit($max, 0);
110 
111  $result = $db->query($sql);
112  if ($result)
113  {
114  $num = $db->num_rows($result);
115 
116  $line = 0;
117  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
118 
119  while ($line < $num) {
120  $objp = $db->fetch_object($result);
121  $datelimite=$db->jdate($objp->datelimite);
122  $date=$db->jdate($objp->df);
123  $datem=$db->jdate($objp->tms);
124 
125  $facturestatic->id = $objp->facid;
126  $facturestatic->ref = $objp->ref;
127  $facturestatic->total_ht = $objp->total_ht;
128  $facturestatic->total_tva = $objp->total_tva;
129  $facturestatic->total_ttc = $objp->total_ttc;
130  $facturestatic->date_echeance = $datelimite;
131  $facturestatic->statut = $objp->fk_statut;
132  $facturestatic->ref_supplier = $objp->ref_supplier;
133 
134  $thirdpartytmp->id = $objp->socid;
135  $thirdpartytmp->name = $objp->name;
136  $thirdpartytmp->fournisseur = 1;
137  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
138  $thirdpartytmp->logo = $objp->logo;
139 
140  $late = '';
141 
142  if ($facturestatic->hasDelay()) {
143  $late=img_warning(sprintf($l_due_date, dol_print_date($datelimite,'day')));
144  }
145 
146  $this->info_box_contents[$line][] = array(
147  'td' => '',
148  'text' => $facturestatic->getNomUrl(1),
149  'text2'=> $late,
150  'asis' => 1,
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'class="tdoverflowmax50"',
155  'text' => $objp->ref_supplier,
156  'tooltip' => $langs->trans('SupplierInvoice').': '.($objp->ref?$objp->ref:$objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier,
157  'url' => DOL_URL_ROOT."/fourn/facture/card.php?facid=".$objp->facid,
158  );
159 
160  $this->info_box_contents[$line][] = array(
161  'td' => 'class="tdoverflowmax50"',
162  'text' => $thirdpartytmp->getNomUrl(1, 'supplier'),
163  'asis' => 1,
164  );
165 
166  $this->info_box_contents[$line][] = array(
167  'td' => 'class="right"',
168  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
169  );
170 
171  $this->info_box_contents[$line][] = array(
172  'td' => 'class="right"',
173  'text' => dol_print_date($date,'day'),
174  );
175 
176  $fac = new FactureFournisseur($db);
177  $fac->fetch($objp->facid);
178  $alreadypaid=$fac->getSommePaiement();
179  $this->info_box_contents[$line][] = array(
180  'td' => 'align="right" width="18"',
181  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3,$alreadypaid,$objp->type),
182  );
183 
184  $line++;
185  }
186 
187  if ($num==0)
188  $this->info_box_contents[$line][0] = array(
189  'td' => 'align="center"',
190  'text'=>$langs->trans("NoModifiedSupplierBills"),
191  );
192 
193  $db->free($result);
194  } else {
195  $this->info_box_contents[0][0] = array(
196  'td' => '',
197  'maxlength'=>500,
198  'text' => ($db->error().' sql='.$sql),
199  );
200  }
201  } else {
202  $this->info_box_contents[0][0] = array(
203  'td' => 'align="left" class="nohover opacitymedium"',
204  'text' => $langs->transnoentities("ReadPermissionNotAllowed")
205  );
206  }
207  }
208 
217  function showBox($head = null, $contents = null, $nooutput=0)
218  {
219  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
220  }
221 }
222 
img_warning($titlealt='default', $moreatt='')
Show warning logo.
Class to manage suppliers invoices.
Class ModeleBoxes.
Class to manage suppliers.
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.