backups/2026-03-28-pre-sidebar-refactor/konfigurator-varmepump.js

Code: DEV-46280997 Size: 3.9 KB Lines: 62 Path: /home/prodconfig.wenesthosting.com/dev.solargroup.wenest.se/backups/2026-03-28-pre-sidebar-refactor/konfigurator-varmepump.js

Task / Comment

Open report form
// konfigurator-varmepump.js
// Visar: varmepump

// === VÄRMEPUMP KONFIGURATOR (kopplad till Produktkatalog) ===
let _vpSelected=null, _vpPrice=0, _vpInstall=0, _vpDeduction='rot', _vpOwners=1, _vpFinYears=15;
let _vpProducts=[];

function initVpConfig(){ var _lbl=document.getElementById('cfgFileLabel');if(_lbl)_lbl.textContent='konfigurator-varmepump.js';
    _vpProducts = (typeof catalogProducts !== 'undefined' ? catalogProducts : []).filter(function(p){ return p.cat === 'varmepump'; });
    renderVpPumps();
    updateVpCalc();
}
function renderVpPumps(){
    var c=document.getElementById('vpPumpCards');if(!c)return;
    if(!_vpProducts.length) { c.innerHTML='<div style="padding:16px;color:#94a3b8;font-size:13px">Inga värmepump-produkter i katalogen</div>'; return; }
    c.innerHTML=_vpProducts.map(function(p){
        var selected = _vpSelected === p.id;
        var desc = p.desc || '';
        var rotBadge = p.rotEligible ? '<div style="font-size:10px;color:#059669;margin-top:4px">✓ ROT-avdrag</div>' : '';
        var greenBadge = p.greenTechEligible ? '<div style="font-size:10px;color:#059669;margin-top:4px">✓ Grön teknik-avdrag</div>' : '';
        return '<div onclick="selectVpPump(\''+p.id+'\','+p.price+')" style="padding:16px;border:2px solid '+(selected?'#3b82f6':'#e5e7eb')+';border-radius:10px;cursor:pointer;background:'+(selected?'#f0f9ff':'#fff')+'">'
            +'<div style="display:flex;align-items:center;justify-content:space-between">'
            +'<div>'
            +'<div style="font-weight:600;font-size:15px">'+p.name+'</div>'
            +'<div style="font-size:12px;color:#64748b;margin-top:2px">'+desc+'</div>'
            +rotBadge+greenBadge
            +'</div>'
            +'<div style="text-align:right">'
            +'<div style="font-size:18px;font-weight:700">'+fmt(p.price)+'</div>'
            +'<div style="font-size:11px;color:#64748b">inkl. installation</div>'
            +(selected?'<div style="color:#3b82f6;font-size:18px;margin-top:2px">✓</div>':'')
            +'</div></div></div>';
    }).join('');
}
function selectVpPump(id,price){if(_vpSelected===id){_vpSelected=null;_vpPrice=0;}else{_vpSelected=id;_vpPrice=price;}renderVpPumps();updateVpCalc();}
function setVpDeduction(t){_vpDeduction=t;cfgSetBtns('deduct','vp-deduct-btn',t);updateVpCalc();}
function setVpOwners(n){_vpOwners=n;cfgSetBtns('owner','vp-owner-btn',n);updateVpCalc();}
function setVpFinYears(y){_vpFinYears=y;cfgSetBtns('fin','vp-fin-btn',y);updateVpCalc();}
function updateVpCalc(){
    var subtotal=_vpPrice;
    var prod = _vpProducts.find(function(p){ return p.id === _vpSelected; });
    var hasRot = prod ? prod.rotEligible : false;
    var hasGreen = prod ? prod.greenTechEligible : false;
    var deductType = hasRot ? (_vpDeduction === 'rot' ? 'rot' : _vpDeduction) : (hasGreen ? (_vpDeduction === 'green' ? 'green' : _vpDeduction) : 'none');
    var laborRatio = 0.5; // Uppskattad arbetsandel
    var deduct=cfgDeduct(subtotal,laborRatio,deductType,_vpOwners);
    var total=subtotal-deduct;
    var monthly=cfgMonthly(total,_vpFinYears);
    document.getElementById('vpPrPump').textContent=fmt(subtotal);
    var installEl = document.getElementById('vpPrInstall');
    if(installEl) installEl.textContent='Ingår';
    document.getElementById('vpPrSubtotal').textContent=fmt(subtotal);
    document.getElementById('vpDeductLabel').textContent=deductType==='green'?'GRÖNT TEKNIK-AVDRAG':deductType==='rot'?'ROT-AVDRAG':'INGET AVDRAG';
    document.getElementById('vpDeductKr').textContent=deduct?'-'+fmt(deduct):'0 kr';
    document.getElementById('vpPrTotal').textContent=fmt(total);
    document.getElementById('vpFinInfo').textContent='('+_vpFinYears+' år, 4.9%)';
    document.getElementById('vpPrMonthly').textContent=fmt(monthly)+'/mån';
    // Update shared summary
    if(typeof cfgAddItem==='function') { var vpName = prod ? prod.name : 'Värmepump'; cfgAddItem('varmepump', vpName, subtotal, deductType, laborRatio); }
}