Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
8.8 kB
2
Indexable
Never
{if $addons.unity.pdp_leasing_info_enabled == 'Y'}
    {if $product.price|number_format:0 >= $addons.unity.pdp_leasing_info_show_from_price || $addons.unity.pdp_leasing_info_show_from_price == 0}
        {assign var="split_price_by" value=$addons.unity.pdp_leasing_info_slpit_price_by|default:3}
        {assign var="split_price_cof" value=$addons.unity.pdp_leasing_info_slpit_cof|default:0}
        {if $split_price_cof == 0}
            {math assign="split_price" equation="x/y" x=$product.price y=$split_price_by format="%.2f" }
        {else}
            {math assign="split_price" equation="x*y" x=$product.price y=$split_price_cof format="%.2f" }
        {/if}
        
        

        {capture name="leasing_info_link"}
            <div class="pdp-buySection-price-splitPayment-link ">
                <span>{__("unity.pdp_leasing_price.link_text",["[split_price_by]" => $split_price_by,"[product_price]" => $product.price|number_format:0, "[product_price_split]" => $split_price|number_format:2])}</span><span class="more-info-icon">{__("unity.icons.info_circle")}</span>
            </div>
        {/capture}

        {capture name="leasing_modal_content"}
            {__("unity.pdp_leasing_price.modal_content",["[item_price]" => $product.seo_snippet.price,"[n]" => $product.seo_snippet.price])}
        {/capture}
        

        {if __("unity.pdp_leasing_price.modal_content") != "" && __("unity.pdp_leasing_price.modal_content") != "_unity.pdp_leasing_price.modal_content"}
            <div class="pdp-buySection-price-splitPayment">
                {include file="addons/unity/common/unity_modal.tpl" title="{__("unity.pdp_leasing_price.modal_title")}" content="{$smarty.capture.leasing_modal_content}" link_text="{$smarty.capture.leasing_info_link}" id="leaseinfo" button_class="more-info {$class}" button_type="span" no_arrow="Y"}
            </div>
        {else}
            <div class="pdp-buySection-price-splitPayment">
                <div class="pdp-buySection-price-splitPayment-link">
                    <span>{__("unity.pdp_leasing_price.link_text",["[split_price_by]" => $split_price_by,"[product_price]" => $product.price|number_format:0, "[product_price_split]" => $split_price|number_format:2])}</span>
                </div>
            </div>
        {/if}
    {/if}
{/if}

<style>

.installments-option {
    cursor: pointer;
}

.installments-option.active {
    border: 4px solid green;
    background: #FF6600;
}

</style>
<script>




