diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 171746ac591e0e3156d1862f7a978e96c7dd62ee..6526a060a980db2093f088aaf736890031d54db8 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -663,7 +663,7 @@ else if ($action == "addline" && $user->rights->propal->creer) $pu_ht=0; $pu_ttc=0; $price_min=0; - $price_base_type = 'HT'; + $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit @@ -673,54 +673,47 @@ else if ($action == "addline" && $user->rights->propal->creer) $prod = new Product($db); $prod->fetch($idprod); - $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); - $tva_npr = get_default_npr($mysoc,$object->client,$prod->id); - - // On defini prix unitaire - if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level) + // If prices fields are update + if (GETPOST('update_price') && (GETPOST('price_ht') || GETPOST('price_ttc'))) { - $pu_ht = $prod->multiprices[$object->client->price_level]; - $pu_ttc = $prod->multiprices_ttc[$object->client->price_level]; - $price_min = $prod->multiprices_min[$object->client->price_level]; - $price_base_type = $prod->multiprices_base_type[$object->client->price_level]; + $pu_ht=price2num(GETPOST('price_ht'), 'MU'); + $pu_ttc=price2num(GETPOST('price_ttc'), 'MU'); + $tva_tx=str_replace('*','', GETPOST('tva_tx')); + $tva_npr=preg_match('/\*/', GETPOST('tva_tx'))?1:0; } else { - $pu_ht = $prod->price; - $pu_ttc = $prod->price_ttc; - $price_min = $prod->price_min; - $price_base_type = $prod->price_base_type; - } + $tva_tx = get_default_tva($mysoc,$object->client,$prod->id); + $tva_npr = get_default_npr($mysoc,$object->client,$prod->id); - // Update if prices fields are defined - if (GETPOST('update_price') && (GETPOST('price_ht') || GETPOST('price_ttc'))) - { - $price_ht=price2num(GETPOST('price_ht'), 'MU'); - $price_ttc=price2num(GETPOST('price_ttc'), 'MU'); - - if ($price_base_type == 'TTC' && $price_ttc != $pu_ttc) + // On defini prix unitaire + if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level) { - $pu_ttc = $price_ttc; - $pu_ht = price2num($price_ttc / (1 + ($prod->tva_tx / 100)),'MU'); + $pu_ht = $prod->multiprices[$object->client->price_level]; + $pu_ttc = $prod->multiprices_ttc[$object->client->price_level]; + $price_min = $prod->multiprices_min[$object->client->price_level]; + $price_base_type = $prod->multiprices_base_type[$object->client->price_level]; } - else if ($price_base_type != 'TTC' && $price_ht != $pu_ht) + else { - $pu_ht = $price_ht; - $pu_ttc = price2num($price_ht * (1 + ($prod->tva_tx / 100)),'MU'); + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; } - } - // On reevalue prix selon taux tva car taux tva transaction peut etre different - // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - if ($tva_tx != $prod->tva_tx) - { - if ($price_base_type != 'HT') + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + if ($tva_tx != $prod->tva_tx) { - $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); - } - else - { - $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + if ($price_base_type != 'HT') + { + $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); + } + else + { + $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); + } } } diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index 1a4ffb08ace39909fcd483910e9512b18c4367c3..72e647f3da1a318f1d8c18d5774c0b58c6194e42 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -294,7 +294,7 @@ $(document).ready(function() { } //$('#add_product_area').show(); // TODO for add product card var addline=false; - if ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0) { + if ($('#price_ht').val().length > 0) { if ($('#idprod').val() == 0) { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { var content = CKEDITOR.instances['product_desc'].getData(); @@ -434,7 +434,7 @@ $(document).ready(function() { }); $('#price_ht').bind('change keyup input', function() { - if ($('#tva_tx').val() > 0 && (($('#idprod').val() == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val() > 0)) { + if (($('#idprod').val() == 0 && $('#price_base_type').val() == 'HT') || $('#idprod').val() > 0) { update_price('price_ht', 'price_ttc'); } }); @@ -478,7 +478,10 @@ $(document).ready(function() { function(data) { var addline=false; if (typeof data[output] != 'undefined') { - $('#' + output).val(data[output]); + // Hide price_ttc if no vat + if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) { + $('#' + output).val(data[output]); + } if ($('#idprod').val() == 0 && $('#select_type').val() >= 0) { if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { var content = CKEDITOR.instances['product_desc'].getData(); @@ -508,12 +511,12 @@ $(document).ready(function() { CKEDITOR.on('instanceReady', function() { CKEDITOR.instances['product_desc'].on('key', function() { var addline=false; - if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) { var content = CKEDITOR.instances['product_desc'].getData(); if (content.length > 0) { addline=true; } - } else if ($('#idprod').val() > 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + } else if ($('#idprod').val() > 0 && $('#price_ht').val().length > 0) { addline=true; } if (addline) { @@ -527,12 +530,12 @@ $(document).ready(function() { $('#product_desc').onDelayedKeyup({ 'handler': function() { var addline=false; - if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) { var content = $('#product_desc').val(); if (content.length > 0) { addline=true; } - } else if ($('#idprod').val() > 0 && ($('#price_ht').val().length > 0 || $('#price_ttc').val().length > 0)) { + } else if ($('#idprod').val() > 0 && $('#price_ht').val().length > 0) { addline=true; } if (addline) {