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