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