31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
38$langs->loadLangs(array(
'products',
'stocks'));
40$action =
GETPOST(
'action',
'aZ09');
41$sref =
GETPOST(
"sref",
'alpha');
42$snom =
GETPOST(
"snom",
'alpha');
43$sall = trim((
GETPOST(
'search_all',
'alphanohtml') !=
'') ?
GETPOST(
'search_all',
'alphanohtml') :
GETPOST(
'sall',
'alphanohtml'));
44$type = GETPOSTISSET(
'type') ?
GETPOST(
'type',
'int') :
Product::TYPE_PRODUCT;
45$search_barcode =
GETPOST(
"search_barcode",
'alpha');
46$search_toolowstock =
GETPOST(
'search_toolowstock');
49$fourn_id =
GETPOST(
"fourn_id",
'int');
50$sbarcode =
GETPOST(
"sbarcode",
'int');
51$search_stock_physique =
GETPOST(
'search_stock_physique',
'alpha');
53$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
54$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
55$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
56if (empty($page) || $page < 0) {
65$limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
66if (empty($page) || $page == -1) {
69$offset = $limit * $page;
72$search_sale =
GETPOST(
"search_sale");
73if (GETPOSTISSET(
'catid')) {
74 $search_categ =
GETPOST(
'catid',
'int');
76 $search_categ =
GETPOST(
'search_categ',
'int');
83 require_once DOL_DOCUMENT_ROOT.
'/core/class/canvas.class.php';
84 $objcanvas =
new Canvas($db, $action);
85 $objcanvas->getCanvas(
'product',
'list', $canvas);
89$virtualdiffersfromphysical = 0;
95 || isModEnabled(
'mrp')) {
96 $virtualdiffersfromphysical = 1;
100$hookmanager->initHooks(array(
'productreassortlist'));
103 $socid = $user->socid;
105$result =
restrictedArea($user,
'produit|service', 0,
'product&product');
113if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
121 $search_toolowstock =
'';
124 $search_stock_physique =
'';
133$helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
135$form =
new Form($db);
137if (!empty($objp->stock_physique) && $objp->stock_physique < 0) {
138 print
'<span class="warning">';
141$sql =
'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
142$sql .=
' p.fk_product_type, p.tms as datem,';
143$sql .=
' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
144$sql .=
' SUM(s.reel) as stock_physique';
146 $sql .=
', u.short_label as unit_short';
149$parameters = array();
150$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object);
151$sql .= $hookmanager->resPrint;
152$sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
153$sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product_stock as s ON p.rowid = s.fk_product';
155 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_units as u on p.fk_unit = u.rowid';
158$parameters = array();
159$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object);
160$sql .= $hookmanager->resPrint;
161$sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
162if (!empty($search_categ) && $search_categ !=
'-1') {
164 if ($search_categ == -2) {
165 $sql .=
" NOT EXISTS ";
170 $sql .=
" SELECT cp.fk_categorie, cp.fk_product";
171 $sql .=
" FROM " . MAIN_DB_PREFIX .
"categorie_product as cp";
172 $sql .=
" WHERE cp.fk_product = p.rowid";
173 if ($search_categ > 0) {
174 $sql .=
" AND cp.fk_categorie = " . ((int) $search_categ);
179 $sql .=
" AND EXISTS (SELECT e.rowid FROM ".MAIN_DB_PREFIX.
"entrepot as e WHERE e.rowid = s.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
"))";
185 FROM ".MAIN_DB_PREFIX.
"entrepot as e
186 WHERE e.rowid = s.fk_entrepot AND e.entity IN (".
getEntity(
'stock').
"))
188 SELECT SUM(cd1.qty) as qty
189 FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd1
190 LEFT JOIN ".MAIN_DB_PREFIX.
"commande_fournisseur as c1
191 ON c1.rowid = cd1.fk_commande
192 WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
195 SELECT SUM(cd2.qty) as qty
196 FROM ".MAIN_DB_PREFIX.
"commandedet as cd2
197 LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c2 ON c2.rowid = cd2.fk_commande
198 WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
201 SELECT SUM(ed3.qty) as qty
202 FROM ".MAIN_DB_PREFIX.
"expeditiondet as ed3
203 LEFT JOIN ".MAIN_DB_PREFIX.
"expedition as e3 ON e3.rowid = ed3.fk_expedition
204 LEFT JOIN ".MAIN_DB_PREFIX.
"commandedet as cd3 ON ed3.fk_origin_line = cd3.rowid
205 LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c3 ON c3.rowid = cd3.fk_commande
206 WHERE e3.entity IN (1) AND cd3.fk_product = p.rowid AND c3.fk_statut IN (1,2) AND e3.fk_statut IN (1,2) AND ed3.qty <> 0
209 SELECT SUM(mp4.qty) as qty
210 FROM ".MAIN_DB_PREFIX.
"mrp_production as mp4
211 LEFT JOIN ".MAIN_DB_PREFIX.
"mrp_mo as m4 ON m4.rowid = mp4.fk_mo AND m4.entity IN (1) AND m4.status IN (1,2)
212 WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
217 $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
222 $sql .=
" AND p.fk_product_type = '1'";
224 $sql .=
" AND p.fk_product_type <> '1'";
230if ($search_barcode) {
236if (!empty($tosell)) {
237 $sql .=
" AND p.tosell = ".((int) $tosell);
240 $sql .=
" AND p.tobuy = ".((int) $tobuy);
242if (!empty($canvas)) {
243 $sql .=
" AND p.canvas = '".$db->escape($canvas).
"'";
246 $sql .=
" AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
249$parameters = array();
250$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
251$sql .= $hookmanager->resPrint;
252$sql .=
" GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
253$sql .=
" p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
256$parameters = array();
257$reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters, $object);
258$sql .= $hookmanager->resPrint;
261if ($search_toolowstock) {
262 $sql_having .=
" HAVING SUM(".$db->ifsql(
's.reel IS NULL',
'0',
's.reel').
") < p.seuil_stock_alerte";
264if ($search_stock_physique !=
'') {
266 $natural_search_physique =
natural_search(
'SUM(' . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
')', $search_stock_physique, 1, 1);
267 $natural_search_physique =
" " . substr($natural_search_physique, 1, -1);
268 if (!empty($sql_having)) {
269 $sql_having .=
" AND";
271 $sql_having .=
" HAVING";
273 $sql_having .= $natural_search_physique;
277$parameters = array();
278$reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters, $object);
279if (!empty($hookmanager->resPrint)) {
280 if (!empty($sql_having)) {
281 $sql_having .=
" AND";
283 $sql_having .=
" HAVING";
285 $sql_having .= $hookmanager->resPrint;
288if (!empty($sql_having)) {
291$sql .= $db->order($sortfield, $sortorder);
294$nbtotalofrecords =
'';
296 $result = $db->query($sql);
297 $nbtotalofrecords = $db->num_rows($result);
298 if (($page * $limit) > $nbtotalofrecords) {
304$sql .= $db->plimit($limit + 1, $offset);
306$resql = $db->query($sql);
308 $num = $db->num_rows($resql);
312 if ($num == 1 &&
GETPOST(
'autojumpifoneonly') && ($sall || $snom || $sref)) {
313 $objp = $db->fetch_object($resql);
314 header(
"Location: card.php?id=$objp->rowid");
320 $texte = $langs->trans(
"Services");
322 $texte = $langs->trans(
"Products");
325 $texte = $langs->trans(
"ProductsAndServices");
327 $texte .=
' ('.$langs->trans(
"MenuStocks").
')';
330 if ($limit > 0 && $limit != $conf->liste_limit) {
331 $param .=
'&limit='.((int) $limit);
334 $param .=
"&sall=".urlencode($sall);
337 $param .=
"&tosell=".urlencode($tosell);
340 $param .=
"&tobuy=".urlencode($tobuy);
343 $param .=
"&type=".urlencode($type);
346 $param .=
"&fourn_id=".urlencode($fourn_id);
349 $param .=
"&snom=".urlencode($snom);
352 $param .=
"&sref=".urlencode($sref);
355 $param .=
"&search_sale=".urlencode($search_sale);
357 if ($search_categ > 0) {
358 $param .=
"&search_categ=".urlencode($search_categ);
360 if ($search_toolowstock) {
361 $param .=
"&search_toolowstock=".urlencode($search_toolowstock);
364 $param .=
"&sbarcode=".urlencode($sbarcode);
366 if ($search_stock_physique) {
367 $param .=
'&search_stock_physique=' . urlencode($search_stock_physique);
372 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" name="formulaire">';
373 print
'<input type="hidden" name="token" value="'.newToken().
'">';
374 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
375 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
376 print
'<input type="hidden" name="page" value="'.$page.
'">';
377 print
'<input type="hidden" name="type" value="'.$type.
'">';
379 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'product', 0,
'',
'', $limit);
381 if ($search_categ > 0) {
382 print
"<div id='ways'>";
384 $c->fetch($search_categ);
385 $ways = $c->print_all_ways(
' > ',
'product/reassort.php');
386 print
" > ".$ways[0].
"<br>\n";
392 if (isModEnabled(
'categorie')) {
393 $moreforfilter .=
'<div class="divsearchfield">';
394 $moreforfilter .=
img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
395 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1);
396 $moreforfilter .=
'</div>';
399 $moreforfilter .=
'<div class="divsearchfield">';
400 $moreforfilter .=
'<label for="search_toolowstock">'.$langs->trans(
"StockTooLow").
' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ?
' checked' :
'').
'>';
401 $moreforfilter .=
'</div>';
403 if (!empty($moreforfilter)) {
404 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
405 print $moreforfilter;
406 $parameters = array();
407 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
408 print $hookmanager->resPrint;
413 $formProduct->loadWarehouses();
414 $warehouses_list = $formProduct->cache_warehouses;
415 $nb_warehouse = count($warehouses_list);
416 $colspan_warehouse = 1;
418 $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
421 print
'<div class="div-table-responsive">';
422 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">';
425 print
'<tr class="liste_titre_filter">';
428 print
'<td class="liste_titre maxwidthsearch">';
429 $searchpicto = $form->showFilterAndCheckAddButtons(0);
433 print
'<td class="liste_titre">';
434 print
'<input class="flat" type="text" name="sref" size="6" value="'.$sref.
'">';
436 print
'<td class="liste_titre">';
437 print
'<input class="flat" type="text" name="snom" size="8" value="'.$snom.
'">';
440 if (isModEnabled(
"service") && $type == 1) {
441 print
'<td class="liste_titre">';
446 print
'<td class="liste_titre"> </td>';
447 print
'<td class="liste_titre right"> </td>';
449 print
'<td class="liste_titre right">';
450 print
'<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).
'">';
452 if ($virtualdiffersfromphysical) {
453 print
'<td class="liste_titre"> </td>';
455 print
'<td class="liste_titre"> </td>';
456 print
'<td class="liste_titre" colspan="'.$colspan_warehouse.
'"> </td>';
457 print
'<td class="liste_titre"></td>';
458 $parameters = array();
459 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
460 print $hookmanager->resPrint;
462 print
'<td class="liste_titre maxwidthsearch">';
463 $searchpicto = $form->showFilterAndCheckAddButtons(0);
470 print
'<tr class="liste_titre">';
477 if (isModEnabled(
"service") && $type == 1) {
478 print_liste_field_titre(
"Duration", $_SERVER[
"PHP_SELF"],
"p.duration",
'', $param,
"", $sortfield, $sortorder,
'center ');
480 print_liste_field_titre(
"StockLimit", $_SERVER[
"PHP_SELF"],
"p.seuil_stock_alerte",
'', $param,
"", $sortfield, $sortorder,
'right ');
481 print_liste_field_titre(
"DesiredStock", $_SERVER[
"PHP_SELF"],
"p.desiredstock",
'', $param,
"", $sortfield, $sortorder,
'right ');
482 print_liste_field_titre(
"PhysicalStock", $_SERVER[
"PHP_SELF"],
"stock_physique",
'', $param,
"", $sortfield, $sortorder,
'right ');
485 if ($nb_warehouse > 1) {
486 foreach ($warehouses_list as &$wh) {
491 if ($virtualdiffersfromphysical) {
492 print_liste_field_titre(
"VirtualStock", $_SERVER[
"PHP_SELF"],
"",
'', $param,
"", $sortfield, $sortorder,
'right ',
'VirtualStockDesc');
496 print_liste_field_titre(
"Unit", $_SERVER[
"PHP_SELF"],
"unit_short",
'', $param,
'align="right"', $sortfield, $sortorder);
499 print_liste_field_titre(
"ProductStatusOnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
'', $param,
"", $sortfield, $sortorder,
'right ');
500 print_liste_field_titre(
"ProductStatusOnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
'', $param,
"", $sortfield, $sortorder,
'right ');
502 $parameters = array(
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
503 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
504 print $hookmanager->resPrint;
511 while ($i < min($num, $limit)) {
512 $objp = $db->fetch_object($resql);
515 $product->fetch($objp->rowid);
516 $product->load_stock();
523 print
'<td class="nowrap">';
524 print $product->getNomUrl(1,
'', 16);
527 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).
'">'.
dol_escape_htmltag($product->label).
'</td>';
529 if (isModEnabled(
"service") && $type == 1) {
530 print
'<td class="center">';
531 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
532 print $regs[1].
' '.$langs->trans(
"DurationYear");
533 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
534 print $regs[1].
' '.$langs->trans(
"DurationMonth");
535 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
536 print $regs[1].
' '.$langs->trans(
"DurationDay");
538 print $objp->duration;
543 print
'<td class="right">';
544 print $objp->seuil_stock_alerte;
546 print
'<td class="right">';
547 print $objp->desiredstock;
550 print
'<td class="right">';
551 if ($objp->seuil_stock_alerte !=
'' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
552 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
554 if ($objp->stock_physique < 0) {
555 print
'<span class="warning">';
557 print
price(
price2num($objp->stock_physique,
'MS'), 0, $langs, 1, 0);
558 if ($objp->stock_physique < 0) {
565 if ($nb_warehouse > 1) {
566 foreach ($warehouses_list as &$wh) {
567 print
'<td class="right">';
568 print
price(empty($product->stock_warehouse[$wh[
'id']]->real) ? 0 :
price2num($product->stock_warehouse[$wh[
'id']]->real,
'MS'), 0, $langs, 1, 0);
575 if ($virtualdiffersfromphysical) {
576 print
'<td class="right">';
577 if ($objp->seuil_stock_alerte !=
'' && ($product->stock_theorique < (
float) $objp->seuil_stock_alerte)) {
578 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
580 if ($objp->stock_physique < 0) {
581 print
'<span class="warning">';
583 print
price(
price2num($product->stock_theorique,
'MS'), 0, $langs, 1, 0);
584 if ($objp->stock_physique < 0) {
591 print
'<td class="left">'.dol_escape_htmltag($objp->unit_short).
'</td>';
593 print
'<td class="center nowraponall">';
594 print
img_picto($langs->trans(
"StockMovement"),
'movement',
'class="pictofixedwidth"');
595 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?idproduct='.$product->id.
'">'.$langs->trans(
"Movements").
'</a>';
597 print
'<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).
'</td>';
598 print
'<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).
'</td>';
600 $parameters = array(
'obj'=>$objp);
601 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $product);
602 print $hookmanager->resPrint;
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage categories.
Class to manage products or services.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.