PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 261 lines | 185 code | 36 blank | 40 comment | 50 complexity | b6b43f15d8104b79e609d816d8716a37 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2012 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/index.php
  21. * \ingroup product
  22. * \brief Page accueil des produits et services
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  26. $type=isset($_GET["type"])?$_GET["type"]:(isset($_POST["type"])?$_POST["type"]:'');
  27. if ($type =='' && !$user->rights->produit->lire) $type='1'; // Force global page on service page only
  28. if ($type =='' && !$user->rights->service->lire) $type='0'; // Force global page on prpduct page only
  29. // Security check
  30. if ($type=='0') $result=restrictedArea($user,'produit');
  31. else if ($type=='1') $result=restrictedArea($user,'service');
  32. else $result=restrictedArea($user,'produit|service');
  33. $langs->load("products");
  34. $product_static = new Product($db);
  35. /*
  36. * View
  37. */
  38. $transAreaType = $langs->trans("ProductsAndServicesArea");
  39. $helpurl='';
  40. if (! isset($_GET["type"]))
  41. {
  42. $transAreaType = $langs->trans("ProductsAndServicesArea");
  43. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  44. }
  45. if ((isset($_GET["type"]) && $_GET["type"] == 0) || empty($conf->service->enabled))
  46. {
  47. $transAreaType = $langs->trans("ProductsArea");
  48. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  49. }
  50. if ((isset($_GET["type"]) && $_GET["type"] == 1) || empty($conf->product->enabled))
  51. {
  52. $transAreaType = $langs->trans("ServicesArea");
  53. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  54. }
  55. llxHeader("",$langs->trans("ProductsAndServices"),$helpurl);
  56. print_fiche_titre($transAreaType);
  57. print '<table border="0" width="100%" class="notopnoleftnoright">';
  58. print '<tr><td valign="top" width="30%" class="notopnoleft">';
  59. /*
  60. * Zone recherche produit/service
  61. */
  62. $rowspan=2;
  63. if (! empty($conf->barcode->enabled)) $rowspan++;
  64. print '<form method="post" action="'.DOL_URL_ROOT.'/product/liste.php">';
  65. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  66. print '<table class="noborder nohover" width="100%">';
  67. print "<tr class=\"liste_titre\">";
  68. print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
  69. print "<tr ".$bc[false]."><td>";
  70. print $langs->trans("Ref").':</td><td><input class="flat" type="text" size="14" name="sref"></td>';
  71. print '<td rowspan="'.$rowspan.'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
  72. if (! empty($conf->barcode->enabled))
  73. {
  74. print "<tr ".$bc[false]."><td>";
  75. print $langs->trans("BarCode").':</td><td><input class="flat" type="text" size="14" name="sbarcode"></td>';
  76. //print '<td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
  77. print '</tr>';
  78. }
  79. print "<tr ".$bc[false]."><td>";
  80. print $langs->trans("Other").':</td><td><input class="flat" type="text" size="14" name="sall"></td>';
  81. //print '<td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
  82. print '</tr>';
  83. print "</table></form><br>";
  84. /*
  85. * Nombre de produits et/ou services
  86. */
  87. $prodser = array();
  88. $prodser[0][0]=$prodser[0][1]=$prodser[1][0]=$prodser[1][1]=0;
  89. $sql = "SELECT COUNT(p.rowid) as total, p.fk_product_type, p.tosell, p.tobuy";
  90. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  91. $sql.= ' WHERE p.entity IN ('.getEntity($product_static->element, 1).')';
  92. $sql.= " GROUP BY p.fk_product_type, p.tosell, p.tobuy";
  93. $result = $db->query($sql);
  94. while ($objp = $db->fetch_object($result))
  95. {
  96. $status=1;
  97. if (! $objp->tosell && ! $objp->tobuy) $status=0;
  98. $prodser[$objp->fk_product_type][$status]=$objp->total;
  99. }
  100. print '<table class="noborder" width="100%">';
  101. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").'</td></tr>';
  102. if (! empty($conf->product->enabled))
  103. {
  104. $statProducts = "<tr $bc[0]>";
  105. $statProducts.= '<td><a href="liste.php?type=0&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ProductsNotOnSell").'</a></td><td align="right">'.round($prodser[0][0]).'</td>';
  106. $statProducts.= "</tr>";
  107. $statProducts.= "<tr $bc[1]>";
  108. $statProducts.= '<td><a href="liste.php?type=0&amp;tosell=1">'.$langs->trans("ProductsOnSell").'</a></td><td align="right">'.round($prodser[0][1]).'</td>';
  109. $statProducts.= "</tr>";
  110. }
  111. if (! empty($conf->service->enabled))
  112. {
  113. $statServices = "<tr $bc[0]>";
  114. $statServices.= '<td><a href="liste.php?type=1&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ServicesNotOnSell").'</a></td><td align="right">'.round($prodser[1][0]).'</td>';
  115. $statServices.= "</tr>";
  116. $statServices.= "<tr $bc[1]>";
  117. $statServices.= '<td><a href="liste.php?type=1&amp;tosell=1">'.$langs->trans("ServicesOnSell").'</a></td><td align="right">'.round($prodser[1][1]).'</td>';
  118. $statServices.= "</tr>";
  119. }
  120. $total=0;
  121. if ($type == '0')
  122. {
  123. print $statProducts;
  124. $total=round($prodser[0][0])+round($prodser[0][1]);
  125. }
  126. else if ($type == '1')
  127. {
  128. print $statServices;
  129. $total=round($prodser[1][0])+round($prodser[1][1]);
  130. }
  131. else
  132. {
  133. print $statProducts.$statServices;
  134. $total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[0][0])+round($prodser[0][1]);
  135. }
  136. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
  137. print $total;
  138. print '</td></tr>';
  139. print '</table>';
  140. print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  141. /*
  142. * Last modified products
  143. */
  144. $max=15;
  145. $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.fk_product_type, p.tosell, p.tobuy,";
  146. $sql.= " p.tms as datem";
  147. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  148. $sql.= " WHERE p.entity IN (".getEntity($product_static->element, 1).")";
  149. if ($type != '') $sql.= " AND p.fk_product_type = ".$type;
  150. $sql.= $db->order("p.tms","DESC");
  151. $sql.= $db->plimit($max,0);
  152. //print $sql;
  153. $result = $db->query($sql);
  154. if ($result)
  155. {
  156. $num = $db->num_rows($result);
  157. $i = 0;
  158. if ($num > 0)
  159. {
  160. $transRecordedType = $langs->trans("LastModifiedProductsAndServices",$max);
  161. if (isset($_GET["type"]) && $_GET["type"] == 0) $transRecordedType = $langs->trans("LastRecordedProducts",$max);
  162. if (isset($_GET["type"]) && $_GET["type"] == 1) $transRecordedType = $langs->trans("LastRecordedServices",$max);
  163. print '<table class="noborder" width="100%">';
  164. $colnb=5;
  165. if (empty($conf->global->PRODUIT_MULTIPRICES)) $colnb++;
  166. print '<tr class="liste_titre"><td colspan="'.$colnb.'">'.$transRecordedType.'</td></tr>';
  167. $var=True;
  168. while ($i < $num)
  169. {
  170. $objp = $db->fetch_object($result);
  171. //Multilangs
  172. if (! empty($conf->global->MAIN_MULTILANGS))
  173. {
  174. $sql = "SELECT label";
  175. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  176. $sql.= " WHERE fk_product=".$objp->rowid;
  177. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  178. $resultd = $db->query($sql);
  179. if ($resultd)
  180. {
  181. $objtp = $db->fetch_object($resultd);
  182. if ($objtp && $objtp->label != '') $objp->label = $objtp->label;
  183. }
  184. }
  185. $var=!$var;
  186. print "<tr ".$bc[$var].">";
  187. print '<td nowrap="nowrap">';
  188. $product_static->id=$objp->rowid;
  189. $product_static->ref=$objp->ref;
  190. $product_static->type=$objp->fk_product_type;
  191. print $product_static->getNomUrl(1,'',16);
  192. print "</td>\n";
  193. print '<td>'.dol_trunc($objp->label,32).'</td>';
  194. print "<td>";
  195. print dol_print_date($db->jdate($objp->datem),'day');
  196. print "</td>";
  197. // Sell price
  198. if (empty($conf->global->PRODUIT_MULTIPRICES))
  199. {
  200. print '<td align="right">';
  201. if ($objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC");
  202. else print price($objp->price).' '.$langs->trans("HT");
  203. print '</td>';
  204. }
  205. print '<td align="right" nowrap="nowrap">';
  206. print $product_static->LibStatut($objp->tosell,5,0);
  207. print "</td>";
  208. print '<td align="right" nowrap="nowrap">';
  209. print $product_static->LibStatut($objp->tobuy,5,1);
  210. print "</td>";
  211. print "</tr>\n";
  212. $i++;
  213. }
  214. $db->free();
  215. print "</table>";
  216. }
  217. }
  218. else
  219. {
  220. dol_print_error($db);
  221. }
  222. print '</td></tr></table>';
  223. llxFooter();
  224. $db->close();
  225. ?>