dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2020 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8  * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
9  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
10  * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
11  * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
12  * Copyright (C) 2021 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("AccountancyTreasuryArea"));
102 
103 print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', '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') && !empty($user->rights->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') && !empty($user->rights->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  if ($num) {
445  $total_ttc = $totalam = $total_ht = 0;
446 
447  while ($i < $num && $i < $max) {
448  $obj = $db->fetch_object($result);
449 
450  if ($i >= $max) {
451  $othernb += 1;
452  $i++;
453  $total_ht += $obj->total_ht;
454  $total_ttc += $obj->total_ttc;
455  continue;
456  }
457 
458  $donationstatic->id = $obj->rowid;
459  $donationstatic->ref = $obj->rowid;
460  $donationstatic->lastname = $obj->lastname;
461  $donationstatic->firstname = $obj->firstname;
462  $donationstatic->date = $db->jdate($obj->date);
463  $donationstatic->statut = $obj->status;
464  $donationstatic->status = $obj->status;
465 
466  $label = $donationstatic->getFullName($langs);
467  if ($obj->societe) {
468  $label .= ($label ? ' - ' : '').$obj->societe;
469  }
470 
471  print '<tr class="oddeven tdoverflowmax100">';
472  print '<td>'.$donationstatic->getNomUrl(1).'</td>';
473  print '<td>'.$label.'</td>';
474  print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
475  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>';
476  print '<td>'.$donationstatic->getLibStatut(3).'</td>';
477  print '</tr>';
478 
479  $i++;
480  }
481 
482  if ($othernb) {
483  print '<tr class="oddeven">';
484  print '<td class="nowrap" colspan="5">';
485  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
486  print '</td>';
487  print "</tr>\n";
488  }
489  } else {
490  print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
491  }
492  print '</table></div><br>';
493  } else {
494  dol_print_error($db);
495  }
496 }
497 
501 if (isModEnabled('tax') && !empty($user->rights->tax->charges->lire)) {
502  if (!$socid) {
503  $chargestatic = new ChargeSociales($db);
504 
505  $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
506  $sql .= " cc.libelle as label,";
507  $sql .= " SUM(pc.amount) as sumpaid";
508  $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
509  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
510  $sql .= " WHERE c.fk_type = cc.id";
511  $sql .= " AND c.entity IN (".getEntity('tax').')';
512  $sql .= " AND c.paye = 0";
513  // Add where from hooks
514  $parameters = array();
515  $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
516  $sql .= $hookmanager->resPrint;
517 
518  $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
519 
520  $resql = $db->query($sql);
521  if ($resql) {
522  $num = $db->num_rows($resql);
523 
524  print '<div class="div-table-responsive-no-min">';
525  print '<table class="noborder centpercent">';
526  print '<tr class="liste_titre">';
527  print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
528  print '<th align="center">'.$langs->trans("DateDue").'</th>';
529  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
530  print '<th class="right">'.$langs->trans("Paid").'</th>';
531  print '<th align="center" width="16">&nbsp;</th>';
532  print '</tr>';
533  if ($num) {
534  $i = 0;
535  $tot_ttc = 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  $i++;
545  continue;
546  }
547 
548  $chargestatic->id = $obj->rowid;
549  $chargestatic->ref = $obj->rowid;
550  $chargestatic->label = $obj->label;
551  $chargestatic->paye = $obj->paye;
552  $chargestatic->status = $obj->paye;
553 
554  print '<tr class="oddeven">';
555  print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
556  print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
557  print '<td class="nowrap right"><span class="amount">'.price($obj->amount).'</span></td>';
558  print '<td class="nowrap right"><span class="amount">'.price($obj->sumpaid).'</span></td>';
559  print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
560  print '</tr>';
561 
562  $tot_ttc += $obj->amount;
563  $i++;
564  }
565 
566  if ($othernb) {
567  print '<tr class="oddeven">';
568  print '<td class="nowrap" colspan="5">';
569  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
570  print '</td>';
571  print "</tr>\n";
572  }
573 
574  print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
575  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
576  print '<td class="right"></td>';
577  print '<td class="right">&nbsp;</td>';
578  print '</tr>';
579  } else {
580  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
581  }
582  print "</table></div><br>";
583  $db->free($resql);
584  } else {
585  dol_print_error($db);
586  }
587  }
588 }
589 
590 /*
591  * Customers orders to be billed
592  */
593 if (isModEnabled('facture') && isModEnabled('commande') && $user->hasRight("commande", "lire") && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) {
594  $commandestatic = new Commande($db);
595  $langs->load("orders");
596 
597  $sql = "SELECT sum(f.total_ht) as tot_fht, sum(f.total_ttc) as tot_fttc";
598  $sql .= ", s.nom as name, s.email";
599  $sql .= ", s.rowid as socid";
600  $sql .= ", s.code_client, s.code_compta";
601  $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.total_tva, c.total_ttc,";
602  $sql .= " cc.rowid as country_id, cc.code as country_code";
603  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
604  if (empty($user->rights->societe->client->voir) && !$socid) {
605  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
606  }
607  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
608  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
609  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
610  $sql .= " WHERE c.fk_soc = s.rowid";
611  $sql .= " AND c.entity = ".$conf->entity;
612  if (empty($user->rights->societe->client->voir) && !$socid) {
613  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
614  }
615  if ($socid) {
616  $sql .= " AND c.fk_soc = ".((int) $socid);
617  }
618  $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
619  $sql .= " AND c.facture = 0";
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.'&amp;billed=0">';
642  print '<span class="badge">'.$num.'</span>';
643  print '</a>';
644  print '</th>';
645 
646  if (!empty($conf->global->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 = $obj->code_compta;
676  //$societestatic->code_fournisseur = $obj->code_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 (!empty($conf->global->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 (!empty($conf->global->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 $resql = '';
746 if ($resql) {
747  print '<div class="div-table-responsive-no-min">';
748  print '<table class="noborder centpercent">';
749  print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
750  print "</tr>\n";
751  $i = 0;
752  while ($i < $db->num_rows($resql)) {
753  $obj = $db->fetch_object($resql);
754 
755  print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
756  print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
757  $i++;
758  }
759  $db->free($resql);
760  print "</table></div><br>";
761 }
762 
763 
764 print '</div></div>';
765 
766 $parameters = array('user' => $user);
767 $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
768 
769 // End of page
770 llxFooter();
771 $db->close();
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage customers orders.
const STATUS_CLOSED
Closed (Sent, billed or not)
Class to manage donations.
Definition: don.class.php:39
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('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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.
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:71
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