From 7c2b5b614f63611e8cfc28cbdfb7977f3054ef2e Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Sun, 25 Oct 2020 19:13:09 +0100 Subject: [PATCH] NEW: preload product description on selection for customer propal/order/invoice --- htdocs/comm/propal/card.php | 7 +++- htdocs/commande/card.php | 5 +++ htdocs/compta/facture/card.php | 5 +++ htdocs/contrat/card.php | 6 ++++ htdocs/core/tpl/objectline_create.tpl.php | 40 ++++++++++++++++------- htdocs/fourn/facture/card.php | 5 +++ htdocs/product/ajax/products.php | 35 ++++++++++++++++++-- 7 files changed, 87 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 4a4cf3c37dd..3a9fc38fbaf 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -995,11 +995,16 @@ if (empty($reshook)) $outputlangs->setDefaultLang($newlang); } - $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description; + $desc = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description; } else { $desc = $prod->description; } + //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time + if ($product_desc==$desc) { + $product_desc=''; + } + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 596fe4e94bc..585b85def0b 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -854,6 +854,11 @@ if (empty($reshook)) $desc = $prod->description; } + //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time + if ($product_desc==$desc) { + $product_desc=''; + } + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 94f817114aa..6b56d39ba3f 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -2068,6 +2068,11 @@ if (empty($reshook)) $desc = $prod->description; } + //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time + if ($product_desc==$desc) { + $product_desc=''; + } + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 64b3275379a..f3dc0355331 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -499,6 +499,12 @@ if (empty($reshook)) } $desc = $prod->description; + + //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time + if ($product_desc==$desc) { + $product_desc=''; + } + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; else $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index d177ce7637c..ec73bf9725b 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -514,13 +514,13 @@ if (!empty($usemargins) && $user->rights->margins->creer) global->DISPLAY_MARGIN_RATES)) { ?> $("input[name='np_marginRate']:first").blur(function(e) { - return checkFreeLine(e, "np_marginRate"); + return checkFreeLine(e, "np_marginRate"); }); global->DISPLAY_MARK_RATES)) { ?> $("input[name='np_markRate']:first").blur(function(e) { - return checkFreeLine(e, "np_markRate"); + return checkFreeLine(e, "np_markRate"); }); rights->margins->creer) var rate = $("input[name='"+npRate+"']:first"); if (rate.val() == '') - return true; + return true; if (! $.isNumeric(rate.val().replace(',','.'))) { - alert('trans("rateMustBeNumeric")); ?>'); - e.stopPropagation(); - setTimeout(function () { rate.focus() }, 50); - return false; + alert('trans("rateMustBeNumeric")); ?>'); + e.stopPropagation(); + setTimeout(function () { rate.focus() }, 50); + return false; } if (npRate == "np_markRate" && rate.val() >= 100) { - alert('trans("markRateShouldBeLesserThan100")); ?>'); - e.stopPropagation(); - setTimeout(function () { rate.focus() }, 50); - return false; + alert('trans("markRateShouldBeLesserThan100")); ?>'); + e.stopPropagation(); + setTimeout(function () { rate.focus() }, 50); + return false; } var price = 0; @@ -659,7 +659,6 @@ if (!empty($usemargins) && $user->rights->margins->creer) ?> var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */ if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */ - //console.log(pbq); if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0) { @@ -675,6 +674,23 @@ if (!empty($usemargins) && $user->rights->margins->creer) function(data) { console.log("Load unit price end, we got value "+data.price_ht); jQuery("#price_ht").val(data.price_ht); + global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?> + var proddesc = data.desc_trans; + + var proddesc = data.desc; + + console.log("Load desciption into text area : "+proddesc); + global->FCKEDITOR_ENABLE_DETAILS)) { ?> + if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") + { + var editor = CKEDITOR.instances['dp_desc']; + if (editor) { + editor.setData(proddesc); + } + } + + jQuery('#dp_desc').text(proddesc); + }, 'json' ); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 542a4a09274..45fb10b525a 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1294,6 +1294,11 @@ if (empty($reshook)) $desc = $productsupplier->desc_supplier; } else $desc = $productsupplier->description; + //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time + if ($product_desc==$desc) { + $product_desc=''; + } + if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); $type = $productsupplier->type; diff --git a/htdocs/product/ajax/products.php b/htdocs/product/ajax/products.php index 7441d88abc0..273eef35300 100644 --- a/htdocs/product/ajax/products.php +++ b/htdocs/product/ajax/products.php @@ -71,7 +71,9 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) { $outref = $object->ref; $outlabel = $object->label; + $outlabel_trans =''; $outdesc = $object->description; + $outdesc_trans =''; $outtype = $object->type; $outqty = 1; $outdiscount = 0; @@ -79,10 +81,25 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $found = false; $price_level = 1; - if ($socid > 0 && !empty($conf->global->PRODUIT_MULTIPRICES)) { + + if ($socid > 0) { $thirdpartytemp = new Societe($db); $thirdpartytemp->fetch($socid); - $price_level = $thirdpartytemp->price_level; + //Load translation description and label + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { + $newlang = $thirdpartytemp->default_lang; + + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + $outdesc_trans = (!empty($object->multilangs[$outputlangs->defaultlang]["description"])) ? $object->multilangs[$outputlangs->defaultlang]["description"] : $object->description; + $outlabel_trans = (!empty($object->multilangs[$outputlangs->defaultlang]["label"])) ? $object->multilangs[$outputlangs->defaultlang]["label"] : $object->label; + } + } + + if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + $price_level = $thirdpartytemp->price_level; + } } // Price by qty @@ -158,7 +175,19 @@ if (!empty($action) && $action == 'fetch' && !empty($id)) $outtva_tx = $object->tva_tx; } - $outjson = array('ref' => $outref, 'label' => $outlabel, 'desc' => $outdesc, 'type' => $outtype, 'price_ht' => $outprice_ht, 'price_ttc' => $outprice_ttc, 'pricebasetype' => $outpricebasetype, 'tva_tx' => $outtva_tx, 'qty' => $outqty, 'discount' => $outdiscount); + $outjson = array( + 'ref' => $outref, + 'label' => $outlabel, + 'label_trans' => $outlabel_trans, + 'desc' => $outdesc, + 'desc_trans' => $outdesc_trans, + 'type' => $outtype, + 'price_ht' => $outprice_ht, + 'price_ttc' => $outprice_ttc, + 'pricebasetype' => $outpricebasetype, + 'tva_tx' => $outtva_tx, + 'qty' => $outqty, + 'discount' => $outdiscount); } echo json_encode($outjson);