dolibarr 18.0.6
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 *
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 = "lastsupplierbills";
35 public $boximg = "object_bill";
36 public $boxlabel = "BoxLastSupplierBills";
37 public $depends = array("facture", "fournisseur");
38
42 public $db;
43
44 public $param;
45
46 public $info_box_head = array();
47 public $info_box_contents = array();
48
49
56 public function __construct($db, $param)
57 {
58 global $user;
59
60 $this->db = $db;
61
62 $this->hidden = !($user->hasRight('fournisseur', 'facture', 'lire'));
63 }
64
71 public function loadBox($max = 5)
72 {
73 global $conf, $user, $langs;
74
75 $this->max = $max;
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 $this->info_box_head = array(
84 'text' => $langs->trans("BoxTitleLast".(!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) ? "" : "Modified")."SupplierBills", $max)
85 );
86
87 if ($user->hasRight('fournisseur', 'facture', 'lire')) {
88 $langs->load("bills");
89
90 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
92 $sql .= ", s.logo, s.email, s.entity";
93 $sql .= ", f.rowid as facid, f.ref, f.ref_supplier";
94 $sql .= ", f.total_ht";
95 $sql .= ", f.total_tva";
96 $sql .= ", f.total_ttc";
97 $sql .= ", f.paye, f.fk_statut as status";
98 $sql .= ', f.datef as date';
99 $sql .= ', f.datec as datec';
100 $sql .= ', f.date_lim_reglement as datelimite, f.tms, f.type';
101 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
102 $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
103 if (empty($user->rights->societe->client->voir) && !$user->socid) {
104 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
105 }
106 $sql .= " WHERE f.fk_soc = s.rowid";
107 $sql .= " AND f.entity = ".$conf->entity;
108 if (empty($user->rights->societe->client->voir) && !$user->socid) {
109 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
110 }
111 if ($user->socid) {
112 $sql .= " AND s.rowid = ".((int) $user->socid);
113 }
114 if (!empty($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE)) {
115 $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
116 } else {
117 $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
118 }
119 $sql .= $this->db->plimit($max, 0);
120
121 $result = $this->db->query($sql);
122 if ($result) {
123 $num = $this->db->num_rows($result);
124
125 $line = 0;
126 $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
127
128 while ($line < $num) {
129 $objp = $this->db->fetch_object($result);
130
131 $datelimite = $this->db->jdate($objp->datelimite);
132 $date = $this->db->jdate($objp->date);
133 $datem = $this->db->jdate($objp->tms);
134
135 $facturestatic->id = $objp->facid;
136 $facturestatic->ref = $objp->ref;
137 $facturestatic->total_ht = $objp->total_ht;
138 $facturestatic->total_tva = $objp->total_tva;
139 $facturestatic->total_ttc = $objp->total_ttc;
140 $facturestatic->date = $date;
141 $facturestatic->date_echeance = $datelimite;
142 $facturestatic->statut = $objp->status;
143 $facturestatic->status = $objp->status;
144 $facturestatic->ref_supplier = $objp->ref_supplier;
145
146 $alreadypaid = $facturestatic->getSommePaiement();
147
148 $facturestatic->alreadypaid = $alreadypaid ? $alreadypaid : 0;
149
150 $thirdpartystatic->id = $objp->socid;
151 $thirdpartystatic->name = $objp->name;
152 $thirdpartystatic->name_alias = $objp->name_alias;
153 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
154 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
155 $thirdpartystatic->fournisseur = $objp->fournisseur;
156 $thirdpartystatic->logo = $objp->logo;
157 $thirdpartystatic->email = $objp->email;
158 $thirdpartystatic->entity = $objp->entity;
159
160 $late = '';
161
162 if ($facturestatic->hasDelay()) {
163 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
164 }
165
166 $this->info_box_contents[$line][] = array(
167 'td' => 'class="nowraponall"',
168 'text' => $facturestatic->getNomUrl(1),
169 'text2'=> $late,
170 'asis' => 1,
171 );
172
173 $this->info_box_contents[$line][] = array(
174 'td' => 'class="tdoverflowmax150"',
175 'text' => $objp->ref_supplier,
176 'tooltip' => $langs->trans('SupplierInvoice').': '.($objp->ref ? $objp->ref : $objp->facid).'<br>'.$langs->trans('RefSupplier').': '.$objp->ref_supplier,
177 'url' => DOL_URL_ROOT."/fourn/facture/card.php?facid=".$objp->facid,
178 );
179
180 $this->info_box_contents[$line][] = array(
181 'td' => 'class="tdoverflowmax150"',
182 'text' => $thirdpartystatic->getNomUrl(1, 'supplier'),
183 'asis' => 1,
184 );
185
186 $this->info_box_contents[$line][] = array(
187 'td' => 'class="nowraponall right amount"',
188 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
189 );
190
191 $this->info_box_contents[$line][] = array(
192 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
193 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
194 );
195
196 $this->info_box_contents[$line][] = array(
197 'td' => 'class="right" width="18"',
198 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $alreadypaid, $objp->type),
199 );
200
201 $line++;
202 }
203
204 if ($num == 0) {
205 $this->info_box_contents[$line][0] = array(
206 'td' => 'class="center"',
207 'text'=>$langs->trans("NoModifiedSupplierBills"),
208 );
209 }
210
211 $this->db->free($result);
212 } else {
213 $this->info_box_contents[0][0] = array(
214 'td' => '',
215 'maxlength'=>500,
216 'text' => ($this->db->error().' sql='.$sql),
217 );
218 }
219 } else {
220 $this->info_box_contents[0][0] = array(
221 'td' => 'class="nohover opacitymedium left"',
222 'text' => $langs->transnoentities("ReadPermissionNotAllowed")
223 );
224 }
225 }
226
235 public function showBox($head = null, $contents = null, $nooutput = 0)
236 {
237 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
238 }
239}
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='', $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...