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