Fix: debug ckeditor and VAT

This commit is contained in:
Regis Houssin 2012-08-27 13:27:27 +02:00
parent 35a0311d28
commit 2f14fbe791
4 changed files with 80 additions and 91 deletions

View File

@ -29,9 +29,8 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
require('../../main.inc.php'); require('../../main.inc.php');
$action = GETPOST('action','alpha'); $output = GETPOST('output','alpha');
$pu_ht = price2num(GETPOST('pu_ht','alpha')); $amount = price2num(GETPOST('amount','alpha'));
$pu_ttc = price2num(GETPOST('pu_ttc','alpha'));
$tva_tx = str_replace('*','',GETPOST('tva_tx','alpha')); $tva_tx = str_replace('*','',GETPOST('tva_tx','alpha'));
/* /*
@ -43,23 +42,27 @@ top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n"; //print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
// Load original field value // Load original field value
if (! empty($action) && isset($tva_tx)) if (! empty($output) && isset($amount) && isset($tva_tx))
{ {
$return=array(); $return=array();
$price=''; $price='';
if ($action == 'get_ttc' && isset($pu_ht) && is_numeric($pu_ht) && $pu_ht != '') { if (is_numeric($amount) && $amount != '')
{
if ($output == 'price_ttc') {
$price = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); $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); echo json_encode($return);
} }

View File

@ -739,7 +739,7 @@ function hideMessage(fieldId,message) {
$.widget("ui.onDelayedKeyup", { $.widget("ui.onDelayedKeyup", {
_init : function() { _init : function() {
var self = this; var self = this;
$(this.element).bind('change keyup input', function() { $(this.element).bind('keyup', function() {
if(typeof(window['inputTimeout']) != "undefined"){ if(typeof(window['inputTimeout']) != "undefined"){
window.clearTimeout(inputTimeout); window.clearTimeout(inputTimeout);
} }

View File

@ -136,7 +136,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
} }
if (ui.item.textarea) { if (ui.item.textarea) {
$.each(ui.item.textarea, function(key, value) { $.each(ui.item.textarea, function(key, value) {
if (typeof CKEDITOR == "object") { if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined") {
CKEDITOR.instances[key].setData(value); CKEDITOR.instances[key].setData(value);
CKEDITOR.instances[key].focus(); CKEDITOR.instances[key].focus();
} else { } else {

View File

@ -76,10 +76,11 @@ if (! empty($conf->margin->enabled)) {
'product_label' => 'label2', 'product_label' => 'label2',
'origin_label_cache' => 'label2', 'origin_label_cache' => 'label2',
'origin_desc_cache' => 'desc', 'origin_desc_cache' => 'desc',
'price_base_type' => 'pricebasetype',
'price_ht' => 'price_ht', 'price_ht' => 'price_ht',
'origin_price_ht_cache' => 'price_ht', 'origin_price_ht_cache' => 'price_ht',
'price_ttc' => 'price_ttc', //'price_ttc' => 'price_ttc',
'origin_price_ttc_cache' => 'price_ttc' //'origin_price_ttc_cache' => 'price_ttc'
), ),
'show' => array( 'show' => array(
'update_label_area', 'update_label_area',
@ -110,7 +111,6 @@ if (! empty($conf->margin->enabled)) {
<span id="update_price_area" class="hideobject"> | <input type="checkbox" id="update_price_checkbox" name="update_price" value="1" /> <span id="update_price_area" class="hideobject"> | <input type="checkbox" id="update_price_checkbox" name="update_price" value="1" />
<?php echo $form->textwithtooltip($langs->trans('UpdateOriginalProductPrice'), $langs->trans('HelpUpdateOriginalProductPrice'),1,0,'','',3); ?> <?php echo $form->textwithtooltip($langs->trans('UpdateOriginalProductPrice'), $langs->trans('HelpUpdateOriginalProductPrice'),1,0,'','',3); ?>
</span> </span>
<span id="price_base_type" class="hideobject"></span>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
@ -156,6 +156,7 @@ if (! empty($conf->margin->enabled)) {
if ($buyer->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0'; if ($buyer->tva_assuj == "0") echo '<input type="hidden" name="np_tva_tx" value="0">0';
else echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer); else echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer);
?> ?>
<input type="hidden" id="price_base_type" name="price_base_type" value="" />
</td> </td>
<td align="right"> <td align="right">
<input type="text" size="8" id="price_ht" name="price_ht" value="<?php echo (GETPOST('price_ht')?GETPOST('price_ht'):''); ?>"> <input type="text" size="8" id="price_ht" name="price_ht" value="<?php echo (GETPOST('price_ht')?GETPOST('price_ht'):''); ?>">
@ -220,7 +221,7 @@ $(document).ready(function() {
$('#idprod').change(function() { $('#idprod').change(function() {
if ($(this).val().length > 0) if ($(this).val().length > 0)
{ {
if (typeof CKEDITOR == 'object') { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
CKEDITOR.instances['product_desc'].focus(); CKEDITOR.instances['product_desc'].focus();
} else { } else {
$('#product_desc').focus(); $('#product_desc').focus();
@ -297,16 +298,18 @@ $(document).ready(function() {
$('#update_price_checkbox').change(function() { $('#update_price_checkbox').change(function() {
if ($(this).attr('checked')) { if ($(this).attr('checked')) {
$('#price_ht').removeAttr('disabled').focus(); $('#price_ht').removeAttr('disabled').focus();
$('#price_ttc').removeAttr('disabled') if ($('#tva_tx').val() > 0) {
$('#price_ttc').removeAttr('disabled')
}
} else { } else {
$('#price_ht') $('#price_ht')
.attr('disabled','disabled') .attr('disabled','disabled')
.val($('#origin_price_ht_cache').val()) .val($('#origin_price_ht_cache').val())
.trigger('change'); .trigger('change');
$('#price_ttc') $('#price_ttc')
.attr('disabled','disabled') .attr('disabled','disabled');
.val($('#origin_price_ttc_cache').val()) //.val($('#origin_price_ttc_cache').val())
.trigger('change'); //.trigger('change');
} }
}); });
@ -336,7 +339,7 @@ $(document).ready(function() {
var origin_desc = $('#origin_desc_cache').val(); var origin_desc = $('#origin_desc_cache').val();
if (typeof CKEDITOR == 'object') { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
var freecontent = CKEDITOR.instances['product_desc'].getData(); var freecontent = CKEDITOR.instances['product_desc'].getData();
if (origin_desc.length > 0) if (origin_desc.length > 0)
var content = origin_desc + '<br />' + freecontent; var content = origin_desc + '<br />' + freecontent;
@ -356,7 +359,7 @@ $(document).ready(function() {
var content = $('#free_desc_cache').val(); var content = $('#free_desc_cache').val();
} }
if (typeof CKEDITOR == 'object') { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined') {
CKEDITOR.instances['product_desc'].setData(content); CKEDITOR.instances['product_desc'].setData(content);
} else { } else {
$('#product_desc').html(content); $('#product_desc').html(content);
@ -364,84 +367,67 @@ $(document).ready(function() {
}); });
$('#price_ht').focusin(function() { $('#price_ht').focusin(function() {
$('#price_base_type').html('HT'); $('#price_base_type').val('HT');
}); });
$('#price_ht').onDelayedKeyup({ $('#price_ht').bind('change keyup input', function() {
handler: function() { if ($('#tva_tx').val() > 0 && ($('#idprod').val().length == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val().length > 0) {
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { update_price('price_ht', 'price_ttc');
'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_ttc').focusin(function() { $('#price_ttc').focusin(function() {
$('#price_base_type').html('TTC'); $('#price_base_type').val('TTC');
}); });
$('#price_ttc').onDelayedKeyup({ $('#price_ttc').bind('change keyup input', function() {
handler: function() { if ($('#price_base_type').val() == 'TTC') {
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { update_price('price_ttc', 'price_ht');
'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');
} }
}); });
if ($('#tva_tx').val() == 0) {
$('#price_ttc').attr('disabled','disabled');
}
$('#tva_tx').change(function() { $('#tva_tx').change(function() {
if ($('#price_base_type').html() == 'HT') { if ($(this).val() == 0) {
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { $('#price_ttc').attr('disabled','disabled');
'action': 'get_ttc', $('#price_ttc').val('');
'pu_ht': $('#price_ht').val(), } else {
'tva_tx': $(this).val() if ($('#idprod').val().length == 0 || ($('#idprod').val().length > 0 && $('#update_price_checkbox').attr('checked') == 'checked')) {
}, $('#price_ttc').removeAttr('disabled');
function(data) { }
if (data && data.price.length > 0) { if ($('#price_base_type').val() == 'HT') {
$('#price_ttc').val(data.price); update_price('price_ht', 'price_ttc');
} } else if ($('#price_base_type').val() == 'TTC') {
}, 'json'); update_price('price_ttc', 'price_ht');
} else if ($('#price_base_type').html() == 'TTC') { }
$.post('<?php echo DOL_URL_ROOT; ?>/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');
} }
}); });
function update_price(input, output) {
$.post('<?php echo DOL_URL_ROOT; ?>/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');
}
}); });
</script> </script>