dolibarr 23.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2020 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
10 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
11 * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
12 * Copyright (C) 2021-2025 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
14 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
37// Load Dolibarr environment
38require '../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
43require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
44require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
47
48// L'espace compta/treso doit toujours etre actif car c'est un espace partage
49// par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
50// de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
51// est protegee par le droit qui va bien du module concerne.
52
61// Load translation files required by the page
62$langs->loadLangs(array('compta', 'bills'));
63if (isModEnabled('order')) {
64 $langs->load("orders");
65}
66
67// Get parameters
68$action = GETPOST('action', 'aZ09');
69$bid = GETPOSTINT('bid');
70
71// Security check
72$socid = '';
73if ($user->socid > 0) {
74 $action = '';
75 $socid = $user->socid;
76}
77
78// Maximum elements of the tables
79$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
80$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
81$maxLatestEditCount = 5;
82$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
83
84// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
85$hookmanager->initHooks(array('invoiceindex'));
86
87
88$maxofloop = getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500);
89
90
91/*
92 * Actions
93 */
94
95// None
96
97
98/*
99 * View
100 */
101
102$now = dol_now();
103
104$form = new Form($db);
105$formfile = new FormFile($db);
106$thirdpartystatic = new Societe($db);
107
108llxHeader("", $langs->trans("InvoicesArea"));
109
110print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
111
112
113print '<div class="fichecenter">';
114
115print '<div class="twocolumns">';
116
117print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
118
119
120if (isModEnabled('invoice')) {
121 print getNumberInvoicesPieChart('customers');
122 print '<br>';
123}
124
125if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
126 print getNumberInvoicesPieChart('suppliers');
127 print '<br>';
128}
129
130if (isModEnabled('invoice')) {
131 print getCustomerInvoiceDraftTable($max, $socid);
132 print '<br>';
133}
134
135if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
136 print getDraftSupplierTable($max, $socid);
137 print '<br>';
138}
139
140
141print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
142
143
144// Latest modified customer invoices
145if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
146 $langs->load("boxes");
147 $tmpinvoice = new Facture($db);
148
149 $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms";
150 $sql .= ", f.date_lim_reglement as datelimite";
151 $sql .= ", s.nom as name";
152 $sql .= ", s.rowid as socid";
153 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.email";
154 $sql .= ", cc.rowid as country_id, cc.code as country_code";
155 $sql .= ", (SELECT SUM(pf.amount) FROM ".$db->prefix()."paiement_facture as pf WHERE pf.fk_facture = f.rowid) as am";
156 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
157 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
158 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
159 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
160 if ($socid > 0) {
161 $sql .= " AND f.fk_soc = ".((int) $socid);
162 }
163 // Filter on sale representative
164 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
165 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $user->id).")";
166 }
167 // Add where from hooks
168 $parameters = array();
169 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
170 $sql .= $hookmanager->resPrint;
171
172 $sql .= " ORDER BY f.tms DESC";
173 $sql .= $db->plimit($max, 0);
174
175 $resql = $db->query($sql);
176 if ($resql) {
177 $num = $db->num_rows($resql);
178 $i = 0;
179 $othernb = 0;
180
181 print '<div class="div-table-responsive-no-min">';
182 print '<table class="noborder centpercent">';
183
184 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max);
185 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
186 print '</th>';
187 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
188 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
189 }
190 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
191 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
192 print '<th width="16">&nbsp;</th>';
193 print '</tr>';
194 if ($num) {
195 $total_ttc = $totalam = $total_ht = 0;
196 while ($i < $num && $i < $conf->liste_limit) {
197 $obj = $db->fetch_object($resql);
198
199 if ($i >= $max) {
200 $othernb += 1;
201 $i++;
202 $total_ht += $obj->total_ht;
203 $total_ttc += $obj->total_ttc;
204 continue;
205 }
206
207 $tmpinvoice->ref = $obj->ref;
208 $tmpinvoice->id = $obj->rowid;
209 $tmpinvoice->total_ht = $obj->total_ht;
210 $tmpinvoice->total_tva = $obj->total_tva;
211 $tmpinvoice->total_ttc = $obj->total_ttc;
212 $tmpinvoice->statut = $obj->status; // deprecated
213 $tmpinvoice->status = $obj->status;
214 $tmpinvoice->paye = $obj->paye; // deprecated
215 $tmpinvoice->paid = $obj->paye;
216 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
217 $tmpinvoice->type = $obj->type;
218
219 $thirdpartystatic->id = $obj->socid;
220 $thirdpartystatic->name = $obj->name;
221 $thirdpartystatic->email = $obj->email;
222 $thirdpartystatic->country_id = $obj->country_id;
223 $thirdpartystatic->country_code = $obj->country_code;
224 $thirdpartystatic->email = $obj->email;
225 $thirdpartystatic->client = 1;
226 $thirdpartystatic->code_client = $obj->code_client;
227 //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
228 $thirdpartystatic->code_compta_client = $obj->code_compta_client;
229 //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
230
231 $totalallpayments = $tmpinvoice->getSommePaiement(0);
232 $totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
233 $totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
234 print '<tr class="oddeven">';
235 print '<td class="nowrap">';
236
237 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
238
239 print '<td class="nobordernopadding nowraponall">';
240 print $tmpinvoice->getNomUrl(1, '');
241 print '</td>';
242 if ($tmpinvoice->hasDelay()) {
243 print '<td width="20" class="nobordernopadding nowrap">';
244 print img_warning($langs->trans("Late"));
245 print '</td>';
246 }
247 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
248 $filename = dol_sanitizeFileName($obj->ref);
249 $filedir = $conf->invoice->dir_output.'/'.dol_sanitizeFileName($obj->ref);
250 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
251 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
252 print '</td></tr></table>';
253
254 print '</td>';
255
256 print '<td class="tdoverflowmax150">';
257 print $thirdpartystatic->getNomUrl(1, 'customer', 44);
258 print '</td>';
259 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
260 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
261 }
262 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
263
264 print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
265
266 print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
267
268 print '</tr>';
269
270 $total_ttc += $obj->total_ttc;
271 $total_ht += $obj->total_ht;
272 $totalam += $obj->am;
273
274 $i++;
275 }
276
277 if ($othernb) {
278 print '<tr class="oddeven">';
279 print '<td class="nowrap" colspan="5">';
280 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
281 print '</td>';
282 print "</tr>\n";
283 }
284 } else {
285 $colspan = 5;
286 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
287 $colspan++;
288 }
289 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
290 }
291 print '</table></div><br>';
292 $db->free($resql);
293 } else {
294 dol_print_error($db);
295 }
296}
297
298
299// Last modified supplier invoices
300if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
301 $langs->load("boxes");
302 $facstatic = new FactureFournisseur($db);
303
304 $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier";
305 $sql .= ", s.nom as name";
306 $sql .= ", s.rowid as socid";
307 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
308 $sql .= ", (SELECT SUM(pf.amount) FROM ".$db->prefix()."paiementfourn_facturefourn as pf WHERE pf.fk_facturefourn = ff.rowid) as am";
309 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
310 $sql .= " WHERE s.rowid = ff.fk_soc";
311 $sql .= " AND ff.entity IN (".getEntity('facture_fourn').")";
312 if ($socid > 0) {
313 $sql .= " AND ff.fk_soc = ".((int) $socid);
314 }
315 // Filter on sale representative
316 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
317 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = ff.fk_soc AND sc.fk_user = ".((int) $user->id).")";
318 }
319 // Add where from hooks
320 $parameters = array();
321 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
322 $sql .= $hookmanager->resPrint;
323
324 $sql .= " ORDER BY ff.tms DESC";
325 $sql .= $db->plimit($max, 0);
326
327 $resql = $db->query($sql);
328 if ($resql) {
329 $num = $db->num_rows($resql);
330
331 print '<div class="div-table-responsive-no-min">';
332 print '<table class="noborder centpercent">';
333 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max);
334 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
335 print '</th>';
336 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
337 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
338 }
339 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
340 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
341 print '<th width="16">&nbsp;</th>';
342 print "</tr>\n";
343 if ($num) {
344 $i = 0;
345 $total_ht = $total_ttc = $totalam = 0;
346 $othernb = 0;
347
348 while ($i < $num) {
349 $obj = $db->fetch_object($resql);
350
351 if ($i >= $max) {
352 $othernb += 1;
353 $i++;
354 $total_ht += $obj->total_ht;
355 $total_ttc += $obj->total_ttc;
356 continue;
357 }
358
359 $facstatic->ref = $obj->ref;
360 $facstatic->id = $obj->rowid;
361 $facstatic->total_ht = $obj->total_ht;
362 $facstatic->total_tva = $obj->total_tva;
363 $facstatic->total_ttc = $obj->total_ttc;
364 $facstatic->statut = $obj->status; // deprecated
365 $facstatic->status = $obj->status;
366 $facstatic->paye = $obj->paye; // deprecated
367 $facstatic->paid = $obj->paye;
368 $facstatic->type = $obj->type;
369 $facstatic->ref_supplier = $obj->ref_supplier;
370
371 $thirdpartystatic->id = $obj->socid;
372 $thirdpartystatic->name = $obj->name;
373 $thirdpartystatic->email = $obj->email;
374 $thirdpartystatic->country_id = 0;
375 $thirdpartystatic->country_code = '';
376 $thirdpartystatic->client = 0;
377 $thirdpartystatic->fournisseur = 1;
378 $thirdpartystatic->code_client = '';
379 $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
380 $thirdpartystatic->code_compta_client = '';
381 $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
382
383 print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
384 print $facstatic->getNomUrl(1, '');
385 print '</td>';
386 print '<td class="nowrap tdoverflowmax100">';
387 print $thirdpartystatic->getNomUrl(1, 'supplier');
388 print '</td>';
389 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
390 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
391 }
392 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
393 print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->tms), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->tms), 'day', 'tzuserrel').'</td>';
394
395 $alreadypaid = $facstatic->getSommePaiement();
396 $alreadypaid += $facstatic->getSumCreditNotesUsed();
397 $alreadypaid += $facstatic->getSumDepositsUsed();
398
399 print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
400 print '</tr>';
401
402 $total_ht += $obj->total_ht;
403 $total_ttc += $obj->total_ttc;
404 $totalam += $obj->am;
405 $i++;
406 }
407
408 if ($othernb) {
409 print '<tr class="oddeven">';
410 print '<td class="nowrap" colspan="5">';
411 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
412 print '</td>';
413 print "</tr>\n";
414 }
415 } else {
416 $colspan = 5;
417 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
418 $colspan++;
419 }
420 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
421 }
422 print '</table></div><br>';
423 } else {
424 dol_print_error($db);
425 }
426}
427
428
429
430// Last donations
431if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
432 include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
433
434 $langs->load("boxes");
435 $donationstatic = new Don($db);
436
437 $sql = "SELECT d.rowid, d.lastname, d.firstname, d.societe, d.datedon as date, d.tms as dm, d.amount, d.fk_statut as status, d.fk_soc as socid";
438 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
439 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
440 // Add where from hooks
441 $parameters = array();
442 $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
443 $sql .= $hookmanager->resPrint;
444
445 $sql .= $db->order("d.tms", "DESC");
446 $sql .= $db->plimit($max, 0);
447
448 $result = $db->query($sql);
449 if ($result) {
450 $num = $db->num_rows($result);
451
452 $i = 0;
453 $othernb = 0;
454
455 print '<div class="div-table-responsive-no-min">';
456 print '<table class="noborder centpercent">';
457 print '<tr class="liste_titre">';
458 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedDonations", $max);
459 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
460 print '</th>';
461 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
462 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
463 print '<th width="16">&nbsp;</th>';
464 print '</tr>';
465
466 if ($num) {
467 $total_ttc = $totalam = $total_ht = 0;
468
469 while ($i < $num && $i < $max) {
470 $obj = $db->fetch_object($result);
471
472 if ($i >= $max) {
473 $othernb += 1;
474 $i++;
475 $total_ht += $obj->total_ht;
476 $total_ttc += $obj->total_ttc;
477 continue;
478 }
479
480 $donationstatic->id = $obj->rowid;
481 $donationstatic->ref = $obj->rowid;
482 $donationstatic->lastname = $obj->lastname;
483 $donationstatic->firstname = $obj->firstname;
484 $donationstatic->date = $db->jdate($obj->date);
485 $donationstatic->status = $obj->status;
486
487 $label = '';
488 if (!empty($obj->socid)) {
489 $companystatic = new Societe($db);
490 $ret = $companystatic->fetch($obj->socid);
491 if ($ret > 0) {
492 $label = $companystatic->getNomUrl(1);
493 }
494 } else {
495 $label = $donationstatic->getFullName($langs);
496 if ($obj->societe) {
497 $label .= ($label ? ' - ' : '').$obj->societe;
498 }
499 }
500
501 print '<tr class="oddeven tdoverflowmax100">';
502 print '<td>'.$donationstatic->getNomUrl(1).'</td>';
503 print '<td>'.$label.'</td>';
504 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
505 print '<td class="right" title="'.dol_escape_htmltag($langs->trans("DateModificationShort").' : '.dol_print_date($db->jdate($obj->dm), 'dayhour', 'tzuserrel')).'">'.dol_print_date($db->jdate($obj->dm), 'day', 'tzuserrel').'</td>';
506 print '<td>'.$donationstatic->getLibStatut(3).'</td>';
507 print '</tr>';
508
509 $i++;
510 }
511
512 if ($othernb) {
513 print '<tr class="oddeven">';
514 print '<td class="nowrap" colspan="5">';
515 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
516 print '</td>';
517 print "</tr>\n";
518 }
519 } else {
520 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
521 }
522 print '</table></div><br>';
523 } else {
524 dol_print_error($db);
525 }
526}
527
531if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
532 if (!$socid) {
533 $chargestatic = new ChargeSociales($db);
534
535 $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
536 $sql .= " cc.libelle as label,";
537 $sql .= " SUM(pc.amount) as totalpaid";
538 $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
539 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
540 $sql .= " WHERE c.fk_type = cc.id";
541 $sql .= " AND c.entity IN (".getEntity('tax').')';
542 $sql .= " AND c.paye = 0";
543 // Add where from hooks
544 $parameters = array();
545 $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
546 $sql .= $hookmanager->resPrint;
547
548 $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
549
550 $resql = $db->query($sql);
551 if ($resql) {
552 $num = $db->num_rows($resql);
553
554 print '<div class="div-table-responsive-no-min">';
555 print '<table class="noborder centpercent">';
556 print '<tr class="liste_titre">';
557 print '<th>'.$langs->trans("ContributionsToPay").($num ? '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge marginleftonly">'.$num.'</span></a>' : '').'</th>';
558 print '<th align="center">'.$langs->trans("DateDue").'</th>';
559 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
560 print '<th class="right">'.$langs->trans("Paid").'</th>';
561 print '<th align="center" width="16">&nbsp;</th>';
562 print '</tr>';
563 if ($num) {
564 $i = 0;
565 $tot_ttc = 0;
566 $tot_paid = 0;
567 $othernb = 0;
568
569 while ($i < $num) {
570 $obj = $db->fetch_object($resql);
571
572 if ($i >= $max) {
573 $othernb += 1;
574 $tot_ttc += $obj->amount;
575 $tot_paid += $obj->totalpaid;
576 $i++;
577 continue;
578 }
579
580 $chargestatic->id = $obj->rowid;
581 $chargestatic->ref = $obj->rowid;
582 $chargestatic->label = $obj->label;
583 $chargestatic->paye = $obj->paye;
584 $chargestatic->status = $obj->paye;
585
586 print '<tr class="oddeven">';
587 print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
588 print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
589 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
590 print '<td class="nowrap right"><span class="amount">'.price($obj->totalpaid).'</span></td>';
591 print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
592 print '</tr>';
593
594 $tot_ttc += $obj->amount;
595 $i++;
596 }
597
598 if ($othernb) {
599 print '<tr class="oddeven">';
600 print '<td class="nowrap" colspan="5">';
601 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
602 print '</td>';
603 print "</tr>\n";
604 }
605
606 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
607 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
608 print '<td class="nowrap right">'.price($tot_paid).'</td>';
609 print '<td class="right">&nbsp;</td>';
610 print '</tr>';
611 } else {
612 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
613 }
614 print "</table></div><br>";
615 $db->free($resql);
616 } else {
617 dol_print_error($db);
618 }
619 }
620}
621
622/*
623 * Customers orders to be billed
624 */
625if (isModEnabled('invoice') && isModEnabled('order') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
626 $commandestatic = new Commande($db);
627 $langs->load("orders");
628
629 $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
630 $sql .= ", s.nom as name, s.email";
631 $sql .= ", s.rowid as socid";
632 $sql .= ", s.code_client, s.code_compta as code_compta_client";
633 $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
634 $sql .= " cc.rowid as country_id, cc.code as country_code";
635 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
636 $sql .= ", ".MAIN_DB_PREFIX."commande as c";
637 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
638 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
639 $sql .= " WHERE c.fk_soc = s.rowid";
640 $sql .= " AND c.entity IN (".getEntity('commande').")";
641 if ($socid) {
642 $sql .= " AND c.fk_soc = ".((int) $socid);
643 }
644 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_CLOSED);
645 $sql .= " AND c.facture = 0";
646 // Filter on sale representative
647 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
648 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
649 }
650
651 // Add where from hooks
652 $parameters = array();
653 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
654 $sql .= $hookmanager->resPrint;
655
656 $sql .= " GROUP BY s.nom, s.email, s.rowid, s.code_client, s.code_compta, c.rowid, c.ref, c.facture, c.fk_statut, c.total_ht, c.total_tva, c.total_ttc, cc.rowid, cc.code";
657
658 $resql = $db->query($sql);
659 if ($resql) {
660 $num = $db->num_rows($resql);
661
662 if ($num) {
663 $i = 0;
664 $othernb = 0;
665
666 print '<div class="div-table-responsive-no-min">';
667 print '<table class="noborder centpercent">';
668
669 print '<tr class="liste_titre">';
670 print '<th colspan="2">';
671 print $langs->trans("OrdersDeliveredToBill");
672 print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&search_billed=0">';
673 print '<span class="badge marginleftonly">'.$num.'</span>';
674 print '</a>';
675 print '</th>';
676
677 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
678 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
679 }
680 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
681 print '<th class="right">'.$langs->trans("ToBill").'</th>';
682 print '<th align="center" width="16">&nbsp;</th>';
683 print '</tr>';
684
685 $tot_ht = $tot_ttc = $tot_tobill = 0;
686 $societestatic = new Societe($db);
687 while ($i < $num) {
688 $obj = $db->fetch_object($resql);
689
690 if ($i >= $max) {
691 $othernb += 1;
692 $i++;
693 $total_ht += $obj->total_ht;
694 $total_ttc += $obj->total_ttc;
695 continue;
696 }
697
698 $societestatic->id = $obj->socid;
699 $societestatic->name = $obj->name;
700 $societestatic->email = $obj->email;
701 $societestatic->country_id = $obj->country_id;
702 $societestatic->country_code = $obj->country_code;
703 $societestatic->client = 1;
704 $societestatic->code_client = $obj->code_client;
705 //$societestatic->code_fournisseur = $obj->code_fournisseur;
706 $societestatic->code_compta_client = $obj->code_compta_client;
707 //$societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
708
709 $commandestatic->id = $obj->rowid;
710 $commandestatic->ref = $obj->ref;
711 $commandestatic->statut = $obj->status; // deprecated
712 $commandestatic->status = $obj->status;
713 $commandestatic->billed = $obj->facture;
714
715 print '<tr class="oddeven">';
716 print '<td class="nowrap">';
717
718 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
719 print '<td class="nobordernopadding nowrap">';
720 print $commandestatic->getNomUrl(1);
721 print '</td>';
722 print '<td width="20" class="nobordernopadding nowrap">';
723 print '&nbsp;';
724 print '</td>';
725 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
726 $filename = dol_sanitizeFileName($obj->ref);
727 $filedir = $conf->order->dir_output.'/'.dol_sanitizeFileName($obj->ref);
728 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
729 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
730 print '</td></tr></table>';
731
732 print '</td>';
733
734 print '<td class="nowrap tdoverflowmax100">';
735 print $societestatic->getNomUrl(1, 'customer');
736 print '</td>';
737 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
738 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
739 }
740 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
741 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
742 print '<td>'.$commandestatic->getLibStatut(3).'</td>';
743 print '</tr>';
744 $tot_ht += $obj->total_ht;
745 $tot_ttc += $obj->total_ttc;
746 //print "x".$tot_ttc."z".$obj->tot_fttc;
747 $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
748 $i++;
749 }
750
751 if ($othernb) {
752 print '<tr class="oddeven">';
753 print '<td class="nowrap" colspan="5">';
754 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
755 print '</td>';
756 print "</tr>\n";
757 }
758
759 print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <span style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</span> </td>';
760 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
761 print '<td class="right">'.price($tot_ht).'</td>';
762 }
763 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
764 print '<td class="nowrap right">'.price($tot_tobill).'</td>';
765 print '<td>&nbsp;</td>';
766 print '</tr>';
767 print '</table></div><br>';
768 }
769 $db->free($resql);
770 } else {
771 dol_print_error($db);
772 }
773}
774
775
776// TODO Mettre ici recup des actions en rapport avec la compta
777$sql = '';
778if ($sql) {
779 $langs->load("projects");
780 print '<div class="div-table-responsive-no-min">';
781 print '<table class="noborder centpercent">';
782 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("TasksToDo").'</th>';
783 print "</tr>\n";
784 $i = 0;
785 $resql = $db->query($sql);
786 if ($resql) {
787 $num_rows = $db->num_rows($resql);
788 while ($i < $num_rows) {
789 $obj = $db->fetch_object($resql);
790
791 print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
792 print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
793 $i++;
794 }
795 $db->free($resql);
796 }
797 print "</table></div><br>";
798}
799
800
801print '</div></div></div>';
802
803$parameters = array('user' => $user);
804$object = null;
805$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
806
807// End of page
808llxFooter();
809$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class for managing the social charges.
Class to manage customers orders.
const STATUS_CLOSED
Closed (Sent, billed or not)
Class to manage donations.
Definition don.class.php:41
Class to manage suppliers invoices.
Class to manage invoices.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_now($mode='gmt')
Return date for now.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices.
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.