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 if (!empty($conf->facture->multidir_output[$object->entity])) {
112 $upload_dir = $conf->facture->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
113 }
114 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
115 $nbLinks = Link::count($db, $object->element, $object->id);
116 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?id='.$object->id;
117 $head[$h][1] = $langs->trans('Documents');
118 if (($nbFiles + $nbLinks) > 0) {
119 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
120 }
121 $head[$h][2] = 'documents';
122 $h++;
123
124 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/agenda.php?id='.$object->id;
125 $head[$h][1] = $langs->trans("Events");
126 if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
127 $nbEvent = 0;
128 // Enable caching of thirdparty count actioncomm
129 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
130 $cachekey = 'count_events_facture_'.$object->id;
131 $dataretrieved = dol_getcache($cachekey);
132 if (!is_null($dataretrieved)) {
133 $nbEvent = $dataretrieved;
134 } else {
135 $sql = "SELECT COUNT(id) as nb";
136 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
137 $sql .= " WHERE fk_element = ".((int) $object->id);
138 $sql .= " AND elementtype = 'invoice'";
139 $resql = $db->query($sql);
140 if ($resql) {
141 $obj = $db->fetch_object($resql);
142 $nbEvent = $obj->nb;
143 } else {
144 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
145 }
146 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
147 }
148
149 $head[$h][1] .= '/';
150 $head[$h][1] .= $langs->trans("Agenda");
151 if ($nbEvent > 0) {
152 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
153 }
154 }
155 $head[$h][2] = 'agenda';
156 $h++;
157
158 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'add', 'external');
159
160 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'remove');
161
162 return $head;
163}
164
171{
172 global $langs, $conf, $user, $db;
173
174 $extrafields = new ExtraFields($db);
175 $extrafields->fetch_name_optionals_label('facture');
176 $extrafields->fetch_name_optionals_label('facturedet');
177 $extrafields->fetch_name_optionals_label('facture_rec');
178 $extrafields->fetch_name_optionals_label('facturedet_rec');
179
180 $h = 0;
181 $head = array();
182
183 $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
184 $head[$h][1] = $langs->trans("Miscellaneous");
185 $head[$h][2] = 'general';
186 $h++;
187
188 $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
189 $head[$h][1] = $langs->trans("Payments");
190 $head[$h][2] = 'payment';
191 $h++;
192
193 // Show more tabs from modules
194 // Entries must be declared in modules descriptor with line
195 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
196 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
197 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
198
199 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
200 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
201 $nbExtrafields = $extrafields->attributes['facture']['count'];
202 if ($nbExtrafields > 0) {
203 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
204 }
205 $head[$h][2] = 'attributes';
206 $h++;
207
208 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
209 $head[$h][1] = $langs->trans("ExtraFieldsLines");
210 $nbExtrafields = $extrafields->attributes['facturedet']['count'];
211 if ($nbExtrafields > 0) {
212 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
213 }
214 $head[$h][2] = 'attributeslines';
215 $h++;
216
217 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
218 $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
219 $nbExtrafields = $extrafields->attributes['facture_rec']['count'];
220 if ($nbExtrafields > 0) {
221 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
222 }
223 $head[$h][2] = 'attributesrec';
224 $h++;
225
226 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
227 $head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
228 $nbExtrafields = $extrafields->attributes['facturedet_rec']['count'];
229 if ($nbExtrafields > 0) {
230 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
231 }
232 $head[$h][2] = 'attributeslinesrec';
233 $h++;
234
235 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
236 $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
237 $head[$h][1] = $langs->trans("InvoiceSituation");
238 $head[$h][2] = 'situation';
239 $h++;
240 }
241
242 complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
243
244 return $head;
245}
246
247
255{
256 global $db, $langs, $conf, $user;
257
258 $h = 0;
259 $head = array();
260
261 $head[$h][0] = DOL_URL_ROOT . '/compta/facture/card-rec.php?id=' . $object->id;
262 $head[$h][1] = $langs->trans("RepeatableInvoice");
263 $head[$h][2] = 'card';
264 $h++;
265
266 $head[$h][0] = DOL_URL_ROOT.'/compta/facture/agenda-rec.php?id='.$object->id;
267 $head[$h][1] = $langs->trans("Events");
268 if (isModEnabled('agenda')&& ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
269 $nbEvent = 0;
270 // Enable caching of thirdparty count actioncomm
271 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
272 $cachekey = 'count_events_facturerec_'.$object->id;
273 $dataretrieved = dol_getcache($cachekey);
274 if (!is_null($dataretrieved)) {
275 $nbEvent = $dataretrieved;
276 } else {
277 $sql = "SELECT COUNT(id) as nb";
278 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
279 $sql .= " WHERE fk_element = ".((int) $object->id);
280 $sql .= " AND elementtype = 'invoicerec'";
281 $resql = $db->query($sql);
282 if ($resql) {
283 $obj = $db->fetch_object($resql);
284 $nbEvent = $obj->nb;
285 } else {
286 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
287 }
288 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
289 }
290
291 $head[$h][1] .= '/';
292 $head[$h][1] .= $langs->trans("Agenda");
293 if ($nbEvent > 0) {
294 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
295 }
296 }
297 $head[$h][2] = 'agenda';
298 $h++;
299
300 // Show more tabs from modules
301 // Entries must be declared in modules descriptor with line
302 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
303 // $this->tabs = array('entity:-tabname); to remove a tab
304 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
305
306 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
307
308 return $head;
309}
310
318{
319 global $db, $langs, $conf;
320
321 $h = 0;
322 $head = array();
323
324 $head[$h][0] = DOL_URL_ROOT . '/fourn/facture/card-rec.php?id=' . $object->id;
325 $head[$h][1] = $langs->trans("RepeatableSupplierInvoice");
326 $head[$h][2] = 'card';
327 $h++;
328
329 // Show more tabs from modules
330 // Entries must be declared in modules descriptor with line
331 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
332 // $this->tabs = array('entity:-tabname); to remove a tab
333 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec');
334
335 complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice_supplier_rec', 'remove');
336
337 return $head;
338}
339
347{
348 global $conf, $db, $langs, $user;
349
350 if (($mode == 'customers' && isModEnabled('facture') && $user->hasRight('facture', 'lire'))
351 || ($mode == 'suppliers' && (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('fournisseur', 'facture', 'lire'))
352 ) {
353 global $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus8, $badgeStatus11;
354 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
355
356 $now = date_create(date('Y-m-d', dol_now()));
357 $datenowsub30 = date_create(date('Y-m-d', dol_now()));
358 $datenowsub15 = date_create(date('Y-m-d', dol_now()));
359 $datenowadd30 = date_create(date('Y-m-d', dol_now()));
360 $datenowadd15 = date_create(date('Y-m-d', dol_now()));
361 $interval30days = date_interval_create_from_date_string('30 days');
362 $interval15days = date_interval_create_from_date_string('15 days');
363 date_sub($datenowsub30, $interval30days);
364 date_sub($datenowsub15, $interval15days);
365 date_add($datenowadd30, $interval30days);
366 date_add($datenowadd15, $interval15days);
367
368 $sql = "SELECT";
369 $sql .= " sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub30, 'Y-m-d')."'", 1, 0).") as nblate30";
370 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($datenowsub15, 'Y-m-d')."'", 1, 0).") as nblate15";
371 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement < '".date_format($now, 'Y-m-d')."'", 1, 0).") as nblatenow";
372 $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";
373 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd15, 'Y-m-d')."'", 1, 0).") as nbnotlate15";
374 $sql .= ", sum(".$db->ifsql("f.date_lim_reglement > '".date_format($datenowadd30, 'Y-m-d')."'", 1, 0).") as nbnotlate30";
375 if ($mode == 'customers') {
376 $element = 'invoice';
377 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
378 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
379 $element = 'supplier_invoice';
380 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
381 } else {
382 return '';
383 }
384 $sql .= " WHERE f.entity IN (".getEntity($element).")";
385 $sql .= " AND f.type <> 2";
386 $sql .= " AND f.fk_statut = 1";
387 if (isset($user->socid) && $user->socid > 0) {
388 $sql .= " AND f.fk_soc = ".((int) $user->socid);
389 }
390
391 $resql = $db->query($sql);
392 if ($resql) {
393 $num = $db->num_rows($resql);
394 $i = 0;
395 $total = 0;
396 $dataseries = array();
397
398 while ($i < $num) {
399 $obj = $db->fetch_object($resql);
400 /*
401 $dataseries = array(array($langs->trans('InvoiceLate30Days'), $obj->nblate30)
402 ,array($langs->trans('InvoiceLate15Days'), $obj->nblate15 - $obj->nblate30)
403 ,array($langs->trans('InvoiceLateMinus15Days'), $obj->nblatenow - $obj->nblate15)
404 ,array($langs->trans('InvoiceNotLate'), $obj->nbnotlatenow - $obj->nbnotlate15)
405 ,array($langs->trans('InvoiceNotLate15Days'), $obj->nbnotlate15 - $obj->nbnotlate30)
406 ,array($langs->trans('InvoiceNotLate30Days'), $obj->nbnotlate30));
407 */
408 $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);
409 $i++;
410 }
411 if (!empty($dataseries[0])) {
412 foreach ($dataseries[0] as $key => $value) {
413 if (is_numeric($value)) {
414 $total += $value;
415 }
416 }
417 }
418 $legend = array(
419 $langs->trans('InvoiceLate30Days'),
420 $langs->trans('InvoiceLate15Days'),
421 $langs->trans('InvoiceLateMinus15Days'),
422 $mode == 'customers' ? $langs->trans('InvoiceNotLate') : $langs->trans("InvoiceToPay"),
423 $mode == 'customers' ? $langs->trans('InvoiceNotLate15Days') : $langs->trans("InvoiceToPay15Days"),
424 $mode == 'customers' ? $langs->trans('InvoiceNotLate30Days') : $langs->trans("InvoiceToPay30Days"),
425 );
426
427 $colorseries = array($badgeStatus8, $badgeStatus1, $badgeStatus3, $badgeStatus4, $badgeStatus11, '-'.$badgeStatus11);
428
429 $result = '<div class="div-table-responsive-no-min">';
430 $result .= '<table class="noborder nohover centpercent">';
431 $result .= '<tr class="liste_titre">';
432 $result .= '<td>'.$langs->trans("NbOfOpenInvoices").' - ';
433 if ($mode == 'customers') {
434 $result .= $langs->trans("CustomerInvoice");
435 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
436 $result .= $langs->trans("SupplierInvoice");
437 } else {
438 return '';
439 }
440 $result .= '</td>';
441 $result .= '</tr>';
442
443 if ($conf->use_javascript_ajax) {
444 //var_dump($dataseries);
445 $dolgraph = new DolGraph();
446 $dolgraph->SetData($dataseries);
447
448 $dolgraph->setLegend($legend);
449
450 $dolgraph->SetDataColor(array_values($colorseries));
451 $dolgraph->setShowLegend(2);
452 $dolgraph->setShowPercent(1);
453 $dolgraph->SetType(array('bars', 'bars', 'bars', 'bars', 'bars', 'bars'));
454 //$dolgraph->SetType(array('pie'));
455 $dolgraph->setHeight('160'); /* 160 min is required to show the 6 lines of legend */
456 $dolgraph->setWidth('450');
457 $dolgraph->setHideXValues(true);
458 if ($mode == 'customers') {
459 $dolgraph->draw('idgraphcustomerinvoices');
460 } elseif ($mode == 'fourn' || $mode == 'suppliers') {
461 $dolgraph->draw('idgraphfourninvoices');
462 } else {
463 return '';
464 }
465 $result .= '<tr maxwidth="255">';
466 $result .= '<td class="center">'.$dolgraph->show($total ? 0 : $langs->trans("NoOpenInvoice")).'</td>';
467 $result .= '</tr>';
468 } else {
469 // Print text lines
470 }
471
472 $result .= '</table>';
473 $result .= '</div>';
474
475 return $result;
476 } else {
477 dol_print_error($db);
478 }
479 }
480 return '';
481}
482
490function getCustomerInvoiceDraftTable($maxCount = 500, $socid = 0)
491{
492 global $conf, $db, $langs, $user, $hookmanager;
493
494 $result = '';
495
496 if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
497 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
498
499 $tmpinvoice = new Facture($db);
500
501 $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total_ht, f.total_tva, f.total_ttc, f.ref_client";
502 $sql .= ", f.type, f.fk_statut as status, f.paye";
503 $sql .= ", s.nom as name";
504 $sql .= ", s.rowid as socid, s.email";
505 $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
506 $sql .= ", cc.rowid as country_id, cc.code as country_code";
507 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
508 $sql .= ", sc.fk_soc, sc.fk_user ";
509 }
510 $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";
511 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
512 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
513 }
514 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
515 $sql .= " AND f.entity IN (".getEntity('invoice').")";
516 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
517 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
518 }
519
520 if ($socid) {
521 $sql .= " AND f.fk_soc = ".((int) $socid);
522 }
523 // Add where from hooks
524 $parameters = array();
525 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
526 $sql .= $hookmanager->resPrint;
527
528 $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,";
529 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
530 $sql .= " cc.rowid, cc.code";
531 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
532 $sql .= ", sc.fk_soc, sc.fk_user";
533 }
534
535 // Add Group from hooks
536 $parameters = array();
537 $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
538 $sql .= $hookmanager->resPrint;
539
540 $resql = $db->query($sql);
541
542 if ($resql) {
543 $num = $db->num_rows($resql);
544 $nbofloop = min($num, $maxofloop);
545
546 $result .= '<div class="div-table-responsive-no-min">';
547 $result .= '<table class="noborder centpercent">';
548
549 $result .= '<tr class="liste_titre">';
550 $result .= '<th colspan="3">';
551 $result .= $langs->trans("CustomersDraftInvoices").' ';
552 $result .= '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
553 $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
554 $result .= '</a>';
555 $result .= '</th>';
556 $result .= '</tr>';
557
558 if ($num) {
559 $companystatic = new Societe($db);
560
561 $i = 0;
562 $othernb = 0;
563 $tot_ttc = 0;
564 while ($i < $nbofloop) {
565 $obj = $db->fetch_object($resql);
566
567 if ($i >= $maxCount) {
568 $othernb += 1;
569 $i++;
570 $tot_ttc += $obj->total_ttc;
571 continue;
572 }
573
574 $tmpinvoice->id = $obj->rowid;
575 $tmpinvoice->ref = $obj->ref;
576 $tmpinvoice->date = $db->jdate($obj->date);
577 $tmpinvoice->type = $obj->type;
578 $tmpinvoice->total_ht = $obj->total_ht;
579 $tmpinvoice->total_tva = $obj->total_tva;
580 $tmpinvoice->total_ttc = $obj->total_ttc;
581 $tmpinvoice->ref_client = $obj->ref_client;
582 $tmpinvoice->statut = $obj->status;
583 $tmpinvoice->paye = $obj->paye;
584
585 $companystatic->id = $obj->socid;
586 $companystatic->name = $obj->name;
587 $companystatic->email = $obj->email;
588 $companystatic->country_id = $obj->country_id;
589 $companystatic->country_code = $obj->country_code;
590 $companystatic->client = 1;
591 $companystatic->code_client = $obj->code_client;
592 $companystatic->code_fournisseur = $obj->code_fournisseur;
593 $companystatic->code_compta = $obj->code_compta;
594 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
595
596 $result .= '<tr class="oddeven">';
597 $result .= '<td class="nowrap tdoverflowmax100">';
598 $result .= $tmpinvoice->getNomUrl(1, '');
599 $result .= '</td>';
600 $result .= '<td class="nowrap tdoverflowmax100">';
601 $result .= $companystatic->getNomUrl(1, 'customer');
602 $result .= '</td>';
603 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
604 $result .= '</tr>';
605 $tot_ttc += $obj->total_ttc;
606 $i++;
607 }
608
609 if ($othernb) {
610 $result .= '<tr class="oddeven">';
611 $result .= '<td class="nowrap" colspan="3">';
612 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
613 $result .= '</td>';
614 $result .= "</tr>\n";
615 }
616
617 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
618 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
619 $result .= '</tr>';
620 } else {
621 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
622 }
623 $result .= "</table></div>";
624 $db->free($resql);
625 } else {
626 dol_print_error($db);
627 }
628 }
629
630 return $result;
631}
632
640function getDraftSupplierTable($maxCount = 500, $socid = 0)
641{
642 global $conf, $db, $langs, $user, $hookmanager;
643
644 $result = '';
645
646 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
647 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
648
649 $facturesupplierstatic = new FactureFournisseur($db);
650
651 $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";
652 $sql .= ", s.nom as name";
653 $sql .= ", s.rowid as socid, s.email";
654 $sql .= ", s.code_client, s.code_compta";
655 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
656 $sql .= ", cc.rowid as country_id, cc.code as country_code";
657 $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";
658 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
659 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
660 }
661 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
662 $sql .= " AND f.entity IN (".getEntity('invoice').')';
663 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
664 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
665 }
666 if ($socid) {
667 $sql .= " AND f.fk_soc = ".((int) $socid);
668 }
669 // Add where from hooks
670 $parameters = array();
671 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
672 $sql .= $hookmanager->resPrint;
673 $resql = $db->query($sql);
674
675 if ($resql) {
676 $num = $db->num_rows($resql);
677 $nbofloop = min($num, $maxofloop);
678
679 $result .= '<div class="div-table-responsive-no-min">';
680 $result .= '<table class="noborder centpercent">';
681
682 $result .= '<tr class="liste_titre">';
683 $result .= '<th colspan="3">';
684 $result .= $langs->trans("SuppliersDraftInvoices").' ';
685 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
686 $result .= '<span class="badge marginleftonlyshort">'.$num.'</span>';
687 $result .= '</a>';
688 $result .= '</th>';
689 $result .= '</tr>';
690
691 if ($num) {
692 $companystatic = new Societe($db);
693
694 $i = 0;
695 $othernb = 0;
696 $tot_ttc = 0;
697 while ($i < $nbofloop) {
698 $obj = $db->fetch_object($resql);
699
700 if ($i >= $maxCount) {
701 $othernb += 1;
702 $i++;
703 $tot_ttc += $obj->total_ttc;
704 continue;
705 }
706
707 $facturesupplierstatic->ref = $obj->ref;
708 $facturesupplierstatic->id = $obj->rowid;
709 $facturesupplierstatic->total_ht = $obj->total_ht;
710 $facturesupplierstatic->total_tva = $obj->total_tva;
711 $facturesupplierstatic->total_ttc = $obj->total_ttc;
712 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
713 $facturesupplierstatic->type = $obj->type;
714 $facturesupplierstatic->statut = $obj->status;
715 $facturesupplierstatic->paye = $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') && !$socid) {
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') && !$socid) {
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') && !$socid) {
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') && !$socid) {
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).'</th>';
915 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
916 $result .= '<th class="right"></th>';
917 $result .= '</tr>';
918
919 if ($num < 1) {
920 $result .= '</table>';
921 $result .= '</div>';
922 return $result;
923 }
924
925 $objectstatic = new FactureFournisseur($db);
926 $companystatic = new Societe($db);
927 $formfile = new FormFile($db);
928 $i = 0;
929
930 while ($i < $num) {
931 $obj = $db->fetch_object($resql);
932
933 $objectstatic->id = $obj->rowid;
934 $objectstatic->ref = $obj->ref;
935 $objectstatic->paye = $obj->paye;
936 $objectstatic->statut = $obj->status;
937 $objectstatic->total_ht = $obj->total_ht;
938 $objectstatic->total_tva = $obj->total_tva;
939 $objectstatic->total_ttc = $obj->total_ttc;
940 $objectstatic->type = $obj->type;
941
942 $companystatic->id = $obj->socid;
943 $companystatic->name = $obj->socname;
944 $companystatic->client = $obj->client;
945 $companystatic->canvas = $obj->canvas;
946
947 $filename = dol_sanitizeFileName($obj->ref);
948 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
949
950 $result .= '<tr class="nowrap">';
951
952 $result .= '<td class="oddeven">';
953 $result .= '<table class="nobordernopadding">';
954 $result .= '<tr class="nocellnopadd">';
955
956 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
957 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
958 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
959
960 $result .= '</tr>';
961 $result .= '</table>';
962 $result .= '</td>';
963
964 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
965
966 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
967
968 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
969
970 $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
971
972 $result .= '</tr>';
973
974 $i++;
975 }
976
977 $result .= '</table>';
978 $result .= '</div>';
979 return $result;
980}
981
989function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
990{
991 global $conf, $db, $langs, $user, $hookmanager;
992
993 $result = '';
994
995 if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
996 $tmpinvoice = new Facture($db);
997
998 $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";
999 $sql .= ", f.date_lim_reglement as datelimite";
1000 $sql .= ", s.nom as name";
1001 $sql .= ", s.rowid as socid, s.email";
1002 $sql .= ", s.code_client, s.code_compta";
1003 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1004 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1005 $sql .= ", sum(pf.amount) as am";
1006 $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";
1007 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1008 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
1009 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1010 }
1011 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1012 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1013 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
1014 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1015 }
1016 if ($socid) {
1017 $sql .= " AND f.fk_soc = ".((int) $socid);
1018 }
1019 // Add where from hooks
1020 $parameters = array();
1021 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1022 $sql .= $hookmanager->resPrint;
1023
1024 $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,";
1025 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1026 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1027 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1028
1029 $resql = $db->query($sql);
1030 if ($resql) {
1031 $num = $db->num_rows($resql);
1032 $i = 0;
1033 $othernb = 0;
1034
1035 $formfile = new FormFile($db);
1036
1037 print '<div class="div-table-responsive-no-min">';
1038 print '<table class="noborder centpercent">';
1039
1040 print '<tr class="liste_titre">';
1041 print '<th colspan="2">';
1042 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1043 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1044 print '<span class="badge">'.$num.'</span>';
1045 print '</a>';
1046 print '</th>';
1047
1048 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1049 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1050 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1051 }
1052 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1053 print '<th class="right">'.$langs->trans("Received").'</th>';
1054 print '<th width="16">&nbsp;</th>';
1055 print '</tr>';
1056 if ($num) {
1057 $societestatic = new Societe($db);
1058 $total_ttc = $totalam = $total = 0;
1059 while ($i < $num) {
1060 $obj = $db->fetch_object($resql);
1061
1062 if ($i >= $maxCount) {
1063 $othernb += 1;
1064 $i++;
1065 $total += $obj->total_ht;
1066 $total_ttc += $obj->total_ttc;
1067 $totalam += $obj->am;
1068 continue;
1069 }
1070
1071 $tmpinvoice->ref = $obj->ref;
1072 $tmpinvoice->id = $obj->rowid;
1073 $tmpinvoice->total_ht = $obj->total_ht;
1074 $tmpinvoice->total_tva = $obj->total_tva;
1075 $tmpinvoice->total_ttc = $obj->total_ttc;
1076 $tmpinvoice->type = $obj->type;
1077 $tmpinvoice->statut = $obj->status;
1078 $tmpinvoice->paye = $obj->paye;
1079 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1080
1081 $societestatic->id = $obj->socid;
1082 $societestatic->name = $obj->name;
1083 $societestatic->email = $obj->email;
1084 $societestatic->country_id = $obj->country_id;
1085 $societestatic->country_code = $obj->country_code;
1086 $societestatic->client = 1;
1087 $societestatic->code_client = $obj->code_client;
1088 $societestatic->code_fournisseur = $obj->code_fournisseur;
1089 $societestatic->code_compta = $obj->code_compta;
1090 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1091
1092 print '<tr class="oddeven">';
1093 print '<td class="nowrap">';
1094
1095 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1096 print '<td class="nobordernopadding nowrap">';
1097 print $tmpinvoice->getNomUrl(1, '');
1098 print '</td>';
1099 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1100 $filename = dol_sanitizeFileName($obj->ref);
1101 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1102 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1103 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1104 print '</td></tr></table>';
1105
1106 print '</td>';
1107 print '<td class="nowrap tdoverflowmax100">';
1108 print $societestatic->getNomUrl(1, 'customer');
1109 print '</td>';
1110 print '<td class="right">';
1111 print dol_print_date($db->jdate($obj->datelimite), 'day');
1112 if ($tmpinvoice->hasDelay()) {
1113 print img_warning($langs->trans("Late"));
1114 }
1115 print '</td>';
1116 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1117 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1118 }
1119 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1120 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1121 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1122 print '</tr>';
1123
1124 $total_ttc += $obj->total_ttc;
1125 $total += $obj->total_ht;
1126 $totalam += $obj->am;
1127
1128 $i++;
1129 }
1130
1131 if ($othernb) {
1132 $colspan = 6;
1133 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1134 $colspan++;
1135 }
1136 print '<tr class="oddeven">';
1137 print '<td class="nowrap" colspan="'.$colspan.'">';
1138 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1139 print '</td>';
1140 print "</tr>\n";
1141 }
1142
1143 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>';
1144 print '<td>&nbsp;</td>';
1145 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1146 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1147 }
1148 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1149 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1150 print '<td>&nbsp;</td>';
1151 print '</tr>';
1152 } else {
1153 $colspan = 6;
1154 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1155 $colspan++;
1156 }
1157 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1158 }
1159 print '</table></div><br>';
1160 $db->free($resql);
1161 } else {
1162 dol_print_error($db);
1163 }
1164 }
1165
1166 return $result;
1167}
1168
1169
1177function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1178{
1179 global $conf, $db, $langs, $user, $hookmanager;
1180
1181 $result = '';
1182
1183 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1184 $facstatic = new FactureFournisseur($db);
1185
1186 $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";
1187 $sql .= ", ff.date_lim_reglement";
1188 $sql .= ", s.nom as name";
1189 $sql .= ", s.rowid as socid, s.email";
1190 $sql .= ", s.code_client, s.code_compta";
1191 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1192 $sql .= ", sum(pf.amount) as am";
1193 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1194 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1195 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
1196 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1197 }
1198 $sql .= " WHERE s.rowid = ff.fk_soc";
1199 $sql .= " AND ff.entity = ".$conf->entity;
1200 $sql .= " AND ff.paye = 0";
1201 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1202 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
1203 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1204 }
1205 if ($socid) {
1206 $sql .= " AND ff.fk_soc = ".((int) $socid);
1207 }
1208 // Add where from hooks
1209 $parameters = array();
1210 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1211 $sql .= $hookmanager->resPrint;
1212
1213 $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,";
1214 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1215 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1216
1217 $resql = $db->query($sql);
1218 if ($resql) {
1219 $num = $db->num_rows($resql);
1220 $othernb = 0;
1221
1222 $formfile = new FormFile($db);
1223
1224 print '<div class="div-table-responsive-no-min">';
1225 print '<table class="noborder centpercent">';
1226
1227 print '<tr class="liste_titre">';
1228 print '<th colspan="2">';
1229 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1230 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1231 print '<span class="badge">'.$num.'</span>';
1232 print '</a>';
1233 print '</th>';
1234
1235 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1236 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1237 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1238 }
1239 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1240 print '<th class="right">'.$langs->trans("Paid").'</th>';
1241 print '<th width="16">&nbsp;</th>';
1242 print "</tr>\n";
1243 $societestatic = new Societe($db);
1244 if ($num) {
1245 $i = 0;
1246 $total = $total_ttc = $totalam = 0;
1247 while ($i < $num) {
1248 $obj = $db->fetch_object($resql);
1249
1250 if ($i >= $maxCount) {
1251 $othernb += 1;
1252 $i++;
1253 $total += $obj->total_ht;
1254 $total_ttc += $obj->total_ttc;
1255 continue;
1256 }
1257
1258 $facstatic->ref = $obj->ref;
1259 $facstatic->id = $obj->rowid;
1260 $facstatic->type = $obj->type;
1261 $facstatic->total_ht = $obj->total_ht;
1262 $facstatic->total_tva = $obj->total_tva;
1263 $facstatic->total_ttc = $obj->total_ttc;
1264 $facstatic->statut = $obj->status;
1265 $facstatic->paye = $obj->paye;
1266
1267 $societestatic->id = $obj->socid;
1268 $societestatic->name = $obj->name;
1269 $societestatic->email = $obj->email;
1270 $societestatic->client = 0;
1271 $societestatic->fournisseur = 1;
1272 $societestatic->code_client = $obj->code_client;
1273 $societestatic->code_fournisseur = $obj->code_fournisseur;
1274 $societestatic->code_compta = $obj->code_compta;
1275 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1276
1277 print '<tr class="oddeven">';
1278 print '<td class="nowrap tdoverflowmax100">';
1279 print $facstatic->getNomUrl(1, '');
1280 print '</td>';
1281 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1282 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1283 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1284 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1285 }
1286 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1287 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1288 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1289 print '</tr>';
1290 $total += $obj->total_ht;
1291 $total_ttc += $obj->total_ttc;
1292 $totalam += $obj->am;
1293 $i++;
1294 }
1295
1296 if ($othernb) {
1297 $colspan = 6;
1298 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1299 $colspan++;
1300 }
1301 print '<tr class="oddeven">';
1302 print '<td class="nowrap" colspan="'.$colspan.'">';
1303 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1304 print '</td>';
1305 print "</tr>\n";
1306 }
1307
1308 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>';
1309 print '<td>&nbsp;</td>';
1310 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1311 print '<td class="right">'.price($total).'</td>';
1312 }
1313 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1314 print '<td class="nowrap right">'.price($totalam).'</td>';
1315 print '<td>&nbsp;</td>';
1316 print '</tr>';
1317 } else {
1318 $colspan = 6;
1319 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1320 $colspan++;
1321 }
1322 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1323 }
1324 print '</table></div><br>';
1325 } else {
1326 dol_print_error($db);
1327 }
1328 }
1329
1330 return $result;
1331}
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.