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->total_ht = $obj->total_ht;
909 $objectstatic->total_tva = $obj->total_tva;
910 $objectstatic->total_ttc = $obj->total_ttc;
911 $objectstatic->type = $obj->type;
912
913 $companystatic->id = $obj->socid;
914 $companystatic->name = $obj->socname;
915 $companystatic->client = $obj->client;
916 $companystatic->canvas = $obj->canvas;
917
918 $filename = dol_sanitizeFileName($obj->ref);
919 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
920
921 $result .= '<tr class="nowrap">';
922
923 $result .= '<td class="oddeven">';
924 $result .= '<table class="nobordernopadding">';
925 $result .= '<tr class="nocellnopadd">';
926
927 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
928 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
929 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
930
931 $result .= '</tr>';
932 $result .= '</table>';
933 $result .= '</td>';
934
935 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
936 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
937 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
938
939 // Load amount of existing payment of invoice (needed for complete status)
940 $payment = $objectstatic->getSommePaiement();
941 $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
942
943 $result .= '</tr>';
944
945 $i++;
946 }
947
948 $result .= '</table>';
949 $result .= '</div>';
950 return $result;
951}
952
960function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
961{
962 global $conf, $db, $langs, $user;
963
964 $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,";
965 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
966 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
967 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
968 if (!$user->hasRight('societe', 'client', 'voir')) {
969 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
970 }
971 $sql .= " WHERE f.fk_soc = s.rowid";
972 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
973 if ($socid) {
974 $sql .= " AND f.fk_soc = ".((int) $socid);
975 }
976 if (!$user->hasRight('societe', 'client', 'voir')) {
977 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
978 }
979 $sql .= " ORDER BY f.tms DESC";
980 $sql .= $db->plimit($maxCount, 0);
981
982 $resql = $db->query($sql);
983 if (!$resql) {
984 dol_print_error($db);
985 return '';
986 }
987
988 $num = $db->num_rows($resql);
989
990 $result = '<div class="div-table-responsive-no-min">';
991 $result .= '<table class="noborder centpercent">';
992 $result .= '<tr class="liste_titre">';
993 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
994 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC">';
995 $result .= '<span class="badge">...</span>';
996 $result .= '</a>';
997 $result .= '</th>';
998 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
999 $result .= '<th class="right"></th>';
1000 $result .= '</tr>';
1001
1002 if ($num < 1) {
1003 $result .= '</table>';
1004 $result .= '</div>';
1005 return $result;
1006 }
1007
1008 $objectstatic = new FactureFournisseur($db);
1009 $companystatic = new Societe($db);
1010 $formfile = new FormFile($db);
1011 $i = 0;
1012
1013 while ($i < $num) {
1014 $obj = $db->fetch_object($resql);
1015
1016 $objectstatic->id = $obj->rowid;
1017 $objectstatic->ref = $obj->ref;
1018 $objectstatic->paye = $obj->paye;
1019 $objectstatic->paid = $obj->paye;
1020 $objectstatic->statut = $obj->status;
1021 $objectstatic->status = $obj->status;
1022 $objectstatic->total_ht = $obj->total_ht;
1023 $objectstatic->total_tva = $obj->total_tva;
1024 $objectstatic->total_ttc = $obj->total_ttc;
1025 $objectstatic->type = $obj->type;
1026
1027 $companystatic->id = $obj->socid;
1028 $companystatic->name = $obj->socname;
1029 $companystatic->client = $obj->client;
1030 $companystatic->canvas = $obj->canvas;
1031
1032 $filename = dol_sanitizeFileName($obj->ref);
1033 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
1034
1035 $result .= '<tr class="nowrap">';
1036
1037 $result .= '<td class="oddeven">';
1038 $result .= '<table class="nobordernopadding">';
1039 $result .= '<tr class="nocellnopadd">';
1040
1041 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
1042 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
1043 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
1044
1045 $result .= '</tr>';
1046 $result .= '</table>';
1047 $result .= '</td>';
1048
1049 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1050
1051 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
1052
1053 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
1054
1055 $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
1056
1057 $result .= '</tr>';
1058
1059 $i++;
1060 }
1061
1062 $result .= '</table>';
1063 $result .= '</div>';
1064 return $result;
1065}
1066
1074function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1075{
1076 global $conf, $db, $langs, $user, $hookmanager;
1077
1078 $result = '';
1079
1080 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1081 $tmpinvoice = new Facture($db);
1082
1083 $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";
1084 $sql .= ", f.date_lim_reglement as datelimite";
1085 $sql .= ", s.nom as name";
1086 $sql .= ", s.rowid as socid, s.email";
1087 $sql .= ", s.code_client, s.code_compta";
1088 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1089 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1090 $sql .= ", sum(pf.amount) as am";
1091 $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";
1092 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1093 if (!$user->hasRight('societe', 'client', 'voir')) {
1094 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1095 }
1096 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1097 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1098 if (!$user->hasRight('societe', 'client', 'voir')) {
1099 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1100 }
1101 if ($socid) {
1102 $sql .= " AND f.fk_soc = ".((int) $socid);
1103 }
1104 // Add where from hooks
1105 $parameters = array();
1106 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1107 $sql .= $hookmanager->resPrint;
1108
1109 $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,";
1110 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1111 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1112 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1113
1114 $resql = $db->query($sql);
1115 if ($resql) {
1116 $num = $db->num_rows($resql);
1117 $i = 0;
1118 $othernb = 0;
1119
1120 $formfile = new FormFile($db);
1121
1122 print '<div class="div-table-responsive-no-min">';
1123 print '<table class="noborder centpercent">';
1124
1125 print '<tr class="liste_titre">';
1126 print '<th colspan="2">';
1127 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1128 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1129 print '<span class="badge">'.$num.'</span>';
1130 print '</a>';
1131 print '</th>';
1132
1133 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1134 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1135 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1136 }
1137 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1138 print '<th class="right">'.$langs->trans("Received").'</th>';
1139 print '<th width="16">&nbsp;</th>';
1140 print '</tr>';
1141 if ($num) {
1142 $societestatic = new Societe($db);
1143 $total_ttc = $totalam = $total = 0;
1144 while ($i < $num) {
1145 $obj = $db->fetch_object($resql);
1146
1147 if ($i >= $maxCount) {
1148 $othernb += 1;
1149 $i++;
1150 $total += $obj->total_ht;
1151 $total_ttc += $obj->total_ttc;
1152 $totalam += $obj->am;
1153 continue;
1154 }
1155
1156 $tmpinvoice->ref = $obj->ref;
1157 $tmpinvoice->id = $obj->rowid;
1158 $tmpinvoice->total_ht = $obj->total_ht;
1159 $tmpinvoice->total_tva = $obj->total_tva;
1160 $tmpinvoice->total_ttc = $obj->total_ttc;
1161 $tmpinvoice->type = $obj->type;
1162 $tmpinvoice->statut = $obj->status;
1163 $tmpinvoice->paye = $obj->paye;
1164 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1165
1166 $societestatic->id = $obj->socid;
1167 $societestatic->name = $obj->name;
1168 $societestatic->email = $obj->email;
1169 $societestatic->country_id = $obj->country_id;
1170 $societestatic->country_code = $obj->country_code;
1171 $societestatic->client = 1;
1172 $societestatic->code_client = $obj->code_client;
1173 $societestatic->code_fournisseur = $obj->code_fournisseur;
1174 $societestatic->code_compta = $obj->code_compta;
1175 $societestatic->code_compta_client = $obj->code_compta;
1176 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1177
1178 print '<tr class="oddeven">';
1179 print '<td class="nowrap">';
1180
1181 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1182 print '<td class="nobordernopadding nowrap">';
1183 print $tmpinvoice->getNomUrl(1, '');
1184 print '</td>';
1185 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1186 $filename = dol_sanitizeFileName($obj->ref);
1187 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1188 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1189 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1190 print '</td></tr></table>';
1191
1192 print '</td>';
1193 print '<td class="nowrap tdoverflowmax100">';
1194 print $societestatic->getNomUrl(1, 'customer');
1195 print '</td>';
1196 print '<td class="right">';
1197 print dol_print_date($db->jdate($obj->datelimite), 'day');
1198 if ($tmpinvoice->hasDelay()) {
1199 print img_warning($langs->trans("Late"));
1200 }
1201 print '</td>';
1202 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1203 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1204 }
1205 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1206 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1207 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1208 print '</tr>';
1209
1210 $total_ttc += $obj->total_ttc;
1211 $total += $obj->total_ht;
1212 $totalam += $obj->am;
1213
1214 $i++;
1215 }
1216
1217 if ($othernb) {
1218 $colspan = 6;
1219 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1220 $colspan++;
1221 }
1222 print '<tr class="oddeven">';
1223 print '<td class="nowrap" colspan="'.$colspan.'">';
1224 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1225 print '</td>';
1226 print "</tr>\n";
1227 }
1228
1229 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>';
1230 print '<td>&nbsp;</td>';
1231 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1232 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1233 }
1234 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1235 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1236 print '<td>&nbsp;</td>';
1237 print '</tr>';
1238 } else {
1239 $colspan = 6;
1240 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1241 $colspan++;
1242 }
1243 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1244 }
1245 print '</table></div><br>';
1246 $db->free($resql);
1247 } else {
1248 dol_print_error($db);
1249 }
1250 }
1251
1252 return $result;
1253}
1254
1255
1263function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1264{
1265 global $conf, $db, $langs, $user, $hookmanager;
1266
1267 $result = '';
1268
1269 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1270 $facstatic = new FactureFournisseur($db);
1271
1272 $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";
1273 $sql .= ", ff.date_lim_reglement";
1274 $sql .= ", s.nom as name";
1275 $sql .= ", s.rowid as socid, s.email";
1276 $sql .= ", s.code_client, s.code_compta";
1277 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1278 $sql .= ", sum(pf.amount) as am";
1279 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1280 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1281 if (!$user->hasRight('societe', 'client', 'voir')) {
1282 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1283 }
1284 $sql .= " WHERE s.rowid = ff.fk_soc";
1285 $sql .= " AND ff.entity = ".$conf->entity;
1286 $sql .= " AND ff.paye = 0";
1287 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1288 if (!$user->hasRight('societe', 'client', 'voir')) {
1289 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1290 }
1291 if ($socid) {
1292 $sql .= " AND ff.fk_soc = ".((int) $socid);
1293 }
1294 // Add where from hooks
1295 $parameters = array();
1296 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1297 $sql .= $hookmanager->resPrint;
1298
1299 $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,";
1300 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1301 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1302
1303 $resql = $db->query($sql);
1304 if ($resql) {
1305 $num = $db->num_rows($resql);
1306 $othernb = 0;
1307
1308 $formfile = new FormFile($db);
1309
1310 print '<div class="div-table-responsive-no-min">';
1311 print '<table class="noborder centpercent">';
1312
1313 print '<tr class="liste_titre">';
1314 print '<th colspan="2">';
1315 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1316 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1317 print '<span class="badge">'.$num.'</span>';
1318 print '</a>';
1319 print '</th>';
1320
1321 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1322 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1323 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1324 }
1325 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1326 print '<th class="right">'.$langs->trans("Paid").'</th>';
1327 print '<th width="16">&nbsp;</th>';
1328 print "</tr>\n";
1329 $societestatic = new Societe($db);
1330 if ($num) {
1331 $i = 0;
1332 $total = $total_ttc = $totalam = 0;
1333 while ($i < $num) {
1334 $obj = $db->fetch_object($resql);
1335
1336 if ($i >= $maxCount) {
1337 $othernb += 1;
1338 $i++;
1339 $total += $obj->total_ht;
1340 $total_ttc += $obj->total_ttc;
1341 continue;
1342 }
1343
1344 $facstatic->ref = $obj->ref;
1345 $facstatic->id = $obj->rowid;
1346 $facstatic->type = $obj->type;
1347 $facstatic->total_ht = $obj->total_ht;
1348 $facstatic->total_tva = $obj->total_tva;
1349 $facstatic->total_ttc = $obj->total_ttc;
1350 $facstatic->statut = $obj->status;
1351 $facstatic->status = $obj->status;
1352 $facstatic->paid = $obj->paye;
1353 $facstatic->paye = $obj->paye;
1354
1355 $societestatic->id = $obj->socid;
1356 $societestatic->name = $obj->name;
1357 $societestatic->email = $obj->email;
1358 $societestatic->client = 0;
1359 $societestatic->fournisseur = 1;
1360 $societestatic->code_client = $obj->code_client;
1361 $societestatic->code_fournisseur = $obj->code_fournisseur;
1362 $societestatic->code_compta = $obj->code_compta;
1363 $societestatic->code_compta_client = $obj->code_compta;
1364 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1365
1366 print '<tr class="oddeven">';
1367 print '<td class="nowrap tdoverflowmax100">';
1368 print $facstatic->getNomUrl(1, '');
1369 print '</td>';
1370 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1371 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1372 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1373 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1374 }
1375 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1376 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1377 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1378 print '</tr>';
1379 $total += $obj->total_ht;
1380 $total_ttc += $obj->total_ttc;
1381 $totalam += $obj->am;
1382 $i++;
1383 }
1384
1385 if ($othernb) {
1386 $colspan = 6;
1387 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1388 $colspan++;
1389 }
1390 print '<tr class="oddeven">';
1391 print '<td class="nowrap" colspan="'.$colspan.'">';
1392 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1393 print '</td>';
1394 print "</tr>\n";
1395 }
1396
1397 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>';
1398 print '<td>&nbsp;</td>';
1399 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1400 print '<td class="right">'.price($total).'</td>';
1401 }
1402 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1403 print '<td class="nowrap right">'.price($totalam).'</td>';
1404 print '<td>&nbsp;</td>';
1405 print '</tr>';
1406 } else {
1407 $colspan = 6;
1408 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1409 $colspan++;
1410 }
1411 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1412 }
1413 print '</table></div><br>';
1414 } else {
1415 dol_print_error($db);
1416 }
1417 }
1418
1419 return $result;
1420}
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)
Save data into a memory area shared by all users, all sessions on server.
dol_getcache($memoryid)
Read a memory area shared by all users, all sessions on server.