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