diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index bf52ff5871a..397d1a008cf 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -2737,6 +2737,12 @@ class Form
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
$sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,";
$sql .= " pfp.supplier_reputation";
+ // if we use supplier description of the products
+ if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
+ $sql .= " ,pfp.desc_fourn as description";
+ } else {
+ $sql .= " ,p.description";
+ }
// Units
if ($conf->global->PRODUCT_USE_UNITS) {
$sql .= ", u.label as unit_long, u.short_label as unit_short, p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units";
@@ -2766,7 +2772,11 @@ class Form
foreach ($scrit as $crit)
{
if ($i > 0) $sql .= " AND ";
- $sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')";
+ $sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%'";
+ if (!empty($conf->global->PRODUIT_FOURN_TEXTS)) {
+ $sql .= " OR pfp.desc_fourn LIKE '".$this->db->escape($prefix.$crit)."%'";
+ }
+ $sql .= ")";
$i++;
}
if (count($scrit) > 1) $sql .= ")";
@@ -2956,8 +2966,9 @@ class Form
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) $opt .= ' disabled';
if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0)
{
- $opt .= ' pbq="'.$objp->idprodfournprice.'" data-pbq="'.$objp->idprodfournprice.'" data-pbqqty="'.$objp->quantity.'" data-pbqup="'.$objp->unitprice.'" data-pbqpercent="'.$objp->remise_percent.'"';
+ $opt .= ' data-qty="'.$objp->quantity.'" data-up="'.$objp->unitprice.'" data-discount="'.$outdiscount.'"';
}
+ $opt .= ' data-description="'.dol_escape_htmltag($objp->description).'"';
$opt .= ' data-html="'.dol_escape_htmltag($optlabel).'"';
$opt .= '>';
@@ -2971,7 +2982,20 @@ class Form
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
$out .= $opt;
- array_push($outarray, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'qty'=>$outqty, 'up'=>$objp->unitprice, 'discount'=>$outdiscount, 'type'=>$outtype, 'duration_value'=>$outdurationvalue, 'duration_unit'=>$outdurationunit, 'disabled'=>(empty($objp->idprodfournprice) ?true:false)));
+ array_push($outarray,
+ array('key'=>$outkey,
+ 'value'=>$outref,
+ 'label'=>$outval,
+ 'qty'=>$outqty,
+ 'up'=>$objp->unitprice,
+ 'discount'=>$outdiscount,
+ 'type'=>$outtype,
+ 'duration_value'=>$outdurationvalue,
+ 'duration_unit'=>$outdurationunit,
+ 'disabled'=>(empty($objp->idprodfournprice) ?true:false),
+ 'description'=>$objp->description
+ )
+ );
// Exemple of var_dump $outarray
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (fff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 10fa477600a..9b225967eb1 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -134,7 +134,11 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
}
return { label: label, value: item.value, id: item.key, disabled: item.disabled,
update: update, textarea: textarea,
- pbq: item.pbq, type: item.type, qty: item.qty, discount: item.discount, pricebasetype: item.pricebasetype, price_ht: item.price_ht, price_ttc: item.price_ttc }
+ pbq: item.pbq,
+ type: item.type, qty: item.qty, discount: item.discount,
+ pricebasetype: item.pricebasetype, price_ht: item.price_ht,
+ price_ttc: item.price_ttc,
+ up: item.up, description : item.description}
}));
}
else console.error("Error: Ajax url '.$url.($urloption ? '?'.$urloption : '').' has returned an empty page. Should be an empty json array.");
@@ -146,14 +150,34 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
console.log("Call change on input '.$htmlname.' because of select definition of autocomplete select call on input#search_'.$htmlname.'");
console.log("Selected id = "+ui.item.id+" - If this value is null, it means you select a record with key that is null so selection is not effective");
- //console.log(ui.item);
- $("#'.$htmlname.'").attr("data-pbq", ui.item.pbq);
- $("#'.$htmlname.'").attr("data-pbqup", ui.item.price_ht);
- $("#'.$htmlname.'").attr("data-pbqbase", ui.item.pricebasetype);
- $("#'.$htmlname.'").attr("data-pbqqty", ui.item.qty);
- $("#'.$htmlname.'").attr("data-pbqpercent", ui.item.discount);
+ console.log(ui.item);
+ //For supplier price
+ $("#'.$htmlname.'").attr("data-up", ui.item.up);
+ $("#'.$htmlname.'").attr("data-discount", ui.item.discount);
+ $("#'.$htmlname.'").attr("data-qty", ui.item.qty);
+ $("#'.$htmlname.'").attr("data-description", ui.item.description);
- $("#'.$htmlname.'").val(ui.item.id).trigger("change"); // Select new value
+ //For customer price
+ ';
+
+ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
+ $script .= '
+ $("#' . $htmlname . '").attr("data-pbq", ui.item.pbq);
+ $("#' . $htmlname . '").attr("data-pbqup", ui.item.price_ht);
+ $("#' . $htmlname . '").attr("data-pbqbase", ui.item.pricebasetype);
+ $("#' . $htmlname . '").attr("data-pbqqty", ui.item.qty);
+ $("#' . $htmlname . '").attr("data-pbqpercent", ui.item.discount);
+ ';
+ } else {
+ $script .= '
+ $("#' . $htmlname . '").attr("data-up", ui.item.price_ht);
+ $("#' . $htmlname . '").attr("data-base", ui.item.pricebasetype);
+ $("#' . $htmlname . '").attr("data-qty", ui.item.qty);
+ $("#' . $htmlname . '").attr("data-discount", ui.item.discount);
+ ';
+ }
+ $script .= '
+ $("#'.$htmlname.'").val(ui.item.id).trigger("change"); // Select new value
// Disable an element
if (options.option_disabled) {
console.log("Make action option_disabled on #"+options.option_disabled+" with disabled="+ui.item.disabled)
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index ec73bf9725b..ba6b4e1bb1b 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -602,39 +602,39 @@ if (!empty($usemargins) && $user->rights->margins->creer)
});
$("#prod_entry_mode_free").on( "click", function() {
- setforfree();
+ setforfree();
});
$("#select_type").change(function()
{
- setforfree();
+ setforfree();
if (jQuery('#select_type').val() >= 0)
{
/* focus work on a standard textarea but not if field was replaced with CKEDITOR */
- jQuery('#dp_desc').focus();
- /* focus if CKEDITOR */
- if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
- {
- var editor = CKEDITOR.instances['dp_desc'];
- if (editor) { editor.focus(); }
- }
+ jQuery('#dp_desc').focus();
+ /* focus if CKEDITOR */
+ if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
+ {
+ var editor = CKEDITOR.instances['dp_desc'];
+ if (editor) { editor.focus(); }
+ }
}
console.log("Hide/show date according to product type");
if (jQuery('#select_type').val() == '0')
{
- jQuery('#trlinefordates').hide();
- jQuery('.divlinefordates').hide();
+ jQuery('#trlinefordates').hide();
+ jQuery('.divlinefordates').hide();
}
else
{
- jQuery('#trlinefordates').show();
- jQuery('.divlinefordates').show();
+ jQuery('#trlinefordates').show();
+ jQuery('.divlinefordates').show();
}
});
$("#prod_entry_mode_predef").on( "click", function() {
- console.log("click prod_entry_mode_predef");
- setforpredef();
- jQuery('#trlinefordates').show();
+ console.log("click prod_entry_mode_predef");
+ setforpredef();
+ jQuery('#trlinefordates').show();
});
rights->margins->creer)
'json'
);
}
- rights->margins->creer)
@@ -804,7 +804,10 @@ if (!empty($usemargins) && $user->rights->margins->creer)
}
?>
- /* To process customer price per quantity (CUSTOMER_PRICE_PER_QTY works only if combo product is not an ajax after x key pressed) */
+ global->PRODUIT_CUSTOMER_PRICES_BY_QTY))
+ {?>
+ /* To process customer price per quantity (PRODUIT_CUSTOMER_PRICES_BY_QTY works only if combo product is not an ajax after x key pressed) */
var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
@@ -816,7 +819,7 @@ if (!empty($usemargins) && $user->rights->margins->creer)
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
- if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
+ if ((jQuery('#idprod').val() > 0) && ! isNaN(pbq) && pbq > 0)
{
var pbqupht = pbqup; /* TODO support of price per qty TTC not yet available */
@@ -832,6 +835,48 @@ if (!empty($usemargins) && $user->rights->margins->creer)
jQuery("#remise_percent").val(pbqpercent);
}
}
+
+ //Deal with supplier
+ if (jQuery('#idprodfournprice').val() >0)
+ {
+ var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
+ if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with autocomplete
+
+ var qty = parseFloat($('option:selected', this).attr('data-qty'));
+ if (isNaN(qty)) { qty = parseFloat(jQuery('#idprodfournprice').attr('data-qty'));}
+
+ var discount = parseFloat($('option:selected', this).attr('data-discount'));
+ if (isNaN(discount)) { discount = parseFloat(jQuery('#idprodfournprice').attr('data-discount'));}
+
+ var description = $('option:selected', this).attr('data-description');
+ if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
+ console.log("We find supplier price :"+up+" qty: "+qty+" discount: "+discount+" for product "+jQuery('#idprodfournprice').val());
+
+ jQuery("#price_ht").val(up);
+ if (jQuery("#qty").val() < qty)
+ {
+ jQuery("#qty").val(qty);
+ }
+ if (jQuery("#remise_percent").val() < discount)
+ {
+ jQuery("#remise_percent").val(discount);
+ }
+
+ console.log("Load desciption into text area : "+description);
+ global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
+ {
+ var editor = CKEDITOR.instances['dp_desc'];
+ if (editor) {
+ editor.setData(description);
+ }
+ }
+
+ jQuery('#dp_desc').text(description);
+
+ }
else
{
jQuery("#pbq").val('');
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index e202b3e8efd..e5ddc3b1b75 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -356,7 +356,7 @@ if (empty($reshook))
// Set if we used free entry or predefined product
$predef = '';
- $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : '');
+ $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
$date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
$prod_entry_mode = GETPOST('prod_entry_mode');
@@ -475,7 +475,7 @@ if (empty($reshook))
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
- $desc = (!empty($productsupplier->multilangs [$outputlangs->defaultlang] ["description"])) ? $productsupplier->multilangs [$outputlangs->defaultlang] ["description"] : $productsupplier->description;
+ $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
} else {
$desc = $productsupplier->description;
}
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index c304a4edce7..3f9ea28c420 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -1180,7 +1180,7 @@ if (empty($reshook))
// Set if we used free entry or predefined product
$predef = '';
- $product_desc = (GETPOST('dp_desc') ?GETPOST('dp_desc') : '');
+ $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
$date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php
index b9a8d6c3b68..41c38c82ba7 100644
--- a/htdocs/product/fournisseurs.php
+++ b/htdocs/product/fournisseurs.php
@@ -166,7 +166,7 @@ if (empty($reshook))
$price_expression = GETPOST('eid', 'int') ? GETPOST('eid', 'int') : ''; // Discard expression if not in expression mode
$delivery_time_days = GETPOST('delivery_time_days', 'int') ? GETPOST('delivery_time_days', 'int') : '';
$supplier_reputation = GETPOST('supplier_reputation');
- $supplier_description = GETPOST('supplier_description', 'alpha');
+ $supplier_description = GETPOST('supplier_description', 'restricthtml');
$barcode = GETPOST('barcode', 'alpha');
$fk_barcode_type = GETPOST('fk_barcode_type', 'int');
$packaging = price2num(GETPOST("packaging", 'alphanohtml'), 'MS');