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