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'));
45$search_barcode =
GETPOST(
"search_barcode",
'alpha');
46$search_toolowstock =
GETPOST(
'search_toolowstock');
51$search_stock_physique =
GETPOST(
'search_stock_physique',
'alpha');
53$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
54$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
56if (empty($page) || $page < 0) {
66if (empty($page) || $page == -1) {
69$offset = $limit * $page;
72$search_sale =
GETPOST(
"search_sale");
73if (GETPOSTISSET(
'catid')) {
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');
115if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
123 $search_toolowstock =
'';
126 $search_stock_physique =
'';
135$helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
137$form =
new Form($db);
139if (!empty($objp->stock_physique) && $objp->stock_physique < 0) {
140 print
'<span class="warning">';
143$sql =
'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
144$sql .=
' p.fk_product_type, p.tms as datem,';
145$sql .=
' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
146if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
147 $sql .=
' p.stock as stock_physique';
149 $sql .=
' SUM(s.reel) as stock_physique';
152 $sql .=
', u.short_label as unit_short';
155$parameters = array();
156$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object);
157$sql .= $hookmanager->resPrint;
158$sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
159if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
160 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'product_stock as s ON p.rowid = s.fk_product';
163 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_units as u on p.fk_unit = u.rowid';
166$parameters = array();
167$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object);
168$sql .= $hookmanager->resPrint;
169$sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
170if (!empty($search_categ) && $search_categ !=
'-1') {
172 if ($search_categ == -2) {
173 $sql .=
" NOT EXISTS ";
178 $sql .=
" SELECT cp.fk_categorie, cp.fk_product";
179 $sql .=
" FROM " . MAIN_DB_PREFIX .
"categorie_product as cp";
180 $sql .=
" WHERE cp.fk_product = p.rowid";
181 if ($search_categ > 0) {
182 $sql .=
" AND cp.fk_categorie = " . ((int) $search_categ);
186if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
188 $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') .
"))";
194 FROM " . MAIN_DB_PREFIX .
"entrepot as e
195 WHERE e.rowid = s.fk_entrepot AND e.entity IN (" .
getEntity(
'stock') .
"))
197 SELECT SUM(cd1.qty) as qty
198 FROM " . MAIN_DB_PREFIX .
"commande_fournisseurdet as cd1
199 LEFT JOIN " . MAIN_DB_PREFIX .
"commande_fournisseur as c1
200 ON c1.rowid = cd1.fk_commande
201 WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
204 SELECT SUM(cd2.qty) as qty
205 FROM " . MAIN_DB_PREFIX .
"commandedet as cd2
206 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c2 ON c2.rowid = cd2.fk_commande
207 WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
210 SELECT SUM(ed3.qty) as qty
211 FROM " . MAIN_DB_PREFIX .
"expeditiondet as ed3
212 LEFT JOIN " . MAIN_DB_PREFIX .
"expedition as e3 ON e3.rowid = ed3.fk_expedition
213 LEFT JOIN " . MAIN_DB_PREFIX .
"commandedet as cd3 ON ed3.fk_elementdet = cd3.rowid
214 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c3 ON c3.rowid = cd3.fk_commande
215 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
218 SELECT SUM(mp4.qty) as qty
219 FROM " . MAIN_DB_PREFIX .
"mrp_production as mp4
220 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)
221 WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
227 $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
232 $sql .=
" AND p.fk_product_type = '1'";
234 $sql .=
" AND p.fk_product_type <> '1'";
240if ($search_barcode) {
246if (!empty($tosell)) {
247 $sql .=
" AND p.tosell = ".((int) $tosell);
250 $sql .=
" AND p.tobuy = ".((int) $tobuy);
252if (!empty($canvas)) {
253 $sql .=
" AND p.canvas = '".$db->escape($canvas).
"'";
256 $sql .=
" AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
258if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
259 if ($search_toolowstock) {
260 $sql .=
" AND p.stock < p.seuil_stock_alerte";
262 if ($search_stock_physique !=
'') {
267$parameters = array();
268$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
269$sql .= $hookmanager->resPrint;
270if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
271 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
272 $sql .=
" p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
276$parameters = array();
277$reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters, $object);
278$sql .= $hookmanager->resPrint;
281if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
282 if ($search_toolowstock) {
283 $sql_having .=
" HAVING SUM(" . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
") < p.seuil_stock_alerte";
285 if ($search_stock_physique !=
'') {
287 $natural_search_physique =
natural_search(
'SUM(' . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
')', $search_stock_physique, 1, 1);
288 $natural_search_physique =
" " . substr($natural_search_physique, 1, -1);
289 if (!empty($sql_having)) {
290 $sql_having .=
" AND";
292 $sql_having .=
" HAVING";
294 $sql_having .= $natural_search_physique;
299$parameters = array();
300$reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters, $object);
301if (!empty($hookmanager->resPrint)) {
302 if (!empty($sql_having)) {
303 $sql_having .=
" AND";
305 $sql_having .=
" HAVING";
307 $sql_having .= $hookmanager->resPrint;
310if (!empty($sql_having)) {
313$sql .= $db->order($sortfield, $sortorder);
316$nbtotalofrecords =
'';
318 $result = $db->query($sql);
319 $nbtotalofrecords = $db->num_rows($result);
320 if (($page * $limit) > $nbtotalofrecords) {
326$sql .= $db->plimit($limit + 1, $offset);
328$resql = $db->query($sql);
330 $num = $db->num_rows($resql);
334 if ($num == 1 &&
GETPOST(
'autojumpifoneonly') && ($sall || $snom || $sref)) {
335 $objp = $db->fetch_object($resql);
336 header(
"Location: card.php?id=$objp->rowid");
342 $texte = $langs->trans(
"Services");
344 $texte = $langs->trans(
"Products");
347 $texte = $langs->trans(
"ProductsAndServices");
349 $texte .=
' ('.$langs->trans(
"MenuStocks").
')';
352 if ($limit > 0 && $limit != $conf->liste_limit) {
353 $param .=
'&limit='.((int) $limit);
356 $param .=
"&sall=".urlencode($sall);
359 $param .=
"&tosell=".urlencode($tosell);
362 $param .=
"&tobuy=".urlencode($tobuy);
365 $param .=
"&type=".urlencode((
string) ($type));
368 $param .=
"&fourn_id=".urlencode((
string) ($fourn_id));
371 $param .=
"&snom=".urlencode($snom);
374 $param .=
"&sref=".urlencode($sref);
377 $param .=
"&search_sale=".urlencode($search_sale);
379 if ($search_categ > 0) {
380 $param .=
"&search_categ=".urlencode((
string) ($search_categ));
382 if ($search_toolowstock) {
383 $param .=
"&search_toolowstock=".urlencode($search_toolowstock);
386 $param .=
"&sbarcode=".urlencode((
string) ($sbarcode));
388 if ($search_stock_physique) {
389 $param .=
'&search_stock_physique=' . urlencode($search_stock_physique);
392 llxHeader(
"", $texte, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-reassort');
394 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" name="formulaire">';
395 print
'<input type="hidden" name="token" value="'.newToken().
'">';
396 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
397 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
398 print
'<input type="hidden" name="page" value="'.$page.
'">';
399 print
'<input type="hidden" name="type" value="'.$type.
'">';
401 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'product', 0,
'',
'', $limit);
403 if ($search_categ > 0) {
404 print
"<div id='ways'>";
406 $c->fetch($search_categ);
407 $ways = $c->print_all_ways(
' > ',
'product/reassort.php');
408 print
" > ".$ways[0].
"<br>\n";
414 if (isModEnabled(
'category')) {
415 $moreforfilter .=
'<div class="divsearchfield">';
416 $moreforfilter .=
img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
417 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1);
418 $moreforfilter .=
'</div>';
421 $moreforfilter .=
'<div class="divsearchfield">';
422 $moreforfilter .=
'<label for="search_toolowstock">'.$langs->trans(
"StockTooLow").
' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ?
' checked' :
'').
'>';
423 $moreforfilter .=
'</div>';
425 if (!empty($moreforfilter)) {
426 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
427 print $moreforfilter;
428 $parameters = array();
429 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object, $action);
430 print $hookmanager->resPrint;
435 $formProduct->loadWarehouses();
436 $warehouses_list = $formProduct->cache_warehouses;
437 $nb_warehouse = count($warehouses_list);
438 $colspan_warehouse = 1;
440 $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
443 print
'<div class="div-table-responsive">';
444 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">';
447 print
'<tr class="liste_titre_filter">';
450 print
'<td class="liste_titre maxwidthsearch">';
451 $searchpicto = $form->showFilterAndCheckAddButtons(0);
455 print
'<td class="liste_titre">';
456 print
'<input class="flat" type="text" name="sref" size="6" value="'.$sref.
'">';
458 print
'<td class="liste_titre">';
459 print
'<input class="flat" type="text" name="snom" size="8" value="'.$snom.
'">';
462 if (isModEnabled(
"service") && $type == 1) {
463 print
'<td class="liste_titre">';
468 print
'<td class="liste_titre"> </td>';
469 print
'<td class="liste_titre right"> </td>';
471 print
'<td class="liste_titre right">';
472 print
'<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).
'">';
474 if ($virtualdiffersfromphysical) {
475 print
'<td class="liste_titre"> </td>';
477 print
'<td class="liste_titre"> </td>';
478 print
'<td class="liste_titre" colspan="'.$colspan_warehouse.
'"> </td>';
479 print
'<td class="liste_titre"></td>';
480 $parameters = array();
481 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
482 print $hookmanager->resPrint;
484 print
'<td class="liste_titre maxwidthsearch">';
485 $searchpicto = $form->showFilterAndCheckAddButtons(0);
492 print
'<tr class="liste_titre">';
499 if (isModEnabled(
"service") && $type == 1) {
500 print_liste_field_titre(
"Duration", $_SERVER[
"PHP_SELF"],
"p.duration",
'', $param,
"", $sortfield, $sortorder,
'center ');
502 print_liste_field_titre(
"StockLimit", $_SERVER[
"PHP_SELF"],
"p.seuil_stock_alerte",
'', $param,
"", $sortfield, $sortorder,
'right ');
503 print_liste_field_titre(
"DesiredStock", $_SERVER[
"PHP_SELF"],
"p.desiredstock",
'', $param,
"", $sortfield, $sortorder,
'right ');
504 print_liste_field_titre(
"PhysicalStock", $_SERVER[
"PHP_SELF"],
"stock_physique",
'', $param,
"", $sortfield, $sortorder,
'right ');
507 if ($nb_warehouse > 1) {
508 foreach ($warehouses_list as &$wh) {
513 if ($virtualdiffersfromphysical) {
514 print_liste_field_titre(
"VirtualStock", $_SERVER[
"PHP_SELF"],
"",
'', $param,
"", $sortfield, $sortorder,
'right ',
'VirtualStockDesc');
518 print_liste_field_titre(
"Unit", $_SERVER[
"PHP_SELF"],
"unit_short",
'', $param,
'align="right"', $sortfield, $sortorder);
521 print_liste_field_titre(
"ProductStatusOnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
'', $param,
"", $sortfield, $sortorder,
'right ');
522 print_liste_field_titre(
"ProductStatusOnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
'', $param,
"", $sortfield, $sortorder,
'right ');
524 $parameters = array(
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
525 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
526 print $hookmanager->resPrint;
533 while ($i < min($num, $limit)) {
534 $objp = $db->fetch_object($resql);
537 $product->fetch($objp->rowid);
538 $product->load_stock();
545 print
'<td class="nowrap">';
546 print $product->getNomUrl(1,
'', 16);
549 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).
'">'.
dol_escape_htmltag($product->label).
'</td>';
551 if (isModEnabled(
"service") && $type == 1) {
552 print
'<td class="center">';
553 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
554 print $regs[1].
' '.$langs->trans(
"DurationYear");
555 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
556 print $regs[1].
' '.$langs->trans(
"DurationMonth");
557 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
558 print $regs[1].
' '.$langs->trans(
"DurationDay");
560 print $objp->duration;
565 print
'<td class="right">';
566 print $objp->seuil_stock_alerte;
568 print
'<td class="right">';
569 print $objp->desiredstock;
572 print
'<td class="right">';
573 if ($objp->seuil_stock_alerte !=
'' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
574 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
576 if ($objp->stock_physique < 0) {
577 print
'<span class="warning">';
579 print
price(
price2num($objp->stock_physique,
'MS'), 0, $langs, 1, 0);
580 if ($objp->stock_physique < 0) {
587 if ($nb_warehouse > 1) {
588 foreach ($warehouses_list as &$wh) {
589 print
'<td class="right">';
590 print
price(empty($product->stock_warehouse[$wh[
'id']]->real) ? 0 :
price2num($product->stock_warehouse[$wh[
'id']]->real,
'MS'), 0, $langs, 1, 0);
597 if ($virtualdiffersfromphysical) {
598 print
'<td class="right">';
599 if ($objp->seuil_stock_alerte !=
'' && ($product->stock_theorique < (
float) $objp->seuil_stock_alerte)) {
600 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
602 if ($objp->stock_physique < 0) {
603 print
'<span class="warning">';
605 print
price(
price2num($product->stock_theorique,
'MS'), 0, $langs, 1, 0);
606 if ($objp->stock_physique < 0) {
613 print
'<td class="left">'.dol_escape_htmltag($objp->unit_short).
'</td>';
615 print
'<td class="center nowraponall">';
616 print
img_picto($langs->trans(
"StockMovement"),
'movement',
'class="pictofixedwidth"');
617 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?idproduct='.$product->id.
'">'.$langs->trans(
"Movements").
'</a>';
619 print
'<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).
'</td>';
620 print
'<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).
'</td>';
622 $parameters = array(
'obj' => $objp);
623 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $product);
624 print $hookmanager->resPrint;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.