🤰 MamaCare

Loading...

Default: matron / matron123
Reset Login


er.role+')'; $('planBadge').innerText=isPro?'PRO':'FREE'; } render(); } function doLogin(){ let u=$('loginUser').value.trim().toLowerCase(); let p=$('loginPass').value.trim(); if(!u||!p){ $('loginMsg').innerText='Enter username & password'; return; } users=JSON.parse(localStorage.getItem('mc_users')||'[]'); let found=users.find(x=>x.username.toLowerCase()===u && x.password===p); if(!found){ $('loginMsg').innerText='Wrong! Use matron / matron123. Or click Reset.'; return; } localStorage.setItem('mc_currentUser',JSON.stringify(found)); currentUser=found; $('loginMsg').innerText=''; checkAuth(); } function resetLogin(){ users=[{username:'matron',password:'matron123',role:'matron',displayName:'Matron'}]; localStorage.setItem('mc_users',JSON.stringify(users)); localStorage.removeItem('mc_currentUser'); currentUser=null; $('loginMsg').innerText='Reset done! Now login matron / matron123'; showLogin(); } function calcEDD(lmp){if(!lmp) return null; let d=new Date(lmp); let edd=new Date(d.getTime()+280*86400000); return edd.toLocaleDateString();} function addPatient(){ let name=$('pName').value.trim(); if(!name){alert('Name needed');return;} if(!isPro && patients.length>=5){showPay();return;} let note=$('pNote').value; let amt=0; let m=note.match(/(\d+)k/i); if(m) amt=parseInt(m[1])*1000; else{ let m2=note.match(/(\d{3,})/); if(m2) amt=parseInt(m2[1]);} let lmp=$('pLMP').value; let edd=lmp?calcEDD(lmp):''; patients.unshift({id:Date.now(),name,age:$('pAge').value,phone:$('pPhone').value,lmp,edd,note,amount:amt,date:new Date().toLocaleDateString(),staff:currentUser?currentUser.displayName:'Matron',qrId:'MC-'+Date.now().toString().slice(-5)}); if(amt>0) payments.unshift({name,amount:amt,date:new Date().toLocaleDateString()}); localStorage.setItem('mc_patients',JSON.stringify(patients)); localStorage.setItem('mc_payments',JSON.stringify(payments)); $('pName').value='';$('pAge').value='';$('pPhone').value='';$('pNote').value='';$('pLMP').value=''; $('eddDisplay').innerText='✅ Saved '+name+' EDD: '+edd; render(); } function render(){ $('listCount').innerText=patients.length; $('patientList').innerHTML=patients.map(p=>`
${p.name}
${p.note} ${p.edd?'•EDD:'+p.edd:''} • ${p.staff}
₦${p.amount}
`).join('')||'No patients'; } function sendWA(phone,name,note,amt){ let msg=`MamaCare Receipt%0APatient: ${name}%0AService: ${note}%0AAmount: ${amt}%0AThank you!`; let clean=phone?phone.replace(/[^0-9]/g,'').slice(-10):''; let url=clean?`https://wa.me/234${clean}?text=${msg}`:`https://wa.me/?text=${msg}`; window.open(url,'_blank'); } function dailyPDF(){ let today=new Date().toLocaleDateString(); let todays=payments.filter(p=>p.date===today); let total=todays.reduce((a,b)=>a+b.amount,0); let text=`MamaCare Daily Report ${today}\nTotal: NGN ${total}\n\n`+todays.map(p=>`${p.name} - ${p.amount}`).join('\n'); let blob=new Blob([text],{type:'text/plain'}); let a=document.createElement('a');a.href=URL.createObjectURL(blob);a.download='MamaCare-'+today+'.txt';a.click(); } // EVENT LISTENERS - NO onclick blocking document.addEventListener('DOMContentLoaded',function(){ $('btnLogin').addEventListener('click',doLogin); $('btnShowPay').addEventListener('click',showPay); $('btnReset').addEventListener('click',resetLogin); $('btnBackLogin').addEventListener('click',showLogin); $('btnFree').addEventListener('click',function(){ $('paywall').style.display='none'; if(!currentUser) showLogin(); }); $('btnLogout').addEventListener('click',function(){localStorage.removeItem('mc_currentUser');location.reload();}); $('btnAddPatient').addEventListener('click',addPatient); $('btnPDF').addEventListener('click',dailyPDF); $('btnPayMonth').addEventListener('click',function(){ let email=$('payEmail').value.trim(); let name=$('payName').value.trim(); if(!email||!name){$('payMsg').innerText='Enter email & clinic';return;} let s=document.createElement('script'); s.src='https://js.paystack.co/v1/inline.js'; s.onload=function(){ let h=PaystackPop.setup({key:'pk_live_8858801747bfb68f91ca0598bbe4f7a9ea3ab7bb',email,amount:500000,currency:'NGN',ref:'MC-MONTH-'+Date.now(),callback:function(){localStorage.setItem('mc_pro','true');alert('Payment success!');location.reload();}});h.openIframe(); }; document.body.appendChild(s); }); $('btnPayLife').addEventListener('click',function(){ let email=$('payEmail').value.trim(); let name=$('payName').value.trim(); if(!email||!name){$('payMsg').innerText='Enter email & clinic';return;} let s=document.createElement('script'); s.src='https://js.paystack.co/v1/inline.js'; s.onload=function(){ let h=PaystackPop.setup({key:'pk_live_8858801747bfb68f91ca0598bbe4f7a9ea3ab7bb',email,amount:2500000,currency:'NGN',ref:'MC-LIFE-'+Date.now(),callback:function(){localStorage.setItem('mc_pro','true');alert('Lifetime unlocked!');location.reload();}});h.openIframe(); }; document.body.appendChild(s); }); $('pLMP').addEventListener('change',function(){let e=calcEDD(this.value); if(e) $('eddDisplay').innerText='EDD: '+e;}); checkAuth(); }); ')||'null'); if(!users||!Array.isArray(users)||users.length===0){users=[{username:'matron',password:'matron123',role:'matron',displayName:'Matron'}];localStorage.setItem('mc_users',JSON.stringify(users));} let staffNames=JSON.parse(localStorage.getItem('mc_staffNames')||'null')||{matron:'Matron',nurse1:'Nurse 1',nurse2:'Nurse 2',nurse3:'Nurse 3'}; let currentUser=JSON.parse(localStorage.getItem('mc_currentUser')||'null');let isPro=localStorage.getItem('mc_pro')==='true';let plan=localStorage.getItem('mc_plan')||'free';let html5QrCode,qrScanner;let darkMode=localStorage.getItem('mc_dark')==='true'; if(darkMode) document.body.classList.add('dark'); function toggleDark(){darkMode=!darkMode;localStorage.setItem('mc_dark',darkMode);document.body.classList.toggle('dark',darkMode);} function checkAuth(){ if(!currentUser){document.getElementById('loginScreen').style.display='flex';}else{document.getElementById('loginScreen').style.display='none';document.getElementById('currentUserDisplay').innerText=currentUser.displayName+' ('+currentUser.role+')';document.getElementById('staffMode').innerText=currentUser.displayName;document.getElementById('planBadge').innerText=isPro?(plan==='lifetime'?'LIFETIME':'PRO'):'FREE';} renderStaffInputs();renderUsers(); } function doLogin(){ const uRaw=document.getElementById('loginUser').value.trim(); const u=uRaw.toLowerCase(); const p=document.getElementById('loginPass').value.trim(); if(!u||!p){document.getElementById('loginMsg').innerText='Enter username and password';return;} users=JSON.parse(localStorage.getItem('mc_users')||'[]'); if(users.length===0){users=[{username:'matron',password:'matron123',role:'matron',displayName:'Matron'}];localStorage.setItem('mc_users',JSON.stringify(users));} const found=users.find(x=>x.username.toLowerCase()===u && x.password===p); if(!found){document.getElementById('loginMsg').innerText='Wrong username/password. Try matron / matron123 or Reset';return;} let logs=JSON.parse(localStorage.getItem('mc_loginLogs')||'[]');logs.unshift({username:found.username,displayName:found.displayName,role:found.role,time:new Date().toLocaleString(),ua:navigator.userAgent});localStorage.setItem('mc_loginLogs',JSON.stringify(logs.slice(0,100))); localStorage.setItem('mc_currentUser',JSON.stringify(found));currentUser=found;document.getElementById('loginMsg').innerText='';checkAuth();checkPaywall();render();backupNowSilent(); } function resetDefaultLogin(){users=[{username:'matron',password:'matron123',role:'matron',displayName:'Matron'}];localStorage.setItem('mc_users',JSON.stringify(users));localStorage.removeItem('mc_currentUser');currentUser=null;document.getElementById('loginMsg').innerText='Reset done! Now login: matron / matron123';checkAuth();} function doLogout(){localStorage.removeItem('mc_currentUser');currentUser=null;document.getElementById('loginScreen').style.display='flex';document.getElementById('paywall').style.display='none';} function showPaywall(){document.getElementById('loginScreen').style.display='none';document.getElementById('paywall').style.display='flex';} function hidePaywall(){document.getElementById('paywall').style.display='none';document.getElementById('loginScreen').style.display='flex';} function checkPaywall(){if(isPro){document.getElementById('paywall').style.display='none';}else if(patients.length>=5 && currentUser){document.getElementById('paywall').style.display='flex';}} function useFree(){document.getElementById('paywall').style.display='none';if(!currentUser){document.getElementById('loginScreen').style.display='flex';} } function payMonthly(){const email=document.getElementById('payEmail').value.trim();const name=document.getElementById('payName').value.trim();if(!email||!name){document.getElementById('payMsg').innerText='Enter Email and Clinic';return;}let h=PaystackPop.setup({key:PAYSTACK_KEY,email,amount:500000,currency:"NGN",ref:"MC-MONTHLY-"+Date.now(),callback:function(r){localStorage.setItem('mc_pro','true');localStorage.setItem('mc_plan','monthly');localStorage.setItem('mc_clinic',name);alert('Monthly Active '+r.reference);hidePaywall();location.reload();},onClose:function(){}});h.openIframe();} function payLifetime(){const email=document.getElementById('payEmail').value.trim();const name=document.getElementById('payName').value.trim();if(!email||!name){document.getElementById('payMsg').innerText='Enter Email and Clinic';return;}let h=PaystackPop.setup({key:PAYSTACK_KEY,email,amount:2500000,currency:"NGN",ref:"MC-LIFETIME-"+Date.now(),callback:function(r){localStorage.setItem('mc_pro','true');localStorage.setItem('mc_plan','lifetime');localStorage.setItem('mc_clinic',name);alert('Lifetime Unlocked '+r.reference);hidePaywall();location.reload();},onClose:function(){}});h.openIframe();} function switchTab(t){['patients','money','scan','qr','settings','backup'].forEach(x=>document.getElementById('tab-'+x).style.display=x===t?'block':'none');if(t==='qr') populateQRSelect();} function calcEDD(lmpStr){if(!lmpStr) return null;const lmp=new Date(lmpStr);const edd=new Date(lmp.getTime()+280*24*60*60*1000);const anc1=new Date(lmp.getTime()+84*24*60*60*1000);const anc2=new Date(lmp.getTime()+182*24*60*60*1000);return {edd:edd.toLocaleDateString(),anc1:anc1.toLocaleDateString(),anc2:anc2.toLocaleDateString(),eddDate:edd}} document.getElementById('pLMP').addEventListener('change',function(){const c=calcEDD(this.value);if(c){document.getElementById('eddDisplay').innerText='📅 EDD: '+c.edd+' | ANC1: '+c.anc1+' | ANC2: '+c.anc2;}}); function addPatient(){const name=document.getElementById('pName').value.trim();if(!name) return alert('Name needed');if(!isPro && patients.length>=5){showPaywall();return;}const note=document.getElementById('pNote').value;let amt=0;const m=note.match(/(\d+)k/i);if(m) amt=parseInt(m[1])*1000;else{const m2=note.match(/(\d{3,})/);if(m2) amt=parseInt(m2[1]);}const lmp=document.getElementById('pLMP').value;const eddInfo=lmp?calcEDD(lmp):null;const qrId='MC-'+Date.now().toString().slice(-6);patients.unshift({id:Date.now(),qrId,name,age:document.getElementById('pAge').value,phone:document.getElementById('pPhone').value,lmp,edd:eddInfo?eddInfo.edd:'',eddDate:eddInfo?eddInfo.eddDate:'',note,amount:amt,date:new Date().toLocaleDateString(),staff:currentUser?currentUser.displayName:staffNames.matron});if(amt>0) payments.unshift({name,amount:amt,date:new Date().toLocaleDateString(),staff:currentUser?currentUser.displayName:''});localStorage.setItem('mc_patients',JSON.stringify(patients));localStorage.setItem('mc_payments',JSON.stringify(payments));['pName','pAge','pPhone','pNote','pLMP'].forEach(id=>document.getElementById(id).value='');document.getElementById('eddDisplay').innerText='✅ Saved '+name+' QR:'+qrId;render();backupNowSilent();} function saveStaffNames(){staffNames.matron=document.getElementById('setMatronName').value||'Matron';staffNames.nurse1=document.getElementById('setNurse1Name').value||'Nurse 1';staffNames.nurse2=document.getElementById('setNurse2Name').value||'Nurse 2';staffNames.nurse3=document.getElementById('setNurse3Name').value||'Nurse 3';localStorage.setItem('mc_staffNames',JSON.stringify(staffNames));users=users.map(u=>{if(u.role==='matron') u.displayName=staffNames.matron;if(u.role==='nurse1') u.displayName=staffNames.nurse1;if(u.role==='nurse2') u.displayName=staffNames.nurse2;if(u.role==='nurse3') u.displayName=staffNames.nurse3;return u;});localStorage.setItem('mc_users',JSON.stringify(users));if(currentUser){const upd=users.find(x=>x.username===currentUser.username);if(upd){currentUser=upd;localStorage.setItem('mc_currentUser',JSON.stringify(upd));}}alert('Saved');checkAuth();render();} function renderStaffInputs(){document.getElementById('setMatronName').value=staffNames.matron;document.getElementById('setNurse1Name').value=staffNames.nurse1;document.getElementById('setNurse2Name').value=staffNames.nurse2;document.getElementById('setNurse3Name').value=staffNames.nurse3;} function saveUser(){const u=document.getElementById('newUser').value.trim().toLowerCase();const p=document.getElementById('newPass').value.trim();const r=document.getElementById('newRole').value;if(!u||!p) return alert('Username+pass needed');const idx=users.findIndex(x=>x.username===u);const display=staffNames[r]||r;if(idx>=0) users[idx]={username:u,password:p,role:r,displayName:display};else users.push({username:u,password:p,role:r,displayName:display});localStorage.setItem('mc_users',JSON.stringify(users));document.getElementById('newUser').value='';document.getElementById('newPass').value='';renderUsers();alert('User '+u+' created');} function renderUsers(){document.getElementById('userList').innerHTML=users.map(u=>`
${u.username} • ${u.role} • ${u.displayName}
`).join('');} function sendWhatsAppReceipt(p){const msg=`MamaCare Receipt%0AClinic: ${localStorage.getItem('mc_clinic')||'MamaCare'}%0APatient: ${p.name}%0AService: ${p.note}%0AAmount: NGN ${p.amount}%0ADate: ${p.date}%0AStaff: ${p.staff}%0A${p.edd?'EDD: '+p.edd:''}%0AThank you!`;const phone=p.phone? p.phone.replace(/[^0-9]/g,'') : '';const url=phone? `https://wa.me/234${phone.slice(-10)}?text=${msg}` : `https://wa.me/?text=${msg}`;window.open(url,'_blank');} function populateQRSelect(){document.getElementById('qrPatientSelect').innerHTML=patients.map(p=>``).join('');} function generateQR(){const qrId=document.getElementById('qrPatientSelect').value;const pat=patients.find(x=>x.qrId===qrId);if(!pat) return alert('Select patient');document.getElementById('qrCode').innerHTML='';new QRCode(document.getElementById('qrCode'),{text:JSON.stringify({id:pat.qrId,name:pat.name,phone:pat.phone,edd:pat.edd}),width:180,height:180});document.getElemhtml5QrC