dolibarr  20.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@inodbox.com>
5  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
6  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
34 {
35  public $boxcode = "lastsupplierbills";
36  public $boximg = "object_bill";
37  public $boxlabel = "BoxLastSupplierBills";
38  public $depends = array("facture", "fournisseur");
39 
46  public function __construct($db, $param)
47  {
48  global $user;
49 
50  $this->db = $db;
51 
52  $this->hidden = !($user->hasRight('fournisseur', 'facture', 'lire'));
53  }
54 
61  public function loadBox($max = 5)
62  {
63  global $conf, $user, $langs;
64 
65  $this->max = $max;
66 
67  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
68  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
69 
70  $facturestatic = new FactureFournisseur($this->db);
71  $thirdpartystatic = new Fournisseur($this->db);
72 
73  $this->info_box_head = array(
74  'text' => $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierBills", $max)
75  );
76 
77  if ($user->hasRight('fournisseur', 'facture', 'lire')) {
78  $langs->load("bills");
79 
80  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
81  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
82  $sql .= ", s.logo, s.email, s.entity";
83  $sql .= ", f.rowid as facid, f.ref, f.ref_supplier";
84  $sql .= ", f.total_ht";
85  $sql .= ", f.total_tva";
86  $sql .= ", f.total_ttc";
87  $sql .= ", f.paye, f.fk_statut as status";
88  $sql .= ', f.datef as date';
89  $sql .= ', f.datec as datec';
90  $sql .= ', f.date_lim_reglement as datelimite, f.tms, f.type';
91  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
92  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
93  if (!$user->hasRight('societe', 'client', 'voir')) {
94  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
95  }
96  $sql .= " WHERE f.fk_soc = s.rowid";
97  $sql .= " AND f.entity = ".$conf->entity;
98  if (!$user->hasRight('societe', 'client', 'voir')) {
99  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
100  }
101  if ($user->socid) {
102  $sql .= " AND s.rowid = ".((int) $user->socid);
103  }
104  if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
105  $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
106  } else {
107  $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
108  }
109  $sql .= $this->db->plimit($max, 0);
110 
111  $result = $this->db->query($sql);
112  if ($result) {
113  $num = $this->db->num_rows($result);
114 
115  $line = 0;
116  $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
117 
118  while ($line < $num) {
119  $objp = $this->db->fetch_object($result);
120 
121  $datelimite = $this->db->jdate($objp->datelimite);
122  $date = $this->db->jdate($objp->date);
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 = $date;
131  $facturestatic->date_echeance = $datelimite;
132  $facturestatic->statut = $objp->status;
133  $facturestatic->status = $objp->status;
134  $facturestatic->ref_supplier = $objp->ref_supplier;
135 
136  $alreadypaid = $facturestatic->getSommePaiement();
137 
138  $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
139 
140  $thirdpartystatic->id = $objp->socid;
141  $thirdpartystatic->name = $objp->name;
142  $thirdpartystatic->name_alias = $objp->name_alias;
143  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
144  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
145  $thirdpartystatic->fournisseur = $objp->fournisseur;
146  $thirdpartystatic->logo = $objp->logo;
147  $thirdpartystatic->email = $objp->email;
148  $thirdpartystatic->entity = $objp->entity;
149 
150  $late = '';
151 
152  if ($facturestatic->hasDelay()) {
153  // @phan-suppress-next-line PhanPluginPrintfVariableFormatString
154  $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
155  }
156 
157  $this->info_box_contents[$line][] = array(
158  'td' => 'class="nowraponall"',
159  'text' => $facturestatic->getNomUrl(1),
160  'text2' => $late,
161  'asis' => 1,
162  );
163 
164  $this->info_box_contents[$line][] = array(
165  'td' => 'class="tdoverflowmax150"',
166  'text' => $objp->ref_supplier,
167  'tooltip' => $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier,
168  'url' => DOL_URL_ROOT."/fourn/facture/card.php?facid=".$objp->facid,
169  );
170 
171  $this->info_box_contents[$line][] = array(
172  'td' => 'class="tdoverflowmax150"',
173  'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
174  'asis' => 1,
175  );
176 
177  $this->info_box_contents[$line][] = array(
178  'td' => 'class="nowraponall right amount"',
179  'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
180  );
181 
182  $this->info_box_contents[$line][] = array(
183  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
184  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
185  );
186 
187  $this->info_box_contents[$line][] = array(
188  'td' => 'class="right" width="18"',
189  'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
190  );
191 
192  $line++;
193  }
194 
195  if ($num == 0) {
196  $this->info_box_contents[$line][0] = array(
197  'td' => 'class="center"',
198  'text' => '<span class="opacitymedium">'.$langs->trans("NoModifiedSupplierBills").'</span>',
199  );
200  }
201 
202  $this->db->free($result);
203  } else {
204  $this->info_box_contents[0][0] = array(
205  'td' => '',
206  'maxlength' => 500,
207  'text' => ($this->db->error().' sql='.$sql),
208  );
209  }
210  } else {
211  $this->info_box_contents[0][0] = array(
212  'td' => 'class="nohover left"',
213  'text' => '<span class="opacitymedium">'.$langs->transnoentities("ReadPermissionNotAllowed").'</span>'
214  );
215  }
216  }
217 
226  public function showBox($head = null, $contents = null, $nooutput = 0)
227  {
228  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
229  }
230 }
Class to manage suppliers invoices.
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show last supplier invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Load data into info_box_contents array to show array later.
__construct($db, $param)
Constructor.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...