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