dolibarr  19.0.0-dev
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
36 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
44 require_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'));
55 if (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 = '';
65 if ($user->socid > 0) {
66  $action = '';
67  $socid = $user->socid;
68 }
69 
70 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
71 
72 // Maximum elements of the tables
73 $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
74 $maxLatestEditCount = 5;
75 $maxOpenCount = empty($conf->global->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 = (empty($conf->global->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 
101 llxHeader("", $langs->trans("InvoicesArea"));
102 
103 print load_fiche_titre($langs->trans("InvoicesArea"), '', 'bill');
104 
105 
106 print '<div class="fichecenter"><div class="fichethirdleft">';
107 
108 if (isModEnabled('facture')) {
109  print getNumberInvoicesPieChart('customers');
110  print '<br>';
111 }
112 
113 if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
114  print getNumberInvoicesPieChart('suppliers');
115  print '<br>';
116 }
117 
118 if (isModEnabled('facture')) {
119  print getCustomerInvoiceDraftTable($max, $socid);
120  print '<br>';
121 }
122 
123 if (isModEnabled('fournisseur') || isModEnabled('supplier_invoice')) {
124  print getDraftSupplierTable($max, $socid);
125  print '<br>';
126 }
127 
128 print '</div><div class="fichetwothirdright">';
129 
130 
131 // Latest modified customer invoices
132 if (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 (empty($user->rights->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 (empty($user->rights->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 (!empty($conf->global->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  print '<tr class="oddeven">';
219  print '<td class="nowrap">';
220 
221  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
222 
223  print '<td class="nobordernopadding nowraponall">';
224  print $tmpinvoice->getNomUrl(1, '');
225  print '</td>';
226  if ($tmpinvoice->hasDelay()) {
227  print '<td width="20" class="nobordernopadding nowrap">';
228  print img_warning($langs->trans("Late"));
229  print '</td>';
230  }
231  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
232  $filename = dol_sanitizeFileName($obj->ref);
233  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
234  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
235  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
236  print '</td></tr></table>';
237 
238  print '</td>';
239 
240  print '<td class="tdoverflowmax150">';
241  print $thirdpartystatic->getNomUrl(1, 'customer', 44);
242  print '</td>';
243  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
244  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht).'</span></td>';
245  }
246  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
247 
248  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>';
249 
250  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
251 
252  print '</tr>';
253 
254  $total_ttc += $obj->total_ttc;
255  $total_ht += $obj->total_ht;
256  $totalam += $obj->am;
257 
258  $i++;
259  }
260 
261  if ($othernb) {
262  print '<tr class="oddeven">';
263  print '<td class="nowrap" colspan="5">';
264  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
265  print '</td>';
266  print "</tr>\n";
267  }
268  } else {
269  $colspan = 5;
270  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
271  $colspan++;
272  }
273  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
274  }
275  print '</table></div><br>';
276  $db->free($resql);
277  } else {
278  dol_print_error($db);
279  }
280 }
281 
282 
283 // Last modified supplier invoices
284 if ((isModEnabled('fournisseur') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire")) || (isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) {
285  $langs->load("boxes");
286  $facstatic = new FactureFournisseur($db);
287 
288  $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";
289  $sql .= ", s.nom as name";
290  $sql .= ", s.rowid as socid";
291  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
292  $sql .= ", SUM(pf.amount) as am";
293  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
294  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
295  if (empty($user->rights->societe->client->voir) && !$socid) {
296  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
297  }
298  $sql .= " WHERE s.rowid = ff.fk_soc";
299  $sql .= " AND ff.entity = ".$conf->entity;
300  if (empty($user->rights->societe->client->voir) && !$socid) {
301  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
302  }
303  if ($socid) {
304  $sql .= " AND ff.fk_soc = ".((int) $socid);
305  }
306  // Add where from hooks
307  $parameters = array();
308  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
309  $sql .= $hookmanager->resPrint;
310 
311  $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,";
312  $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
313  $sql .= " ORDER BY ff.tms DESC ";
314  $sql .= $db->plimit($max, 0);
315 
316  $resql = $db->query($sql);
317  if ($resql) {
318  $num = $db->num_rows($resql);
319 
320  print '<div class="div-table-responsive-no-min">';
321  print '<table class="noborder centpercent">';
322  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
323  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
324  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
325  }
326  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
327  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
328  print '<th width="16">&nbsp;</th>';
329  print "</tr>\n";
330  if ($num) {
331  $i = 0;
332  $total_ht = $total_ttc = $totalam = 0;
333  $othernb = 0;
334 
335  while ($i < $num) {
336  $obj = $db->fetch_object($resql);
337 
338  if ($i >= $max) {
339  $othernb += 1;
340  $i++;
341  $total_ht += $obj->total_ht;
342  $total_ttc += $obj->total_ttc;
343  continue;
344  }
345 
346  $facstatic->ref = $obj->ref;
347  $facstatic->id = $obj->rowid;
348  $facstatic->total_ht = $obj->total_ht;
349  $facstatic->total_tva = $obj->total_tva;
350  $facstatic->total_ttc = $obj->total_ttc;
351  $facstatic->statut = $obj->status;
352  $facstatic->paye = $obj->paye;
353  $facstatic->type = $obj->type;
354  $facstatic->ref_supplier = $obj->ref_supplier;
355 
356  $thirdpartystatic->id = $obj->socid;
357  $thirdpartystatic->name = $obj->name;
358  $thirdpartystatic->email = $obj->email;
359  $thirdpartystatic->country_id = 0;
360  $thirdpartystatic->country_code = '';
361  $thirdpartystatic->client = 0;
362  $thirdpartystatic->fournisseur = 1;
363  $thirdpartystatic->code_client = '';
364  $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
365  $thirdpartystatic->code_compta = '';
366  $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
367 
368  print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
369  print $facstatic->getNomUrl(1, '');
370  print '</td>';
371  print '<td class="nowrap tdoverflowmax100">';
372  print $thirdpartystatic->getNomUrl(1, 'supplier');
373  print '</td>';
374  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
375  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
376  }
377  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
378  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>';
379  $alreadypaid = $facstatic->getSommePaiement();
380  print '<td>'.$facstatic->getLibStatut(3, $alreadypaid).'</td>';
381  print '</tr>';
382  $total_ht += $obj->total_ht;
383  $total_ttc += $obj->total_ttc;
384  $totalam += $obj->am;
385  $i++;
386  }
387 
388  if ($othernb) {
389  print '<tr class="oddeven">';
390  print '<td class="nowrap" colspan="5">';
391  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
392  print '</td>';
393  print "</tr>\n";
394  }
395  } else {
396  $colspan = 5;
397  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
398  $colspan++;
399  }
400  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
401  }
402  print '</table></div><br>';
403  } else {
404  dol_print_error($db);
405  }
406 }
407 
408 
409 
410 // Latest donations
411 if (isModEnabled('don') && $user->hasRight('don', 'lire')) {
412  include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
413 
414  $langs->load("boxes");
415  $donationstatic = new Don($db);
416 
417  $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";
418  $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
419  $sql .= " WHERE d.entity IN (".getEntity('donation').")";
420  // Add where from hooks
421  $parameters = array();
422  $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
423  $sql .= $hookmanager->resPrint;
424 
425  $sql .= $db->order("d.tms", "DESC");
426  $sql .= $db->plimit($max, 0);
427 
428  $result = $db->query($sql);
429  if ($result) {
430  $num = $db->num_rows($result);
431 
432  $i = 0;
433  $othernb = 0;
434 
435  print '<div class="div-table-responsive-no-min">';
436  print '<table class="noborder centpercent">';
437  print '<tr class="liste_titre">';
438  print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
439  print '<th></th>';
440  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
441  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
442  print '<th width="16">&nbsp;</th>';
443  print '</tr>';
444 
445  if ($num) {
446  $total_ttc = $totalam = $total_ht = 0;
447 
448  while ($i < $num && $i < $max) {
449  $obj = $db->fetch_object($result);
450 
451  if ($i >= $max) {
452  $othernb += 1;
453  $i++;
454  $total_ht += $obj->total_ht;
455  $total_ttc += $obj->total_ttc;
456  continue;
457  }
458 
459  $donationstatic->id = $obj->rowid;
460  $donationstatic->ref = $obj->rowid;
461  $donationstatic->lastname = $obj->lastname;
462  $donationstatic->firstname = $obj->firstname;
463  $donationstatic->date = $db->jdate($obj->date);
464  $donationstatic->statut = $obj->status;
465  $donationstatic->status = $obj->status;
466 
467  $label = $donationstatic->getFullName($langs);
468  if ($obj->societe) {
469  $label .= ($label ? ' - ' : '').$obj->societe;
470  }
471 
472  print '<tr class="oddeven tdoverflowmax100">';
473  print '<td>'.$donationstatic->getNomUrl(1).'</td>';
474  print '<td>'.$label.'</td>';
475  print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
476  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>';
477  print '<td>'.$donationstatic->getLibStatut(3).'</td>';
478  print '</tr>';
479 
480  $i++;
481  }
482 
483  if ($othernb) {
484  print '<tr class="oddeven">';
485  print '<td class="nowrap" colspan="5">';
486  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
487  print '</td>';
488  print "</tr>\n";
489  }
490  } else {
491  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
492  }
493  print '</table></div><br>';
494  } else {
495  dol_print_error($db);
496  }
497 }
498 
502 if (isModEnabled('tax') && !empty($user->rights->tax->charges->lire)) {
503  if (!$socid) {
504  $chargestatic = new ChargeSociales($db);
505 
506  $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
507  $sql .= " cc.libelle as label,";
508  $sql .= " SUM(pc.amount) as sumpaid";
509  $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
510  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
511  $sql .= " WHERE c.fk_type = cc.id";
512  $sql .= " AND c.entity IN (".getEntity('tax').')';
513  $sql .= " AND c.paye = 0";
514  // Add where from hooks
515  $parameters = array();
516  $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
517  $sql .= $hookmanager->resPrint;
518 
519  $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
520 
521  $resql = $db->query($sql);
522  if ($resql) {
523  $num = $db->num_rows($resql);
524 
525  print '<div class="div-table-responsive-no-min">';
526  print '<table class="noborder centpercent">';
527  print '<tr class="liste_titre">';
528  print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
529  print '<th align="center">'.$langs->trans("DateDue").'</th>';
530  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
531  print '<th class="right">'.$langs->trans("Paid").'</th>';
532  print '<th align="center" width="16">&nbsp;</th>';
533  print '</tr>';
534  if ($num) {
535  $i = 0;
536  $tot_ttc = 0;
537  $othernb = 0;
538 
539  while ($i < $num) {
540  $obj = $db->fetch_object($resql);
541 
542  if ($i >= $max) {
543  $othernb += 1;
544  $tot_ttc += $obj->amount;
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="right"></td>';
578  print '<td class="right">&nbsp;</td>';
579  print '</tr>';
580  } else {
581  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</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('facture') && isModEnabled('commande') && $user->hasRight("commande", "lire") && empty($conf->global->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  if (empty($user->rights->societe->client->voir) && !$socid) {
606  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
607  }
608  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
609  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
610  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
611  $sql .= " WHERE c.fk_soc = s.rowid";
612  $sql .= " AND c.entity = ".$conf->entity;
613  if (empty($user->rights->societe->client->voir) && !$socid) {
614  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
615  }
616  if ($socid) {
617  $sql .= " AND c.fk_soc = ".((int) $socid);
618  }
619  $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
620  $sql .= " AND c.facture = 0";
621  // Add where from hooks
622  $parameters = array();
623  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
624  $sql .= $hookmanager->resPrint;
625 
626  $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";
627 
628  $resql = $db->query($sql);
629  if ($resql) {
630  $num = $db->num_rows($resql);
631 
632  if ($num) {
633  $i = 0;
634  $othernb = 0;
635 
636  print '<div class="div-table-responsive-no-min">';
637  print '<table class="noborder centpercent">';
638 
639  print "<tr class=\"liste_titre\">";
640  print '<th colspan="2">';
641  print $langs->trans("OrdersDeliveredToBill").' ';
642  print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
643  print '<span class="badge">'.$num.'</span>';
644  print '</a>';
645  print '</th>';
646 
647  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
648  print '<th class="right">'.$langs->trans("AmountHT").'</th>';
649  }
650  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
651  print '<th class="right">'.$langs->trans("ToBill").'</th>';
652  print '<th align="center" width="16">&nbsp;</th>';
653  print '</tr>';
654 
655  $tot_ht = $tot_ttc = $tot_tobill = 0;
656  $societestatic = new Societe($db);
657  while ($i < $num) {
658  $obj = $db->fetch_object($resql);
659 
660  if ($i >= $max) {
661  $othernb += 1;
662  $i++;
663  $total_ht += $obj->total_ht;
664  $total_ttc += $obj->total_ttc;
665  continue;
666  }
667 
668  $societestatic->id = $obj->socid;
669  $societestatic->name = $obj->name;
670  $societestatic->email = $obj->email;
671  $societestatic->country_id = $obj->country_id;
672  $societestatic->country_code = $obj->country_code;
673  $societestatic->client = 1;
674  $societestatic->code_client = $obj->code_client;
675  //$societestatic->code_fournisseur = $obj->code_fournisseur;
676  $societestatic->code_compta = $obj->code_compta;
677  //$societestatic->code_fournisseur = $obj->code_fournisseur;
678 
679  $commandestatic->id = $obj->rowid;
680  $commandestatic->ref = $obj->ref;
681  $commandestatic->statut = $obj->status;
682  $commandestatic->billed = $obj->facture;
683 
684  print '<tr class="oddeven">';
685  print '<td class="nowrap">';
686 
687  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
688  print '<td class="nobordernopadding nowrap">';
689  print $commandestatic->getNomUrl(1);
690  print '</td>';
691  print '<td width="20" class="nobordernopadding nowrap">';
692  print '&nbsp;';
693  print '</td>';
694  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
695  $filename = dol_sanitizeFileName($obj->ref);
696  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
697  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
698  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
699  print '</td></tr></table>';
700 
701  print '</td>';
702 
703  print '<td class="nowrap tdoverflowmax100">';
704  print $societestatic->getNomUrl(1, 'customer');
705  print '</td>';
706  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
707  print '<td class="right"><span class="amount">'.price($obj->total_ht).'</span></td>';
708  }
709  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc).'</span></td>';
710  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc - $obj->tot_fttc).'</span></td>';
711  print '<td>'.$commandestatic->getLibStatut(3).'</td>';
712  print '</tr>';
713  $tot_ht += $obj->total_ht;
714  $tot_ttc += $obj->total_ttc;
715  //print "x".$tot_ttc."z".$obj->tot_fttc;
716  $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
717  $i++;
718  }
719 
720  if ($othernb) {
721  print '<tr class="oddeven">';
722  print '<td class="nowrap" colspan="5">';
723  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
724  print '</td>';
725  print "</tr>\n";
726  }
727 
728  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>';
729  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) {
730  print '<td class="right">'.price($tot_ht).'</td>';
731  }
732  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
733  print '<td class="nowrap right">'.price($tot_tobill).'</td>';
734  print '<td>&nbsp;</td>';
735  print '</tr>';
736  print '</table></div><br>';
737  }
738  $db->free($resql);
739  } else {
740  dol_print_error($db);
741  }
742 }
743 
744 
745 // TODO Mettre ici recup des actions en rapport avec la compta
746 $sql = '';
747 if ($sql) {
748  print '<div class="div-table-responsive-no-min">';
749  print '<table class="noborder centpercent">';
750  print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
751  print "</tr>\n";
752  $i = 0;
753  $resql = $db->query($sql);
754  if ($resql) {
755  $num_rows = $db->num_rows($resql);
756  while ($i < $num_rows) {
757  $obj = $db->fetch_object($resql);
758 
759  print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
760  print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
761  $i++;
762  }
763  $db->free($resql);
764  }
765  print "</table></div><br>";
766 }
767 
768 
769 print '</div></div>';
770 
771 $parameters = array('user' => $user);
772 $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
773 
774 // End of page
775 llxFooter();
776 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:51
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1323
ChargeSociales
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Definition: chargesociales.class.php:34
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:51
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
Commande\STATUS_CLOSED
const STATUS_CLOSED
Closed (Sent, billed or not)
Definition: commande.class.php:408
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4784
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Don
Class to manage donations.
Definition: don.class.php:39
Facture
Class to manage invoices.
Definition: facture.class.php:60
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
getCustomerInvoiceDraftTable
getCustomerInvoiceDraftTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
Definition: invoice.lib.php:486
Commande
Class to manage customers orders.
Definition: commande.class.php:47
getNumberInvoicesPieChart
getNumberInvoicesPieChart($mode)
Return an HTML table that contains a pie chart of the number of customers or supplier invoices.
Definition: invoice.lib.php:343
llxHeader
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:63
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->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') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
price
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.
Definition: functions.lib.php:5829
getDraftSupplierTable
getDraftSupplierTable($maxCount=500, $socid=0)
Return a HTML table that contains a list with customer invoice drafts.
Definition: invoice.lib.php:636