dolibarr 19.0.3
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
25include_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->hasRight('fournisseur', 'facture', 'lire'));
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $conf, $user, $langs;
73
74 $this->max = $max;
75 //$this->max = 1000;
76
77 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
78 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
79
80 $facturestatic = new FactureFournisseur($this->db);
81 $thirdpartystatic = new Fournisseur($this->db);
82
83 $langs->load("bills");
84
85 $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidSupplierBills", $this->max));
86
87 if ($user->hasRight('fournisseur', 'facture', 'lire')) {
88 $sql1 = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
89 $sql1 .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
90 $sql1 .= ", s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6";
91 $sql1 .= ", f.rowid as facid, f.ref, f.ref_supplier, f.date_lim_reglement as datelimite";
92 $sql1 .= ", f.datef as df";
93 $sql1 .= ", f.total_ht";
94 $sql1 .= ", f.total_tva";
95 $sql1 .= ", f.total_ttc";
96 $sql1 .= ", f.paye, f.fk_statut as status, f.type";
97 $sql1 .= ", f.tms";
98 $sql1 .= ", SUM(pf.amount) as am";
99 $sql2 = " FROM ".MAIN_DB_PREFIX."societe as s";
100 $sql2 .= ",".MAIN_DB_PREFIX."facture_fourn as f";
101 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf ON f.rowid = pf.fk_facturefourn";
102 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
103 $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
104 }
105 $sql2 .= " WHERE f.fk_soc = s.rowid";
106 $sql2 .= " AND f.entity IN (".getEntity('supplier_invoice').")";
107 $sql2 .= " AND f.paye = 0";
108 $sql2 .= " AND fk_statut = 1";
109 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
110 $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
111 }
112 if ($user->socid) {
113 $sql2 .= " AND s.rowid = ".((int) $user->socid);
114 }
115 $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,";
116 $sql3 .= " f.rowid, f.ref, f.ref_supplier, f.date_lim_reglement,";
117 $sql3 .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut, f.tms";
118 $sql3 .= " ORDER BY datelimite DESC, f.ref_supplier DESC ";
119 $sql3 .= $this->db->plimit($this->max + 1, 0);
120
121 $sql = $sql1.$sql2.$sql3;
122
123 $result = $this->db->query($sql);
124 if ($result) {
125 $num = $this->db->num_rows($result);
126
127 $line = 0;
128 $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
129
130 while ($line < min($num, $this->max)) {
131 $objp = $this->db->fetch_object($result);
132
133 $datelimite = $this->db->jdate($objp->datelimite);
134 $date = $this->db->jdate($objp->df);
135 $datem = $this->db->jdate($objp->tms);
136
137 $facturestatic->id = $objp->facid;
138 $facturestatic->ref = $objp->ref;
139 $facturestatic->type = $objp->type;
140 $facturestatic->total_ht = $objp->total_ht;
141 $facturestatic->total_tva = $objp->total_tva;
142 $facturestatic->total_ttc = $objp->total_ttc;
143 $facturestatic->date = $date;
144 $facturestatic->date_echeance = $datelimite;
145 $facturestatic->statut = $objp->status;
146 $facturestatic->status = $objp->status;
147
148 //$alreadypaid = $facturestatic->getSommePaiement();
149
150 $facturestatic->paye = $objp->paye;
151 $facturestatic->alreadypaid = $objp->am;
152
153 $thirdpartystatic->id = $objp->socid;
154 $thirdpartystatic->name = $objp->name;
155 $thirdpartystatic->name_alias = $objp->name_alias;
156 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
157 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
158 $thirdpartystatic->fournisseur = $objp->fournisseur;
159 $thirdpartystatic->logo = $objp->logo;
160 $thirdpartystatic->email = $objp->email;
161 $thirdpartystatic->entity = $objp->entity;
162 $thirdpartystatic->tva_intra = $objp->tva_intra;
163 $thirdpartystatic->idprof1 = !empty($objp->idprof1) ? $objp->idprof1 : '';
164 $thirdpartystatic->idprof2 = !empty($objp->idprof2) ? $objp->idprof2 : '';
165 $thirdpartystatic->idprof3 = !empty($objp->idprof3) ? $objp->idprof3 : '';
166 $thirdpartystatic->idprof4 = !empty($objp->idprof4) ? $objp->idprof4 : '';
167 $thirdpartystatic->idprof5 = !empty($objp->idprof5) ? $objp->idprof5 : '';
168 $thirdpartystatic->idprof6 = !empty($objp->idprof6) ? $objp->idprof6 : '';
169
170 $late = '';
171 if ($facturestatic->hasDelay()) {
172 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
173 }
174
175 $tooltip = $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier;
176
177 $this->info_box_contents[$line][] = array(
178 'td' => 'class="nowraponall"',
179 'text' => $facturestatic->getNomUrl(1),
180 'text2'=> $late,
181 'asis' => 1,
182 );
183
184 $this->info_box_contents[$line][] = array(
185 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
186 'text' => $thirdpartystatic->getNomUrl(1, '', 44),
187 'asis' => 1,
188 );
189
190 $this->info_box_contents[$line][] = array(
191 'td' => 'class="nowraponall right amount"',
192 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
193 );
194
195 $this->info_box_contents[$line][] = array(
196 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
197 'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
198 );
199
200 $this->info_box_contents[$line][] = array(
201 'td' => 'class="right" width="18"',
202 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am, $objp->type),
203 );
204
205 $line++;
206 }
207 if ($this->max < $num) {
208 $this->info_box_contents[$line][] = array('td' => 'colspan="6"', 'text' => '...');
209 $line++;
210 }
211
212 if ($num == 0) {
213 $this->info_box_contents[$line][0] = array(
214 'td' => 'class="center"',
215 'text'=> '<span class="opacitymedium">'.$langs->trans("NoUnpaidSupplierBills").'</span>',
216 );
217 }
218
219 $sql = "SELECT SUM(f.total_ht) as total_ht ".$sql2;
220
221 $result = $this->db->query($sql);
222 $objp = $this->db->fetch_object($result);
223 $totalamount = $objp->total_ht;
224
225 // Add the sum à the bottom of the boxes
226 $this->info_box_contents[$line][] = array(
227 'tr' => 'class="liste_total_wrap"',
228 'td' => 'class="liste_total"',
229 'text' => $langs->trans("Total"),
230 );
231 $this->info_box_contents[$line][] = array(
232 'td' => 'class="liste_total"',
233 'text' => "&nbsp;",
234 );
235 $this->info_box_contents[$line][] = array(
236 'td' => 'class="right liste_total" ',
237 'text' => price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
238 );
239 $this->info_box_contents[$line][] = array(
240 'td' => 'class="liste_total"',
241 'text' => "&nbsp;",
242 );
243 $this->info_box_contents[$line][] = array(
244 'td' => 'class="liste_total"',
245 'text' => "&nbsp;",
246 );
247
248 $this->db->free($result);
249 } else {
250 $this->info_box_contents[0][0] = array(
251 'td' => '',
252 'maxlength'=>500,
253 'text' => ($this->db->error().' sql='.$sql),
254 );
255 }
256 } else {
257 $this->info_box_contents[0][0] = array(
258 'td' => 'class="nohover left"',
259 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
260 );
261 }
262 }
263
272 public function showBox($head = null, $contents = null, $nooutput = 0)
273 {
274 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
275 }
276}
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.
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='', $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...