dolibarr 21.0.0-beta
invoice.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
7 * Copyright (C) 2017 ATM-CONSULTING <contact@atm-consulting.fr>
8 * Copyright (C) 2024 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 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
573
574 $tmpinvoice = new Facture($db);
575
576 $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
577 $sql .= ", f.type, f.fk_statut as status, f.paye";
578 $sql .= ", s.nom as name";
579 $sql .= ", s.rowid as socid, s.email";
580 $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
581 $sql .= ", cc.rowid as country_id, cc.code as country_code";
582 if (!$user->hasRight('societe', 'client', 'voir')) {
583 $sql .= ", sc.fk_soc, sc.fk_user ";
584 }
585 $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";
586 if (!$user->hasRight('societe', 'client', 'voir')) {
587 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
588 }
589 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
590 $sql .= " AND f.entity IN (".getEntity('invoice').")";
591 if (!$user->hasRight('societe', 'client', 'voir')) {
592 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
593 }
594
595 if ($socid) {
596 $sql .= " AND f.fk_soc = ".((int) $socid);
597 }
598 // Add where from hooks
599 $parameters = array();
600 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
601 $sql .= $hookmanager->resPrint;
602
603 $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,";
604 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
605 $sql .= " cc.rowid, cc.code";
606 if (!$user->hasRight('societe', 'client', 'voir')) {
607 $sql .= ", sc.fk_soc, sc.fk_user";
608 }
609
610 // Add Group from hooks
611 $parameters = array();
612 $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
613 $sql .= $hookmanager->resPrint;
614
615 $resql = $db->query($sql);
616
617 if ($resql) {
618 $num = $db->num_rows($resql);
619 $nbofloop = min($num, $maxofloop);
620
621 $result .= '<div class="div-table-responsive-no-min">';
622 $result .= '<table class="noborder centpercent">';
623
624 $result .= '<tr class="liste_titre">';
625 $result .= '<th colspan="3">';
626 $result .= $langs->trans("CustomersDraftInvoices");
627 $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
628 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
629 $result .= '</a>';
630 $result .= '</th>';
631 $result .= '</tr>';
632
633 if ($num) {
634 $companystatic = new Societe($db);
635
636 $i = 0;
637 $othernb = 0;
638 $tot_ttc = 0;
639 while ($i < $nbofloop) {
640 $obj = $db->fetch_object($resql);
641
642 if ($i >= $maxCount) {
643 $othernb += 1;
644 $i++;
645 $tot_ttc += $obj->total_ttc;
646 continue;
647 }
648
649 $tmpinvoice->id = $obj->rowid;
650 $tmpinvoice->ref = $obj->ref;
651 $tmpinvoice->date = $db->jdate($obj->date);
652 $tmpinvoice->type = $obj->type;
653 $tmpinvoice->total_ht = $obj->total_ht;
654 $tmpinvoice->total_tva = $obj->total_tva;
655 $tmpinvoice->total_ttc = $obj->total_ttc;
656 $tmpinvoice->ref_client = $obj->ref_client;
657 $tmpinvoice->statut = $obj->status;
658 $tmpinvoice->paye = $obj->paye;
659
660 $companystatic->id = $obj->socid;
661 $companystatic->name = $obj->name;
662 $companystatic->email = $obj->email;
663 $companystatic->country_id = $obj->country_id;
664 $companystatic->country_code = $obj->country_code;
665 $companystatic->client = 1;
666 $companystatic->code_client = $obj->code_client;
667 $companystatic->code_fournisseur = $obj->code_fournisseur;
668 $companystatic->code_compta = $obj->code_compta;
669 $companystatic->code_compta_client = $obj->code_compta;
670 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
671
672 $result .= '<tr class="oddeven">';
673 $result .= '<td class="nowrap tdoverflowmax100">';
674 $result .= $tmpinvoice->getNomUrl(1, '');
675 $result .= '</td>';
676 $result .= '<td class="nowrap tdoverflowmax100">';
677 $result .= $companystatic->getNomUrl(1, 'customer');
678 $result .= '</td>';
679 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
680 $result .= '</tr>';
681 $tot_ttc += $obj->total_ttc;
682 $i++;
683 }
684
685 if ($othernb) {
686 $result .= '<tr class="oddeven">';
687 $result .= '<td class="nowrap" colspan="3">';
688 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
689 $result .= '</td>';
690 $result .= "</tr>\n";
691 }
692
693 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
694 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
695 $result .= '</tr>';
696 } else {
697 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
698 }
699 $result .= "</table></div>";
700 $db->free($resql);
701 } else {
702 dol_print_error($db);
703 }
704 }
705
706 return $result;
707}
708
716function getDraftSupplierTable($maxCount = 500, $socid = 0)
717{
718 global $conf, $db, $langs, $user, $hookmanager;
719
720 $result = '';
721
722 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
723 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
724
725 $facturesupplierstatic = new FactureFournisseur($db);
726
727 $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";
728 $sql .= ", s.nom as name";
729 $sql .= ", s.rowid as socid, s.email";
730 $sql .= ", s.code_client, s.code_compta";
731 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
732 $sql .= ", cc.rowid as country_id, cc.code as country_code";
733 $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";
734 if (!$user->hasRight('societe', 'client', 'voir')) {
735 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
736 }
737 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
738 $sql .= " AND f.entity IN (".getEntity('invoice').')';
739 if (!$user->hasRight('societe', 'client', 'voir')) {
740 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
741 }
742 if ($socid) {
743 $sql .= " AND f.fk_soc = ".((int) $socid);
744 }
745 // Add where from hooks
746 $parameters = array();
747 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
748 $sql .= $hookmanager->resPrint;
749 $resql = $db->query($sql);
750
751 if ($resql) {
752 $num = $db->num_rows($resql);
753 $nbofloop = min($num, $maxofloop);
754
755 $result .= '<div class="div-table-responsive-no-min">';
756 $result .= '<table class="noborder centpercent">';
757
758 $result .= '<tr class="liste_titre">';
759 $result .= '<th colspan="3">';
760 $result .= $langs->trans("SuppliersDraftInvoices");
761 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
762 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
763 $result .= '</a>';
764 $result .= '</th>';
765 $result .= '</tr>';
766
767 if ($num) {
768 $companystatic = new Societe($db);
769
770 $i = 0;
771 $othernb = 0;
772 $tot_ttc = 0;
773 while ($i < $nbofloop) {
774 $obj = $db->fetch_object($resql);
775
776 if ($i >= $maxCount) {
777 $othernb += 1;
778 $i++;
779 $tot_ttc += $obj->total_ttc;
780 continue;
781 }
782
783 $facturesupplierstatic->ref = $obj->ref;
784 $facturesupplierstatic->id = $obj->rowid;
785 $facturesupplierstatic->total_ht = $obj->total_ht;
786 $facturesupplierstatic->total_tva = $obj->total_tva;
787 $facturesupplierstatic->total_ttc = $obj->total_ttc;
788 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
789 $facturesupplierstatic->type = $obj->type;
790 $facturesupplierstatic->statut = $obj->status;
791 $facturesupplierstatic->status = $obj->status;
792 $facturesupplierstatic->paye = $obj->paye;
793 $facturesupplierstatic->paid = $obj->paye;
794
795 $companystatic->id = $obj->socid;
796 $companystatic->name = $obj->name;
797 $companystatic->email = $obj->email;
798 $companystatic->country_id = $obj->country_id;
799 $companystatic->country_code = $obj->country_code;
800 $companystatic->fournisseur = 1;
801 $companystatic->code_client = $obj->code_client;
802 $companystatic->code_fournisseur = $obj->code_fournisseur;
803 $companystatic->code_compta = $obj->code_compta;
804 $companystatic->code_compta_client = $obj->code_compta;
805 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
806
807 $result .= '<tr class="oddeven">';
808 $result .= '<td class="nowrap tdoverflowmax100">';
809 $result .= $facturesupplierstatic->getNomUrl(1, '');
810 $result .= '</td>';
811 $result .= '<td class="nowrap tdoverflowmax100">';
812 $result .= $companystatic->getNomUrl(1, 'supplier');
813 $result .= '</td>';
814 $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
815 $result .= '</tr>';
816 $tot_ttc += $obj->total_ttc;
817 $i++;
818 }
819
820 if ($othernb) {
821 $result .= '<tr class="oddeven">';
822 $result .= '<td class="nowrap" colspan="3">';
823 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
824 $result .= '</td>';
825 $result .= "</tr>\n";
826 }
827
828 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
829 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
830 $result .= '</tr>';
831 } else {
832 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
833 }
834 $result .= "</table></div>";
835 $db->free($resql);
836 } else {
837 dol_print_error($db);
838 }
839 }
840
841 return $result;
842}
843
844
852function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
853{
854 global $conf, $db, $langs, $user;
855
856 $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,";
857 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
858 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
859 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
860 if (!$user->hasRight('societe', 'client', 'voir')) {
861 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
862 }
863 $sql .= " WHERE f.fk_soc = s.rowid";
864 $sql .= " AND f.entity IN (".getEntity('facture').")";
865 if ($socid) {
866 $sql .= " AND f.fk_soc = ".((int) $socid);
867 }
868 if (!$user->hasRight('societe', 'client', 'voir')) {
869 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
870 }
871 $sql .= " ORDER BY f.tms DESC";
872 $sql .= $db->plimit($maxCount, 0);
873
874 $resql = $db->query($sql);
875 if (!$resql) {
876 dol_print_error($db);
877 }
878
879 $num = $db->num_rows($resql);
880
881 $result = '<div class="div-table-responsive-no-min">';
882 $result .= '<table class="noborder centpercent">';
883
884 $result .= '<tr class="liste_titre">';
885 $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
886 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
887 $result .= '<th class="right"></th>';
888 $result .= '</tr>';
889
890 if ($num < 1) {
891 $result .= '</table>';
892 $result .= '</div>';
893 return $result;
894 }
895
896 $formfile = new FormFile($db);
897 $objectstatic = new Facture($db);
898 $companystatic = new Societe($db);
899 $i = 0;
900
901 while ($i < $num) {
902 $obj = $db->fetch_object($resql);
903
904 $objectstatic->id = $obj->rowid;
905 $objectstatic->ref = $obj->ref;
906 $objectstatic->paye = $obj->paye;
907 $objectstatic->statut = $obj->status;
908 $objectstatic->status = $obj->status;
909 $objectstatic->total_ht = $obj->total_ht;
910 $objectstatic->total_tva = $obj->total_tva;
911 $objectstatic->total_ttc = $obj->total_ttc;
912 $objectstatic->type = $obj->type;
913
914 $companystatic->id = $obj->socid;
915 $companystatic->name = $obj->socname;
916 $companystatic->client = $obj->client;
917 $companystatic->canvas = $obj->canvas;
918
919 $filename = dol_sanitizeFileName($obj->ref);
920 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
921
922 $result .= '<tr class="nowrap">';
923
924 $result .= '<td class="oddeven">';
925 $result .= '<table class="nobordernopadding">';
926 $result .= '<tr class="nocellnopadd">';
927
928 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
929 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
930 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
931
932 $result .= '</tr>';
933 $result .= '</table>';
934 $result .= '</td>';
935
936 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
937 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
938 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
939
940 // Load amount of existing payment of invoice (needed for complete status)
941 $payment = $objectstatic->getSommePaiement();
942 $result .= '<td class="right">'.$objectstatic->getLibStatut(3, $payment).'</td>';
943
944 $result .= '</tr>';
945
946 $i++;
947 }
948
949 $result .= '</table>';
950 $result .= '</div>';
951 return $result;
952}
953
961function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
962{
963 global $conf, $db, $langs, $user;
964
965 $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,";
966 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
967 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
968 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
969 if (!$user->hasRight('societe', 'client', 'voir')) {
970 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
971 }
972 $sql .= " WHERE f.fk_soc = s.rowid";
973 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
974 if ($socid) {
975 $sql .= " AND f.fk_soc = ".((int) $socid);
976 }
977 if (!$user->hasRight('societe', 'client', 'voir')) {
978 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
979 }
980 $sql .= " ORDER BY f.tms DESC";
981 $sql .= $db->plimit($maxCount, 0);
982
983 $resql = $db->query($sql);
984 if (!$resql) {
985 dol_print_error($db);
986 return '';
987 }
988
989 $num = $db->num_rows($resql);
990
991 $result = '<div class="div-table-responsive-no-min">';
992 $result .= '<table class="noborder centpercent">';
993 $result .= '<tr class="liste_titre">';
994 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
995 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC">';
996 $result .= '<span class="badge">...</span>';
997 $result .= '</a>';
998 $result .= '</th>';
999 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1000 $result .= '<th class="right"></th>';
1001 $result .= '</tr>';
1002
1003 if ($num < 1) {
1004 $result .= '</table>';
1005 $result .= '</div>';
1006 return $result;
1007 }
1008
1009 $objectstatic = new FactureFournisseur($db);
1010 $companystatic = new Societe($db);
1011 $formfile = new FormFile($db);
1012 $i = 0;
1013
1014 while ($i < $num) {
1015 $obj = $db->fetch_object($resql);
1016
1017 $objectstatic->id = $obj->rowid;
1018 $objectstatic->ref = $obj->ref;
1019 $objectstatic->paye = $obj->paye;
1020 $objectstatic->paid = $obj->paye;
1021 $objectstatic->statut = $obj->status;
1022 $objectstatic->status = $obj->status;
1023 $objectstatic->total_ht = $obj->total_ht;
1024 $objectstatic->total_tva = $obj->total_tva;
1025 $objectstatic->total_ttc = $obj->total_ttc;
1026 $objectstatic->type = $obj->type;
1027
1028 $companystatic->id = $obj->socid;
1029 $companystatic->name = $obj->socname;
1030 $companystatic->client = $obj->client;
1031 $companystatic->canvas = $obj->canvas;
1032
1033 $filename = dol_sanitizeFileName($obj->ref);
1034 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
1035
1036 $result .= '<tr class="nowrap">';
1037
1038 $result .= '<td class="oddeven">';
1039 $result .= '<table class="nobordernopadding">';
1040 $result .= '<tr class="nocellnopadd">';
1041
1042 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
1043 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
1044 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
1045
1046 $result .= '</tr>';
1047 $result .= '</table>';
1048 $result .= '</td>';
1049
1050 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1051
1052 $result .= '<td title="'.$langs->trans("DateModification").': '.dol_print_date($db->jdate($obj->datec), 'dayhour').'">'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
1053
1054 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
1055
1056 $result .= '<td class="right">'.$objectstatic->getLibStatut(3).'</td>';
1057
1058 $result .= '</tr>';
1059
1060 $i++;
1061 }
1062
1063 $result .= '</table>';
1064 $result .= '</div>';
1065 return $result;
1066}
1067
1075function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1076{
1077 global $conf, $db, $langs, $user, $hookmanager;
1078
1079 $result = '';
1080
1081 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1082 $tmpinvoice = new Facture($db);
1083
1084 $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";
1085 $sql .= ", f.date_lim_reglement as datelimite";
1086 $sql .= ", s.nom as name";
1087 $sql .= ", s.rowid as socid, s.email";
1088 $sql .= ", s.code_client, s.code_compta";
1089 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1090 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1091 $sql .= ", sum(pf.amount) as am";
1092 $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";
1093 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1094 if (!$user->hasRight('societe', 'client', 'voir')) {
1095 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1096 }
1097 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1098 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1099 if (!$user->hasRight('societe', 'client', 'voir')) {
1100 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1101 }
1102 if ($socid) {
1103 $sql .= " AND f.fk_soc = ".((int) $socid);
1104 }
1105 // Add where from hooks
1106 $parameters = array();
1107 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1108 $sql .= $hookmanager->resPrint;
1109
1110 $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,";
1111 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1112 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1113 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1114
1115 $resql = $db->query($sql);
1116 if ($resql) {
1117 $num = $db->num_rows($resql);
1118 $i = 0;
1119 $othernb = 0;
1120
1121 $formfile = new FormFile($db);
1122
1123 print '<div class="div-table-responsive-no-min">';
1124 print '<table class="noborder centpercent">';
1125
1126 print '<tr class="liste_titre">';
1127 print '<th colspan="2">';
1128 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1129 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1130 print '<span class="badge">'.$num.'</span>';
1131 print '</a>';
1132 print '</th>';
1133
1134 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1135 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1136 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1137 }
1138 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1139 print '<th class="right">'.$langs->trans("Received").'</th>';
1140 print '<th width="16">&nbsp;</th>';
1141 print '</tr>';
1142 if ($num) {
1143 $societestatic = new Societe($db);
1144 $total_ttc = $totalam = $total = 0;
1145 while ($i < $num) {
1146 $obj = $db->fetch_object($resql);
1147
1148 if ($i >= $maxCount) {
1149 $othernb += 1;
1150 $i++;
1151 $total += $obj->total_ht;
1152 $total_ttc += $obj->total_ttc;
1153 $totalam += $obj->am;
1154 continue;
1155 }
1156
1157 $tmpinvoice->ref = $obj->ref;
1158 $tmpinvoice->id = $obj->rowid;
1159 $tmpinvoice->total_ht = $obj->total_ht;
1160 $tmpinvoice->total_tva = $obj->total_tva;
1161 $tmpinvoice->total_ttc = $obj->total_ttc;
1162 $tmpinvoice->type = $obj->type;
1163 $tmpinvoice->statut = $obj->status;
1164 $tmpinvoice->paye = $obj->paye;
1165 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1166
1167 $societestatic->id = $obj->socid;
1168 $societestatic->name = $obj->name;
1169 $societestatic->email = $obj->email;
1170 $societestatic->country_id = $obj->country_id;
1171 $societestatic->country_code = $obj->country_code;
1172 $societestatic->client = 1;
1173 $societestatic->code_client = $obj->code_client;
1174 $societestatic->code_fournisseur = $obj->code_fournisseur;
1175 $societestatic->code_compta = $obj->code_compta;
1176 $societestatic->code_compta_client = $obj->code_compta;
1177 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1178
1179 print '<tr class="oddeven">';
1180 print '<td class="nowrap">';
1181
1182 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1183 print '<td class="nobordernopadding nowrap">';
1184 print $tmpinvoice->getNomUrl(1, '');
1185 print '</td>';
1186 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1187 $filename = dol_sanitizeFileName($obj->ref);
1188 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1189 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1190 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1191 print '</td></tr></table>';
1192
1193 print '</td>';
1194 print '<td class="nowrap tdoverflowmax100">';
1195 print $societestatic->getNomUrl(1, 'customer');
1196 print '</td>';
1197 print '<td class="right">';
1198 print dol_print_date($db->jdate($obj->datelimite), 'day');
1199 if ($tmpinvoice->hasDelay()) {
1200 print img_warning($langs->trans("Late"));
1201 }
1202 print '</td>';
1203 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1204 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1205 }
1206 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1207 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1208 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1209 print '</tr>';
1210
1211 $total_ttc += $obj->total_ttc;
1212 $total += $obj->total_ht;
1213 $totalam += $obj->am;
1214
1215 $i++;
1216 }
1217
1218 if ($othernb) {
1219 $colspan = 6;
1220 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1221 $colspan++;
1222 }
1223 print '<tr class="oddeven">';
1224 print '<td class="nowrap" colspan="'.$colspan.'">';
1225 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1226 print '</td>';
1227 print "</tr>\n";
1228 }
1229
1230 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>';
1231 print '<td>&nbsp;</td>';
1232 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1233 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1234 }
1235 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1236 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1237 print '<td>&nbsp;</td>';
1238 print '</tr>';
1239 } else {
1240 $colspan = 6;
1241 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1242 $colspan++;
1243 }
1244 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1245 }
1246 print '</table></div><br>';
1247 $db->free($resql);
1248 } else {
1249 dol_print_error($db);
1250 }
1251 }
1252
1253 return $result;
1254}
1255
1256
1264function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1265{
1266 global $conf, $db, $langs, $user, $hookmanager;
1267
1268 $result = '';
1269
1270 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1271 $facstatic = new FactureFournisseur($db);
1272
1273 $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";
1274 $sql .= ", ff.date_lim_reglement";
1275 $sql .= ", s.nom as name";
1276 $sql .= ", s.rowid as socid, s.email";
1277 $sql .= ", s.code_client, s.code_compta";
1278 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1279 $sql .= ", sum(pf.amount) as am";
1280 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1281 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1282 if (!$user->hasRight('societe', 'client', 'voir')) {
1283 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1284 }
1285 $sql .= " WHERE s.rowid = ff.fk_soc";
1286 $sql .= " AND ff.entity = ".$conf->entity;
1287 $sql .= " AND ff.paye = 0";
1288 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1289 if (!$user->hasRight('societe', 'client', 'voir')) {
1290 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1291 }
1292 if ($socid) {
1293 $sql .= " AND ff.fk_soc = ".((int) $socid);
1294 }
1295 // Add where from hooks
1296 $parameters = array();
1297 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1298 $sql .= $hookmanager->resPrint;
1299
1300 $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,";
1301 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1302 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1303
1304 $resql = $db->query($sql);
1305 if ($resql) {
1306 $num = $db->num_rows($resql);
1307 $othernb = 0;
1308
1309 print '<div class="div-table-responsive-no-min">';
1310 print '<table class="noborder centpercent">';
1311
1312 print '<tr class="liste_titre">';
1313 print '<th colspan="2">';
1314 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1315 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1316 print '<span class="badge">'.$num.'</span>';
1317 print '</a>';
1318 print '</th>';
1319
1320 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1321 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1322 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1323 }
1324 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1325 print '<th class="right">'.$langs->trans("Paid").'</th>';
1326 print '<th width="16">&nbsp;</th>';
1327 print "</tr>\n";
1328
1329 $societestatic = new Societe($db);
1330
1331 if ($num) {
1332 $i = 0;
1333 $total = $total_ttc = $totalam = 0;
1334 while ($i < $num) {
1335 $obj = $db->fetch_object($resql);
1336
1337 if ($i >= $maxCount) {
1338 $othernb += 1;
1339 $i++;
1340 $total += $obj->total_ht;
1341 $total_ttc += $obj->total_ttc;
1342 continue;
1343 }
1344
1345 $facstatic->ref = $obj->ref;
1346 $facstatic->id = $obj->rowid;
1347 $facstatic->type = $obj->type;
1348 $facstatic->total_ht = $obj->total_ht;
1349 $facstatic->total_tva = $obj->total_tva;
1350 $facstatic->total_ttc = $obj->total_ttc;
1351 $facstatic->statut = $obj->status;
1352 $facstatic->status = $obj->status;
1353 $facstatic->paid = $obj->paye;
1354 $facstatic->paye = $obj->paye;
1355
1356 $societestatic->id = $obj->socid;
1357 $societestatic->name = $obj->name;
1358 $societestatic->email = $obj->email;
1359 $societestatic->client = 0;
1360 $societestatic->fournisseur = 1;
1361 $societestatic->code_client = $obj->code_client;
1362 $societestatic->code_fournisseur = $obj->code_fournisseur;
1363 $societestatic->code_compta = $obj->code_compta;
1364 $societestatic->code_compta_client = $obj->code_compta;
1365 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1366
1367 print '<tr class="oddeven">';
1368 print '<td class="nowrap tdoverflowmax100">';
1369 print $facstatic->getNomUrl(1, '');
1370 print '</td>';
1371 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1372 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1373 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1374 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1375 }
1376 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1377 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1378 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1379 print '</tr>';
1380 $total += $obj->total_ht;
1381 $total_ttc += $obj->total_ttc;
1382 $totalam += $obj->am;
1383 $i++;
1384 }
1385
1386 if ($othernb) {
1387 $colspan = 6;
1388 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1389 $colspan++;
1390 }
1391 print '<tr class="oddeven">';
1392 print '<td class="nowrap" colspan="'.$colspan.'">';
1393 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1394 print '</td>';
1395 print "</tr>\n";
1396 }
1397
1398 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>';
1399 print '<td>&nbsp;</td>';
1400 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1401 print '<td class="right">'.price($total).'</td>';
1402 }
1403 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1404 print '<td class="nowrap right">'.price($totalam).'</td>';
1405 print '<td>&nbsp;</td>';
1406 print '</tr>';
1407 } else {
1408 $colspan = 6;
1409 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1410 $colspan++;
1411 }
1412 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1413 }
1414 print '</table></div><br>';
1415 } else {
1416 dol_print_error($db);
1417 }
1418 }
1419
1420 return $result;
1421}
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.