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_client = $obj->code_compta;
596 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
597
598 $result .= '<tr class="oddeven">';
599 $result .= '<td class="nowrap tdoverflowmax100">';
600 $result .= $tmpinvoice->getNomUrl(1, '');
601 $result .= '</td>';
602 $result .= '<td class="nowrap tdoverflowmax100">';
603 $result .= $companystatic->getNomUrl(1, 'customer');
604 $result .= '</td>';
605 $result .= '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
606 $result .= '</tr>';
607 $tot_ttc += $obj->total_ttc;
608 $i++;
609 }
610
611 if ($othernb) {
612 $result .= '<tr class="oddeven">';
613 $result .= '<td class="nowrap" colspan="3">';
614 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
615 $result .= '</td>';
616 $result .= "</tr>\n";
617 }
618
619 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
620 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
621 $result .= '</tr>';
622 } else {
623 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
624 }
625 $result .= "</table></div>";
626 $db->free($resql);
627 } else {
628 dol_print_error($db);
629 }
630 }
631
632 return $result;
633}
634
642function getDraftSupplierTable($maxCount = 500, $socid = 0)
643{
644 global $conf, $db, $langs, $user, $hookmanager;
645
646 $result = '';
647
648 if ((isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) && $user->hasRight('facture', 'lire')) {
649 $maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
650
651 $facturesupplierstatic = new FactureFournisseur($db);
652
653 $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";
654 $sql .= ", s.nom as name";
655 $sql .= ", s.rowid as socid, s.email";
656 $sql .= ", s.code_client, s.code_compta";
657 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
658 $sql .= ", cc.rowid as country_id, cc.code as country_code";
659 $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";
660 if (!$user->hasRight('societe', 'client', 'voir')) {
661 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
662 }
663 $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
664 $sql .= " AND f.entity IN (".getEntity('invoice').')';
665 if (!$user->hasRight('societe', 'client', 'voir')) {
666 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
667 }
668 if ($socid) {
669 $sql .= " AND f.fk_soc = ".((int) $socid);
670 }
671 // Add where from hooks
672 $parameters = array();
673 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
674 $sql .= $hookmanager->resPrint;
675 $resql = $db->query($sql);
676
677 if ($resql) {
678 $num = $db->num_rows($resql);
679 $nbofloop = min($num, $maxofloop);
680
681 $result .= '<div class="div-table-responsive-no-min">';
682 $result .= '<table class="noborder centpercent">';
683
684 $result .= '<tr class="liste_titre">';
685 $result .= '<th colspan="3">';
686 $result .= $langs->trans("SuppliersDraftInvoices");
687 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
688 $result .= '<span class="badge marginleftonly">'.$num.'</span>';
689 $result .= '</a>';
690 $result .= '</th>';
691 $result .= '</tr>';
692
693 if ($num) {
694 $companystatic = new Societe($db);
695
696 $i = 0;
697 $othernb = 0;
698 $tot_ttc = 0;
699 while ($i < $nbofloop) {
700 $obj = $db->fetch_object($resql);
701
702 if ($i >= $maxCount) {
703 $othernb += 1;
704 $i++;
705 $tot_ttc += $obj->total_ttc;
706 continue;
707 }
708
709 $facturesupplierstatic->ref = $obj->ref;
710 $facturesupplierstatic->id = $obj->rowid;
711 $facturesupplierstatic->total_ht = $obj->total_ht;
712 $facturesupplierstatic->total_tva = $obj->total_tva;
713 $facturesupplierstatic->total_ttc = $obj->total_ttc;
714 $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
715 $facturesupplierstatic->type = $obj->type;
716 $facturesupplierstatic->statut = $obj->status;
717 $facturesupplierstatic->status = $obj->status;
718 $facturesupplierstatic->paye = $obj->paye;
719 $facturesupplierstatic->paid = $obj->paye;
720
721 $companystatic->id = $obj->socid;
722 $companystatic->name = $obj->name;
723 $companystatic->email = $obj->email;
724 $companystatic->country_id = $obj->country_id;
725 $companystatic->country_code = $obj->country_code;
726 $companystatic->fournisseur = 1;
727 $companystatic->code_client = $obj->code_client;
728 $companystatic->code_fournisseur = $obj->code_fournisseur;
729 $companystatic->code_compta = $obj->code_compta;
730 $companystatic->code_compta_client = $obj->code_compta;
731 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
732
733 $result .= '<tr class="oddeven">';
734 $result .= '<td class="nowrap tdoverflowmax100">';
735 $result .= $facturesupplierstatic->getNomUrl(1, '');
736 $result .= '</td>';
737 $result .= '<td class="nowrap tdoverflowmax100">';
738 $result .= $companystatic->getNomUrl(1, 'supplier');
739 $result .= '</td>';
740 $result .= '<td class="right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
741 $result .= '</tr>';
742 $tot_ttc += $obj->total_ttc;
743 $i++;
744 }
745
746 if ($othernb) {
747 $result .= '<tr class="oddeven">';
748 $result .= '<td class="nowrap" colspan="3">';
749 $result .= '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
750 $result .= '</td>';
751 $result .= "</tr>\n";
752 }
753
754 $result .= '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
755 $result .= '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
756 $result .= '</tr>';
757 } else {
758 $result .= '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
759 }
760 $result .= "</table></div>";
761 $db->free($resql);
762 } else {
763 dol_print_error($db);
764 }
765 }
766
767 return $result;
768}
769
770
778function getCustomerInvoiceLatestEditTable($maxCount = 5, $socid = 0)
779{
780 global $conf, $db, $langs, $user;
781
782 $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,";
783 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
784 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
785 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
786 if (!$user->hasRight('societe', 'client', 'voir')) {
787 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
788 }
789 $sql .= " WHERE f.fk_soc = s.rowid";
790 $sql .= " AND f.entity IN (".getEntity('facture').")";
791 if ($socid) {
792 $sql .= " AND f.fk_soc = ".((int) $socid);
793 }
794 if (!$user->hasRight('societe', 'client', 'voir')) {
795 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
796 }
797 $sql .= " ORDER BY f.tms DESC";
798 $sql .= $db->plimit($maxCount, 0);
799
800 $resql = $db->query($sql);
801 if (!$resql) {
802 dol_print_error($db);
803 }
804
805 $num = $db->num_rows($resql);
806
807 $result = '<div class="div-table-responsive-no-min">';
808 $result .= '<table class="noborder centpercent">';
809
810 $result .= '<tr class="liste_titre">';
811 $result .= '<th colspan="3">'.$langs->trans("LastCustomersBills", $maxCount).'</th>';
812 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
813 $result .= '<th class="right"></th>';
814 $result .= '</tr>';
815
816 if ($num < 1) {
817 $result .= '</table>';
818 $result .= '</div>';
819 return $result;
820 }
821
822 $formfile = new FormFile($db);
823 $objectstatic = new Facture($db);
824 $companystatic = new Societe($db);
825 $i = 0;
826
827 while ($i < $num) {
828 $obj = $db->fetch_object($resql);
829
830 $objectstatic->id = $obj->rowid;
831 $objectstatic->ref = $obj->ref;
832 $objectstatic->paye = $obj->paye;
833 $objectstatic->statut = $obj->status;
834 $objectstatic->total_ht = $obj->total_ht;
835 $objectstatic->total_tva = $obj->total_tva;
836 $objectstatic->total_ttc = $obj->total_ttc;
837 $objectstatic->type = $obj->type;
838
839 $companystatic->id = $obj->socid;
840 $companystatic->name = $obj->socname;
841 $companystatic->client = $obj->client;
842 $companystatic->canvas = $obj->canvas;
843
844 $filename = dol_sanitizeFileName($obj->ref);
845 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
846
847 $result .= '<tr class="nowrap">';
848
849 $result .= '<td class="oddeven">';
850 $result .= '<table class="nobordernopadding">';
851 $result .= '<tr class="nocellnopadd">';
852
853 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
854 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
855 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
856
857 $result .= '</tr>';
858 $result .= '</table>';
859 $result .= '</td>';
860
861 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
862 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
863 $result .= '<td class="right amount">'.price($obj->total_ttc).'</td>';
864
865 // Load amount of existing payment of invoice (needed for complete status)
866 $payment = $objectstatic->getSommePaiement();
867 $result .= '<td class="right">'.$objectstatic->getLibStatut(5, $payment).'</td>';
868
869 $result .= '</tr>';
870
871 $i++;
872 }
873
874 $result .= '</table>';
875 $result .= '</div>';
876 return $result;
877}
878
886function getPurchaseInvoiceLatestEditTable($maxCount = 5, $socid = 0)
887{
888 global $conf, $db, $langs, $user;
889
890 $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,";
891 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client";
892 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
893 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
894 if (!$user->hasRight('societe', 'client', 'voir')) {
895 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
896 }
897 $sql .= " WHERE f.fk_soc = s.rowid";
898 $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
899 if ($socid) {
900 $sql .= " AND f.fk_soc = ".((int) $socid);
901 }
902 if (!$user->hasRight('societe', 'client', 'voir')) {
903 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
904 }
905 $sql .= " ORDER BY f.tms DESC";
906 $sql .= $db->plimit($maxCount, 0);
907
908 $resql = $db->query($sql);
909 if (!$resql) {
910 dol_print_error($db);
911 return '';
912 }
913
914 $num = $db->num_rows($resql);
915
916 $result = '<div class="div-table-responsive-no-min">';
917 $result .= '<table class="noborder centpercent">';
918 $result .= '<tr class="liste_titre">';
919 $result .= '<th colspan="3">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).' ';
920 $result .= '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=DESC">';
921 $result .= '<span class="badge">...</span>';
922 $result .= '</a>';
923 $result .= '</th>';
924 $result .= '<th class="right">'.$langs->trans("AmountTTC").'</th>';
925 $result .= '<th class="right"></th>';
926 $result .= '</tr>';
927
928 if ($num < 1) {
929 $result .= '</table>';
930 $result .= '</div>';
931 return $result;
932 }
933
934 $objectstatic = new FactureFournisseur($db);
935 $companystatic = new Societe($db);
936 $formfile = new FormFile($db);
937 $i = 0;
938
939 while ($i < $num) {
940 $obj = $db->fetch_object($resql);
941
942 $objectstatic->id = $obj->rowid;
943 $objectstatic->ref = $obj->ref;
944 $objectstatic->paye = $obj->paye;
945 $objectstatic->paid = $obj->paye;
946 $objectstatic->statut = $obj->status;
947 $objectstatic->status = $obj->status;
948 $objectstatic->total_ht = $obj->total_ht;
949 $objectstatic->total_tva = $obj->total_tva;
950 $objectstatic->total_ttc = $obj->total_ttc;
951 $objectstatic->type = $obj->type;
952
953 $companystatic->id = $obj->socid;
954 $companystatic->name = $obj->socname;
955 $companystatic->client = $obj->client;
956 $companystatic->canvas = $obj->canvas;
957
958 $filename = dol_sanitizeFileName($obj->ref);
959 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
960
961 $result .= '<tr class="nowrap">';
962
963 $result .= '<td class="oddeven">';
964 $result .= '<table class="nobordernopadding">';
965 $result .= '<tr class="nocellnopadd">';
966
967 $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
968 $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
969 $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
970
971 $result .= '</tr>';
972 $result .= '</table>';
973 $result .= '</td>';
974
975 $result .= '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
976
977 $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
978
979 $result .= '<td class="amount right">'.price($obj->total_ttc).'</td>';
980
981 $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
982
983 $result .= '</tr>';
984
985 $i++;
986 }
987
988 $result .= '</table>';
989 $result .= '</div>';
990 return $result;
991}
992
1000function getCustomerInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1001{
1002 global $conf, $db, $langs, $user, $hookmanager;
1003
1004 $result = '';
1005
1006 if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
1007 $tmpinvoice = new Facture($db);
1008
1009 $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";
1010 $sql .= ", f.date_lim_reglement as datelimite";
1011 $sql .= ", s.nom as name";
1012 $sql .= ", s.rowid as socid, s.email";
1013 $sql .= ", s.code_client, s.code_compta";
1014 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1015 $sql .= ", cc.rowid as country_id, cc.code as country_code";
1016 $sql .= ", sum(pf.amount) as am";
1017 $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";
1018 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
1019 if (!$user->hasRight('societe', 'client', 'voir')) {
1020 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1021 }
1022 $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1023 $sql .= " AND f.entity IN (".getEntity('invoice').')';
1024 if (!$user->hasRight('societe', 'client', 'voir')) {
1025 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1026 }
1027 if ($socid) {
1028 $sql .= " AND f.fk_soc = ".((int) $socid);
1029 }
1030 // Add where from hooks
1031 $parameters = array();
1032 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
1033 $sql .= $hookmanager->resPrint;
1034
1035 $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,";
1036 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
1037 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1038 $sql .= " ORDER BY f.datef ASC, f.ref ASC";
1039
1040 $resql = $db->query($sql);
1041 if ($resql) {
1042 $num = $db->num_rows($resql);
1043 $i = 0;
1044 $othernb = 0;
1045
1046 $formfile = new FormFile($db);
1047
1048 print '<div class="div-table-responsive-no-min">';
1049 print '<table class="noborder centpercent">';
1050
1051 print '<tr class="liste_titre">';
1052 print '<th colspan="2">';
1053 print $langs->trans("BillsCustomersUnpaid", $num).' ';
1054 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
1055 print '<span class="badge">'.$num.'</span>';
1056 print '</a>';
1057 print '</th>';
1058
1059 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1060 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1061 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1062 }
1063 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1064 print '<th class="right">'.$langs->trans("Received").'</th>';
1065 print '<th width="16">&nbsp;</th>';
1066 print '</tr>';
1067 if ($num) {
1068 $societestatic = new Societe($db);
1069 $total_ttc = $totalam = $total = 0;
1070 while ($i < $num) {
1071 $obj = $db->fetch_object($resql);
1072
1073 if ($i >= $maxCount) {
1074 $othernb += 1;
1075 $i++;
1076 $total += $obj->total_ht;
1077 $total_ttc += $obj->total_ttc;
1078 $totalam += $obj->am;
1079 continue;
1080 }
1081
1082 $tmpinvoice->ref = $obj->ref;
1083 $tmpinvoice->id = $obj->rowid;
1084 $tmpinvoice->total_ht = $obj->total_ht;
1085 $tmpinvoice->total_tva = $obj->total_tva;
1086 $tmpinvoice->total_ttc = $obj->total_ttc;
1087 $tmpinvoice->type = $obj->type;
1088 $tmpinvoice->statut = $obj->status;
1089 $tmpinvoice->paye = $obj->paye;
1090 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1091
1092 $societestatic->id = $obj->socid;
1093 $societestatic->name = $obj->name;
1094 $societestatic->email = $obj->email;
1095 $societestatic->country_id = $obj->country_id;
1096 $societestatic->country_code = $obj->country_code;
1097 $societestatic->client = 1;
1098 $societestatic->code_client = $obj->code_client;
1099 $societestatic->code_fournisseur = $obj->code_fournisseur;
1100 $societestatic->code_compta = $obj->code_compta;
1101 $societestatic->code_compta_client = $obj->code_compta;
1102 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1103
1104 print '<tr class="oddeven">';
1105 print '<td class="nowrap">';
1106
1107 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1108 print '<td class="nobordernopadding nowrap">';
1109 print $tmpinvoice->getNomUrl(1, '');
1110 print '</td>';
1111 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1112 $filename = dol_sanitizeFileName($obj->ref);
1113 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1114 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1115 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1116 print '</td></tr></table>';
1117
1118 print '</td>';
1119 print '<td class="nowrap tdoverflowmax100">';
1120 print $societestatic->getNomUrl(1, 'customer');
1121 print '</td>';
1122 print '<td class="right">';
1123 print dol_print_date($db->jdate($obj->datelimite), 'day');
1124 if ($tmpinvoice->hasDelay()) {
1125 print img_warning($langs->trans("Late"));
1126 }
1127 print '</td>';
1128 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1129 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1130 }
1131 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1132 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1133 print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1134 print '</tr>';
1135
1136 $total_ttc += $obj->total_ttc;
1137 $total += $obj->total_ht;
1138 $totalam += $obj->am;
1139
1140 $i++;
1141 }
1142
1143 if ($othernb) {
1144 $colspan = 6;
1145 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1146 $colspan++;
1147 }
1148 print '<tr class="oddeven">';
1149 print '<td class="nowrap" colspan="'.$colspan.'">';
1150 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1151 print '</td>';
1152 print "</tr>\n";
1153 }
1154
1155 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>';
1156 print '<td>&nbsp;</td>';
1157 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1158 print '<td class="right"><span class="amount">'.price($total).'</span></td>';
1159 }
1160 print '<td class="nowrap right"><span class="amount">'.price($total_ttc).'</span></td>';
1161 print '<td class="nowrap right"><span class="amount">'.price($totalam).'</span></td>';
1162 print '<td>&nbsp;</td>';
1163 print '</tr>';
1164 } else {
1165 $colspan = 6;
1166 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1167 $colspan++;
1168 }
1169 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1170 }
1171 print '</table></div><br>';
1172 $db->free($resql);
1173 } else {
1174 dol_print_error($db);
1175 }
1176 }
1177
1178 return $result;
1179}
1180
1181
1189function getPurchaseInvoiceUnpaidOpenTable($maxCount = 500, $socid = 0)
1190{
1191 global $conf, $db, $langs, $user, $hookmanager;
1192
1193 $result = '';
1194
1195 if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
1196 $facstatic = new FactureFournisseur($db);
1197
1198 $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";
1199 $sql .= ", ff.date_lim_reglement";
1200 $sql .= ", s.nom as name";
1201 $sql .= ", s.rowid as socid, s.email";
1202 $sql .= ", s.code_client, s.code_compta";
1203 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1204 $sql .= ", sum(pf.amount) as am";
1205 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1206 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1207 if (!$user->hasRight('societe', 'client', 'voir')) {
1208 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1209 }
1210 $sql .= " WHERE s.rowid = ff.fk_soc";
1211 $sql .= " AND ff.entity = ".$conf->entity;
1212 $sql .= " AND ff.paye = 0";
1213 $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1214 if (!$user->hasRight('societe', 'client', 'voir')) {
1215 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1216 }
1217 if ($socid) {
1218 $sql .= " AND ff.fk_soc = ".((int) $socid);
1219 }
1220 // Add where from hooks
1221 $parameters = array();
1222 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1223 $sql .= $hookmanager->resPrint;
1224
1225 $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,";
1226 $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1227 $sql .= " ORDER BY ff.date_lim_reglement ASC";
1228
1229 $resql = $db->query($sql);
1230 if ($resql) {
1231 $num = $db->num_rows($resql);
1232 $othernb = 0;
1233
1234 $formfile = new FormFile($db);
1235
1236 print '<div class="div-table-responsive-no-min">';
1237 print '<table class="noborder centpercent">';
1238
1239 print '<tr class="liste_titre">';
1240 print '<th colspan="2">';
1241 print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1242 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1243 print '<span class="badge">'.$num.'</span>';
1244 print '</a>';
1245 print '</th>';
1246
1247 print '<th class="right">'.$langs->trans("DateDue").'</th>';
1248 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1249 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1250 }
1251 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1252 print '<th class="right">'.$langs->trans("Paid").'</th>';
1253 print '<th width="16">&nbsp;</th>';
1254 print "</tr>\n";
1255 $societestatic = new Societe($db);
1256 if ($num) {
1257 $i = 0;
1258 $total = $total_ttc = $totalam = 0;
1259 while ($i < $num) {
1260 $obj = $db->fetch_object($resql);
1261
1262 if ($i >= $maxCount) {
1263 $othernb += 1;
1264 $i++;
1265 $total += $obj->total_ht;
1266 $total_ttc += $obj->total_ttc;
1267 continue;
1268 }
1269
1270 $facstatic->ref = $obj->ref;
1271 $facstatic->id = $obj->rowid;
1272 $facstatic->type = $obj->type;
1273 $facstatic->total_ht = $obj->total_ht;
1274 $facstatic->total_tva = $obj->total_tva;
1275 $facstatic->total_ttc = $obj->total_ttc;
1276 $facstatic->statut = $obj->status;
1277 $facstatic->status = $obj->status;
1278 $facstatic->paid = $obj->paye;
1279 $facstatic->paye = $obj->paye;
1280
1281 $societestatic->id = $obj->socid;
1282 $societestatic->name = $obj->name;
1283 $societestatic->email = $obj->email;
1284 $societestatic->client = 0;
1285 $societestatic->fournisseur = 1;
1286 $societestatic->code_client = $obj->code_client;
1287 $societestatic->code_fournisseur = $obj->code_fournisseur;
1288 $societestatic->code_compta = $obj->code_compta;
1289 $societestatic->code_compta_client = $obj->code_compta;
1290 $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1291
1292 print '<tr class="oddeven">';
1293 print '<td class="nowrap tdoverflowmax100">';
1294 print $facstatic->getNomUrl(1, '');
1295 print '</td>';
1296 print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1297 print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1298 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1299 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
1300 }
1301 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
1302 print '<td class="nowrap right"><span class="amount">'.price($obj->am).'</span></td>';
1303 print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1304 print '</tr>';
1305 $total += $obj->total_ht;
1306 $total_ttc += $obj->total_ttc;
1307 $totalam += $obj->am;
1308 $i++;
1309 }
1310
1311 if ($othernb) {
1312 $colspan = 6;
1313 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1314 $colspan++;
1315 }
1316 print '<tr class="oddeven">';
1317 print '<td class="nowrap" colspan="'.$colspan.'">';
1318 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1319 print '</td>';
1320 print "</tr>\n";
1321 }
1322
1323 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>';
1324 print '<td>&nbsp;</td>';
1325 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1326 print '<td class="right">'.price($total).'</td>';
1327 }
1328 print '<td class="nowrap right">'.price($total_ttc).'</td>';
1329 print '<td class="nowrap right">'.price($totalam).'</td>';
1330 print '<td>&nbsp;</td>';
1331 print '</tr>';
1332 } else {
1333 $colspan = 6;
1334 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
1335 $colspan++;
1336 }
1337 print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1338 }
1339 print '</table></div><br>';
1340 } else {
1341 dol_print_error($db);
1342 }
1343 }
1344
1345 return $result;
1346}
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 a 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.