dolibarr 21.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
31
40// Load translation files required by the page
41$langs->load("stocks");
42
43$sref = GETPOST("sref", 'alpha');
44$snom = GETPOST("snom", 'alpha');
45$sall = trim(GETPOST('search_all', 'alphanohtml'));
46
47$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
48$sortfield = GETPOST('sortfield', 'aZ09comma');
49$sortorder = GETPOST('sortorder', 'aZ09comma');
50$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
51if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
52 // If $page is not defined, or '' or -1 or if we click on clear filters
53 $page = 0;
54}
55$offset = $limit * $page;
56
57if (!$sortfield) {
58 $sortfield = "e.ref";
59}
60if (!$sortorder) {
61 $sortorder = "ASC";
62}
63
64$year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
65
66// Security check
67$result = restrictedArea($user, 'stock');
68
69
70/*
71 * View
72 */
73
74$sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays,";
75$sql .= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue";
76$sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
77$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
78$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
79$sql .= " WHERE e.entity IN (".getEntity('stock').")";
80if ($sref) {
81 $sql .= natural_search("e.ref", $sref);
82}
83if ($sall) {
84 $sql .= " AND (e.ref LIKE '%".$db->escape($sall)."%'";
85 $sql .= " OR e.description LIKE '%".$db->escape($sall)."%'";
86 $sql .= " OR e.lieu LIKE '%".$db->escape($sall)."%'";
87 $sql .= " OR e.address LIKE '%".$db->escape($sall)."%'";
88 $sql .= " OR e.town LIKE '%".$db->escape($sall)."%')";
89}
90$sql .= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays";
91$sql .= $db->order($sortfield, $sortorder);
92$sql .= $db->plimit($limit + 1, $offset);
93
94$result = $db->query($sql);
95if ($result) {
96 $num = $db->num_rows($result);
97
98 $i = 0;
99
100 $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
101 llxHeader("", $langs->trans("EnhancedValueOfWarehouses"), $help_url, '', 0, 0, '', '', '', 'mod-product page-stock_valo');
102
103 print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
104
105 print '<table class="noborder centpercent">';
106 print "<tr class=\"liste_titre\">";
107 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
108 print_liste_field_titre("LocationSummary", $_SERVER["PHP_SELF"], "e.lieu", "", "", "", $sortfield, $sortorder);
109 print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "e.valo_pmp", '', '', '', $sortfield, $sortorder, 'right ');
110 print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'right ');
111 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.statut", '', '', '', $sortfield, $sortorder, 'right ');
112 print "</tr>\n";
113
114 if ($num) {
115 $entrepot = new Entrepot($db);
116 $total = $totalsell = 0;
117 $var = false;
118 while ($i < min($num, $limit)) {
119 $objp = $db->fetch_object($result);
120 print '<tr class="oddeven">';
121 print '<td><a href="card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowWarehouse"), 'stock').' '.$objp->ref.'</a></td>';
122 print '<td>'.$objp->lieu.'</td>';
123 // PMP value
124 print '<td class="right">';
125 if (price2num($objp->estimatedvalue, 'MT')) {
126 print price(price2num($objp->estimatedvalue, 'MT'), 1);
127 } else {
128 print '';
129 }
130 print '</td>';
131 // Selling value
132 print '<td class="right">';
133 if (!getDolGlobalString('PRODUIT_MULTIPRICES')) {
134 print price(price2num($objp->sellvalue, 'MT'), 1);
135 } else {
136 print $langs->trans("Variable");
137 }
138 print '</td>';
139 // Status
140 print '<td class="right">'.$entrepot->LibStatut($objp->statut, 5).'</td>';
141 print "</tr>\n";
142 $total += price2num($objp->estimatedvalue, 'MU');
143 $totalsell += price2num($objp->sellvalue, 'MU');
144
145 $i++;
146 }
147
148 print '<tr class="liste_total">';
149 print '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
150 print '<td class="right">'.price(price2num($total, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
151 print '<td class="right">'.price(price2num($totalsell, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
152 print '<td class="right">&nbsp;</td>';
153 print "</tr>\n";
154 }
155
156 $db->free($result);
157
158 print "</table>";
159
160 print '<br>';
161
162 $file = 'entrepot-'.$year.'.png';
163 if (file_exists($conf->stock->dir_temp.'/'.$file)) {
164 $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
165 print '<img src="'.$url.'">';
166 }
167
168 $file = 'entrepot-'.((int) $year - 1).'.png';
169 if (file_exists($conf->stock->dir_temp.'/'.$file)) {
170 $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
171 print '<br><img src="'.$url.'">';
172 }
173} else {
174 dol_print_error($db);
175}
176
177// End of page
178llxFooter();
179$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage warehouses.
llxFooter()
Footer empty.
Definition document.php:107
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
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 a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.