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 $totalallpayments = $tmpinvoice->getSommePaiement(0);
223 $totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
224 $totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
225 print '<tr class="oddeven">';
226 print '<td class="nowrap">';
227
228 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
229
230 print '<td class="nobordernopadding nowraponall">';
231 print $tmpinvoice->getNomUrl(1, '');
232 print '</td>';
233 if ($tmpinvoice->hasDelay()) {
234 print '<td width="20" class="nobordernopadding nowrap">';
235 print img_warning($langs->trans("Late"));
236 print '</td>';
237 }
238 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
239 $filename = dol_sanitizeFileName($obj->ref);
240 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
241 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
242 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
243 print '</td></tr></table>';
244
245 print '</td>';
246
247 print '<td class="tdoverflowmax150">';
248 print $thirdpartystatic->getNomUrl(1, 'customer', 44);
249 print '</td>';
250 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
251 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
252 }
253 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
254
255 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>';
256
257 print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
258
259 print '</tr>';
260
261 $total_ttc += $obj->total_ttc;
262 $total_ht += $obj->total_ht;
263 $totalam += $obj->am;
264
265 $i++;
266 }
267
268 if ($othernb) {
269 print '<tr class="oddeven">';
270 print '<td class="nowrap" colspan="5">';
271 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
272 print '</td>';
273 print "</tr>\n";
274 }
275 } else {
276 $colspan = 5;
277 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
278 $colspan++;
279 }
280 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
281 }
282 print '</table></div><br>';
283 $db->free($resql);
284 } else {
285 dol_print_error($db);
286 }
287}
288
289
290// Last modified supplier invoices
291if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
292 $langs->load("boxes");
293 $facstatic = new FactureFournisseur($db);
294
295 $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";
296 $sql .= ", s.nom as name";
297 $sql .= ", s.rowid as socid";
298 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
299 $sql .= ", (SELECT SUM(pf.amount) FROM ".$db->prefix()."paiementfourn_facturefourn as pf WHERE pf.fk_facturefourn = ff.rowid) as am";
300 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
301 $sql .= " WHERE s.rowid = ff.fk_soc";
302 $sql .= " AND ff.entity IN (".getEntity('facture_fourn').")";
303 if ($socid > 0) {
304 $sql .= " AND ff.fk_soc = ".((int) $socid);
305 }
306 // Filter on sale representative
307 if (!$user->hasRight('societe', 'client', 'voir')) {
308 $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).")";
309 }
310 // Add where from hooks
311 $parameters = array();
312 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
313 $sql .= $hookmanager->resPrint;
314
315 $sql .= " ORDER BY ff.tms DESC";
316 $sql .= $db->plimit($max, 0);
317
318 $resql = $db->query($sql);
319 if ($resql) {
320 $num = $db->num_rows($resql);
321
322 print '<div class="div-table-responsive-no-min">';
323 print '<table class="noborder centpercent">';
324 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max);
325 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
326 print '</th>';
327 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
328 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
329 }
330 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
331 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
332 print '<th width="16">&nbsp;</th>';
333 print "</tr>\n";
334 if ($num) {
335 $i = 0;
336 $total_ht = $total_ttc = $totalam = 0;
337 $othernb = 0;
338
339 while ($i < $num) {
340 $obj = $db->fetch_object($resql);
341
342 if ($i >= $max) {
343 $othernb += 1;
344 $i++;
345 $total_ht += $obj->total_ht;
346 $total_ttc += $obj->total_ttc;
347 continue;
348 }
349
350 $facstatic->ref = $obj->ref;
351 $facstatic->id = $obj->rowid;
352 $facstatic->total_ht = $obj->total_ht;
353 $facstatic->total_tva = $obj->total_tva;
354 $facstatic->total_ttc = $obj->total_ttc;
355 $facstatic->statut = $obj->status;
356 $facstatic->status = $obj->status;
357 $facstatic->paye = $obj->paye;
358 $facstatic->paid = $obj->paye;
359 $facstatic->type = $obj->type;
360 $facstatic->ref_supplier = $obj->ref_supplier;
361
362 $thirdpartystatic->id = $obj->socid;
363 $thirdpartystatic->name = $obj->name;
364 $thirdpartystatic->email = $obj->email;
365 $thirdpartystatic->country_id = 0;
366 $thirdpartystatic->country_code = '';
367 $thirdpartystatic->client = 0;
368 $thirdpartystatic->fournisseur = 1;
369 $thirdpartystatic->code_client = '';
370 $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
371 $thirdpartystatic->code_compta_client = '';
372 $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
373
374 print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
375 print $facstatic->getNomUrl(1, '');
376 print '</td>';
377 print '<td class="nowrap tdoverflowmax100">';
378 print $thirdpartystatic->getNomUrl(1, 'supplier');
379 print '</td>';
380 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
381 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
382 }
383 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
384 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>';
385
386 $alreadypaid = $facstatic->getSommePaiement();
387 $alreadypaid += $facstatic->getSumCreditNotesUsed();
388 $alreadypaid += $facstatic->getSumDepositsUsed();
389
390 print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
391 print '</tr>';
392
393 $total_ht += $obj->total_ht;
394 $total_ttc += $obj->total_ttc;
395 $totalam += $obj->am;
396 $i++;
397 }
398
399 if ($othernb) {
400 print '<tr class="oddeven">';
401 print '<td class="nowrap" colspan="5">';
402 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
403 print '</td>';
404 print "</tr>\n";
405 }
406 } else {
407 $colspan = 5;
408 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
409 $colspan++;
410 }
411 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
412 }
413 print '</table></div><br>';
414 } else {
415 dol_print_error($db);
416 }
417}
418
419
420
421// Latest donations
422if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
423 include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
424
425 $langs->load("boxes");
426 $donationstatic = new Don($db);
427
428 $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";
429 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
430 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
431 // Add where from hooks
432 $parameters = array();
433 $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
434 $sql .= $hookmanager->resPrint;
435
436 $sql .= $db->order("d.tms", "DESC");
437 $sql .= $db->plimit($max, 0);
438
439 $result = $db->query($sql);
440 if ($result) {
441 $num = $db->num_rows($result);
442
443 $i = 0;
444 $othernb = 0;
445
446 print '<div class="div-table-responsive-no-min">';
447 print '<table class="noborder centpercent">';
448 print '<tr class="liste_titre">';
449 print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedDonations", $max);
450 print '<a href="'.DOL_URL_ROOT.'/don/list.php?sortfield=f.tms&sortorder=desc"><span class="badge marginleftonly">...</span></a>';
451 print '</th>';
452 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
453 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
454 print '<th width="16">&nbsp;</th>';
455 print '</tr>';
456
457 if ($num) {
458 $total_ttc = $totalam = $total_ht = 0;
459
460 while ($i < $num && $i < $max) {
461 $obj = $db->fetch_object($result);
462
463 if ($i >= $max) {
464 $othernb += 1;
465 $i++;
466 $total_ht += $obj->total_ht;
467 $total_ttc += $obj->total_ttc;
468 continue;
469 }
470
471 $donationstatic->id = $obj->rowid;
472 $donationstatic->ref = $obj->rowid;
473 $donationstatic->lastname = $obj->lastname;
474 $donationstatic->firstname = $obj->firstname;
475 $donationstatic->date = $db->jdate($obj->date);
476 $donationstatic->statut = $obj->status;
477 $donationstatic->status = $obj->status;
478
479 $label = $donationstatic->getFullName($langs);
480 if ($obj->societe) {
481 $label .= ($label ? ' - ' : '').$obj->societe;
482 }
483
484 print '<tr class="oddeven tdoverflowmax100">';
485 print '<td>'.$donationstatic->getNomUrl(1).'</td>';
486 print '<td>'.$label.'</td>';
487 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
488 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>';
489 print '<td>'.$donationstatic->getLibStatut(3).'</td>';
490 print '</tr>';
491
492 $i++;
493 }
494
495 if ($othernb) {
496 print '<tr class="oddeven">';
497 print '<td class="nowrap" colspan="5">';
498 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
499 print '</td>';
500 print "</tr>\n";
501 }
502 } else {
503 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
504 }
505 print '</table></div><br>';
506 } else {
507 dol_print_error($db);
508 }
509}
510
514if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
515 if (!$socid) {
516 $chargestatic = new ChargeSociales($db);
517
518 $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
519 $sql .= " cc.libelle as label,";
520 $sql .= " SUM(pc.amount) as sumpaid";
521 $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
522 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
523 $sql .= " WHERE c.fk_type = cc.id";
524 $sql .= " AND c.entity IN (".getEntity('tax').')';
525 $sql .= " AND c.paye = 0";
526 // Add where from hooks
527 $parameters = array();
528 $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
529 $sql .= $hookmanager->resPrint;
530
531 $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
532
533 $resql = $db->query($sql);
534 if ($resql) {
535 $num = $db->num_rows($resql);
536
537 print '<div class="div-table-responsive-no-min">';
538 print '<table class="noborder centpercent">';
539 print '<tr class="liste_titre">';
540 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>';
541 print '<th align="center">'.$langs->trans("DateDue").'</th>';
542 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
543 print '<th class="right">'.$langs->trans("Paid").'</th>';
544 print '<th align="center" width="16">&nbsp;</th>';
545 print '</tr>';
546 if ($num) {
547 $i = 0;
548 $tot_ttc = 0;
549 $tot_paid = 0;
550 $othernb = 0;
551
552 while ($i < $num) {
553 $obj = $db->fetch_object($resql);
554
555 if ($i >= $max) {
556 $othernb += 1;
557 $tot_ttc += $obj->amount;
558 $tot_paid += $obj->sumpaid;
559 $i++;
560 continue;
561 }
562
563 $chargestatic->id = $obj->rowid;
564 $chargestatic->ref = $obj->rowid;
565 $chargestatic->label = $obj->label;
566 $chargestatic->paye = $obj->paye;
567 $chargestatic->status = $obj->paye;
568
569 print '<tr class="oddeven">';
570 print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
571 print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
572 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
573 print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
574 print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
575 print '</tr>';
576
577 $tot_ttc += $obj->amount;
578 $i++;
579 }
580
581 if ($othernb) {
582 print '<tr class="oddeven">';
583 print '<td class="nowrap" colspan="5">';
584 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
585 print '</td>';
586 print "</tr>\n";
587 }
588
589 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
590 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
591 print '<td class="nowrap right">'.price($tot_paid).'</td>';
592 print '<td class="right">&nbsp;</td>';
593 print '</tr>';
594 } else {
595 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
596 }
597 print "</table></div><br>";
598 $db->free($resql);
599 } else {
600 dol_print_error($db);
601 }
602 }
603}
604
605/*
606 * Customers orders to be billed
607 */
608if (isModEnabled('invoice') && isModEnabled('order') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
609 $commandestatic = new Commande($db);
610 $langs->load("orders");
611
612 $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
613 $sql .= ", s.nom as name, s.email";
614 $sql .= ", s.rowid as socid";
615 $sql .= ", s.code_client, s.code_compta as code_compta_client";
616 $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
617 $sql .= " cc.rowid as country_id, cc.code as country_code";
618 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
619 $sql .= ", ".MAIN_DB_PREFIX."commande as c";
620 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
621 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
622 $sql .= " WHERE c.fk_soc = s.rowid";
623 $sql .= " AND c.entity IN (".getEntity('commande').")";
624 if ($socid) {
625 $sql .= " AND c.fk_soc = ".((int) $socid);
626 }
627 $sql .= " AND c.fk_statut = ".((int) Commande::STATUS_CLOSED);
628 $sql .= " AND c.facture = 0";
629 // Filter on sale representative
630 if (!$user->hasRight('societe', 'client', 'voir')) {
631 $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).")";
632 }
633
634 // Add where from hooks
635 $parameters = array();
636 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
637 $sql .= $hookmanager->resPrint;
638
639 $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";
640
641 $resql = $db->query($sql);
642 if ($resql) {
643 $num = $db->num_rows($resql);
644
645 if ($num) {
646 $i = 0;
647 $othernb = 0;
648
649 print '<div class="div-table-responsive-no-min">';
650 print '<table class="noborder centpercent">';
651
652 print '<tr class="liste_titre">';
653 print '<th colspan="2">';
654 print $langs->trans("OrdersDeliveredToBill");
655 print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&search_billed=0">';
656 print '<span class="badge marginleftonly">'.$num.'</span>';
657 print '</a>';
658 print '</th>';
659
660 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
661 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
662 }
663 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
664 print '<th class="right">'.$langs->trans("ToBill").'</th>';
665 print '<th align="center" width="16">&nbsp;</th>';
666 print '</tr>';
667
668 $tot_ht = $tot_ttc = $tot_tobill = 0;
669 $societestatic = new Societe($db);
670 while ($i < $num) {
671 $obj = $db->fetch_object($resql);
672
673 if ($i >= $max) {
674 $othernb += 1;
675 $i++;
676 $total_ht += $obj->total_ht;
677 $total_ttc += $obj->total_ttc;
678 continue;
679 }
680
681 $societestatic->id = $obj->socid;
682 $societestatic->name = $obj->name;
683 $societestatic->email = $obj->email;
684 $societestatic->country_id = $obj->country_id;
685 $societestatic->country_code = $obj->country_code;
686 $societestatic->client = 1;
687 $societestatic->code_client = $obj->code_client;
688 //$societestatic->code_fournisseur = $obj->code_fournisseur;
689 $societestatic->code_compta_client = $obj->code_compta_client;
690 //$societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
691
692 $commandestatic->id = $obj->rowid;
693 $commandestatic->ref = $obj->ref;
694 $commandestatic->statut = $obj->status;
695 $commandestatic->billed = $obj->facture;
696
697 print '<tr class="oddeven">';
698 print '<td class="nowrap">';
699
700 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
701 print '<td class="nobordernopadding nowrap">';
702 print $commandestatic->getNomUrl(1);
703 print '</td>';
704 print '<td width="20" class="nobordernopadding nowrap">';
705 print '&nbsp;';
706 print '</td>';
707 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
708 $filename = dol_sanitizeFileName($obj->ref);
709 $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
710 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
711 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
712 print '</td></tr></table>';
713
714 print '</td>';
715
716 print '<td class="nowrap tdoverflowmax100">';
717 print $societestatic->getNomUrl(1, 'customer');
718 print '</td>';
719 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
720 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
721 }
722 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
723 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
724 print '<td>'.$commandestatic->getLibStatut(3).'</td>';
725 print '</tr>';
726 $tot_ht += $obj->total_ht;
727 $tot_ttc += $obj->total_ttc;
728 //print "x".$tot_ttc."z".$obj->tot_fttc;
729 $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
730 $i++;
731 }
732
733 if ($othernb) {
734 print '<tr class="oddeven">';
735 print '<td class="nowrap" colspan="5">';
736 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
737 print '</td>';
738 print "</tr>\n";
739 }
740
741 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>';
742 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
743 print '<td class="right">'.price($tot_ht).'</td>';
744 }
745 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
746 print '<td class="nowrap right">'.price($tot_tobill).'</td>';
747 print '<td>&nbsp;</td>';
748 print '</tr>';
749 print '</table></div><br>';
750 }
751 $db->free($resql);
752 } else {
753 dol_print_error($db);
754 }
755}
756
757
758// TODO Mettre ici recup des actions en rapport avec la compta
759$sql = '';
760if ($sql) {
761 print '<div class="div-table-responsive-no-min">';
762 print '<table class="noborder centpercent">';
763 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("TasksToDo").'</th>';
764 print "</tr>\n";
765 $i = 0;
766 $resql = $db->query($sql);
767 if ($resql) {
768 $num_rows = $db->num_rows($resql);
769 while ($i < $num_rows) {
770 $obj = $db->fetch_object($resql);
771
772 print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
773 print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
774 $i++;
775 }
776 $db->free($resql);
777 }
778 print "</table></div><br>";
779}
780
781
782print '</div></div></div>';
783
784$parameters = array('user' => $user);
785$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
786
787// End of page
788llxFooter();
789$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.