diff --git a/htdocs/core/ajax/vatrates.php b/htdocs/core/ajax/vatrates.php
index 97ed9e4697c..6572bd883f1 100644
--- a/htdocs/core/ajax/vatrates.php
+++ b/htdocs/core/ajax/vatrates.php
@@ -32,6 +32,7 @@ require '../../main.inc.php';
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$htmlname = GETPOST('htmlname','alpha');
+$productid = (GETPOST('productid','int')?GETPOST('productid','int'):0);
/*
* View
@@ -46,15 +47,15 @@ if (! empty($id) && ! empty($action) && ! empty($htmlname))
{
$form = new Form($db);
$soc = new Societe($db);
-
+
$soc->fetch($id);
-
+
$return=array();
-
- $return['value'] = $form->load_tva('tva_tx','',$soc,$mysoc,0,0,'',true);
+
+ $return['value'] = $form->load_tva('tva_tx','',$soc,$mysoc,$productid,0,'',true);
$return['num'] = $form->num;
$return['error'] = $form->error;
-
+
echo json_encode($return);
}
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index 878cee4812f..790d8580b93 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -2741,6 +2741,10 @@ function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournpr
{
global $db,$mysoc;
+ if (! class_exists('Product')) {
+ require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
+ }
+
$ret=0;
$found=0;
diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php
index 2fdf04d2403..203ea15931f 100644
--- a/htdocs/core/tpl/objectline_add.tpl.php
+++ b/htdocs/core/tpl/objectline_add.tpl.php
@@ -153,7 +153,7 @@ if (! empty($conf->margin->enabled)) {
tva_assuj == "0") echo '0';
+ if ($buyer->tva_assuj == "0") echo '0';
else echo $form->load_tva('tva_tx', (GETPOST('tva_tx')?GETPOST('tva_tx'):-1), $seller, $buyer);
?>
@@ -229,6 +229,18 @@ $(document).ready(function() {
$('#product_desc').focus();
}
+ // Update vat rate combobox
+ $.post('/core/ajax/vatrates.php', {
+ 'action': 'getVATRate',
+ 'id': id; ?>,
+ 'productid': $(this).val(),
+ 'htmlname': 'tva_tx' },
+ function(data) {
+ if (typeof data != 'undefined' && data.error == null) {
+ $("#tva_tx").html(data.value);
+ }
+ }, 'json');
+
// For compatibility with combobox
global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$.post('/product/ajax/products.php', {
@@ -258,6 +270,17 @@ $(document).ready(function() {
$('#update_price_checkbox').removeAttr('checked');
$('#price_ttc').val('');
+ // Update vat rate combobox
+ $.post('/core/ajax/vatrates.php', {
+ 'action': 'getVATRate',
+ 'id': id; ?>,
+ 'htmlname': 'tva_tx' },
+ function(data) {
+ if (typeof data != 'undefined' && data.error == null) {
+ $("#tva_tx").html(data.value);
+ }
+ }, 'json');
+
// For compatibility with combobox
global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$('#select_type').val('').removeAttr('disabled').trigger('change');
@@ -272,7 +295,6 @@ $(document).ready(function() {
$('#update_desc_area').hide().trigger('hide');
$('#update_price_area').hide().trigger('hide');
-
}
});
@@ -346,11 +368,13 @@ $(document).ready(function() {
$('#update_price_area').bind('hide', function() {
$('#price_ht').removeAttr('disabled');
$('#price_ttc').removeAttr('disabled');
+ $('#tva_tx').removeAttr('disabled');
});
$('#update_price_area').bind('show', function() {
$('#price_ht').attr('disabled', 'disabled');
$('#price_ttc').attr('disabled', 'disabled');
+ $('#tva_tx').attr('disabled', 'disabled');
});
$('#update_price_checkbox').change(function() {
@@ -359,15 +383,14 @@ $(document).ready(function() {
if ($('#tva_tx').val() > 0) {
$('#price_ttc').removeAttr('disabled')
}
+ $('#tva_tx').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');
+ $('#price_ttc').attr('disabled','disabled');
+ $('#tva_tx').attr('disabled', 'disabled');
}
});
|