33require
'../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
48$langs->loadLangs(array(
'products',
'stocks'));
50$action =
GETPOST(
'action',
'aZ09');
51$sref =
GETPOST(
"sref",
'alpha');
52$snom =
GETPOST(
"snom",
'alpha');
53$sall = trim(
GETPOST(
'search_all',
'alphanohtml'));
55$search_barcode =
GETPOST(
"search_barcode",
'alpha');
56$search_toolowstock =
GETPOST(
'search_toolowstock');
61$search_stock_physique =
GETPOST(
'search_stock_physique',
'alpha');
63$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
64$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
66if (empty($page) || $page < 0) {
76if (empty($page) || $page == -1) {
79$offset = $limit * $page;
82$search_sale =
GETPOST(
"search_sale");
93 require_once DOL_DOCUMENT_ROOT.
'/core/class/canvas.class.php';
94 $objcanvas =
new Canvas($db, $action);
95 $objcanvas->getCanvas(
'product',
'list', $canvas);
99$virtualdiffersfromphysical = 0;
106 $virtualdiffersfromphysical = 1;
110$hookmanager->initHooks(array(
'productreassortlist'));
113 $socid = $user->socid;
115$result =
restrictedArea($user,
'produit|service', 0,
'product&product');
125if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
133 $search_toolowstock =
'';
136 $search_stock_physique =
'';
145$helpurl =
'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
147$form =
new Form($db);
149$sql =
'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
150$sql .=
' p.fk_product_type, p.tms as datem,';
151$sql .=
' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
152if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
153 $sql .=
' p.stock as stock_physique';
155 $sql .=
' SUM(s.reel) as stock_physique';
158 $sql .=
', u.short_label as unit_short';
161$parameters = array();
162$reshook = $hookmanager->executeHooks(
'printFieldListSelect', $parameters, $object);
163$sql .= $hookmanager->resPrint;
164$sql .=
' FROM '.MAIN_DB_PREFIX.
'product as p';
165if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
166 $sql .=
' LEFT JOIN ' . MAIN_DB_PREFIX .
'product_stock as s ON p.rowid = s.fk_product';
169 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_units as u on p.fk_unit = u.rowid';
172$parameters = array();
173$reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters, $object);
174$sql .= $hookmanager->resPrint;
175$sql .=
" WHERE p.entity IN (".getEntity(
'product').
")";
176if (!empty($search_categ) && $search_categ !=
'-1') {
178 if ($search_categ == -2) {
179 $sql .=
" NOT EXISTS ";
184 $sql .=
" SELECT cp.fk_categorie, cp.fk_product";
185 $sql .=
" FROM " . MAIN_DB_PREFIX .
"categorie_product as cp";
186 $sql .=
" WHERE cp.fk_product = p.rowid";
187 if ($search_categ > 0) {
188 $sql .=
" AND cp.fk_categorie = " . ((int) $search_categ);
192if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
194 $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') .
"))";
200 FROM " . MAIN_DB_PREFIX .
"entrepot as e
201 WHERE e.rowid = s.fk_entrepot AND e.entity IN (" .
getEntity(
'stock') .
"))
203 SELECT SUM(cd1.qty) as qty
204 FROM " . MAIN_DB_PREFIX .
"commande_fournisseurdet as cd1
205 LEFT JOIN " . MAIN_DB_PREFIX .
"commande_fournisseur as c1
206 ON c1.rowid = cd1.fk_commande
207 WHERE c1.entity IN (1) AND cd1.fk_product = p.rowid AND c1.fk_statut in (3,4) AND cd1.qty <> 0
210 SELECT SUM(cd2.qty) as qty
211 FROM " . MAIN_DB_PREFIX .
"commandedet as cd2
212 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c2 ON c2.rowid = cd2.fk_commande
213 WHERE c2.entity IN (1) AND cd2.fk_product = p.rowid AND c2.fk_statut in (1,2) AND cd2.qty <> 0
216 SELECT SUM(ed3.qty) as qty
217 FROM " . MAIN_DB_PREFIX .
"expeditiondet as ed3
218 LEFT JOIN " . MAIN_DB_PREFIX .
"expedition as e3 ON e3.rowid = ed3.fk_expedition
219 LEFT JOIN " . MAIN_DB_PREFIX .
"commandedet as cd3 ON ed3.fk_elementdet = cd3.rowid
220 LEFT JOIN " . MAIN_DB_PREFIX .
"commande as c3 ON c3.rowid = cd3.fk_commande
221 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
224 SELECT SUM(mp4.qty) as qty
225 FROM " . MAIN_DB_PREFIX .
"mrp_production as mp4
226 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)
227 WHERE mp4.fk_product = p.rowid AND mp4.qty <> 0
233 $sql .=
natural_search(array(
'p.ref',
'p.label',
'p.description',
'p.note'), $sall);
238 $sql .=
" AND p.fk_product_type = '1'";
240 $sql .=
" AND p.fk_product_type <> '1'";
246if ($search_barcode) {
252if (!empty($tosell)) {
253 $sql .=
" AND p.tosell = ".((int) $tosell);
256 $sql .=
" AND p.tobuy = ".((int) $tobuy);
258if (!empty($canvas)) {
259 $sql .=
" AND p.canvas = '".$db->escape($canvas).
"'";
262 $sql .=
" AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id);
264if (
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
265 if ($search_toolowstock) {
266 $sql .=
" AND p.stock < p.seuil_stock_alerte";
268 if ($search_stock_physique !=
'') {
273$parameters = array();
274$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $object);
275$sql .= $hookmanager->resPrint;
276if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
277 $sql .=
" GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
278 $sql .=
" p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
282$parameters = array();
283$reshook = $hookmanager->executeHooks(
'printFieldListGroupBy', $parameters, $object);
284$sql .= $hookmanager->resPrint;
287if (!
getDolGlobalString(
'PRODUCT_STOCK_LIST_SHOW_WITH_PRECALCULATED_DENORMALIZED_PHYSICAL_STOCK')) {
288 if ($search_toolowstock) {
289 $sql_having .=
" HAVING SUM(" . $db->ifsql(
's.reel IS NULL',
'0',
's.reel') .
") < p.seuil_stock_alerte";
291 if ($search_stock_physique !=
'') {
292 $natural_search_physique =
natural_search(
'__SUM_OF_REEL__', $search_stock_physique, 1, 1);
293 $natural_search_physique =
" " . substr(str_replace(
'__SUM_OF_REEL__',
'SUM(COALESCE(s.reel, 0))', $natural_search_physique), 1, -1);
294 if (!empty($sql_having)) {
295 $sql_having .=
" AND";
297 $sql_having .=
" HAVING";
299 $sql_having .= $natural_search_physique;
304$parameters = array();
305$reshook = $hookmanager->executeHooks(
'printFieldListHaving', $parameters, $object);
306if (empty($reshook)) {
307 if (empty($sql_having)) {
308 $sql_having .=
" HAVING 1=1";
310 $sql_having .= $hookmanager->resPrint;
312 $sql_having = $hookmanager->resPrint;
315if (!empty($sql_having)) {
319$sql .= $db->order($sortfield, $sortorder);
322$nbtotalofrecords =
'';
324 $result = $db->query($sql);
325 $nbtotalofrecords = $db->num_rows($result);
326 if (($page * $limit) > (
int) $nbtotalofrecords) {
332$sql .= $db->plimit($limit + 1, $offset);
334$resql = $db->query($sql);
336 $num = $db->num_rows($resql);
340 if ($num == 1 &&
GETPOST(
'autojumpifoneonly') && ($sall || $snom || $sref)) {
341 $objp = $db->fetch_object($resql);
342 header(
"Location: card.php?id=$objp->rowid");
347 $texte = $langs->trans(
"Services");
349 $texte = $langs->trans(
"Products");
351 $texte .=
' ('.$langs->trans(
"MenuStocks").
')';
354 if ($limit > 0 && $limit !=
$conf->liste_limit) {
355 $param .=
'&limit='.((int) $limit);
358 $param .=
"&sall=".urlencode($sall);
361 $param .=
"&tosell=".urlencode($tosell);
364 $param .=
"&tobuy=".urlencode($tobuy);
367 $param .=
"&type=".urlencode((
string) ($type));
370 $param .=
"&fourn_id=".urlencode((
string) ($fourn_id));
373 $param .=
"&snom=".urlencode($snom);
376 $param .=
"&sref=".urlencode($sref);
379 $param .=
"&search_sale=".urlencode($search_sale);
381 if ($search_categ > 0) {
382 $param .=
"&search_categ=".urlencode((
string) ($search_categ));
384 if ($search_toolowstock) {
385 $param .=
"&search_toolowstock=".urlencode($search_toolowstock);
388 $param .=
"&sbarcode=".urlencode((
string) ($sbarcode));
390 if ($search_stock_physique) {
391 $param .=
'&search_stock_physique=' . urlencode($search_stock_physique);
394 llxHeader(
"", $texte, $helpurl,
'', 0, 0,
'',
'',
'',
'mod-product page-reassort');
396 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="post" name="formulaire">';
397 print
'<input type="hidden" name="token" value="'.newToken().
'">';
398 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
399 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
400 print
'<input type="hidden" name="page" value="'.$page.
'">';
401 print
'<input type="hidden" name="type" value="'.$type.
'">';
403 print_barre_liste($texte, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'product', 0,
'',
'', $limit);
405 if ($search_categ > 0) {
406 print
"<div id='ways'>";
408 $c->fetch($search_categ);
409 $ways =
$c->print_all_ways(
'auto',
'product/reassort.php');
410 print
" > ".$ways[0].
"<br>\n";
417 $moreforfilter .=
'<div class="divsearchfield">';
418 $moreforfilter .= img_picto($langs->trans(
'Categories'),
'category',
'class="pictofixedwidth"');
419 $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ,
'search_categ', 1);
420 $moreforfilter .=
'</div>';
423 $moreforfilter .=
'<div class="divsearchfield">';
424 $moreforfilter .=
'<label for="search_toolowstock">'.$langs->trans(
"StockTooLow").
' </label><input type="checkbox" id="search_toolowstock" name="search_toolowstock" value="1"'.($search_toolowstock ?
' checked' :
'').
'>';
425 $moreforfilter .=
'</div>';
427 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
428 print $moreforfilter;
429 $parameters = array();
430 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters, $object, $action);
431 print $hookmanager->resPrint;
435 $formProduct->loadWarehouses();
436 $warehouses_list = $formProduct->cache_warehouses;
437 $nb_warehouse = count($warehouses_list);
438 $colspan_warehouse = 1;
441 $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1;
444 print
'<div class="div-table-responsive">';
445 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">';
448 print
'<tr class="liste_titre_filter">';
450 if (
$conf->main_checkbox_left_column) {
451 print
'<td class="liste_titre maxwidthsearch">';
452 $searchpicto = $form->showFilterAndCheckAddButtons(0);
457 print
'<td class="liste_titre">';
458 print
'<input class="flat" type="text" name="sref" size="6" value="'.$sref.
'">';
461 print
'<td class="liste_titre">';
462 print
'<input class="flat" type="text" name="snom" size="8" value="'.$snom.
'">';
467 print
'<td class="liste_titre">';
473 print
'<td class="liste_titre"> </td>';
475 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).
'">';
482 if ($virtualdiffersfromphysical) {
483 print
'<td class="liste_titre"> </td>';
487 print
'<td class="liste_titre"></td>';
490 $parameters = array();
491 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters);
492 print $hookmanager->resPrint;
493 print
'<td class="liste_titre"> </td>';
495 print
'<td class="liste_titre" colspan="'.$colspan_warehouse.
'"> </td>';
497 print
'<td class="liste_titre"></td>';
499 if (!
$conf->main_checkbox_left_column) {
500 print
'<td class="liste_titre maxwidthsearch">';
501 $searchpicto = $form->showFilterAndCheckAddButtons(0);
509 print
'<tr class="liste_titre">';
511 if (
$conf->main_checkbox_left_column) {
517 print_liste_field_titre(
"Duration", $_SERVER[
"PHP_SELF"],
"p.duration",
'', $param,
"", $sortfield, $sortorder,
'center ');
519 print_liste_field_titre(
"StockLimit", $_SERVER[
"PHP_SELF"],
"p.seuil_stock_alerte",
'', $param,
"", $sortfield, $sortorder,
'right ');
520 print_liste_field_titre(
"DesiredStock", $_SERVER[
"PHP_SELF"],
"p.desiredstock",
'', $param,
"", $sortfield, $sortorder,
'right ');
521 print_liste_field_titre(
"PhysicalStock", $_SERVER[
"PHP_SELF"],
"stock_physique",
'', $param,
"", $sortfield, $sortorder,
'right ');
524 if ($nb_warehouse > 1) {
525 foreach ($warehouses_list as &$wh) {
530 if ($virtualdiffersfromphysical) {
531 print_liste_field_titre(
"VirtualStock", $_SERVER[
"PHP_SELF"],
"",
'', $param,
"", $sortfield, $sortorder,
'right ',
'VirtualStockDesc');
535 print_liste_field_titre(
"Unit", $_SERVER[
"PHP_SELF"],
"unit_short",
'', $param,
'align="right"', $sortfield, $sortorder);
538 $parameters = array(
'param' => $param,
'sortfield' => $sortfield,
'sortorder' => $sortorder);
539 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters);
540 print $hookmanager->resPrint;
542 print_liste_field_titre(
"ProductStatusOnSell", $_SERVER[
"PHP_SELF"],
"p.tosell",
'', $param,
"", $sortfield, $sortorder,
'right ');
543 print_liste_field_titre(
"ProductStatusOnBuy", $_SERVER[
"PHP_SELF"],
"p.tobuy",
'', $param,
"", $sortfield, $sortorder,
'right ');
545 if (!
$conf->main_checkbox_left_column) {
550 while ($i < min($num, $limit)) {
551 $objp = $db->fetch_object($resql);
554 $product->fetch($objp->rowid);
555 $product->load_stock();
559 if (
$conf->main_checkbox_left_column) {
562 print
'<td class="tdoverflowmax250">';
563 print $product->getNomUrl(1);
566 print
'<td class="tdoverflowmax150" title="'.dol_escape_htmltag($product->label).
'">'.
dol_escape_htmltag($product->label).
'</td>';
569 print
'<td class="center">';
571 if (preg_match(
'/([0-9]+)y/i', $objp->duration, $regs)) {
572 print $regs[1].
' '.$langs->trans(
"DurationYear");
573 } elseif (preg_match(
'/([0-9]+)m/i', $objp->duration, $regs)) {
574 print $regs[1].
' '.$langs->trans(
"DurationMonth");
575 } elseif (preg_match(
'/([0-9]+)d/i', $objp->duration, $regs)) {
576 print $regs[1].
' '.$langs->trans(
"DurationDay");
578 print $objp->duration;
583 print
'<td class="right">';
584 print $objp->seuil_stock_alerte;
586 print
'<td class="right">';
587 print $objp->desiredstock;
590 print
'<td class="right">';
591 if ($objp->seuil_stock_alerte !=
'' && ($objp->stock_physique < $objp->seuil_stock_alerte)) {
592 print img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
594 if ($objp->stock_physique < 0) {
595 print
'<span class="warning">';
597 print
price(
price2num($objp->stock_physique,
'MS'), 0, $langs, 1, 0);
598 if ($objp->stock_physique < 0) {
605 if ($nb_warehouse > 1) {
606 foreach ($warehouses_list as &$wh) {
607 print
'<td class="right">';
608 print
price(empty($product->stock_warehouse[$wh[
'id']]->real) ? 0 :
price2num($product->stock_warehouse[$wh[
'id']]->real,
'MS'), 0, $langs, 1, 0);
615 if ($virtualdiffersfromphysical) {
616 print
'<td class="right">';
617 if ($objp->seuil_stock_alerte !=
'' && ($product->stock_theorique < (
float) $objp->seuil_stock_alerte)) {
618 print img_warning($langs->trans(
"StockLowerThanLimit", $objp->seuil_stock_alerte)).
' ';
620 if ($objp->stock_physique < 0) {
621 print
'<span class="warning">';
623 print
price(
price2num($product->stock_theorique,
'MS'), 0, $langs, 1, 0);
624 if ($objp->stock_physique < 0) {
631 print
'<td class="left">'.dol_escape_htmltag($objp->unit_short).
'</td>';
634 $parameters = array(
'obj' => $objp);
635 $reshook = $hookmanager->executeHooks(
'printFieldListValue', $parameters, $product);
636 print $hookmanager->resPrint;
637 print
'<td class="center nowraponall">';
638 print img_picto($langs->trans(
"StockMovement"),
'movement',
'class="pictofixedwidth"');
639 print
'<a href="'.DOL_URL_ROOT.
'/product/stock/movement_list.php?idproduct='.$product->id.
'">'.$langs->trans(
"Movements").
'</a>';
641 print
'<td class="right nowrap">'.$product->LibStatut($objp->statut, 5, 0).
'</td>';
642 print
'<td class="right nowrap">'.$product->LibStatut($objp->tobuy, 5, 1).
'</td>';
644 if (!
$conf->main_checkbox_left_column) {
652 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
662 dol_print_error($db);
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.