dolibarr  13.0.2
index.php
1 <?php
2 /* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
24 require '../../main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
28 
29 // Security check
30 restrictedArea($user, 'facture');
31 
32 // Load translation files required by the page
33 $langs->load('bills');
34 
35 // Filter to show only result of one customer
36 $socid = GETPOST('socid', 'int');
37 if (isset($user->socid) && $user->socid > 0)
38 {
39  $action = '';
40  $socid = $user->socid;
41 }
42 
43 // Maximum elements of the tables
44 $maxDraftCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
45 $maxLatestEditCount = 5;
46 $maxOpenCount = empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD;
47 
48 /*
49 * View
50 */
51 
52 llxHeader("", $langs->trans("CustomersInvoicesArea"), "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes");
53 
54 print load_fiche_titre($langs->trans("CustomersInvoicesArea"), '', 'bill');
55 
56 print '<div class="fichecenter">';
57 
58 print '<div class="fichethirdleft">';
59 
60 // This is useless due to the global search combo
61 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))
62 {
63  print getAreaSearchFrom();
64  print '<br>';
65 }
66 
67 print getPieChart($socid);
68 print '<br>';
69 print getDraftTable($maxDraftCount, $socid);
70 
71 print '</div>';
72 
73 print '<div class="fichetwothirdright">';
74 print '<div class="ficheaddleft">';
75 
76 print getLatestEditTable($maxLatestEditCount, $socid);
77 print '<br>';
78 print getOpenTable($maxOpenCount, $socid);
79 
80 print '</div>';
81 print '</div>';
82 
83 print '</div>';
84 
85 // End of page
86 llxFooter();
87 $db->close();
88 
94 function getAreaSearchFrom()
95 {
96  global $langs;
97 
98  $result = '<form method="post" action="'.DOL_URL_ROOT.'/compta/facture/list.php">';
99  $result .= '<div class="div-table-responsive-no-min">';
100  $result .= '<input type="hidden" name="token" value="'.newToken().'">';
101  $result .= '<table class="noborder nohover centpercent">';
102 
103  $result .= '<tr class="liste_titre">';
104  $result .= '<td colspan="3">'.$langs->trans("Search").'</td>';
105  $result .= '</tr>';
106 
107  $result .= '<tr class="oddeven">';
108  $result .= '<td>'.$langs->trans("Invoice").':</td><td><input type="text" class="flat" name="sall" size=18></td>';
109  $result .= '<td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
110  $result .= '</tr>';
111 
112  $result .= "</table>";
113  $result .= "</div>";
114  $result .= "</form>";
115 
116  return $result;
117 }
118 
125 function getPieChart($socid = 0)
126 {
127  global $conf, $db, $langs, $user;
128 
129  $sql = "SELECT count(f.rowid), f.fk_statut";
130  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
131  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
132  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
133  $sql .= " WHERE f.fk_soc = s.rowid";
134  $sql .= " AND f.entity IN (".getEntity('facture').")";
135  if ($user->socid) $sql .= ' AND f.fk_soc = '.$user->socid;
136  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
137  $sql .= " GROUP BY f.fk_statut";
138 
139  $resql = $db->query($sql);
140  if (!$resql)
141  {
142  dol_print_error($db);
143  return '';
144  }
145 
146  $num = $db->num_rows($resql);
147  $i = 0;
148 
149  $total = 0;
150  $vals = [];
151 
152  while ($i < $num)
153  {
154  $row = $db->fetch_row($resql);
155  if ($row)
156  {
157  $vals[$row[1]] = $row[0];
158  $total += $row[0];
159  }
160 
161  $i++;
162  }
163 
164  $db->free($resql);
165 
166  $result = '<div class="div-table-responsive-no-min">';
167  $result .= '<table class="noborder nohover centpercent">';
168  $result .= '<tr class="liste_titre">';
169  $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CustomerInvoice").'</td>';
170  $result .= '</tr>';
171 
172  $objectstatic = new Facture($db);
174  $dataseries = [];
175 
176  foreach ($array as $status)
177  {
178  $objectstatic->statut = $status;
179  $objectstatic->paye = $status == Facture::STATUS_CLOSED ? -1 : 0;
180 
181  $dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)];
182  if (!$conf->use_javascript_ajax)
183  {
184  $result .= '<tr class="oddeven">';
185  $result .= '<td>'.$objectstatic->getLibStatut(0).'</td>';
186  $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
187  $result .= '</tr>';
188  }
189  }
190 
191  if ($conf->use_javascript_ajax)
192  {
193  $dolgraph = new DolGraph();
194  $dolgraph->SetData($dataseries);
195  $dolgraph->setShowLegend(2);
196  $dolgraph->setShowPercent(1);
197  $dolgraph->SetType(['pie']);
198  $dolgraph->setHeight('200');
199  $dolgraph->draw('idgraphthirdparties');
200 
201  $result .= '<tr>';
202  $result .= '<td align="center" colspan="2">'.$dolgraph->show($total ? 0 : 1).'</td>';
203  $result .= '</tr>';
204  }
205 
206  $result .= '<tr class="liste_total">';
207  $result .= '<td>'.$langs->trans("Total").'</td>';
208  $result .= '<td class="right">'.$total.'</td>';
209  $result .= '</tr>';
210 
211  $result .= '</table>';
212  $result .= '</div>';
213  return $result;
214 }
215 
223 function getDraftTable($maxCount = 500, $socid = 0)
224 {
225  global $db, $langs, $user;
226 
227  $sql = "SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total as total_ttc";
228  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
229  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
230  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
231  $sql .= " WHERE f.fk_soc = s.rowid";
232  $sql .= " AND f.entity IN (".getEntity('facture').")";
233  $sql .= " AND f.fk_statut = ".Facture::STATUS_DRAFT;
234  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
235  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
236  $sql .= $db->plimit($maxCount, 0);
237 
238  $resql = $db->query($sql);
239  if (!$resql)
240  {
241  dol_print_error($db);
242  return '';
243  }
244 
245  $num = $db->num_rows($resql);
246 
247  $result = '<div class="div-table-responsive-no-min">';
248  $result .= '<table class="noborder centpercent">';
249 
250  $result .= '<tr class="liste_titre">';
251  $result .= '<td colspan="3">';
252  $result .= $langs->trans("CustomersDraftInvoices");
253  $result .= ' <a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status=0">';
254  $result .= '<span class="badge">'.$num.'</span>';
255  $result .= '</a>';
256  $result .= '</td>';
257  $result .= '</tr>';
258 
259  if ($num < 1)
260  {
261  $result .= '</table>';
262  $result .= '</div>';
263  return $result;
264  }
265 
266  $objectstatic = new Facture($db);
267  $companystatic = new Societe($db);
268  $nbofloop = min($num, $maxCount);
269  $total = 0;
270  $i = 0;
271 
272  while ($i < $nbofloop)
273  {
274  $obj = $db->fetch_object($resql);
275 
276  $objectstatic->id = $obj->rowid;
277  $objectstatic->ref = $obj->ref;
278 
279  $companystatic->id = $obj->socid;
280  $companystatic->name = $obj->socname;
281  $companystatic->client = $obj->client;
282  $companystatic->canvas = $obj->canvas;
283 
284  $result .= '<tr class="oddeven">';
285  $result .= '<td class="nowrap">'.$objectstatic->getNomUrl(1).'</td>';
286  $result .= '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
287  $result .= '<td class="right">'.price($obj->total_ttc).'</td>';
288  $result .= '</tr>';
289 
290  $i++;
291  $total += $obj->total_ttc;
292  }
293 
294  if ($num > $nbofloop)
295  {
296  $result .= '<tr class="liste_total">';
297  $result .= '<td colspan="3" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
298  $result .= '</tr>';
299  }
300  elseif ($total > 0)
301  {
302  $result .= '<tr class="liste_total">';
303  $result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
304  $result .= '<td class="right">'.price($total).'</td>';
305  $result .= '</tr>';
306  }
307 
308  $result .= '</table>';
309  $result .= '</div>';
310  return $result;
311 }
312 
320 function getLatestEditTable($maxCount = 5, $socid = 0)
321 {
322  global $conf, $db, $langs, $user;
323 
324  $sql = "SELECT f.rowid, f.entity, f.ref, f.fk_statut as status, f.paye, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
325  $sql .= " f.datec";
326  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
327  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
328  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
329  $sql .= " WHERE f.fk_soc = s.rowid";
330  $sql .= " AND f.entity IN (".getEntity('facture').")";
331  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
332  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
333  $sql .= " ORDER BY f.tms DESC";
334  $sql .= $db->plimit($maxCount, 0);
335 
336  $resql = $db->query($sql);
337  if (!$resql)
338  {
339  dol_print_error($db);
340  }
341 
342  $num = $db->num_rows($resql);
343 
344  $result = '<div class="div-table-responsive-no-min">';
345  $result .= '<table class="noborder centpercent">';
346 
347  $result .= '<tr class="liste_titre">';
348  $result .= '<td colspan="4">'.$langs->trans("LastCustomersBills", $maxCount).'</td>';
349  $result .= '</tr>';
350 
351  if ($num < 1)
352  {
353  $result .= '</table>';
354  $result .= '</div>';
355  return $result;
356  }
357 
358  $formfile = new FormFile($db);
359  $objectstatic = new Facture($db);
360  $companystatic = new Societe($db);
361  $i = 0;
362 
363  while ($i < $num)
364  {
365  $obj = $db->fetch_object($resql);
366 
367  $objectstatic->id = $obj->rowid;
368  $objectstatic->ref = $obj->ref;
369  $objectstatic->paye = $obj->paye;
370  $objectstatic->statut = $obj->status;
371 
372  $companystatic->id = $obj->socid;
373  $companystatic->name = $obj->socname;
374  $companystatic->client = $obj->client;
375  $companystatic->canvas = $obj->canvas;
376 
377  $filename = dol_sanitizeFileName($obj->ref);
378  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
379 
380  $result .= '<tr width="20%" class="nowrap">';
381 
382  $result .= '<td class="oddeven">';
383  $result .= '<table class="nobordernopadding">';
384  $result .= '<tr class="nocellnopadd">';
385 
386  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
387  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
388  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
389 
390  $result .= '</tr>';
391  $result .= '</table>';
392  $result .= '</td>';
393 
394  $result .= '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
395  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
396  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
397 
398  $result .= '</tr>';
399 
400  $i++;
401  }
402 
403  $result .= '</table>';
404  $result .= '</div>';
405  return $result;
406 }
407 
415 function getOpenTable($maxCount = 500, $socid = 0)
416 {
417  global $conf, $db, $langs, $user;
418 
419  $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client";
420  $sql .= ", f.rowid as id, f.entity, f.total as total_ttc, f.total as total_ht, f.ref, f.fk_statut";
421  $sql .= ", f.datef as df, f.date_lim_reglement as datelimite";
422  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
423  $sql .= ", ".MAIN_DB_PREFIX."facture as f";
424  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
425  $sql .= " WHERE f.fk_soc = s.rowid";
426  $sql .= " AND f.entity IN (".getEntity('facture').")";
427  $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED;
428  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
429  if ($socid) $sql .= " AND s.rowid = ".$socid;
430  $sql .= " ORDER BY f.rowid DESC";
431  $sql .= $db->plimit($maxCount, 0);
432 
433  $resql = $db->query($sql);
434  if (!$resql)
435  {
436  dol_print_error($db);
437  }
438 
439  $num = $db->num_rows($resql);
440 
441  $result = '<div class="div-table-responsive-no-min">';
442  $result .= '<table class="noborder centpercent">';
443 
444  $result .= '<tr class="liste_titre">';
445  $result .= '<td colspan="4">';
446  $result .= $langs->trans("BillsCustomersUnpaid");
447  $result .= ' <a href="'.DOL_URL_ROOT.'/compta/facture/list.php?search_status=1">';
448  $result .= '<span class="badge">'.$num.'</span>';
449  $result .= '</a>';
450  $result .= '</td>';
451  $result .= '</tr>';
452 
453  if ($num < 1)
454  {
455  $result .= '</table>';
456  $result .= '</div>';
457  return $result;
458  }
459 
460  $objectstatic = new Facture($db);
461  $companystatic = new Societe($db);
462  $formfile = new FormFile($db);
463  $nbofloop = min($num, $maxCount);
464  $now = dol_now();
465  $total = 0;
466  $i = 0;
467 
468  while ($i < $nbofloop)
469  {
470  $obj = $db->fetch_object($resql);
471 
472  $objectstatic->id = $obj->id;
473  $objectstatic->ref = $obj->ref;
474 
475  $companystatic->id = $obj->socid;
476  $companystatic->name = $obj->socname;
477  $companystatic->client = $obj->client;
478  $companystatic->canvas = $obj->canvas;
479 
480  $filename = dol_sanitizeFileName($obj->ref);
481  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
482 
483  $result .= '<tr class="oddeven">';
484 
485  $result .= '<td class="nowrap" width="140">';
486  $result .= '<table class="nobordernopadding">';
487  $result .= '<tr class="nocellnopadd">';
488 
489  $result .= '<td class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
490 
491  $result .= '<td width="18" class="nobordernopadding nowrap">';
492 
493  if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay))
494  {
495  $result .= img_warning($langs->trans("Late"));
496  }
497 
498  $result .= '</td>';
499 
500  $result .= '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
501 
502  $result .= '</tr>';
503  $result .= '</table>';
504  $result .= '</td>';
505 
506  $result .= '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
507  $result .= '<td class="right">'.dol_print_date($db->jdate($obj->df), 'day').'</td>';
508  $result .= '<td class="right">'.price($obj->total_ttc).'</td>';
509 
510  $result .= '</tr>';
511 
512  $i++;
513  $total += $obj->total_ttc;
514  }
515 
516  if ($num > $nbofloop)
517  {
518  $result .= '<tr class="liste_total">';
519  $result .= '<td colspan="4" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
520  $result .= '</tr>';
521  }
522  elseif ($total > 0)
523  {
524  $result .= '<tr class="liste_total">';
525  $result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
526  $result .= '<td align="right">'.price($total).'</td>';
527  $result .= '<td>&nbsp;</td>';
528  $result .= '</tr>';
529  }
530 
531  $result .= '</table>';
532  $result .= '</div>';
533  return $result;
534 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_now($mode= 'auto')
Return date for now.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
llxHeader()
Empty header.
Definition: wrapper.php:45
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.
const STATUS_DRAFT
Draft status.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
const STATUS_CLOSED
Classified paid.
Class to offer components to list and upload files.
const STATUS_ABANDONED
Classified abandoned and no payment done.
print
Draft customers invoices.
Definition: index.php:89
Class to build graphs.
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