dolibarr  13.0.2
valo.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
28 
29 // Load translation files required by the page
30 $langs->load("stocks");
31 
32 // Security check
33 $result = restrictedArea($user, 'stock');
34 
35 $sref = GETPOST("sref", 'alpha');
36 $snom = GETPOST("snom", 'alpha');
37 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
38 
39 $sortfield = GETPOST("sortfield", 'alpha');
40 $sortorder = GETPOST("sortorder", 'alpha');
41 if (!$sortfield) $sortfield = "e.ref";
42 if (!$sortorder) $sortorder = "ASC";
43 $page = $_GET["page"];
44 if ($page < 0) $page = 0;
45 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
46 $offset = $limit * $page;
47 
48 $year = strftime("%Y", time());
49 
50 
51 /*
52  * View
53  */
54 
55 $sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays,";
56 $sql .= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue";
57 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
58 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
59 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
60 $sql .= " WHERE e.entity IN (".getEntity('stock').")";
61 if ($sref) $sql .= natural_search("e.ref", $sref);
62 if ($sall)
63 {
64  $sql .= " AND (e.ref LIKE '%".$db->escape($sall)."%'";
65  $sql .= " OR e.description LIKE '%".$db->escape($sall)."%'";
66  $sql .= " OR e.lieu LIKE '%".$db->escape($sall)."%'";
67  $sql .= " OR e.address LIKE '%".$db->escape($sall)."%'";
68  $sql .= " OR e.town LIKE '%".$db->escape($sall)."%')";
69 }
70 $sql .= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays";
71 $sql .= $db->order($sortfield, $sortorder);
72 $sql .= $db->plimit($limit + 1, $offset);
73 
74 $result = $db->query($sql);
75 if ($result)
76 {
77  $num = $db->num_rows($result);
78 
79  $i = 0;
80 
81  $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
82  llxHeader("", $langs->trans("EnhancedValueOfWarehouses"), $help_url);
83 
84  print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
85 
86  print '<table class="noborder centpercent">';
87  print "<tr class=\"liste_titre\">";
88  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
89  print_liste_field_titre("LocationSummary", $_SERVER["PHP_SELF"], "e.lieu", "", "", "", $sortfield, $sortorder);
90  print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "e.valo_pmp", '', '', '', $sortfield, $sortorder, 'right ');
91  print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'right ');
92  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.statut", '', '', '', $sortfield, $sortorder, 'right ');
93  print "</tr>\n";
94 
95  if ($num)
96  {
97  $entrepot = new Entrepot($db);
98  $total = $totalsell = 0;
99  $var = false;
100  while ($i < min($num, $limit))
101  {
102  $objp = $db->fetch_object($result);
103  print '<tr class="oddeven">';
104  print '<td><a href="card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowWarehouse"), 'stock').' '.$objp->ref.'</a></td>';
105  print '<td>'.$objp->lieu.'</td>';
106  // PMP value
107  print '<td class="right">';
108  if (price2num($objp->estimatedvalue, 'MT')) print price(price2num($objp->estimatedvalue, 'MT'), 1);
109  else print '';
110  print '</td>';
111  // Selling value
112  print '<td class="right">';
113  if (empty($conf->global->PRODUIT_MULTIPRICES)) print price(price2num($objp->sellvalue, 'MT'), 1);
114  else print $langs->trans("Variable");
115  print '</td>';
116  // Status
117  print '<td class="right">'.$entrepot->LibStatut($objp->statut, 5).'</td>';
118  print "</tr>\n";
119  $total += price2num($objp->estimatedvalue, 'MU');
120  $totalsell += price2num($objp->sellvalue, 'MU');
121 
122  $i++;
123  }
124 
125  print '<tr class="liste_total">';
126  print '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
127  print '<td class="right">'.price(price2num($total, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
128  print '<td class="right">'.price(price2num($totalsell, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
129  print '<td class="right">&nbsp;</td>';
130  print "</tr>\n";
131  }
132 
133  $db->free($result);
134 
135  print "</table>";
136 
137  print '<br>';
138 
139  $file = 'entrepot-'.$year.'.png';
140  if (file_exists($conf->stock->dir_temp.'/'.$file))
141  {
142  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
143  print '<img src="'.$url.'">';
144  }
145 
146  $file = 'entrepot-'.($year - 1).'.png';
147  if (file_exists($conf->stock->dir_temp.'/'.$file))
148  {
149  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
150  print '<br><img src="'.$url.'">';
151  }
152 } else {
153  dol_print_error($db);
154 }
155 
156 // End of page
157 llxFooter();
158 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
Class to manage warehouses.