valo.php 5.9 KB

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