<script>
$(document).ready(function() {
// BENUTZERABHAENGIGE PREISBERECHNUNG
// fix dropdown width
var dropdown = $('select[name="Mindestlaufzeit"]');
if (!dropdown){
return;
}
var dropdownList= dropdown.parents('div.dropdown-list');
if (!dropdownList){
return;
}
dropdownList.css('width','auto');
// get purchase pricing
var priceArr = dropdown.parents('table').find('tbody tr td:nth-child(2)').map(function(){
// match extracts the first price (in case there are multiple prices)
try{
var p = parseFloat($(this).text().match(/^([\d\.,]*\s€)/)[0].replace(/[€\.\s]/g,'').trim());
console.log("Base Price: " + p);
return p;
} catch (e) {
return "";
}
}).get();
dropdown.change(
function() {
let min_duration = $(this).val();
let index = dropdown.prop('selectedIndex');
let tds = $(this).parents('table').find('tbody tr td:nth-child(3)');
tds.each(
function(tdIndex) {
let purchasePrice = priceArr[tdIndex];
let price = priceArr[tdIndex] / (parseInt(min_duration, 10));
//let price = purchasePrice / ((parseInt(min_duration, 10)/1.75) + ((16 + index) - Math.sqrt(min_duration)));
if (price <= 7) { price = 7; };
let priceTag = Number(price)
$(this).text(priceTag.toFixed(2).replace('.',',') + " €");
}
);
}
);
dropdown.prop('selectedIndex', 2);
dropdown.change(); // calculate on load
});
</script> |