function calplata (perioada = 24) {

    // var totalvalue = parseInt(document.getElementById("totalvalue").value);
    // console.log(totalvalue);
    $('#totalvalue').val(perioada);
    var totalValue = +$('#tbi-item-price span').text();
    // var totalValue = perioada;
    // var perioada = parseInt(document.getElementById("perioada").value);
    var dobanda = 0;
    var comision = 0;
    var valasig = 0;

    console.log('period', perioada);

   if (totalvalue >= 100 && totalvalue <= 2000){
        dobanda = 0;
        perioada = 40;
        comision = 0;
        valasig = 0;
    } else if (totalvalue >= 2001 && totalvalue <= 4000){
        dobanda = 0.29;
        // perioada = parseInt(document.getElementById("perioada").value);
        comision = 95;
        valasig = 0.0020;
    } else if (totalvalue >= 4001 && totalvalue <= 8000){
        dobanda = 0.21;
        // perioada = parseInt(document.getElementById("perioada").value);
        comision = 95;
        valasig = 0.0020;
    } else if (totalvalue >= 8001 && totalvalue <= 65000){
        dobanda = 0.18;
        // perioada = parseInt(document.getElementById("perioada").value);
        comision = 95;
        valasig = 0.0020;
    }
	

    //calcul valoare asigurare
	var valasigurare = valasig*(totalvalue+comision)*perioada;

    //componente valoare rata
	var principal = (totalvalue+comision+valasigurare);
	var CalculateInterest = dobanda/12;
	var calculatedPayments = perioada;

    //formula valoare rata
	var x = Math.pow(1 + CalculateInterest, calculatedPayments);
	var monthly = (principal * x * CalculateInterest) / (x - 1);
	var monthlyPayment = monthly.toFixed(2);
	
    //dae var

	var interest = 0.1;
	var dueEndOrBeginning = 0;
	var futureValue = 0;
	var paymentsPerYear = perioada;
	if (totalvalue < 2001){
		var presentValue =  totalvalue;
		var paymentAmount = -((totalvalue+comision)/4);
	}else{
		var presentValue =  (totalvalue+valasigurare);
		var paymentAmount = (monthlyPayment*-1);
	}

    //dae formula

		var FINANCIAL_MAX_ITERATIONS = 128;//Bet accuracy with 128
		var FINANCIAL_PRECISION = 0.0000001;//1.0e-8
					
		var y, y0, y1, x0, x1 = 0, f = 0, i = 0;
		var rate = interest; // initiallizing rate to our guess interest 
		if (Math.abs(rate) < FINANCIAL_PRECISION)
		{
		y = presentValue * (1 + paymentsPerYear * rate) + paymentAmount * (1 + rate * dueEndOrBeginning) * paymentsPerYear + futureValue;
		}
		else
		{
		f = Math.exp(paymentsPerYear * Math.log(1 + rate));
		y = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue;
		}
		y0 = presentValue + paymentAmount * paymentsPerYear + futureValue;
		y1 = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue;
					
    // find root by Newton secant method
		i = x0 = 0.0;
		x1 = rate;

		while ((Math.abs(y0 - y1) > FINANCIAL_PRECISION)
		&& (i < FINANCIAL_MAX_ITERATIONS))
		{
		rate = (y1 * x0 - y0 * x1) / (y1 - y0);
		x0 = x1;
		x1 = rate;

		if (Math.abs(rate) < FINANCIAL_PRECISION)
		{
		y = presentValue * (1 + paymentsPerYear * rate) + paymentAmount * (1 + rate * dueEndOrBeginning) * paymentsPerYear + futureValue;
		}
		else
		{
		f = Math.exp(paymentsPerYear * Math.log(1 + rate));
		y = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue;
		}
					
		y0 = y1;
		y1 = y;
		++i;
		}
        console.log('total', totalValue);			
		console.log(rate);				
		var dae = ((((1+rate) ** 12)-1)*100).toFixed(2);

		
    document.getElementById("asigurare").innerText = valasigurare.toFixed(2);
    document.getElementById("dae").innerText = dae;



    totalValue = 600;
    console.log('total val', totalvalue);


    if (totalvalue < 2001){
        document.getElementById("rata").innerText = (totalvalue+40)/4;
        document.getElementById("totaldeplata").innerText = (totalvalue+80).toFixed(2);
    }else{
        document.getElementById("rata").innerText = monthlyPayment;
        document.getElementById("totaldeplata").innerText = (monthlyPayment*perioada).toFixed(2);
    }
}

$('.installments-option').on('click', function(){
    $('.installments-option.active').removeClass('active');
    $(this).addClass('active');

    calplata($(this).attr('data-time-period'));
})

$('.tbi-leasing-snippet').on('click', calplata());

$('#customRange').on('change', function() {
    calplata($(this).val());
})









</script>

{literal}
<script>
    document.addEventListener('DOMContentLoaded', function() {
    const slider = document.getElementById('customRange');
    const dynamicLabel = document.getElementById('dynamicValue');

    function adjustSlider() {
        const ranges = [6, 12, 18, 24, 36, 48, 60];
        const max = slider.max;
        const proportion = slider.value / max;
        const index = Math.round(proportion * (ranges.length - 1));
        const customValue = ranges[index];
        const newValueProportion = index / (ranges.length - 1);

        slider.value = newValueProportion * max;
        const newPosition = newValueProportion * 100;

        dynamicLabel.style.left = `calc(${newPosition}% - ${dynamicLabel.offsetWidth / 2}px)`;

        if (customValue === 6 || customValue === 60) {
            dynamicLabel.style.display = 'none';
        } else {
            dynamicLabel.style.display = 'block';
            dynamicLabel.innerText = customValue;
        }
    }

    // Bind the input event handler
    slider.addEventListener('input', adjustSlider);

    // Trigger the adjustment logic immediately to apply the correct initial state
    adjustSlider();
});

document.getElementById('customRange').addEventListener('input', function() {
    var value = parseInt(this.value);
    var max = parseInt(this.max);
    var percent = (value / max) * 100; // Calculates how far the thumb is along the slider as a percentage

    // Set the background gradient dynamically
    this.style.background = `linear-gradient(to right, #FF6600 0%, #FF6600 ${percent}%, white ${percent}%, white 100%)`;
});

</script>
{/literal}
    
Leave a Comment