dolibarr 20.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 * 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
27include_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 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."SupplierBills", $max);
74 $this->info_box_head = array(
75 'text' => $text.'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>'
76 );
77
78 if ($user->hasRight('fournisseur', 'facture', 'lire')) {
79 $langs->load("bills");
80
81 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
82 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
83 $sql .= ", s.logo, s.email, s.entity";
84 $sql .= ", f.rowid as facid, f.ref, f.ref_supplier";
85 $sql .= ", f.total_ht";
86 $sql .= ", f.total_tva";
87 $sql .= ", f.total_ttc";
88 $sql .= ", f.paye, f.fk_statut as status";
89 $sql .= ', f.datef as date';
90 $sql .= ', f.datec as datec';
91 $sql .= ', f.date_lim_reglement as datelimite, f.tms, f.type';
92 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
93 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
94 if (!$user->hasRight('societe', 'client', 'voir')) {
95 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
96 }
97 $sql .= " WHERE f.fk_soc = s.rowid";
98 $sql .= " AND f.entity = ".$conf->entity;
99 if (!$user->hasRight('societe', 'client', 'voir')) {
100 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
101 }
102 if ($user->socid) {
103 $sql .= " AND s.rowid = ".((int) $user->socid);
104 }
105 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
106 $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
107 } else {
108 $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
109 }
110 $sql .= $this->db->plimit($max, 0);
111
112 $result = $this->db->query($sql);
113 if ($result) {
114 $num = $this->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 = $this->db->fetch_object($result);
121
122 $datelimite = $this->db->jdate($objp->datelimite);
123 $date = $this->db->jdate($objp->date);
124 $datem = $this->db->jdate($objp->tms);
125
126 $facturestatic->id = $objp->facid;
127 $facturestatic->ref = $objp->ref;
128 $facturestatic->total_ht = $objp->total_ht;
129 $facturestatic->total_tva = $objp->total_tva;
130 $facturestatic->total_ttc = $objp->total_ttc;
131 $facturestatic->date = $date;
132 $facturestatic->date_echeance = $datelimite;
133 $facturestatic->statut = $objp->status;
134 $facturestatic->status = $objp->status;
135 $facturestatic->ref_supplier = $objp->ref_supplier;
136
137 $alreadypaid = $facturestatic->getSommePaiement();
138
139 $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
140
141 $thirdpartystatic->id = $objp->socid;
142 $thirdpartystatic->name = $objp->name;
143 $thirdpartystatic->name_alias = $objp->name_alias;
144 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
145 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
146 $thirdpartystatic->fournisseur = $objp->fournisseur;
147 $thirdpartystatic->logo = $objp->logo;
148 $thirdpartystatic->email = $objp->email;
149 $thirdpartystatic->entity = $objp->entity;
150
151 $late = '';
152
153 if ($facturestatic->hasDelay()) {
154 // @phan-suppress-next-line PhanPluginPrintfVariableFormatString
155 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
156 }
157
158 $this->info_box_contents[$line][] = array(
159 'td' => 'class="nowraponall"',
160 'text' => $facturestatic->getNomUrl(1),
161 'text2' => $late,
162 'asis' => 1,
163 );
164
165 $this->info_box_contents[$line][] = array(
166 'td' => 'class="tdoverflowmax150"',
167 'text' => $objp->ref_supplier,
168 'tooltip' => $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier,
169 'url' => DOL_URL_ROOT."/fourn/facture/card.php?facid=".$objp->facid,
170 );
171
172 $this->info_box_contents[$line][] = array(
173 'td' => 'class="tdoverflowmax150"',
174 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
175 'asis' => 1,
176 );
177
178 $this->info_box_contents[$line][] = array(
179 'td' => 'class="nowraponall right amount"',
180 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
181 );
182
183 $this->info_box_contents[$line][] = array(
184 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
185 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
186 );
187
188 $this->info_box_contents[$line][] = array(
189 'td' => 'class="right" width="18"',
190 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
191 );
192
193 $line++;
194 }
195
196 if ($num == 0) {
197 $this->info_box_contents[$line][0] = array(
198 'td' => 'class="center"',
199 'text' => '<span class="opacitymedium">'.$langs->trans("NoModifiedSupplierBills").'</span>',
200 );
201 }
202
203 $this->db->free($result);
204 } else {
205 $this->info_box_contents[0][0] = array(
206 'td' => '',
207 'maxlength' => 500,
208 'text' => ($this->db->error().' sql='.$sql),
209 );
210 }
211 } else {
212 $this->info_box_contents[0][0] = array(
213 'td' => 'class="nohover left"',
214 'text' => '<span class="opacitymedium">'.$langs->transnoentities("ReadPermissionNotAllowed").'</span>'
215 );
216 }
217 }
218
227 public function showBox($head = null, $contents = null, $nooutput = 0)
228 {
229 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
230 }
231}
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.
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...