diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 374e740ea40..9056f3bde9d 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -620,7 +620,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) /* When changing predefined product, we reload list of supplier prices required for margin combo */ $("#idprod, #idprodfournprice").change(function() { - console.log("#idprod, #idprodfournprice change triggered this.val = "+$(this).val()); + console.log("Call method change() after change on #idprod or #idprodfournprice. this.val = "+$(this).val()); setforpredef(); // TODO Keep vat combo visible and set it to first entry into list that match result of get_default_tva @@ -631,6 +631,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) { ?> // Get the HT price for the product and display it + console.log("Load price without tax and set it into #price_ht"); $.post('/product/ajax/products.php?action=fetch', { 'id': $(this).val(), 'socid' : socid; ?> }, function(data) { jQuery("#price_ht").val(data.price_ht); }, diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 19fd7926453..918950179c7 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -59,8 +59,9 @@ dol_syslog(join(',', $_GET)); if (!empty($action) && $action == 'fetch' && !empty($id)) { - // When action='fetch', id must be the product id. + // action='fetch' is used to get product information on a product. So when action='fetch', id must be the product id. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $outjson = array(); @@ -77,6 +78,13 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $found = false; + $price_level = 1; + if ($socid > 0 && !empty($conf->global->PRODUIT_MULTIPRICES)) { + $thirdpartytemp = new Societe($db); + $thirdpartytemp->fetch($socid); + $price_level = $thirdpartytemp->price_level; + } + // Price by qty if (!empty($price_by_qty_rowid) && $price_by_qty_rowid >= 1 && (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY))) // If we need a particular price related to qty { @@ -100,14 +108,13 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) } // Multiprice - if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES))) // If we need a particular price - // level (from 1 to 6) + if (!$found && isset($price_level) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES))) // If we need a particular price level (from 1 to 6) { $sql = "SELECT price, price_ttc, price_base_type, tva_tx"; $sql .= " FROM ".MAIN_DB_PREFIX."product_price "; - $sql .= " WHERE fk_product='".$id."'"; + $sql .= " WHERE fk_product = '".$id."'"; $sql .= " AND entity IN (".getEntity('productprice').")"; - $sql .= " AND price_level=".$price_level; + $sql .= " AND price_level = ".((int) $price_level); $sql .= " ORDER BY date_price"; $sql .= " DESC LIMIT 1"; @@ -160,8 +167,7 @@ else { require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; - $langs->load("products"); - $langs->load("main"); + $langs->loadLangs(array("main", "products")); top_httphead(); @@ -186,6 +192,7 @@ else $searchkey = (($idprod && GETPOST($idprod, 'alpha')) ? GETPOST($idprod, 'alpha') : (GETPOST($htmlname, 'alpha') ? GETPOST($htmlname, 'alpha') : '')); $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, '1', 0, '', $hidepriceinlabel, $warehouseStatus); } elseif ($mode == 2) { // mode=2: supplier