PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/product/liste.old.php

https://bitbucket.org/speedealing/speedealing
PHP | 472 lines | 355 code | 61 blank | 56 comment | 112 complexity | 4864a43fea066d6f5d7325e5dbf21ba6 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. * Copyright (C) 2012 Marcos GarcĂ­a <marcosgdf@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/product/liste.php
  22. * \ingroup produit
  23. * \brief Page to list products and services
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. if (! empty($conf->categorie->enabled))
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. $langs->load("products");
  32. $langs->load("stocks");
  33. $action = GETPOST('action');
  34. $sref=GETPOST("sref");
  35. $sbarcode=GETPOST("sbarcode");
  36. $snom=GETPOST("snom");
  37. $sall=GETPOST("sall");
  38. $type=GETPOST("type","int");
  39. $search_sale = GETPOST("search_sale");
  40. $search_categ = GETPOST("search_categ",'int');
  41. $tosell = GETPOST("tosell");
  42. $tobuy = GETPOST("tobuy");
  43. $fourn_id = GETPOST("fourn_id",'int');
  44. $catid = GETPOST('catid','int');
  45. $sortfield = GETPOST("sortfield",'alpha');
  46. $sortorder = GETPOST("sortorder",'alpha');
  47. $page = GETPOST("page",'int');
  48. if ($page == -1) { $page = 0; }
  49. $offset = $conf->liste_limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (! $sortfield) $sortfield="p.ref";
  53. if (! $sortorder) $sortorder="ASC";
  54. $limit = $conf->liste_limit;
  55. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  56. //$object->getCanvas($id);
  57. $canvas=GETPOST("canvas");
  58. $objcanvas='';
  59. if (! empty($canvas))
  60. {
  61. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  62. $objcanvas = new Canvas($db,$action);
  63. $objcanvas->getCanvas('product','list',$canvas);
  64. }
  65. // Security check
  66. if ($type=='0') $result=restrictedArea($user,'produit','','','','','',$objcanvas);
  67. else if ($type=='1') $result=restrictedArea($user,'service','','','','','',$objcanvas);
  68. else $result=restrictedArea($user,'produit|service','','','','','',$objcanvas);
  69. /*
  70. * Actions
  71. */
  72. if (isset($_POST["button_removefilter_x"]))
  73. {
  74. $sref="";
  75. $sbarcode="";
  76. $snom="";
  77. $search_categ=0;
  78. }
  79. /*
  80. * View
  81. */
  82. $htmlother=new FormOther($db);
  83. $form=new Form($db);
  84. if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
  85. {
  86. $objcanvas->assign_values('list'); // This must contains code to load data (must call LoadListDatas($limit, $offset, $sortfield, $sortorder))
  87. $objcanvas->display_canvas('list'); // This is code to show template
  88. }
  89. else
  90. {
  91. $title=$langs->trans("ProductsAndServices");
  92. if (isset($type))
  93. {
  94. if ($type==1)
  95. {
  96. $texte = $langs->trans("Services");
  97. }
  98. else
  99. {
  100. $texte = $langs->trans("Products");
  101. }
  102. }
  103. else
  104. {
  105. $texte = $langs->trans("ProductsAndServices");
  106. }
  107. $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
  108. $sql.= ' p.fk_product_type, p.tms as datem,';
  109. $sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,';
  110. $sql.= ' MIN(pfp.unitprice) as minsellprice';
  111. $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
  112. if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
  113. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
  114. $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
  115. if ($sall)
  116. {
  117. $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%'";
  118. if (! empty($conf->barcode->enabled))
  119. {
  120. $sql.= " OR p.barcode LIKE '%".$db->escape($sall)."%'";
  121. }
  122. $sql.= ')';
  123. }
  124. // if the type is not 1, we show all products (type = 0,2,3)
  125. if (dol_strlen($type))
  126. {
  127. if ($type == 1) $sql.= " AND p.fk_product_type = '1'";
  128. else $sql.= " AND p.fk_product_type <> '1'";
  129. }
  130. if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'";
  131. if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'";
  132. if ($snom) $sql.= " AND p.label LIKE '%".$db->escape($snom)."%'";
  133. if (isset($tosell) && dol_strlen($tosell) > 0) $sql.= " AND p.tosell = ".$db->escape($tosell);
  134. if (isset($tobuy) && dol_strlen($tobuy) > 0) $sql.= " AND p.tobuy = ".$db->escape($tobuy);
  135. if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
  136. if ($catid > 0) $sql.= " AND cp.fk_categorie = ".$catid;
  137. if ($catid == -2) $sql.= " AND cp.fk_categorie IS NULL";
  138. if ($search_categ > 0) $sql.= " AND cp.fk_categorie = ".$search_categ;
  139. if ($search_categ == -2) $sql.= " AND cp.fk_categorie IS NULL";
  140. if ($fourn_id > 0) $sql.= " AND pfp.fk_soc = ".$fourn_id;
  141. $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
  142. $sql.= " p.fk_product_type, p.tms,";
  143. $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
  144. //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
  145. $sql.= $db->order($sortfield,$sortorder);
  146. $sql.= $db->plimit($limit + 1, $offset);
  147. dol_syslog("sql=".$sql);
  148. $resql = $db->query($sql);
  149. if ($resql)
  150. {
  151. $num = $db->num_rows($resql);
  152. $i = 0;
  153. if ($num == 1 && ($sall || $snom || $sref || $sbarcode) && $action != 'list')
  154. {
  155. $objp = $db->fetch_object($resql);
  156. header("Location: fiche.php?id=".$objp->rowid);
  157. exit;
  158. }
  159. $helpurl='';
  160. if (isset($type))
  161. {
  162. if ($type == 0)
  163. {
  164. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  165. }
  166. else if ($type == 1)
  167. {
  168. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  169. }
  170. }
  171. llxHeader('',$title,$helpurl,'');
  172. // Displays product removal confirmation
  173. if (GETPOST('delprod')) dol_htmloutput_mesg($langs->trans("ProductDeleted",GETPOST('delprod')));
  174. $param="&amp;sref=".$sref.($sbarcode?"&amp;sbarcode=".$sbarcode:"")."&amp;snom=".$snom."&amp;sall=".$sall."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy;
  175. $param.=($fourn_id?"&amp;fourn_id=".$fourn_id:"");
  176. $param.=($search_categ?"&amp;search_categ=".$search_categ:"");
  177. $param.=isset($type)?"&amp;type=".$type:"";
  178. print_barre_liste($texte, $page, "liste.php", $param, $sortfield, $sortorder,'',$num);
  179. if (! empty($catid))
  180. {
  181. print "<div id='ways'>";
  182. $c = new Categorie($db);
  183. $ways = $c->print_all_ways(' &gt; ','product/liste.php');
  184. print " &gt; ".$ways[0]."<br>\n";
  185. print "</div><br>";
  186. }
  187. if (! empty($canvas) && file_exists(DOL_DOCUMENT_ROOT.'/product/canvas/'.$canvas.'/actions_card_'.$canvas.'.class.php'))
  188. {
  189. $fieldlist = $object->field_list;
  190. $datas = $object->list_datas;
  191. $picto='title.png';
  192. $title_picto = img_picto('',$picto);
  193. $title_text = $title;
  194. // Default templates directory
  195. $template_dir = DOL_DOCUMENT_ROOT . '/product/canvas/'.$canvas.'/tpl/';
  196. // Check if a custom template is present
  197. if (file_exists(DOL_DOCUMENT_ROOT . '/theme/'.$conf->theme.'/tpl/product/'.$canvas.'/list.tpl.php'))
  198. {
  199. $template_dir = DOL_DOCUMENT_ROOT . '/theme/'.$conf->theme.'/tpl/product/'.$canvas.'/';
  200. }
  201. include $template_dir.'list.tpl.php'; // Include native PHP templates
  202. }
  203. else
  204. {
  205. print '<form action="liste.php" method="post" name="formulaire">';
  206. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  207. print '<input type="hidden" name="action" value="list">';
  208. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  209. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  210. print '<input type="hidden" name="type" value="'.$type.'">';
  211. print '<table class="liste" width="100%">';
  212. // Filter on categories
  213. $moreforfilter='';
  214. if (! empty($conf->categorie->enabled))
  215. {
  216. $moreforfilter.=$langs->trans('Categories'). ': ';
  217. $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ',1);
  218. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  219. }
  220. if ($moreforfilter)
  221. {
  222. print '<tr class="liste_titre">';
  223. print '<td class="liste_titre" colspan="9">';
  224. print $moreforfilter;
  225. print '</td></tr>';
  226. }
  227. // Lignes des titres
  228. print "<tr class=\"liste_titre\">";
  229. print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder);
  230. print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder);
  231. if (! empty($conf->barcode->enabled)) print_liste_field_titre($langs->trans("BarCode"), $_SERVER["PHP_SELF"], "p.barcode",$param,'','',$sortfield,$sortorder);
  232. print_liste_field_titre($langs->trans("DateModification"), $_SERVER["PHP_SELF"], "p.tms",$param,"",'align="center"',$sortfield,$sortorder);
  233. if (! empty($conf->service->enabled) && $type != 0) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
  234. if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellingPrice"), $_SERVER["PHP_SELF"], "p.price",$param,"",'align="right"',$sortfield,$sortorder);
  235. print '<td class="liste_titre" align="right">'.$langs->trans("BuyingPriceMinShort").'</td>';
  236. if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) print '<td class="liste_titre" align="right">'.$langs->trans("PhysicalStock").'</td>';
  237. print_liste_field_titre($langs->trans("Sell"), $_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="right"',$sortfield,$sortorder);
  238. print_liste_field_titre($langs->trans("Buy"), $_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder);
  239. print "</tr>\n";
  240. // Lignes des champs de filtre
  241. print '<tr class="liste_titre">';
  242. print '<td class="liste_titre" align="left">';
  243. print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">';
  244. print '</td>';
  245. print '<td class="liste_titre" align="left">';
  246. print '<input class="flat" type="text" name="snom" size="12" value="'.$snom.'">';
  247. print '</td>';
  248. if (! empty($conf->barcode->enabled))
  249. {
  250. print '<td class="liste_titre">';
  251. print '<input class="flat" type="text" name="sbarcode" size="6" value="'.$sbarcode.'">';
  252. print '</td>';
  253. }
  254. print '<td class="liste_titre">';
  255. print '&nbsp;';
  256. print '</td>';
  257. // Duration
  258. if (! empty($conf->service->enabled) && $type != 0)
  259. {
  260. print '<td class="liste_titre">';
  261. print '&nbsp;';
  262. print '</td>';
  263. }
  264. // Sell price
  265. if (empty($conf->global->PRODUIT_MULTIPRICES))
  266. {
  267. print '<td class="liste_titre">';
  268. print '&nbsp;';
  269. print '</td>';
  270. }
  271. // Minimum buying Price
  272. print '<td class="liste_titre">';
  273. print '&nbsp;';
  274. print '</td>';
  275. // Stock
  276. if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1)
  277. {
  278. print '<td class="liste_titre">';
  279. print '&nbsp;';
  280. print '</td>';
  281. }
  282. print '<td class="liste_titre">';
  283. print '&nbsp;';
  284. print '</td>';
  285. print '<td class="liste_titre" align="right">';
  286. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  287. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  288. print '</td>';
  289. print '</tr>';
  290. $product_static=new Product($db);
  291. $product_fourn =new ProductFournisseur($db);
  292. $var=true;
  293. while ($i < min($num,$limit))
  294. {
  295. $objp = $db->fetch_object($resql);
  296. // Multilangs
  297. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  298. {
  299. $sql = "SELECT label";
  300. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  301. $sql.= " WHERE fk_product=".$objp->rowid;
  302. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  303. $sql.= " LIMIT 1";
  304. $result = $db->query($sql);
  305. if ($result)
  306. {
  307. $objtp = $db->fetch_object($result);
  308. if (! empty($objtp->label)) $objp->label = $objtp->label;
  309. }
  310. }
  311. $var=!$var;
  312. print '<tr '.$bc[$var].'>';
  313. // Ref
  314. print '<td nowrap="nowrap">';
  315. $product_static->id = $objp->rowid;
  316. $product_static->ref = $objp->ref;
  317. $product_static->type = $objp->fk_product_type;
  318. print $product_static->getNomUrl(1,'',24);
  319. print "</td>\n";
  320. // Label
  321. print '<td>'.dol_trunc($objp->label,40).'</td>';
  322. // Barcode
  323. if (! empty($conf->barcode->enabled))
  324. {
  325. print '<td>'.$objp->barcode.'</td>';
  326. }
  327. // Date
  328. print '<td align="center">'.dol_print_date($db->jdate($objp->datem),'day')."</td>\n";
  329. // Duration
  330. if (! empty($conf->service->enabled) && $type != 0)
  331. {
  332. print '<td align="center">';
  333. if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear");
  334. elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth");
  335. elseif (preg_match('/([0-9]+)w/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationWeek");
  336. elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay");
  337. else print $objp->duration;
  338. print '</td>';
  339. }
  340. // Sell price
  341. if (empty($conf->global->PRODUIT_MULTIPRICES))
  342. {
  343. print '<td align="right">';
  344. if ($objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC");
  345. else print price($objp->price).' '.$langs->trans("HT");
  346. print '</td>';
  347. }
  348. // Better buy price
  349. print '<td align="right">';
  350. if ($objp->minsellprice != '')
  351. {
  352. //print price($objp->minsellprice).' '.$langs->trans("HT");
  353. if ($product_fourn->find_min_price_product_fournisseur($objp->rowid) > 0)
  354. {
  355. if ($product_fourn->product_fourn_price_id > 0)
  356. {
  357. $htmltext=$product_fourn->display_price_product_fournisseur();
  358. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire) print $form->textwithpicto(price($product_fourn->fourn_unitprice).' '.$langs->trans("HT"),$htmltext);
  359. else print price($product_fourn->fourn_unitprice).' '.$langs->trans("HT");
  360. }
  361. }
  362. }
  363. print '</td>';
  364. // Show stock
  365. if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1)
  366. {
  367. if ($objp->fk_product_type != 1)
  368. {
  369. $product_static->id = $objp->rowid;
  370. $product_static->load_stock();
  371. print '<td align="right">';
  372. if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' ';
  373. print $product_static->stock_reel;
  374. print '</td>';
  375. }
  376. else
  377. {
  378. print '<td>&nbsp;</td>';
  379. }
  380. }
  381. // Status (to buy)
  382. print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->tosell,5,0).'</td>';
  383. // Status (to sell)
  384. print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->tobuy,5,1).'</td>';
  385. print "</tr>\n";
  386. $i++;
  387. }
  388. if ($num > $conf->liste_limit)
  389. {
  390. if ($sref || $snom || $sall || $sbarcode || GETPOST('search'))
  391. {
  392. print_barre_liste('', $page, "liste.php", "&amp;sref=".$sref."&amp;snom=".$snom."&amp;sall=".$sall."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy, $sortfield, $sortorder,'',$num);
  393. }
  394. else
  395. {
  396. print_barre_liste('', $page, "liste.php", "&amp;sref=$sref&amp;snom=$snom&amp;fourn_id=$fourn_id".(isset($type)?"&amp;type=$type":"")."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy, $sortfield, $sortorder,'',$num);
  397. }
  398. }
  399. $db->free($resql);
  400. print "</table>";
  401. print '</form>';
  402. }
  403. }
  404. else
  405. {
  406. dol_print_error($db);
  407. }
  408. }
  409. llxFooter();
  410. $db->close();
  411. ?>