PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/reassort.php

https://bitbucket.org/speedealing/speedealing
PHP | 359 lines | 269 code | 46 blank | 44 comment | 57 complexity | 6b020f165f8432e9dbcebd54ae6a10e9 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/reassort.php
  21. * \ingroup produit
  22. * \brief Page to list stocks
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  28. $langs->load("products");
  29. $langs->load("stocks");
  30. // Security check
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. $result=restrictedArea($user,'produit|service');
  33. $action=GETPOST('action','alpha');
  34. $sref=GETPOST("sref");
  35. $snom=GETPOST("snom");
  36. $sall=GETPOST("sall");
  37. $type=GETPOST("type","int");
  38. $sbarcode=GETPOST("sbarcode");
  39. $catid=GETPOST('catid','int');
  40. $toolowstock=GETPOST('toolowstock');
  41. $tosell = GETPOST("tosell");
  42. $tobuy = GETPOST("tobuy");
  43. $fourn_id = GETPOST("fourn_id",'int');
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if (! $sortfield) $sortfield="stock_physique";
  48. if (! $sortorder) $sortorder="ASC";
  49. $limit = $conf->liste_limit;
  50. $offset = $limit * $page ;
  51. // Load sale and categ filters
  52. $search_sale = GETPOST("search_sale");
  53. $search_categ = GETPOST("search_categ");
  54. // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
  55. //$object->getCanvas($id);
  56. $canvas=GETPOST("canvas");
  57. $objcanvas='';
  58. if (! empty($canvas))
  59. {
  60. require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
  61. $objcanvas = new Canvas($db,$action);
  62. $objcanvas->getCanvas('product','list',$canvas);
  63. }
  64. if (! empty($_POST["button_removefilter_x"]))
  65. {
  66. $sref="";
  67. $snom="";
  68. $sall="";
  69. $search_sale="";
  70. $search_categ="";
  71. $type="";
  72. $catid='';
  73. $toolowstock='';
  74. }
  75. /*
  76. * Actions
  77. */
  78. // None
  79. /*
  80. * View
  81. */
  82. $htmlother=new FormOther($db);
  83. $title=$langs->trans("ProductsAndServices");
  84. $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
  85. $sql.= ' p.fk_product_type, p.tms as datem,';
  86. $sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte,';
  87. $sql.= ' SUM(s.reel) as stock_physique';
  88. $sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
  89. // We'll need this table joined to the select in order to filter by categ
  90. if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
  91. $sql.= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product';
  92. $sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
  93. if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
  94. if ($sall)
  95. {
  96. $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)."%')";
  97. }
  98. // if the type is not 1, we show all products (type = 0,2,3)
  99. if (dol_strlen($type))
  100. {
  101. if ($type==1)
  102. {
  103. $sql.= " AND p.fk_product_type = '1'";
  104. }
  105. else
  106. {
  107. $sql.= " AND p.fk_product_type <> '1'";
  108. }
  109. }
  110. if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'";
  111. if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'";
  112. if ($snom) $sql.= " AND p.label LIKE '%".$db->escape($snom)."%'";
  113. if (! empty($tosell))
  114. {
  115. $sql.= " AND p.tosell = ".$tosell;
  116. }
  117. if (! empty($tobuy))
  118. {
  119. $sql.= " AND p.tobuy = ".$tobuy;
  120. }
  121. if (! empty($canvas))
  122. {
  123. $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
  124. }
  125. if($catid)
  126. {
  127. $sql.= " AND cp.fk_categorie = ".$catid;
  128. }
  129. if ($fourn_id > 0)
  130. {
  131. $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
  132. }
  133. // Insert categ filter
  134. if ($search_categ)
  135. {
  136. $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ);
  137. }
  138. $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
  139. $sql.= " p.fk_product_type, p.tms,";
  140. $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
  141. if ($toolowstock) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
  142. $sql.= $db->order($sortfield,$sortorder);
  143. $sql.= $db->plimit($limit + 1, $offset);
  144. $resql = $db->query($sql);
  145. if ($resql)
  146. {
  147. $num = $db->num_rows($resql);
  148. $i = 0;
  149. if ($num == 1 && ($sall or $snom or $sref))
  150. {
  151. $objp = $db->fetch_object($resql);
  152. header("Location: fiche.php?id=$objp->rowid");
  153. exit;
  154. }
  155. $helpurl='';
  156. $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:M&oacute;dulo_Stocks';
  157. if (isset($type))
  158. {
  159. if ($type==1) { $texte = $langs->trans("Services"); }
  160. else { $texte = $langs->trans("Products"); }
  161. } else {
  162. $texte = $langs->trans("ProductsAndServices");
  163. }
  164. $texte.=' ('.$langs->trans("Stocks").')';
  165. llxHeader("",$title,$helpurl,$texte);
  166. if ($sref || $snom || $sall || GETPOST('search'))
  167. {
  168. print_barre_liste($texte, $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&amp;sall=".$sall."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy, $sortfield, $sortorder,'',$num);
  169. }
  170. else
  171. {
  172. print_barre_liste($texte, $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&amp;type=$type":""), $sortfield, $sortorder,'',$num);
  173. }
  174. if (! empty($catid))
  175. {
  176. print "<div id='ways'>";
  177. $c = new Categorie($db);
  178. $c->fetch($catid);
  179. $ways = $c->print_all_ways(' &gt; ','product/reassort.php');
  180. print " &gt; ".$ways[0]."<br>\n";
  181. print "</div><br>";
  182. }
  183. print '<form action="reassort.php" method="post" name="formulaire">';
  184. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  185. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  186. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  187. print '<input type="hidden" name="type" value="'.$type.'">';
  188. print '<table class="liste" width="100%">';
  189. // Filter on categories
  190. $moreforfilter='';
  191. if (! empty($conf->categorie->enabled))
  192. {
  193. $moreforfilter.=$langs->trans('Categories'). ': ';
  194. $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ');
  195. $moreforfilter.=' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ';
  196. }
  197. $moreforfilter.=$langs->trans("StockTooLow").' <input type="checkbox" name="toolowstock" value="1"'.($toolowstock?' checked="checked"':'').'>';
  198. if ($moreforfilter)
  199. {
  200. print '<tr class="liste_titre">';
  201. print '<td class="liste_titre" colspan="9">';
  202. print $moreforfilter;
  203. print '</td></tr>';
  204. }
  205. $param="&tosell=$tosell&tobuy=$tobuy".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref";
  206. // Lignes des titres
  207. print "<tr class=\"liste_titre\">";
  208. print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref",$param,"","",$sortfield,$sortorder);
  209. print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label",$param,"","",$sortfield,$sortorder);
  210. if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
  211. print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder);
  212. print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder);
  213. // TODO Add info of running suppliers/customers orders
  214. //print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder);
  215. print '<td class="liste_titre">&nbsp;</td>';
  216. print_liste_field_titre($langs->trans("Sell"),"reassort.php", "p.tosell",$param,"",'align="right"',$sortfield,$sortorder);
  217. print_liste_field_titre($langs->trans("Buy"),"reassort.php", "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder);
  218. print "</tr>\n";
  219. // Lignes des champs de filtre
  220. print '<tr class="liste_titre">';
  221. print '<td class="liste_titre">';
  222. print '<input class="flat" type="text" name="sref" value="'.$sref.'">';
  223. print '</td>';
  224. print '<td class="liste_titre">';
  225. print '<input class="flat" type="text" name="snom" value="'.$snom.'">';
  226. print '</td>';
  227. if (! empty($conf->service->enabled) && $type == 1)
  228. {
  229. print '<td class="liste_titre">';
  230. print '&nbsp;';
  231. print '</td>';
  232. }
  233. print '<td class="liste_titre">&nbsp;</td>';
  234. print '<td class="liste_titre" align="right">&nbsp;</td>';
  235. print '<td class="liste_titre">&nbsp;</td>';
  236. print '<td class="liste_titre">&nbsp;</td>';
  237. print '<td class="liste_titre" align="right">';
  238. print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
  239. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" alt="'.$langs->trans("RemoveFilter").'">';
  240. print '</td>';
  241. print '</tr>';
  242. $product_static=new Product($db);
  243. $var=True;
  244. while ($i < min($num,$limit))
  245. {
  246. $objp = $db->fetch_object($resql);
  247. // Multilangs
  248. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  249. {
  250. $sql = "SELECT label";
  251. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  252. $sql.= " WHERE fk_product=".$objp->rowid;
  253. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  254. $sql.= " LIMIT 1";
  255. $result = $db->query($sql);
  256. if ($result)
  257. {
  258. $objtp = $db->fetch_object($result);
  259. if (! empty($objtp->label)) $objp->label = $objtp->label;
  260. }
  261. }
  262. $var=!$var;
  263. print '<tr '.$bc[$var].'><td nowrap="nowrap">';
  264. $product_static->ref=$objp->ref;
  265. $product_static->id=$objp->rowid;
  266. $product_static->type=$objp->fk_product_type;
  267. print $product_static->getNomUrl(1,'',16);
  268. //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
  269. print '</td>';
  270. print '<td>'.$objp->label.'</td>';
  271. if (! empty($conf->service->enabled) && $type == 1)
  272. {
  273. print '<td align="center">';
  274. if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear");
  275. elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth");
  276. elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay");
  277. else print $objp->duration;
  278. print '</td>';
  279. }
  280. //print '<td align="right">'.$objp->stock_theorique.'</td>';
  281. print '<td align="right">'.$objp->seuil_stock_alerte.'</td>';
  282. print '<td align="right">';
  283. if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' ';
  284. print $objp->stock_physique;
  285. print '</td>';
  286. print '<td align="right"><a href="'.DOL_URL_ROOT.'/product/stock/mouvement.php?idproduct='.$product_static->id.'">'.$langs->trans("Movements").'</a></td>';
  287. print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->statut,5,0).'</td>';
  288. print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->tobuy,5,1).'</td>';
  289. print "</tr>\n";
  290. $i++;
  291. }
  292. print "</table>";
  293. print '</form>';
  294. if ($num > $conf->liste_limit)
  295. {
  296. if ($sref || $snom || $sall || GETPOST('search'))
  297. {
  298. print_barre_liste('', $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&amp;sall=".$sall."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, '');
  299. }
  300. else
  301. {
  302. print_barre_liste('', $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&amp;type=$type":"")."&amp;tosell=".$tosell."&amp;tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, '');
  303. }
  304. }
  305. $db->free($resql);
  306. }
  307. else
  308. {
  309. dol_print_error($db);
  310. }
  311. llxFooter();
  312. $db->close();
  313. ?>