Browse Source

[Administration] Produits > prix spécifiques : calcul des prix via un champs de remises en pourcentage #1156

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
15c1a1777c
2 changed files with 32 additions and 2 deletions
  1. +9
    -2
      backend/views/product/update/prices/_form.php
  2. +23
    -0
      backend/web/js/backend.js

+ 9
- 2
backend/views/product/update/prices/_form.php View File

<?= $form->field($model, 'price', [ <?= $form->field($model, 'price', [
'template' => ' 'template' => '
<div class="row"> <div class="row">
<div class="col-xs-6">
<div class="col-xs-4">
<label for="reduction-increase-percent" class="control-label">Réduction / augmentation</label>
<div class="input-group">
<input type="text" id="reduction-increase-percent" class="form-control" name="" value="" data-price-base="'.$productManager->getPrice($modelProduct).'">
<span class="input-group-addon">%</span>
</div>
</div>
<div class="col-xs-4">
<label for="product-price" class="control-label without-tax">Prix ('. $productManager->strUnit($productManager->getRefUnit($modelProduct->unit), 'wording_unit').') HT</label> <label for="product-price" class="control-label without-tax">Prix ('. $productManager->strUnit($productManager->getRefUnit($modelProduct->unit), 'wording_unit').') HT</label>
<div class="input-group"> <div class="input-group">
{input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span> {input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
</div> </div>
</div> </div>
<div class="col-xs-6">
<div class="col-xs-4">
<label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. $productManager->strUnit($productManager->getRefUnit($modelProduct->unit), 'wording_unit').') TTC</label> <label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. $productManager->strUnit($productManager->getRefUnit($modelProduct->unit), 'wording_unit').') TTC</label>
<div class="input-group"> <div class="input-group">
<input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'"> <input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'">

+ 23
- 0
backend/web/js/backend.js View File

opendistrib_product_prices_event_price_with_tax(); opendistrib_product_prices_event_price_with_tax();
$('#productprice-price').change(opendistrib_product_prices_event_price_with_tax); $('#productprice-price').change(opendistrib_product_prices_event_price_with_tax);
$('#productprice-price-with-tax').change(opendistrib_product_prices_event_price); $('#productprice-price-with-tax').change(opendistrib_product_prices_event_price);
$('#reduction-increase-percent').change(function() {
opendistrib_product_prices_event_reduction_increase();
});
} }
} }


$('#productprice-price-with-tax').val(getPriceWithTax(price, taxRateValue)); $('#productprice-price-with-tax').val(getPriceWithTax(price, taxRateValue));
// formattage // formattage
$('#productprice-price').val(parseFloat(price).toFixed(5)); $('#productprice-price').val(parseFloat(price).toFixed(5));

opendistrib_product_prices_update_reduction_increase();
} }
} }


$('#productprice-price').val(getPrice(priceWithTax, taxRateValue)); $('#productprice-price').val(getPrice(priceWithTax, taxRateValue));
// formattage // formattage
$('#productprice-price-with-tax').val(parseFloat(priceWithTax).toFixed(2)); $('#productprice-price-with-tax').val(parseFloat(priceWithTax).toFixed(2));

opendistrib_product_prices_update_reduction_increase();
}
}
function opendistrib_product_prices_update_reduction_increase() {
var productPriceBase = $('#reduction-increase-percent').data('price-base');
var productPriceSpecific = $('#productprice-price').val().replace(',', '.');
var reductionIncreasePercent = (productPriceSpecific / productPriceBase) * 100 - 100;
$('#reduction-increase-percent').val(parseFloat(reductionIncreasePercent).toFixed(5));
}

function opendistrib_product_prices_event_reduction_increase() {
var productPriceBase = $('#reduction-increase-percent').data('price-base');
var reductionIncreasePercent = $('#reduction-increase-percent').val();
if(reductionIncreasePercent) {
var newPrice = productPriceBase + productPriceBase * (reductionIncreasePercent / 100);
$('#productprice-price').val(parseFloat(newPrice).toFixed(5));
opendistrib_product_prices_event_price_with_tax();
} }
} }



Loading…
Cancel
Save