Add filter on warehouse status to object line product list

This commit is contained in:
fappels 2016-11-30 13:03:17 +01:00
parent 59ba5ef484
commit 49442c0b7f
3 changed files with 26 additions and 9 deletions

View File

@ -1630,7 +1630,7 @@ class Form
* @param int $hidepriceinlabel 1=Hide prices in label * @param int $hidepriceinlabel 1=Hide prices in label
* @return void * @return void
*/ */
function select_produits($selected='', $htmlname='productid', $filtertype='', $limit=20, $price_level=0, $status=1, $finished=2, $selected_input_value='', $hidelabel=0, $ajaxoptions=array(), $socid=0, $showempty='1', $forcecombo=0, $morecss='', $hidepriceinlabel=0) function select_produits($selected='', $htmlname='productid', $filtertype='', $limit=20, $price_level=0, $status=1, $finished=2, $selected_input_value='', $hidelabel=0, $ajaxoptions=array(), $socid=0, $showempty='1', $forcecombo=0, $morecss='', $hidepriceinlabel=0, $warehouseStatus=0)
{ {
global $langs,$conf; global $langs,$conf;
@ -1649,7 +1649,7 @@ class Form
unset($producttmpselect); unset($producttmpselect);
} }
// mode=1 means customers products // mode=1 means customers products
$urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished; $urloption='htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished.'&warehousestatus='.$warehouseStatus;
//Price by customer //Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
$urloption.='&socid='.$socid; $urloption.='&socid='.$socid;
@ -1670,7 +1670,7 @@ class Form
} }
else else
{ {
print $this->select_produits_list($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0,$socid,$showempty,$forcecombo,$morecss,$hidepriceinlabel); print $this->select_produits_list($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0,$socid,$showempty,$forcecombo,$morecss,$hidepriceinlabel, $warehouseStatus);
} }
} }
@ -1691,28 +1691,33 @@ class Form
* @param int $forcecombo Force to use combo box * @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select * @param string $morecss Add more css on select
* @param int $hidepriceinlabel 1=Hide prices in label * @param int $hidepriceinlabel 1=Hide prices in label
* @param int $warehouseStatus Additional warehousestatus to filter (stock from status 1 is always shown)
* @return array Array of keys for json * @return array Array of keys for json
*/ */
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) 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=0)
{ {
global $langs,$conf,$user,$db; global $langs,$conf,$user,$db;
$out=''; $out='';
$outarray=array(); $outarray=array();
$sql = "SELECT "; $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";
$sql.= " 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.stock, p.fk_price_expression"; $selectFieldsGrouped = ", sum(ps.reel) as stock";
$sql = "SELECT ";
$sql.= $selectFields . $selectFieldsGrouped;
//Price by customer //Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { 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.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'; $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 // Multilang : we add translation
if (! empty($conf->global->MAIN_MULTILANGS)) if (! empty($conf->global->MAIN_MULTILANGS))
{ {
$sql.= ", pl.label as label_translated"; $sql.= ", pl.label as label_translated";
$selectFields.= ", pl.label as label_translated";
} }
// Price by quantity // Price by quantity
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
@ -1725,8 +1730,11 @@ class Form
if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level; if ($price_level >= 1 && !empty($conf->global->PRODUIT_MULTIPRICES)) $sql.= " AND price_level=".$price_level;
$sql.= " ORDER BY date_price"; $sql.= " ORDER BY date_price";
$sql.= " DESC LIMIT 1) as price_by_qty"; $sql.= " DESC LIMIT 1) as price_by_qty";
$selectFields.= ", price_rowid, price_by_qty";
} }
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid";
$sql.= " JOIN ".MAIN_DB_PREFIX."entrepot as e on (ps.fk_entrepot = e.rowid AND e.statut IN (1, ".$warehouseStatus."))";
//Price by customer //Price by customer
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { 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"; $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid";
@ -1772,6 +1780,7 @@ class Form
if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'"; if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'";
$sql.=')'; $sql.=')';
} }
$sql.= ' GROUP BY'.$selectFields;
$sql.= $db->order("p.ref"); $sql.= $db->order("p.ref");
$sql.= $db->plimit($limit); $sql.= $db->plimit($limit);

View File

@ -184,7 +184,14 @@ else {
if (empty($senderissupplier)) if (empty($senderissupplier))
{ {
$form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(),$buyer->id); if ($conf->global->ENTREPOT_EXTRA_STATUS)
{
$form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(),$buyer->id, '1', 0, '', 0, 3);
}
else
{
$form->select_produits(GETPOST('idprod'), 'idprod', $filtertype, $conf->product->limit_size, $buyer->price_level, 1, 2, '', 1, array(),$buyer->id);
}
} }
else else
{ {

View File

@ -50,6 +50,7 @@ $id = GETPOST('id', 'int');
$price_by_qty_rowid = GETPOST('pbq', 'int'); $price_by_qty_rowid = GETPOST('pbq', 'int');
$finished = GETPOST('finished', 'int'); $finished = GETPOST('finished', 'int');
$alsoproductwithnosupplierprice = GETPOST('alsoproductwithnosupplierprice', 'int'); $alsoproductwithnosupplierprice = GETPOST('alsoproductwithnosupplierprice', 'int');
$warehouseStatus = GETPOST('warehousestatus', 'int');
/* /*
@ -185,7 +186,7 @@ else
$form = new Form($db); $form = new Form($db);
if (empty($mode) || $mode == 1) { // mode=1: customer if (empty($mode) || $mode == 1) { // mode=1: customer
$arrayresult = $form->select_produits_list("", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid); $arrayresult = $form->select_produits_list("", $htmlname, $type, 0, $price_level, $searchkey, $status, $finished, $outjson, $socid, '1', 0, '', 0, $warehouseStatus);
} elseif ($mode == 2) { // mode=2: supplier } elseif ($mode == 2) { // mode=2: supplier
$arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice); $arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
} }