dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
13 * Copyright (C) 2024 Rafael San José <rsanjose@alxarafe.com>
14 * Copyright (C) 2024-2026 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';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
49require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
50require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
51require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
52require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
53require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
54require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
56
57// The Accounting/Treasury workspace must remain enabled as it serves as a shared hub
58// for various modules (banking, invoicing, etc.), irrespective of accounting usage.
59// Individual sub-functions are secured by their respective module permissions.
60
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 = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
80
81$maxLatestEditCount = 5;
82$maxDraftCount = getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500);
83$maxOpenCount = getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500);
84$maxofloop = getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500);
85
86// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
87$hookmanager->initHooks(array('invoiceindex'));
88
89
90
91/*
92 * Actions
93 */
94
95// Add box (when submit is done from a form when ajax disabled)
96include DOL_DOCUMENT_ROOT.'/core/actions_addbox.inc.php';
97
98
99/*
100 * View
101 */
102
103$now = dol_now();
104
105$form = new Form($db);
106$formfile = new FormFile($db);
107$thirdpartystatic = new Societe($db);
108
109// Load $resultboxes
110$resultboxes = FormOther::getBoxesArea($user, "9");
111
112llxHeader("", $langs->trans("InvoicesArea"));
113
114print load_fiche_titre($langs->trans("InvoicesArea"), $resultboxes['selectboxlist'], 'bill');
115
116
117print '<div class="fichecenter">';
118
119print '<div class="twocolumns">';
120
121print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
122
123
124if (isModEnabled('invoice')) {
125 print getNumberInvoicesPieChart('customers');
126 print '<br>';
127}
128
129if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
130 print getNumberInvoicesPieChart('suppliers');
131 print '<br>';
132}
133
134if (isModEnabled('invoice')) {
135 print getCustomerInvoiceDraftTable($max, $socid);
136 print '<br>';
137}
138
139if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
140 print getDraftSupplierTable($max, $socid);
141 print '<br>';
142}
143
144
145print $resultboxes['boxlista'];
146
147print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
148
149
150// Latest modified customer invoices
151if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
152 $langs->load("boxes");
153 $tmpinvoice = new Facture($db);
154
155 $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";
156 $sql .= ", f.date_lim_reglement as datelimite";
157 $sql .= ", s.nom as name";
158 $sql .= ", s.rowid as socid";
159 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.email";
160 $sql .= ", cc.rowid as country_id, cc.code as country_code";
161 $sql .= ", (SELECT SUM(pf.amount) FROM ".$db->prefix()."paiement_facture as pf WHERE pf.fk_facture = f.rowid) as am";
162 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
163 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
164 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
165 $sql .= " WHERE f.entity IN (".getEntity('invoice').")";
166 if ($socid > 0) {
167 $sql .= " AND f.fk_soc = ".((int) $socid);
168 }
169 // Filter on sale representative
170 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
171 $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).")";
172 }
173 // Add where from hooks
174 $parameters = array();
175 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
176 $sql .= $hookmanager->resPrint;
177
178 $sql .= " ORDER BY f.tms DESC";
179 $sql .= $db->plimit($max, 0);
180
181 $resql = $db->query($sql);
182 if ($resql) {
183 $num = $db->num_rows($resql);
184 $i = 0;
185 $othernb = 0;
186
187 print '<div class="div-table-responsive-no-min">';
188 print '<table class="noborder centpercent">';
189
190 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max);
191 print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
192 print '</th>';
193 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
194 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
195 }
196 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
197 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
198 print '<th width="16">&nbsp;</th>';
199 print '</tr>';
200 if ($num) {
201 $total_ttc = $totalam = $total_ht = 0;
202 while ($i < $num && $i < $conf->liste_limit) {
203 $obj = $db->fetch_object($resql);
204
205 if ($i >= $max) {
206 $othernb += 1;
207 $i++;
208 $total_ht += $obj->total_ht;
209 $total_ttc += $obj->total_ttc;
210 continue;
211 }
212
213 $tmpinvoice->ref = $obj->ref;
214 $tmpinvoice->id = $obj->rowid;
215 $tmpinvoice->total_ht = $obj->total_ht;
216 $tmpinvoice->total_tva = $obj->total_tva;
217 $tmpinvoice->total_ttc = $obj->total_ttc;
218 $tmpinvoice->statut = $obj->status; // deprecated
219 $tmpinvoice->status = $obj->status;
220 $tmpinvoice->paye = $obj->paye; // deprecated
221 $tmpinvoice->paid = $obj->paye;
222 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
223 $tmpinvoice->type = $obj->type;
224
225 $thirdpartystatic->id = $obj->socid;
226 $thirdpartystatic->name = $obj->name;
227 $thirdpartystatic->email = $obj->email;
228 $thirdpartystatic->country_id = $obj->country_id;
229 $thirdpartystatic->country_code = $obj->country_code;
230 $thirdpartystatic->email = $obj->email;
231 $thirdpartystatic->client = 1;
232 $thirdpartystatic->code_client = $obj->code_client;
233 //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
234 $thirdpartystatic->code_compta_client = $obj->code_compta_client;
235 //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
236
237 $totalallpayments = $tmpinvoice->getSommePaiement(0);
238 $totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
239 $totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
240 print '<tr class="oddeven">';
241 print '<td class="nowrap">';
242
243 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
244
245 print '<td class="nobordernopadding nowraponall">';
246 print $tmpinvoice->getNomUrl(1, '');
247 print '</td>';
248 if ($tmpinvoice->hasDelay()) {
249 print '<td width="20" class="nobordernopadding nowrap">';
250 print img_warning($langs->trans("Late"));
251 print '</td>';
252 }
253 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
254 $filename = dol_sanitizeFileName($obj->ref);
255 $filedir = $conf->invoice->dir_output.'/'.dol_sanitizeFileName($obj->ref);
256 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
257 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
258 print '</td></tr></table>';
259
260 print '</td>';
261
262 print '<td class="tdoverflowmax150">';
263 print $thirdpartystatic->getNomUrl(1, 'customer', 44);
264 print '</td>';
265 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
266 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
267 }
268 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
269
270 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>';
271
272 print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
273
274 print '</tr>';
275
276 $total_ttc += $obj->total_ttc;
277 $total_ht += $obj->total_ht;
278 $totalam += $obj->am;
279
280 $i++;
281 }
282
283 if ($othernb) {
284 print '<tr class="oddeven">';
285 print '<td class="nowrap" colspan="5">';
286 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
287 print '</td>';
288 print "</tr>\n";
289 }
290 } else {
291 $colspan = 5;
292 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
293 $colspan++;
294 }
295 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
296 }
297 print '</table></div><br>';
298 $db->free($resql);
299 } else {
300 dol_print_error($db);
301 }
302}
303
304
305// Last modified supplier invoices
306if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
307 $langs->load("boxes");
308 $facstatic = new FactureFournisseur($db);
309
310 $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";
311 $sql .= ", s.nom as name";
312 $sql .= ", s.rowid as socid";
313 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
314 $sql .= ", (SELECT SUM(pf.amount) FROM ".$db->prefix()."paiementfourn_facturefourn as pf WHERE pf.fk_facturefourn = ff.rowid) as am";
315 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
316 $sql .= " WHERE s.rowid = ff.fk_soc";
317 $sql .= " AND ff.entity IN (".getEntity('facture_fourn').")";
318 if ($socid > 0) {
319 $sql .= " AND ff.fk_soc = ".((int) $socid);
320 }
321 // Filter on sale representative
322 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
323 $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).")";
324 }
325 // Add where from hooks
326 $parameters = array();
327 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
328 $sql .= $hookmanager->resPrint;
329
330 $sql .= " ORDER BY ff.tms DESC";
331 $sql .= $db->plimit($max, 0);
332
333 $resql = $db->query($sql);
334 if ($resql) {
335 $num = $db->num_rows($resql);
336
337 print '<div class="div-table-responsive-no-min">';
338 print '<table class="noborder centpercent">';
339 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max);
340 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
341 print '</th>';
342 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
343 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
344 }
345 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
346 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
347 print '<th width="16">&nbsp;</th>';
348 print "</tr>\n";
349 if ($num) {
350 $i = 0;
351 $total_ht = $total_ttc = $totalam = 0;
352 $othernb = 0;
353
354 while ($i < $num) {
355 $obj = $db->fetch_object($resql);
356
357 if ($i >= $max) {
358 $othernb += 1;
359 $i++;
360 $total_ht += $obj->total_ht;
361 $total_ttc += $obj->total_ttc;
362 continue;
363 }
364
365 $facstatic->ref = $obj->ref;
366 $facstatic->id = $obj->rowid;
367 $facstatic->total_ht = $obj->total_ht;
368 $facstatic->total_tva = $obj->total_tva;
369 $facstatic->total_ttc = $obj->total_ttc;
370 $facstatic->statut = $obj->status; // deprecated
371 $facstatic->status = $obj->status;
372 $facstatic->paye = $obj->paye; // deprecated
373 $facstatic->paid = $obj->paye;
374 $facstatic->type = $obj->type;
375 $facstatic->ref_supplier = $obj->ref_supplier;
376
377 $thirdpartystatic->id = $obj->socid;
378 $thirdpartystatic->name = $obj->name;
379 $thirdpartystatic->email = $obj->email;
380 $thirdpartystatic->country_id = 0;
381 $thirdpartystatic->country_code = '';
382 $thirdpartystatic->client = 0;
383 $thirdpartystatic->fournisseur = 1;
384 $thirdpartystatic->code_client = '';
385 $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
386 $thirdpartystatic->code_compta_client = '';
387 $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
388
389 print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
390 print $facstatic->getNomUrl(1, '');
391 print '</td>';
392 print '<td class="nowrap tdoverflowmax100">';
393 print $thirdpartystatic->getNomUrl(1, 'supplier');
394 print '</td>';
395 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
396 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
397 }
398 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
399 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>';
400
401 $alreadypaid = $facstatic->getSommePaiement();
402 $alreadypaid += $facstatic->getSumCreditNotesUsed();
403 $alreadypaid += $facstatic->getSumDepositsUsed();
404
405 print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
406 print '</tr>';
407
408 $total_ht += $obj->total_ht;
409 $total_ttc += $obj->total_ttc;
410 $totalam += $obj->am;
411 $i++;
412 }
413
414 if ($othernb) {
415 print '<tr class="oddeven">';
416 print '<td class="nowrap" colspan="5">';
417 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
418 print '</td>';
419 print "</tr>\n";
420 }
421 } else {
422 $colspan = 5;
423 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
424 $colspan++;
425 }
426 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
427 }
428 print '</table></div><br>';
429 } else {
430 dol_print_error($db);
431 }
432}
433
434
435
436// Last donations
437if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
438 include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
439
440 $langs->load("boxes");
441 $donationstatic = new Don($db);
442
443 $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";
444 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
445 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
446 // Add where from hooks
447 $parameters = array();
448 $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
449 $sql .= $hookmanager->resPrint;
450
451 $sql .= $db->order("d.tms", "DESC");
452 $sql .= $db->plimit($max, 0);
453
454 $result = $db->query($sql);
455 if ($result) {
456 $num = $db->num_rows($result);
457
458 $i = 0;
459 $othernb = 0;
460
461 print '<div class="div-table-responsive-no-min">';
462 print '<table class="noborder centpercent">';
463 print '<tr class="liste_titre">';
464 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedDonations", $max);
465 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=d.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
466 print '</th>';
467 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
468 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
469 print '<th width="16">&nbsp;</th>';
470 print '</tr>';
471
472 if ($num) {
473 $total_ttc = $totalam = $total_ht = 0;
474
475 while ($i < $num && $i < $max) {
476 $obj = $db->fetch_object($result);
477
478 if ($i >= $max) {
479 $othernb += 1;
480 $i++;
481 $total_ht += $obj->total_ht;
482 $total_ttc += $obj->total_ttc;
483 continue;
484 }
485
486 $donationstatic->id = $obj->rowid;
487 $donationstatic->ref = $obj->rowid;
488 $donationstatic->lastname = $obj->lastname;
489 $donationstatic->firstname = $obj->firstname;
490 $donationstatic->date = $db->jdate($obj->date);
491 $donationstatic->status = $obj->status;
492
493 $label = '';
494 if (!empty($obj->socid)) {
495 $companystatic = new Societe($db);
496 $ret = $companystatic->fetch($obj->socid);
497 if ($ret > 0) {
498 $label = $companystatic->getNomUrl(1);
499 }
500 } else {
501 $label = $donationstatic->getFullName($langs);
502 if ($obj->societe) {
503 $label .= ($label ? ' - ' : '').$obj->societe;
504 }
505 }
506
507 print '<tr class="oddeven tdoverflowmax100">';
508 print '<td>'.$donationstatic->getNomUrl(1).'</td>';
509 print '<td>'.$label.'</td>';
510 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
511 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>';
512 print '<td>'.$donationstatic->getLibStatut(3).'</td>';
513 print '</tr>';
514
515 $i++;
516 }
517
518 if ($othernb) {
519 print '<tr class="oddeven">';
520 print '<td class="nowrap" colspan="5">';
521 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
522 print '</td>';
523 print "</tr>\n";
524 }
525 } else {
526 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
527 }
528 print '</table></div><br>';
529 } else {
530 dol_print_error($db);
531 }
532}
533
537if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
538 if (!$socid) {
539 $chargestatic = new ChargeSociales($db);
540
541 $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
542 $sql .= " cc.libelle as label,";
543 $sql .= " SUM(pc.amount) as totalpaid";
544 $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
545 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
546 $sql .= " WHERE c.fk_type = cc.id";
547 $sql .= " AND c.entity IN (".getEntity('tax').')';
548 $sql .= " AND c.paye = 0";
549 // Add where from hooks
550 $parameters = array();
551 $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
552 $sql .= $hookmanager->resPrint;
553
554 $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
555
556 $resql = $db->query($sql);
557 if ($resql) {
558 $num = $db->num_rows($resql);
559
560 print '<div class="div-table-responsive-no-min">';
561 print '<table class="noborder centpercent">';
562 print '<tr class="liste_titre">';
563 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>';
564 print '<th align="center">'.$langs->trans("DateDue").'</th>';
565 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
566 print '<th class="right">'.$langs->trans("Paid").'</th>';
567 print '<th align="center" width="16">&nbsp;</th>';
568 print '</tr>';
569 if ($num) {
570 $i = 0;
571 $tot_ttc = 0;
572 $tot_paid = 0;
573 $othernb = 0;
574
575 while ($i < $num) {
576 $obj = $db->fetch_object($resql);
577
578 if ($i >= $max) {
579 $othernb += 1;
580 $tot_ttc += $obj->amount;
581 $tot_paid += $obj->totalpaid;
582 $i++;
583 continue;
584 }
585
586 $chargestatic->id = $obj->rowid;
587 $chargestatic->ref = $obj->rowid;
588 $chargestatic->label = $obj->label;
589 $chargestatic->paye = $obj->paye;
590 $chargestatic->status = $obj->paye;
591
592 print '<tr class="oddeven">';
593 print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
594 print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
595 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
596 print '<td class="nowrap right"><span class="amount">'.price($obj->totalpaid).'</span></td>';
597 print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
598 print '</tr>';
599
600 $tot_ttc += $obj->amount;
601 $i++;
602 }
603
604 if ($othernb) {
605 print '<tr class="oddeven">';
606 print '<td class="nowrap" colspan="5">';
607 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
608 print '</td>';
609 print "</tr>\n";
610 }
611
612 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
613 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
614 print '<td class="nowrap right">'.price($tot_paid).'</td>';
615 print '<td class="right">&nbsp;</td>';
616 print '</tr>';
617 } else {
618 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
619 }
620 print "</table></div><br>";
621 $db->free($resql);
622 } else {
623 dol_print_error($db);
624 }
625 }
626}
627
628/*
629 * Customers orders to be billed
630 */
631if (isModEnabled('invoice') && isModEnabled('order') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
632 $commandestatic = new Commande($db);
633 $langs->load("orders");
634
635 $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
636 $sql .= ", s.nom as name, s.email";
637 $sql .= ", s.rowid as socid";
638 $sql .= ", s.code_client, s.code_compta as code_compta_client";
639 $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
640 $sql .= " cc.rowid as country_id, cc.code as country_code";
641 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
642 $sql .= ", ".MAIN_DB_PREFIX."commande as c";
643 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
644 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
645 $sql .= " WHERE c.fk_soc = s.rowid";
646 $sql .= " AND c.entity IN (".getEntity('commande').")";
647 if ($socid) {
648 $sql .= " AND c.fk_soc = ".((int) $socid);
649 }
650 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_CLOSED);
651 $sql .= " AND c.facture = 0";
652 // Filter on sale representative
653 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
654 $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).")";
655 }
656
657 // Add where from hooks
658 $parameters = array();
659 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
660 $sql .= $hookmanager->resPrint;
661
662 $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";
663
664 $resql = $db->query($sql);
665 if ($resql) {
666 $num = $db->num_rows($resql);
667
668 if ($num) {
669 $i = 0;
670 $othernb = 0;
671
672 print '<div class="div-table-responsive-no-min">';
673 print '<table class="noborder centpercent">';
674
675 print '<tr class="liste_titre">';
676 print '<th colspan="2">';
677 print $langs->trans("OrdersDeliveredToBill");
678 print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&search_billed=0">';
679 print '<span class="badge marginleftonly">'.$num.'</span>';
680 print '</a>';
681 print '</th>';
682
683 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
684 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
685 }
686 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
687 print '<th class="right">'.$langs->trans("ToBill").'</th>';
688 print '<th align="center" width="16">&nbsp;</th>';
689 print '</tr>';
690
691 $tot_ht = $tot_ttc = $tot_tobill = 0;
692 $total_ht = $total_ttc = 0;
693 $societestatic = new Societe($db);
694 while ($i < $num) {
695 $obj = $db->fetch_object($resql);
696
697 if ($i >= $max) {
698 $othernb += 1;
699 $i++;
700 $total_ht += $obj->total_ht;
701 $total_ttc += $obj->total_ttc;
702 continue;
703 }
704
705 $societestatic->id = $obj->socid;
706 $societestatic->name = $obj->name;
707 $societestatic->email = $obj->email;
708 $societestatic->country_id = $obj->country_id;
709 $societestatic->country_code = $obj->country_code;
710 $societestatic->client = 1;
711 $societestatic->code_client = $obj->code_client;
712 //$societestatic->code_fournisseur = $obj->code_fournisseur;
713 $societestatic->code_compta_client = $obj->code_compta_client;
714 //$societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
715
716 $commandestatic->id = $obj->rowid;
717 $commandestatic->ref = $obj->ref;
718 $commandestatic->statut = $obj->status; // deprecated
719 $commandestatic->status = $obj->status;
720 $commandestatic->billed = $obj->facture;
721
722 print '<tr class="oddeven">';
723 print '<td class="nowrap">';
724
725 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
726 print '<td class="nobordernopadding nowrap">';
727 print $commandestatic->getNomUrl(1);
728 print '</td>';
729 print '<td width="20" class="nobordernopadding nowrap">';
730 print '&nbsp;';
731 print '</td>';
732 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
733 $filename = dol_sanitizeFileName($obj->ref);
734 $filedir = $conf->order->dir_output.'/'.dol_sanitizeFileName($obj->ref);
735 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
736 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
737 print '</td></tr></table>';
738
739 print '</td>';
740
741 print '<td class="nowrap tdoverflowmax100">';
742 print $societestatic->getNomUrl(1, 'customer');
743 print '</td>';
744 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
745 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
746 }
747 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
748 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
749 print '<td>'.$commandestatic->getLibStatut(3).'</td>';
750 print '</tr>';
751 $tot_ht += $obj->total_ht;
752 $tot_ttc += $obj->total_ttc;
753 //print "x".$tot_ttc."z".$obj->tot_fttc;
754 $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
755 $i++;
756 }
757
758 if ($othernb) {
759 print '<tr class="oddeven">';
760 print '<td class="nowrap" colspan="5">';
761 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
762 print '</td>';
763 print "</tr>\n";
764 }
765
766 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>';
767 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
768 print '<td class="right">'.price($tot_ht).'</td>';
769 }
770 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
771 print '<td class="nowrap right">'.price($tot_tobill).'</td>';
772 print '<td>&nbsp;</td>';
773 print '</tr>';
774 print '</table></div><br>';
775 }
776 $db->free($resql);
777 } else {
778 dol_print_error($db);
779 }
780}
781
782
783// TODO Place accounting-related action retrieval here.
784$sql = '';
785if ($sql) {
786 $langs->load("projects");
787 print '<div class="div-table-responsive-no-min">';
788 print '<table class="noborder centpercent">';
789 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("TasksToDo").'</th>';
790 print "</tr>\n";
791 $i = 0;
792 $resql = $db->query($sql);
793 if ($resql) {
794 $num_rows = $db->num_rows($resql);
795 while ($i < $num_rows) {
796 $obj = $db->fetch_object($resql);
797
798 print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
799 print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
800 $i++;
801 }
802 $db->free($resql);
803 }
804 print "</table></div><br>";
805}
806
807
808print $resultboxes['boxlistb'];
809
810print '</div></div></div>';
811
812$parameters = array('user' => $user);
813$object = null;
814$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
815
816// End of page
817llxFooter();
818$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.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of us...
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.