Fix several errors in search an sorting in stock by lot view
This commit is contained in:
parent
f1ee2bdddf
commit
7667dc735e
@ -45,8 +45,9 @@ $sref=GETPOST("sref");
|
||||
$snom=GETPOST("snom");
|
||||
$sall=GETPOST("sall");
|
||||
$type=GETPOST("type","int");
|
||||
$sbarcode=GETPOST("sbarcode");
|
||||
$search_batch=GETPOST('search_batch');
|
||||
$sbarcode=GETPOST("sbarcode",'alpha');
|
||||
$search_warehouse=GETPOST('search_warehouse','alpha');
|
||||
$search_batch=GETPOST('search_batch','alpha');
|
||||
$catid=GETPOST('catid','int');
|
||||
$toolowstock=GETPOST('toolowstock');
|
||||
$tosell = GETPOST("tosell");
|
||||
@ -85,6 +86,8 @@ if (! empty($_POST["button_removefilter_x"]))
|
||||
$type="";
|
||||
$catid='';
|
||||
$toolowstock='';
|
||||
$search_batch='';
|
||||
$search_warehouse='';
|
||||
}
|
||||
|
||||
|
||||
@ -110,14 +113,16 @@ $title=$langs->trans("ProductsAndServices");
|
||||
$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,';
|
||||
$sql.= ' p.fk_product_type, p.tms as datem,';
|
||||
$sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tobatch,';
|
||||
$sql.= ' s.fk_entrepot,';
|
||||
$sql.= ' ps.fk_entrepot,';
|
||||
$sql.= ' e.label as warehouse_label,';
|
||||
$sql.= ' pb.batch, pb.eatby as oldeatby, pb.sellby as oldsellby,';
|
||||
$sql.= ' pl.eatby, pl.sellby,';
|
||||
$sql.= ' SUM(pb.qty) as stock_physique, COUNT(pb.rowid) as nbinbatchtable';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = s.rowid';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch';
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps on p.rowid = ps.fk_product'; // Detail for each warehouse
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid'; // Link on unique key
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse
|
||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key
|
||||
// We'll need this table joined to the select in order to filter by categ
|
||||
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
|
||||
$sql.= " WHERE p.entity IN (".getEntity('product', 1).")";
|
||||
@ -138,45 +143,26 @@ if (dol_strlen($type))
|
||||
$sql.= " AND p.fk_product_type <> '1'";
|
||||
}
|
||||
}
|
||||
if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'";
|
||||
if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'";
|
||||
if ($snom) $sql.= " AND p.label LIKE '%".$db->escape($snom)."%'";
|
||||
if (! empty($tosell))
|
||||
{
|
||||
$sql.= " AND p.tosell = ".$tosell;
|
||||
}
|
||||
if (! empty($tobuy))
|
||||
{
|
||||
$sql.= " AND p.tobuy = ".$tobuy;
|
||||
}
|
||||
if (! empty($canvas))
|
||||
{
|
||||
$sql.= " AND p.canvas = '".$db->escape($canvas)."'";
|
||||
}
|
||||
if($catid)
|
||||
{
|
||||
$sql.= " AND cp.fk_categorie = ".$catid;
|
||||
}
|
||||
if ($fourn_id > 0)
|
||||
{
|
||||
$sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
|
||||
}
|
||||
if ($sref) $sql.= natural_search("p.ref", $sref);
|
||||
if ($sbarcode) $sql.= natural_search("p.barcode", $sbarcode);
|
||||
if ($snom) $sql.= natural_search("p.label", $snom);
|
||||
if (! empty($tosell)) $sql.= " AND p.tosell = ".$tosell;
|
||||
if (! empty($tobuy)) $sql.= " AND p.tobuy = ".$tobuy;
|
||||
if (! empty($canvas)) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
|
||||
if($catid) $sql.= " AND cp.fk_categorie = ".$catid;
|
||||
if ($fourn_id > 0) $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
|
||||
// Insert categ filter
|
||||
if ($search_categ)
|
||||
{
|
||||
$sql .= " AND cp.fk_categorie = ".$db->escape($search_categ);
|
||||
}
|
||||
if ($search_batch)
|
||||
{
|
||||
$sql .= " AND pb.batch LIKE '%".$db->escape($search_batch)."%'";
|
||||
}
|
||||
if ($search_categ) $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ);
|
||||
if ($search_warehouse) $sql .= natural_search("e.label", $search_warehouse);
|
||||
if ($search_batch) $sql .= natural_search("pb.batch", $search_batch);
|
||||
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
|
||||
$sql.= " p.fk_product_type, p.tms,";
|
||||
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tobatch,";
|
||||
$sql.= " s.fk_entrepot,";
|
||||
$sql.= " ps.fk_entrepot,";
|
||||
$sql.= " e.label,";
|
||||
$sql.= " pb.batch, pb.eatby, pb.sellby,";
|
||||
$sql.= " pl.eatby, pl.sellby";
|
||||
if ($toolowstock) $sql.= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; // Not used yet
|
||||
if ($toolowstock) $sql.= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$sql.= $db->plimit($limit + 1, $offset);
|
||||
$resql = $db->query($sql);
|
||||
@ -262,7 +248,7 @@ if ($resql)
|
||||
print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder);
|
||||
if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Warehouse"), $_SERVER["PHP_SELF"], "",$param,"",'',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Warehouse"), $_SERVER["PHP_SELF"], "e.label",$param,"",'',$sortfield,$sortorder);
|
||||
//print_liste_field_titre($langs->trans("DesiredStock"), $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Batch"), $_SERVER["PHP_SELF"], "pb.batch",$param,"",'align="center"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("EatByDate"), $_SERVER["PHP_SELF"], "pb.eatby",$param,"",'align="center"',$sortfield,$sortorder);
|
||||
@ -289,7 +275,7 @@ if ($resql)
|
||||
print ' ';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre"><input class="flat" type="text" name="search_warehouse" size="6" value="'.$search_warehouse.'"></td>';
|
||||
print '<td class="liste_titre" align="center"><input class="flat" type="text" name="search_batch" size="6" value="'.$search_batch.'"></td>';
|
||||
print '<td class="liste_titre" align="right"> </td>';
|
||||
print '<td class="liste_titre"> </td>';
|
||||
@ -356,7 +342,9 @@ if ($resql)
|
||||
print '<td>';
|
||||
if ($objp->fk_entrepot > 0)
|
||||
{
|
||||
$warehousetmp->fetch($objp->fk_entrepot);
|
||||
$warehousetmp->id=$objp->fk_entrepot;
|
||||
$warehousetmp->label=$objp->warehouse_label;
|
||||
//$warehousetmp->fetch($objp->fk_entrepot);
|
||||
print $warehousetmp->getNomUrl(1);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
@ -548,7 +548,7 @@ class Entrepot extends CommonObject
|
||||
|
||||
$result='';
|
||||
$label = '<u>' . $langs->trans("ShowWarehouse").'</u>';
|
||||
$label.= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->libelle;
|
||||
$label.= '<br><b>' . $langs->trans('Ref') . ':</b> ' . (empty($this->label)?$this->libelle:$this->label);
|
||||
if (! empty($this->lieu))
|
||||
$label.= '<br><b>' . $langs->trans('LocationSummary').':</b> '.$this->lieu;
|
||||
|
||||
@ -556,7 +556,7 @@ class Entrepot extends CommonObject
|
||||
$linkend='</a>';
|
||||
|
||||
if ($withpicto) $result.=($link.img_object($label, 'stock', 'class="classfortooltip"').$linkend.' ');
|
||||
$result.=$link.$this->libelle.$linkend;
|
||||
$result.=$link.(empty($this->label)?$this->libelle:$this->label).$linkend;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user