dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
18  */
19 
25 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
26 
27 
32 {
33  public $boxcode = "oldestunpaidsupplierbills";
34  public $boximg = "object_bill";
35  public $boxlabel = "BoxOldestUnpaidSupplierBills";
36  public $depends = array("facture", "fournisseur");
37 
41  public $db;
42 
43  public $param;
44 
45  public $info_box_head = array();
46  public $info_box_contents = array();
47 
48 
55  public 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  public function loadBox($max = 5)
71  {
72  global $conf, $user, $langs;
73 
74  $this->max = $max;
75 
76  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
77  $facturestatic = new FactureFournisseur($this->db);
78  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
79  $thirdpartystatic = new Fournisseur($this->db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $max));
82 
83  if ($user->rights->fournisseur->facture->lire)
84  {
85  $langs->load("bills");
86 
87  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
88  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
89  $sql .= ", s.logo, s.email, s.entity";
90  $sql .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
91  $sql .= ", f.datef as df";
92  $sql .= ", f.total_ht as total_ht";
93  $sql .= ", f.tva as total_tva";
94  $sql .= ", f.total_ttc";
95  $sql .= ", f.paye, f.fk_statut as status, 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->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99  $sql .= " WHERE f.fk_soc = s.rowid";
100  $sql .= " AND f.entity = ".$conf->entity;
101  $sql .= " AND f.paye = 0";
102  $sql .= " AND fk_statut = 1";
103  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
104  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
105  $sql .= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
106  $sql .= $this->db->plimit($max, 0);
107 
108  $result = $this->db->query($sql);
109  if ($result)
110  {
111  $num = $this->db->num_rows($result);
112 
113  $line = 0;
114  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
115 
116  $facturestatic = new FactureFournisseur($this->db);
117 
118  while ($line < $num)
119  {
120  $objp = $this->db->fetch_object($result);
121  $datelimite = $this->db->jdate($objp->datelimite);
122  $date = $this->db->jdate($objp->df);
123  $datem = $this->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->status;
132  $facturestatic->status = $objp->status;
133 
134  $thirdpartystatic->id = $objp->socid;
135  $thirdpartystatic->name = $objp->name;
136  $thirdpartystatic->name_alias = $objp->name_alias;
137  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
138  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
139  $thirdpartystatic->fournisseur = $objp->fournisseur;
140  $thirdpartystatic->logo = $objp->logo;
141  $thirdpartystatic->email = $objp->email;
142  $thirdpartystatic->entity = $objp->entity;
143 
144  $late = '';
145  if ($facturestatic->hasDelay()) {
146  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day')));
147  }
148 
149  $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
150 
151  $this->info_box_contents[$line][] = array(
152  'td' => 'class="nowraponall"',
153  'text' => $facturestatic->getNomUrl(1),
154  'text2'=> $late,
155  'asis' => 1
156  );
157 
158  $this->info_box_contents[$line][] = array(
159  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
160  'text' => $thirdpartystatic->getNomUrl(1, '', 40),
161  'asis' => 1,
162  );
163 
164  $this->info_box_contents[$line][] = array(
165  'td' => 'class="nowraponall right"',
166  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
167  );
168 
169  $this->info_box_contents[$line][] = array(
170  'td' => 'class="right"',
171  'text' => dol_print_date($datelimite, 'day'),
172  );
173 
174  $fac = new FactureFournisseur($this->db);
175  $fac->fetch($objp->facid);
176  $alreadypaid = $fac->getSommePaiement();
177  $this->info_box_contents[$line][] = array(
178  'td' => 'class="right" width="18"',
179  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
180  );
181 
182  $line++;
183  }
184 
185  if ($num == 0)
186  $this->info_box_contents[$line][0] = array(
187  'td' => 'class="center"',
188  'text'=>$langs->trans("NoUnpaidSupplierBills"),
189  );
190 
191  $this->db->free($result);
192  } else {
193  $this->info_box_contents[0][0] = array(
194  'td' => '',
195  'maxlength'=>500,
196  'text' => ($this->db->error().' sql='.$sql),
197  );
198  }
199  } else {
200  $this->info_box_contents[0][0] = array(
201  'td' => 'class="nohover opacitymedium left"',
202  'text' => $langs->trans("ReadPermissionNotAllowed")
203  );
204  }
205  }
206 
215  public function showBox($head = null, $contents = null, $nooutput = 0)
216  {
217  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
218  }
219 }
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage suppliers invoices.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage suppliers.
__construct($db, $param)
Constructor.
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...
loadBox($max=5)
Load data into info_box_contents array to show array later.
dol_print_date($time, $format= '', $tzoutput= 'auto', $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 paid suppliers invoices.