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