PageSourceSearch

https://care.soberpedia.ai/assets/BusinessOrderDetailsModal-DTAC4JnJ.js

js soberpedia.ai collected 2026-10-05 15:07:57 UTC 16,026 bytes, 1 lines download raw bytes

1import{r,j as e,c as Te}from"./react-vendor-CU6Sz31W.js";import{eo as Ie,u as Be,al as De,eD as Pe,gY as $e,t as o,b as Me,gZ as ze,g_ as h,L as q,I as Ee,U as ue,i as p,c7 as Fe,c8 as Ve,c9 as He,ca as Ye,cb as qe,bY as Oe,z as We,g$ as Ge,eM as Xe,bb as Ze,at as Je,S as Ke}from"./index-DEXJEDAi.js";import{u as Qe}from"./usePatientTerminology-D5bkkKg2.js";import{u as Ue}from"./useBusinessTagDefinitions-BOOODPmJ.js";import{B as es,A as ss,c as ts}from"./BusinessTagPicker-L3PG9Oa0.js";import{B as as}from"./BusinessEntityDrawer-BK69K0NF.js";import{B as de}from"./BusinessState-DD1p_okQ.js";import{b as ns,c as b}from"./businessSalesApi-_pXRaGVq.js";import{o as me,f as pe}from"./salesFormat-DgGRPsY8.js";import{a as fe}from"./servicePricing-BPZAE8eG.js";import{w as is}from"./orderDeepLink-1Gq1AblN.js";import"./firebase-w6DYUbFN.js";import"./payment-icons-Daq1K3F1.js";import"./businessTagsApi-BWZKtrAp.js";import"./table-CxPdvV_9.js";import"./activity-timeline-LcjxVO4l.js";import"./chartPalette-CFmN-0p5.js";import"./ellipsis-C0FvDuxB.js";import"./CreateBusinessTagDialog-arE4ac7H.js";import"./businessTagEmojiCatalog-DyuQVEw_.js";import"./BusinessSubnav-CJbjo38o.js";const ls=["pending","paid","closed","refunded","partially_refunded","cancelled"],rs={account_credit_purchase:"Credits",product:"Product",package:"Package",membership:"Membership",gratuity:"Tip"};function he(a){return rs[String(a||"").toLowerCase()]||""}function xe(a){return String((a==null?void 0:a.kind)||(a==null?void 0:a.type)||"").toLowerCase()==="deposit"}function os(a){if(xe(a))return"Deposit applied";const c=String(a.method||a.type||"card").toLowerCase();if(c==="account_credit"||c==="credit")return"Account balance";if(c==="gift_card")return`Gift card${a.giftCardId?` (${String(a.giftCardId).slice(0,8)}…)`:""}`;if(c==="cash")return"Cash";if(c==="other")return a.note?`Other — ${a.note}`:"Other";const u=a.cardBrand||a.brand||"Card",l=a.last4||a.cardLast4||"",f=a.expMonth&&a.expYear?`${String(a.expMonth).padStart(2,"0")}/${String(a.expYear).slice(-2)}`:"";return`${u}${l?` ${l}`:""}${f?` ${f}`:""}`.trim()||"Payment"}function P(a){return(a==null?void 0:a.orderNumber)!=null?`Order #${a.orderNumber}`:a!=null&&a.id?`Order ${a.id.slice(0,8)}…`:"Order"}function cs({open:a,onOpenChange:c,orderId:u,onOrderUpdated:l}){var re,oe;const f=Ie(),{singular:be}=Qe(),{userType:O,userDoc:$}=Be(),{branding:M}=De(),{locations:W}=Pe(),{can:z}=$e(),j=z("view_orders"),w=z("process_payments"),G=z("issue_refunds"),S=O==="Business Provider"||O==="Business Provider Delegate",N=($==null?void 0:$.businessId)||null;ns(N);const{definitions:X,refresh:je}=Ue(!!(N&&j)),[k,Z]=r.useState(!1),[t,J]=r.useState(null),[g,K]=r.useState([]),[C,Q]=r.useState(""),[E,U]=r.useState(""),[_,ee]=r.useState(""),[Ne,L]=r.useState(!1),[A,se]=r.useState(""),[m,d]=r.useState(!1),[ge,ye]=r.useState(()=>new Set),[ve,y]=r.useState(!1),[R,T]=r.useState(null),[F,te]=r.useState(!1),x=r.useCallback(async()=>{if(!(!u||!j)){Z(!0);try{const n=(await b("getOrder",{orderId:u})).order||null;J(n),K(Array.isArray(n==null?void 0:n.tags)?[...n.tags]:[]),se((n==null?void 0:n.status)||"pending")}catch(s){o.error(s.message||"Could not load order"),J(null)}finally{Z(!1)}}},[u,j]);r.useEffect(()=>{a&&u&&x()},[a,u,x]),r.useEffect(()=>{a||(y(!1),T(null),L(!1))},[a]);const ae=t!=null&&t.locationId?((re=W.find(s=>s.id===t.locationId))==null?void 0:re.name)??null:null;async function we(){const s=t==null?void 0:t.appointmentId;if(!s){o.message("This order is not linked to an appointment.");return}te(!0);try{const n=await ts("getAppointment",{businessId:N,appointmentId:s});if(!n.appointment){o.error("Appointment not found");return}T({id:s,...n.appointment}),y(!0)}catch(n){o.error(n.message||"Could not load appointment")}finally{te(!1)}}function ne(s){if(String(s).toLowerCase().startsWith("offer:"))return s;const n=X.find(i=>i.id===s);return n?`${n.emoji?`${n.emoji} `:""}${n.label}`.trim():s}async function ie(s){if(!(!t||S)){d(!0);try{await b("updateOrderTags",{orderId:t.id,tags:s}),K(s),await x(),l==null||l()}catch(n){o.error(n.message||"Could not update tags")}finally{d(!1)}}}async function Se(){if(!(!t||!C.trim()||S)){d(!0);try{await b("addOrderNote",{orderId:t.id,text:C.trim()}),Q(""),o.success("Note added"),await x(),l==null||l()}catch(s){o.error(s.message||"Could not add note")}finally{d(!1)}}}
1async function ke(){if(!(!t||!w||A===t.status)){d(!0);try{await b("updateOrderStatus",{orderId:t.id,status:A}),o.success("Status updated"),await x(),l==null||l()}catch(s){o.error(s.message||"Could not update status")}finally{d(!1)}}}async function Ce(){if(!t||!G||!_.trim()){o.error("Reason is required");return}const s=E.trim()===""?null:Number(E);if(s!=null&&(Number.isNaN(s)||s<=0)){o.error("Enter a valid amount or leave blank for full remaining");return}d(!0);try{await b("processRefund",{orderId:t.id,reason:_.trim(),...s!=null?{amount:s}:{}}),o.success("Refund recorded"),ee(""),U(""),L(!1),await x(),l==null||l()}catch(n){o.error(n.message||"Refund failed")}finally{d(!1)}}async function V(s){if(!(!t||!w)){d(!0);try{const n=await b("sendReceipt",{orderId:t.id,channel:s});if(s==="print"&&n.receiptHtml){const i=window.open("","_blank");i&&(i.document.write(n.receiptHtml),i.document.close(),i.focus()),o.success("Receipt opened for printing")}else o.success(s==="email"?"Receipt queued for email":"Receipt sent");l==null||l()}catch(n){o.error(n.message||"Could not send receipt")}finally{d(!1)}}}function _e(s){ye(n=>{const i=new Set(n);return i.has(s)?i.delete(s):i.add(s),i})}const I=(M==null?void 0:M.accentColor)||Me,H=!((t==null?void 0:t.payments)||[]).some(xe)&&Number(t==null?void 0:t.depositAmount)>0,le=(()=>{if(!t||["refunded","cancelled"].includes(String(t.status||"")))return 0;const s=Number(t.amountDue);if(Number.isFinite(s))return Math.max(0,Math.round(s*100)/100);const n=(t.payments||[]).reduce((i,B)=>i+(Number(B.amount)||0),0)+(H&&Number(t.depositAmount)||0);return Math.max(0,Math.round(((Number(t.total)||0)-n)*100)/100)})(),Le=t?e.jsxs("div",{className:"business-sales-identity",children:[e.jsx("button",{type:"button",className:"business-sales-identity__name",style:{color:I},onClick:()=>{t.patientId&&(c(!1),f(`/patients?patient=${encodeURIComponent(t.patientId)}`))},"aria-label":`Open ${t.patientName||be} profile`,children:t.patientName||"No name on file"}),e.jsxs("div",{className:"business-sales-identity__meta",children:[e.jsx("span",{className:ze(t.status),children:me(t.status)}),e.jsx("span",{children:pe(t.createdAt)}),e.jsx("span",{children:h(t.total)})]})]}):null,Ae=t&&Ne?e.jsxs("div",{className:"business-sales-section",children:[e.jsxs("h3",{className:"business-sales-section__title",children:["Refund ",P(t).toLowerCase()]}),e.jsxs("p",{className:"text-sm text-[var(--business-ink-muted)]",children:["Refunding ",P(t)," for ",t.patientName||"this client"," returns money to the original payment method. This cannot be undone."]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{htmlFor:"business-order-refund-amount",children:"Amount"}),e.jsx(Ee,{id:"business-order-refund-amount",placeholder:"Leave blank to refund the remaining balance",value:E,onChange:s=>U(s.target.value),inputMode:"decimal"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{htmlFor:"business-order-refund-reason",children:"Reason"}),e.jsx(ue,{id:"business-order-refund-reason",value:_,onChange:s=>ee(s.target.value),rows:3})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(p,{type:"button",variant:"outline",onClick:()=>L(!1),children:"Cancel"}),e.jsx(p,{type:"button",variant:"destructive",onClick:Ce,disabled:m||!_.trim(),children:m?"Refunding…":"Refund order"})]})]}):null;return e.jsxs(e.Fragment,{children:[e.jsxs(as,{open:a,onOpenChange:c,title:P(t),identity:Le,size:"wide",childView:Ae,primaryAction:!k&&(t!=null&&t.appointmentId)?e.jsxs(p,{type:"button",size:"sm",onClick:we,disabled:F,className:"text-white",style:{backgroundColor:I},"data-testid":"button-order-detail-view-appointment",children:[F?e.jsx(Ke,{size:"md"}):null,F?"Loading…":"View appointment"]}):null,testId:"drawer-sales-order",children:[k?e.jsx(de,{kind:"loading",title:"Loading order"}):null,!k&&!t?e.jsx(de,{kind:"error",title:"This order could not load."}):null,!k&&t?e.jsxs("div",{className:"business-sales-detail",children:[w?e.jsxs("section",{className:"business-sales-section",children:[e.jsx("h3",{className:"business-sales-section__title",children:"Status"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Fe,{value:A,onValueChange:se,children:[e.jsx(Ve,{className:"w-[200px]","aria-label":`Status for ${P(t)}`,children:e.jsx(He,{placeholder:"Status"})}),e.jsx(Ye,{children:ls.map(s=>e.jsx(qe,{value:s,children:me(s)},s))})]}),e.jsx(p,{type:"button",variant:"outline",size:"sm",onClick:ke,disabled:m||A===t.status,children:"Apply status"})]})]}):null,e.jsxs("section",{className:"business-sales-section",children:[e.jsx("h3",{className:"business-sales-section__title",children:"Items"}),e.jsxs("ul",{className:"business-sales-lines",children:[(t.lineItems||[]).length===0?e.jsx("li",{className:"business-sales-lines__empty",children:"No line items"}):null,(t.lineItems||[]).map((s,n)=>{const i=Array.isArray(s.productUsage)?s.productUsage:[],B=i.length>0,D=ge.has(n),ce=s.providerName||s.staffName||s.employeeName,Y=s.serviceName||s.description||"Item";return e.jsx("li",{className:"business-sales-lines__item",children:e.jsxs("div",{className:"flex items-start gap-2",children:[B?e.jsx("button",{type:"button",className:"mt-0.5 rounded p-0.5 text-[var(--business-ink-muted)]",onClick:()=>_e(n),"aria-expanded":D,"aria-label":D?`Hide products used for ${Y}`:`Show products used for ${Y}`,children:D?e.jsx(Oe,{className:"size-4"}):e.jsx(We,{className:"size-4"})}):e.jsx("span",{className:"w-5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[he(s.lineType)?e.
1jsx("span",{className:"business-sales-lines__type",children:he(s.lineType)}):null,e.jsx("span",{className:"font-medium",children:Y}),fe({price:s.unitPrice,priceModel:s.priceModel,unitLabel:s.unitLabel},s.units)?e.jsx("span",{className:"mt-0.5 block text-xs tabular-nums text-[var(--business-ink-muted)]",children:fe({price:s.unitPrice,priceModel:s.priceModel,unitLabel:s.unitLabel},s.units)}):null,ce?e.jsxs("span",{className:"mt-0.5 block text-xs text-[var(--business-ink-muted)]",children:["with ",ce]}):null]}),e.jsx("span",{className:"shrink-0 font-mono",children:h(s.price)})]}),B&&D?e.jsx("ul",{className:"business-sales-lines__usage",children:i.map((v,Re)=>e.jsxs("li",{children:[v.quantity??0,"× ",v.productName||v.name||"Product"," — ",h(v.cost??v.price)]},Re))}):null]})]})},n)})]}),e.jsxs("p",{className:"business-sales-total",children:["Total ",h(t.total)]})]}),e.jsxs("section",{className:"business-sales-section",children:[e.jsx("h3",{className:"business-sales-section__title",children:"Payments"}),e.jsxs("ul",{className:"business-sales-breakdown",children:[(t.payments||[]).length===0&&!H?e.jsx("li",{className:"text-[var(--business-ink-muted)]",children:"No payments recorded"}):null,(t.payments||[]).map((s,n)=>e.jsxs("li",{children:[e.jsx("span",{className:"truncate",children:os(s)}),e.jsx("span",{className:"shrink-0 font-medium",children:h(s.amount)})]},n)),H?e.jsxs("li",{children:[e.jsx("span",{className:"truncate font-medium",children:"Deposit applied"}),e.jsx("span",{className:"shrink-0 font-medium",children:h(t.depositAmount)})]}):null]}),le>0?e.jsxs("div",{className:"space-y-1","data-testid":"block-order-amount-due",children:[e.jsxs("p",{className:"text-sm font-semibold text-[var(--business-ink)]",children:["Still owed ",h(le)]}),e.jsx("p",{className:"text-sm text-[var(--business-ink-muted)]",children:t.appointmentId?"Collect it from the appointment: open it below and use Checkout to take cash, apply credit, or send the card payment link.":"This walk-in order was left unpaid. Payment can be taken on a new sale from Start sale; taking money against this existing order is not supported yet."})]}):null,(t.refunds||[]).length>0?e.jsx("ul",{className:"business-sales-breakdown",children:t.refunds.map((s,n)=>{var i;return e.jsxs("li",{children:[e.jsxs("span",{className:"truncate",children:["Refund — ",(i=s.reason)==null?void 0:i.slice(0,80)]}),e.jsx("span",{className:"shrink-0 font-medium",children:h(s.amount)})]},n)})}):null,e.jsxs("div",{className:"flex flex-wrap gap-2",children:[w?e.jsxs(e.Fragment,{children:[e.jsxs(p,{type:"button",size:"sm",variant:"outline",onClick:()=>V("print"),disabled:m,children:[e.jsx(Ge,{className:"size-4","aria-hidden":!0})," Print receipt"]}),e.jsxs(p,{type:"button",size:"sm",variant:"outline",onClick:()=>V("email"),disabled:m,children:[e.jsx(Xe,{className:"size-4","aria-hidden":!0})," Email receipt"]}),e.jsxs(p,{type:"button",size:"sm",variant:"outline",onClick:()=>V("sms"),disabled:m,children:[e.jsx(Ze,{className:"size-4","aria-hidden":!0})," Text receipt"]})]}):null,G?e.jsx(p,{type:"button",size:"sm",variant:"outline",className:"business-sales-destructive",onClick:()=>L(!0),disabled:m,"data-testid":"button-order-detail-refund",children:"Refund order"}):null]})]}),!S&&j?e.jsxs("section",{className:"business-sales-section",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("h3",{className:"business-sales-section__title",children:"Tags"}),e.jsx(es,{scope:"order",definitions:X,value:g.filter(s=>!String(s).toLowerCase().startsWith("offer:")),onChange:s=>{const n=g.filter(i=>String(i).toLowerCase().startsWith("offer:"));ie([...n,...s])},disabled:m,allowCreate:!0,accentColor:I,onDefinitionsRefresh:je,compact:!0})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.length===0?e.jsx("span",{className:"text-sm text-[var(--business-ink-muted)]",children:"No tags"}):g.map(s=>e.jsxs("span",{className:"business-sales-tag",children:[e.jsx("span",{className:"max-w-[200px] truncate",children:ne(s)}),e.jsx("button",{type:"button",className:"business-sales-tag__remove","aria-label":`Remove tag ${ne(s)}`,onClick:()=>void ie(g.filter(n=>n!==s)),children:e.jsx(Je,{className:"size-3","aria-hidden":!0})})]},s))})]}):null,e.jsxs("section",{className:"business-sales-section",children:[e.jsx("h3",{className:"business-sales-section__title",children:"Internal notes"}),!S&&j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"business-order-note",className:"sr-only",children:"Add an internal note"}),e.jsx(ue,{id:"business-order-note",value:C,onChange:s=>Q(s.target.value),rows:3,placeholder:"Visible to staff with order access"}),e.jsx(p,{type:"button",size:"sm",variant:"outline",onClick:Se,disabled:m||!C.trim(),children:"Add note"})]}):null,e.jsxs("ul",{className:"business-sales-notes",children:[(t.internalNotes||[]).length===0?e.jsx("li",{className:"text-[var(--business-ink-muted)]",children:"None yet"}):null,[...t.internalNotes||[]].reverse().map(s=>e.jsxs("li",{children:[e.jsx("span",{className:"font-medium",children:s.actorName||"Staff"})," · ",e.jsx("span",{className:"text-[var(--business-ink-muted)]",children:s.createdAt?pe(s.createdAt):""}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap",children:s.text})]},s.id||s.createdAt))]})]}),e.jsxs("p",{className:"text-sm text-[var(--business-ink-muted)]",children:["Location: ",ae||t.locationId||"All locations"]})]}):null]}),N&&R&&e.jsx(ss,{open:ve,onOpenChange:s=>{y(s),s||T(null)},appointment:R,locationName:R.locationId?((oe=W.find(s=>
1s.id===R.locationId))==null?void 0:oe.name)??null:ae,accentColor:I,onNavigatePatient:s=>{s&&(y(!1),T(null),c(!1),f(`/patients?patient=${encodeURIComponent(s)}`))},onViewOrder:s=>{f(`/sales?order=${encodeURIComponent(s)}`),y(!1),c(!1)},businessId:N})]})}function Is(){const[a,c]=Te(),u=a.get("order")||"",l=r.useCallback(f=>{f||c(is(a,null),{replace:!0})},[a,c]);return e.jsx(cs,{open:!!u,onOpenChange:l,orderId:u})}export{Is 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.