dolibarr 19.0.4
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-2023 Frédéric France <frederic.france@netlogic.fr>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
35// Load Dolibarr environment
36require '../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
40require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
45
46// L'espace compta/treso doit toujours etre actif car c'est un espace partage
47// par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
48// de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
49// est protegee par le droit qui va bien du module concerne.
50//if (!$user->rights->compta->general->lire)
51// accessforbidden();
52
53// Load translation files required by the page
54$langs->loadLangs(array('compta', 'bills'));
55if (isModEnabled('commande')) {
56 $langs->load("orders");
57}
58
59// Get parameters
60$action = GETPOST('action', 'aZ09');
61$bid = GETPOST('bid', 'int');
62
63// Security check
64$socid = '';
65if ($user->socid > 0) {
66 $action = '';
67 $socid = $user->socid;
68}
69
70$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT');
71
72// Maximum elements of the tables
73$maxDraftCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
74$maxLatestEditCount = 5;
75$maxOpenCount = !getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
76
77// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
78$hookmanager->initHooks(array('invoiceindex'));
79
80
81$maxofloop = (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
82
83
84/*
85 * Actions
86 */
87
88// None
89
90
91/*
92 * View
93 */
94
95$now = dol_now();
96
97$form = new Form($db);
98$formfile = new FormFile($db);
99$thirdpartystatic = new Societe($db);
100
101llxHeader("", $langs->trans("InvoicesArea"));
102
103print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
104
105
106print '<div class="fichecenter"><div class="fichethirdleft">';
107
108if (isModEnabled('facture')) {
109 print getNumberInvoicesPieChart('customers');
110 print '<br>';
111}
112
113if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
114 print getNumberInvoicesPieChart('suppliers');
115 print '<br>';
116}
117
118if (isModEnabled('facture')) {
119 print getCustomerInvoiceDraftTable($max, $socid);
120 print '<br>';
121}
122
123if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
124 print getDraftSupplierTable($max, $socid);
125 print '<br>';
126}
127
128print '</div><div class="fichetwothirdright">';
129
130
131// Latest modified customer invoices
132if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
133 $langs->load("boxes");
134 $tmpinvoice = new Facture($db);
135
136 $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";
137 $sql .= ", f.date_lim_reglement as datelimite";
138 $sql .= ", s.nom as name";
139 $sql .= ", s.rowid as socid";
140 $sql .= ", s.code_client, s.code_compta, s.email";
141 $sql .= ", cc.rowid as country_id, cc.code as country_code";
142 $sql .= ", sum(pf.amount) as am";
143 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays, ".MAIN_DB_PREFIX."facture as f";
144 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
145 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
146 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
147 }
148 $sql .= " WHERE s.rowid = f.fk_soc";
149 $sql .= " AND f.entity IN (".getEntity('invoice').")";
150 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
151 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
152 }
153 if ($socid) {
154 $sql .= " AND f.fk_soc = ".((int) $socid);
155 }
156 // Add where from hooks
157 $parameters = array();
158 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
159 $sql .= $hookmanager->resPrint;
160
161 $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
162 $sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
163 $sql .= " cc.rowid, cc.code";
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 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
176 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
177 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
178 }
179 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
180 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
181 print '<th width="16">&nbsp;</th>';
182 print '</tr>';
183 if ($num) {
184 $total_ttc = $totalam = $total_ht = 0;
185 while ($i < $num && $i < $conf->liste_limit) {
186 $obj = $db->fetch_object($resql);
187
188 if ($i >= $max) {
189 $othernb += 1;
190 $i++;
191 $total_ht += $obj->total_ht;
192 $total_ttc += $obj->total_ttc;
193 continue;
194 }
195
196 $tmpinvoice->ref = $obj->ref;
197 $tmpinvoice->id = $obj->rowid;
198 $tmpinvoice->total_ht = $obj->total_ht;
199 $tmpinvoice->total_tva = $obj->total_tva;
200 $tmpinvoice->total_ttc = $obj->total_ttc;
201 $tmpinvoice->statut = $obj->status;
202 $tmpinvoice->paye = $obj->paye;
203 $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
204 $tmpinvoice->type = $obj->type;
205
206 $thirdpartystatic->id = $obj->socid;
207 $thirdpartystatic->name = $obj->name;
208 $thirdpartystatic->email = $obj->email;
209 $thirdpartystatic->country_id = $obj->country_id;
210 $thirdpartystatic->country_code = $obj->country_code;
211 $thirdpartystatic->email = $obj->email;
212 $thirdpartystatic->client = 1;
213 $thirdpartystatic->code_client = $obj->code_client;
214 //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
215 $thirdpartystatic->code_compta = $obj->code_compta;
216 //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
217
218 $totalallpayments = $tmpinvoice->getSommePaiement(0);
219 $totalallpayments += $tmpinvoice->getSumCreditNotesUsed(0);
220 $totalallpayments += $tmpinvoice->getSumDepositsUsed(0);
221 print '<tr class="oddeven">';
222 print '<td class="nowrap">';
223
224 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
225
226 print '<td class="nobordernopadding nowraponall">';
227 print $tmpinvoice->getNomUrl(1, '');
228 print '</td>';
229 if ($tmpinvoice->hasDelay()) {
230 print '<td width="20" class="nobordernopadding nowrap">';
231 print img_warning($langs->trans("Late"));
232 print '</td>';
233 }
234 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
235 $filename = dol_sanitizeFileName($obj->ref);
236 $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
237 $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
238 print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
239 print '</td></tr></table>';
240
241 print '</td>';
242
243 print '<td class="tdoverflowmax150">';
244 print $thirdpartystatic->getNomUrl(1, 'customer', 44);
245 print '</td>';
246 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
247 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
248 }
249 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
250
251 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>';
252
253 print '<td>'.$tmpinvoice->getLibStatut(3, $totalallpayments).'</td>';
254
255 print '</tr>';
256
257 $total_ttc += $obj->total_ttc;
258 $total_ht += $obj->total_ht;
259 $totalam += $obj->am;
260
261 $i++;
262 }
263
264 if ($othernb) {
265 print '<tr class="oddeven">';
266 print '<td class="nowrap" colspan="5">';
267 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
268 print '</td>';
269 print "</tr>\n";
270 }
271 } else {
272 $colspan = 5;
273 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
274 $colspan++;
275 }
276 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
277 }
278 print '</table></div><br>';
279 $db->free($resql);
280 } else {
281 dol_print_error($db);
282 }
283}
284
285
286// Last modified supplier invoices
287if ((isModEnabled('fournisseur') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
288 $langs->load("boxes");
289 $facstatic = new FactureFournisseur($db);
290
291 $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";
292 $sql .= ", s.nom as name";
293 $sql .= ", s.rowid as socid";
294 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
295 $sql .= ", SUM(pf.amount) as am";
296 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
297 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
298 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
299 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
300 }
301 $sql .= " WHERE s.rowid = ff.fk_soc";
302 $sql .= " AND ff.entity = ".$conf->entity;
303 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
304 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
305 }
306 if ($socid) {
307 $sql .= " AND ff.fk_soc = ".((int) $socid);
308 }
309 // Add where from hooks
310 $parameters = array();
311 $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
312 $sql .= $hookmanager->resPrint;
313
314 $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.type, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye, ff.ref_supplier,";
315 $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
316 $sql .= " ORDER BY ff.tms DESC ";
317 $sql .= $db->plimit($max, 0);
318
319 $resql = $db->query($sql);
320 if ($resql) {
321 $num = $db->num_rows($resql);
322
323 print '<div class="div-table-responsive-no-min">';
324 print '<table class="noborder centpercent">';
325 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
326 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
327 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
328 }
329 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
330 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
331 print '<th width="16">&nbsp;</th>';
332 print "</tr>\n";
333 if ($num) {
334 $i = 0;
335 $total_ht = $total_ttc = $totalam = 0;
336 $othernb = 0;
337
338 while ($i < $num) {
339 $obj = $db->fetch_object($resql);
340
341 if ($i >= $max) {
342 $othernb += 1;
343 $i++;
344 $total_ht += $obj->total_ht;
345 $total_ttc += $obj->total_ttc;
346 continue;
347 }
348
349 $facstatic->ref = $obj->ref;
350 $facstatic->id = $obj->rowid;
351 $facstatic->total_ht = $obj->total_ht;
352 $facstatic->total_tva = $obj->total_tva;
353 $facstatic->total_ttc = $obj->total_ttc;
354 $facstatic->statut = $obj->status;
355 $facstatic->paye = $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 = '';
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 $alreadypaid = $facstatic->getSommePaiement();
383 $alreadypaid += $facstatic->getSumCreditNotesUsed();
384 $alreadypaid += $facstatic->getSumDepositsUsed();
385 print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
386 print '</tr>';
387 $total_ht += $obj->total_ht;
388 $total_ttc += $obj->total_ttc;
389 $totalam += $obj->am;
390 $i++;
391 }
392
393 if ($othernb) {
394 print '<tr class="oddeven">';
395 print '<td class="nowrap" colspan="5">';
396 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
397 print '</td>';
398 print "</tr>\n";
399 }
400 } else {
401 $colspan = 5;
402 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
403 $colspan++;
404 }
405 print '<tr class="oddeven"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoInvoice").'</span></td></tr>';
406 }
407 print '</table></div><br>';
408 } else {
409 dol_print_error($db);
410 }
411}
412
413
414
415// Latest donations
416if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
417 include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
418
419 $langs->load("boxes");
420 $donationstatic = new Don($db);
421
422 $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";
423 $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
424 $sql .= " WHERE d.entity IN (".getEntity('donation').")";
425 // Add where from hooks
426 $parameters = array();
427 $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
428 $sql .= $hookmanager->resPrint;
429
430 $sql .= $db->order("d.tms", "DESC");
431 $sql .= $db->plimit($max, 0);
432
433 $result = $db->query($sql);
434 if ($result) {
435 $num = $db->num_rows($result);
436
437 $i = 0;
438 $othernb = 0;
439
440 print '<div class="div-table-responsive-no-min">';
441 print '<table class="noborder centpercent">';
442 print '<tr class="liste_titre">';
443 print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
444 print '<th></th>';
445 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
446 print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
447 print '<th width="16">&nbsp;</th>';
448 print '</tr>';
449
450 if ($num) {
451 $total_ttc = $totalam = $total_ht = 0;
452
453 while ($i < $num && $i < $max) {
454 $obj = $db->fetch_object($result);
455
456 if ($i >= $max) {
457 $othernb += 1;
458 $i++;
459 $total_ht += $obj->total_ht;
460 $total_ttc += $obj->total_ttc;
461 continue;
462 }
463
464 $donationstatic->id = $obj->rowid;
465 $donationstatic->ref = $obj->rowid;
466 $donationstatic->lastname = $obj->lastname;
467 $donationstatic->firstname = $obj->firstname;
468 $donationstatic->date = $db->jdate($obj->date);
469 $donationstatic->statut = $obj->status;
470 $donationstatic->status = $obj->status;
471
472 $label = $donationstatic->getFullName($langs);
473 if ($obj->societe) {
474 $label .= ($label ? ' - ' : '').$obj->societe;
475 }
476
477 print '<tr class="oddeven tdoverflowmax100">';
478 print '<td>'.$donationstatic->getNomUrl(1).'</td>';
479 print '<td>'.$label.'</td>';
480 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
481 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>';
482 print '<td>'.$donationstatic->getLibStatut(3).'</td>';
483 print '</tr>';
484
485 $i++;
486 }
487
488 if ($othernb) {
489 print '<tr class="oddeven">';
490 print '<td class="nowrap" colspan="5">';
491 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
492 print '</td>';
493 print "</tr>\n";
494 }
495 } else {
496 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
497 }
498 print '</table></div><br>';
499 } else {
500 dol_print_error($db);
501 }
502}
503
507if (isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) {
508 if (!$socid) {
509 $chargestatic = new ChargeSociales($db);
510
511 $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
512 $sql .= " cc.libelle as label,";
513 $sql .= " SUM(pc.amount) as sumpaid";
514 $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
515 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
516 $sql .= " WHERE c.fk_type = cc.id";
517 $sql .= " AND c.entity IN (".getEntity('tax').')';
518 $sql .= " AND c.paye = 0";
519 // Add where from hooks
520 $parameters = array();
521 $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
522 $sql .= $hookmanager->resPrint;
523
524 $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
525
526 $resql = $db->query($sql);
527 if ($resql) {
528 $num = $db->num_rows($resql);
529
530 print '<div class="div-table-responsive-no-min">';
531 print '<table class="noborder centpercent">';
532 print '<tr class="liste_titre">';
533 print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
534 print '<th align="center">'.$langs->trans("DateDue").'</th>';
535 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
536 print '<th class="right">'.$langs->trans("Paid").'</th>';
537 print '<th align="center" width="16">&nbsp;</th>';
538 print '</tr>';
539 if ($num) {
540 $i = 0;
541 $tot_ttc = 0;
542 $othernb = 0;
543
544 while ($i < $num) {
545 $obj = $db->fetch_object($resql);
546
547 if ($i >= $max) {
548 $othernb += 1;
549 $tot_ttc += $obj->amount;
550 $i++;
551 continue;
552 }
553
554 $chargestatic->id = $obj->rowid;
555 $chargestatic->ref = $obj->rowid;
556 $chargestatic->label = $obj->label;
557 $chargestatic->paye = $obj->paye;
558 $chargestatic->status = $obj->paye;
559
560 print '<tr class="oddeven">';
561 print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
562 print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
563 print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
564 print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
565 print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
566 print '</tr>';
567
568 $tot_ttc += $obj->amount;
569 $i++;
570 }
571
572 if ($othernb) {
573 print '<tr class="oddeven">';
574 print '<td class="nowrap" colspan="5">';
575 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
576 print '</td>';
577 print "</tr>\n";
578 }
579
580 print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
581 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
582 print '<td class="right"></td>';
583 print '<td class="right">&nbsp;</td>';
584 print '</tr>';
585 } else {
586 print '<tr class="oddeven"><td colspan="5"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
587 }
588 print "</table></div><br>";
589 $db->free($resql);
590 } else {
591 dol_print_error($db);
592 }
593 }
594}
595
596/*
597 * Customers orders to be billed
598 */
599if (isModEnabled('facture') && isModEnabled('commande') && $user->hasRight("commande", "lire") && !getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) {
600 $commandestatic = new Commande($db);
601 $langs->load("orders");
602
603 $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
604 $sql .= ", s.nom as name, s.email";
605 $sql .= ", s.rowid as socid";
606 $sql .= ", s.code_client, s.code_compta";
607 $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
608 $sql .= " cc.rowid as country_id, cc.code as country_code";
609 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
610 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
611 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
612 }
613 $sql .= ", ".MAIN_DB_PREFIX."commande as c";
614 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
615 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
616 $sql .= " WHERE c.fk_soc = s.rowid";
617 $sql .= " AND c.entity = ".$conf->entity;
618 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
619 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
620 }
621 if ($socid) {
622 $sql .= " AND c.fk_soc = ".((int) $socid);
623 }
624 $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
625 $sql .= " AND c.facture = 0";
626 // Add where from hooks
627 $parameters = array();
628 $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
629 $sql .= $hookmanager->resPrint;
630
631 $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";
632
633 $resql = $db->query($sql);
634 if ($resql) {
635 $num = $db->num_rows($resql);
636
637 if ($num) {
638 $i = 0;
639 $othernb = 0;
640
641 print '<div class="div-table-responsive-no-min">';
642 print '<table class="noborder centpercent">';
643
644 print "<tr class=\"liste_titre\">";
645 print '<th colspan="2">';
646 print $langs->trans("OrdersDeliveredToBill").' ';
647 print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
648 print '<span class="badge">'.$num.'</span>';
649 print '</a>';
650 print '</th>';
651
652 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
653 print '<th class="right">'.$langs->trans("AmountHT").'</th>';
654 }
655 print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
656 print '<th class="right">'.$langs->trans("ToBill").'</th>';
657 print '<th align="center" width="16">&nbsp;</th>';
658 print '</tr>';
659
660 $tot_ht = $tot_ttc = $tot_tobill = 0;
661 $societestatic = new Societe($db);
662 while ($i < $num) {
663 $obj = $db->fetch_object($resql);
664
665 if ($i >= $max) {
666 $othernb += 1;
667 $i++;
668 $total_ht += $obj->total_ht;
669 $total_ttc += $obj->total_ttc;
670 continue;
671 }
672
673 $societestatic->id = $obj->socid;
674 $societestatic->name = $obj->name;
675 $societestatic->email = $obj->email;
676 $societestatic->country_id = $obj->country_id;
677 $societestatic->country_code = $obj->country_code;
678 $societestatic->client = 1;
679 $societestatic->code_client = $obj->code_client;
680 //$societestatic->code_fournisseur = $obj->code_fournisseur;
681 $societestatic->code_compta = $obj->code_compta;
682 //$societestatic->code_fournisseur = $obj->code_fournisseur;
683
684 $commandestatic->id = $obj->rowid;
685 $commandestatic->ref = $obj->ref;
686 $commandestatic->statut = $obj->status;
687 $commandestatic->billed = $obj->facture;
688
689 print '<tr class="oddeven">';
690 print '<td class="nowrap">';
691
692 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
693 print '<td class="nobordernopadding nowrap">';
694 print $commandestatic->getNomUrl(1);
695 print '</td>';
696 print '<td width="20" class="nobordernopadding nowrap">';
697 print '&nbsp;';
698 print '</td>';
699 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
700 $filename = dol_sanitizeFileName($obj->ref);
701 $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
702 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
703 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
704 print '</td></tr></table>';
705
706 print '</td>';
707
708 print '<td class="nowrap tdoverflowmax100">';
709 print $societestatic->getNomUrl(1, 'customer');
710 print '</td>';
711 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
712 print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
713 }
714 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
715 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
716 print '<td>'.$commandestatic->getLibStatut(3).'</td>';
717 print '</tr>';
718 $tot_ht += $obj->total_ht;
719 $tot_ttc += $obj->total_ttc;
720 //print "x".$tot_ttc."z".$obj->tot_fttc;
721 $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
722 $i++;
723 }
724
725 if ($othernb) {
726 print '<tr class="oddeven">';
727 print '<td class="nowrap" colspan="5">';
728 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
729 print '</td>';
730 print "</tr>\n";
731 }
732
733 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>';
734 if (getDolGlobalString('MAIN_SHOW_HT_ON_SUMMARY')) {
735 print '<td class="right">'.price($tot_ht).'</td>';
736 }
737 print '<td class="nowrap right">'.price($tot_ttc).'</td>';
738 print '<td class="nowrap right">'.price($tot_tobill).'</td>';
739 print '<td>&nbsp;</td>';
740 print '</tr>';
741 print '</table></div><br>';
742 }
743 $db->free($resql);
744 } else {
745 dol_print_error($db);
746 }
747}
748
749
750// TODO Mettre ici recup des actions en rapport avec la compta
751$sql = '';
752if ($sql) {
753 print '<div class="div-table-responsive-no-min">';
754 print '<table class="noborder centpercent">';
755 print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
756 print "</tr>\n";
757 $i = 0;
758 $resql = $db->query($sql);
759 if ($resql) {
760 $num_rows = $db->num_rows($resql);
761 while ($i < $num_rows) {
762 $obj = $db->fetch_object($resql);
763
764 print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
765 print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
766 $i++;
767 }
768 $db->free($resql);
769 }
770 print "</table></div><br>";
771}
772
773
774print '</div></div>';
775
776$parameters = array('user' => $user);
777$reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
778
779// End of page
780llxFooter();
781$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage customers orders.
const STATUS_CLOSED
Closed (Sent, billed or not)
Class to manage donations.
Definition don.class.php:40
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...)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return 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.