PageSourceSearch

https://tire-track-loyalty-3a0d7f0a.base44.app/assets/CustomerFinancing-CZK_RtXq.js

js tire-track-loyalty-3a0d7f0a.base44.app collected 2026-10-03 03:12:02 UTC 17,680 bytes, 1 lines download raw bytes

1import{r as u,j as e,u as z,b as D,c as O,L as K}from"./index-DdU35jPJ.js";import{c as G}from"./index-CtlYlah8.js";import{h}from"./moment-BLMuvzoS.js";import{o as L}from"./financingOptions-CIAN_Bce.js";import{T as H}from"./triangle-alert-l3tEQyle.js";import{C as $}from"./calendar-WJIH9OsN.js";import{C as Q}from"./clock-D8ofwCOI.js";import{C as V}from"./chevron-up-w1zviHLx.js";import{C as J}from"./chevron-down-DcLGbHop.js";import{F as X}from"./file-text-BIInLmy-.js";import{D as Z}from"./download-BAHbJTmZ.js";import{B as ee}from"./button-BfxMpK8P.js";import{u as te}from"./fuelMemberContext-CrT88XzT.js";import{w as ae}from"./uiAsync-Br22hwGx.js";import{c as ne}from"./customerScrollSurface-DvPzgNAk.js";import{A as se}from"./arrow-left-CoQakR5q.js";import{C as P}from"./credit-card-BsmBHB--.js";import"./createLucideIcon-DMxicyrC.js";import"./index-gN4drEn4.js";import"./index-Dp3B9jqt.js";import"./clsx-B-dksMZM.js";import"./utils-DCmAa5as.js";import"./bundle-mjs-BTmSotT-.js";const C=t=>`$${(t||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function le({f:t,fullSchedule:s,isToday:a,expanded:n,setExpanded:r,totalWksCeil:c}){const d=u.useId(),o=s.filter(l=>!l.isPaid&&!l.isMissed).slice(0,3);return e.jsxs("div",{className:"border-t border-[#F1F5F9]",children:[e.jsxs("div",{"data-financing-anchor":`next:${t.id}`,className:"p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-slate-400 font-semibold mb-2",children:"Next Payment"}),e.jsxs("div",{className:`flex items-center gap-3 p-3.5 rounded-xl ${a?"bg-amber-50 border border-amber-200":"bg-slate-50 border border-[#E5E7EB]"}`,children:[a?e.jsx(H,{className:"w-5 h-5 text-amber-500 shrink-0"}):e.jsx($,{className:"w-5 h-5 text-slate-400 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-sm font-semibold ${a?"text-amber-800":"text-[#17213A]"}`,children:a?"Payment due today":t.next_payment_date?h(t.next_payment_date).format("dddd, MMM D, YYYY"):"—"}),e.jsxs("p",{className:`text-xs ${a?"text-amber-600":"text-slate-400"}`,children:[C(t.weekly_payment)," weekly"]})]})]}),o.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-slate-400 font-semibold mb-2",children:"Upcoming Payments"}),e.jsx("div",{className:"space-y-2",children:o.map(l=>{var i;return e.jsxs("div",{className:"th-financing-upcoming flex items-center justify-between px-3 py-2 rounded-xl bg-slate-50 border border-[#E5E7EB]",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx($,{className:"w-3.5 h-3.5 text-slate-400 shrink-0"}),e.jsx("span",{className:"text-sm text-[#17213A] truncate",children:h(l.scheduledDate).format("MMM D, YYYY")}),l.isNext&&e.jsx("span",{className:"text-xs bg-amber-100 text-amber-700 px-1.5 py-0.5 rounded-full font-semibold shrink-0",children:"Next"})]}),e.jsx("span",{className:"text-sm font-semibold text-[#17213A] shrink-0",children:C(((i=l.recorded)==null?void 0:i.amount)||t.weekly_payment)})]},l.weekNum)})})]})]}),s.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","data-financing-anchor":`schedule:${t.id}`,"aria-expanded":n,"aria-controls":n?d:void 0,onClick:()=>r(!n),className:"th-financing-schedule-toggle w-full flex items-center justify-between px-5 py-3 border-t border-[#F1F5F9] text-sm font-medium text-slate-500 hover:bg-slate-50 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Full Payment Schedule (",t.weeks_paid||0," of ",c," paid)"]}),n?e.jsx(V,{className:"w-4 h-4"}):e.jsx(J,{className:"w-4 h-4"})]}),n&&e.jsx("div",{id:d,className:"th-financing-schedule border-t border-[#F1F5F9] max-h-80 overflow-y-auto",children:e.jsxs("table",{role:"table","aria-label":"Full payment schedule",className:"w-full text-sm",children:[e.jsx("thead",{role:"rowgroup",className:"sticky top-0 bg-white border-b border-[#F1F5F9]",children:e.jsxs("tr",{role:"row",children:[e.jsx("th",{role:"columnheader",scope:"col",className:"text-left px-5 py-2 text-xs font-semibold text-slate-400 uppercase",children:"Week"}),e.jsx("th",{role:"columnheader",scope:"col",className:"text-left px-5 py-2 text-xs font-semibold text-slate-400 uppercase",children:"Date"}),e.jsx("th",{role:"columnheader",scope:"col",className:"text-right px-5 py-2 text-xs font-semibold text-slate-400 uppercase",children:"Amount"}),e.jsx("th",{role:"columnheader",scope:"col",className:"text-center px-5 py-2 text-xs font-semibold text-slate-400 uppercase",children:"Status"})]})}),e.jsx("tbody",{role:"rowgroup",className:"divide-y divide-[#F8FAFC]",children:s.map(l=>{var i;return e.jsxs("tr",{role:"row","data-financing-anchor":`payment:${t.id}:${l.weekNum}`,className:`${l.isNext?"bg-amber-50":l.isPaid?"bg-emerald-50/40":""}`,children:[e.jsxs("td",{role:"cell","data-label":"Week",className:"px-5 py-2.5 text-slate-600 font-medium",children:["# ",l.weekNum,l.isNext&&e.jsx("span",{className:"ml-1 text-xs bg-amber-100 text-amber-700 px-1.5 py-0.5 rounded-full font-semibold",children:"Next"})]}),e.jsx("td",{role:"cell","data-label":"Date",className:"px-5 py-2.5 text-slate-600",children:h(l.scheduledDate).format("MMM D, YYYY")}),e.jsx("td",{role:"cell","data-label":"Amount",className:"px-5 py-2.5 text-right font-semibold text-[#17213A]",children:C(((i=l.recorded)==null?void 0:i.amount)||t.weekly_payment)}),e.jsx("td",{role:"cell","data-label":"Status",className:"px-5 py-2.5 text-center",children:e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full font-medium ${l.isPaid?"bg-emerald-100 text-emerald-700":l.isMissed?"bg-red-100 text-red-700":l.isNext?"bg-amber-100 text-amber-700":"bg-slate-100 text-slate-500"}`,children:l.isPaid?"Paid":l.isMissed?"Missed":l.isNext?"Due Next":"Scheduled"})})]},l.weekNum)})})]})})]})]})}const M=t=>
1`$${(t||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,ie={financing_agreement:"Financing Agreement",customer_id:"Customer ID",customer_authorization:"Customer Authorization",void_check:"Voided Check",bank_document:"Bank Document",other:"Document"};function re({f:t}){const s=(t.documents||[]).filter(n=>n.file_url),a=[{label:"Plan",value:t.financing_option?L(t.financing_option):"—"},{label:"Amount Financed",value:M(t.financed_amount)},{label:"Weekly Payment",value:M(t.weekly_payment)},{label:"Term",value:t.total_weeks?`${Math.ceil(t.total_weeks)} weeks`:"—"},{label:"Down Payment",value:M(t.down_payment)},{label:"First Payment",value:t.first_payment_date?h(t.first_payment_date).format("MMM D, YYYY"):"—"}];return e.jsxs("div",{"data-financing-anchor":`contract:${t.id}`,className:"th-financing-contract border-t border-[#F1F5F9] p-5",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-slate-400 font-semibold mb-3",children:"Contract Summary"}),e.jsx("div",{className:"th-financing-contract-rows grid grid-cols-2 gap-x-4 gap-y-2.5",children:a.map(n=>e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-slate-400 shrink-0",children:n.label}),e.jsx("span",{className:"text-xs font-semibold text-[#17213A] text-right truncate",children:n.value})]},n.label))}),s.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-xs text-slate-400 mb-2",children:"Documents"}),e.jsx("div",{className:"space-y-2",children:s.map((n,r)=>e.jsxs("a",{href:n.file_url,target:"_blank",rel:"noreferrer",className:"th-financing-document flex items-center gap-2 px-3 py-2 rounded-xl border border-[#E5E7EB] hover:border-[#2563EB]/30 hover:bg-[#2563EB]/5 transition-colors",children:[e.jsx(X,{className:"w-4 h-4 text-[#2563EB] shrink-0"}),e.jsx("span",{className:"text-sm text-[#17213A] flex-1 min-w-0 truncate",children:ie[n.doc_type]||n.file_name||"Document"}),e.jsx(Z,{className:"w-4 h-4 text-slate-400 shrink-0"})]},n.id||r))})]})]})}const j=t=>`$${(t||0).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,B={current:{label:"Current",bg:"bg-emerald-50",text:"text-emerald-700",dot:"bg-emerald-500"},late:{label:"Late",bg:"bg-amber-50",text:"text-amber-700",dot:"bg-amber-500"},delinquent:{label:"Delinquent",bg:"bg-orange-50",text:"text-orange-700",dot:"bg-orange-500"},default:{label:"Default",bg:"bg-red-50",text:"text-red-700",dot:"bg-red-500"}},ce={active:{label:"Active",bg:"bg-emerald-50",text:"text-emerald-700",dot:"bg-emerald-500"},paused:{label:"Paused",bg:"bg-slate-100",text:"text-slate-600",dot:"bg-slate-400"},completed:{label:"Completed",bg:"bg-blue-50",text:"text-blue-700",dot:"bg-blue-500"},defaulted:{label:"Defaulted",bg:"bg-red-50",text:"text-red-700",dot:"bg-red-500"},cancelled:{label:"Cancelled",bg:"bg-slate-100",text:"text-slate-500",dot:"bg-slate-400"}};function de({f:t,customer:s,payments:a,expanded:n,onExpandedChange:r}){const[c,d]=u.useState(!1),o=n??c,l=r||d,i=t.total_weeks||52.143,m=Math.ceil(i),x=Math.min(100,Math.round((t.weeks_paid||0)/i*100)),b=a.filter(p=>p.financing_order_id===t.id).sort((p,_)=>(p.scheduled_date||"").localeCompare(_.scheduled_date||"")),N=h().format("YYYY-MM-DD"),f=t.next_payment_date===N,y=t.installation_date||(t.created_date?h(t.created_date).format("YYYY-MM-DD"):null),A=t.first_payment_date,I=A?Array.from({length:m},(p,_)=>{const E=_+1;let F=h(A).add(_*7,"days");for(;F.day()===0||F.day()===6;)F.add(1,"day");const Y=F.format("YYYY-MM-DD"),k=b.find(q=>q.week_number===E),T=h().format("YYYY-MM-DD"),S=(k==null?void 0:k.status)==="completed"||E<=(t.weeks_paid||0),U=!S&&Y<T,W=Y===t.next_payment_date;return{weekNum:E,scheduledDate:Y,recorded:k,isPaid:S,isMissed:U,isNext:W}}):[],w=B[t.payment_status]||B.current,v=ce[t.status]||{label:t.status,bg:"bg-slate-100",text:"text-slate-600",dot:"bg-slate-400"},R=[{label:"Amount Financed",value:j(t.financed_amount)},{label:"Amount Paid",value:j(t.total_collected)},{label:"Remaining Balance",value:j(t.remaining_balance)},{label:"Weekly Payment",value:j(t.weekly_payment)}];return e.jsxs("div",{className:"th-financing-agreement bg-white rounded-2xl border border-[#
1E5E7EB] shadow-sm overflow-hidden",children:[e.jsxs("div",{"data-financing-anchor":`agreement:${t.id}`,className:"p-5 border-b border-[#F1F5F9]",children:[e.jsxs("div",{className:"th-financing-heading flex items-start justify-between gap-3 mb-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-bold text-[#17213A] text-lg",children:t.customer_name||(s==null?void 0:s.company_name)}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5",children:y?`Started ${h(y).format("MMM D, YYYY")}`:"Agreement"}),t.financing_option&&e.jsx("span",{className:"mt-2 inline-flex items-center text-xs px-2.5 py-1 rounded-full font-semibold bg-[#2563EB]/10 text-[#2563EB]",children:L(t.financing_option)})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1.5 shrink-0",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-full font-semibold ${v.bg} ${v.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${v.dot}`}),v.label]}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 text-xs px-2.5 py-1 rounded-full font-semibold ${w.bg} ${w.text}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${w.dot}`}),w.label]})]})]}),e.jsxs("div",{className:"th-financing-balance-layout flex items-end justify-between gap-3 mb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-slate-400 font-semibold mb-1",children:"Remaining Balance"}),e.jsx("p",{className:"th-financing-balance text-[#17213A] text-4xl font-bold tracking-tight",children:j(t.remaining_balance)})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsxs("p",{className:"text-xs text-slate-400",children:[t.weeks_paid||0," of ",m," weeks"]}),e.jsxs("p",{className:"text-sm font-bold text-[#2563EB]",children:[x,"% complete"]})]})]}),e.jsx("div",{className:"w-full bg-slate-100 rounded-full h-2.5",children:e.jsx("div",{className:"th-financing-progress bg-[#2563EB] h-2.5 rounded-full transition-all",style:{width:`${x}%`}})})]}),e.jsx("div",{"data-financing-anchor":`stats:${t.id}`,className:"th-financing-stats grid grid-cols-2 gap-px bg-[#F1F5F9]",children:R.map(p=>e.jsxs("div",{className:"bg-white p-4",children:[e.jsx("p",{className:"text-xs text-slate-400 mb-1",children:p.label}),e.jsx("p",{className:"text-lg font-bold text-[#17213A]",children:p.value})]},p.label))}),e.jsx(le,{f:t,fullSchedule:I,isToday:f,expanded:o,setExpanded:l,totalWksCeil:m}),e.jsx(re,{f:t})]})}async function oe(t){let s=t!=null&&t.id?await D.entities.Customer.filter({auth_user_id:t.id}):[];!s.length&&(t!=null&&t.email)&&(s=await D.entities.Customer.filter({user_email:t.email}));const a=s[0];if(!a)throw new Error("Your financing account could not be loaded. Please retry.");const[n,r]=await Promise.all([D.entities.FinancingOrder.filter({customer_id:a.id},"-created_date",50),D.entities.FinancingPayment.filter({customer_id:a.id},"-scheduled_date",500)]);return{customer:a,financing:n,payments:r}}function me(t){var n;const s=String((t==null?void 0:t.id)||(t==null?void 0:t.email)||"").trim().toLowerCase(),a=z({queryKey:["customer-financing",s,(t==null?void 0:t.email)||""],queryFn:()=>ae(oe(t),"Financing took too long to load. Please retry."),enabled:!!s,staleTime:6e4,gcTime:3e5,retry:!1,refetchOnWindowFocus:!0});return{data:a.data,loading:a.isPending,refreshing:a.isFetching,error:a.isError?((n=a.error)==null?void 0:n.message)||"Financing could not be loaded. Please retry.":"",refresh:a.refetch}}const g=new Map;function xe(t,s=Date.now()){const a=t?g.get(t):null;return!a||s-a.savedAt>=18e5?(g.delete(t),null):a}function ue(t,s,a=Date.now()){t&&(g.delete(t),g.set(t,{y:s.y,anchor:s.anchor,expandedIds:[...s.expandedIds||[]],savedAt:a}),g.size>8&&g.delete(g.keys().next().value))}function he({active:t,ownerKey:s,ready:a}){const n=u.useRef(null),r=u.useRef(null),c=s,d=u.useMemo(()=>xe(s),[s]),[o,l]=u.useState((d==null?void 0:d.expandedIds)||[]),i=u.useRef(o);return i.current=o,u.useLayoutEffect(()=>{if(!t||!a||!c||!n.current)return;
1const m=n.current,x=ne(m,!0,window,{anchorAttribute:"data-financing-anchor",stickySelector:null,minAnchorVisible:64});return r.current!==c&&(x.restore({y:0}),r.current=c),()=>{ue(c,{...x.capture(),expandedIds:i.current})}},[t,c,a]),u.useLayoutEffect(()=>{if(!t){r.current=null;return}return document.documentElement.classList.add("th-member-financing-open"),document.body.classList.add("th-member-financing-open"),()=>{document.documentElement.classList.remove("th-member-financing-open"),document.body.classList.remove("th-member-financing-open")}},[t]),{expandedIds:o,setExpanded:(m,x)=>l(b=>x?[...new Set([...b,m])]:b.filter(N=>N!==m)),surface:{ref:n,className:t?"th-member-financing-feed":"",role:t?"region":void 0,"aria-label":t?"Financing feed":void 0,tabIndex:t?0:void 0}}}function Re(){const{user:t}=O(),{active:s}=te(),a=String((t==null?void 0:t.id)||(t==null?void 0:t.email)||"").trim().toLowerCase();return e.jsx(pe,{user:t,ownerKey:a,fuelMember:s},a)}function pe({user:t,ownerKey:s,fuelMember:a}){const{data:n,loading:r,error:c,refreshing:d,refresh:o}=me(t),{customer:l=null,financing:i=[],payments:m=[]}=n||{},{surface:x,expandedIds:b,setExpanded:N}=he({active:a,ownerKey:s,ready:!!n});return e.jsx("div",{...x,className:`th-customer-scroll-surface min-h-screen bg-[#f8f9fc] ${x.className}`,children:e.jsxs("div",{"data-financing-content":!0,className:"mx-auto max-w-2xl px-3 pb-24 pt-4 sm:px-6 sm:py-6",children:[e.jsxs(K,{to:G("CustomerDashboard"),
1className:"inline-flex items-center gap-2 text-slate-400 hover:text-[#17213A] text-sm mb-4 transition-colors",children:[e.jsx(se,{className:"w-4 h-4"})," Back"]}),e.jsxs("div",{"data-financing-anchor":"heading",className:"flex items-start gap-3 mb-5",children:[e.jsx("div",{className:"th-financing-heading-icon w-11 h-11 rounded-2xl bg-[#2563EB] flex items-center justify-center shadow-sm shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold text-[#17213A]",children:"My Financing"}),e.jsx("p",{className:"text-slate-400 text-sm",children:(l==null?void 0:l.company_name)||(t==null?void 0:t.full_name)||"Your financing agreements"})]})]}),c&&e.jsxs("div",{role:"status",className:"mb-5 rounded-2xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900",children:[e.jsx("p",{children:n?"Your financing could not be refreshed. Showing the last loaded details.":c}),e.jsx(ee,{variant:"outline",onClick:()=>o(),disabled:d,className:"mt-2",children:d?"Retrying…":"Retry financing"})]}),r&&e.jsxs("div",{role:"status","aria-label":"Loading financing",className:"space-y-4",children:[e.jsx("div",{className:"th-loading-skeleton h-52 rounded-2xl"}),e.jsx("div",{className:"th-loading-skeleton h-48 rounded-2xl"})]}),n&&(i.length===0?e.jsxs("div",{className:"bg-white rounded-2xl border border-[#E5E7EB] shadow-sm p-8 text-center",children:[e.jsx("div",{className:"w-14 h-14 bg-slate-50 rounded-2xl flex items-center justify-center mx-auto mb-3",children:e.jsx(P,{className:"w-6 h-6 text-slate-300"})}),e.jsx("p",{className:"text-[#17213A] font-semibold text-sm",children:"No financing agreements"}),e.jsx("p",{className:"text-slate-400 text-xs mt-1",children:"When you finance an order with Truck Haters, your agreement and payment schedule will appear here."})]}):e.jsx("div",{className:"space-y-5",children:i.map(f=>e.jsx(de,{f,customer:l,payments:m,expanded:a?b.includes(f.id):void 0,onExpandedChange:a?y=>N(f.id,y):void 0},f.id))}))]})})}export{Re as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.