PREVENTATIVE CARE MANAGEMENT PLAN
const drillNames=[...explored].map(k=>DRILL[k]?.[0]||(k.startsWith('sp-')?supports[Number(k.slice(3))][0]:k)).join(', '); const rows=[['Program','PCMP — Level Five Health Plus Preventive Care Management Plan'],['Company',d.company],['Contact',d.name],['Title',d.title||'Not provided'],['Email',d.email],['Phone',d.phone||'Not provided'],['Business address',d.address||'Not provided'],['Preferred contact',contactPref||'Not selected'],['Others to include',[...stakeholders].join(', ')||'Not selected'],['Estimated eligible employees',d.employees],['Employee criterion','Full-time W-2, 30+ hours/week; final eligibility subject to review'],['Perspective',role==='advisor'?'Advisor / Consultant':'Employer'],['Interested in saving payroll taxes / bottom line',qa1||'Not answered'],['Importance of employee & family well-being',qa2||'Not answered'],['Priority',priority||'Not selected'],['Fit check',fit+(Object.values(fitAns).some(Boolean)?' → '+verdict().h:'')],['Most valued support',[...favorites].join(', ')||'None marked'],['Launch timing',timing||'Not selected'],['Participation illustration',pct+'%'],['Illustrative annual net employer savings',money(e.low)+'–'+money(e.high)],['Opener quick check',quickCount!=null?quickCount+' employees':'Not used'],['Chapters viewed',CHAPTERS.filter(c=>visited.has(c[0])).map(c=>c[1]).join(', ')],['Details explored',drillNames||'None'],['Visitor question / note',d.question||'None'],['Source','OnPoint website — PCMP interactive presentation'],['Request reference',a.reference],['Submitted at',a.created]]; return'
PCMP company-review request
'+rows.map(([k,v])=>''+esc(k)+': '+esc(v)).join('
')+'
Visitor asked OnPoint to contact them about a company review. Financial figures are planning illustrations, not deal revenue or guaranteed savings.
'}async function createLead(d,a){ // Resolve the actual PCMP pipeline before creating any records. Never fall back to Cost Segregation. if(!a.pipeline){const ps=await crmList('/pipelines');a.pipeline=selectPipeline(ps);a.stage=selectStage(await crmList('/stages?pipeline_id='+a.pipeline.id),a.pipeline.id)} if(!a.orgId){const found=await crmRequest('/organizations/search?term='+encodeURIComponent(d.company)+'&fields=name&exact_match=true');let m=(found?.items||[]).map(v=>v.item).filter(x=>normalize(x.name)===normalize(d.company));if(m.length===1)a.orgId=m[0].id;else{let o=await crmRequest('/organizations','POST',{name:d.company});if(!o?.id)throw new Error('Organization not confirmed');a.orgId=o.id}} if(!a.personId){const found=await crmRequest('/persons/search?term='+encodeURIComponent(d.email)+'&fields=email&exact_match=true');let m=(found?.items||[]).map(v=>v.item).filter(x=>{let em=(x.emails||x.email||[]);if(!Array.isArray(em))em=[em];return em.some(e=>normalize(typeof e==='string'?e:e.value)===normalize(d.email))&&Number(x.organization?.id||x.org_id?.value||x.org_id)===Number(a.orgId)});if(m.length===1)a.personId=m[0].id;else{let data={name:d.name,org_id:a.orgId,email:[{value:d.email,primary:true,label:'work'}]};if(d.phone)data.phone=[{value:d.phone,primary:true,label:'work'}];let p=await crmRequest('/persons','POST',data);if(!p?.id)throw new Error('Contact not confirmed');a.personId=p.id}} if(!a.dealId){const found=await crmRequest('/deals/search?term='+encodeURIComponent(a.title)+'&fields=title&exact_match=true');let m=(found?.items||[]).map(v=>v.item).filter(x=>x.title===a.title);if(m.length>1)throw new Error('Ambiguous submission receipt');if(m.length===1)a.dealId=m[0].id;else{let fields=[];try{fields=await crmList('/dealFields')}catch{}let data=applyPcmpFields({title:a.title,org_id:a.orgId,person_id:a.personId,pipeline_id:a.pipeline.id,stage_id:a.stage.id,status:'open'},fields,Number(d.employees));let deal=await crmRequest('/deals','POST',data);if(!deal?.id)throw new Error('Deal not confirmed');a.dealId=deal.id}} if(!a.noteSaved){if(a.noteTried){let notes=await crmList('/notes?deal_id='+a.dealId);if(notes.some(n=>String(n.content||'').includes(a.reference)))a.noteSaved=true}if(!a.noteSaved){a.noteTried=true;let note=await crmRequest('/notes','POST',{deal_id:a.dealId,content:noteForLead(d,a),pinned_to_deal_flag:1});if(!note?.id)throw new Error('Request details not confirmed');a.noteSaved=true}} return{reference:a.reference,dealId:a.dealId};}async function submitLead(e){ e.preventDefault();if(submitting||leadReceipt)return;const form=e.target; if(!form.checkValidity()){form.reportValidity();setStatus('Please complete the required fields marked *.',true);return} const d=Object.fromEntries(new FormData(form).entries());if(d.website)return; for(const k of['company','name','title','email','phone','address','question'])d[k]=String(d[k]||'').trim(); if(!d.company||!d.name||!d.email||!d.phone||d.employees===''||!Number.isInteger(Number(d.employees))||Number(d.employees)<0||Number(d.employees)>1000000){setStatus('Please provide your company, contact details and a whole-number employee estimate.',true);return} leadDraft=d;const identity=JSON.stringify([normalize(d.company),normalize(d.name),normalize(d.email)]); if(crmAttempt&&crmAttempt.identity!==identity&&crmAttempt.dealId){setStatus('Part of your earlier request was received. Restore the original company and contact details, then retry to finish it.',true);return} if(!crmAttempt||crmAttempt.identity!==identity){const b=new Uint32Array(3);crypto.getRandomValues(b);const ref='PCMP-'+Array.from(b,n=>n.toString(16).padStart(8,'0')).join('');crmAttempt={reference:ref,created:new Date().toISOString(),identity,title:'PCMP — '+d.company+' — '+ref.slice(-8)}} submitting=true;const btn=$('submitLeadBtn');btn.disabled=true;btn.textContent='Sending your request…';setStatus('Connecting with OnPoint…'); try{leadReceipt=await createLead(d,crmAttempt);$('leadCard').classList.add('sent');setStatus('Thank you — your request has been received. An OnPoint Preventive Care Management Plan specialist will reach out to answer your questions and coordinate next steps. We appreciate the opportunity to be of service. Reference: '+leadReceipt.reference);if(audioOn)speakText('Thank you'+(first()?', '+first():'')+'. Your request is on its way. An OnPoint Preventive Care Management Plan specialist will reach out to answer your questions and coordinate everything'+(coName()?' for '+coName():'')+' going forward'+({'As soon as possible':', with your goal of moving as soon as possible in mind','Within 90 days':', with your ninety-day timeline in mind','Next plan year':', with your plan-year timeline in mind'}[timing]||'')+'. We appreciate the opportunity to be of service.')} catch{setStatus(crmAttempt?.dealId?'Your request reached OnPoint, but some details didn\'t attach. Select Retry to finish.':'Your request didn\'t go through. Please retry, or email solutions@onpointfast.com. Your entries are still here.',true);btn.textContent='Retry'} finally{submitting=false;btn.disabled=false}} /* ---------- Keyboard ---------- */addEventListener('keydown',e=>{ if($('modal').open||['INPUT','SELECT','TEXTAREA'].includes(e.target.tagName))return; if(e.target.getAttribute?.('role')==='tab'&&['ArrowLeft','ArrowRight','ArrowUp','ArrowDown'].includes(e.key)){e.preventDefault();selectSupport((supportIndex+(e.key==='ArrowRight'||e.key==='ArrowDown'?1:5))%6,true);return} if(e.key==='ArrowRight'&&page!=='welcome'&&page!=='review'){e.preventDefault();next()} if(e.key==='ArrowLeft'){e.preventDefault();back()}});document.addEventListener('visibilitychange',()=>{if(document.hidden){stopSpeech();audioOn=false;chrome()}});addEventListener('pagehide',stopSpeech);render();setTimeout(()=>{if(page==='welcome'&&audioOn&&!speaking&&!hasHC)speakSlide()},700);
