dolibarr  16.0.5
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', 'aZ09comma');
40 $sortorder = GETPOST('sortorder', 'aZ09comma');
41 if (!$sortfield) {
42  $sortfield = "e.ref";
43 }
44 if (!$sortorder) {
45  $sortorder = "ASC";
46 }
47 $page = $_GET["page"];
48 if ($page < 0) {
49  $page = 0;
50 }
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 $offset = $limit * $page;
53 
54 $year = strftime("%Y", time());
55 
56 
57 /*
58  * View
59  */
60 
61 $sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays,";
62 $sql .= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue";
63 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
64 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
65 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
66 $sql .= " WHERE e.entity IN (".getEntity('stock').")";
67 if ($sref) {
68  $sql .= natural_search("e.ref", $sref);
69 }
70 if ($sall) {
71  $sql .= " AND (e.ref LIKE '%".$db->escape($sall)."%'";
72  $sql .= " OR e.description LIKE '%".$db->escape($sall)."%'";
73  $sql .= " OR e.lieu LIKE '%".$db->escape($sall)."%'";
74  $sql .= " OR e.address LIKE '%".$db->escape($sall)."%'";
75  $sql .= " OR e.town LIKE '%".$db->escape($sall)."%')";
76 }
77 $sql .= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays";
78 $sql .= $db->order($sortfield, $sortorder);
79 $sql .= $db->plimit($limit + 1, $offset);
80 
81 $result = $db->query($sql);
82 if ($result) {
83  $num = $db->num_rows($result);
84 
85  $i = 0;
86 
87  $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
88  llxHeader("", $langs->trans("EnhancedValueOfWarehouses"), $help_url);
89 
90  print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
91 
92  print '<table class="noborder centpercent">';
93  print "<tr class=\"liste_titre\">";
94  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
95  print_liste_field_titre("LocationSummary", $_SERVER["PHP_SELF"], "e.lieu", "", "", "", $sortfield, $sortorder);
96  print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "e.valo_pmp", '', '', '', $sortfield, $sortorder, 'right ');
97  print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'right ');
98  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.statut", '', '', '', $sortfield, $sortorder, 'right ');
99  print "</tr>\n";
100 
101  if ($num) {
102  $entrepot = new Entrepot($db);
103  $total = $totalsell = 0;
104  $var = false;
105  while ($i < min($num, $limit)) {
106  $objp = $db->fetch_object($result);
107  print '<tr class="oddeven">';
108  print '<td><a href="card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowWarehouse"), 'stock').' '.$objp->ref.'</a></td>';
109  print '<td>'.$objp->lieu.'</td>';
110  // PMP value
111  print '<td class="right">';
112  if (price2num($objp->estimatedvalue, 'MT')) {
113  print price(price2num($objp->estimatedvalue, 'MT'), 1);
114  } else {
115  print '';
116  }
117  print '</td>';
118  // Selling value
119  print '<td class="right">';
120  if (empty($conf->global->PRODUIT_MULTIPRICES)) {
121  print price(price2num($objp->sellvalue, 'MT'), 1);
122  } else {
123  print $langs->trans("Variable");
124  }
125  print '</td>';
126  // Status
127  print '<td class="right">'.$entrepot->LibStatut($objp->statut, 5).'</td>';
128  print "</tr>\n";
129  $total += price2num($objp->estimatedvalue, 'MU');
130  $totalsell += price2num($objp->sellvalue, 'MU');
131 
132  $i++;
133  }
134 
135  print '<tr class="liste_total">';
136  print '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
137  print '<td class="right">'.price(price2num($total, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
138  print '<td class="right">'.price(price2num($totalsell, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
139  print '<td class="right">&nbsp;</td>';
140  print "</tr>\n";
141  }
142 
143  $db->free($result);
144 
145  print "</table>";
146 
147  print '<br>';
148 
149  $file = 'entrepot-'.$year.'.png';
150  if (file_exists($conf->stock->dir_temp.'/'.$file)) {
151  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
152  print '<img src="'.$url.'">';
153  }
154 
155  $file = 'entrepot-'.($year - 1).'.png';
156  if (file_exists($conf->stock->dir_temp.'/'.$file)) {
157  $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
158  print '<br><img src="'.$url.'">';
159  }
160 } else {
161  dol_print_error($db);
162 }
163 
164 // End of page
165 llxFooter();
166 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
print_barre_liste
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.
Definition: functions.lib.php:5257
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
Entrepot
Class to manage warehouses.
Definition: entrepot.class.php:35
price
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.
Definition: functions.lib.php:5541
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59