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