dolibarr 19.0.4
box_factures_imp.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2019 Frederic France <frederic.france@netlogic.fr>
6 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.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
28require_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
30
31
36{
37 public $boxcode = "oldestunpaidcustomerbills";
38 public $boximg = "object_bill";
39 public $boxlabel = "BoxOldestUnpaidCustomerBills";
40 public $depends = array("facture");
41
45 public $db;
46
47 public $param;
48
49 public $info_box_head = array();
50 public $info_box_contents = array();
51
52
59 public function __construct($db, $param)
60 {
61 global $user;
62
63 $this->db = $db;
64
65 $this->hidden = !($user->hasRight('facture', 'lire'));
66 }
67
74 public function loadBox($max = 5)
75 {
76 global $conf, $user, $langs;
77
78 $this->max = $max;
79 //$this->max = 1000;
80
81 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
82 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
83
84 $facturestatic = new Facture($this->db);
85 $societestatic = new Societe($this->db);
86
87 $langs->load("bills");
88
89 $textHead = $langs->trans("BoxTitleOldestUnpaidCustomerBills");
90 $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidCustomerBills", $this->max), 'limit'=> dol_strlen($textHead));
91
92 if ($user->hasRight('facture', 'lire')) {
93 $sql1 = "SELECT s.rowid as socid, s.nom as name, s.name_alias, s.code_client, s.client";
94 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
95 $sql1 .= ", spe.accountancy_code_customer as code_compta";
96 } else {
97 $sql1 .= ", s.code_compta";
98 }
99 $sql1 .= ", s.logo, s.email, s.entity";
100 $sql1 .= ", s.tva_intra, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6";
101 $sql1 .= ", f.ref, f.date_lim_reglement as datelimite";
102 $sql1 .= ", f.type";
103 $sql1 .= ", f.datef as date";
104 $sql1 .= ", f.total_ht";
105 $sql1 .= ", f.total_tva";
106 $sql1 .= ", f.total_ttc";
107 $sql1 .= ", f.paye, f.fk_statut as status, f.rowid as facid";
108 $sql1 .= ", SUM(pf.amount) as am";
109 $sql2 = " FROM ".MAIN_DB_PREFIX."societe as s";
110 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
111 $sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
112 }
113 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
114 $sql2 .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
115 }
116 $sql2 .= ", ".MAIN_DB_PREFIX."facture as f";
117 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
118 $sql2 .= " WHERE f.fk_soc = s.rowid";
119 $sql2 .= " AND f.entity IN (".getEntity('invoice').")";
120 $sql2 .= " AND f.paye = 0";
121 $sql2 .= " AND fk_statut = 1";
122 if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
123 $sql2 .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
124 }
125 if ($user->socid) {
126 $sql2 .= " AND s.rowid = ".((int) $user->socid);
127 }
128 $sql3 = " GROUP BY s.rowid, s.nom, s.name_alias, s.code_client, s.client, s.logo, s.email, s.entity, s.tva_intra, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6,";
129 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
130 $sql3 .= " spe.accountancy_code_customer,";
131 } else {
132 $sql3 .= " s.code_compta,";
133 }
134 $sql3 .= " f.rowid, f.ref, f.date_lim_reglement,";
135 $sql3 .= " f.type, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.fk_statut";
136 $sql3 .= " ORDER BY datelimite ASC, f.ref ASC ";
137 $sql3 .= $this->db->plimit($this->max + 1, 0);
138
139 $sql = $sql1.$sql2.$sql3;
140
141 $result = $this->db->query($sql);
142 if ($result) {
143 $num = $this->db->num_rows($result);
144
145 $line = 0;
146 $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateDue')).': %s)';
147
148 while ($line < min($num, $this->max)) {
149 $objp = $this->db->fetch_object($result);
150
151 $datelimite = $this->db->jdate($objp->datelimite);
152
153 $facturestatic->id = $objp->facid;
154 $facturestatic->ref = $objp->ref;
155 $facturestatic->type = $objp->type;
156 $facturestatic->total_ht = $objp->total_ht;
157 $facturestatic->total_tva = $objp->total_tva;
158 $facturestatic->total_ttc = $objp->total_ttc;
159 $facturestatic->statut = $objp->status;
160 $facturestatic->status = $objp->status;
161 $facturestatic->date = $this->db->jdate($objp->date);
162 $facturestatic->date_lim_reglement = $this->db->jdate($objp->datelimite);
163
164 $facturestatic->paye = $objp->paye;
165 $facturestatic->alreadypaid = $objp->am;
166
167 $societestatic->id = $objp->socid;
168 $societestatic->name = $objp->name;
169 //$societestatic->name_alias = $objp->name_alias;
170 $societestatic->code_client = $objp->code_client;
171 $societestatic->code_compta = $objp->code_compta;
172 $societestatic->client = $objp->client;
173 $societestatic->logo = $objp->logo;
174 $societestatic->email = $objp->email;
175 $societestatic->entity = $objp->entity;
176 $societestatic->tva_intra = $objp->tva_intra;
177 $societestatic->idprof1 = $objp->idprof1;
178 $societestatic->idprof2 = $objp->idprof2;
179 $societestatic->idprof3 = $objp->idprof3;
180 $societestatic->idprof4 = $objp->idprof4;
181 $societestatic->idprof5 = $objp->idprof5;
182 $societestatic->idprof6 = $objp->idprof6;
183
184 $late = '';
185 if ($facturestatic->hasDelay()) {
186 $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day', 'tzuserrel')));
187 }
188
189 $this->info_box_contents[$line][] = array(
190 'td' => 'class="nowraponall"',
191 'text' => $facturestatic->getNomUrl(1),
192 'text2'=> $late,
193 'asis' => 1,
194 );
195
196 $this->info_box_contents[$line][] = array(
197 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
198 'text' => $societestatic->getNomUrl(1, '', 44),
199 'asis' => 1,
200 );
201
202 $this->info_box_contents[$line][] = array(
203 'td' => 'class="nowraponall right amount"',
204 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency),
205 );
206
207 $this->info_box_contents[$line][] = array(
208 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateDue").': '.dol_print_date($datelimite, 'day', 'tzuserrel')).'"',
209 'text' => dol_print_date($datelimite, 'day', 'tzuserrel'),
210 );
211
212 $this->info_box_contents[$line][] = array(
213 'td' => 'class="right" width="18"',
214 'text' => $facturestatic->LibStatut($objp->paye, $objp->status, 3, $objp->am),
215 );
216
217 $line++;
218 }
219 if ($this->max < $num) {
220 $this->info_box_contents[$line][] = array('td' => 'colspan="6"', 'text' => '...');
221 $line++;
222 }
223
224 if ($num == 0) {
225 $this->info_box_contents[$line][0] = array(
226 'td' => 'class="center"',
227 'text'=> '<span class="opacitymedium">'.$langs->trans("NoUnpaidCustomerBills").'</span>'
228 );
229 }
230
231 $sql = "SELECT SUM(f.total_ht) as total_ht ".$sql2;
232
233 $result = $this->db->query($sql);
234 $objp = $this->db->fetch_object($result);
235 $totalamount = $objp->total_ht;
236
237 // Add the sum à the bottom of the boxes
238 $this->info_box_contents[$line][] = array(
239 'tr' => 'class="liste_total_wrap"',
240 'td' => 'class="liste_total"',
241 'text' => $langs->trans("Total"),
242 );
243 $this->info_box_contents[$line][] = array(
244 'td' => 'class="liste_total"',
245 'text' => "&nbsp;",
246 );
247 $this->info_box_contents[$line][] = array(
248 'td' => 'class="right liste_total" ',
249 'text' => price($totalamount, 0, $langs, 0, -1, -1, $conf->currency),
250 );
251 $this->info_box_contents[$line][] = array(
252 'td' => 'class="liste_total"',
253 'text' => "&nbsp;",
254 );
255 $this->info_box_contents[$line][] = array(
256 'td' => 'class="liste_total"',
257 'text' => "&nbsp;",
258 );
259
260 $this->db->free($result);
261 } else {
262 $this->info_box_contents[0][0] = array(
263 'td' => '',
264 'maxlength'=>500,
265 'text' => ($this->db->error().' sql='.$sql),
266 );
267 }
268 } else {
269 $this->info_box_contents[0][0] = array(
270 'td' => 'class="nohover left"',
271 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
272 );
273 }
274 }
275
284 public function showBox($head = null, $contents = null, $nooutput = 0)
285 {
286 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
287 }
288}
Class to manage invoices.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show not paid sales 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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...