dolibarr  16.0.1
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 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 
34 require '../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
43 
44 // L'espace compta/treso doit toujours etre actif car c'est un espace partage
45 // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
46 // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
47 // est protegee par le droit qui va bien du module concerne.
48 //if (!$user->rights->compta->general->lire)
49 // accessforbidden();
50 
51 // Load translation files required by the page
52 $langs->loadLangs(array('compta', 'bills'));
53 if (isModEnabled('commande')) {
54  $langs->load("orders");
55 }
56 
57 $action = GETPOST('action', 'aZ09');
58 $bid = GETPOST('bid', 'int');
59 
60 // Security check
61 $socid = '';
62 if ($user->socid > 0) {
63  $action = '';
64  $socid = $user->socid;
65 }
66 
67 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
68 
69 // Maximum elements of the tables
70 $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
71 $maxLatestEditCount = 5;
72 $maxOpenCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
73 
74 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
75 $hookmanager->initHooks(array('invoiceindex'));
76 
77 
78 $maxofloop = (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD);
79 
80 
81 /*
82  * Actions
83  */
84 
85 // None
86 
87 
88 /*
89  * View
90  */
91 
92 $now = dol_now();
93 
94 $form = new Form($db);
95 $formfile = new FormFile($db);
96 $thirdpartystatic = new Societe($db);
97 
98 llxHeader("", $langs->trans("AccountancyTreasuryArea"));
99 
100 print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', 'bill');
101 
102 
103 print '<div class="fichecenter"><div class="fichethirdleft">';
104 
105 if (isModEnabled('facture')) {
106  print getNumberInvoicesPieChart('customers');
107  print '<br>';
108 }
109 
110 if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
111  print getNumberInvoicesPieChart('fourn');
112  print '<br>';
113 }
114 
115 if (isModEnabled('facture')) {
116  print getCustomerInvoiceDraftTable($max, $socid);
117  print '<br>';
118 }
119 
120 if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
121  print getDraftSupplierTable($max, $socid);
122  print '<br>';
123 }
124 
125 print '</div><div class="fichetwothirdright">';
126 
127 
128 // Latest modified customer invoices
129 if (isModEnabled('facture') && !empty($user->rights->facture->lire)) {
130  $langs->load("boxes");
131  $tmpinvoice = new Facture($db);
132 
133  $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";
134  $sql .= ", f.date_lim_reglement as datelimite";
135  $sql .= ", s.nom as name";
136  $sql .= ", s.rowid as socid";
137  $sql .= ", s.code_client, s.code_compta, s.email";
138  $sql .= ", cc.rowid as country_id, cc.code as country_code";
139  $sql .= ", sum(pf.amount) as am";
140  $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";
141  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
142  if (empty($user->rights->societe->client->voir) && !$socid) {
143  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
144  }
145  $sql .= " WHERE s.rowid = f.fk_soc";
146  $sql .= " AND f.entity IN (".getEntity('invoice').")";
147  if (empty($user->rights->societe->client->voir) && !$socid) {
148  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
149  }
150  if ($socid) {
151  $sql .= " AND f.fk_soc = ".((int) $socid);
152  }
153  // Add where from hooks
154  $parameters = array();
155  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
156  $sql .= $hookmanager->resPrint;
157 
158  $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,";
159  $sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
160  $sql .= " cc.rowid, cc.code";
161  $sql .= " ORDER BY f.tms DESC";
162  $sql .= $db->plimit($max, 0);
163 
164  $resql = $db->query($sql);
165  if ($resql) {
166  $num = $db->num_rows($resql);
167  $i = 0;
168  $othernb = 0;
169 
170  print '<div class="div-table-responsive-no-min">';
171  print '<table class="noborder centpercent">';
172  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
173  if (!empty($conf->global->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->paye = $obj->paye;
200  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
201  $tmpinvoice->type = $obj->type;
202 
203  $thirdpartystatic->id = $obj->socid;
204  $thirdpartystatic->name = $obj->name;
205  $thirdpartystatic->email = $obj->email;
206  $thirdpartystatic->country_id = $obj->country_id;
207  $thirdpartystatic->country_code = $obj->country_code;
208  $thirdpartystatic->email = $obj->email;
209  $thirdpartystatic->client = 1;
210  $thirdpartystatic->code_client = $obj->code_client;
211  //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
212  $thirdpartystatic->code_compta = $obj->code_compta;
213  //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
214 
215  print '<tr class="oddeven">';
216  print '<td class="nowrap">';
217 
218  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
219 
220  print '<td class="nobordernopadding nowraponall">';
221  print $tmpinvoice->getNomUrl(1, '');
222  print '</td>';
223  if ($tmpinvoice->hasDelay()) {
224  print '<td width="20" class="nobordernopadding nowrap">';
225  print img_warning($langs->trans("Late"));
226  print '</td>';
227  }
228  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
229  $filename = dol_sanitizeFileName($obj->ref);
230  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
231  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
232  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
233  print '</td></tr></table>';
234 
235  print '</td>';
236 
237  print '<td class="tdoverflowmax150">';
238  print $thirdpartystatic->getNomUrl(1, 'customer', 44);
239  print '</td>';
240  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
241  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
242  }
243  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
244 
245  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>';
246 
247  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
248 
249  print '</tr>';
250 
251  $total_ttc += $obj->total_ttc;
252  $total_ht += $obj->total_ht;
253  $totalam += $obj->am;
254 
255  $i++;
256  }
257 
258  if ($othernb) {
259  print '<tr class="oddeven">';
260  print '<td class="nowrap" colspan="5">';
261  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
262  print '</td>';
263  print "</tr>\n";
264  }
265  } else {
266  $colspan = 5;
267  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
268  $colspan++;
269  }
270  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
271  }
272  print '</table></div><br>';
273  $db->free($resql);
274  } else {
275  dol_print_error($db);
276  }
277 }
278 
279 
280 // Last modified supplier invoices
281 if ((isModEnabled('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) {
282  $langs->load("boxes");
283  $facstatic = new FactureFournisseur($db);
284 
285  $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";
286  $sql .= ", s.nom as name";
287  $sql .= ", s.rowid as socid";
288  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
289  $sql .= ", SUM(pf.amount) as am";
290  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
291  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
292  if (empty($user->rights->societe->client->voir) && !$socid) {
293  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
294  }
295  $sql .= " WHERE s.rowid = ff.fk_soc";
296  $sql .= " AND ff.entity = ".$conf->entity;
297  if (empty($user->rights->societe->client->voir) && !$socid) {
298  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
299  }
300  if ($socid) {
301  $sql .= " AND ff.fk_soc = ".((int) $socid);
302  }
303  // Add where from hooks
304  $parameters = array();
305  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
306  $sql .= $hookmanager->resPrint;
307 
308  $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,";
309  $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
310  $sql .= " ORDER BY ff.tms DESC ";
311  $sql .= $db->plimit($max, 0);
312 
313  $resql = $db->query($sql);
314  if ($resql) {
315  $num = $db->num_rows($resql);
316 
317  print '<div class="div-table-responsive-no-min">';
318  print '<table class="noborder centpercent">';
319  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
320  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
321  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
322  }
323  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
324  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
325  print '<th width="16">&nbsp;</th>';
326  print "</tr>\n";
327  if ($num) {
328  $i = 0;
329  $total_ht = $total_ttc = $totalam = 0;
330  $othernb = 0;
331 
332  while ($i < $num) {
333  $obj = $db->fetch_object($resql);
334 
335  if ($i >= $max) {
336  $othernb += 1;
337  $i++;
338  $total_ht += $obj->total_ht;
339  $total_ttc += $obj->total_ttc;
340  continue;
341  }
342 
343  $facstatic->ref = $obj->ref;
344  $facstatic->id = $obj->rowid;
345  $facstatic->total_ht = $obj->total_ht;
346  $facstatic->total_tva = $obj->total_tva;
347  $facstatic->total_ttc = $obj->total_ttc;
348  $facstatic->statut = $obj->status;
349  $facstatic->paye = $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 = '';
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 (!empty($conf->global->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 (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
395  $colspan++;
396  }
397  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</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') && !empty($user->rights->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>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
436  print '<th></th>';
437  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
438  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
439  print '<th width="16">&nbsp;</th>';
440  print '</tr>';
441  if ($num) {
442  $total_ttc = $totalam = $total_ht = 0;
443 
444  while ($i < $num && $i < $max) {
445  $obj = $db->fetch_object($result);
446 
447  if ($i >= $max) {
448  $othernb += 1;
449  $i++;
450  $total_ht += $obj->total_ht;
451  $total_ttc += $obj->total_ttc;
452  continue;
453  }
454 
455  $donationstatic->id = $obj->rowid;
456  $donationstatic->ref = $obj->rowid;
457  $donationstatic->lastname = $obj->lastname;
458  $donationstatic->firstname = $obj->firstname;
459  $donationstatic->date = $obj->date;
460  $donationstatic->statut = $obj->status;
461  $donationstatic->status = $obj->status;
462 
463  $label = $donationstatic->getFullName($langs);
464  if ($obj->societe) {
465  $label .= ($label ? ' - ' : '').$obj->societe;
466  }
467 
468  print '<tr class="oddeven tdoverflowmax100">';
469  print '<td>'.$donationstatic->getNomUrl(1).'</td>';
470  print '<td>'.$label.'</td>';
471  print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
472  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>';
473  print '<td>'.$donationstatic->getLibStatut(3).'</td>';
474  print '</tr>';
475 
476  $i++;
477  }
478 
479  if ($othernb) {
480  print '<tr class="oddeven">';
481  print '<td class="nowrap" colspan="5">';
482  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
483  print '</td>';
484  print "</tr>\n";
485  }
486  } else {
487  print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
488  }
489  print '</table></div><br>';
490  } else {
491  dol_print_error($db);
492  }
493 }
494 
498 if (isModEnabled('tax') && !empty($user->rights->tax->charges->lire)) {
499  if (!$socid) {
500  $chargestatic = new ChargeSociales($db);
501 
502  $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
503  $sql .= " cc.libelle as label,";
504  $sql .= " SUM(pc.amount) as sumpaid";
505  $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
506  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
507  $sql .= " WHERE c.fk_type = cc.id";
508  $sql .= " AND c.entity IN (".getEntity('tax').')';
509  $sql .= " AND c.paye = 0";
510  // Add where from hooks
511  $parameters = array();
512  $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
513  $sql .= $hookmanager->resPrint;
514 
515  $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
516 
517  $resql = $db->query($sql);
518  if ($resql) {
519  $num = $db->num_rows($resql);
520 
521  print '<div class="div-table-responsive-no-min">';
522  print '<table class="noborder centpercent">';
523  print '<tr class="liste_titre">';
524  print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
525  print '<th align="center">'.$langs->trans("DateDue").'</th>';
526  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
527  print '<th class="right">'.$langs->trans("Paid").'</th>';
528  print '<th align="center" width="16">&nbsp;</th>';
529  print '</tr>';
530  if ($num) {
531  $i = 0;
532  $tot_ttc = 0;
533  $othernb = 0;
534 
535  while ($i < $num) {
536  $obj = $db->fetch_object($resql);
537 
538  if ($i >= $max) {
539  $othernb += 1;
540  $tot_ttc += $obj->amount;
541  $i++;
542  continue;
543  }
544 
545  $chargestatic->id = $obj->rowid;
546  $chargestatic->ref = $obj->rowid;
547  $chargestatic->label = $obj->label;
548  $chargestatic->paye = $obj->paye;
549  $chargestatic->status = $obj->paye;
550 
551  print '<tr class="oddeven">';
552  print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
553  print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
554  print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
555  print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
556  print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
557  print '</tr>';
558 
559  $tot_ttc += $obj->amount;
560  $i++;
561  }
562 
563  if ($othernb) {
564  print '<tr class="oddeven">';
565  print '<td class="nowrap" colspan="5">';
566  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
567  print '</td>';
568  print "</tr>\n";
569  }
570 
571  print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
572  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
573  print '<td class="right"></td>';
574  print '<td class="right">&nbsp;</td>';
575  print '</tr>';
576  } else {
577  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
578  }
579  print "</table></div><br>";
580  $db->free($resql);
581  } else {
582  dol_print_error($db);
583  }
584  }
585 }
586 
587 /*
588  * Customers orders to be billed
589  */
590 if (isModEnabled('facture') && isModEnabled('commande') && $user->rights->commande->lire && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
591  $commandestatic = new Commande($db);
592  $langs->load("orders");
593 
594  $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
595  $sql .= ", s.nom as name, s.email";
596  $sql .= ", s.rowid as socid";
597  $sql .= ", s.code_client, s.code_compta";
598  $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
599  $sql .= " cc.rowid as country_id, cc.code as country_code";
600  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
601  if (empty($user->rights->societe->client->voir) && !$socid) {
602  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
603  }
604  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
605  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
606  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
607  $sql .= " WHERE c.fk_soc = s.rowid";
608  $sql .= " AND c.entity = ".$conf->entity;
609  if (empty($user->rights->societe->client->voir) && !$socid) {
610  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
611  }
612  if ($socid) {
613  $sql .= " AND c.fk_soc = ".((int) $socid);
614  }
615  $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
616  $sql .= " AND c.facture = 0";
617  // Add where from hooks
618  $parameters = array();
619  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
620  $sql .= $hookmanager->resPrint;
621 
622  $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";
623 
624  $resql = $db->query($sql);
625  if ($resql) {
626  $num = $db->num_rows($resql);
627 
628  if ($num) {
629  $i = 0;
630  $othernb = 0;
631 
632  print '<div class="div-table-responsive-no-min">';
633  print '<table class="noborder centpercent">';
634 
635  print "<tr class=\"liste_titre\">";
636  print '<th colspan="2">';
637  print $langs->trans("OrdersDeliveredToBill").' ';
638  print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
639  print '<span class="badge">'.$num.'</span>';
640  print '</a>';
641  print '</th>';
642 
643  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
644  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
645  }
646  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
647  print '<th class="right">'.$langs->trans("ToBill").'</th>';
648  print '<th align="center" width="16">&nbsp;</th>';
649  print '</tr>';
650 
651  $tot_ht = $tot_ttc = $tot_tobill = 0;
652  $societestatic = new Societe($db);
653  while ($i < $num) {
654  $obj = $db->fetch_object($resql);
655 
656  if ($i >= $max) {
657  $othernb += 1;
658  $i++;
659  $total_ht += $obj->total_ht;
660  $total_ttc += $obj->total_ttc;
661  continue;
662  }
663 
664  $societestatic->id = $obj->socid;
665  $societestatic->name = $obj->name;
666  $societestatic->email = $obj->email;
667  $societestatic->country_id = $obj->country_id;
668  $societestatic->country_code = $obj->country_code;
669  $societestatic->client = 1;
670  $societestatic->code_client = $obj->code_client;
671  //$societestatic->code_fournisseur = $obj->code_fournisseur;
672  $societestatic->code_compta = $obj->code_compta;
673  //$societestatic->code_fournisseur = $obj->code_fournisseur;
674 
675  $commandestatic->id = $obj->rowid;
676  $commandestatic->ref = $obj->ref;
677  $commandestatic->statut = $obj->status;
678  $commandestatic->billed = $obj->facture;
679 
680  print '<tr class="oddeven">';
681  print '<td class="nowrap">';
682 
683  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
684  print '<td class="nobordernopadding nowrap">';
685  print $commandestatic->getNomUrl(1);
686  print '</td>';
687  print '<td width="20" class="nobordernopadding nowrap">';
688  print '&nbsp;';
689  print '</td>';
690  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
691  $filename = dol_sanitizeFileName($obj->ref);
692  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
693  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
694  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
695  print '</td></tr></table>';
696 
697  print '</td>';
698 
699  print '<td class="nowrap tdoverflowmax100">';
700  print $societestatic->getNomUrl(1, 'customer');
701  print '</td>';
702  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
703  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
704  }
705  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
706  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
707  print '<td>'.$commandestatic->getLibStatut(3).'</td>';
708  print '</tr>';
709  $tot_ht += $obj->total_ht;
710  $tot_ttc += $obj->total_ttc;
711  //print "x".$tot_ttc."z".$obj->tot_fttc;
712  $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
713  $i++;
714  }
715 
716  if ($othernb) {
717  print '<tr class="oddeven">';
718  print '<td class="nowrap" colspan="5">';
719  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
720  print '</td>';
721  print "</tr>\n";
722  }
723 
724  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>';
725  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
726  print '<td class="right">'.price($tot_ht).'</td>';
727  }
728  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
729  print '<td class="nowrap right">'.price($tot_tobill).'</td>';
730  print '<td>&nbsp;</td>';
731  print '</tr>';
732  print '</table></div><br>';
733  }
734  $db->free($resql);
735  } else {
736  dol_print_error($db);
737  }
738 }
739 
740 
741 // TODO Mettre ici recup des actions en rapport avec la compta
742 $resql = '';
743 if ($resql) {
744  print '<div class="div-table-responsive-no-min">';
745  print '<table class="noborder centpercent">';
746  print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
747  print "</tr>\n";
748  $i = 0;
749  while ($i < $db->num_rows($resql)) {
750  $obj = $db->fetch_object($resql);
751 
752  print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
753  print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
754  $i++;
755  }
756  $db->free($resql);
757  print "</table></div><br>";
758 }
759 
760 
761 print '</div></div>';
762 
763 $parameters = array('user' => $user);
764 $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
765 
766 // End of page
767 llxFooter();
768 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const STATUS_CLOSED
Closed (Sent, billed or not)
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
dol_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices...
Class to manage suppliers invoices.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
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.
Class to manage customers orders.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
Class to manage donations.
Definition: don.class.php:38
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_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:73
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.