Skip to content

Commit

Permalink
Add filter on warehouse status to object line product list
Browse files Browse the repository at this point in the history
  • Loading branch information
fappels committed Nov 30, 2016
1 parent 59ba5ef commit 49442c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
23 changes: 16 additions & 7 deletions htdocs/core/class/html.form.class.php
Expand Up @@ -1630,7 +1630,7 @@ function select_dolusers_forevent($action='', $htmlname='userid', $show_empty=0,
* @param int $hidepriceinlabel 1=Hide prices in label
* @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;

Expand All @@ -1649,7 +1649,7 @@ function select_produits($selected='', $htmlname='productid', $filtertype='', $l
unset($producttmpselect);
}
// 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
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
$urloption.='&socid='.$socid;
Expand All @@ -1670,7 +1670,7 @@ function select_produits($selected='', $htmlname='productid', $filtertype='', $l
}
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);
}
}

Expand All @@ -1691,28 +1691,33 @@ function select_produits($selected='', $htmlname='productid', $filtertype='', $l
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @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
*/
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;

$out='';
$outarray=array();

$sql = "SELECT ";
$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";
$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";
$selectFieldsGrouped = ", sum(ps.reel) as stock";

$sql = "SELECT ";
$sql.= $selectFields . $selectFieldsGrouped;
//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.= ", pl.label as label_translated";
}
// Price by quantity
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
Expand All @@ -1725,8 +1730,11 @@ function select_produits_list($selected='',$htmlname='productid',$filtertype='',
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";
$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
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";
Expand Down Expand Up @@ -1772,6 +1780,7 @@ function select_produits_list($selected='',$htmlname='productid',$filtertype='',
if (! empty($conf->barcode->enabled)) $sql.= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'";
$sql.=')';
}
$sql.= ' GROUP BY'.$selectFields;
$sql.= $db->order("p.ref");
$sql.= $db->plimit($limit);

Expand Down
9 changes: 8 additions & 1 deletion htdocs/core/tpl/objectline_create.tpl.php
Expand Up @@ -184,7 +184,14 @@

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
{
Expand Down
3 changes: 2 additions & 1 deletion htdocs/product/ajax/products.php
Expand Up @@ -50,6 +50,7 @@
$price_by_qty_rowid = GETPOST('pbq', 'int');
$finished = GETPOST('finished', 'int');
$alsoproductwithnosupplierprice = GETPOST('alsoproductwithnosupplierprice', 'int');
$warehouseStatus = GETPOST('warehousestatus', 'int');


/*
Expand Down Expand Up @@ -185,7 +186,7 @@

$form = new Form($db);
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
$arrayresult = $form->select_produits_fournisseurs_list($socid, "", $htmlname, $type, "", $searchkey, $status, $outjson, 0, $alsoproductwithnosupplierprice);
}
Expand Down

0 comments on commit 49442c0

Please sign in to comment.