dolibarr  13.0.2
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-2013 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  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
40 
41 // L'espace compta/treso doit toujours etre actif car c'est un espace partage
42 // par de nombreux modules (banque, facture, commande a facturer, etc...) independamment
43 // de l'utilisation de la compta ou non. C'est au sein de cet espace que chaque sous fonction
44 // est protegee par le droit qui va bien du module concerne.
45 //if (!$user->rights->compta->general->lire)
46 // accessforbidden();
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array('compta', 'bills'));
50 if (!empty($conf->commande->enabled))
51  $langs->load("orders");
52 
53 $action = GETPOST('action', 'aZ09');
54 $bid = GETPOST('bid', 'int');
55 
56 // Security check
57 $socid = '';
58 if ($user->socid > 0)
59 {
60  $action = '';
61  $socid = $user->socid;
62 }
63 
64 $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
65 
66 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
67 $hookmanager->initHooks(array('invoiceindex'));
68 
69 /*
70  * Actions
71  */
72 
73 
74 /*
75  * View
76  */
77 
78 $now = dol_now();
79 
80 $form = new Form($db);
81 $formfile = new FormFile($db);
82 $thirdpartystatic = new Societe($db);
83 
84 llxHeader("", $langs->trans("AccountancyTreasuryArea"));
85 
86 print load_fiche_titre($langs->trans("AccountancyTreasuryArea"), '', 'bill');
87 
88 
89 print '<div class="fichecenter"><div class="fichethirdleft">';
90 
91 
92 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
93 {
94  // Search customer invoices
95  if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
96  {
97  $listofsearchfields['search_invoice'] = array('text'=>'CustomerInvoice');
98  }
99  // Search supplier invoices
100  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->lire)
101  {
102  $listofsearchfields['search_supplier_invoice'] = array('text'=>'SupplierInvoice');
103  }
104  if (!empty($conf->don->enabled) && $user->rights->don->lire)
105  {
106  $langs->load("donations");
107  $listofsearchfields['search_donation'] = array('text'=>'Donation');
108  }
109 
110  if (count($listofsearchfields))
111  {
112  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
113  print '<input type="hidden" name="token" value="'.newToken().'">';
114  print '<div class="div-table-responsive-no-min">';
115  print '<table class="noborder nohover centpercent">';
116  $i = 0;
117  foreach ($listofsearchfields as $key => $value)
118  {
119  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
120  print '<tr '.$bc[false].'>';
121  print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'"></td>';
122  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
123  print '</tr>';
124  $i++;
125  }
126  print '</table>';
127  print '</div>';
128  print '</form>';
129  print '<br>';
130  }
131 }
132 
133 
137 if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
138 {
139  $tmpinvoice = new Facture($db);
140 
141  $sql = "SELECT f.rowid, f.ref, f.datef as date, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.ref_client";
142  $sql .= ", f.type, f.fk_statut as status, f.paye";
143  $sql .= ", s.nom as name";
144  $sql .= ", s.rowid as socid, s.email";
145  $sql .= ", s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur";
146  $sql .= ", cc.rowid as country_id, cc.code as country_code";
147  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
148  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
149  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
150  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".Facture::STATUS_DRAFT;
151  $sql .= " AND f.entity IN (".getEntity('invoice').")";
152  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
153 
154  if ($socid)
155  {
156  $sql .= " AND f.fk_soc = $socid";
157  }
158  // Add where from hooks
159  $parameters = array();
160  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerDraft', $parameters);
161  $sql .= $hookmanager->resPrint;
162 
163  $sql .= " GROUP BY f.rowid, f.ref, f.datef, f.total, f.tva, f.total_ttc, f.ref_client, f.type, f.fk_statut, f.paye,";
164  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, s.code_fournisseur, s.code_compta_fournisseur,";
165  $sql .= " cc.rowid, cc.code";
166  if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user";
167 
168  // Add Group from hooks
169  $parameters = array();
170  $reshook = $hookmanager->executeHooks('printFieldListGroupByCustomerDraft', $parameters);
171  $sql .= $hookmanager->resPrint;
172 
173  $resql = $db->query($sql);
174 
175  if ($resql)
176  {
177  $num = $db->num_rows($resql);
178 
179  print '<div class="div-table-responsive-no-min">';
180  print '<table class="noborder centpercent">';
181 
182  print '<tr class="liste_titre">';
183  print '<th colspan="3">';
184  print $langs->trans("CustomersDraftInvoices").' ';
185  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_DRAFT.'">';
186  print '<span class="badge marginleftonlyshort">'.$num.'</span>';
187  print '</a>';
188  print '</th>';
189  print '</tr>';
190 
191  if ($num)
192  {
193  $companystatic = new Societe($db);
194 
195  $i = 0;
196  $tot_ttc = 0;
197  while ($i < $num)
198  {
199  $obj = $db->fetch_object($resql);
200 
201  $tmpinvoice->id = $obj->rowid;
202  $tmpinvoice->ref = $obj->ref;
203  $tmpinvoice->date = $db->jdate($obj->date);
204  $tmpinvoice->type = $obj->type;
205  $tmpinvoice->total_ht = $obj->total_ht;
206  $tmpinvoice->total_tva = $obj->total_tva;
207  $tmpinvoice->total_ttc = $obj->total_ttc;
208  $tmpinvoice->ref_client = $obj->ref_client;
209  $tmpinvoice->statut = $obj->status;
210  $tmpinvoice->paye = $obj->paye;
211 
212  $companystatic->id = $obj->socid;
213  $companystatic->name = $obj->name;
214  $companystatic->email = $obj->email;
215  $companystatic->country_id = $obj->country_id;
216  $companystatic->country_code = $obj->country_code;
217  $companystatic->client = 1;
218  $companystatic->code_client = $obj->code_client;
219  $companystatic->code_fournisseur = $obj->code_fournisseur;
220  $companystatic->code_compta = $obj->code_compta;
221  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
222 
223  print '<tr class="oddeven"><td class="nowrap tdoverflowmax100">';
224  print $tmpinvoice->getNomUrl(1, '');
225  print '</td>';
226  print '<td class="nowrap tdoverflowmax100">';
227  print $companystatic->getNomUrl(1, 'customer');
228  print '</td>';
229  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
230  print '</tr>';
231  $tot_ttc += $obj->total_ttc;
232  $i++;
233  }
234 
235  print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
236  print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
237  print '</tr>';
238  } else {
239  print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
240  }
241  print "</table></div><br>";
242  $db->free($resql);
243  } else {
244  dol_print_error($db);
245  }
246 }
247 
251 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
252 {
253  $facturesupplierstatic = new FactureFournisseur($db);
254 
255  $sql = "SELECT f.ref, f.rowid, f.total_ht, f.total_tva, f.total_ttc, f.type, f.ref_supplier, f.fk_statut as status, f.paye";
256  $sql .= ", s.nom as name";
257  $sql .= ", s.rowid as socid, s.email";
258  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
259  $sql .= ", cc.rowid as country_id, cc.code as country_code";
260  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
261  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
262  $sql .= " WHERE s.rowid = f.fk_soc AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
263  $sql .= " AND f.entity IN (".getEntity('invoice').')';
264  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
265  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
266  // Add where from hooks
267  $parameters = array();
268  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierDraft', $parameters);
269  $sql .= $hookmanager->resPrint;
270  $resql = $db->query($sql);
271 
272  if ($resql)
273  {
274  $num = $db->num_rows($resql);
275 
276  print '<div class="div-table-responsive-no-min">';
277  print '<table class="noborder centpercent">';
278 
279  print '<tr class="liste_titre">';
280  print '<th colspan="3">';
281  print $langs->trans("SuppliersDraftInvoices").' ';
282  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_DRAFT.'">';
283  print '<span class="badge marginleftonlyshort">'.$num.'</span>';
284  print '</a>';
285  print '</th>';
286  print '</tr>';
287 
288  if ($num)
289  {
290  $companystatic = new Societe($db);
291 
292  $i = 0;
293  $tot_ttc = 0;
294  while ($i < $num)
295  {
296  $obj = $db->fetch_object($resql);
297 
298  $facturesupplierstatic->ref = $obj->ref;
299  $facturesupplierstatic->id = $obj->rowid;
300  $facturesupplierstatic->total_ht = $obj->total_ht;
301  $facturesupplierstatic->total_tva = $obj->total_tva;
302  $facturesupplierstatic->total_ttc = $obj->total_ttc;
303  $facturesupplierstatic->ref_supplier = $obj->ref_supplier;
304  $facturesupplierstatic->type = $obj->type;
305  $facturesupplierstatic->statut = $obj->status;
306  $facturesupplierstatic->paye = $obj->paye;
307 
308  $companystatic->id = $obj->socid;
309  $companystatic->name = $obj->name;
310  $companystatic->email = $obj->email;
311  $companystatic->country_id = $obj->country_id;
312  $companystatic->country_code = $obj->country_code;
313  $companystatic->fournisseur = 1;
314  $companystatic->code_client = $obj->code_client;
315  $companystatic->code_fournisseur = $obj->code_fournisseur;
316  $companystatic->code_compta = $obj->code_compta;
317  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
318 
319  print '<tr class="oddeven"><td class="nowrap tdoverflowmax100">';
320  print $facturesupplierstatic->getNomUrl(1, '');
321  print '</td>';
322  print '<td class="nowrap tdoverflowmax100">';
323  print $companystatic->getNomUrl(1, 'supplier');
324  print '</td>';
325  print '<td class="right">'.price($obj->total_ttc).'</td>';
326  print '</tr>';
327  $tot_ttc += $obj->total_ttc;
328  $i++;
329  }
330 
331  print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
332  print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
333  print '</tr>';
334  } else {
335  print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
336  }
337  print "</table></div><br>";
338  $db->free($resql);
339  } else {
340  dol_print_error($db);
341  }
342 }
343 
344 
345 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
346 
347 
348 // Latest modified customer invoices
349 if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
350 {
351  $langs->load("boxes");
352  $tmpinvoice = new Facture($db);
353 
354  $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms";
355  $sql .= ", f.date_lim_reglement as datelimite";
356  $sql .= ", s.nom as name";
357  $sql .= ", s.rowid as socid";
358  $sql .= ", s.code_client, s.code_compta, s.email";
359  $sql .= ", cc.rowid as country_id, cc.code as country_code";
360  $sql .= ", sum(pf.amount) as am";
361  $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";
362  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
363  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
364  $sql .= " WHERE s.rowid = f.fk_soc";
365  $sql .= " AND f.entity IN (".getEntity('invoice').")";
366  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
367  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
368  // Add where from hooks
369  $parameters = array();
370  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerLastModified', $parameters);
371  $sql .= $hookmanager->resPrint;
372 
373  $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
374  $sql .= " s.nom, s.rowid, s.code_client, s.code_compta, s.email,";
375  $sql .= " cc.rowid, cc.code";
376  $sql .= " ORDER BY f.tms DESC";
377  $sql .= $db->plimit($max, 0);
378 
379  $resql = $db->query($sql);
380  if ($resql)
381  {
382  $num = $db->num_rows($resql);
383  $i = 0;
384  $othernb = 0;
385 
386  print '<div class="div-table-responsive-no-min">';
387  print '<table class="noborder centpercent">';
388  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("BoxTitleLastCustomerBills", $max).'</th>';
389  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
390  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
391  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
392  print '<th width="16">&nbsp;</th>';
393  print '</tr>';
394  if ($num)
395  {
396  $total_ttc = $totalam = $total = 0;
397  while ($i < $num && $i < $conf->liste_limit)
398  {
399  $obj = $db->fetch_object($resql);
400 
401  if ($i >= $max) {
402  $othernb += 1;
403  $i++;
404  $total += $obj->total_ht;
405  $total_ttc += $obj->total_ttc;
406  continue;
407  }
408 
409  $tmpinvoice->ref = $obj->ref;
410  $tmpinvoice->id = $obj->rowid;
411  $tmpinvoice->total_ht = $obj->total_ht;
412  $tmpinvoice->total_tva = $obj->total_tva;
413  $tmpinvoice->total_ttc = $obj->total_ttc;
414  $tmpinvoice->statut = $obj->status;
415  $tmpinvoice->paye = $obj->paye;
416  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
417  $tmpinvoice->type = $obj->type;
418 
419  $thirdpartystatic->id = $obj->socid;
420  $thirdpartystatic->name = $obj->name;
421  $thirdpartystatic->email = $obj->email;
422  $thirdpartystatic->country_id = $obj->country_id;
423  $thirdpartystatic->country_code = $obj->country_code;
424  $thirdpartystatic->email = $obj->email;
425  $thirdpartystatic->client = 1;
426  $thirdpartystatic->code_client = $obj->code_client;
427  //$thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
428  $thirdpartystatic->code_compta = $obj->code_compta;
429  //$thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
430 
431  print '<tr class="oddeven">';
432  print '<td class="nowrap">';
433 
434  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
435  print '<td class="nobordernopadding nowraponall">';
436  print $tmpinvoice->getNomUrl(1, '');
437  print '</td>';
438  print '<td width="20" class="nobordernopadding nowrap">';
439  if ($tmpinvoice->hasDelay()) {
440  print img_warning($langs->trans("Late"));
441  }
442  print '</td>';
443  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
444  $filename = dol_sanitizeFileName($obj->ref);
445  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
446  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
447  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
448  print '</td></tr></table>';
449 
450  print '</td>';
451  print '<td class="left">';
452  print $thirdpartystatic->getNomUrl(1, 'customer', 44);
453  print '</td>';
454  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="nowrap right">'.price($obj->total_ht).'</td>';
455  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
456  print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
457  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
458  print '</tr>';
459 
460  $total_ttc += $obj->total_ttc;
461  $total += $obj->total_ht;
462  $totalam += $obj->am;
463 
464  $i++;
465  }
466 
467  if ($othernb) {
468  print '<tr class="oddeven">';
469  print '<td class="nowrap" colspan="5">';
470  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
471  print '</td>';
472  print "</tr>\n";
473  }
474  } else {
475  $colspan = 5;
476  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
477  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
478  }
479  print '</table></div><br>';
480  $db->free($resql);
481  } else {
482  dol_print_error($db);
483  }
484 }
485 
486 
487 
488 // Last modified supplier invoices
489 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
490 {
491  $langs->load("boxes");
492  $facstatic = new FactureFournisseur($db);
493 
494  $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.libelle, ff.total_ht, ff.total_tva, ff.total_ttc, ff.tms, ff.paye";
495  $sql .= ", s.nom as name";
496  $sql .= ", s.rowid as socid";
497  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.email";
498  $sql .= ", SUM(pf.amount) as am";
499  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
500  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
501  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
502  $sql .= " WHERE s.rowid = ff.fk_soc";
503  $sql .= " AND ff.entity = ".$conf->entity;
504  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
505  if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
506  // Add where from hooks
507  $parameters = array();
508  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierLastModified', $parameters);
509  $sql .= $hookmanager->resPrint;
510 
511  $sql .= " GROUP BY ff.rowid, ff.ref, ff.fk_statut, ff.libelle, ff.total_ht, ff.tva, ff.total_tva, ff.total_ttc, ff.tms, ff.paye,";
512  $sql .= " s.nom, s.rowid, s.code_fournisseur, s.code_compta_fournisseur, s.email";
513  $sql .= " ORDER BY ff.tms DESC ";
514  $sql .= $db->plimit($max, 0);
515 
516  $resql = $db->query($sql);
517  if ($resql)
518  {
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"><th colspan="2">'.$langs->trans("BoxTitleLastSupplierBills", $max).'</th>';
524  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
525  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
526  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
527  print '<th width="16">&nbsp;</th>';
528  print "</tr>\n";
529  if ($num)
530  {
531  $i = 0;
532  $total = $total_ttc = $totalam = 0;
533  $othernb = 0;
534 
535  while ($i < $num)
536  {
537  $obj = $db->fetch_object($resql);
538 
539  if ($i >= $max) {
540  $othernb += 1;
541  $i++;
542  $total += $obj->total_ht;
543  $total_ttc += $obj->total_ttc;
544  continue;
545  }
546 
547  $facstatic->ref = $obj->ref;
548  $facstatic->id = $obj->rowid;
549  $facstatic->total_ht = $obj->total_ht;
550  $facstatic->total_tva = $obj->total_tva;
551  $facstatic->total_ttc = $obj->total_ttc;
552  $facstatic->statut = $obj->status;
553  $facstatic->paye = $obj->paye;
554 
555  $thirdpartystatic->id = $obj->socid;
556  $thirdpartystatic->name = $obj->name;
557  $thirdpartystatic->email = $obj->email;
558  $thirdpartystatic->country_id = 0;
559  $thirdpartystatic->country_code = '';
560  $thirdpartystatic->client = 0;
561  $thirdpartystatic->fournisseur = 1;
562  $thirdpartystatic->code_client = '';
563  $thirdpartystatic->code_fournisseur = $obj->code_fournisseur;
564  $thirdpartystatic->code_compta = '';
565  $thirdpartystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
566 
567  print '<tr class="oddeven nowraponall tdoverflowmax100"><td>';
568  print $facstatic->getNomUrl(1, '');
569  print '</td>';
570  print '<td class="nowrap tdoverflowmax100">';
571  print $thirdpartystatic->getNomUrl(1, 'supplier');
572  print '</td>';
573  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
574  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
575  print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
576  print '<td>'.$facstatic->getLibStatut(3).'</td>';
577  print '</tr>';
578  $total += $obj->total_ht;
579  $total_ttc += $obj->total_ttc;
580  $totalam += $obj->am;
581  $i++;
582  }
583 
584  if ($othernb) {
585  print '<tr class="oddeven">';
586  print '<td class="nowrap" colspan="5">';
587  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
588  print '</td>';
589  print "</tr>\n";
590  }
591  } else {
592  $colspan = 5;
593  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
594  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
595  }
596  print '</table></div><br>';
597  } else {
598  dol_print_error($db);
599  }
600 }
601 
602 
603 
604 // Latest donations
605 if (!empty($conf->don->enabled) && $user->rights->don->lire)
606 {
607  include_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
608 
609  $langs->load("boxes");
610  $donationstatic = new Don($db);
611 
612  $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";
613  $sql .= " FROM ".MAIN_DB_PREFIX."don as d";
614  $sql .= " WHERE d.entity IN (".getEntity('donation').")";
615  // Add where from hooks
616  $parameters = array();
617  $reshook = $hookmanager->executeHooks('printFieldListWhereLastDonations', $parameters);
618  $sql .= $hookmanager->resPrint;
619 
620  $sql .= $db->order("d.tms", "DESC");
621  $sql .= $db->plimit($max, 0);
622 
623  $result = $db->query($sql);
624  if ($result)
625  {
626  $num = $db->num_rows($result);
627 
628  $i = 0;
629  $othernb = 0;
630 
631  print '<div class="div-table-responsive-no-min">';
632  print '<table class="noborder centpercent">';
633  print '<tr class="liste_titre">';
634  print '<th>'.$langs->trans("BoxTitleLastModifiedDonations", $max).'</th>';
635  print '<th></th>';
636  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
637  print '<th class="right">'.$langs->trans("DateModificationShort").'</th>';
638  print '<th width="16">&nbsp;</th>';
639  print '</tr>';
640  if ($num)
641  {
642  $total_ttc = $totalam = $total = 0;
643 
644  while ($i < $num && $i < $max)
645  {
646  $objp = $db->fetch_object($result);
647 
648  if ($i >= $max) {
649  $othernb += 1;
650  $i++;
651  $total += $obj->total_ht;
652  $total_ttc += $obj->total_ttc;
653  continue;
654  }
655 
656  $donationstatic->id = $objp->rowid;
657  $donationstatic->ref = $objp->rowid;
658  $donationstatic->lastname = $objp->lastname;
659  $donationstatic->firstname = $objp->firstname;
660  $donationstatic->date = $objp->date;
661  $donationstatic->statut = $objp->status;
662  $donationstatic->status = $objp->status;
663 
664  $label = $donationstatic->getFullName($langs);
665  if ($objp->societe) $label .= ($label ? ' - ' : '').$objp->societe;
666 
667  print '<tr class="oddeven tdoverflowmax100">';
668  print '<td>'.$donationstatic->getNomUrl(1).'</td>';
669  print '<td>'.$label.'</td>';
670  print '<td class="nowrap right">'.price($objp->amount).'</td>';
671  print '<td class="right">'.dol_print_date($db->jdate($objp->dm), 'day').'</td>';
672  print '<td>'.$donationstatic->getLibStatut(3).'</td>';
673  print '</tr>';
674 
675  $i++;
676  }
677 
678  if ($othernb) {
679  print '<tr class="oddeven">';
680  print '<td class="nowrap" colspan="5">';
681  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
682  print '</td>';
683  print "</tr>\n";
684  }
685  } else {
686  print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
687  }
688  print '</table></div><br>';
689  } else dol_print_error($db);
690 }
691 
695 if (!empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
696 {
697  if (!$socid)
698  {
699  $chargestatic = new ChargeSociales($db);
700 
701  $sql = "SELECT c.rowid, c.amount, c.date_ech, c.paye,";
702  $sql .= " cc.libelle as label,";
703  $sql .= " SUM(pc.amount) as sumpaid";
704  $sql .= " FROM (".MAIN_DB_PREFIX."c_chargesociales as cc, ".MAIN_DB_PREFIX."chargesociales as c)";
705  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = c.rowid";
706  $sql .= " WHERE c.fk_type = cc.id";
707  $sql .= " AND c.entity IN (".getEntity('tax').')';
708  $sql .= " AND c.paye = 0";
709  // Add where from hooks
710  $parameters = array();
711  $reshook = $hookmanager->executeHooks('printFieldListWhereSocialContributions', $parameters);
712  $sql .= $hookmanager->resPrint;
713 
714  $sql .= " GROUP BY c.rowid, c.amount, c.date_ech, c.paye, cc.libelle";
715 
716  $resql = $db->query($sql);
717  if ($resql)
718  {
719  $num = $db->num_rows($resql);
720 
721  print '<div class="div-table-responsive-no-min">';
722  print '<table class="noborder centpercent">';
723  print '<tr class="liste_titre">';
724  print '<th>'.$langs->trans("ContributionsToPay").($num ? ' <a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?status=0"><span class="badge">'.$num.'</span></a>' : '').'</th>';
725  print '<th align="center">'.$langs->trans("DateDue").'</th>';
726  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
727  print '<th class="right">'.$langs->trans("Paid").'</th>';
728  print '<th align="center" width="16">&nbsp;</th>';
729  print '</tr>';
730  if ($num)
731  {
732  $i = 0;
733  $tot_ttc = 0;
734  $othernb = 0;
735 
736  while ($i < $num)
737  {
738  $obj = $db->fetch_object($resql);
739 
740  if ($i >= $max) {
741  $othernb += 1;
742  $i++;
743  $total += $obj->total_ht;
744  $total_ttc += $obj->total_ttc;
745  continue;
746  }
747 
748  $chargestatic->id = $obj->rowid;
749  $chargestatic->ref = $obj->rowid;
750  $chargestatic->label = $obj->label;
751  $chargestatic->paye = $obj->paye;
752  $chargestatic->status = $obj->paye;
753 
754  print '<tr class="oddeven">';
755  print '<td class="nowraponall">'.$chargestatic->getNomUrl(1).'</td>';
756  print '<td class="center">'.dol_print_date($db->jdate($obj->date_ech), 'day').'</td>';
757  print '<td class="nowrap right">'.price($obj->amount).'</td>';
758  print '<td class="nowrap right">'.price($obj->sumpaid).'</td>';
759  print '<td class="center">'.$chargestatic->getLibStatut(3).'</td>';
760  print '</tr>';
761 
762  $tot_ttc += $obj->amount;
763  $i++;
764  }
765 
766  if ($othernb) {
767  print '<tr class="oddeven">';
768  print '<td class="nowrap" colspan="5">';
769  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
770  print '</td>';
771  print "</tr>\n";
772  }
773 
774  print '<tr class="liste_total"><td class="left" colspan="2">'.$langs->trans("Total").'</td>';
775  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
776  print '<td class="right"></td>';
777  print '<td class="right">&nbsp;</td>';
778  print '</tr>';
779  } else {
780  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
781  }
782  print "</table></div><br>";
783  $db->free($resql);
784  } else {
785  dol_print_error($db);
786  }
787  }
788 }
789 
790 /*
791  * Customers orders to be billed
792  */
793 if (!empty($conf->facture->enabled) && !empty($conf->commande->enabled) && $user->rights->commande->lire && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER))
794 {
795  $commandestatic = new Commande($db);
796  $langs->load("orders");
797 
798  $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc";
799  $sql .= ", s.nom as name, s.email";
800  $sql .= ", s.rowid as socid";
801  $sql .= ", s.code_client, s.code_compta";
802  $sql .= ", c.rowid, c.ref, c.facture, c.fk_statut as status, c.total_ht, c.tva as total_tva, c.total_ttc,";
803  $sql .= " cc.rowid as country_id, cc.code as country_code";
804  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s LEFT JOIN ".MAIN_DB_PREFIX."c_country as cc ON cc.rowid = s.fk_pays";
805  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
806  $sql .= ", ".MAIN_DB_PREFIX."commande as c";
807  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_source = c.rowid AND el.sourcetype = 'commande'";
808  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON el.fk_target = f.rowid AND el.targettype = 'facture'";
809  $sql .= " WHERE c.fk_soc = s.rowid";
810  $sql .= " AND c.entity = ".$conf->entity;
811  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
812  if ($socid) $sql .= " AND c.fk_soc = ".$socid;
813  $sql .= " AND c.fk_statut = ".Commande::STATUS_CLOSED;
814  $sql .= " AND c.facture = 0";
815  // Add where from hooks
816  $parameters = array();
817  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerOrderToBill', $parameters);
818  $sql .= $hookmanager->resPrint;
819 
820  $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.tva, c.total_ttc, cc.rowid, cc.code";
821 
822  $resql = $db->query($sql);
823  if ($resql)
824  {
825  $num = $db->num_rows($resql);
826 
827  if ($num)
828  {
829  $i = 0;
830  $othernb = 0;
831 
832  print '<div class="div-table-responsive-no-min">';
833  print '<table class="noborder centpercent">';
834 
835  print "<tr class=\"liste_titre\">";
836  print '<th colspan="2">';
837  print $langs->trans("OrdersDeliveredToBill").' ';
838  print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_CLOSED.'&amp;billed=0">';
839  print '<span class="badge">'.$num.'</span>';
840  print '</a>';
841  print '</th>';
842 
843  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
844  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
845  print '<th class="right">'.$langs->trans("ToBill").'</th>';
846  print '<th align="center" width="16">&nbsp;</th>';
847  print '</tr>';
848 
849  $tot_ht = $tot_ttc = $tot_tobill = 0;
850  $societestatic = new Societe($db);
851  while ($i < $num)
852  {
853  $obj = $db->fetch_object($resql);
854 
855  if ($i >= $max) {
856  $othernb += 1;
857  $i++;
858  $total += $obj->total_ht;
859  $total_ttc += $obj->total_ttc;
860  continue;
861  }
862 
863  $societestatic->id = $obj->socid;
864  $societestatic->name = $obj->name;
865  $societestatic->email = $obj->email;
866  $societestatic->country_id = $obj->country_id;
867  $societestatic->country_code = $obj->country_code;
868  $societestatic->client = 1;
869  $societestatic->code_client = $obj->code_client;
870  //$societestatic->code_fournisseur = $obj->code_fournisseur;
871  $societestatic->code_compta = $obj->code_compta;
872  //$societestatic->code_fournisseur = $obj->code_fournisseur;
873 
874  $commandestatic->id = $obj->rowid;
875  $commandestatic->ref = $obj->ref;
876  $commandestatic->statut = $obj->status;
877  $commandestatic->billed = $obj->facture;
878 
879  print '<tr class="oddeven">';
880  print '<td class="nowrap">';
881 
882  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
883  print '<td width="110" class="nobordernopadding nowrap">';
884  print $commandestatic->getNomUrl(1);
885  print '</td>';
886  print '<td width="20" class="nobordernopadding nowrap">';
887  print '&nbsp;';
888  print '</td>';
889  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
890  $filename = dol_sanitizeFileName($obj->ref);
891  $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
892  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
893  print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
894  print '</td></tr></table>';
895 
896  print '</td>';
897 
898  print '<td class="nowrap tdoverflowmax100">';
899  print $societestatic->getNomUrl(1, 'customer');
900  print '</td>';
901  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
902  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
903  print '<td class="nowrap right">'.price($obj->total_ttc - $obj->tot_fttc).'</td>';
904  print '<td>'.$commandestatic->getLibStatut(3).'</td>';
905  print '</tr>';
906  $tot_ht += $obj->total_ht;
907  $tot_ttc += $obj->total_ttc;
908  //print "x".$tot_ttc."z".$obj->tot_fttc;
909  $tot_tobill += ($obj->total_ttc - $obj->tot_fttc);
910  $i++;
911  }
912 
913  if ($othernb) {
914  print '<tr class="oddeven">';
915  print '<td class="nowrap" colspan="5">';
916  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
917  print '</td>';
918  print "</tr>\n";
919  }
920 
921  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</font> </td>';
922  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($tot_ht).'</td>';
923  print '<td class="nowrap right">'.price($tot_ttc).'</td>';
924  print '<td class="nowrap right">'.price($tot_tobill).'</td>';
925  print '<td>&nbsp;</td>';
926  print '</tr>';
927  print '</table></div><br>';
928  }
929  $db->free($resql);
930  } else {
931  dol_print_error($db);
932  }
933 }
934 
935 /*
936  * Unpaid customers invoices
937  */
938 if (!empty($conf->facture->enabled) && $user->rights->facture->lire)
939 {
940  $tmpinvoice = new Facture($db);
941 
942  $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.datef, f.type, f.total as total_ht, f.tva as total_tva, f.total_ttc, f.paye, f.tms";
943  $sql .= ", f.date_lim_reglement as datelimite";
944  $sql .= ", s.nom as name";
945  $sql .= ", s.rowid as socid, s.email";
946  $sql .= ", s.code_client, s.code_compta";
947  $sql .= ", cc.rowid as country_id, cc.code as country_code";
948  $sql .= ", sum(pf.amount) as am";
949  $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";
950  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
951  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
952  $sql .= " WHERE s.rowid = f.fk_soc AND f.paye = 0 AND f.fk_statut = ".Facture::STATUS_VALIDATED;
953  $sql .= " AND f.entity IN (".getEntity('invoice').')';
954  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
955  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
956  // Add where from hooks
957  $parameters = array();
958  $reshook = $hookmanager->executeHooks('printFieldListWhereCustomerUnpaid', $parameters);
959  $sql .= $hookmanager->resPrint;
960 
961  $sql .= " GROUP BY f.rowid, f.ref, f.fk_statut, f.datef, f.type, f.total, f.tva, f.total_ttc, f.paye, f.tms, f.date_lim_reglement,";
962  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_compta, cc.rowid, cc.code";
963  $sql .= " ORDER BY f.datef ASC, f.ref ASC";
964 
965  $resql = $db->query($sql);
966  if ($resql)
967  {
968  $num = $db->num_rows($resql);
969  $i = 0;
970  $othernb = 0;
971 
972  print '<div class="div-table-responsive-no-min">';
973  print '<table class="noborder centpercent">';
974 
975  print '<tr class="liste_titre">';
976  print '<th colspan="2">';
977  print $langs->trans("BillsCustomersUnpaid", $num).' ';
978  print '<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status='.Facture::STATUS_VALIDATED.'">';
979  print '<span class="badge">'.$num.'</span>';
980  print '</a>';
981  print '</th>';
982 
983  print '<th class="right">'.$langs->trans("DateDue").'</th>';
984  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
985  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
986  print '<th class="right">'.$langs->trans("Received").'</th>';
987  print '<th width="16">&nbsp;</th>';
988  print '</tr>';
989  if ($num)
990  {
991  $societestatic = new Societe($db);
992  $total_ttc = $totalam = $total = 0;
993  while ($i < $num && $i < $conf->liste_limit)
994  {
995  $obj = $db->fetch_object($resql);
996 
997  if ($i >= $max) {
998  $othernb += 1;
999  $i++;
1000  $total += $obj->total_ht;
1001  $total_ttc += $obj->total_ttc;
1002  continue;
1003  }
1004 
1005  $tmpinvoice->ref = $obj->ref;
1006  $tmpinvoice->id = $obj->rowid;
1007  $tmpinvoice->total_ht = $obj->total_ht;
1008  $tmpinvoice->total_tva = $obj->total_tva;
1009  $tmpinvoice->total_ttc = $obj->total_ttc;
1010  $tmpinvoice->type = $obj->type;
1011  $tmpinvoice->statut = $obj->status;
1012  $tmpinvoice->paye = $obj->paye;
1013  $tmpinvoice->date_lim_reglement = $db->jdate($obj->datelimite);
1014 
1015  $societestatic->id = $obj->socid;
1016  $societestatic->name = $obj->name;
1017  $societestatic->email = $obj->email;
1018  $societestatic->country_id = $obj->country_id;
1019  $societestatic->country_code = $obj->country_code;
1020  $societestatic->client = 1;
1021  $societestatic->code_client = $obj->code_client;
1022  $societestatic->code_fournisseur = $obj->code_fournisseur;
1023  $societestatic->code_compta = $obj->code_compta;
1024  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1025 
1026  print '<tr class="oddeven">';
1027  print '<td class="nowrap">';
1028 
1029  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1030  print '<td width="110" class="nobordernopadding nowrap">';
1031  print $tmpinvoice->getNomUrl(1, '');
1032  print '</td>';
1033  print '<td width="20" class="nobordernopadding nowrap">';
1034  if ($tmpinvoice->hasDelay()) {
1035  print img_warning($langs->trans("Late"));
1036  }
1037  print '</td>';
1038  print '<td width="16" class="nobordernopadding hideonsmartphone right">';
1039  $filename = dol_sanitizeFileName($obj->ref);
1040  $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1041  $urlsource = $_SERVER['PHP_SELF'].'?facid='.$obj->rowid;
1042  print $formfile->getDocumentsLink($tmpinvoice->element, $filename, $filedir);
1043  print '</td></tr></table>';
1044 
1045  print '</td>';
1046  print '<td class="nowrap tdoverflowmax100">';
1047  print $societestatic->getNomUrl(1, 'customer');
1048  print '</td>';
1049  print '<td class="right">'.dol_print_date($db->jdate($obj->datelimite), 'day').'</td>';
1050  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
1051  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
1052  print '<td class="nowrap right">'.price($obj->am).'</td>';
1053  print '<td>'.$tmpinvoice->getLibStatut(3, $obj->am).'</td>';
1054  print '</tr>';
1055 
1056  $total_ttc += $obj->total_ttc;
1057  $total += $obj->total_ht;
1058  $totalam += $obj->am;
1059 
1060  $i++;
1061  }
1062 
1063  if ($othernb) {
1064  $colspan = 6;
1065  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
1066  print '<tr class="oddeven">';
1067  print '<td class="nowrap" colspan="'.$colspan.'">';
1068  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1069  print '</td>';
1070  print "</tr>\n";
1071  }
1072 
1073  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc - $totalam).')</font> </td>';
1074  print '<td>&nbsp;</td>';
1075  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
1076  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1077  print '<td class="nowrap right">'.price($totalam).'</td>';
1078  print '<td>&nbsp;</td>';
1079  print '</tr>';
1080  } else {
1081  $colspan = 6;
1082  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
1083  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1084  }
1085  print '</table></div><br>';
1086  $db->free($resql);
1087  } else {
1088  dol_print_error($db);
1089  }
1090 }
1091 
1092 /*
1093  * Unpaid supplier invoices
1094  */
1095 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_invoice->enabled)) && $user->rights->fournisseur->facture->lire)
1096 {
1097  $facstatic = new FactureFournisseur($db);
1098 
1099  $sql = "SELECT ff.rowid, ff.ref, ff.fk_statut as status, ff.type, ff.libelle as label, ff.total_ht, ff.total_tva, ff.total_ttc, ff.paye";
1100  $sql .= ", ff.date_lim_reglement";
1101  $sql .= ", s.nom as name";
1102  $sql .= ", s.rowid as socid, s.email";
1103  $sql .= ", s.code_client, s.code_compta";
1104  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur";
1105  $sql .= ", sum(pf.amount) as am";
1106  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
1107  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf on ff.rowid=pf.fk_facturefourn";
1108  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1109  $sql .= " WHERE s.rowid = ff.fk_soc";
1110  $sql .= " AND ff.entity = ".$conf->entity;
1111  $sql .= " AND ff.paye = 0";
1112  $sql .= " AND ff.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
1113  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
1114  if ($socid) $sql .= " AND ff.fk_soc = ".$socid;
1115  // Add where from hooks
1116  $parameters = array();
1117  $reshook = $hookmanager->executeHooks('printFieldListWhereSupplierUnpaid', $parameters);
1118  $sql .= $hookmanager->resPrint;
1119 
1120  $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.paye, ff.date_lim_reglement,";
1121  $sql .= " s.nom, s.rowid, s.email, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur";
1122  $sql .= " ORDER BY ff.date_lim_reglement ASC";
1123 
1124  $resql = $db->query($sql);
1125  if ($resql)
1126  {
1127  $num = $db->num_rows($resql);
1128  $othernb = 0;
1129 
1130  print '<div class="div-table-responsive-no-min">';
1131  print '<table class="noborder centpercent">';
1132 
1133  print '<tr class="liste_titre">';
1134  print '<th colspan="2">';
1135  print $langs->trans("BillsSuppliersUnpaid", $num).' ';
1136  print '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status='.FactureFournisseur::STATUS_VALIDATED.'">';
1137  // TODO: "impayees.php" looks very outdatetd and should be set to deprecated or directly remove in the next version
1138  // <a href="'.DOL_URL_ROOT.'/fourn/facture/impayees.php">
1139  print '<span class="badge">'.$num.'</span>';
1140  print '</a>';
1141  print '</th>';
1142 
1143  print '<th class="right">'.$langs->trans("DateDue").'</th>';
1144  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<th class="right">'.$langs->trans("AmountHT").'</th>';
1145  print '<th class="right">'.$langs->trans("AmountTTC").'</th>';
1146  print '<th class="right">'.$langs->trans("Paid").'</th>';
1147  print '<th width="16">&nbsp;</th>';
1148  print "</tr>\n";
1149  $societestatic = new Societe($db);
1150  if ($num)
1151  {
1152  $i = 0;
1153  $total = $total_ttc = $totalam = 0;
1154  while ($i < $num)
1155  {
1156  $obj = $db->fetch_object($resql);
1157 
1158  if ($i >= $max) {
1159  $othernb += 1;
1160  $i++;
1161  $total += $obj->total_ht;
1162  $total_ttc += $obj->total_ttc;
1163  continue;
1164  }
1165 
1166  $facstatic->ref = $obj->ref;
1167  $facstatic->id = $obj->rowid;
1168  $facstatic->type = $obj->type;
1169  $facstatic->total_ht = $obj->total_ht;
1170  $facstatic->total_tva = $obj->total_tva;
1171  $facstatic->total_ttc = $obj->total_ttc;
1172  $facstatic->statut = $obj->status;
1173  $facstatic->paye = $obj->paye;
1174 
1175  $societestatic->id = $obj->socid;
1176  $societestatic->name = $obj->name;
1177  $societestatic->email = $obj->email;
1178  $societestatic->client = 0;
1179  $societestatic->fournisseur = 1;
1180  $societestatic->code_client = $obj->code_client;
1181  $societestatic->code_fournisseur = $obj->code_fournisseur;
1182  $societestatic->code_compta = $obj->code_compta;
1183  $societestatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1184 
1185  print '<tr class="oddeven"><td class="nowrap tdoverflowmax100">';
1186  print $facstatic->getNomUrl(1, '');
1187  print '</td>';
1188  print '<td class="nowrap tdoverflowmax100">'.$societestatic->getNomUrl(1, 'supplier').'</td>';
1189  print '<td class="right">'.dol_print_date($db->jdate($obj->date_lim_reglement), 'day').'</td>';
1190  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($obj->total_ht).'</td>';
1191  print '<td class="nowrap right">'.price($obj->total_ttc).'</td>';
1192  print '<td class="nowrap right">'.price($obj->am).'</td>';
1193  print '<td>'.$facstatic->getLibStatut(3, $obj->am).'</td>';
1194  print '</tr>';
1195  $total += $obj->total_ht;
1196  $total_ttc += $obj->total_ttc;
1197  $totalam += $obj->am;
1198  $i++;
1199  }
1200 
1201  if ($othernb) {
1202  $colspan = 6;
1203  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
1204  print '<tr class="oddeven">';
1205  print '<td class="nowrap" colspan="'.$colspan.'">';
1206  print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1207  print '</td>';
1208  print "</tr>\n";
1209  }
1210 
1211  print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc - $totalam).')</font> </td>';
1212  print '<td>&nbsp;</td>';
1213  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print '<td class="right">'.price($total).'</td>';
1214  print '<td class="nowrap right">'.price($total_ttc).'</td>';
1215  print '<td class="nowrap right">'.price($totalam).'</td>';
1216  print '<td>&nbsp;</td>';
1217  print '</tr>';
1218  } else {
1219  $colspan = 6;
1220  if (!empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++;
1221  print '<tr class="oddeven"><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoInvoice").'</td></tr>';
1222  }
1223  print '</table></div><br>';
1224  } else {
1225  dol_print_error($db);
1226  }
1227 }
1228 
1229 
1230 
1231 // TODO Mettre ici recup des actions en rapport avec la compta
1233 if ($resql)
1234 {
1235  print '<div class="div-table-responsive-no-min">';
1236  print '<table class="noborder centpercent">';
1237  print '<tr class="liste_titre"><thcolspan="2">'.$langs->trans("TasksToDo").'</th>';
1238  print "</tr>\n";
1239  $i = 0;
1240  while ($i < $db->num_rows($resql))
1241  {
1242  $obj = $db->fetch_object($resql);
1243 
1244  print '<tr class="oddeven"><td>'.dol_print_date($db->jdate($obj->da), "day").'</td>';
1245  print '<td><a href="action/card.php">'.$obj->label.'</a></td></tr>';
1246  $i++;
1247  }
1248  $db->free($resql);
1249  print "</table></div><br>";
1250 }
1251 
1252 
1253 print '</div></div></div>';
1254 
1255 $parameters = array('user' => $user);
1256 $reshook = $hookmanager->executeHooks('dashboardAccountancy', $parameters, $object); // Note that $action and $object may have been modified by hook
1257 
1258 // End of page
1259 llxFooter();
1260 $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)
dol_now($mode= 'auto')
Return date for now.
const STATUS_VALIDATED
Validated (need to be paid)
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_VALIDATED
Validated (need to be paid)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
Class to manage donations.
Definition: don.class.php:37
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
Classe permettant la gestion des paiements des charges La tva collectee n&#39;est calculee que sur les fa...