dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
18  */
19 
25 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26 
27 
32 {
33  var $boxcode = "oldestunpaidsupplierbills";
34  var $boximg = "object_bill";
35  var $boxlabel = "BoxOldestUnpaidSupplierBills";
36  var $depends = array("facture","fournisseur");
37 
41  public $db;
42 
43  var $param;
44 
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
48 
55  function __construct($db,$param)
56  {
57  global $user;
58 
59  $this->db=$db;
60 
61  $this->hidden=! ($user->rights->fournisseur->facture->lire);
62  }
63 
70  function loadBox($max=5)
71  {
72  global $conf, $user, $langs, $db;
73 
74  $this->max=$max;
75 
76  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
77  $facturestatic=new FactureFournisseur($db);
78  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
79  $thirdpartytmp=new Fournisseur($db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills",$max));
82 
83  if ($user->rights->fournisseur->facture->lire)
84  {
85  $sql = "SELECT s.nom as name, s.rowid as socid,";
86  $sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite,";
87  $sql.= " f.amount, f.datef as df,";
88  $sql.= " f.total_ht as total_ht,";
89  $sql.= " f.tva as total_tva,";
90  $sql.= " f.total_ttc,";
91  $sql.= " f.paye, f.fk_statut, f.type";
92  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93  $sql.= ",".MAIN_DB_PREFIX."facture_fourn as f";
94  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95  $sql.= " WHERE f.fk_soc = s.rowid";
96  $sql.= " AND f.entity = ".$conf->entity;
97  $sql.= " AND f.paye=0";
98  $sql.= " AND fk_statut = 1";
99  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
100  if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
101  $sql.= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
102  $sql.= $db->plimit($max, 0);
103 
104  $result = $db->query($sql);
105  if ($result)
106  {
107  $num = $db->num_rows($result);
108 
109  $line = 0;
110  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
111 
112  $facturestatic = new FactureFournisseur($db);
113 
114  while ($line < $num)
115  {
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  $facturestatic->id = $objp->facid;
121  $facturestatic->ref = $objp->ref;
122  $facturestatic->total_ht = $objp->total_ht;
123  $facturestatic->total_tva = $objp->total_tva;
124  $facturestatic->total_ttc = $objp->total_ttc;
125  $facturestatic->date_echeance = $datelimite;
126  $facturestatic->statut = $objp->fk_statut;
127  $thirdpartytmp->id = $objp->socid;
128  $thirdpartytmp->name = $objp->name;
129  $thirdpartytmp->fournisseur = 1;
130  $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
131  $thirdpartytmp->logo = $objp->logo;
132 
133  $late='';
134  if ($facturestatic->hasDelay()) {
135  $late=img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));
136  }
137 
138  $tooltip = $langs->trans('SupplierInvoice') . ': ' . ($objp->ref?$objp->ref:$objp->facid) . '<br>' . $langs->trans('RefSupplier') . ': ' . $objp->ref_supplier;
139 
140  $this->info_box_contents[$line][] = array(
141  'td' => '',
142  'text' => $facturestatic->getNomUrl(1),
143  'text2'=> $late,
144  'asis' => 1
145  );
146 
147  $this->info_box_contents[$line][] = array(
148  'td' => '',
149  'text' => $thirdpartytmp->getNomUrl(1, '', 40),
150  'asis' => 1,
151  );
152 
153  $this->info_box_contents[$line][] = array(
154  'td' => 'class="right"',
155  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
156  );
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => 'class="right"',
160  'text' => dol_print_date($datelimite,'day'),
161  );
162 
163  $fac = new FactureFournisseur($db);
164  $fac->fetch($objp->facid);
165  $alreadypaid=$fac->getSommePaiement();
166  $this->info_box_contents[$line][] = array(
167  'td' => 'align="right" width="18"',
168  'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3,$alreadypaid,$objp->type),
169  );
170 
171  $line++;
172  }
173 
174  if ($num==0)
175  $this->info_box_contents[$line][0] = array(
176  'td' => 'align="center"',
177  'text'=>$langs->trans("NoUnpaidSupplierBills"),
178  );
179 
180  $db->free($result);
181  } else {
182  $this->info_box_contents[0][0] = array(
183  'td' => '',
184  'maxlength'=>500,
185  'text' => ($db->error().' sql='.$sql),
186  );
187  }
188  } else {
189  $this->info_box_contents[0][0] = array(
190  'td' => 'align="left" class="nohover opacitymedium"',
191  'text' => $langs->trans("ReadPermissionNotAllowed")
192  );
193  }
194  }
195 
204  function showBox($head = null, $contents = null, $nooutput=0)
205  {
206  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
207  }
208 }
209 
img_warning($titlealt='default', $moreatt='')
Show warning logo.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage suppliers invoices.
Class ModeleBoxes.
Class to manage suppliers.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
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).
Class to manage the box to show not payed suppliers invoices.