PageSourceSearch

https://os.sosme.ai/assets/PosExchangePage-bFN66nA5.js

js sosme.ai collected 2026-10-05 15:12:30 UTC 11,288 bytes, 1 lines download raw bytes

1import{a as te,r as o,aA as f,y as D,j as e,q as se,av as I,L as Q,ai as ae,aL as ne}from"./index-DelWp-6b.js";import{u as L}from"./useQuery-B9eAwr7I.js";import{u as K}from"./useMutation-CwYdRQCa.js";import{c as P,d as ie}from"./pos.service-C1tcIoyJ.js";import{p as re}from"./posLookups.service-D1Jgtun7.js";import{s as B,p as oe}from"./posCatalog.service-7qdLIIfk.js";import{u as le}from"./usePosSession-iCXXNYrT.js";import{P as O,a as b,c as u,p as N}from"./PosAdminShell-BWrNWsyQ.js";import{S as l,b as X}from"./pos.types-iW8hZPC7.js";import{P as de}from"./package-x-B6sw9KrA.js";import{P as z}from"./plus-BjX2r5pd.js";import{M as ce}from"./minus-D0XrMftF.js";import{A as H}from"./arrow-left-right-DwUC5in6.js";import"./paging-BO6Zj7Ff.js";import"./unwrap-CuJafpqD.js";const h=(v,c="SAR")=>`${(Number(v)||0).toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})} ${c}`;function Ce(){var M,T,G;const v=te(),c=le(),[x,$]=o.useState(""),[r,A]=o.useState(null),[w,k]=o.useState({}),[g,E]=o.useState({}),[S,W]=o.useState(""),[d,m]=o.useState([]),[y,J]=o.useState(""),[C,U]=o.useState(""),[n,R]=o.useState(null),V=L({queryKey:["pos","reasons",X.Refund],queryFn:()=>ie.list(X.Refund,!0),staleTime:10*60*1e3}),Y=L({queryKey:["pos","lk","instruments"],queryFn:re.paymentInstruments,staleTime:10*60*1e3}),Z=L({queryKey:["pos","catalog",S],queryFn:()=>oe.search(S.trim()),enabled:!!r}),j=K({mutationFn:async t=>{const a=await P.list({posStoreId:c.store.id,search:t,pageSize:5}),s=Array.isArray(a)?a:a.items??[],i=s.find(ee=>ee.saleNo===t)??s[0];if(!i)throw new Error(`No sale matches “${t}”.`);return P.get(i.id)},onSuccess:t=>{A(t),k({}),E({}),m([]),R(null)},onError:t=>f.error(D(t,"Could not find that sale."))}),F=o.useMemo(()=>((r==null?void 0:r.lines)??[]).filter(t=>t.quantity-t.returnedQty>0),[r]),p=o.useMemo(()=>Object.entries(w).filter(([,t])=>t>0).map(([t,a])=>({posSaleLineId:t,quantity:a,restock:(g[t]??l.Good)===l.Good,restockStatus:g[t]??l.Good,posReasonCodeId:y||void 0})),[w,g,y]),_=t=>m(a=>{const s=a.find(i=>i.itemSkuId===t.id);return s?a.map(i=>i===s?{...i,quantity:i.quantity+1}:i):[...a,{lineRef:`X${Date.now().toString(36)}${Math.random().toString(36).slice(2,5)}`,itemSkuId:t.id,name:B(t),quantity:1}]}),q=K({mutationFn:()=>P.exchange(r.id,{posShiftId:c.shift.id,returnLines:p,newLines:d.map(t=>({lineRef:t.lineRef,itemSkuId:t.itemSkuId,quantity:t.quantity})),payments:C?[{paymentInstrumentId:C,tenderedAmount:0}]:[],posReasonCodeId:y||void 0,couponCodes:[],idempotencyKey:`exc-${r.id}-${p.map(t=>t.posSaleLineId).join(",")}-${d.map(t=>t.itemSkuId).join(",")}`}),onSuccess:t=>{var a;(a=t.warnings)==null||a.forEach(s=>f(s,{icon:"⚠️",duration:6e3})),R(t),f.success(`Exchange done — ${t.settlementMode} settlement`)},onError:t=>f.error(D(t,"The exchange could not be completed."))});return!c.isLoading&&!c.isReady?e.jsx(O,{title:"Exchange",backTo:"/pos/sale",children:e.jsxs("div",{className:"rounded-2xl border border-dashed border-white/15 p-10 text-center",children:[e.jsx(se,{className:"w-10 h-10 mx-auto mb-3 text-slate-600"}),e.jsx("h2",{className:"font-bold text-sm mb-1",children:"No open shift"}),e.jsx("p",{className:"text-[13px] text-slate-400 mb-5",children:"An exchange moves money and stock both ways, so it belongs to a shift."}),e.jsx("button",{type:"button",onClick:()=>v("/pos/shift"),className:"px-4 py-2 rounded-xl text-[13px] font-semibold text-white",style:{background:"var(--primary-600)"},children:"Open a shift"})]})}):e.jsx(O,{title:"Exchange",subtitle:"Give something back, take something else — settled in one transaction",backTo:"/pos/returns",children:e.jsxs("div",{className:"space-y-5",children:[e.jsx(b,{icon:I,title:"Find the original sale",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{className:u,placeholder:"POS-2026-000001",value:x,onChange:t=>$(t.target.value),onKeyDown:t=>{t.key==="Enter"&&x.trim()&&j.mutate(x.trim())}}),e.jsxs("button",{type:"button",onClick:()=>j.mutate(x.trim()),disabled:!x.trim()||j.isPending,className:"shrink-0 inline-flex items-center gap-2 px-4 rounded-xl text-[13px] font-semibold text-white disabled:opacity-40",style:{background:"var(--primary-600)"},children:[j.isPending?e.jsx(Q,{className:"w-4 h-4 animate-spin"}):e.jsx(I,{className:"w-4 h-4"}),"Find"]})]})}),r&&!n&&e.jsxs("div",{className:"grid lg:grid-cols-2 gap-5",children:[e.jsx(b,{icon:de,title:"Coming back",desc:`From ${r.saleNo}`,children:F.length===0?e.jsx("p",{className:"text-[13px] text-slate-400 py-2",children:"Nothing left to return on this sale."}):e.jsx("div",{className:"space-y-2",children:F.map(t=>{const a=t.quantity-t.returnedQty;return e.jsxs("div",{className:"rounded-xl bg-white/[0.03] border border-white/10 p-3",children:[e.jsx("div",{className:"text-[13px] font-semibold",children:t.itemName}),e.jsxs("div",{className:"text-[11px] text-slate-400 font-mono mb-2",children:[t.skuCode," · max ",a," · ",h(t.lineTotal,r.currency)]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("div",{className:"w-24",children:[e.jsx("label",{className:N,htmlFor:`bq-${t.id}`,children:"Qty"}),e.jsx("input",{id:`bq-${t.id}`,type:"number",min:0,max:a,step:"any",className:u,value:w[t.id]??"",onChange:s=>k(i=>({...i,[t.id]:Math.min(Number(s.target.value)||0,a)}))})]}),e.jsxs("div",{className:"flex-1 min-w-[150px]",children:[e.jsx("label",{className:N,htmlFor:`br-${t.id}`,children:"Back as"}),e.jsxs("select",{id:`br-${t.id}`,className:u,value:g[t.id]??l.Good,onChange:s=>E(i=>({...i,[t.id]:Number(s.target.value)})),children:[e.jsx("option",{value:l.Good,children:"Good — sellable"}),e.jsx("option",{value:l.Damaged,children:"Damaged"}),e.jsx("option",{value:l.Expired,children:"Expired"}),e.jsx("option",{value:l.Quarantine,children:"Quarantine"}),e.jsx("option",{value:l.Blocked,children:"Blocked"})]})]})]})]},t.id)})})}),e.jsxs(b,{icon:z,title:"Going out",desc:"What the customer is taking instead.",children:[e.jsxs("div",{className:"relative mb-3",children:[e.jsx(I,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-500"}),e.jsx("input",{className:`${u} pl-9`,placeholder:"Search the catalogue…",value:S,onChange:t=>W(t.target.value)})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 mb-4 max-h-40 overflow-y-auto",children:(M=Z.data)==null?void 0:M.slice(0,8).map(t=>e.jsxs("button",{type:"button",onClick:()=>_(t),className:"text-left rounded-lg bg-white/[0.03] border border-white/10 hover:border-[var(--primary-500)] p-2 transition",children:[e.jsx("div",{className:"text-[12px] font-semibold line-clamp-1",children:B(t)}),e.jsx("div",{className:"text-[10px] text-slate-400 font-mono",children:t.skuCode})]},t.id))}),e.jsxs("div",{className:"space-y-2",children:[d.map(t=>e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-white/[0.03] border border-white/10 p-2.5",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-semibold truncate",children:t.name}),e.jsx("button",{type:"button",onClick:()=>m(a=>a.map(s=>s.lineRef===t.lineRef?{...s,quantity:Math.max(1,s.quantity-1)}:s)),className:"w-7 h-7 rounded-lg bg-white/5 hover:bg-white/10 flex items-center justify-center","aria-label":"Decrease",children:e.jsx(ce,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"w-8 text-center text-[13px] font-bold tabular-nums",children:t.quantity}),e.jsx("button",{type:"button",onClick:()=>m(a=>a.map(s=>s.lineRef===t.lineRef?{...s,quantity:s.quantity+1}:s)),className:"w-7 h-7 rounded-lg bg-white/5 hover:bg-white/10 flex items-center justify-center","aria-label":"Increase",children:e.jsx(z,{className:"w-3.5 h-3.5"})}),e.jsx("button",{type:"button",onClick:()=>m(a=>a.filter(s=>s.lineRef!==t.lineRef)),className:"w-7 h-7 rounded-lg hover:bg-rose-500/15 text-slate-500 hover:text-rose-300 flex items-center justify-center","aria-label":`Remove ${t.name}`,children:e.jsx(ae,{className:"w-3.5 h-3.5"})})]},t.lineRef)),d.length===0&&e.jsx("p",{className:"text-[12px] text-slate-500 py-2",children:"Nothing selected yet."})]})]})]}),r&&!n&&(p.length>0||d.length>0)&&e.jsxs(b,{icon:H,title:"Settle",desc:"The server nets the two sides according to the store's exchange setting.",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:N,htmlFor:"xreason",children:"Reason"}),e.jsxs("select",{id:"xreason",className:u,value:y,onChange:t=>J(t.target.value),children:[e.jsx("option",{value:"",children:"Select a reason…"}),(T=V.data)==null?void 0:T.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:N,htmlFor:"xinstr",children:"Settle any difference with"}),e.jsxs("select",{id:"xinstr",className:u,value:C,onChange:t=>U(t.target.value),children:[e.jsx("option",{value:"",children:"Let the server decide"}),(G=Y.data)==null?void 0:G.map(t=>e.jsx("option",{value:t.id,children:t.label},t.id))]})]})]}),e.jsxs("button",{type:"button",onClick:()=>q.mutate(),disabled:q.isPending||p.length===0||d.length===0,className:"inline-flex items-center gap-2 px-5 py-3 rounded-xl font-bold text-white disabled:opacity-40 transition",style:{background:"var(--primary-600)"},children:[q.isPending?e.jsx(Q,{className:"w-4 h-4 animate-spin"}):e.jsx(H,{className:"w-4 h-4"}),"Complete the exchange"]}),(p.length===0||d.length===0)&&e.jsx("p",{className:"mt-2 text-[11px] text-slate-500",children:"An exchange needs both sides — something back and something out."})]}),n&&e.jsxs(b,{icon:ne,title:"Done",desc:`${n.settlementMode} settlement`,children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"rounded-xl bg-emerald-500/10 border border-emerald-500/30 px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-emerald-300",children:"Collect from the customer"}),e.jsx("div",{className:"text-2xl font-bold text-emerald-200",children:h(n.customerPays,n.newSale.currency)})]}),e.jsxs("div",{className:"rounded-xl bg-sky-500/10 border border-sky-500/30 px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-sky-300",children:"Hand back to the customer"}),e.jsx("div",{className:"text-2xl font-bold text-sky-200",children:h(n.customerRefunded,n.newSale.currency)})]})]}),e.jsx("div",{className:"rounded-xl border border-white/10 overflow-hidden text-[12px]",children:e.jsx("table",{className:"w-full",children:e.jsx("tbody",{children:[["Returned",n.returnSale.saleNo,h(n.refundTotal,n.newSale.currency)],["New sale",n.newSale.saleNo,h(n.newSaleTotal,n.newSale.currency)],["Credit applied",n.settlementMode==="Gross"?"n
1ot used under Gross":"—",h(n.creditApplied,n.newSale.currency)],["Credit note",n.creditNoteNumber??"—",""]].map(([t,a,s])=>e.jsxs("tr",{className:"border-b border-white/5 last:border-0",children:[e.jsx("td",{className:"px-3 py-2 text-slate-400",children:t}),e.jsx("td",{className:"px-3 py-2 font-mono",children:a}),e.jsx("td",{className:"px-3 py-2 text-right font-mono",children:s})]},t))})})}),e.jsx("button",{type:"button",onClick:()=>{R(null),A(null),$(""),m([]),k({})},className:"mt-4 px-4 py-2.5 rounded-xl text-[13px] font-semibold bg-white/5 hover:bg-white/10 border border-white/10",children:"Another exchange"})]})]})})}export{Ce 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.