dolibarr 25.0.0-alpha
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 {
74 dol_print_error($db);
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.'/admin/extrafields.php', array('elementtype' => 'facture'));
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.'/admin/extrafields.php', array('elementtype' => 'facturedet'));
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.'/admin/extrafields.php', array('elementtype' => 'facture_rec'));
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.'/admin/extrafields.php', array('elementtype' => 'facturedet_rec'));
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 $theme_vars_file = dol_getThemeFilePath('theme_vars.inc.php');
430 if ($theme_vars_file) {
431 include $theme_vars_file;
432 }
433
434 $now = date_create(date('Y-m-d', dol_now()));
435 $datenowsub30 = date_create(date('Y-m-d', dol_now()));
436 $datenowsub15 = date_create(date('Y-m-d', dol_now()));
437 $datenowadd30 = date_create(date('Y-m-d', dol_now()));
438 $datenowadd15 = date_create(date('Y-m-d', dol_now()));
439 $interval30days = date_interval_create_from_date_string('30 days');
440 $interval15days = date_interval_create_from_date_string('15 days');
441 date_sub($datenowsub30, $interval30days);
442 date_sub($datenowsub15, $interval15days);
443 date_add($datenowadd30, $interval30days);
444 date_add($datenowadd15, $interval15days);
445
446 $amount_mode = (getDolGlobalInt('FACTURE_VALIDATED_IN_AMOUNT') == 1);
447
448 $sql = "SELECT";
449 $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late30";
450 $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";
451 $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";
452 $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";
453 $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";
454 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate30";
455 if ($mode == 'customers') {
456 $element = 'invoice';
457 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
458 } elseif ($mode == 'suppliers') {
459 $element = 'supplier_invoice';
460 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
461 } else {
462 return '';
463 }
464 $sql .= " WHERE f.entity IN (".getEntity($element).")";
465 $sql .= " AND f.type <> 2";
466 $sql .= " AND f.fk_statut = 1";
467 if (isset($user->socid) && $user->socid > 0) {
468 $sql .= " AND f.fk_soc = ".((int) $user->socid);
469 }
470
471 $resql = $db->query($sql);
472 if ($resql) {
473 $num = $db->num_rows($resql);
474 $i = 0;
475 $total = 0;
476 $dataseries = array();
477
478 while ($i < $num) {
479 $obj = $db->fetch_object($resql);
480 /*
481 $dataseries = array(
482 array($langs->trans('InvoiceLate30Days'), $obj->nblate30),
483 array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30),
484 array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15),
485 array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15),
486 array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30),
487 array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30),
488 );
489 */
490 $dataseries[$i] = array($langs->transnoentitiesnoconv('NbOfOpenInvoices'), $obj->late30, $obj->late15, $obj->latenow, $obj->notlatenow, $obj->notlate15, $obj->notlate30);
491 $i++;
492 }
493 if (!empty($dataseries[0])) {
494 foreach ($dataseries[0] as $key => $value) {
495 if (is_numeric($value)) {
496 $total += $value;
497 }
498 }
499 }
500 $legend = array(
501 $langs->trans('InvoiceLate30Days'),
502 $langs->trans('InvoiceLate15Days'),
503 $langs->trans('InvoiceLateMinus15Days'),
504 $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
505 $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
506 $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
507 );
508
509 $colorseries = array('#998844', $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
510
511 $result = '<div class="div-table-responsive-no-min">';
512 $result .= '<table class="noborder nohover centpercent">';
513 $result .= '<tr class="liste_titre">';
514 $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
515 if ($mode == 'customers') {
516 $result .= $langs->trans("CustomerInvoice");
517 } elseif ($mode == 'suppliers') {
518 $result .= $langs->trans("SupplierInvoice");
519 } else {
520 return '';
521 }
522 $result .= '</td>';
523 $result .= '</tr>';
524
525 if ($conf->use_javascript_ajax) {
526 $dolgraph = new DolGraph();
527 $dolgraph->SetData($dataseries); // @phan-suppress-current-line PhanTypeMismatchArgument
528
529 $dolgraph->setLegend($legend);
530
531 $dolgraph->SetDataColor($colorseries);
532 $dolgraph->setShowLegend(2);
533 $dolgraph->setShowPercent(1);
534 $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
535 //$dolgraph->SetType(array('pie'));
536 $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
537 $dolgraph->setWidth('450');
538 $dolgraph->setHideXValues(true);
539 //$dolgraph->setBarWidth('15');
540 if ($mode == 'customers') {
541 $dolgraph->draw('idgraphcustomerinvoices');
542 } elseif ($mode == 'suppliers') {
543 $dolgraph->draw('idgraphfourninvoices');
544 } else {
545 return '';
546 }
547 $result .= '<tr maxwidth="255">';
548 $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
549 $result .= '</tr>';
550 } else {
551 // Print text lines
552 }
553
554 $result .= '</table>';
555 $result .= '</div>';
556
557 return $result;
558 } else {
559 dol_print_error($db);
560 }
561 }
562 return '';
563}
564
572function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
573{
574 global $conf, $db, $langs, $user, $hookmanager;
575
576 $result = '';
577
578 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
579 if ($user->socid > 0) {
580 $socid = $user->socid;
581 }
582 $maxofloop = getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500);
583
584 $tmpinvoice = new Facture($db);
585
586 $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
587 $sql .= ", f.type, f.fk_statut as status, f.paye";
588 $sql .= ", s.nom as name";
589 $sql .= ", s.rowid as socid, s.email";
590 $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
591 $sql .= ", cc.rowid as country_id, cc.code as country_code";
592 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
593 $sql .= ", sc.fk_soc, sc.fk_user ";
594 }
595 $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";
596 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
597 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
598 }
599 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
600 $sql .= " AND f.entity IN (".getEntity('invoice').")";
601 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
602 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
603 }
604
605 if ($socid) {
606 $sql .= " AND f.fk_soc = ".((int) $socid);
607 }
608 // Add where from hooks
609 $parameters = array();
610 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
611 $sql .= $hookmanager->resPrint;
612
613 $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,";
614 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
615 $sql .= " cc.rowid, cc.code";
616 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
617 $sql .= ", sc.fk_soc, sc.fk_user";
618 }
619
620 // Add Group from hooks
621 $parameters = array();
622 $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
623 $sql .= $hookmanager->resPrint;
624
625 $resql = $db->query($sql);
626
627 if ($resql) {
628 $num = $db->num_rows($resql);
629 $nbofloop = min($num, $maxofloop);
630
631 $result .= '<div class="div-table-responsive-no-min">';
632 $result .= '<table class="noborder centpercent">';
633
634 $result .= '<tr class="liste_titre">';
635 $result .= '<th colspan="3">';
636 $result .= $langs->trans("CustomersDraftInvoices");
637 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/compta/facture/list.php', ['search_status' => Facture::STATUS_DRAFT]).'">';
638 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
639 $result .= '</a>';
640 $result .= '</th>';
641 $result .= '</tr>';
642
643 if ($num) {
644 $companystatic = new Societe($db);
645
646 $i = 0;
647 $othernb = 0;
648 $tot_ttc = 0;
649 while ($i < $nbofloop) {
650 $obj = $db->fetch_object($resql);
651
652 if ($i >= $maxCount) {
653 $othernb += 1;
654 $i++;
655 $tot_ttc += $obj->total_ttc;
656 continue;
657 }
658
659 $tmpinvoice->id = $obj->rowid;
660 $tmpinvoice->ref = $obj->ref;
661 $tmpinvoice->date = $db->jdate($obj->date);
662 $tmpinvoice->type = $obj->type;
663 $tmpinvoice->total_ht = $obj->total_ht;
664 $tmpinvoice->total_tva = $obj->total_tva;
665 $tmpinvoice->total_ttc = $obj->total_ttc;
666 $tmpinvoice->ref_client = $obj->ref_client;
667 $tmpinvoice->statut = $obj->status;
668 $tmpinvoice->paye = $obj->paye;
669
670 $companystatic->id = $obj->socid;
671 $companystatic->name = $obj->name;
672 $companystatic->email = $obj->email;
673 $companystatic->country_id = $obj->country_id;
674 $companystatic->country_code = $obj->country_code;
675 $companystatic->client = 1;
676 $companystatic->code_client = $obj->code_client;
677 $companystatic->code_fournisseur = $obj->code_fournisseur;
678 $companystatic->code_compta = $obj->code_compta;
679 $companystatic->code_compta_client = $obj->code_compta;
680 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
681
682 $result .= '<tr class="oddeven">';
683 $result .= '<td class="nowrap tdoverflowmax100">';
684 $result .= $tmpinvoice->getNomUrl(1, '');
685 $result .= '</td>';
686 $result .= '<td class="nowrap tdoverflowmax100">';
687 $result .= $companystatic->getNomUrl(1, 'customer');
688 $result .= '</td>';
689 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
690 $result .= '</tr>';
691 $tot_ttc += $obj->total_ttc;
692 $i++;
693 }
694
695 if ($othernb) {
696 $result .= '<tr class="oddeven">';
697 $result .= '<td class="nowrap" colspan="3">';
698 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
699 $result .= '</td>';
700 $result .= "</tr>\n";
701 }
702
703 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
704 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
705 $result .= '</tr>';
706 } else {
707 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
708 }
709 $result .= "</table></div>";
710 $db->free($resql);
711 } else {
712 dol_print_error($db);
713 }
714 }
715
716 return $result;
717}
718
726function getDraftSupplierTable($maxCount = 500, $socid = 0)
727{
728 global $conf, $db, $langs, $user, $hookmanager;
729
730 $result = '';
731
732 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
733 if ($user->socid > 0) {
734 $socid = $user->socid;
735 }
736 $maxofloop = getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500);
737
738 $facturesupplierstatic = new FactureFournisseur($db);
739
740 $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";
741 $sql .= ", s.nom as name";
742 $sql .= ", s.rowid as socid, s.email";
743 $sql .= ", s.code_client, s.code_compta";
744 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
745 $sql .= ", cc.rowid as country_id, cc.code as country_code";
746 $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";
747 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
748 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
749 }
750 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
751 $sql .= " AND f.entity IN (".getEntity('invoice').')';
752 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
753 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
754 }
755 if ($socid) {
756 $sql .= " AND f.fk_soc = ".((int) $socid);
757 }
758 // Add where from hooks
759 $parameters = array();
760 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
761 $sql .= $hookmanager->resPrint;
762 $resql = $db->query($sql);
763
764 if ($resql) {
765 $num = $db->num_rows($resql);
766 $nbofloop = min($num, $maxofloop);
767
768 $result .= '<div class="div-table-responsive-no-min">';
769 $result .= '<table class="noborder centpercent">';
770
771 $result .= '<tr class="liste_titre">';
772 $result .= '<th colspan="3">';
773 $result .= $langs->trans("SuppliersDraftInvoices");
774 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['search_status' => FactureFournisseur::STATUS_DRAFT]).'">';
775 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
776 $result .= '</a>';
777 $result .= '</th>';
778 $result .= '</tr>';
779
780 if ($num) {
781 $companystatic = new Societe($db);
782
783 $i = 0;
784 $othernb = 0;
785 $tot_ttc = 0;
786 while ($i < $nbofloop) {
787 $obj = $db->fetch_object($resql);
788
789 if ($i >= $maxCount) {
790 $othernb += 1;
791 $i++;
792 $tot_ttc += $obj->total_ttc;
793 continue;
794 }
795
796 $facturesupplierstatic->ref = $obj->ref;
797 $facturesupplierstatic->id = $obj->rowid;
798 $facturesupplierstatic->total_ht = $obj->total_ht;
799 $facturesupplierstatic->total_tva = $obj->total_tva;
800 $facturesupplierstatic->total_ttc = $obj->total_ttc;
801 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
802 $facturesupplierstatic->type = $obj->type;
803 $facturesupplierstatic->statut = $obj->status;
804 $facturesupplierstatic->status = $obj->status;
805 $facturesupplierstatic->paye = $obj->paye;
806 $facturesupplierstatic->paid = $obj->paye;
807
808 $companystatic->id = $obj->socid;
809 $companystatic->name = $obj->name;
810 $companystatic->email = $obj->email;
811 $companystatic->country_id = $obj->country_id;
812 $companystatic->country_code = $obj->country_code;
813 $companystatic->fournisseur = 1;
814 $companystatic->code_client = $obj->code_client;
815 $companystatic->code_fournisseur = $obj->code_fournisseur;
816 $companystatic->code_compta = $obj->code_compta;
817 $companystatic->code_compta_client = $obj->code_compta;
818 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
819
820 $result .= '<tr class="oddeven">';
821 $result .= '<td class="nowrap tdoverflowmax100">';
822 $result .= $facturesupplierstatic->getNomUrl(1, '');
823 $result .= '</td>';
824 $result .= '<td class="nowrap tdoverflowmax100">';
825 $result .= $companystatic->getNomUrl(1, 'supplier');
826 $result .= '</td>';
827 $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
828 $result .= '</tr>';
829 $tot_ttc += $obj->total_ttc;
830 $i++;
831 }
832
833 if ($othernb) {
834 $result .= '<tr class="oddeven">';
835 $result .= '<td class="nowrap" colspan="3">';
836 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
837 $result .= '</td>';
838 $result .= "</tr>\n";
839 }
840
841 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
842 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
843 $result .= '</tr>';
844 } else {
845 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
846 }
847 $result .= "</table></div>";
848 $db->free($resql);
849 } else {
850 dol_print_error($db);
851 }
852 }
853
854 return $result;
855}
856
857
865function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
866{
867 global $conf, $db, $langs, $user;
868 if ($user->socid > 0) {
869 $socid = $user->socid;
870 }
871 $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,";
872 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
873 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
874 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
875 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
876 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
877 }
878 $sql .= " WHERE f.fk_soc = s.rowid";
879 $sql .= " AND f.entity IN (".getEntity('facture').")";
880 if ($socid) {
881 $sql .= " AND f.fk_soc = ".((int) $socid);
882 }
883 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
884 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
885 }
886 $sql .= " ORDER BY f.tms DESC";
887 $sql .= $db->plimit($maxCount, 0);
888
889 $resql = $db->query($sql);
890 if (!$resql) {
891 dol_print_error($db);
892 }
893
894 $num = $db->num_rows($resql);
895
896 $result = '<div class="div-table-responsive-no-min">';
897 $result .= '<table class="noborder centpercent">';
898
899 $result .= '<tr class="liste_titre">';
900 $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
901 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
902 $result .= '<th class="right"></th>';
903 $result .= '</tr>';
904
905 if ($num < 1) {
906 $result .= '</table>';
907 $result .= '</div>';
908 return $result;
909 }
910
911 $formfile = new FormFile($db);
912 $objectstatic = new Facture($db);
913 $companystatic = new Societe($db);
914 $i = 0;
915
916 while ($i < $num) {
917 $obj = $db->fetch_object($resql);
918
919 $objectstatic->id = $obj->rowid;
920 $objectstatic->ref = $obj->ref;
921 $objectstatic->paye = $obj->paye;
922 $objectstatic->statut = $obj->status;
923 $objectstatic->status = $obj->status;
924 $objectstatic->total_ht = $obj->total_ht;
925 $objectstatic->total_tva = $obj->total_tva;
926 $objectstatic->total_ttc = $obj->total_ttc;
927 $objectstatic->type = $obj->type;
928
929 $companystatic->id = $obj->socid;
930 $companystatic->name = $obj->socname;
931 $companystatic->client = $obj->client;
932 $companystatic->canvas = $obj->canvas;
933
934 $filename = dol_sanitizeFileName($obj->ref);
935 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
936
937 $result .= '<tr class="oddeven">';
938
939 $result .= '<td class="nowrap">';
940 $result .= '<table class="nobordernopadding">';
941 $result .= '<tr class="nocellnopadd">';
942
943 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
944 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
945 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
946
947 $result .= '</tr>';
948 $result .= '</table>';
949 $result .= '</td>';
950
951 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
952 $result .= '<td title="'.dol_print_date($db->jdate($obj->datec), 'day').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
953 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
954
955 // Load amount of existing payment of invoice (needed for complete status)
956 $payment = $objectstatic->getSommePaiement();
957 $result .= '<td class="right">'.$objectstatic->getLibStatut(3, $payment).'</td>';
958
959 $result .= '</tr>';
960
961 $i++;
962 }
963
964 $result .= '</table>';
965 $result .= '</div>';
966 return $result;
967}
968
976function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
977{
978 global $conf, $db, $langs, $user;
979 if ($user->socid > 0) {
980 $socid = $user->socid;
981 }
982 $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,";
983 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
984 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
985 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
986 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
987 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
988 }
989 $sql .= " WHERE f.fk_soc = s.rowid";
990 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
991 if ($socid) {
992 $sql .= " AND f.fk_soc = ".((int) $socid);
993 }
994 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
995 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
996 }
997 $sql .= " ORDER BY f.tms DESC";
998 $sql .= $db->plimit($maxCount, 0);
999
1000 $resql = $db->query($sql);
1001 if (!$resql) {
1002 dol_print_error($db);
1003 return '';
1004 }
1005
1006 $num = $db->num_rows($resql);
1007
1008 $result = '<div class="div-table-responsive-no-min">';
1009 $result .= '<table class="noborder centpercent">';
1010 $result .= '<tr class="liste_titre">';
1011 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
1012 $result .= '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['sortfield' => 'f.tms', 'sortorder' => 'DESC']).'">';
1013 $result .= '<span class="badge">...</span>';
1014 $result .= '</a>';
1015 $result .= '</th>';
1016 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1017 $result .= '<th class="right"></th>';
1018 $result .= '</tr>';
1019
1020 if ($num < 1) {
1021 $result .= '</table>';
1022 $result .= '</div>';
1023 return $result;
1024 }
1025
1026 $objectstatic = new FactureFournisseur($db);
1027 $companystatic = new Societe($db);
1028 $formfile = new FormFile($db);
1029 $i = 0;
1030
1031 while ($i < $num) {
1032 $obj = $db->fetch_object($resql);
1033
1034 $objectstatic->id = $obj->rowid;
1035 $objectstatic->ref = $obj->ref;
1036 $objectstatic->paye = $obj->paye;
1037 $objectstatic->paid = $obj->paye;
1038 $objectstatic->statut = $obj->status;
1039 $objectstatic->status = $obj->status;
1040 $objectstatic->total_ht = $obj->total_ht;
1041 $objectstatic->total_tva = $obj->total_tva;
1042 $objectstatic->total_ttc = $obj->total_ttc;
1043 $objectstatic->type = $obj->type;
1044
1045 $companystatic->id = $obj->socid;
1046 $companystatic->name = $obj->socname;
1047 $companystatic->client = $obj->client;
1048 $companystatic->canvas = $obj->canvas;
1049
1050 $filename = dol_sanitizeFileName($obj->ref);
1051 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
1052
1053 $result .= '<tr class="nowrap">';
1054
1055 $result .= '<td class="oddeven">';
1056 $result .= '<table class="nobordernopadding">';
1057 $result .= '<tr class="nocellnopadd">';
1058
1059 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
1060 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
1061 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
1062
1063 $result .= '</tr>';
1064 $result .= '</table>';
1065 $result .= '</td>';
1066
1067 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1068
1069 $result .= '<td title="'.$langs->trans("DateModification").': '.dol_print_date($db->jdate($obj->datec), 'dayhour').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
1070
1071 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
1072
1073 $result .= '<td class="right">'.$objectstatic->getLibStatut(3).'</td>';
1074
1075 $result .= '</tr>';
1076
1077 $i++;
1078 }
1079
1080 $result .= '</table>';
1081 $result .= '</div>';
1082 return $result;
1083}
1084
1092function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1093{
1094 global $conf, $db, $langs, $user, $hookmanager;
1095
1096 $result = '';
1097
1098 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1099 if ($user->socid > 0) {
1100 $socid = $user->socid;
1101 }
1102 $tmpinvoice = new Facture($db);
1103
1104 $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";
1105 $sql .= ", f.date_lim_reglement as datelimite";
1106 $sql .= ", s.nom as name";
1107 $sql .= ", s.rowid as socid, s.email";
1108 $sql .= ", s.code_client, s.code_compta";
1109 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1110 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1111 $sql .= ", sum(pf.amount) as am";
1112 $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";
1113 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1114 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1115 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1116 }
1117 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1118 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1119 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1120 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1121 }
1122 if ($socid) {
1123 $sql .= " AND f.fk_soc = ".((int) $socid);
1124 }
1125 // Add where from hooks
1126 $parameters = array();
1127 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1128 $sql .= $hookmanager->resPrint;
1129
1130 $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,";
1131 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1132 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1133 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1134
1135 $resql = $db->query($sql);
1136 if ($resql) {
1137 $num = $db->num_rows($resql);
1138 $i = 0;
1139 $othernb = 0;
1140
1141 $formfile = new FormFile($db);
1142
1143 print '<div class="div-table-responsive-no-min">';
1144 print '<table class="noborder centpercent">';
1145
1146 print '<tr class="liste_titre">';
1147 print '<th colspan="2">';
1148 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1149 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1150 print '<span class="badge">'.$num.'</span>';
1151 print '</a>';
1152 print '</th>';
1153
1154 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1155 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1156 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1157 }
1158 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1159 print '<th class="right">'.$langs->trans("Received").'</th>';
1160 print '<th width="16">&nbsp;</th>';
1161 print '</tr>';
1162 if ($num) {
1163 $societestatic = new Societe($db);
1164 $total_ttc = $totalam = $total = 0;
1165 while ($i < $num) {
1166 $obj = $db->fetch_object($resql);
1167
1168 if ($i >= $maxCount) {
1169 $othernb += 1;
1170 $i++;
1171 $total += $obj->total_ht;
1172 $total_ttc += $obj->total_ttc;
1173 $totalam += $obj->am;
1174 continue;
1175 }
1176
1177 $tmpinvoice->ref = $obj->ref;
1178 $tmpinvoice->id = $obj->rowid;
1179 $tmpinvoice->total_ht = $obj->total_ht;
1180 $tmpinvoice->total_tva = $obj->total_tva;
1181 $tmpinvoice->total_ttc = $obj->total_ttc;
1182 $tmpinvoice->type = $obj->type;
1183 $tmpinvoice->statut = $obj->status;
1184 $tmpinvoice->paye = $obj->paye;
1185 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1186
1187 $societestatic->id = $obj->socid;
1188 $societestatic->name = $obj->name;
1189 $societestatic->email = $obj->email;
1190 $societestatic->country_id = $obj->country_id;
1191 $societestatic->country_code = $obj->country_code;
1192 $societestatic->client = 1;
1193 $societestatic->code_client = $obj->code_client;
1194 $societestatic->code_fournisseur = $obj->code_fournisseur;
1195 $societestatic->code_compta = $obj->code_compta;
1196 $societestatic->code_compta_client = $obj->code_compta;
1197 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1198
1199 print '<tr class="oddeven">';
1200 print '<td class="nowrap">';
1201
1202 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1203 print '<td class="nobordernopadding nowrap">';
1204 print $tmpinvoice->getNomUrl(1, '');
1205 print '</td>';
1206 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1207 $filename = dol_sanitizeFileName($obj->ref);
1208 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1209 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1210 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1211 print '</td></tr></table>';
1212
1213 print '</td>';
1214 print '<td class="nowrap tdoverflowmax100">';
1215 print $societestatic->getNomUrl(1, 'customer');
1216 print '</td>';
1217 print '<td class="right" title="'.dol_print_date($db->jdate($obj->datelimite), 'day').'">';
1218 print dol_print_date($db->jdate($obj->datelimite), 'day');
1219 if ($tmpinvoice->hasDelay()) {
1220 print img_warning($langs->trans("Late"));
1221 }
1222 print '</td>';
1223 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1224 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1225 }
1226 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1227 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1228 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1229 print '</tr>';
1230
1231 $total_ttc += $obj->total_ttc;
1232 $total += $obj->total_ht;
1233 $totalam += $obj->am;
1234
1235 $i++;
1236 }
1237
1238 if ($othernb) {
1239 $colspan = 6;
1240 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1241 $colspan++;
1242 }
1243 print '<tr class="oddeven">';
1244 print '<td class="nowrap" colspan="'.$colspan.'">';
1245 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1246 print '</td>';
1247 print "</tr>\n";
1248 }
1249
1250 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>';
1251 print '<td>&nbsp;</td>';
1252 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1253 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1254 }
1255 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1256 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1257 print '<td>&nbsp;</td>';
1258 print '</tr>';
1259 } else {
1260 $colspan = 6;
1261 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1262 $colspan++;
1263 }
1264 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1265 }
1266 print '</table></div><br>';
1267 $db->free($resql);
1268 } else {
1269 dol_print_error($db);
1270 }
1271 }
1272
1273 return $result;
1274}
1275
1276
1284function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1285{
1286 global $conf, $db, $langs, $user, $hookmanager;
1287
1288 $result = '';
1289
1290 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1291 if ($user->socid > 0) {
1292 $socid = $user->socid;
1293 }
1294 $facstatic = new FactureFournisseur($db);
1295
1296 $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";
1297 $sql .= ", ff.date_lim_reglement";
1298 $sql .= ", s.nom as name";
1299 $sql .= ", s.rowid as socid, s.email";
1300 $sql .= ", s.code_client, s.code_compta";
1301 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1302 $sql .= ", sum(pf.amount) as am";
1303 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1304 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1305 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1306 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1307 }
1308 $sql .= " WHERE s.rowid = ff.fk_soc";
1309 $sql .= " AND ff.entity = ".((int) $conf->entity);
1310 $sql .= " AND ff.paye = 0";
1311 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1312 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1313 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1314 }
1315 if ($socid) {
1316 $sql .= " AND ff.fk_soc = ".((int) $socid);
1317 }
1318 // Add where from hooks
1319 $parameters = array();
1320 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1321 $sql .= $hookmanager->resPrint;
1322
1323 $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,";
1324 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1325 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1326
1327 $resql = $db->query($sql);
1328 if ($resql) {
1329 $num = $db->num_rows($resql);
1330 $othernb = 0;
1331
1332 print '<div class="div-table-responsive-no-min">';
1333 print '<table class="noborder centpercent">';
1334
1335 print '<tr class="liste_titre">';
1336 print '<th colspan="2">';
1337 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1338 print '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/fourn/facture/list.php', ['search_status' => FactureFournisseur::STATUS_VALIDATED]).'">';
1339 print '<span class="badge">'.$num.'</span>';
1340 print '</a>';
1341 print '</th>';
1342
1343 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1344 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1345 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1346 }
1347 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1348 print '<th class="right">'.$langs->trans("Paid").'</th>';
1349 print '<th width="16">&nbsp;</th>';
1350 print "</tr>\n";
1351
1352 $societestatic = new Societe($db);
1353
1354 if ($num) {
1355 $i = 0;
1356 $total = $total_ttc = $totalam = 0;
1357 while ($i < $num) {
1358 $obj = $db->fetch_object($resql);
1359
1360 if ($i >= $maxCount) {
1361 $othernb += 1;
1362 $i++;
1363 $total += $obj->total_ht;
1364 $total_ttc += $obj->total_ttc;
1365 continue;
1366 }
1367
1368 $facstatic->ref = $obj->ref;
1369 $facstatic->id = $obj->rowid;
1370 $facstatic->type = $obj->type;
1371 $facstatic->total_ht = $obj->total_ht;
1372 $facstatic->total_tva = $obj->total_tva;
1373 $facstatic->total_ttc = $obj->total_ttc;
1374 $facstatic->statut = $obj->status;
1375 $facstatic->status = $obj->status;
1376 $facstatic->paid = $obj->paye;
1377 $facstatic->paye = $obj->paye;
1378
1379 $societestatic->id = $obj->socid;
1380 $societestatic->name = $obj->name;
1381 $societestatic->email = $obj->email;
1382 $societestatic->client = 0;
1383 $societestatic->fournisseur = 1;
1384 $societestatic->code_client = $obj->code_client;
1385 $societestatic->code_fournisseur = $obj->code_fournisseur;
1386 $societestatic->code_compta = $obj->code_compta;
1387 $societestatic->code_compta_client = $obj->code_compta;
1388 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1389
1390 print '<tr class="oddeven">';
1391 print '<td class="nowrap tdoverflowmax100">';
1392 print $facstatic->getNomUrl(1, '');
1393 print '</td>';
1394 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1395 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1396 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1397 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1398 }
1399 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1400 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1401 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1402 print '</tr>';
1403 $total += $obj->total_ht;
1404 $total_ttc += $obj->total_ttc;
1405 $totalam += $obj->am;
1406 $i++;
1407 }
1408
1409 if ($othernb) {
1410 $colspan = 6;
1411 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1412 $colspan++;
1413 }
1414 print '<tr class="oddeven">';
1415 print '<td class="nowrap" colspan="'.$colspan.'">';
1416 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1417 print '</td>';
1418 print "</tr>\n";
1419 }
1420
1421 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>';
1422 print '<td>&nbsp;</td>';
1423 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1424 print '<td class="right">'.price($total).'</td>';
1425 }
1426 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1427 print '<td class="nowrap right">'.price($totalam).'</td>';
1428 print '<td>&nbsp;</td>';
1429 print '</tr>';
1430 } else {
1431 $colspan = 6;
1432 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1433 $colspan++;
1434 }
1435 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1436 }
1437 print '</table></div><br>';
1438 } else {
1439 dol_print_error($db);
1440 }
1441 }
1442
1443 return $result;
1444}
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:
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:65
dol_now($mode='gmt')
Return date for now.
dol_getThemeFilePath($file, $theme='')
Return the full filesystem path of a file located in the currently selected theme directory.
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).
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:492