valo.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. /**
  20. * \file htdocs/product/stock/valo.php
  21. * \ingroup stock
  22. * \brief Page with stock values
  23. */
  24. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  27. // Load translation files required by the page
  28. $langs->load("stocks");
  29. // Security check
  30. $result = restrictedArea($user, 'stock');
  31. $sref = GETPOST("sref", 'alpha');
  32. $snom = GETPOST("snom", 'alpha');
  33. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  34. $sortfield = GETPOST('sortfield', 'aZ09comma');
  35. $sortorder = GETPOST('sortorder', 'aZ09comma');
  36. if (!$sortfield) {
  37. $sortfield = "e.ref";
  38. }
  39. if (!$sortorder) {
  40. $sortorder = "ASC";
  41. }
  42. $page = $_GET["page"];
  43. if ($page < 0) {
  44. $page = 0;
  45. }
  46. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  47. $offset = $limit * $page;
  48. $year = dol_print_date(dol_now('gmt'), "%Y", 'gmt');
  49. /*
  50. * View
  51. */
  52. $sql = "SELECT e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays,";
  53. $sql .= " SUM(ps.pmp * ps.reel) as estimatedvalue, SUM(p.price * ps.reel) as sellvalue";
  54. $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e";
  55. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON e.rowid = ps.fk_entrepot";
  56. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid";
  57. $sql .= " WHERE e.entity IN (".getEntity('stock').")";
  58. if ($sref) {
  59. $sql .= natural_search("e.ref", $sref);
  60. }
  61. if ($sall) {
  62. $sql .= " AND (e.ref LIKE '%".$db->escape($sall)."%'";
  63. $sql .= " OR e.description LIKE '%".$db->escape($sall)."%'";
  64. $sql .= " OR e.lieu LIKE '%".$db->escape($sall)."%'";
  65. $sql .= " OR e.address LIKE '%".$db->escape($sall)."%'";
  66. $sql .= " OR e.town LIKE '%".$db->escape($sall)."%')";
  67. }
  68. $sql .= " GROUP BY e.rowid, e.ref, e.statut, e.lieu, e.address, e.zip, e.town, e.fk_pays";
  69. $sql .= $db->order($sortfield, $sortorder);
  70. $sql .= $db->plimit($limit + 1, $offset);
  71. $result = $db->query($sql);
  72. if ($result) {
  73. $num = $db->num_rows($result);
  74. $i = 0;
  75. $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  76. llxHeader("", $langs->trans("EnhancedValueOfWarehouses"), $help_url);
  77. print_barre_liste($langs->trans("EnhancedValueOfWarehouses"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
  78. print '<table class="noborder centpercent">';
  79. print "<tr class=\"liste_titre\">";
  80. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "e.ref", "", "", "", $sortfield, $sortorder);
  81. print_liste_field_titre("LocationSummary", $_SERVER["PHP_SELF"], "e.lieu", "", "", "", $sortfield, $sortorder);
  82. print_liste_field_titre("EstimatedStockValue", $_SERVER["PHP_SELF"], "e.valo_pmp", '', '', '', $sortfield, $sortorder, 'right ');
  83. print_liste_field_titre("EstimatedStockValueSell", $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'right ');
  84. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "e.statut", '', '', '', $sortfield, $sortorder, 'right ');
  85. print "</tr>\n";
  86. if ($num) {
  87. $entrepot = new Entrepot($db);
  88. $total = $totalsell = 0;
  89. $var = false;
  90. while ($i < min($num, $limit)) {
  91. $objp = $db->fetch_object($result);
  92. print '<tr class="oddeven">';
  93. print '<td><a href="card.php?id='.$objp->rowid.'">'.img_object($langs->trans("ShowWarehouse"), 'stock').' '.$objp->ref.'</a></td>';
  94. print '<td>'.$objp->lieu.'</td>';
  95. // PMP value
  96. print '<td class="right">';
  97. if (price2num($objp->estimatedvalue, 'MT')) {
  98. print price(price2num($objp->estimatedvalue, 'MT'), 1);
  99. } else {
  100. print '';
  101. }
  102. print '</td>';
  103. // Selling value
  104. print '<td class="right">';
  105. if (empty($conf->global->PRODUIT_MULTIPRICES)) {
  106. print price(price2num($objp->sellvalue, 'MT'), 1);
  107. } else {
  108. print $langs->trans("Variable");
  109. }
  110. print '</td>';
  111. // Status
  112. print '<td class="right">'.$entrepot->LibStatut($objp->statut, 5).'</td>';
  113. print "</tr>\n";
  114. $total += price2num($objp->estimatedvalue, 'MU');
  115. $totalsell += price2num($objp->sellvalue, 'MU');
  116. $i++;
  117. }
  118. print '<tr class="liste_total">';
  119. print '<td colspan="2" class="right">'.$langs->trans("Total").'</td>';
  120. print '<td class="right">'.price(price2num($total, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
  121. print '<td class="right">'.price(price2num($totalsell, 'MT'), 1, $langs, 0, 0, -1, $conf->currency).'</td>';
  122. print '<td class="right">&nbsp;</td>';
  123. print "</tr>\n";
  124. }
  125. $db->free($result);
  126. print "</table>";
  127. print '<br>';
  128. $file = 'entrepot-'.$year.'.png';
  129. if (file_exists($conf->stock->dir_temp.'/'.$file)) {
  130. $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
  131. print '<img src="'.$url.'">';
  132. }
  133. $file = 'entrepot-'.($year - 1).'.png';
  134. if (file_exists($conf->stock->dir_temp.'/'.$file)) {
  135. $url = DOL_URL_ROOT.'/viewimage.php?modulepart=graph_stock&amp;file='.$file;
  136. print '<br><img src="'.$url.'">';
  137. }
  138. } else {
  139. dol_print_error($db);
  140. }
  141. // End of page
  142. llxFooter();
  143. $db->close();