diff --git a/htdocs/core/ajax/price.php b/htdocs/core/ajax/price.php
index c1aab70882e..79f7d1f439b 100644
--- a/htdocs/core/ajax/price.php
+++ b/htdocs/core/ajax/price.php
@@ -29,9 +29,8 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
require('../../main.inc.php');
-$action = GETPOST('action','alpha');
-$pu_ht = price2num(GETPOST('pu_ht','alpha'));
-$pu_ttc = price2num(GETPOST('pu_ttc','alpha'));
+$output = GETPOST('output','alpha');
+$amount = price2num(GETPOST('amount','alpha'));
$tva_tx = str_replace('*','',GETPOST('tva_tx','alpha'));
/*
@@ -43,23 +42,27 @@ top_httphead();
//print ''."\n";
// Load original field value
-if (! empty($action) && isset($tva_tx))
+if (! empty($output) && isset($amount) && isset($tva_tx))
{
$return=array();
$price='';
- if ($action == 'get_ttc' && isset($pu_ht) && is_numeric($pu_ht) && $pu_ht != '') {
-
- $price = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
-
+ if (is_numeric($amount) && $amount != '')
+ {
+ if ($output == 'price_ttc') {
+
+ $price = price2num($amount * (1 + ($tva_tx/100)), 'MU');
+ $return['price_ht'] = $amount;
+ $return['price_ttc'] = (isset($price) && $price != '' ? price($price) : '');
+
+ }
+ else if ($output == 'price_ht') {
+
+ $price = price2num($amount / (1 + ($tva_tx/100)), 'MU');
+ $return['price_ht'] = (isset($price) && $price != '' ? price($price) : '');
+ $return['price_ttc'] = ($tva_tx == 0 ? $price : $amount);
+ }
}
- else if ($action == 'get_ht' && isset($pu_ttc) && is_numeric($pu_ttc) && $pu_ttc != '') {
-
- $price = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
-
- }
-
- $return['price'] = (isset($price) && $price != '' ? price($price) : '');
echo json_encode($return);
}
diff --git a/htdocs/core/js/lib_head.js b/htdocs/core/js/lib_head.js
index fc408e246e2..11e78f419b1 100644
--- a/htdocs/core/js/lib_head.js
+++ b/htdocs/core/js/lib_head.js
@@ -739,7 +739,7 @@ function hideMessage(fieldId,message) {
$.widget("ui.onDelayedKeyup", {
_init : function() {
var self = this;
- $(this.element).bind('change keyup input', function() {
+ $(this.element).bind('keyup', function() {
if(typeof(window['inputTimeout']) != "undefined"){
window.clearTimeout(inputTimeout);
}
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 3d099d59442..9e726f0eb18 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -135,17 +135,14 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
});
}
if (ui.item.textarea) {
- $.each(ui.item.textarea, function(key, value) {';
- if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
- $script.= ' // We use CKEditor
- CKEDITOR.instances[key].setData(value);
- CKEDITOR.instances[key].focus();';
- } else {
- $script.= ' // We use a simple textarea
- $("#" + key).html(value);
- $("#" + key).focus();';
- }
- $script.='
+ $.each(ui.item.textarea, function(key, value) {
+ if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
+ CKEDITOR.instances[key].setData(value);
+ CKEDITOR.instances[key].focus();
+ } else {
+ $("#" + key).html(value);
+ $("#" + key).focus();
+ }
});
}
}
@@ -413,4 +410,4 @@ function ajax_constantonoff($code,$input=array(),$entity=false)
return $out;
}
-?>
\ No newline at end of file
+?>
diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php
index 8e54eb0c3a3..d1f988772ef 100644
--- a/htdocs/core/tpl/objectline_add.tpl.php
+++ b/htdocs/core/tpl/objectline_add.tpl.php
@@ -76,10 +76,11 @@ if (! empty($conf->margin->enabled)) {
'product_label' => 'label2',
'origin_label_cache' => 'label2',
'origin_desc_cache' => 'desc',
+ 'price_base_type' => 'pricebasetype',
'price_ht' => 'price_ht',
'origin_price_ht_cache' => 'price_ht',
- 'price_ttc' => 'price_ttc',
- 'origin_price_ttc_cache' => 'price_ttc'
+ //'price_ttc' => 'price_ttc',
+ //'origin_price_ttc_cache' => 'price_ttc'
),
'show' => array(
'update_label_area',
@@ -110,7 +111,6 @@ if (! empty($conf->margin->enabled)) {
|
textwithtooltip($langs->trans('UpdateOriginalProductPrice'), $langs->trans('HelpUpdateOriginalProductPrice'),1,0,'','',3); ?>
-
@@ -156,6 +156,7 @@ if (! empty($conf->margin->enabled)) {
if ($buyer->tva_assuj == "0") echo '0';
else echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer);
?>
+
@@ -217,18 +218,15 @@ $(document).ready(function() {
$('#service_duration_area').hide();
$('#idprod').change(function() {
- if ($(this).val() > 0)
- {
- fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if ($(this).val().length > 0) {
+ if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
// We use CKEditor
CKEDITOR.instances['product_desc'].focus();
-
+ } else {
// We use a simple textarea
$('#product_desc').focus();
-
- $('#addlinebutton').removeAttr('disabled');
- } else {
- $('#addlinebutton').attr('disabled','disabled');
+ }
+ } else {
$('#update_desc_checkbox').removeAttr('checked').trigger('change');
$('#update_price_checkbox').removeAttr('checked').trigger('change');
}
@@ -299,16 +297,18 @@ $(document).ready(function() {
$('#update_price_checkbox').change(function() {
if ($(this).attr('checked')) {
$('#price_ht').removeAttr('disabled').focus();
- $('#price_ttc').removeAttr('disabled')
+ if ($('#tva_tx').val() > 0) {
+ $('#price_ttc').removeAttr('disabled')
+ }
} else {
$('#price_ht')
.attr('disabled','disabled')
.val($('#origin_price_ht_cache').val())
.trigger('change');
$('#price_ttc')
- .attr('disabled','disabled')
- .val($('#origin_price_ttc_cache').val())
- .trigger('change');
+ .attr('disabled','disabled');
+ //.val($('#origin_price_ttc_cache').val())
+ //.trigger('change');
}
});
@@ -338,21 +338,21 @@ $(document).ready(function() {
var origin_desc = $('#origin_desc_cache').val();
- fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
// We use CKEditor
var freecontent = CKEDITOR.instances['product_desc'].getData();
if (origin_desc.length > 0)
var content = origin_desc + ' ' + freecontent;
else
var content = freecontent;
-
+ } else {
// We use a simple textarea
var freecontent = $('#product_desc').html();
if (origin_desc.length > 0)
var content = origin_desc + '\r\n' + freecontent;
else
var content = freecontent;
-
+ }
$('#free_desc_cache').val(freecontent);
@@ -360,94 +360,77 @@ $(document).ready(function() {
var content = $('#free_desc_cache').val();
}
- fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
// We use CKEditor
CKEDITOR.instances['product_desc'].setData(content);
-
+ } else {
// We use a simple textarea
$('#product_desc').html(content);
-
+ }
});
$('#price_ht').focusin(function() {
- $('#price_base_type').html('HT');
+ $('#price_base_type').val('HT');
});
- $('#price_ht').onDelayedKeyup({
- handler: function() {
- $.post('/core/ajax/price.php', {
- 'action': 'get_ttc',
- 'pu_ht': $(this).val(),
- 'tva_tx': $('#tva_tx').val()
- },
- function(data) {
- if (data && data.price.length > 0) {
- $('#price_ttc').val(data.price);
- if ($('#select_type').val() >= 0) {
- $('#addlinebutton').removeAttr('disabled');
- } else {
- $('#addlinebutton').attr('disabled','disabled');
- }
- } else {
- $('#price_ttc').val('');
- $('#addlinebutton').attr('disabled','disabled');
- }
- }, 'json');
+ $('#price_ht').bind('change keyup input', function() {
+ if ($('#tva_tx').val() > 0 && ($('#idprod').val().length == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val().length > 0) {
+ update_price('price_ht', 'price_ttc');
}
});
$('#price_ttc').focusin(function() {
- $('#price_base_type').html('TTC');
+ $('#price_base_type').val('TTC');
});
- $('#price_ttc').onDelayedKeyup({
- handler: function() {
- $.post('/core/ajax/price.php', {
- 'action': 'get_ht',
- 'pu_ttc': $(this).val(),
- 'tva_tx': $('#tva_tx').val()
- },
- function(data) {
- if (data && data.price.length > 0) {
- $('#price_ht').val(data.price);
- if ($('#select_type').val() >= 0) {
- $('#addlinebutton').removeAttr('disabled');
- } else {
- $('#addlinebutton').attr('disabled','disabled');
- }
- } else {
- $('#price_ht').val('');
- $('#addlinebutton').attr('disabled','disabled');
- }
- }, 'json');
+ $('#price_ttc').bind('change keyup input', function() {
+ if ($('#price_base_type').val() == 'TTC') {
+ update_price('price_ttc', 'price_ht');
}
});
+ if ($('#tva_tx').val() == 0) {
+ $('#price_ttc').attr('disabled','disabled');
+ }
+
$('#tva_tx').change(function() {
- if ($('#price_base_type').html() == 'HT') {
- $.post('/core/ajax/price.php', {
- 'action': 'get_ttc',
- 'pu_ht': $('#price_ht').val(),
- 'tva_tx': $(this).val()
- },
- function(data) {
- if (data && data.price.length > 0) {
- $('#price_ttc').val(data.price);
- }
- }, 'json');
- } else if ($('#price_base_type').html() == 'TTC') {
- $.post('/core/ajax/price.php', {
- 'action': 'get_ht',
- 'pu_ttc': $('#price_ttc').val(),
- 'tva_tx': $(this).val()
- },
- function(data) {
- if (data && data.price.length > 0) {
- $('#price_ht').val(data.price);
- }
- }, 'json');
+ if ($(this).val() == 0) {
+ $('#price_ttc').attr('disabled','disabled');
+ $('#price_ttc').val('');
+ } else {
+ if ($('#idprod').val().length == 0 || ($('#idprod').val().length > 0 && $('#update_price_checkbox').attr('checked') == 'checked')) {
+ $('#price_ttc').removeAttr('disabled');
+ }
+ if ($('#price_base_type').val() == 'HT') {
+ update_price('price_ht', 'price_ttc');
+ } else if ($('#price_base_type').val() == 'TTC') {
+ update_price('price_ttc', 'price_ht');
+ }
}
});
+
+ function update_price(input, output) {
+ $.post('/core/ajax/price.php', {
+ 'amount': $('#' + input).val(),
+ 'output': output,
+ 'tva_tx': $('#tva_tx').val()
+ },
+ function(data) {
+ if (typeof data[output] != 'undefined') {
+ $('#' + output).val(data[output]);
+ if ($('#select_type').val() >= 0) {
+ $('#addlinebutton').removeAttr('disabled');
+ } else {
+ $('#addlinebutton').attr('disabled','disabled');
+ }
+ } else {
+ $('#' + input).val('');
+ $('#' + output).val('');
+ $('#addlinebutton').attr('disabled','disabled');
+ }
+ }, 'json');
+ }
+
});
@@ -456,7 +439,7 @@ $(document).ready(function() {
$("#idprod").change(function() {
$("#fournprice").empty();
$("#buying_price").show();
- if ($(this).val().length > 0)
+ if ($(this).val() > 0)
{
$.post('/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) {
if (data && data.length > 0) {
|