Bonjour
/htdocs/core/class/html.form.class.php
recherche la fonction select_produits_list
en voici un bout modifié:
function select_produits_list($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$outputmode=0,$socid=0,$showempty='1',$forcecombo=0,$morecss='',$hidepriceinlabel=0, $warehouseStatus='')
{
global $langs,$conf,$user,$db;
$out='';
$outarray=array();
$warehouseStatusArray = array();
if (! empty($warehouseStatus))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
if (preg_match('/warehouseclosed/', $warehouseStatus))
{
$warehouseStatusArray[] = Entrepot::STATUS_CLOSED;
}
if (preg_match('/warehouseopen/', $warehouseStatus))
{
$warehouseStatusArray[] = Entrepot::STATUS_OPEN_ALL;
}
if (preg_match('/warehouseinternal/', $warehouseStatus))
{
$warehouseStatusArray[] = Entrepot::STATUS_OPEN_INTERNAL;
}
}
$selectFields = " p.rowid, p.label, p.ref, p.description, p.barcode, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.fk_price_expression";
(count($warehouseStatusArray)) ? $selectFieldsGrouped = ", sum(ps.reel) as stock" : $selectFieldsGrouped = ", p.stock";
$sql = "SELECT ";
$sql.= $selectFields . $selectFieldsGrouped;
$sql.= ', pfp.ref_fourn';
//Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
$sql.=' ,pcp.rowid as idprodcustprice, pcp.price as custprice, pcp.price_ttc as custprice_ttc,';
$sql.=' pcp.price_base_type as custprice_base_type, pcp.tva_tx as custtva_tx';
$selectFields.= ", idprodcustprice, custprice, custprice_ttc, custprice_base_type, custtva_tx";
}
// Multilang : we add translation
if (! empty($conf->global->MAIN_MULTILANGS))
{
$sql.= ", pl.label as label_translated";
$selectFields.= ", label_translated";
}
// Price by quantity
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
{
$sql.= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
$sql.= " ORDER BY date_price";
$sql.= " DESC LIMIT 1) as price_rowid";
$sql.= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid";
if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
$sql.= " ORDER BY date_price";
$sql.= " DESC LIMIT 1) as price_by_qty";
$selectFields.= ", price_rowid, price_by_qty";
}
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
if (count($warehouseStatusArray))
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid";
}
//Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
$sql.=" LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid";
}
// Multilang : we add translation
if (! empty($conf->global->MAIN_MULTILANGS))
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'";
}
if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
$sql .= " LEFT JOIN llx_product_attribute_combination pac ON pac.fk_product_child = p.rowid";
}
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp ON pfp.fk_product=p.rowid';
$sql.= ' WHERE p.entity IN ('.getEntity('product').')';
if (count($warehouseStatusArray))
{
$sql.= ' AND (p.fk_product_type = 1 OR e.statut IN ('.$this->db->escape(implode(',',$warehouseStatusArray)).'))';
}
if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
$sql .= " AND pac.rowid IS NULL";
}
if ($finished == 0)
{
$sql.= " AND p.finished = ".$finished;
}
elseif ($finished == 1)
{
$sql.= " AND p.finished = ".$finished;
if ($status >= 0) $sql.= " AND p.tosell = ".$status;
}
elseif ($status >= 0)
{
$sql.= " AND p.tosell = ".$status;
}
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
// Add criteria on ref/label
if ($filterkey != '')
{
$sql.=' AND (';
$prefix=empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)?'%':''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
// For natural search
$scrit = explode(' ', $filterkey);
$i=0;
if (count($scrit) > 1) $sql.="(";
foreach ($scrit as $crit)
{
if ($i > 0) $sql.=" AND ";
$sql.="(p.ref LIKE '".$db->escape($prefix.$crit)."%' OR p.label LIKE '".$db->escape($prefix.$crit)."%'";
$sql.=" OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'";
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '".$db->escape($prefix.$crit)."%'";
$sql.=")";
$i++;
}
if (count($scrit) > 1) $sql.=")";
if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'";
$sql.=')';
}
if (count($warehouseStatusArray))
{
$sql.= ' GROUP BY'.$selectFields;
}
Fred