popuprop.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/product/popuprop.php
  24. * \ingroup propal, produit
  25. * \brief Liste des produits/services par popularite
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  29. // Load translation files required by the page
  30. //Required to translate NbOfProposals
  31. $langs->load('propal');
  32. $type=GETPOST("type","int");
  33. // Security check
  34. if (! empty($user->societe_id)) $socid=$user->societe_id;
  35. $result=restrictedArea($user,'produit|service');
  36. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  37. $sortfield = GETPOST("sortfield",'alpha');
  38. $sortorder = GETPOST("sortorder",'alpha');
  39. $page = GETPOST("page",'int');
  40. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  41. if (! $sortfield) $sortfield="c";
  42. if (! $sortorder) $sortorder="DESC";
  43. $offset = $limit * $page ;
  44. $pageprev = $page - 1;
  45. $pagenext = $page + 1;
  46. $staticproduct=new Product($db);
  47. /*
  48. * View
  49. */
  50. $helpurl='';
  51. if ($type == '0')
  52. {
  53. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  54. }
  55. else if ($type == '1')
  56. {
  57. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  58. }
  59. else
  60. {
  61. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  62. }
  63. $title=$langs->trans("Statistics");
  64. llxHeader('', $title, $helpurl);
  65. print load_fiche_titre($title, $mesg,'title_products.png');
  66. $param = '';
  67. $title = $langs->trans("ListProductServiceByPopularity");
  68. if ((string) $type == '1') {
  69. $title = $langs->trans("ListServiceByPopularity");
  70. }
  71. if ((string) $type == '0') {
  72. $title = $langs->trans("ListProductByPopularity");
  73. }
  74. if ($type != '') $param .= '&type='.$type;
  75. $h=0;
  76. $head = array();
  77. $head[$h][0] = DOL_URL_ROOT.'/product/stats/card.php?id=all';
  78. $head[$h][1] = $langs->trans("Chart");
  79. $head[$h][2] = 'chart';
  80. $h++;
  81. $head[$h][0] = $_SERVER['PHP_SELF'];
  82. $head[$h][1] = $title;
  83. $head[$h][2] = 'popularityprop';
  84. $h++;
  85. dol_fiche_head($head, 'popularityprop', $langs->trans("Statistics"), -1);
  86. // Array of liens to show
  87. $infoprod=array();
  88. // Add lines for proposals
  89. $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, SUM(pd.qty) as c";
  90. $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
  91. $sql.= ", ".MAIN_DB_PREFIX."product as p";
  92. $sql.= ' WHERE p.entity IN ('.getEntity('product').')';
  93. $sql.= " AND p.rowid = pd.fk_product";
  94. if ($type !== '') {
  95. $sql.= " AND fk_product_type = ".$type;
  96. }
  97. $sql.= " GROUP BY p.rowid, p.label, p.ref, p.fk_product_type";
  98. $result=$db->query($sql);
  99. if ($result)
  100. {
  101. $totalnboflines = $db->num_rows($result);
  102. }
  103. $sql.= $db->order($sortfield,$sortorder);
  104. $sql.= $db->plimit($limit+1, $offset);
  105. $resql=$db->query($sql);
  106. if ($resql)
  107. {
  108. $num = $db->num_rows($resql);
  109. $i = 0;
  110. while ($i < $num)
  111. {
  112. $objp = $db->fetch_object($resql);
  113. $infoprod[$objp->rowid]=array('type'=>$objp->type, 'ref'=>$objp->ref, 'label'=>$objp->label);
  114. $infoprod[$objp->rowid]['nblineproposal']=$objp->c;
  115. $i++;
  116. }
  117. $db->free($resql);
  118. }
  119. else
  120. {
  121. dol_print_error($db);
  122. }
  123. //var_dump($infoprod);
  124. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $totalnboflines, '');
  125. print '<table class="noborder" width="100%">';
  126. print "<tr class=\"liste_titre\">";
  127. print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
  128. print_liste_field_titre('Type', $_SERVER["PHP_SELF"], 'p.fk_product_type', '', $param, '', $sortfield, $sortorder);
  129. print_liste_field_titre('Label', $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder);
  130. print_liste_field_titre('NbOfQtyInProposals', $_SERVER["PHP_SELF"], 'c', '', $param, 'align="right"', $sortfield, $sortorder);
  131. print "</tr>\n";
  132. foreach($infoprod as $prodid => $vals)
  133. {
  134. // Multilangs
  135. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  136. {
  137. $sql = "SELECT label";
  138. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  139. $sql.= " WHERE fk_product=".$prodid;
  140. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  141. $sql.= " LIMIT 1";
  142. $resultp = $db->query($sql);
  143. if ($resultp)
  144. {
  145. $objtp = $db->fetch_object($resultp);
  146. if (! empty($objtp->label)) $vals['label'] = $objtp->label;
  147. }
  148. }
  149. print "<tr>";
  150. print '<td><a href="'.DOL_URL_ROOT.'/product/stats/card.php?id='.$prodid.'">';
  151. if ($vals['type'] == 1) print img_object($langs->trans("ShowService"),"service");
  152. else print img_object($langs->trans("ShowProduct"),"product");
  153. print " ";
  154. print $vals['ref'].'</a></td>';
  155. print '<td>';
  156. if ($vals['type'] == 1) print $langs->trans("Service");
  157. else print $langs->trans("Product");
  158. print '</td>';
  159. print '<td>'.$vals['label'].'</td>';
  160. print '<td align="right">'.$vals['nblineproposal'].'</td>';
  161. print "</tr>\n";
  162. $i++;
  163. }
  164. print "</table>";
  165. dol_fiche_end();
  166. // End of page
  167. llxFooter();
  168. $db->close();