dolibarr 24.0.0-beta
invoice.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
7 * Copyright (C) 2017 ATM-CONSULTING <contact@atm-consulting.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
39{
40 global $db, $langs, $conf, $user;
41
42 $h = 0;
43 $head = array();
44
45 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/card.php', ['id' => $object->id]);
46 $head[$h][1] = $langs->trans('CustomerInvoice');
47 $head[$h][2] = 'compta';
48 $h++;
49
50 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
51 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
52 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/contact.php', ['id' => $object->id]);
53 $head[$h][1] = $langs->trans('ContactsAddresses');
54 if ($nbContact > 0) {
55 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
56 }
57 $head[$h][2] = 'contact';
58 $h++;
59 }
60
61 if (isModEnabled('prelevement')) {
62 $nbStandingOrders = 0;
63 $sql = "SELECT COUNT(pfd.rowid) as nb";
64 $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
65 $sql .= " WHERE pfd.fk_facture = ".((int) $object->id);
66 $sql .= " AND type = 'ban'";
67 $resql = $db->query($sql);
68 if ($resql) {
69 $obj = $db->fetch_object($resql);
70 if ($obj) {
71 $nbStandingOrders = $obj->nb;
72 }
73 } else {
75 }
76 $langs->load("banks");
77
78 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/prelevement.php', ['id' => $object->id]);
79 $head[$h][1] = $langs->trans('StandingOrders');
80 if ($nbStandingOrders > 0) {
81 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
82 }
83 $head[$h][2] = 'standingorders';
84 $h++;
85 }
86
87 // Show more tabs from modules
88 // Entries must be declared in modules descriptor with line
89 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
90 // $this->tabs = array('entity:-tabname); to remove a tab
91 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'core');
92
93 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
94 $nbNote = 0;
95 if (!empty($object->note_private)) {
96 $nbNote++;
97 }
98 if (!empty($object->note_public)) {
99 $nbNote++;
100 }
101 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/note.php', ['id' => $object->id]);
102 $head[$h][1] = $langs->trans('Notes');
103 if ($nbNote > 0) {
104 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
105 }
106 $head[$h][2] = 'note';
107 $h++;
108 }
109
110 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
111 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
112 $upload_dir = $conf->facture->dir_output."/".dol_sanitizeFileName($object->ref);
113 if (!empty($conf->facture->multidir_output[$object->entity])) {
114 $upload_dir = $conf->facture->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
115 }
116 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
117 $nbLinks = Link::count($db, $object->element, $object->id);
118 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/document.php', ['id' => $object->id]);
119 $head[$h][1] = $langs->trans('Documents');
120 if (($nbFiles + $nbLinks) > 0) {
121 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
122 }
123 $head[$h][2] = 'documents';
124 $h++;
125
126 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/agenda.php', ['id' => $object->id]);
127 $head[$h][1] = $langs->trans("Events");
128 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
129 $nbEvent = 0;
130 // Enable caching of thirdparty count actioncomm
131 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
132 $cachekey = 'count_events_facture_'.$object->id;
133 $dataretrieved = dol_getcache($cachekey);
134 if (!is_null($dataretrieved)) {
135 $nbEvent = $dataretrieved;
136 } else {
137 $sql = "SELECT COUNT(id) as nb";
138 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
139 $sql .= " WHERE fk_element = ".((int) $object->id);
140 $sql .= " AND elementtype = 'invoice'";
141 $resql = $db->query($sql);
142 if ($resql) {
143 $obj = $db->fetch_object($resql);
144 $nbEvent = $obj->nb;
145 } else {
146 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
147 }
148 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
149 }
150
151 $head[$h][1] .= '/';
152 $head[$h][1] .= $langs->trans("Agenda");
153 if ($nbEvent > 0) {
154 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
155 }
156 }
157 $head[$h][2] = 'agenda';
158 $h++;
159
160 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'external');
161
162 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'remove');
163
164 return $head;
165}
166
173{
174 global $langs, $conf, $extrafields;
175
176 $extrafields->fetch_name_optionals_label('facture');
177 $extrafields->fetch_name_optionals_label('facturedet');
178 $extrafields->fetch_name_optionals_label('facture_rec');
179 $extrafields->fetch_name_optionals_label('facturedet_rec');
180
181 $h = 0;
182 $head = array();
183
184 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/invoice.php');
185 $head[$h][1] = $langs->trans("Miscellaneous");
186 $head[$h][2] = 'general';
187 $h++;
188
189 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/payment.php');
190 $head[$h][1] = $langs->trans("Payments");
191 $head[$h][2] = 'payment';
192 $h++;
193
194 // Show more tabs from modules
195 // Entries must be declared in modules descriptor with line
196 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
197 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
198 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
199
200 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/admin/invoice_cust_extrafields.php');
201 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
202 $nbExtrafields = $extrafields->attributes['facture']['count'];
203 if ($nbExtrafields > 0) {
204 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
205 }
206 $head[$h][2] = 'attributes';
207 $h++;
208
209 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/admin/invoicedet_cust_extrafields.php');
210 $head[$h][1] = $langs->trans("ExtraFieldsLines");
211 $nbExtrafields = $extrafields->attributes['facturedet']['count'];
212 if ($nbExtrafields > 0) {
213 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
214 }
215 $head[$h][2] = 'attributeslines';
216 $h++;
217
218 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/admin/invoice_rec_cust_extrafields.php');
219 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
220 $nbExtrafields = $extrafields->attributes['facture_rec']['count'];
221 if ($nbExtrafields > 0) {
222 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
223 }
224 $head[$h][2] = 'attributesrec';
225 $h++;
226
227 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/admin/invoicedet_rec_cust_extrafields.php');
228 $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
229 $nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
230 if ($nbExtrafields > 0) {
231 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
232 }
233 $head[$h][2] = 'attributeslinesrec';
234 $h++;
235
236 if (getDolGlobalInt('INVOICE_USE_SITUATION') > 0) { // Warning, implementation with value 1 is seriously bugged and the new one with value 2, not compatible with 1, is expected to become stable
237 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/admin/invoice_situation.php');
238 $head[$h][1] = $langs->trans("InvoiceSituation");
239 $head[$h][2] = 'situation';
240 $h++;
241 }
242
243 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
244
245 return $head;
246}
247
248
256{
257 global $db, $langs, $conf, $user;
258
259 $h = 0;
260 $head = array();
261
262 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/compta/facture/card-rec.php', ['id' => $object->id]);
263 $head[$h][1] = $langs->trans("RepeatableInvoice");
264 $head[$h][2] = 'card';
265 $h++;
266
267 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/compta/facture/list.php', ['search_fk_fac_rec_source' => $object->id]);
268 $head[$h][1] = $langs->trans('InvoicesGeneratedFromRec');
269 //count facture rec
270 $nbFacture = 0;
271 $sql = "SELECT COUNT(rowid) as nb";
272 $sql .= " FROM ".MAIN_DB_PREFIX."facture";
273 $sql .= " WHERE fk_fac_rec_source = ".((int) $object->id);
274 $resql = $db->query($sql);
275 if ($resql) {
276 $obj = $db->fetch_object($resql);
277 $nbFacture = $obj->nb;
278 } else {
279 dol_syslog('Failed to count invoices with invoice model '.$db->lasterror(), LOG_ERR);
280 }
281 if ($nbFacture > 0) {
282 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFacture.'</span>';
283 }
284 $head[$h][2] = 'generated';
285 $h++;
286
287 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
288 $nbNote = 0;
289 if (!empty($object->note_private)) {
290 $nbNote++;
291 }
292 if (!empty($object->note_public)) {
293 $nbNote++;
294 }
295 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/note-rec.php', ['id' => $object->id]);
296 $head[$h][1] = $langs->trans('Notes');
297 if ($nbNote > 0) {
298 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
299 }
300 $head[$h][2] = 'note';
301 $h++;
302 }
303
304 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/compta/facture/agenda-rec.php', ['id' => $object->id]);
305 $head[$h][1] = $langs->trans("Events");
306 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
307 $nbEvent = 0;
308 // Enable caching of thirdparty count actioncomm
309 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
310 $cachekey = 'count_events_facturerec_'.$object->id;
311 $dataretrieved = dol_getcache($cachekey);
312 if (!is_null($dataretrieved)) {
313 $nbEvent = $dataretrieved;
314 } else {
315 $sql = "SELECT COUNT(id) as nb";
316 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
317 $sql .= " WHERE fk_element = ".((int) $object->id);
318 $sql .= " AND elementtype = 'invoicerec'";
319 $resql = $db->query($sql);
320 if ($resql) {
321 $obj = $db->fetch_object($resql);
322 $nbEvent = $obj->nb;
323 } else {
324 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
325 }
326 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
327 }
328
329 $head[$h][1] .= '/';
330 $head[$h][1] .= $langs->trans("Agenda");
331 if ($nbEvent > 0) {
332 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
333 }
334 }
335 $head[$h][2] = 'agenda';
336 $h++;
337
338 // Show more tabs from modules
339 // Entries must be declared in modules descriptor with line
340 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
341 // $this->tabs = array('entity:-tabname); to remove a tab
342 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
343
344 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
345
346 return $head;
347}
348
356{
357 global $db, $langs, $conf;
358
359 $h = 0;
360 $head = array();
361
362 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/fourn/facture/card-rec.php', ['id' => $object->id]);
363 $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
364 $head[$h][2] = 'card';
365 $h++;
366
367 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
368 $nbNote = 0;
369 if (!empty($object->note_private)) {
370 $nbNote++;
371 }
372 if (!empty($object->note_public)) {
373 $nbNote++;
374 }
375 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/note-rec.php', ['id' => $object->id]);
376 $head[$h][1] = $langs->trans('Notes');
377 if ($nbNote > 0) {
378 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
379 }
380 $head[$h][2] = 'note';
381 $h++;
382 }
383 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT . '/fourn/facture/list.php', ['search_fk_fac_rec_source' => $object->id]);
384 $head[$h][1] = $langs->trans('InvoicesGeneratedFromRec');
385
386 //count facture rec
387 $nbFactureFourn = 0;
388 $sql = "SELECT COUNT(rowid) as nb";
389 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
390 $sql .= " WHERE fk_fac_rec_source = ".((int) $object->id);
391 $resql = $db->query($sql);
392 if ($resql) {
393 $obj = $db->fetch_object($resql);
394 $nbFactureFourn = $obj->nb;
395 } else {
396 dol_syslog('Failed to count invoices with supplier invoice model '.$db->lasterror(), LOG_ERR);
397 }
398 if ($nbFactureFourn > 0) {
399 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFactureFourn.'</span>';
400 }
401 $head[$h][2] = 'generated';
402 $h++;
403
404 // Show more tabs from modules
405 // Entries must be declared in modules descriptor with line
406 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
407 // $this->tabs = array('entity:-tabname); to remove a tab
408 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
409
410 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
411
412 return $head;
413}
414
422{
423 global $conf, $db, $langs, $user;
424
425 if (($mode == 'customers' && isModEnabled('invoice') && $user->hasRight('facture', 'lire'))
426 || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('fournisseur', 'facture', 'lire'))
427 ) {
428 global $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11;
429 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
430
431 $now = date_create(date('Y-m-d', dol_now()));
432 $datenowsub30 = date_create(date('Y-m-d', dol_now()));
433 $datenowsub15 = date_create(date('Y-m-d', dol_now()));
434 $datenowadd30 = date_create(date('Y-m-d', dol_now()));
435 $datenowadd15 = date_create(date('Y-m-d', dol_now()));
436 $interval30days = date_interval_create_from_date_string('30 days');
437 $interval15days = date_interval_create_from_date_string('15 days');
438 date_sub($datenowsub30, $interval30days);
439 date_sub($datenowsub15, $interval15days);
440 date_add($datenowadd30, $interval30days);
441 date_add($datenowadd15, $interval15days);
442
443 $amount_mode = (getDolGlobalInt('FACTURE_VALIDATED_IN_AMOUNT') == 1);
444
445 $sql = "SELECT";
446 $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late30";
447 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late15";
448 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement >= '".date_format($datenowsub15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as latenow";
449 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($now, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd15, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlatenow";
450 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd15, 'Y-m-d')."' AND f.date_lim_reglement < '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate15";
451 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate30";
452 if ($mode == 'customers') {
453 $element = 'invoice';
454 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
455 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
456 $element = 'supplier_invoice';
457 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
458 } else {
459 return '';
460 }
461 $sql .= " WHERE f.entity IN (".getEntity($element).")";
462 $sql .= " AND f.type <> 2";
463 $sql .= " AND f.fk_statut = 1";
464 if (isset($user->socid) && $user->socid > 0) {
465 $sql .= " AND f.fk_soc = ".((int) $user->socid);
466 }
467
468 $resql = $db->query($sql);
469 if ($resql) {
470 $num = $db->num_rows($resql);
471 $i = 0;
472 $total = 0;
473 $dataseries = array();
474
475 while ($i < $num) {
476 $obj = $db->fetch_object($resql);
477 /*
478 $dataseries = array(
479 array($langs->trans('InvoiceLate30Days'), $obj->nblate30),
480 array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30),
481 array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15),
482 array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15),
483 array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30),
484 array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30),
485 );
486 */
487 $dataseries[$i] = array($langs->transnoentitiesnoconv('NbOfOpenInvoices'), $obj->late30, $obj->late15, $obj->latenow, $obj->notlatenow, $obj->notlate15, $obj->notlate30);
488 $i++;
489 }
490 if (!empty($dataseries[0])) {
491 foreach ($dataseries[0] as $key => $value) {
492 if (is_numeric($value)) {
493 $total += $value;
494 }
495 }
496 }
497 $legend = array(
498 $langs->trans('InvoiceLate30Days'),
499 $langs->trans('InvoiceLate15Days'),
500 $langs->trans('InvoiceLateMinus15Days'),
501 $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
502 $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
503 $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
504 );
505
506 $colorseries = array('#998844', $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
507
508 $result = '<div class="div-table-responsive-no-min">';
509 $result .= '<table class="noborder nohover centpercent">';
510 $result .= '<tr class="liste_titre">';
511 $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
512 if ($mode == 'customers') {
513 $result .= $langs->trans("CustomerInvoice");
514 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
515 $result .= $langs->trans("SupplierInvoice");
516 } else {
517 return '';
518 }
519 $result .= '</td>';
520 $result .= '</tr>';
521
522 if ($conf->use_javascript_ajax) {
523 $dolgraph = new DolGraph();
524 $dolgraph->SetData($dataseries); // @phan-suppress-current-line PhanTypeMismatchArgument
525
526 $dolgraph->setLegend($legend);
527
528 $dolgraph->SetDataColor($colorseries);
529 $dolgraph->setShowLegend(2);
530 $dolgraph->setShowPercent(1);
531 $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
532 //$dolgraph->SetType(array('pie'));
533 $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
534 $dolgraph->setWidth('450');
535 $dolgraph->setHideXValues(true);
536 //$dolgraph->setBarWidth('15');
537 if ($mode == 'customers') {
538 $dolgraph->draw('idgraphcustomerinvoices');
539 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
540 $dolgraph->draw('idgraphfourninvoices');
541 } else {
542 return '';
543 }
544 $result .= '<tr maxwidth="255">';
545 $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
546 $result .= '</tr>';
547 } else {
548 // Print text lines
549 }
550
551 $result .= '</table>';
552 $result .= '</div>';
553
554 return $result;
555 } else {
557 }
558 }
559 return '';
560}
561
569function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
570{
571 global $conf, $db, $langs, $user, $hookmanager;
572
573 $result = '';
574
575 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
576 if ($user->socid > 0) {
577 $socid = $user->socid;
578 }
579 $maxofloop = getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500);
580
581 $tmpinvoice = new Facture($db);
582
583 $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
584 $sql .= ", f.type, f.fk_statut as status, f.paye";
585 $sql .= ", s.nom as name";
586 $sql .= ", s.rowid as socid, s.email";
587 $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
588 $sql .= ", cc.rowid as country_id, cc.code as country_code";
589 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
590 $sql .= ", sc.fk_soc, sc.fk_user ";
591 }
592 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
593 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
594 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
595 }
596 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
597 $sql .= " AND f.entity IN (".getEntity('invoice').")";
598 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
599 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
600 }
601
602 if ($socid) {
603 $sql .= " AND f.fk_soc = ".((int) $socid);
604 }
605 // Add where from hooks
606 $parameters = array();
607 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
608 $sql .= $hookmanager->resPrint;
609
610 $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total_ht, f.total_tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,";
611 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
612 $sql .= " cc.rowid, cc.code";
613 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
614 $sql .= ", sc.fk_soc, sc.fk_user";
615 }
616
617 // Add Group from hooks
618 $parameters = array();
619 $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
620 $sql .= $hookmanager->resPrint;
621
622 $resql = $db->query($sql);
623
624 if ($resql) {
625 $num = $db->num_rows($resql);
626 $nbofloop = min($num, $maxofloop);
627
628 $result .= '<div class="div-table-responsive-no-min">';
629 $result .= '<table class="noborder centpercent">';
630
631 $result .= '<tr class="liste_titre">';
632 $result .= '<th colspan="3">';
633 $result .= $langs->trans("CustomersDraftInvoices");
634 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/compta/facture/list.php', ['search_status' => Facture::STATUS_DRAFT]).'">';
635 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
636 $result .= '</a>';
637 $result .= '</th>';
638 $result .= '</tr>';
639
640 if ($num) {
641 $companystatic = new Societe($db);
642
643 $i = 0;
644 $othernb = 0;
645 $tot_ttc = 0;
646 while ($i < $nbofloop) {
647 $obj = $db->fetch_object($resql);
648
649 if ($i >= $maxCount) {
650 $othernb += 1;
651 $i++;
652 $tot_ttc += $obj->total_ttc;
653 continue;
654 }
655
656 $tmpinvoice->id = $obj->rowid;
657 $tmpinvoice->ref = $obj->ref;
658 $tmpinvoice->date = $db->jdate($obj->date);
659 $tmpinvoice->type = $obj->type;
660 $tmpinvoice->total_ht = $obj->total_ht;
661 $tmpinvoice->total_tva = $obj->total_tva;
662 $tmpinvoice->total_ttc = $obj->total_ttc;
663 $tmpinvoice->ref_client = $obj->ref_client;
664 $tmpinvoice->statut = $obj->status;
665 $tmpinvoice->paye = $obj->paye;
666
667 $companystatic->id = $obj->socid;
668 $companystatic->name = $obj->name;
669 $companystatic->email = $obj->email;
670 $companystatic->country_id = $obj->country_id;
671 $companystatic->country_code = $obj->country_code;
672 $companystatic->client = 1;
673 $companystatic->code_client = $obj->code_client;
674 $companystatic->code_fournisseur = $obj->code_fournisseur;
675 $companystatic->code_compta = $obj->code_compta;
676 $companystatic->code_compta_client = $obj->code_compta;
677 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
678
679 $result .= '<tr class="oddeven">';
680 $result .= '<td class="nowrap tdoverflowmax100">';
681 $result .= $tmpinvoice->getNomUrl(1, '');
682 $result .= '</td>';
683 $result .= '<td class="nowrap tdoverflowmax100">';
684 $result .= $companystatic->getNomUrl(1, 'customer');
685 $result .= '</td>';
686 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
687 $result .= '</tr>';
688 $tot_ttc += $obj->total_ttc;
689 $i++;
690 }
691
692 if ($othernb) {
693 $result .= '<tr class="oddeven">';
694 $result .= '<td class="nowrap" colspan="3">';
695 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
696 $result .= '</td>';
697 $result .= "</tr>\n";
698 }
699
700 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
701 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
702 $result .= '</tr>';
703 } else {
704 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
705 }
706 $result .= "</table></div>";
707 $db->free($resql);
708 } else {
710 }
711 }
712
713 return $result;
714}
715
723function getDraftSupplierTable($maxCount = 500, $socid = 0)
724{
725 global $conf, $db, $langs, $user, $hookmanager;
726
727 $result = '';
728
729 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
730 if ($user->socid > 0) {
731 $socid = $user->socid;
732 }
733 $maxofloop = getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500);
734
735 $facturesupplierstatic = new FactureFournisseur($db);
736
737 $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye";
738 $sql .= ", s.nom as name";
739 $sql .= ", s.rowid as socid, s.email";
740 $sql .= ", s.code_client, s.code_compta";
741 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
742 $sql .= ", cc.rowid as country_id, cc.code as country_code";
743 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
744 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
745 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
746 }
747 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
748 $sql .= " AND f.entity IN (".getEntity('invoice').')';
749 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
750 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
751 }
752 if ($socid) {
753 $sql .= " AND f.fk_soc = ".((int) $socid);
754 }
755 // Add where from hooks
756 $parameters = array();
757 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
758 $sql .= $hookmanager->resPrint;
759 $resql = $db->query($sql);
760
761 if ($resql) {
762 $num = $db->num_rows($resql);
763 $nbofloop = min($num, $maxofloop);
764
765 $result .= '<div class="div-table-responsive-no-min">';
766 $result .= '<table class="noborder centpercent">';
767
768 $result .= '<tr class="liste_titre">';
769 $result .= '<th colspan="3">';
770 $result .= $langs->trans("SuppliersDraftInvoices");
771 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['search_status' => FactureFournisseur::STATUS_DRAFT]).'">';
772 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
773 $result .= '</a>';
774 $result .= '</th>';
775 $result .= '</tr>';
776
777 if ($num) {
778 $companystatic = new Societe($db);
779
780 $i = 0;
781 $othernb = 0;
782 $tot_ttc = 0;
783 while ($i < $nbofloop) {
784 $obj = $db->fetch_object($resql);
785
786 if ($i >= $maxCount) {
787 $othernb += 1;
788 $i++;
789 $tot_ttc += $obj->total_ttc;
790 continue;
791 }
792
793 $facturesupplierstatic->ref = $obj->ref;
794 $facturesupplierstatic->id = $obj->rowid;
795 $facturesupplierstatic->total_ht = $obj->total_ht;
796 $facturesupplierstatic->total_tva = $obj->total_tva;
797 $facturesupplierstatic->total_ttc = $obj->total_ttc;
798 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
799 $facturesupplierstatic->type = $obj->type;
800 $facturesupplierstatic->statut = $obj->status;
801 $facturesupplierstatic->status = $obj->status;
802 $facturesupplierstatic->paye = $obj->paye;
803 $facturesupplierstatic->paid = $obj->paye;
804
805 $companystatic->id = $obj->socid;
806 $companystatic->name = $obj->name;
807 $companystatic->email = $obj->email;
808 $companystatic->country_id = $obj->country_id;
809 $companystatic->country_code = $obj->country_code;
810 $companystatic->fournisseur = 1;
811 $companystatic->code_client = $obj->code_client;
812 $companystatic->code_fournisseur = $obj->code_fournisseur;
813 $companystatic->code_compta = $obj->code_compta;
814 $companystatic->code_compta_client = $obj->code_compta;
815 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
816
817 $result .= '<tr class="oddeven">';
818 $result .= '<td class="nowrap tdoverflowmax100">';
819 $result .= $facturesupplierstatic->getNomUrl(1, '');
820 $result .= '</td>';
821 $result .= '<td class="nowrap tdoverflowmax100">';
822 $result .= $companystatic->getNomUrl(1, 'supplier');
823 $result .= '</td>';
824 $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
825 $result .= '</tr>';
826 $tot_ttc += $obj->total_ttc;
827 $i++;
828 }
829
830 if ($othernb) {
831 $result .= '<tr class="oddeven">';
832 $result .= '<td class="nowrap" colspan="3">';
833 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
834 $result .= '</td>';
835 $result .= "</tr>\n";
836 }
837
838 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
839 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
840 $result .= '</tr>';
841 } else {
842 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
843 }
844 $result .= "</table></div>";
845 $db->free($resql);
846 } else {
848 }
849 }
850
851 return $result;
852}
853
854
862function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
863{
864 global $conf, $db, $langs, $user;
865 if ($user->socid > 0) {
866 $socid = $user->socid;
867 }
868 $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.type, f.total_ht, f.total_tva, f.total_ttc, f.datec,";
869 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
870 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
871 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
872 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
873 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
874 }
875 $sql .= " WHERE f.fk_soc = s.rowid";
876 $sql .= " AND f.entity IN (".getEntity('facture').")";
877 if ($socid) {
878 $sql .= " AND f.fk_soc = ".((int) $socid);
879 }
880 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
881 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
882 }
883 $sql .= " ORDER BY f.tms DESC";
884 $sql .= $db->plimit($maxCount, 0);
885
886 $resql = $db->query($sql);
887 if (!$resql) {
889 }
890
891 $num = $db->num_rows($resql);
892
893 $result = '<div class="div-table-responsive-no-min">';
894 $result .= '<table class="noborder centpercent">';
895
896 $result .= '<tr class="liste_titre">';
897 $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
898 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
899 $result .= '<th class="right"></th>';
900 $result .= '</tr>';
901
902 if ($num < 1) {
903 $result .= '</table>';
904 $result .= '</div>';
905 return $result;
906 }
907
908 $formfile = new FormFile($db);
909 $objectstatic = new Facture($db);
910 $companystatic = new Societe($db);
911 $i = 0;
912
913 while ($i < $num) {
914 $obj = $db->fetch_object($resql);
915
916 $objectstatic->id = $obj->rowid;
917 $objectstatic->ref = $obj->ref;
918 $objectstatic->paye = $obj->paye;
919 $objectstatic->statut = $obj->status;
920 $objectstatic->status = $obj->status;
921 $objectstatic->total_ht = $obj->total_ht;
922 $objectstatic->total_tva = $obj->total_tva;
923 $objectstatic->total_ttc = $obj->total_ttc;
924 $objectstatic->type = $obj->type;
925
926 $companystatic->id = $obj->socid;
927 $companystatic->name = $obj->socname;
928 $companystatic->client = $obj->client;
929 $companystatic->canvas = $obj->canvas;
930
931 $filename = dol_sanitizeFileName($obj->ref);
932 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
933
934 $result .= '<tr class="oddeven">';
935
936 $result .= '<td class="nowrap">';
937 $result .= '<table class="nobordernopadding">';
938 $result .= '<tr class="nocellnopadd">';
939
940 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
941 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
942 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
943
944 $result .= '</tr>';
945 $result .= '</table>';
946 $result .= '</td>';
947
948 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
949 $result .= '<td title="'.dol_print_date($db->jdate($obj->datec), 'day').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
950 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
951
952 // Load amount of existing payment of invoice (needed for complete status)
953 $payment = $objectstatic->getSommePaiement();
954 $result .= '<td class="right">'.$objectstatic->getLibStatut(3, $payment).'</td>';
955
956 $result .= '</tr>';
957
958 $i++;
959 }
960
961 $result .= '</table>';
962 $result .= '</div>';
963 return $result;
964}
965
973function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
974{
975 global $conf, $db, $langs, $user;
976 if ($user->socid > 0) {
977 $socid = $user->socid;
978 }
979 $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.datec,";
980 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
981 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
982 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
983 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
984 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
985 }
986 $sql .= " WHERE f.fk_soc = s.rowid";
987 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
988 if ($socid) {
989 $sql .= " AND f.fk_soc = ".((int) $socid);
990 }
991 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
992 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
993 }
994 $sql .= " ORDER BY f.tms DESC";
995 $sql .= $db->plimit($maxCount, 0);
996
997 $resql = $db->query($sql);
998 if (!$resql) {
1000 return '';
1001 }
1002
1003 $num = $db->num_rows($resql);
1004
1005 $result = '<div class="div-table-responsive-no-min">';
1006 $result .= '<table class="noborder centpercent">';
1007 $result .= '<tr class="liste_titre">';
1008 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
1009 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['sortfield' => 'f.tms', 'sortorder' => 'DESC']).'">';
1010 $result .= '<span class="badge">...</span>';
1011 $result .= '</a>';
1012 $result .= '</th>';
1013 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1014 $result .= '<th class="right"></th>';
1015 $result .= '</tr>';
1016
1017 if ($num < 1) {
1018 $result .= '</table>';
1019 $result .= '</div>';
1020 return $result;
1021 }
1022
1023 $objectstatic = new FactureFournisseur($db);
1024 $companystatic = new Societe($db);
1025 $formfile = new FormFile($db);
1026 $i = 0;
1027
1028 while ($i < $num) {
1029 $obj = $db->fetch_object($resql);
1030
1031 $objectstatic->id = $obj->rowid;
1032 $objectstatic->ref = $obj->ref;
1033 $objectstatic->paye = $obj->paye;
1034 $objectstatic->paid = $obj->paye;
1035 $objectstatic->statut = $obj->status;
1036 $objectstatic->status = $obj->status;
1037 $objectstatic->total_ht = $obj->total_ht;
1038 $objectstatic->total_tva = $obj->total_tva;
1039 $objectstatic->total_ttc = $obj->total_ttc;
1040 $objectstatic->type = $obj->type;
1041
1042 $companystatic->id = $obj->socid;
1043 $companystatic->name = $obj->socname;
1044 $companystatic->client = $obj->client;
1045 $companystatic->canvas = $obj->canvas;
1046
1047 $filename = dol_sanitizeFileName($obj->ref);
1048 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
1049
1050 $result .= '<tr class="nowrap">';
1051
1052 $result .= '<td class="oddeven">';
1053 $result .= '<table class="nobordernopadding">';
1054 $result .= '<tr class="nocellnopadd">';
1055
1056 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
1057 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
1058 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
1059
1060 $result .= '</tr>';
1061 $result .= '</table>';
1062 $result .= '</td>';
1063
1064 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1065
1066 $result .= '<td title="'.$langs->trans("DateModification").': '.dol_print_date($db->jdate($obj->datec), 'dayhour').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
1067
1068 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
1069
1070 $result .= '<td class="right">'.$objectstatic->getLibStatut(3).'</td>';
1071
1072 $result .= '</tr>';
1073
1074 $i++;
1075 }
1076
1077 $result .= '</table>';
1078 $result .= '</div>';
1079 return $result;
1080}
1081
1089function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1090{
1091 global $conf, $db, $langs, $user, $hookmanager;
1092
1093 $result = '';
1094
1095 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1096 if ($user->socid > 0) {
1097 $socid = $user->socid;
1098 }
1099 $tmpinvoice = new Facture($db);
1100
1101 $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
1102 $sql .= ", f.date_lim_reglement as datelimite";
1103 $sql .= ", s.nom as name";
1104 $sql .= ", s.rowid as socid, s.email";
1105 $sql .= ", s.code_client, s.code_compta";
1106 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1107 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1108 $sql .= ", sum(pf.amount) as am";
1109 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays,".MAIN_DB_PREFIX."facture as f";
1110 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1111 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1112 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1113 }
1114 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1115 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1116 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1117 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1118 }
1119 if ($socid) {
1120 $sql .= " AND f.fk_soc = ".((int) $socid);
1121 }
1122 // Add where from hooks
1123 $parameters = array();
1124 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1125 $sql .= $hookmanager->resPrint;
1126
1127 $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
1128 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1129 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1130 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1131
1132 $resql = $db->query($sql);
1133 if ($resql) {
1134 $num = $db->num_rows($resql);
1135 $i = 0;
1136 $othernb = 0;
1137
1138 $formfile = new FormFile($db);
1139
1140 print '<div class="div-table-responsive-no-min">';
1141 print '<table class="noborder centpercent">';
1142
1143 print '<tr class="liste_titre">';
1144 print '<th colspan="2">';
1145 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1146 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1147 print '<span class="badge">'.$num.'</span>';
1148 print '</a>';
1149 print '</th>';
1150
1151 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1152 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1153 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1154 }
1155 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1156 print '<th class="right">'.$langs->trans("Received").'</th>';
1157 print '<th width="16">&nbsp;</th>';
1158 print '</tr>';
1159 if ($num) {
1160 $societestatic = new Societe($db);
1161 $total_ttc = $totalam = $total = 0;
1162 while ($i < $num) {
1163 $obj = $db->fetch_object($resql);
1164
1165 if ($i >= $maxCount) {
1166 $othernb += 1;
1167 $i++;
1168 $total += $obj->total_ht;
1169 $total_ttc += $obj->total_ttc;
1170 $totalam += $obj->am;
1171 continue;
1172 }
1173
1174 $tmpinvoice->ref = $obj->ref;
1175 $tmpinvoice->id = $obj->rowid;
1176 $tmpinvoice->total_ht = $obj->total_ht;
1177 $tmpinvoice->total_tva = $obj->total_tva;
1178 $tmpinvoice->total_ttc = $obj->total_ttc;
1179 $tmpinvoice->type = $obj->type;
1180 $tmpinvoice->statut = $obj->status;
1181 $tmpinvoice->paye = $obj->paye;
1182 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1183
1184 $societestatic->id = $obj->socid;
1185 $societestatic->name = $obj->name;
1186 $societestatic->email = $obj->email;
1187 $societestatic->country_id = $obj->country_id;
1188 $societestatic->country_code = $obj->country_code;
1189 $societestatic->client = 1;
1190 $societestatic->code_client = $obj->code_client;
1191 $societestatic->code_fournisseur = $obj->code_fournisseur;
1192 $societestatic->code_compta = $obj->code_compta;
1193 $societestatic->code_compta_client = $obj->code_compta;
1194 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1195
1196 print '<tr class="oddeven">';
1197 print '<td class="nowrap">';
1198
1199 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1200 print '<td class="nobordernopadding nowrap">';
1201 print $tmpinvoice->getNomUrl(1, '');
1202 print '</td>';
1203 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1204 $filename = dol_sanitizeFileName($obj->ref);
1205 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1206 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1207 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1208 print '</td></tr></table>';
1209
1210 print '</td>';
1211 print '<td class="nowrap tdoverflowmax100">';
1212 print $societestatic->getNomUrl(1, 'customer');
1213 print '</td>';
1214 print '<td class="right" title="'.dol_print_date($db->jdate($obj->datelimite), 'day').'">';
1215 print dol_print_date($db->jdate($obj->datelimite), 'day');
1216 if ($tmpinvoice->hasDelay()) {
1217 print img_warning($langs->trans("Late"));
1218 }
1219 print '</td>';
1220 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1221 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1222 }
1223 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1224 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1225 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1226 print '</tr>';
1227
1228 $total_ttc += $obj->total_ttc;
1229 $total += $obj->total_ht;
1230 $totalam += $obj->am;
1231
1232 $i++;
1233 }
1234
1235 if ($othernb) {
1236 $colspan = 6;
1237 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1238 $colspan++;
1239 }
1240 print '<tr class="oddeven">';
1241 print '<td class="nowrap" colspan="'.$colspan.'">';
1242 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1243 print '</td>';
1244 print "</tr>\n";
1245 }
1246
1247 print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')</span> </td>';
1248 print '<td>&nbsp;</td>';
1249 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1250 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1251 }
1252 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1253 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1254 print '<td>&nbsp;</td>';
1255 print '</tr>';
1256 } else {
1257 $colspan = 6;
1258 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1259 $colspan++;
1260 }
1261 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1262 }
1263 print '</table></div><br>';
1264 $db->free($resql);
1265 } else {
1267 }
1268 }
1269
1270 return $result;
1271}
1272
1273
1281function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1282{
1283 global $conf, $db, $langs, $user, $hookmanager;
1284
1285 $result = '';
1286
1287 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1288 if ($user->socid > 0) {
1289 $socid = $user->socid;
1290 }
1291 $facstatic = new FactureFournisseur($db);
1292
1293 $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
1294 $sql .= ", ff.date_lim_reglement";
1295 $sql .= ", s.nom as name";
1296 $sql .= ", s.rowid as socid, s.email";
1297 $sql .= ", s.code_client, s.code_compta";
1298 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1299 $sql .= ", sum(pf.amount) as am";
1300 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1301 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1302 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1303 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1304 }
1305 $sql .= " WHERE s.rowid = ff.fk_soc";
1306 $sql .= " AND ff.entity = ".$conf->entity;
1307 $sql .= " AND ff.paye = 0";
1308 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1309 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1310 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1311 }
1312 if ($socid) {
1313 $sql .= " AND ff.fk_soc = ".((int) $socid);
1314 }
1315 // Add where from hooks
1316 $parameters = array();
1317 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1318 $sql .= $hookmanager->resPrint;
1319
1320 $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye, ff.date_lim_reglement,";
1321 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1322 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1323
1324 $resql = $db->query($sql);
1325 if ($resql) {
1326 $num = $db->num_rows($resql);
1327 $othernb = 0;
1328
1329 print '<div class="div-table-responsive-no-min">';
1330 print '<table class="noborder centpercent">';
1331
1332 print '<tr class="liste_titre">';
1333 print '<th colspan="2">';
1334 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1335 print '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['search_status' => FactureFournisseur::STATUS_VALIDATED]).'">';
1336 print '<span class="badge">'.$num.'</span>';
1337 print '</a>';
1338 print '</th>';
1339
1340 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1341 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1342 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1343 }
1344 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1345 print '<th class="right">'.$langs->trans("Paid").'</th>';
1346 print '<th width="16">&nbsp;</th>';
1347 print "</tr>\n";
1348
1349 $societestatic = new Societe($db);
1350
1351 if ($num) {
1352 $i = 0;
1353 $total = $total_ttc = $totalam = 0;
1354 while ($i < $num) {
1355 $obj = $db->fetch_object($resql);
1356
1357 if ($i >= $maxCount) {
1358 $othernb += 1;
1359 $i++;
1360 $total += $obj->total_ht;
1361 $total_ttc += $obj->total_ttc;
1362 continue;
1363 }
1364
1365 $facstatic->ref = $obj->ref;
1366 $facstatic->id = $obj->rowid;
1367 $facstatic->type = $obj->type;
1368 $facstatic->total_ht = $obj->total_ht;
1369 $facstatic->total_tva = $obj->total_tva;
1370 $facstatic->total_ttc = $obj->total_ttc;
1371 $facstatic->statut = $obj->status;
1372 $facstatic->status = $obj->status;
1373 $facstatic->paid = $obj->paye;
1374 $facstatic->paye = $obj->paye;
1375
1376 $societestatic->id = $obj->socid;
1377 $societestatic->name = $obj->name;
1378 $societestatic->email = $obj->email;
1379 $societestatic->client = 0;
1380 $societestatic->fournisseur = 1;
1381 $societestatic->code_client = $obj->code_client;
1382 $societestatic->code_fournisseur = $obj->code_fournisseur;
1383 $societestatic->code_compta = $obj->code_compta;
1384 $societestatic->code_compta_client = $obj->code_compta;
1385 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1386
1387 print '<tr class="oddeven">';
1388 print '<td class="nowrap tdoverflowmax100">';
1389 print $facstatic->getNomUrl(1, '');
1390 print '</td>';
1391 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1392 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1393 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1394 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1395 }
1396 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1397 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1398 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1399 print '</tr>';
1400 $total += $obj->total_ht;
1401 $total_ttc += $obj->total_ttc;
1402 $totalam += $obj->am;
1403 $i++;
1404 }
1405
1406 if ($othernb) {
1407 $colspan = 6;
1408 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1409 $colspan++;
1410 }
1411 print '<tr class="oddeven">';
1412 print '<td class="nowrap" colspan="'.$colspan.'">';
1413 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1414 print '</td>';
1415 print "</tr>\n";
1416 }
1417
1418 print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')</span> </td>';
1419 print '<td>&nbsp;</td>';
1420 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1421 print '<td class="right">'.price($total).'</td>';
1422 }
1423 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1424 print '<td class="nowrap right">'.price($totalam).'</td>';
1425 print '<td>&nbsp;</td>';
1426 print '</tr>';
1427 } else {
1428 $colspan = 6;
1429 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1430 $colspan++;
1431 }
1432 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1433 }
1434 print '</table></div><br>';
1435 } else {
1437 }
1438 }
1439
1440 return $result;
1441}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to build graphs.
Class to manage suppliers invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated (need to be paid)
Class to offer components to list and upload files.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
dol_now($mode='gmt')
Return date for now.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices.
invoice_admin_prepare_head()
Return array head with list of tabs to view object information.
getCustomerInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited customer invoices.
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
getPurchaseInvoiceLatestEditTable($maxCount=5, $socid=0)
Return a HTML table that contains a list with latest edited supplier invoices.
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
getCustomerInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid customers invoices.
facture_prepare_head($object)
Initialize the array of tabs for customer invoice.
getPurchaseInvoiceUnpaidOpenTable($maxCount=500, $socid=0)
Return a HTML table that contains of unpaid purchase invoices.
dol_setcache($memoryid, $data, $expire=0, $filecache=0, $replace=0)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid, $filecache=0)
Read a memory area shared by all users, all sessions on server.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:487