dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27
28
33{
34 public $boxcode = "oldestunpaidsupplierbills";
35 public $boximg = "object_bill";
36 public $boxlabel = "BoxOldestUnpaidSupplierBills";
37 public $depends = array("facture", "fournisseur");
38
45 public function __construct($db, $param)
46 {
47 global $user;
48
49 $this->db = $db;
50
51 $this->hidden = !($user->hasRight('fournisseur', 'facture', 'lire'));
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $conf, $user, $langs;
63
64 $this->max = $max;
65 //$this->max = 1000;
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 $langs->load("bills");
74
75 $textHead = $langs->trans("BoxTitleOldestUnpaidSupplierBills");
76 $this->info_box_head = array(
77 'text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $this->max).'<a class="paddingleft valignmiddle" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status=1&sortfield=f.date_lim_reglement,f.ref&sortorder=ASC,ASC"><span class="badge">...</span></a>',
78 'limit' => dol_strlen($textHead)
79 );
80
81 if ($user->hasRight('fournisseur', 'facture', 'lire')) {
82 $sql1 = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql1 .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
84 $sql1 .= ", s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6";
85 $sql1 .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
86 $sql1 .= ", f.datef as df";
87 $sql1 .= ", f.total_ht";
88 $sql1 .= ", f.total_tva";
89 $sql1 .= ", f.total_ttc";
90 $sql1 .= ", f.paye, f.fk_statut as status, f.type";
91 $sql1 .= ", f.tms";
92 $sql1 .= ", SUM(pf.amount) as am";
93 $sql2 = " FROM ".MAIN_DB_PREFIX."societe as s";
94 $sql2 .= ",".MAIN_DB_PREFIX."facture_fourn as f";
95 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
96 if (!$user->hasRight('societe', 'client', 'voir')) {
97 $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98 }
99 $sql2 .= " WHERE f.fk_soc = s.rowid";
100 $sql2 .= " AND f.entity IN (".getEntity('supplier_invoice').")";
101 $sql2 .= " AND f.paye = 0";
102 $sql2 .= " AND fk_statut = 1";
103 if (!$user->hasRight('societe', 'client', 'voir')) {
104 $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105 }
106 if ($user->socid) {
107 $sql2 .= " AND s.rowid = ".((int) $user->socid);
108 }
109 $sql3 = " GROUP BY s.rowid, s.nom, s.name_alias, s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
110 $sql3 .= " f.rowid, f.ref, f.ref_supplier, f.date_lim_reglement,";
111 $sql3 .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.tms";
112 $sql3 .= " ORDER BY datelimite ASC, f.ref_supplier ASC";
113 $sql3 .= $this->db->plimit($this->max + 1, 0);
114
115 $sql = $sql1.$sql2.$sql3;
116
117 $result = $this->db->query($sql);
118 if ($result) {
119 $num = $this->db->num_rows($result);
120
121 $line = 0;
122 $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
123
124 while ($line < min($num, $this->max)) {
125 $objp = $this->db->fetch_object($result);
126
127 $datelimite = $this->db->jdate($objp->datelimite);
128 $date = $this->db->jdate($objp->df);
129 $datem = $this->db->jdate($objp->tms);
130
131 $facturestatic->id = $objp->facid;
132 $facturestatic->ref = $objp->ref;
133 $facturestatic->type = $objp->type;
134 $facturestatic->total_ht = $objp->total_ht;
135 $facturestatic->total_tva = $objp->total_tva;
136 $facturestatic->total_ttc = $objp->total_ttc;
137 $facturestatic->date = $date;
138 $facturestatic->date_echeance = $datelimite;
139 $facturestatic->statut = $objp->status;
140 $facturestatic->status = $objp->status;
141
142 //$alreadypaid = $facturestatic->getSommePaiement();
143
144 $facturestatic->paye = $objp->paye;
145 $facturestatic->paid = $objp->paye;
146 $facturestatic->alreadypaid = $objp->am;
147 $facturestatic->totalpaid = $objp->am;
148
149 $thirdpartystatic->id = $objp->socid;
150 $thirdpartystatic->name = $objp->name;
151 $thirdpartystatic->name_alias = $objp->name_alias;
152 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
153 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
154 $thirdpartystatic->fournisseur = $objp->fournisseur;
155 $thirdpartystatic->logo = $objp->logo;
156 $thirdpartystatic->email = $objp->email;
157 $thirdpartystatic->entity = $objp->entity;
158 $thirdpartystatic->tva_intra = $objp->tva_intra;
159 $thirdpartystatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 : '';
160 $thirdpartystatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 : '';
161 $thirdpartystatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 : '';
162 $thirdpartystatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 : '';
163 $thirdpartystatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 : '';
164 $thirdpartystatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 : '';
165
166 $late = '';
167 if ($facturestatic->hasDelay()) {
168 // @phan-suppress-next-line PhanPluginPrintfVariableFormatString
169 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
170 }
171
172 $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
173
174 $this->info_box_contents[$line][] = array(
175 'td' => 'class="nowraponall"',
176 'text' => $facturestatic->getNomUrl(1),
177 'text2' => $late,
178 'asis' => 1,
179 );
180
181 $this->info_box_contents[$line][] = array(
182 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
183 'text' => $thirdpartystatic->getNomUrl(1, '', 44),
184 'asis' => 1,
185 );
186
187 $this->info_box_contents[$line][] = array(
188 'td' => 'class="nowraponall right amount"',
189 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
190 );
191
192 $this->info_box_contents[$line][] = array(
193 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
194 'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
195 );
196
197 $this->info_box_contents[$line][] = array(
198 'td' => 'class="right" width="18"',
199 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
200 );
201
202 $line++;
203 }
204 if ($this->max < $num) {
205 $this->info_box_contents[$line][] = array('td' => 'colspan="6"', 'text' => '...');
206 $line++;
207 }
208
209 if ($num == 0) {
210 $this->info_box_contents[$line][0] = array(
211 'td' => 'class="center" colspan="3"',
212 'text' => '<span class="opacitymedium">'.$langs->trans("NoUnpaidSupplierBills").'</span>',
213 );
214 } else {
215 $sql = "SELECT SUM(f.total_ht) as total_ht ".$sql2;
216
217 $result = $this->db->query($sql);
218 $objp = $this->db->fetch_object($result);
219 $totalamount = $objp->total_ht;
220
221 // Add the sum à the bottom of the boxes
222 $this->info_box_contents[$line][] = array(
223 'tr' => 'class="liste_total_wrap"',
224 'td' => 'class="liste_total"',
225 'text' => $langs->trans("Total"),
226 );
227 $this->info_box_contents[$line][] = array(
228 'td' => 'class="liste_total"',
229 'text' => "&nbsp;",
230 );
231 $this->info_box_contents[$line][] = array(
232 'td' => 'class="right liste_total" ',
233 'text' => price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
234 );
235 $this->info_box_contents[$line][] = array(
236 'td' => 'class="liste_total"',
237 'text' => "&nbsp;",
238 );
239 $this->info_box_contents[$line][] = array(
240 'td' => 'class="liste_total"',
241 'text' => "&nbsp;",
242 );
243
244 $this->db->free($result);
245 }
246 } else {
247 $this->info_box_contents[0][0] = array(
248 'td' => '',
249 'maxlength' => 500,
250 'text' => ($this->db->error().' sql='.$sql),
251 );
252 }
253 } else {
254 $this->info_box_contents[0][0] = array(
255 'td' => 'class="nohover left"',
256 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
257 );
258 }
259 }
260
261
262
271 public function showBox($head = null, $contents = null, $nooutput = 0)
272 {
273 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
274 }
275}
Class to manage suppliers invoices.
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show not paid suppliers invoices.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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).
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...