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.'/fourn/class/fournisseur.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, 'fournisseur', 0, '', 'facture');
31 
32 // Load translation files required by the page
33 $langs->loadLangs(['bills', 'boxes']);
34 
35 // Filter to show only result of one supplier
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("SupplierInvoicesArea"), 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
53 
54 print load_fiche_titre($langs->trans("SupplierInvoicesArea"), '', 'supplier_invoice');
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_fourn 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_fourn').")";
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 
169  $result .= '<tr class="liste_titre">';
170  $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SupplierInvoice").'</td>';
171  $result .= '</tr>';
172 
173  $objectstatic = new FactureFournisseur($db);
175  $dataseries = [];
176 
177  foreach ($array as $status)
178  {
179  $objectstatic->statut = $status;
180  $objectstatic->paye = $status == FactureFournisseur::STATUS_CLOSED ? -1 : 0;
181 
182  $dataseries[] = [$objectstatic->getLibStatut(1), (isset($vals[$status]) ? (int) $vals[$status] : 0)];
183  if (!$conf->use_javascript_ajax)
184  {
185  $result .= '<tr class="oddeven">';
186  $result .= '<td>'.$objectstatic->getLibStatut(0).'</td>';
187  $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
188  $result .= '</tr>';
189  }
190  }
191 
192  if ($conf->use_javascript_ajax)
193  {
194  $dolgraph = new DolGraph();
195  $dolgraph->SetData($dataseries);
196  $dolgraph->setShowLegend(2);
197  $dolgraph->setShowPercent(1);
198  $dolgraph->SetType(['pie']);
199  $dolgraph->setHeight('200');
200  $dolgraph->draw('idgraphthirdparties');
201 
202  $result .= '<tr>';
203  $result .= '<td align="center" colspan="2">'.$dolgraph->show($total ? 0 : 1).'</td>';
204  $result .= '</tr>';
205  }
206 
207  $result .= '<tr class="liste_total">';
208  $result .= '<td>'.$langs->trans("Total").'</td>';
209  $result .= '<td class="right">'.$total.'</td>';
210  $result .= '</tr>';
211 
212  $result .= '</table>';
213  $result .= '</div>';
214 
215  return $result;
216 }
217 
225 function getDraftTable($maxCount = 500, $socid = 0)
226 {
227  global $db, $langs, $user;
228 
229  $sql = "SELECT f.rowid, f.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client, f.total_ttc";
230  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
231  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
232  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
233  $sql .= " WHERE f.fk_soc = s.rowid";
234  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
235  $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_DRAFT;
236  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
237  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
238  $sql .= $db->plimit($maxCount, 0);
239 
240  $resql = $db->query($sql);
241  if (!$resql)
242  {
243  dol_print_error($db);
244  return '';
245  }
246 
247  $num = $db->num_rows($resql);
248 
249  $result = '<div class="div-table-responsive-no-min">';
250  $result .= '<table class="noborder centpercent">';
251 
252  $result .= '<tr class="liste_titre">';
253  $result .= '<td colspan="3">';
254  $result .= $langs->trans("SuppliersDraftInvoices");
255  $result .= ' <a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status=0">';
256  $result .= '<span class="badge">'.$num.'</span>';
257  $result .= '</a>';
258  $result .= '</td>';
259  $result .= '</tr>';
260 
261  if ($num < 1)
262  {
263  $result .= '</table>';
264  $result .= '</div>';
265  return $result;
266  }
267 
268  $objectstatic = new FactureFournisseur($db);
269  $companystatic = new Societe($db);
270  $nbofloop = min($num, $maxCount);
271  $total = 0;
272  $i = 0;
273 
274  while ($i < $nbofloop)
275  {
276  $obj = $db->fetch_object($resql);
277 
278  $objectstatic->id = $obj->rowid;
279  $objectstatic->ref = $obj->ref;
280 
281  $companystatic->id = $obj->socid;
282  $companystatic->name = $obj->socname;
283  $companystatic->client = $obj->client;
284  $companystatic->canvas = $obj->canvas;
285 
286  $result .= '<tr class="oddeven">';
287  $result .= '<td class="nowrap">'.$objectstatic->getNomUrl(1).'</td>';
288  $result .= '<td>'.$companystatic->getNomUrl(1, 'supplier', 24).'</td>';
289  $result .= '<td class="right">'.price($obj->total_ttc).'</td>';
290  $result .= '</tr>';
291 
292  $i++;
293  $total += $obj->total_ttc;
294  }
295 
296  if ($num > $nbofloop)
297  {
298  $result .= '<tr class="liste_total">';
299  $result .= '<td colspan="3" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
300  $result .= '</tr>';
301  }
302  elseif ($total > 0)
303  {
304  $result .= '<tr class="liste_total">';
305  $result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
306  $result .= '<td class="right">'.price($total).'</td>';
307  $result .= '</tr>';
308  }
309 
310  $result .= '</table>';
311  $result .= '</div>';
312  return $result;
313 }
314 
322 function getLatestEditTable($maxCount = 5, $socid = 0)
323 {
324  global $conf, $db, $langs, $user;
325 
326  $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,";
327  $sql .= " f.datec";
328  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
329  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
330  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
331  $sql .= " WHERE f.fk_soc = s.rowid";
332  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
333  if ($socid) $sql .= " AND f.fk_soc = ".$socid;
334  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
335  $sql .= " ORDER BY f.tms DESC";
336  $sql .= $db->plimit($maxCount, 0);
337 
338  $resql = $db->query($sql);
339  if (!$resql)
340  {
341  dol_print_error($db);
342  return '';
343  }
344 
345  $num = $db->num_rows($resql);
346 
347  $result = '<div class="div-table-responsive-no-min">';
348  $result .= '<table class="noborder centpercent">';
349  $result .= '<tr class="liste_titre">';
350  $result .= '<td colspan="4">'.$langs->trans("BoxTitleLastSupplierBills", $maxCount).'</td>';
351  $result .= '</tr>';
352 
353  if ($num < 1)
354  {
355  $result .= '</table>';
356  $result .= '</div>';
357  return $result;
358  }
359 
360  $objectstatic = new FactureFournisseur($db);
361  $companystatic = new Societe($db);
362  $formfile = new FormFile($db);
363  $i = 0;
364 
365  while ($i < $num)
366  {
367  $obj = $db->fetch_object($resql);
368 
369  $objectstatic->id = $obj->rowid;
370  $objectstatic->ref = $obj->ref;
371  $objectstatic->paye = $obj->paye;
372  $objectstatic->statut = $obj->status;
373 
374  $companystatic->id = $obj->socid;
375  $companystatic->name = $obj->socname;
376  $companystatic->client = $obj->client;
377  $companystatic->canvas = $obj->canvas;
378 
379  $filename = dol_sanitizeFileName($obj->ref);
380  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
381 
382  $result .= '<tr width="20%" class="nowrap">';
383 
384  $result .= '<td class="oddeven">';
385  $result .= '<table class="nobordernopadding">';
386  $result .= '<tr class="nocellnopadd">';
387 
388  $result .= '<td width="96" class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
389  $result .= '<td width="16" class="nobordernopadding nowrap">&nbsp;</td>';
390  $result .= '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
391 
392  $result .= '</tr>';
393  $result .= '</table>';
394  $result .= '</td>';
395 
396  $result .= '<td>'.$companystatic->getNomUrl(1, 'supplier').'</td>';
397  $result .= '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
398  $result .= '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
399 
400  $result .= '</tr>';
401 
402  $i++;
403  }
404 
405  $result .= '</table>';
406  $result .= '</div>';
407  return $result;
408 }
409 
417 function getOpenTable($maxCount = 500, $socid = 0)
418 {
419  global $conf, $db, $langs, $user;
420 
421  $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client";
422  $sql .= ", f.rowid as id, f.entity, f.total_ttc, f.total_ht, f.ref, f.fk_statut";
423  $sql .= ", f.datef as df, f.date_lim_reglement as datelimite";
424  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
425  $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f";
426  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
427  $sql .= " WHERE f.fk_soc = s.rowid";
428  $sql .= " AND f.entity IN (".getEntity('facture_fourn').")";
429  $sql .= " AND f.fk_statut = ".FactureFournisseur::STATUS_VALIDATED;
430  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
431  if ($socid) $sql .= " AND s.rowid = ".$socid;
432  $sql .= " ORDER BY f.rowid DESC";
433  $sql .= $db->plimit($maxCount, 0);
434 
435  $resql = $db->query($sql);
436  if (!$resql)
437  {
438  dol_print_error($db);
439  return '';
440  }
441 
442  $num = $db->num_rows($resql);
443 
444  $result = '<div class="div-table-responsive-no-min">';
445  $result .= '<table class="noborder centpercent">';
446  $result .= '<tr class="liste_titre">';
447  $result .= '<td colspan="4">';
448  $result .= $langs->trans("BillsCustomersUnpaid");
449  $result .= ' <a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?search_status=1">';
450  $result .= '<span class="badge">'.$num.'</span>';
451  $result .= '</a>';
452  $result .= '</td>';
453  $result .= '</tr>';
454 
455  if ($num < 1)
456  {
457  $result .= '</table>';
458  $result .= '</div>';
459  return $result;
460  }
461 
462  $objectstatic = new FactureFournisseur($db);
463  $companystatic = new Societe($db);
464  $formfile = new FormFile($db);
465  $nbofloop = min($num, $maxCount);
466  $now = dol_now();
467  $total = 0;
468  $i = 0;
469 
470  while ($i < $nbofloop)
471  {
472  $obj = $db->fetch_object($resql);
473 
474  $objectstatic->id = $obj->id;
475  $objectstatic->ref = $obj->ref;
476 
477  $companystatic->id = $obj->socid;
478  $companystatic->name = $obj->socname;
479  $companystatic->client = $obj->client;
480  $companystatic->canvas = $obj->canvas;
481 
482  $filename = dol_sanitizeFileName($obj->ref);
483  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.$filename;
484 
485  $result .= '<tr class="oddeven">';
486 
487  $result .= '<td class="nowrap" width="140">';
488  $result .= '<table class="nobordernopadding">';
489  $result .= '<tr class="nocellnopadd">';
490 
491  $result .= '<td class="nobordernopadding nowrap">'.$objectstatic->getNomUrl(1).'</td>';
492  $result .= '<td width="18" class="nobordernopadding nowrap">';
493 
494  if ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay))
495  {
496  $result .= img_warning($langs->trans("Late"));
497  }
498 
499  $result .= '</td>';
500 
501  $result .= '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($objectstatic->element, $filename, $filedir).'</td>';
502 
503  $result .= '</tr>';
504  $result .= '</table>';
505  $result .= '</td>';
506 
507  $result .= '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
508  $result .= '<td class="right">'.dol_print_date($db->jdate($obj->df), 'day').'</td>';
509  $result .= '<td class="right">'.price($obj->total_ttc).'</td>';
510 
511  $result .= '</tr>';
512 
513  $i++;
514  $total += $obj->total_ttc;
515  }
516 
517  if ($num > $nbofloop)
518  {
519  $result .= '<tr class="liste_total">';
520  $result .= '<td colspan="4" class="right">'.$langs->trans("XMoreLines", ($num - $nbofloop)).'</td>';
521  $result .= '</tr>';
522  }
523  elseif ($total > 0)
524  {
525  $result .= '<tr class="liste_total">';
526  $result .= '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
527  $result .= '<td align="right">'.price($total).'</td>';
528  $result .= '<td>&nbsp;</td>';
529  $result .= '</tr>';
530  }
531 
532  $result .= '</table>';
533  $result .= '</div>';
534  return $result;
535 }
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.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage suppliers invoices.
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...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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.
Class to offer components to list and upload files.
const STATUS_CLOSED
Classified paid.
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...
const STATUS_ABANDONED
Classified abandoned and no payment done.
llxFooter()
Empty footer.
Definition: wrapper.php:59