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