32require
'../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
47$langs->loadLangs(array(
'products',
'stocks'));
49$action =
GETPOST(
'action',
'aZ09');
50$sref =
GETPOST(
"sref",
'alpha');
51$snom =
GETPOST(
"snom",
'alpha');
52$sall = trim(
GETPOST(
'search_all',
'alphanohtml'));
54$search_barcode =
GETPOST(
"search_barcode",
'alpha');
55$search_toolowstock =
GETPOST(
'search_toolowstock');
60$search_stock_physique =
GETPOST(
'search_stock_physique',
'alpha');
62$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
63$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
65if (empty($page) || $page < 0) {
75if (empty($page) || $page == -1) {
78$offset = $limit * $page;
81$search_sale =
GETPOST(
"search_sale");
82if (GETPOSTISSET(
'catid')) {
92 require_once DOL_DOCUMENT_ROOT.
'/core/class/canvas.class.php';
93 $objcanvas =
new Canvas($db, $action);
94 $objcanvas->getCanvas(
'product',
'list', $canvas);
98$virtualdiffersfromphysical = 0;
104 || isModEnabled(
'mrp')) {
105 $virtualdiffersfromphysical = 1;
109$hookmanager->initHooks(array(
'productreassortlist'));
112 $socid = $user->socid;
114$result =
restrictedArea($user,
'produit|service', 0,
'product&product');
124if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
132 $search_toolowstock =
'';
135 $search_stock_physique =
'';
144$helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
146$form =
new Form($db);
148if (!empty($objp->stock_physique) && $objp->stock_physique < 0) {
149 print
'<span class="warning">';
152$sql =
'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
153$sql .=
' p.fk_product_type, p.tms as datem,';
154$sql .=
' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
155if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
156 $sql .=
' p.stock as stock_physique';
158 $sql .=
' SUM(s.reel) as stock_physique';
161 $sql .=
', u.short_label as unit_short';
164$parameters = array();
165$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object);
166$sql .= $hookmanager->resPrint;
167$sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
168if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
169 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'product_stock as s ON p.rowid = s.fk_product';
172 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_units as u on p.fk_unit = u.rowid';
175$parameters = array();
176$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object);
177$sql .= $hookmanager->resPrint;
178$sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
179if (!empty($search_categ) && $search_categ !=
'-1') {
181 if ($search_categ == -2) {
182 $sql .=
" NOT EXISTS ";
187 $sql .=
" SELECT cp.fk_categorie, cp.fk_product";
188 $sql .=
" FROM " . MAIN_DB_PREFIX .
"categorie_product as cp";
189 $sql .=
" WHERE cp.fk_product = p.rowid";
190 if ($search_categ > 0) {
191 $sql .=
" AND cp.fk_categorie = " . ((int) $search_categ);
195if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
197 $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') .
"))";
203 FROM " . MAIN_DB_PREFIX .
"entrepot as e
204 WHERE e.rowid = s.fk_entrepot AND e.entity IN (" .
getEntity(
'stock') .
"))
206 SELECT SUM(cd1.qty) as qty
207 FROM " . MAIN_DB_PREFIX .
"commande_fournisseurdet as cd1
208 LEFT JOIN " . MAIN_DB_PREFIX .
"commande_fournisseur as c1
209 ON c1.rowid = cd1.fk_commande
210 WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
213 SELECT SUM(cd2.qty) as qty
214 FROM " . MAIN_DB_PREFIX .
"commandedet as cd2
215 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c2 ON c2.rowid = cd2.fk_commande
216 WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
219 SELECT SUM(ed3.qty) as qty
220 FROM " . MAIN_DB_PREFIX .
"expeditiondet as ed3
221 LEFT JOIN " . MAIN_DB_PREFIX .
"expedition as e3 ON e3.rowid = ed3.fk_expedition
222 LEFT JOIN " . MAIN_DB_PREFIX .
"commandedet as cd3 ON ed3.fk_elementdet = cd3.rowid
223 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c3 ON c3.rowid = cd3.fk_commande
224 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
227 SELECT SUM(mp4.qty) as qty
228 FROM " . MAIN_DB_PREFIX .
"mrp_production as mp4
229 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)
230 WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
236 $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
241 $sql .=
" AND p.fk_product_type = '1'";
243 $sql .=
" AND p.fk_product_type <> '1'";
249if ($search_barcode) {
255if (!empty($tosell)) {
256 $sql .=
" AND p.tosell = ".((int) $tosell);
259 $sql .=
" AND p.tobuy = ".((int) $tobuy);
261if (!empty($canvas)) {
262 $sql .=
" AND p.canvas = '".$db->escape($canvas).
"'";
265 $sql .=
" AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
267if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
268 if ($search_toolowstock) {
269 $sql .=
" AND p.stock < p.seuil_stock_alerte";
271 if ($search_stock_physique !=
'') {
276$parameters = array();
277$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
278$sql .= $hookmanager->resPrint;
279if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
280 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
281 $sql .=
" p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
285$parameters = array();
286$reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters, $object);
287$sql .= $hookmanager->resPrint;
290if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
291 if ($search_toolowstock) {
292 $sql_having .=
" HAVING SUM(" . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
") < p.seuil_stock_alerte";
294 if ($search_stock_physique !=
'') {
296 $natural_search_physique =
natural_search(
'SUM(' . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
')', $search_stock_physique, 1, 1);
297 $natural_search_physique =
" " . substr($natural_search_physique, 1, -1);
298 if (!empty($sql_having)) {
299 $sql_having .=
" AND";
301 $sql_having .=
" HAVING";
303 $sql_having .= $natural_search_physique;
308$parameters = array();
309$reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters, $object);
310if (!empty($hookmanager->resPrint)) {
311 if (!empty($sql_having)) {
312 $sql_having .=
" AND";
314 $sql_having .=
" HAVING";
316 $sql_having .= $hookmanager->resPrint;
319if (!empty($sql_having)) {
322$sql .= $db->order($sortfield, $sortorder);
325$nbtotalofrecords =
'';
327 $result = $db->query($sql);
328 $nbtotalofrecords = $db->num_rows($result);
329 if (($page * $limit) > $nbtotalofrecords) {
335$sql .= $db->plimit($limit + 1, $offset);
337$resql = $db->query($sql);
339 $num = $db->num_rows($resql);
343 if ($num == 1 &&
GETPOST(
'autojumpifoneonly') && ($sall || $snom || $sref)) {
344 $objp = $db->fetch_object($resql);
345 header(
"Location: card.php?id=$objp->rowid");
351 $texte = $langs->trans(
"Services");
353 $texte = $langs->trans(
"Products");
356 $texte = $langs->trans(
"ProductsAndServices");
358 $texte .=
' ('.$langs->trans(
"MenuStocks").
')';
361 if ($limit > 0 && $limit !=
$conf->liste_limit) {
362 $param .=
'&limit='.((int) $limit);
365 $param .=
"&sall=".urlencode($sall);
368 $param .=
"&tosell=".urlencode($tosell);
371 $param .=
"&tobuy=".urlencode($tobuy);
374 $param .=
"&type=".urlencode((
string) ($type));
377 $param .=
"&fourn_id=".urlencode((
string) ($fourn_id));
380 $param .=
"&snom=".urlencode($snom);
383 $param .=
"&sref=".urlencode($sref);
386 $param .=
"&search_sale=".urlencode($search_sale);
388 if ($search_categ > 0) {
389 $param .=
"&search_categ=".urlencode((
string) ($search_categ));
391 if ($search_toolowstock) {
392 $param .=
"&search_toolowstock=".urlencode($search_toolowstock);
395 $param .=
"&sbarcode=".urlencode((
string) ($sbarcode));
397 if ($search_stock_physique) {
398 $param .=
'&search_stock_physique=' . urlencode($search_stock_physique);
401 llxHeader(
"", $texte, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-reassort');
403 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" name="formulaire">';
404 print
'<input type="hidden" name="token" value="'.newToken().
'">';
405 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
406 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
407 print
'<input type="hidden" name="page" value="'.$page.
'">';
408 print
'<input type="hidden" name="type" value="'.$type.
'">';
410 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'product', 0,
'',
'', $limit);
412 if ($search_categ > 0) {
413 print
"<div id='ways'>";
415 $c->fetch($search_categ);
416 $ways = $c->print_all_ways(
' > ',
'product/reassort.php');
417 print
" > ".$ways[0].
"<br>\n";
423 if (isModEnabled(
'category')) {
424 $moreforfilter .=
'<div class="divsearchfield">';
425 $moreforfilter .=
img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
426 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1);
427 $moreforfilter .=
'</div>';
430 $moreforfilter .=
'<div class="divsearchfield">';
431 $moreforfilter .=
'<label for="search_toolowstock">'.$langs->trans(
"StockTooLow").
' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ?
' checked' :
'').
'>';
432 $moreforfilter .=
'</div>';
434 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
435 print $moreforfilter;
436 $parameters = array();
437 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object, $action);
438 print $hookmanager->resPrint;
442 $formProduct->loadWarehouses();
443 $warehouses_list = $formProduct->cache_warehouses;
444 $nb_warehouse = count($warehouses_list);
445 $colspan_warehouse = 1;
447 $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
450 print
'<div class="div-table-responsive">';
451 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">';
454 print
'<tr class="liste_titre_filter">';
457 print
'<td class="liste_titre maxwidthsearch">';
458 $searchpicto = $form->showFilterAndCheckAddButtons(0);
462 print
'<td class="liste_titre">';
463 print
'<input class="flat" type="text" name="sref" size="6" value="'.$sref.
'">';
465 print
'<td class="liste_titre">';
466 print
'<input class="flat" type="text" name="snom" size="8" value="'.$snom.
'">';
469 if (isModEnabled(
"service") && $type == 1) {
470 print
'<td class="liste_titre">';
475 print
'<td class="liste_titre"> </td>';
476 print
'<td class="liste_titre right"> </td>';
478 print
'<td class="liste_titre right">';
479 print
'<input class="flat" type="text" size="5" name="search_stock_physique" value="'.dol_escape_htmltag($search_stock_physique).
'">';
481 if ($virtualdiffersfromphysical) {
482 print
'<td class="liste_titre"> </td>';
484 print
'<td class="liste_titre"> </td>';
485 print
'<td class="liste_titre" colspan="'.$colspan_warehouse.
'"> </td>';
486 print
'<td class="liste_titre"></td>';
487 $parameters = array();
488 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
489 print $hookmanager->resPrint;
491 print
'<td class="liste_titre maxwidthsearch">';
492 $searchpicto = $form->showFilterAndCheckAddButtons(0);
499 print
'<tr class="liste_titre">';
506 if (isModEnabled(
"service") && $type == 1) {
507 print_liste_field_titre(
"Duration", $_SERVER[
"PHP_SELF"],
"p.duration",
'', $param,
"", $sortfield, $sortorder,
'center ');
509 print_liste_field_titre(
"StockLimit", $_SERVER[
"PHP_SELF"],
"p.seuil_stock_alerte",
'', $param,
"", $sortfield, $sortorder,
'right ');
510 print_liste_field_titre(
"DesiredStock", $_SERVER[
"PHP_SELF"],
"p.desiredstock",
'', $param,
"", $sortfield, $sortorder,
'right ');
511 print_liste_field_titre(
"PhysicalStock", $_SERVER[
"PHP_SELF"],
"stock_physique",
'', $param,
"", $sortfield, $sortorder,
'right ');
514 if ($nb_warehouse > 1) {
515 foreach ($warehouses_list as &$wh) {
520 if ($virtualdiffersfromphysical) {
521 print_liste_field_titre(
"VirtualStock", $_SERVER[
"PHP_SELF"],
"",
'', $param,
"", $sortfield, $sortorder,
'right ',
'VirtualStockDesc');
525 print_liste_field_titre(
"Unit", $_SERVER[
"PHP_SELF"],
"unit_short",
'', $param,
'align="right"', $sortfield, $sortorder);
528 print_liste_field_titre(
"ProductStatusOnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
'', $param,
"", $sortfield, $sortorder,
'right ');
529 print_liste_field_titre(
"ProductStatusOnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
'', $param,
"", $sortfield, $sortorder,
'right ');
531 $parameters = array(
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
532 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
533 print $hookmanager->resPrint;
540 while ($i < min($num, $limit)) {
541 $objp = $db->fetch_object($resql);
544 $product->fetch($objp->rowid);
545 $product->load_stock();
552 print
'<td class="nowrap">';
553 print $product->getNomUrl(1,
'', 16);
556 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).
'">'.
dol_escape_htmltag($product->label).
'</td>';
558 if (isModEnabled(
"service") && $type == 1) {
559 print
'<td class="center">';
560 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
561 print $regs[1].
' '.$langs->trans(
"DurationYear");
562 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
563 print $regs[1].
' '.$langs->trans(
"DurationMonth");
564 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
565 print $regs[1].
' '.$langs->trans(
"DurationDay");
567 print $objp->duration;
572 print
'<td class="right">';
573 print $objp->seuil_stock_alerte;
575 print
'<td class="right">';
576 print $objp->desiredstock;
579 print
'<td class="right">';
580 if ($objp->seuil_stock_alerte !=
'' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
581 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
583 if ($objp->stock_physique < 0) {
584 print
'<span class="warning">';
586 print
price(
price2num($objp->stock_physique,
'MS'), 0, $langs, 1, 0);
587 if ($objp->stock_physique < 0) {
594 if ($nb_warehouse > 1) {
595 foreach ($warehouses_list as &$wh) {
596 print
'<td class="right">';
597 print
price(empty($product->stock_warehouse[$wh[
'id']]->real) ? 0 :
price2num($product->stock_warehouse[$wh[
'id']]->real,
'MS'), 0, $langs, 1, 0);
604 if ($virtualdiffersfromphysical) {
605 print
'<td class="right">';
606 if ($objp->seuil_stock_alerte !=
'' && ($product->stock_theorique < (
float) $objp->seuil_stock_alerte)) {
607 print
img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
609 if ($objp->stock_physique < 0) {
610 print
'<span class="warning">';
612 print
price(
price2num($product->stock_theorique,
'MS'), 0, $langs, 1, 0);
613 if ($objp->stock_physique < 0) {
620 print
'<td class="left">'.dol_escape_htmltag($objp->unit_short).
'</td>';
622 print
'<td class="center nowraponall">';
623 print
img_picto($langs->trans(
"StockMovement"),
'movement',
'class="pictofixedwidth"');
624 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?idproduct='.$product->id.
'">'.$langs->trans(
"Movements").
'</a>';
626 print
'<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).
'</td>';
627 print
'<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).
'</td>';
629 $parameters = array(
'obj' => $objp);
630 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $product);
631 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage categories.
Class to manage products or services.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
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 a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.