backups/2026-03-28-pre-sidebar-refactor/kalkyl-ramverk.js

Code: DEV-F7C86966 Size: 1.2 KB Lines: 29 Path: /home/prodconfig.wenesthosting.com/dev.solargroup.wenest.se/backups/2026-03-28-pre-sidebar-refactor/kalkyl-ramverk.js

Task / Comment

Open report form
// kalkyl-ramverk.js
// Visar: ramverk

// konfigurator-generic.js - Generic framework + sub-configurators

// === GENERISK KALKYL-RAMVERK (alla nya) ===
// =============================================
const CFG_FINANCE_RATE = 0.049;

function cfgMonthly(total, years) {
    if(!total||!years) return 0;
    const r=CFG_FINANCE_RATE/12, n=years*12;
    return Math.round(total*r*Math.pow(1+r,n)/(Math.pow(1+r,n)-1));
}
function cfgDeduct(subtotal, laborRatio, type, owners) {
    const maxPerOwner=50000, maxTotal=owners*maxPerOwner;
    if(type==='green') return Math.min(Math.round(subtotal*0.20), maxTotal);
    if(type==='rot') return Math.min(Math.round(subtotal*laborRatio*0.30), maxTotal);
    return 0;
}
function cfgSetBtns(prefix, cls, activeVal) {
    document.querySelectorAll('.'+cls).forEach(b=>{
        const v=b.dataset.dt||b.dataset.oc||b.dataset.yr;
        if(v===String(activeVal)){b.style.background=prefix==='fin'?'#3b82f6':'#059669';b.style.color='#fff';b.style.borderColor=prefix==='fin'?'#3b82f6':'#059669';}
        else{b.style.background='#fff';b.style.color=prefix==='fin'?'#3b82f6':'#059669';b.style.borderColor=prefix==='fin'?'#bfdbfe':'#bbf7d0';}
    });
}