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