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