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