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