dolibarr 19.0.4
box_factures.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 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
32{
33 public $boxcode = "lastcustomerbills";
34 public $boximg = "object_bill";
35 public $boxlabel = "BoxLastCustomerBills";
36 public $depends = array("facture");
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('facture', 'lire');
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $conf, $user, $langs;
73
74 $this->max = $max;
75
76 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
77 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
78
79 $facturestatic = new Facture($this->db);
80 $societestatic = new Societe($this->db);
81
82 $langs->load("bills");
83
84 $text = $langs->trans("BoxTitleLast".(getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE') ? "" : "Modified")."CustomerBills", $max);
85 $this->info_box_head = array(
86 'text' => $text,
87 'limit'=> dol_strlen($text)
88 );
89
90 if ($user->hasRight('facture', 'lire')) {
91 $sql = "SELECT f.rowid as facid";
92 $sql .= ", f.ref, f.type, f.total_ht";
93 $sql .= ", f.total_tva";
94 $sql .= ", f.total_ttc";
95 $sql .= ", f.datef as date";
96 $sql .= ", f.paye, f.fk_statut as status, f.datec, f.tms";
97 $sql .= ", f.date_lim_reglement as datelimite";
98 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
99 $sql .= ", s.code_client, s.code_compta, s.client";
100 $sql .= ", s.logo, s.email, s.entity";
101 $sql .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
102 $sql .= ", SUM(pf.amount) as am";
103 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
104 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture,";
105 $sql .= " ".MAIN_DB_PREFIX."societe as s";
106 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
107 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
108 }
109 $sql .= " WHERE f.fk_soc = s.rowid";
110 $sql .= " AND f.entity IN (".getEntity('invoice').")";
111 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
112 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
113 }
114 if ($user->socid) {
115 $sql .= " AND s.rowid = ".((int) $user->socid);
116 }
117 $sql .= " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.code_compta, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
118 $sql .= " f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datef, f.paye, f.fk_statut, f.datec, f.tms, f.date_lim_reglement";
119 if (getDolGlobalString('MAIN_LASTBOX_ON_OBJECT_DATE')) {
120 $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
121 } else {
122 $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
123 }
124 $sql .= $this->db->plimit($max, 0);
125
126 $result = $this->db->query($sql);
127 if ($result) {
128 $num = $this->db->num_rows($result);
129 $now = dol_now();
130
131 $line = 0;
132 $l_due_date = $langs->trans('Late').' ('.$langs->trans('DateDue').': %s)';
133
134 while ($line < $num) {
135 $objp = $this->db->fetch_object($result);
136
137 $datelimite = $this->db->jdate($objp->datelimite);
138 $datem = $this->db->jdate($objp->tms);
139
140 $facturestatic->id = $objp->facid;
141 $facturestatic->ref = $objp->ref;
142 $facturestatic->type = $objp->type;
143 $facturestatic->total_ht = $objp->total_ht;
144 $facturestatic->total_tva = $objp->total_tva;
145 $facturestatic->total_ttc = $objp->total_ttc;
146 $facturestatic->statut = $objp->status;
147 $facturestatic->status = $objp->status;
148 $facturestatic->date = $this->db->jdate($objp->date);
149 $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
150
151 $facturestatic->paye = $objp->paye;
152 $facturestatic->alreadypaid = $objp->am;
153
154 $societestatic->id = $objp->socid;
155 $societestatic->name = $objp->name;
156 //$societestatic->name_alias = $objp->name_alias;
157 $societestatic->code_client = $objp->code_client;
158 $societestatic->code_compta = $objp->code_compta;
159 $societestatic->client = $objp->client;
160 $societestatic->logo = $objp->logo;
161 $societestatic->email = $objp->email;
162 $societestatic->entity = $objp->entity;
163 $societestatic->tva_intra = $objp->tva_intra;
164 $societestatic->idprof1 = $objp->idprof1;
165 $societestatic->idprof2 = $objp->idprof2;
166 $societestatic->idprof3 = $objp->idprof3;
167 $societestatic->idprof4 = $objp->idprof4;
168 $societestatic->idprof5 = $objp->idprof5;
169 $societestatic->idprof6 = $objp->idprof6;
170
171 $late = '';
172 if ($facturestatic->hasDelay()) {
173 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
174 }
175
176 $this->info_box_contents[$line][] = array(
177 'td' => 'class="nowraponall"',
178 'text' => $facturestatic->getNomUrl(1),
179 'text2'=> $late,
180 'asis' => 1,
181 );
182
183 $this->info_box_contents[$line][] = array(
184 'td' => 'class="tdoverflowmax200"',
185 'text' => $societestatic->getNomUrl(1, '', 40),
186 'asis' => 1,
187 );
188
189 $this->info_box_contents[$line][] = array(
190 'td' => 'class="right nowraponall amount"',
191 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
192 );
193
194 $this->info_box_contents[$line][] = array(
195 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
196 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
197 );
198
199 $this->info_box_contents[$line][] = array(
200 'td' => 'class="right" width="18"',
201 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
202 );
203
204 $line++;
205 }
206
207 if ($num == 0) {
208 $this->info_box_contents[$line][0] = array(
209 'td' => 'class="center"',
210 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedInvoices").'</span>',
211 );
212 }
213
214 $this->db->free($result);
215 } else {
216 $this->info_box_contents[0][0] = array(
217 'td' => '',
218 'maxlength'=>500,
219 'text' => ($this->db->error().' sql='.$sql),
220 );
221 }
222 } else {
223 $this->info_box_contents[0][0] = array(
224 'td' => 'class="nohover left"',
225 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
226 );
227 }
228 }
229
238 public function showBox($head = null, $contents = null, $nooutput = 0)
239 {
240 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
241 }
242}
Class to manage invoices.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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...