dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024 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] = 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] = DOL_URL_ROOT.'/compta/facture/contact.php?id='.urlencode((string) ($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] = DOL_URL_ROOT.'/compta/facture/prelevement.php?id='.urlencode((string) ($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] = 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] = 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] = 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, $user, $db;
175
176 $extrafields = new ExtraFields($db);
177 $extrafields->fetch_name_optionals_label('facture');
178 $extrafields->fetch_name_optionals_label('facturedet');
179 $extrafields->fetch_name_optionals_label('facture_rec');
180 $extrafields->fetch_name_optionals_label('facturedet_rec');
181
182 $h = 0;
183 $head = array();
184
185 $head[$h][0] = DOL_URL_ROOT.'/admin/invoice.php';
186 $head[$h][1] = $langs->trans("Miscellaneous");
187 $head[$h][2] = 'general';
188 $h++;
189
190 $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
191 $head[$h][1] = $langs->trans("Payments");
192 $head[$h][2] = 'payment';
193 $h++;
194
195 // Show more tabs from modules
196 // Entries must be declared in modules descriptor with line
197 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
198 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
199 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
200
201 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoice_cust_extrafields.php';
202 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
203 $nbExtrafields = $extrafields->attributes['facture']['count'];
204 if ($nbExtrafields > 0) {
205 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
206 }
207 $head[$h][2] = 'attributes';
208 $h++;
209
210 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoicedet_cust_extrafields.php';
211 $head[$h][1] = $langs->trans("ExtraFieldsLines");
212 $nbExtrafields = $extrafields->attributes['facturedet']['count'];
213 if ($nbExtrafields > 0) {
214 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
215 }
216 $head[$h][2] = 'attributeslines';
217 $h++;
218
219 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoice_rec_cust_extrafields.php';
220 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
221 $nbExtrafields = $extrafields->attributes['facture_rec']['count'];
222 if ($nbExtrafields > 0) {
223 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
224 }
225 $head[$h][2] = 'attributesrec';
226 $h++;
227
228 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/invoicedet_rec_cust_extrafields.php';
229 $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
230 $nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
231 if ($nbExtrafields > 0) {
232 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
233 }
234 $head[$h][2] = 'attributeslinesrec';
235 $h++;
236
237 if (getDolGlobalInt('INVOICE_USE_SITUATION') > 0) { // Warning, implementation with value 1 is seriously bugged and a new one not compatible is expected to become stable
238 $head[$h][0] = DOL_URL_ROOT.'/admin/invoice_situation.php';
239 $head[$h][1] = $langs->trans("InvoiceSituation");
240 $head[$h][2] = 'situation';
241 $h++;
242 }
243
244 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
245
246 return $head;
247}
248
249
257{
258 global $db, $langs, $conf, $user;
259
260 $h = 0;
261 $head = array();
262
263 $head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
264 $head[$h][1] = $langs->trans("RepeatableInvoice");
265 $head[$h][2] = 'card';
266 $h++;
267
268 $head[$h][0] = DOL_URL_ROOT . '/compta/facture/list.php?search_fk_fac_rec_source=' . $object->id;
269 $head[$h][1] = $langs->trans('InvoicesGeneratedFromRec');
270 //count facture rec
271 $nbFacture = 0;
272 $sql = "SELECT COUNT(rowid) as nb";
273 $sql .= " FROM ".MAIN_DB_PREFIX."facture";
274 $sql .= " WHERE fk_fac_rec_source = ".((int) $object->id);
275 $resql = $db->query($sql);
276 if ($resql) {
277 $obj = $db->fetch_object($resql);
278 $nbFacture = $obj->nb;
279 } else {
280 dol_syslog('Failed to count invoices with invoice model '.$db->lasterror(), LOG_ERR);
281 }
282 if ($nbFacture > 0) {
283 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFacture.'</span>';
284 }
285 $head[$h][2] = 'generated';
286 $h++;
287
288 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
289 $nbNote = 0;
290 if (!empty($object->note_private)) {
291 $nbNote++;
292 }
293 if (!empty($object->note_public)) {
294 $nbNote++;
295 }
296 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note-rec.php?id='.$object->id;
297 $head[$h][1] = $langs->trans('Notes');
298 if ($nbNote > 0) {
299 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
300 }
301 $head[$h][2] = 'note';
302 $h++;
303 }
304
305 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/agenda-rec.php?id='.$object->id;
306 $head[$h][1] = $langs->trans("Events");
307 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
308 $nbEvent = 0;
309 // Enable caching of thirdparty count actioncomm
310 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
311 $cachekey = 'count_events_facturerec_'.$object->id;
312 $dataretrieved = dol_getcache($cachekey);
313 if (!is_null($dataretrieved)) {
314 $nbEvent = $dataretrieved;
315 } else {
316 $sql = "SELECT COUNT(id) as nb";
317 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
318 $sql .= " WHERE fk_element = ".((int) $object->id);
319 $sql .= " AND elementtype = 'invoicerec'";
320 $resql = $db->query($sql);
321 if ($resql) {
322 $obj = $db->fetch_object($resql);
323 $nbEvent = $obj->nb;
324 } else {
325 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
326 }
327 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
328 }
329
330 $head[$h][1] .= '/';
331 $head[$h][1] .= $langs->trans("Agenda");
332 if ($nbEvent > 0) {
333 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
334 }
335 }
336 $head[$h][2] = 'agenda';
337 $h++;
338
339 // Show more tabs from modules
340 // Entries must be declared in modules descriptor with line
341 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
342 // $this->tabs = array('entity:-tabname); to remove a tab
343 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
344
345 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
346
347 return $head;
348}
349
357{
358 global $db, $langs, $conf;
359
360 $h = 0;
361 $head = array();
362
363 $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
364 $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
365 $head[$h][2] = 'card';
366 $h++;
367
368 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
369 $nbNote = 0;
370 if (!empty($object->note_private)) {
371 $nbNote++;
372 }
373 if (!empty($object->note_public)) {
374 $nbNote++;
375 }
376 $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note-rec.php?id='.$object->id;
377 $head[$h][1] = $langs->trans('Notes');
378 if ($nbNote > 0) {
379 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
380 }
381 $head[$h][2] = 'note';
382 $h++;
383 }
384 $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/list.php?search_fk_fac_rec_source=' . $object->id;
385 $head[$h][1] = $langs->trans('InvoicesGeneratedFromRec');
386
387 //count facture rec
388 $nbFactureFourn = 0;
389 $sql = "SELECT COUNT(rowid) as nb";
390 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
391 $sql .= " WHERE fk_fac_rec_source = ".((int) $object->id);
392 $resql = $db->query($sql);
393 if ($resql) {
394 $obj = $db->fetch_object($resql);
395 $nbFactureFourn = $obj->nb;
396 } else {
397 dol_syslog('Failed to count invoices with supplier invoice model '.$db->lasterror(), LOG_ERR);
398 }
399 if ($nbFactureFourn > 0) {
400 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFactureFourn.'</span>';
401 }
402 $head[$h][2] = 'generated';
403 $h++;
404
405 // Show more tabs from modules
406 // Entries must be declared in modules descriptor with line
407 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
408 // $this->tabs = array('entity:-tabname); to remove a tab
409 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
410
411 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
412
413 return $head;
414}
415
423{
424 global $conf, $db, $langs, $user;
425
426 if (($mode == 'customers' && isModEnabled('invoice') && $user->hasRight('facture', 'lire'))
427 || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('fournisseur', 'facture', 'lire'))
428 ) {
429 global $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus8, $badgeStatus11;
430 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
431
432 $now = date_create(date('Y-m-d', dol_now()));
433 $datenowsub30 = date_create(date('Y-m-d', dol_now()));
434 $datenowsub15 = date_create(date('Y-m-d', dol_now()));
435 $datenowadd30 = date_create(date('Y-m-d', dol_now()));
436 $datenowadd15 = date_create(date('Y-m-d', dol_now()));
437 $interval30days = date_interval_create_from_date_string('30 days');
438 $interval15days = date_interval_create_from_date_string('15 days');
439 date_sub($datenowsub30, $interval30days);
440 date_sub($datenowsub15, $interval15days);
441 date_add($datenowadd30, $interval30days);
442 date_add($datenowadd15, $interval15days);
443
444 $amount_mode = (getDolGlobalInt('FACTURE_VALIDATED_IN_AMOUNT') == 1);
445
446 $sql = "SELECT";
447 $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as late30";
448 $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";
449 $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";
450 $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";
451 $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";
452 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement >= '".date_format($datenowadd30, 'Y-m-d')."'", $amount_mode ? "f.total_ht" : 1, '0').") as notlate30";
453 if ($mode == 'customers') {
454 $element = 'invoice';
455 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
456 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
457 $element = 'supplier_invoice';
458 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
459 } else {
460 return '';
461 }
462 $sql .= " WHERE f.entity IN (".getEntity($element).")";
463 $sql .= " AND f.type <> 2";
464 $sql .= " AND f.fk_statut = 1";
465 if (isset($user->socid) && $user->socid > 0) {
466 $sql .= " AND f.fk_soc = ".((int) $user->socid);
467 }
468
469 $resql = $db->query($sql);
470 if ($resql) {
471 $num = $db->num_rows($resql);
472 $i = 0;
473 $total = 0;
474 $dataseries = array();
475
476 while ($i < $num) {
477 $obj = $db->fetch_object($resql);
478 /*
479 $dataseries = array(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 $dataseries[$i] = array($langs->transnoentitiesnoconv('NbOfOpenInvoices'), $obj->late30, $obj->late15, $obj->latenow, $obj->notlatenow, $obj->notlate15, $obj->notlate30);
487 $i++;
488 }
489 if (!empty($dataseries[0])) {
490 foreach ($dataseries[0] as $key => $value) {
491 if (is_numeric($value)) {
492 $total += $value;
493 }
494 }
495 }
496 $legend = array(
497 $langs->trans('InvoiceLate30Days'),
498 $langs->trans('InvoiceLate15Days'),
499 $langs->trans('InvoiceLateMinus15Days'),
500 $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
501 $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
502 $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
503 );
504
505 $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
506
507 $result = '<div class="div-table-responsive-no-min">';
508 $result .= '<table class="noborder nohover centpercent">';
509 $result .= '<tr class="liste_titre">';
510 $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
511 if ($mode == 'customers') {
512 $result .= $langs->trans("CustomerInvoice");
513 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
514 $result .= $langs->trans("SupplierInvoice");
515 } else {
516 return '';
517 }
518 $result .= '</td>';
519 $result .= '</tr>';
520
521 if ($conf->use_javascript_ajax) {
522 //var_dump($dataseries);
523 $dolgraph = new DolGraph();
524 $dolgraph->SetData($dataseries); // @phan-suppress-current-line PhanTypeMismatchArgument
525
526 $dolgraph->setLegend($legend);
527
528 $dolgraph->SetDataColor(array_values($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 if ($mode == 'customers') {
537 $dolgraph->draw('idgraphcustomerinvoices');
538 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
539 $dolgraph->draw('idgraphfourninvoices');
540 } else {
541 return '';
542 }
543 $result .= '<tr maxwidth="255">';
544 $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
545 $result .= '</tr>';
546 } else {
547 // Print text lines
548 }
549
550 $result .= '</table>';
551 $result .= '</div>';
552
553 return $result;
554 } else {
555 dol_print_error($db);
556 }
557 }
558 return '';
559}
560
568function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
569{
570 global $conf, $db, $langs, $user, $hookmanager;
571
572 $result = '';
573
574 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
575 if ($user->socid > 0) {
576 $socid = $user->socid;
577 }
578 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
579
580 $tmpinvoice = new Facture($db);
581
582 $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
583 $sql .= ", f.type, f.fk_statut as status, f.paye";
584 $sql .= ", s.nom as name";
585 $sql .= ", s.rowid as socid, s.email";
586 $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
587 $sql .= ", cc.rowid as country_id, cc.code as country_code";
588 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
589 $sql .= ", sc.fk_soc, sc.fk_user ";
590 }
591 $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";
592 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
593 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
594 }
595 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
596 $sql .= " AND f.entity IN (".getEntity('invoice').")";
597 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
598 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
599 }
600
601 if ($socid) {
602 $sql .= " AND f.fk_soc = ".((int) $socid);
603 }
604 // Add where from hooks
605 $parameters = array();
606 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
607 $sql .= $hookmanager->resPrint;
608
609 $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,";
610 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
611 $sql .= " cc.rowid, cc.code";
612 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
613 $sql .= ", sc.fk_soc, sc.fk_user";
614 }
615
616 // Add Group from hooks
617 $parameters = array();
618 $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
619 $sql .= $hookmanager->resPrint;
620
621 $resql = $db->query($sql);
622
623 if ($resql) {
624 $num = $db->num_rows($resql);
625 $nbofloop = min($num, $maxofloop);
626
627 $result .= '<div class="div-table-responsive-no-min">';
628 $result .= '<table class="noborder centpercent">';
629
630 $result .= '<tr class="liste_titre">';
631 $result .= '<th colspan="3">';
632 $result .= $langs->trans("CustomersDraftInvoices");
633 $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
634 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
635 $result .= '</a>';
636 $result .= '</th>';
637 $result .= '</tr>';
638
639 if ($num) {
640 $companystatic = new Societe($db);
641
642 $i = 0;
643 $othernb = 0;
644 $tot_ttc = 0;
645 while ($i < $nbofloop) {
646 $obj = $db->fetch_object($resql);
647
648 if ($i >= $maxCount) {
649 $othernb += 1;
650 $i++;
651 $tot_ttc += $obj->total_ttc;
652 continue;
653 }
654
655 $tmpinvoice->id = $obj->rowid;
656 $tmpinvoice->ref = $obj->ref;
657 $tmpinvoice->date = $db->jdate($obj->date);
658 $tmpinvoice->type = $obj->type;
659 $tmpinvoice->total_ht = $obj->total_ht;
660 $tmpinvoice->total_tva = $obj->total_tva;
661 $tmpinvoice->total_ttc = $obj->total_ttc;
662 $tmpinvoice->ref_client = $obj->ref_client;
663 $tmpinvoice->statut = $obj->status;
664 $tmpinvoice->paye = $obj->paye;
665
666 $companystatic->id = $obj->socid;
667 $companystatic->name = $obj->name;
668 $companystatic->email = $obj->email;
669 $companystatic->country_id = $obj->country_id;
670 $companystatic->country_code = $obj->country_code;
671 $companystatic->client = 1;
672 $companystatic->code_client = $obj->code_client;
673 $companystatic->code_fournisseur = $obj->code_fournisseur;
674 $companystatic->code_compta = $obj->code_compta;
675 $companystatic->code_compta_client = $obj->code_compta;
676 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
677
678 $result .= '<tr class="oddeven">';
679 $result .= '<td class="nowrap tdoverflowmax100">';
680 $result .= $tmpinvoice->getNomUrl(1, '');
681 $result .= '</td>';
682 $result .= '<td class="nowrap tdoverflowmax100">';
683 $result .= $companystatic->getNomUrl(1, 'customer');
684 $result .= '</td>';
685 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
686 $result .= '</tr>';
687 $tot_ttc += $obj->total_ttc;
688 $i++;
689 }
690
691 if ($othernb) {
692 $result .= '<tr class="oddeven">';
693 $result .= '<td class="nowrap" colspan="3">';
694 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
695 $result .= '</td>';
696 $result .= "</tr>\n";
697 }
698
699 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
700 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
701 $result .= '</tr>';
702 } else {
703 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
704 }
705 $result .= "</table></div>";
706 $db->free($resql);
707 } else {
708 dol_print_error($db);
709 }
710 }
711
712 return $result;
713}
714
722function getDraftSupplierTable($maxCount = 500, $socid = 0)
723{
724 global $conf, $db, $langs, $user, $hookmanager;
725
726 $result = '';
727
728 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
729 if ($user->socid > 0) {
730 $socid = $user->socid;
731 }
732 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
733
734 $facturesupplierstatic = new FactureFournisseur($db);
735
736 $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";
737 $sql .= ", s.nom as name";
738 $sql .= ", s.rowid as socid, s.email";
739 $sql .= ", s.code_client, s.code_compta";
740 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
741 $sql .= ", cc.rowid as country_id, cc.code as country_code";
742 $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";
743 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
744 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
745 }
746 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
747 $sql .= " AND f.entity IN (".getEntity('invoice').')';
748 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
749 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
750 }
751 if ($socid) {
752 $sql .= " AND f.fk_soc = ".((int) $socid);
753 }
754 // Add where from hooks
755 $parameters = array();
756 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
757 $sql .= $hookmanager->resPrint;
758 $resql = $db->query($sql);
759
760 if ($resql) {
761 $num = $db->num_rows($resql);
762 $nbofloop = min($num, $maxofloop);
763
764 $result .= '<div class="div-table-responsive-no-min">';
765 $result .= '<table class="noborder centpercent">';
766
767 $result .= '<tr class="liste_titre">';
768 $result .= '<th colspan="3">';
769 $result .= $langs->trans("SuppliersDraftInvoices");
770 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
771 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
772 $result .= '</a>';
773 $result .= '</th>';
774 $result .= '</tr>';
775
776 if ($num) {
777 $companystatic = new Societe($db);
778
779 $i = 0;
780 $othernb = 0;
781 $tot_ttc = 0;
782 while ($i < $nbofloop) {
783 $obj = $db->fetch_object($resql);
784
785 if ($i >= $maxCount) {
786 $othernb += 1;
787 $i++;
788 $tot_ttc += $obj->total_ttc;
789 continue;
790 }
791
792 $facturesupplierstatic->ref = $obj->ref;
793 $facturesupplierstatic->id = $obj->rowid;
794 $facturesupplierstatic->total_ht = $obj->total_ht;
795 $facturesupplierstatic->total_tva = $obj->total_tva;
796 $facturesupplierstatic->total_ttc = $obj->total_ttc;
797 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
798 $facturesupplierstatic->type = $obj->type;
799 $facturesupplierstatic->statut = $obj->status;
800 $facturesupplierstatic->status = $obj->status;
801 $facturesupplierstatic->paye = $obj->paye;
802 $facturesupplierstatic->paid = $obj->paye;
803
804 $companystatic->id = $obj->socid;
805 $companystatic->name = $obj->name;
806 $companystatic->email = $obj->email;
807 $companystatic->country_id = $obj->country_id;
808 $companystatic->country_code = $obj->country_code;
809 $companystatic->fournisseur = 1;
810 $companystatic->code_client = $obj->code_client;
811 $companystatic->code_fournisseur = $obj->code_fournisseur;
812 $companystatic->code_compta = $obj->code_compta;
813 $companystatic->code_compta_client = $obj->code_compta;
814 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
815
816 $result .= '<tr class="oddeven">';
817 $result .= '<td class="nowrap tdoverflowmax100">';
818 $result .= $facturesupplierstatic->getNomUrl(1, '');
819 $result .= '</td>';
820 $result .= '<td class="nowrap tdoverflowmax100">';
821 $result .= $companystatic->getNomUrl(1, 'supplier');
822 $result .= '</td>';
823 $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
824 $result .= '</tr>';
825 $tot_ttc += $obj->total_ttc;
826 $i++;
827 }
828
829 if ($othernb) {
830 $result .= '<tr class="oddeven">';
831 $result .= '<td class="nowrap" colspan="3">';
832 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
833 $result .= '</td>';
834 $result .= "</tr>\n";
835 }
836
837 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
838 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
839 $result .= '</tr>';
840 } else {
841 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
842 }
843 $result .= "</table></div>";
844 $db->free($resql);
845 } else {
846 dol_print_error($db);
847 }
848 }
849
850 return $result;
851}
852
853
861function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
862{
863 global $conf, $db, $langs, $user;
864 if ($user->socid > 0) {
865 $socid = $user->socid;
866 }
867 $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,";
868 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
869 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
870 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
871 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
872 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
873 }
874 $sql .= " WHERE f.fk_soc = s.rowid";
875 $sql .= " AND f.entity IN (".getEntity('facture').")";
876 if ($socid) {
877 $sql .= " AND f.fk_soc = ".((int) $socid);
878 }
879 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
880 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
881 }
882 $sql .= " ORDER BY f.tms DESC";
883 $sql .= $db->plimit($maxCount, 0);
884
885 $resql = $db->query($sql);
886 if (!$resql) {
887 dol_print_error($db);
888 }
889
890 $num = $db->num_rows($resql);
891
892 $result = '<div class="div-table-responsive-no-min">';
893 $result .= '<table class="noborder centpercent">';
894
895 $result .= '<tr class="liste_titre">';
896 $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
897 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
898 $result .= '<th class="right"></th>';
899 $result .= '</tr>';
900
901 if ($num < 1) {
902 $result .= '</table>';
903 $result .= '</div>';
904 return $result;
905 }
906
907 $formfile = new FormFile($db);
908 $objectstatic = new Facture($db);
909 $companystatic = new Societe($db);
910 $i = 0;
911
912 while ($i < $num) {
913 $obj = $db->fetch_object($resql);
914
915 $objectstatic->id = $obj->rowid;
916 $objectstatic->ref = $obj->ref;
917 $objectstatic->paye = $obj->paye;
918 $objectstatic->statut = $obj->status;
919 $objectstatic->status = $obj->status;
920 $objectstatic->total_ht = $obj->total_ht;
921 $objectstatic->total_tva = $obj->total_tva;
922 $objectstatic->total_ttc = $obj->total_ttc;
923 $objectstatic->type = $obj->type;
924
925 $companystatic->id = $obj->socid;
926 $companystatic->name = $obj->socname;
927 $companystatic->client = $obj->client;
928 $companystatic->canvas = $obj->canvas;
929
930 $filename = dol_sanitizeFileName($obj->ref);
931 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
932
933 $result .= '<tr class="oddeven">';
934
935 $result .= '<td class="nowrap">';
936 $result .= '<table class="nobordernopadding">';
937 $result .= '<tr class="nocellnopadd">';
938
939 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
940 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
941 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
942
943 $result .= '</tr>';
944 $result .= '</table>';
945 $result .= '</td>';
946
947 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
948 $result .= '<td title="'.dol_print_date($db->jdate($obj->datec), 'day').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
949 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
950
951 // Load amount of existing payment of invoice (needed for complete status)
952 $payment = $objectstatic->getSommePaiement();
953 $result .= '<td class="right">'.$objectstatic->getLibStatut(3, $payment).'</td>';
954
955 $result .= '</tr>';
956
957 $i++;
958 }
959
960 $result .= '</table>';
961 $result .= '</div>';
962 return $result;
963}
964
972function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
973{
974 global $conf, $db, $langs, $user;
975 if ($user->socid > 0) {
976 $socid = $user->socid;
977 }
978 $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,";
979 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
980 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
981 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
982 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
983 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
984 }
985 $sql .= " WHERE f.fk_soc = s.rowid";
986 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
987 if ($socid) {
988 $sql .= " AND f.fk_soc = ".((int) $socid);
989 }
990 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
991 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
992 }
993 $sql .= " ORDER BY f.tms DESC";
994 $sql .= $db->plimit($maxCount, 0);
995
996 $resql = $db->query($sql);
997 if (!$resql) {
998 dol_print_error($db);
999 return '';
1000 }
1001
1002 $num = $db->num_rows($resql);
1003
1004 $result = '<div class="div-table-responsive-no-min">';
1005 $result .= '<table class="noborder centpercent">';
1006 $result .= '<tr class="liste_titre">';
1007 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
1008 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC">';
1009 $result .= '<span class="badge">...</span>';
1010 $result .= '</a>';
1011 $result .= '</th>';
1012 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1013 $result .= '<th class="right"></th>';
1014 $result .= '</tr>';
1015
1016 if ($num < 1) {
1017 $result .= '</table>';
1018 $result .= '</div>';
1019 return $result;
1020 }
1021
1022 $objectstatic = new FactureFournisseur($db);
1023 $companystatic = new Societe($db);
1024 $formfile = new FormFile($db);
1025 $i = 0;
1026
1027 while ($i < $num) {
1028 $obj = $db->fetch_object($resql);
1029
1030 $objectstatic->id = $obj->rowid;
1031 $objectstatic->ref = $obj->ref;
1032 $objectstatic->paye = $obj->paye;
1033 $objectstatic->paid = $obj->paye;
1034 $objectstatic->statut = $obj->status;
1035 $objectstatic->status = $obj->status;
1036 $objectstatic->total_ht = $obj->total_ht;
1037 $objectstatic->total_tva = $obj->total_tva;
1038 $objectstatic->total_ttc = $obj->total_ttc;
1039 $objectstatic->type = $obj->type;
1040
1041 $companystatic->id = $obj->socid;
1042 $companystatic->name = $obj->socname;
1043 $companystatic->client = $obj->client;
1044 $companystatic->canvas = $obj->canvas;
1045
1046 $filename = dol_sanitizeFileName($obj->ref);
1047 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
1048
1049 $result .= '<tr class="nowrap">';
1050
1051 $result .= '<td class="oddeven">';
1052 $result .= '<table class="nobordernopadding">';
1053 $result .= '<tr class="nocellnopadd">';
1054
1055 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
1056 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
1057 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
1058
1059 $result .= '</tr>';
1060 $result .= '</table>';
1061 $result .= '</td>';
1062
1063 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1064
1065 $result .= '<td title="'.$langs->trans("DateModification").': '.dol_print_date($db->jdate($obj->datec), 'dayhour').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
1066
1067 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
1068
1069 $result .= '<td class="right">'.$objectstatic->getLibStatut(3).'</td>';
1070
1071 $result .= '</tr>';
1072
1073 $i++;
1074 }
1075
1076 $result .= '</table>';
1077 $result .= '</div>';
1078 return $result;
1079}
1080
1088function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1089{
1090 global $conf, $db, $langs, $user, $hookmanager;
1091
1092 $result = '';
1093
1094 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1095 if ($user->socid > 0) {
1096 $socid = $user->socid;
1097 }
1098 $tmpinvoice = new Facture($db);
1099
1100 $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";
1101 $sql .= ", f.date_lim_reglement as datelimite";
1102 $sql .= ", s.nom as name";
1103 $sql .= ", s.rowid as socid, s.email";
1104 $sql .= ", s.code_client, s.code_compta";
1105 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1106 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1107 $sql .= ", sum(pf.amount) as am";
1108 $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";
1109 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1110 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1111 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1112 }
1113 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1114 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1115 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1116 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1117 }
1118 if ($socid) {
1119 $sql .= " AND f.fk_soc = ".((int) $socid);
1120 }
1121 // Add where from hooks
1122 $parameters = array();
1123 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1124 $sql .= $hookmanager->resPrint;
1125
1126 $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,";
1127 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1128 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1129 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1130
1131 $resql = $db->query($sql);
1132 if ($resql) {
1133 $num = $db->num_rows($resql);
1134 $i = 0;
1135 $othernb = 0;
1136
1137 $formfile = new FormFile($db);
1138
1139 print '<div class="div-table-responsive-no-min">';
1140 print '<table class="noborder centpercent">';
1141
1142 print '<tr class="liste_titre">';
1143 print '<th colspan="2">';
1144 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1145 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1146 print '<span class="badge">'.$num.'</span>';
1147 print '</a>';
1148 print '</th>';
1149
1150 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1151 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1152 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1153 }
1154 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1155 print '<th class="right">'.$langs->trans("Received").'</th>';
1156 print '<th width="16">&nbsp;</th>';
1157 print '</tr>';
1158 if ($num) {
1159 $societestatic = new Societe($db);
1160 $total_ttc = $totalam = $total = 0;
1161 while ($i < $num) {
1162 $obj = $db->fetch_object($resql);
1163
1164 if ($i >= $maxCount) {
1165 $othernb += 1;
1166 $i++;
1167 $total += $obj->total_ht;
1168 $total_ttc += $obj->total_ttc;
1169 $totalam += $obj->am;
1170 continue;
1171 }
1172
1173 $tmpinvoice->ref = $obj->ref;
1174 $tmpinvoice->id = $obj->rowid;
1175 $tmpinvoice->total_ht = $obj->total_ht;
1176 $tmpinvoice->total_tva = $obj->total_tva;
1177 $tmpinvoice->total_ttc = $obj->total_ttc;
1178 $tmpinvoice->type = $obj->type;
1179 $tmpinvoice->statut = $obj->status;
1180 $tmpinvoice->paye = $obj->paye;
1181 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1182
1183 $societestatic->id = $obj->socid;
1184 $societestatic->name = $obj->name;
1185 $societestatic->email = $obj->email;
1186 $societestatic->country_id = $obj->country_id;
1187 $societestatic->country_code = $obj->country_code;
1188 $societestatic->client = 1;
1189 $societestatic->code_client = $obj->code_client;
1190 $societestatic->code_fournisseur = $obj->code_fournisseur;
1191 $societestatic->code_compta = $obj->code_compta;
1192 $societestatic->code_compta_client = $obj->code_compta;
1193 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1194
1195 print '<tr class="oddeven">';
1196 print '<td class="nowrap">';
1197
1198 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1199 print '<td class="nobordernopadding nowrap">';
1200 print $tmpinvoice->getNomUrl(1, '');
1201 print '</td>';
1202 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1203 $filename = dol_sanitizeFileName($obj->ref);
1204 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1205 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1206 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1207 print '</td></tr></table>';
1208
1209 print '</td>';
1210 print '<td class="nowrap tdoverflowmax100">';
1211 print $societestatic->getNomUrl(1, 'customer');
1212 print '</td>';
1213 print '<td class="right" title="'.dol_print_date($db->jdate($obj->datelimite), 'day').'">';
1214 print dol_print_date($db->jdate($obj->datelimite), 'day');
1215 if ($tmpinvoice->hasDelay()) {
1216 print img_warning($langs->trans("Late"));
1217 }
1218 print '</td>';
1219 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1220 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1221 }
1222 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1223 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1224 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1225 print '</tr>';
1226
1227 $total_ttc += $obj->total_ttc;
1228 $total += $obj->total_ht;
1229 $totalam += $obj->am;
1230
1231 $i++;
1232 }
1233
1234 if ($othernb) {
1235 $colspan = 6;
1236 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1237 $colspan++;
1238 }
1239 print '<tr class="oddeven">';
1240 print '<td class="nowrap" colspan="'.$colspan.'">';
1241 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1242 print '</td>';
1243 print "</tr>\n";
1244 }
1245
1246 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>';
1247 print '<td>&nbsp;</td>';
1248 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1249 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1250 }
1251 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1252 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1253 print '<td>&nbsp;</td>';
1254 print '</tr>';
1255 } else {
1256 $colspan = 6;
1257 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1258 $colspan++;
1259 }
1260 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1261 }
1262 print '</table></div><br>';
1263 $db->free($resql);
1264 } else {
1265 dol_print_error($db);
1266 }
1267 }
1268
1269 return $result;
1270}
1271
1272
1280function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1281{
1282 global $conf, $db, $langs, $user, $hookmanager;
1283
1284 $result = '';
1285
1286 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1287 if ($user->socid > 0) {
1288 $socid = $user->socid;
1289 }
1290 $facstatic = new FactureFournisseur($db);
1291
1292 $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";
1293 $sql .= ", ff.date_lim_reglement";
1294 $sql .= ", s.nom as name";
1295 $sql .= ", s.rowid as socid, s.email";
1296 $sql .= ", s.code_client, s.code_compta";
1297 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1298 $sql .= ", sum(pf.amount) as am";
1299 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1300 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1301 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1302 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1303 }
1304 $sql .= " WHERE s.rowid = ff.fk_soc";
1305 $sql .= " AND ff.entity = ".$conf->entity;
1306 $sql .= " AND ff.paye = 0";
1307 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1308 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1309 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1310 }
1311 if ($socid) {
1312 $sql .= " AND ff.fk_soc = ".((int) $socid);
1313 }
1314 // Add where from hooks
1315 $parameters = array();
1316 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1317 $sql .= $hookmanager->resPrint;
1318
1319 $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,";
1320 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1321 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1322
1323 $resql = $db->query($sql);
1324 if ($resql) {
1325 $num = $db->num_rows($resql);
1326 $othernb = 0;
1327
1328 print '<div class="div-table-responsive-no-min">';
1329 print '<table class="noborder centpercent">';
1330
1331 print '<tr class="liste_titre">';
1332 print '<th colspan="2">';
1333 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1334 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1335 print '<span class="badge">'.$num.'</span>';
1336 print '</a>';
1337 print '</th>';
1338
1339 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1340 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1341 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1342 }
1343 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1344 print '<th class="right">'.$langs->trans("Paid").'</th>';
1345 print '<th width="16">&nbsp;</th>';
1346 print "</tr>\n";
1347
1348 $societestatic = new Societe($db);
1349
1350 if ($num) {
1351 $i = 0;
1352 $total = $total_ttc = $totalam = 0;
1353 while ($i < $num) {
1354 $obj = $db->fetch_object($resql);
1355
1356 if ($i >= $maxCount) {
1357 $othernb += 1;
1358 $i++;
1359 $total += $obj->total_ht;
1360 $total_ttc += $obj->total_ttc;
1361 continue;
1362 }
1363
1364 $facstatic->ref = $obj->ref;
1365 $facstatic->id = $obj->rowid;
1366 $facstatic->type = $obj->type;
1367 $facstatic->total_ht = $obj->total_ht;
1368 $facstatic->total_tva = $obj->total_tva;
1369 $facstatic->total_ttc = $obj->total_ttc;
1370 $facstatic->statut = $obj->status;
1371 $facstatic->status = $obj->status;
1372 $facstatic->paid = $obj->paye;
1373 $facstatic->paye = $obj->paye;
1374
1375 $societestatic->id = $obj->socid;
1376 $societestatic->name = $obj->name;
1377 $societestatic->email = $obj->email;
1378 $societestatic->client = 0;
1379 $societestatic->fournisseur = 1;
1380 $societestatic->code_client = $obj->code_client;
1381 $societestatic->code_fournisseur = $obj->code_fournisseur;
1382 $societestatic->code_compta = $obj->code_compta;
1383 $societestatic->code_compta_client = $obj->code_compta;
1384 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1385
1386 print '<tr class="oddeven">';
1387 print '<td class="nowrap tdoverflowmax100">';
1388 print $facstatic->getNomUrl(1, '');
1389 print '</td>';
1390 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1391 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1392 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1393 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1394 }
1395 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1396 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1397 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1398 print '</tr>';
1399 $total += $obj->total_ht;
1400 $total_ttc += $obj->total_ttc;
1401 $totalam += $obj->am;
1402 $i++;
1403 }
1404
1405 if ($othernb) {
1406 $colspan = 6;
1407 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1408 $colspan++;
1409 }
1410 print '<tr class="oddeven">';
1411 print '<td class="nowrap" colspan="'.$colspan.'">';
1412 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1413 print '</td>';
1414 print "</tr>\n";
1415 }
1416
1417 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>';
1418 print '<td>&nbsp;</td>';
1419 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1420 print '<td class="right">'.price($total).'</td>';
1421 }
1422 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1423 print '<td class="nowrap right">'.price($totalam).'</td>';
1424 print '<td>&nbsp;</td>';
1425 print '</tr>';
1426 } else {
1427 $colspan = 6;
1428 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1429 $colspan++;
1430 }
1431 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1432 }
1433 print '</table></div><br>';
1434 } else {
1435 dol_print_error($db);
1436 }
1437 }
1438
1439 return $result;
1440}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
Class to build graphs.
Class to manage standard extra fields.
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...)
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:63
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
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).
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.