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