=b.n)openDD=null;}}R();break;}
case"addb":S[p.k].push({id:uid(),c:null,n:0,it:[],cu:[]});openDD=null;R();break;
case"rmb":if(cDel()){S[p.k]=S[p.k].filter(x=>x.id!==p.bid);if(!S[p.k].length)S[p.k]=[{id:uid(),c:null,n:0,it:[],cu:[]}];openDD=null;R();}break;
case"next":goNext();break;case"back":goBack();break;
case"skip":if(S.ss<=1)break;if(S.ss===7)goNext();else{S.ss++;openDD=null;R();}break;
case"tab":S.at=p.v;S.hp=null;showAddForm=null;R();break;
case"sub":S.hp=p.v;showAddForm=null;R();break;
case"subback":S.hp=null;showAddForm=null;R();break;
case"theme":S.th=S.th==="dark"?"light":"dark";menuOpen=false;sv();R();break;
case"settings":S.hp="settings";S.at="home";menuOpen=false;R();break;
case"about":S.hp="about";S.at="home";menuOpen=false;R();break;
case"cursettings":S.hp="cursettings";S.at="home";menuOpen=false;R();break;
case"copydata":S.hp="copydata";S.at="home";menuOpen=false;R();break;
case"showaf":showAddForm=p.t;R();break;
case"hideaf":showAddForm=null;R();break;
// Quick add from settings - navigate to tab and show form
case"qacc":S.at="cc";S.hp=null;showAddForm="cc";menuOpen=false;R();break;
case"qaln":S.at="loans";S.hp=null;showAddForm="ln";menuOpen=false;R();break;
case"qabk":S.at="banks";S.hp=null;showAddForm="bk";menuOpen=false;R();break;
case"qaiv":S.at="investments";S.hp=null;showAddForm="iv";menuOpen=false;R();break;
case"qame":S.at="home";S.hp="monthly";showAddForm=null;menuOpen=false;R();break;
case"qaye":S.at="home";S.hp="yearly";showAddForm=null;menuOpen=false;R();break;
case"qais":S.at="home";S.hp="managePay";showAddForm=null;menuOpen=false;R();break;
case"qagl":S.at="home";S.hp="gl";showAddForm=null;menuOpen=false;R();break;
// Save inline forms
case"savecc":{const f=document.getElementById("af");if(!f)break;const nm=f.querySelector("[name=name]")?.value?.trim();if(!nm){alert("Name required");break;}
md.cd[nm]={currency:f.querySelector("[name=currency]")?.value||"USD",totalLimit:f.querySelector("[name=totalLimit]")?.value||"",used:f.querySelector("[name=used]")?.value||"",dueDate:f.querySelector("[name=dueDate]")?.value||"",thisMonthPayment:"",source:"",status:"Pending",notes:f.querySelector("[name=notes]")?.value||"",country:"us"};
showAddForm=null;sv();R();break;}
case"saveln":{const f=document.getElementById("af");if(!f)break;const nm=f.querySelector("[name=name]")?.value?.trim();if(!nm){alert("Name required");break;}
md.ld2[nm]={currency:f.querySelector("[name=currency]")?.value||"USD",totalLoan:f.querySelector("[name=totalLoan]")?.value||"",balance:f.querySelector("[name=balance]")?.value||"",dueDate:f.querySelector("[name=dueDate]")?.value||"",thisMonthPayment:"",source:"",status:"Pending",notes:f.querySelector("[name=notes]")?.value||"",country:"us"};
showAddForm=null;sv();R();break;}
case"savebk":{const f=document.getElementById("af");if(!f)break;const nm=f.querySelector("[name=name]")?.value?.trim();if(!nm){alert("Name required");break;}
md.bd[nm]={balance:f.querySelector("[name=balance]")?.value||"",currency:f.querySelector("[name=currency]")?.value||"USD",country:"us"};
showAddForm=null;sv();R();break;}
case"saveiv":{const f=document.getElementById("af");if(!f)break;const nm=f.querySelector("[name=name]")?.value?.trim();if(!nm){alert("Name required");break;}
md.vd[nm]={amount:f.querySelector("[name=amount]")?.value||"",type:f.querySelector("[name=type]")?.value||"Stocks",currency:f.querySelector("[name=currency]")?.value||"USD",source:"",status:"Pending"};
showAddForm=null;sv();R();break;}
case"rmcc":if(cDel()){delete md.cd[p.v];sv();R();}break;
case"rmln":if(cDel()){delete md.ld2[p.v];sv();R();}break;
case"rmbk":if(cDel()){delete md.bd[p.v];sv();R();}break;
case"rmiv2":if(cDel()){delete md.vd[p.v];sv();R();}break;
case"adde":{md[p.k].push({id:uid(),name:"",amount:"",currency:S.ac,category:"Other",dueDate:"",payDate:"",paySource:"",status:"Pending"});sv();R();break;}
case"rme":if(cDel()){md[p.k].splice(+p.i,1);sv();R();}break;
case"addis":md.is.push({id:uid(),name:"",type:"Salary",amount:"",tax:"",afterTax:"",currency:S.ac});sv();R();break;
case"rmis":if(cDel()){md.is.splice(+p.i,1);sv();R();}break;
case"addgl":md.gl.push({id:uid(),name:"",debits:[{acc:"",amt:""}],credits:[{acc:"",amt:""}],date:"",currency:S.ac});sv();R();break;
case"rmgl":if(cDel()){md.gl.splice(+p.i,1);sv();R();}break;
case"addi":{S.iv.push({id:uid(),name:"",type:"Stocks",amount:"",currency:S.ac});R();break;}
case"rmiv":if(cDel()){S.iv.splice(+p.i,1);R();}break;
case"refresh":fetchR();menuOpen=false;break;
case"docopy":{const from=document.getElementById("copy-from")?.value;const to=document.getElementById("copy-to")?.value;if(from&&to&&from!==to)copyMonth(from,to);break;}
case"setcurmode":S.curMode=p.v;sv();R();break;
case"setdefcur":S.ac=document.getElementById("defcur-sel")?.value||S.ac;sv();R();break;
}
});
document.addEventListener("click",function(e){if(openDD&&!e.target.closest(".dw")){openDD=null;R();}});
document.addEventListener("input",function(e){
if(e.target.dataset.sf){const q=e.target.value.toLowerCase();const l=e.target.closest(".dp").querySelector(".dl");if(l)Array.from(l.children).forEach(el=>{el.style.display=el.textContent.toLowerCase().includes(q)?"":"none";});}
if(e.target.dataset.ed){const d=e.target.dataset;const md=mD();
if(d.md&&d.idx!==undefined&&d.key){if(md[d.md]&&md[d.md][+d.idx])md[d.md][+d.idx][d.key]=e.target.value;}
else if(d.mobj&&d.sub&&d.key){if(md[d.mobj]&&md[d.mobj][d.sub])md[d.mobj][d.sub][d.key]=e.target.value;}
else if(d.arr&&d.idx!==undefined&&d.key){if(S[d.arr]&&S[d.arr][+d.idx])S[d.arr][+d.idx][d.key]=e.target.value;}
else if(d.field){S[d.field]=e.target.value;}
if(d.md==="is"&&(d.key==="amount"||d.key==="tax")){const inc=md.is[+d.idx];if(inc){inc.afterTax=((parseFloat(inc.amount)||0)-(parseFloat(inc.tax)||0)).toFixed(2);const el=document.getElementById("at-"+d.idx);if(el)el.textContent=gCS(inc.currency)+inc.afterTax;}}
sv();}
});
document.addEventListener("change",function(e){
if(e.target.dataset.ed){const d=e.target.dataset;const md=mD();
if(d.md&&d.idx!==undefined&&d.key){if(md[d.md]&&md[d.md][+d.idx])md[d.md][+d.idx][d.key]=e.target.value;}
else if(d.mobj&&d.sub&&d.key){if(md[d.mobj]&&md[d.mobj][d.sub])md[d.mobj][d.sub][d.key]=e.target.value;}
else if(d.arr&&d.idx!==undefined&&d.key){if(S[d.arr]&&S[d.arr][+d.idx])S[d.arr][+d.idx][d.key]=e.target.value;}
if(d.md==="is"&&d.key==="type"){const inc=md.is[+d.idx];if(inc){inc.afterTax=inc.type==="Salary"?((parseFloat(inc.amount)||0)-(parseFloat(inc.tax)||0)).toFixed(2):(inc.amount||"");}}
sv();if(d.rr)R();}
});
// โโ RENDER โโ
let rg=false;
function R(){
if(rg)return;rg=true;svL(S);
const app=document.getElementById("app");app.className="app"+(S.th==="light"?" light":"");
document.body.className=S.th==="light"?"light":"";document.documentElement.className=S.th==="light"?"light":"";
if(!authReady){app.innerHTML=``;rg=false;return;}
if(!currentUser){app.innerHTML=`๐ฐ
KPR Financial Manager
Track credit cards, loans, bank accounts, expenses & investments across multiple countries.
Sign in with Google `;rg=false;return;}
let h="";
if(!S.sd){h=rSetup();}
else{
// Top bar
h+=`${S.th==="dark"?"โ๏ธ":"๐"} ๐
KPR Finance `;
h+=``;
if(S.at==="home")h+=rHome();else h+=rAcct(S.at);
h+=`
`;
// Bottom nav - modern icons, home is center circle icon-only
h+=``;
[{k:"cc",l:"Cards",i:"๐ณ"},{k:"loans",l:"Loans",i:"๐ฆ"},{k:"home",l:"",i:"๐ "},{k:"banks",l:"Banks",i:"๐ง"},{k:"investments",l:"Invest",i:"๐"}].forEach(t=>{
const act=S.at===t.k;const isH=t.k==="home";
h+=`${t.i} ${t.l?`${t.l} `:""} `;
});
h+=`
`;
}
app.innerHTML=h;rg=false;
}
// โโ SETUP โโ
function rSetup(){
const ST=["Use Type","Cards","Loans","Banks","Monthly","Yearly","Investments"];
let h=``;
// Logout top right during setup
h+=`
Logout
`;
h+=`
`;
ST.forEach((nm,i)=>{const n=i+1,cls=S.ss>n?"d":S.ss===n?"a":"";h+=`${S.ss>n?"โ":n} ${nm} ${iโบ':""}`;});
h+=`
`;
if(S.ss===1){h+=`
Who are you setting this up for? Pick the option that fits.
`;
[{k:"personal",ic:"๐ค",t:"Personal use",d:"Track your own cards, loans, expenses & investments."},{k:"business",ic:"๐ผ",t:"Business",d:"Track business cards, working capital & operating costs."}].forEach(o=>{h+=`
${S.ut===o.k?"โ":""} ${o.ic}
${o.t} ${o.d}
`;});
h+=`
`;if(S.ut==="business")h+=`
Business name *
`;
}else if(S.ss>=2&&S.ss<=4){
const cfg=[,,{k:"cb",cat:CC,lb:"credit cards",cl:"Add custom card",ti:"Add your credit cards"},{k:"lb",cat:LN,lb:"loans",cl:"Add custom lender",ti:"Add your loans"},{k:"bb",cat:BK,lb:"bank accounts",cl:"Add custom bank",ti:"Add your bank accounts"}][S.ss];
h+=`
${cfg.ti} Pick country, count, and select.
`;
S[cfg.k].forEach((b,idx)=>{const co=b.c?CTRY.find(x=>x.code===b.c):null;const opts=b.c?[...(cfg.cat[b.c]||[]),...b.cu]:[];
h+=`
Country ${idx+1} `;if(S[cfg.k].length>1)h+=`Remove ร `;h+=`
`;
const cid=cfg.k+"-c-"+b.id;h+=`
Country ${co?co.flag+" "+co.name:`Select country... `} โผ `;
if(openDD===cid){h+=`
`;CTRY.forEach(c=>{h+=`
${c.flag} ${c.name}${b.c===c.code?" โ":""}
`;});h+=`
`;}h+=`
`;
h+=`
How many ${cfg.lb}? โ ${b.n} +
${!b.c?"Pick a country first":b.n===0?"Use + to set count":b.it.length+" of "+b.n+" selected"} `;
if(b.c&&b.n>0){const mid=cfg.k+"-i-"+b.id,lr=b.it.length>=b.n;
h+=`
Select your ${b.n} ${cfg.lb} ${b.it.length===0?`Choose... `:b.it.length===1?esc(b.it[0]):b.it.length+" of "+b.n+" selected"} โผ `;
if(openDD===mid){h+=`
+ ${cfg.cl}
`;
opts.forEach(o=>{const sel=b.it.includes(o),dis=!sel&&lr;h+=`
${esc(o)}${sel?" โ":""}
`;});h+=`
`;}h+=`
`;
if(b.it.length===b.n)h+=`
โ All ${b.n} selected
`;
if(b.it.length>0){h+=`
`;b.it.forEach(i=>{h+=`${esc(i)}ร `;});h+=`
`;}
}h+=`
`;});
h+=`
!b.c)?"disabled":""}>+ Add country `;
}else if(S.ss===5||S.ss===6){const key=S.ss===5?"me":"ye",title=S.ss===5?"Monthly expenses":"Yearly expenses",md=mD();
if(!md[key])md[key]=[];
h+=`
${title} Add your costs with category.
+ Add expense `;
}else if(S.ss===7){
h+=`
Investments Add platforms you track.
+ Add investment `;
}
const cp=canP();const canSkip=S.ss>1;
h+=`
โ Back ${canSkip?`Skip โ `:""}${S.ss===7?"Finish setup โ":"Continue โ"}
`;return h;
}
// โโ HOME โโ
function rHome(){
const sym=gS(),md=mD(),ps=gPS(),ro=isRO(),mode=gMM(S.selMonth||cMK());
if(S.hp==="monthly")return rExpPg("me","Monthly Expenses",sym,ps,ro,md);
if(S.hp==="yearly")return rExpPg("ye","Yearly Expenses",sym,ps,ro,md);
if(S.hp==="managePay")return rMP(sym,ro,md);
if(S.hp==="gl")return rGL(sym,ro,md);
if(S.hp==="settings")return rSettings();
if(S.hp==="about")return rAbout();
if(S.hp==="cursettings")return rCurSettings();
if(S.hp==="copydata")return rCopyData();
const tInc=sCvt(md.is||[],"afterTax","currency")||sCvt(md.is||[],"amount","currency");
const tTax=sCvt(md.is||[],"tax","currency");
const ccT=sOCvt(md.cd||{},"thisMonthPayment");const lnT=sOCvt(md.ld2||{},"thisMonthPayment");
const moT=sCvt(md.me||[],"amount","currency");
const mk=S.selMonth||cMK();const[,mm]=mk.split("-");
const yeF=(md.ye||[]).filter(e=>e.payDate&&e.payDate.split("-")[1]===mm);
const yrT=sCvt(yeF,"amount","currency");
const ivT=sCvt(Object.values(md.vd||{}),"amount","currency");
const tSp=ccT+lnT+moT+yrT+ivT;const net=tInc-tSp;
const assets=sOCvt(md.bd||{},"balance")+ivT;
const ccBal=Object.values(md.cd||{}).reduce((t,c)=>t+cvt(c.used||0,c.currency||"USD",S.ac),0);
const lnBal=Object.values(md.ld2||{}).reduce((t,l)=>t+cvt(l.balance||0,l.currency||"USD",S.ac),0);
const nw=assets-ccBal-lnBal;
let h=``;
h+=`${mSel()}${cSel()}
`;
if(ro)h+=`๐ Viewing history โ read-only
`;
if(mode==="budget")h+=`๐ Budget mode
`;
h+=``;
[{l:"๐
Monthly",p:"monthly"},{l:"๐ Yearly",p:"yearly"},{l:"๐ผ Income",p:"managePay"},{l:"๐ GL",p:"gl"}].forEach(b=>{h+=`
${b.l}
`;});
h+=`
`;
h+=`๐ฐ Net Worth
${sym}${nw.toFixed(2)}
`;
h+=``;
h+=`
๐ This Month
`;
h+=`
`;
[{l:"๐ต Income",v:tInc,c:"var(--ok)"},{l:"๐๏ธ Taxes",v:tTax,c:"var(--wrn)"},{l:"๐ธ Spent",v:tSp,c:"var(--err)"},{l:"โจ Remaining",v:net,c:net<0?"var(--err)":"var(--accent)"}].forEach((r,i)=>{const br=i%2===0?"border-right:1px solid var(--bd);":"";const bb=i<2?"border-bottom:1px solid var(--bd);":"";h+=`
${r.l}
${sym}${r.v.toFixed(2)}
`;});
h+=`
Breakdown
`;
[{l:"CC & Loans",v:ccT+lnT,c:"var(--err)"},{l:"Monthly & Yearly",v:moT+yrT,c:"var(--wrn)"},{l:"Investments",v:ivT,c:"var(--ok)"}].forEach(r=>{h+=`
${r.l} ${sym}${r.v.toFixed(2)}
`;});
h+=`
`;
return h;
}
function rSettings(){
let h=`โ
Settings `;
h+=`
Quick add `;
[{a:"qacc",l:"+ Add credit card"},{a:"qaln",l:"+ Add loan"},{a:"qabk",l:"+ Add bank account"},{a:"qaiv",l:"+ Add investment"},{a:"qame",l:"+ Add monthly expense"},{a:"qaye",l:"+ Add yearly expense"},{a:"qais",l:"+ Add income source"},{a:"qagl",l:"+ Add GL entry"}].forEach(b=>{h+=`${b.l} `;});
h+=`
Danger zone Reset all data `;
return h;
}
function rAbout(){
return`โ
About ๐ฐ
v${APP_VERSION}
KPR Financial Manager
Multi-country finance tracker with cloud sync
Built with Firebase โข Deployed on Vercel
`;
}
function rCurSettings(){
let h=`โ
Currency settings `;
h+=`Default currency ${ALL_CUR.map(c=>`${c} ${gCS(c)} `).join("")} `;
h+=`
Currency mode `;
h+=`Convert currencies `;
h+=`Single currency `;
h+=`
${S.curMode==="convert"?"Values are converted using live exchange rates":"All values shown as entered โ no conversion"}
`;
return h;
}
function rCopyData(){
const opts=gMO();
let h=`โ
Copy month data `;
h+=`Copy all data (cards, loans, banks, expenses, income, GL) from one month to another.
`;
h+=`
Copy from ${opts.map(m=>`${gML(m)}${S.months&&S.months[m]?" โ":""} `).join("")} `;
h+=`Copy to ${opts.map(m=>`${gML(m)} `).join("")}
`;
h+=`
Copy data `;
return h;
}
function aF(type){
if(showAddForm!==type)return"";
if(type==="cc")return``;
if(type==="ln")return``;
if(type==="bk")return``;
if(type==="iv")return``;
return"";
}
function rExpPg(key,title,sym,ps,ro,md){
const arr=md[key]||[];const total=sCvt(arr,"amount","currency");
let h=`โ
${title} `;
if(ro)h+=`๐ History โ read-only
`;
h+=`Total ${sym}${total.toFixed(2)}
`;
const cats={};arr.forEach(e=>{const c=e.category||"Other";if(!cats[c])cats[c]=[];cats[c].push(e);});
h+=``;
Object.entries(cats).forEach(([cat,items])=>{
const catT=items.reduce((t,e)=>t+cvt(e.amount,e.currency||"USD",S.ac),0);
h+=`
${cat} ${sym}${catT.toFixed(2)}
`;
items.forEach(e=>{const i=arr.indexOf(e);const cv2=cvt(e.amount,e.currency||"USD",S.ac);
h+=`
${esc(e.name)||"โ"} ${sym}${cv2.toFixed(0)} ${ro?"":`ร `}
`;});
h+=`
`;
});
if(!Object.keys(cats).length)h+=`
No expenses yet
`;
h+=`
`;
if(!ro)h+=`+ Add expense `;
return h;
}
function rMP(sym,ro,md){
let h=`โ
Manage Income `;
if(ro)h+=`๐ History โ read-only
`;
h+=``;
(md.is||[]).forEach((inc,i)=>{const iS=gCS(inc.currency);
h+=`
Income #${i+1} ${ro?"":`ร `}
`;
h+=`
Source
Type ${["Salary","Lending","GL","Freelance","Other"].map(t=>`${t} `).join("")}
Currency ${ALL_CUR.map(c=>`${c} `).join("")}
`;
if(inc.type==="Salary"){h+=`
`;}
else{h+=`
Amount
`;}
h+=`
`;});
h+=`
`;
if(!ro)h+=`+ Add income source `;return h;
}
function rGL(sym,ro,md){
let h=`โ
General Ledger `;
if(ro)h+=`๐ History โ read-only
`;
h+=``;
(md.gl||[]).forEach((e,i)=>{
if(!e.debits)e.debits=[{acc:"",amt:""}];if(!e.credits)e.credits=[{acc:"",amt:""}];
const tDb=e.debits.reduce((t,d)=>t+(parseFloat(d.amt)||0),0);
const tCr=e.credits.reduce((t,c)=>t+(parseFloat(c.amt)||0),0);
const diff=tDb-tCr;const bal=Math.abs(diff)<0.01;
h+=`
Txn #${i+1} ${bal?"โ Balanced":"Diff: "+gCS(e.currency||"USD")+Math.abs(diff).toFixed(2)}
${ro?"":`
ร `}
`;
h+=`
`;
h+=`
`;
});
h+=`
`;
if(!ro)h+=`+ Add transaction `;
const gDb=(md.gl||[]).reduce((t,e)=>t+(e.debits||[]).reduce((s,d)=>s+cvt(d.amt,e.currency||"USD",S.ac),0),0);
const gCr=(md.gl||[]).reduce((t,e)=>t+(e.credits||[]).reduce((s,c)=>s+cvt(c.amt,e.currency||"USD",S.ac),0),0);
h+=`Debits
${sym}${gDb.toFixed(2)}
Credits
${sym}${gCr.toFixed(2)}
Balance
${Math.abs(gDb-gCr)<0.01?"โ Balanced":sym+Math.abs(gCr-gDb).toFixed(2)}
`;
return h;
}
// โโ ACCOUNT PAGES โโ
function rAcct(type){
const sym=gS(),ro=isRO(),ps=gPS(),md=mD();
if(type==="cc")return rCCP(sym,ro,ps,md);
if(type==="loans")return rLnP(sym,ro,ps,md);
if(type==="banks")return rBkP(sym,ro,md);
if(type==="investments")return rIvP(sym,ro,ps,md);
return"";
}
function rCCP(sym,ro,ps,md){
const data=md.cd||{},items=Object.keys(data);
const tUsed=items.reduce((t,k)=>t+cvt(data[k].used||0,data[k].currency||"USD",S.ac),0);
const tLim=items.reduce((t,k)=>t+cvt(data[k].totalLimit||0,data[k].currency||"USD",S.ac),0);
let h=`
Credit Cards ${cSel()}`;
if(ro)h+=`๐ History โ read-only
`;
h+=`Limit (${S.ac})
${sym}${tLim.toFixed(2)}
Used (${S.ac})
${sym}${tUsed.toFixed(2)}
`;
h+=aF("cc");
h+=``;
if(!items.length)h+=`
No cards yet
`;
items.forEach(name=>{const it=data[name];const c=it.currency||"USD";const cs=gCS(c);const avail=(parseFloat(it.totalLimit)||0)-(parseFloat(it.used)||0);
h+=`
${esc(name)} (${c})
${ro?"":`
ร `}
`;
h+=`
`;
h+=`
`;
if(it.notes||!ro)h+=`
Notes
`;
h+=`
`;});
h+=`
`;
if(!ro)h+=`+ Add credit card `;
return h;
}
function rLnP(sym,ro,ps,md){
const data=md.ld2||{},items=Object.keys(data);
const tBal=items.reduce((t,k)=>t+cvt(data[k].balance||0,data[k].currency||"USD",S.ac),0);
let h=`
Loans ${cSel()}`;
if(ro)h+=`๐ History โ read-only
`;
h+=`Outstanding (${S.ac})
${sym}${tBal.toFixed(2)}
`;
h+=aF("ln");
h+=``;
if(!items.length)h+=`
No loans yet
`;
items.forEach(name=>{const it=data[name];const c=it.currency||"USD";const cs=gCS(c);const pO=(parseFloat(it.totalLoan)||0)-(parseFloat(it.balance)||0);
h+=`
${esc(name)} (${c})
${ro?"":`
ร `}
`;
h+=`
`;
h+=`
`;
if(it.notes||!ro)h+=`
Notes
`;
h+=`
`;});
h+=`
`;
if(!ro)h+=`+ Add loan `;
return h;
}
function rBkP(sym,ro,md){
const data=md.bd||{},items=Object.keys(data);
const tBal=items.reduce((t,k)=>t+cvt(data[k].balance||0,data[k].currency||gIC(data[k].country),S.ac),0);
let h=`
Banks ${cSel()}`;
if(ro)h+=`๐ History โ read-only
`;
h+=`Total (${S.ac})
${sym}${tBal.toFixed(2)}
`;
h+=aF("bk");
h+=``;
if(!items.length)h+=`
No accounts yet
`;
items.forEach(name=>{const it=data[name];const c=it.currency||gIC(it.country);
h+=`
${esc(name)} (${c})
${ro?"":`
ร `}
`;
h+=`
`;
if(c!==S.ac)h+=`
โ ${sym}${cvt(it.balance,c,S.ac).toFixed(2)} ${S.ac}
`;
h+=`
`;});
h+=`
`;
if(!ro)h+=`+ Add bank `;
return h;
}
function rIvP(sym,ro,ps,md){
const data=md.vd||{},items=Object.keys(data);
const tInv=items.reduce((t,k)=>t+cvt(data[k].amount||0,data[k].currency||"USD",S.ac),0);
let h=`
Investments ${cSel()}`;
if(ro)h+=`๐ History โ read-only
`;
h+=`Total (${S.ac})
${sym}${tInv.toFixed(2)}
`;
h+=aF("iv");
h+=``;
if(!items.length)h+=`
No investments yet
`;
items.forEach(name=>{const it=data[name];const c=it.currency||"USD";
h+=`
${esc(name)} (${c} ยท ${it.type||"Stocks"})
${ro?"":`
ร `}
`;
h+=`
`;
if(c!==S.ac)h+=`
โ ${sym}${cvt(it.amount,c,S.ac).toFixed(2)} ${S.ac}
`;
h+=`
`;});
h+=`
`;
if(!ro)h+=`+ Add investment `;
return h;
}
R();