1import{ab as B,i as I,r as C,l as y,A as j,j as e,B as E,L as d,f as F,aV as T,aG as G,bS as A,bg as p,y as O,ao as S,bL as q,bh as R}from"./index-CV3Wh3hK.js";import{u as H,R as Q}from"./useRecordRealtime-CXFjCNqc.js";import{D as U}from"./ui-7qwazfDU.js";import{R as W}from"./TaskModal-BoJVBsQr.js";import{R as z,A as Y}from"./ActivityTimeline-DuCRO5X9.js";import{S as J}from"./store-CSDNbr09.js";import"./PlainSelect-CkHM2lu6.js";import"./message-square-BBTUrA1J.js";import"./paperclip-CHRqiJGY.js";import"./pencil-C7TegPN8.js";import"./dateFields-P3GFFClQ.js";import"./calendar-BG-FR-m2.js";import"./popover-RDRsTn5w.js";import"./index-BPwkcYDO.js";import"./index-BGOq8ltu.js";import"./calendar-CeX9Py-p.js";import"./uploadMedia-B_06Aj4Q.js";import"./ban-DJtJr13O.js";import"./user-check-Bqt_Px5y.js";import"./package-check-CxsI-ooe.js";import"./upload-Dn7x9pfp.js";import"./useAdminCaps-CWrPNFQY.js";import"./activityLabels-DRCxnIzT.js";import"./history-Dtob6r3E.js";const r=i=>new Intl.NumberFormat("vi-VN").format(Math.round(Number(i)||0)),D={cash:"Tiá»n mặt",transfer:"Chuyá»n khoản",mixed:"Kết hợp (TM + CK)",card:"Thẻ",wallet:"VÃ"};function ve(){const{id:i}=B(),L=I(),[x,f]=C.useState("return"),{data:s,isLoading:K}=y({queryKey:["order-return",i],queryFn:async()=>(await(await fetch(`${j}/api/orders/returns/${i}`,{credentials:"include",cache:"no-store"})).json().catch(()=>({}))).return||null,meta:{realtime:"manual"}}),V=C.useCallback(async()=>{const t=await fetch(`${j}/api/orders/returns/${i}`,{credentials:"include",cache:"no-store"});return t.status===404?null:(await t.json().catch(()=>({}))).return||null},[i]),M=H({data:s,recheck:V,version:t=>`${t.refund}|${t.goods_total}|${t.net_paid||""}|${t.voucher_id||""}|${t.exchange_order_code||""}|${t.note||""}`}),{data:v=[]}=y({queryKey:["return-ex-vouchers",s==null?void 0:s.exchange_order_id],enabled:!!(s!=null&&s.exchange_order_id),queryFn:async()=>(await(await fetch(`${j}/api/cashbook/by-order/${s.exchange_order_id}`,{credentials:"include",cache:"no-store"})).json().catch(()=>({}))).vouchers||[]}),{data:w=[]}=y({queryKey:["return-rt-vouchers",s==null?void 0:s.id],enabled:!!(s!=null&&s.id),queryFn:async()=>(await(await fetch(`${j}/api/cashbook/by-return/${s.id}`,{credentials:"include",cache:"no-store"})).json().catch(()=>({}))).vouchers||[]});if(K)return e.jsx(U,{});if(!s)return e.jsxs("div",{className:"p-8 text-center",children:[e.jsx("p",{className:"text-gray-500 mb-4",children:"Không tìm thấy phiếu trả hà ng"}),e.jsx(E,{onClick:()=>L("/admin/returns"),className:"rounded-full",children:"Quay lại"})]});const _=Array.isArray(s.items)?s.items:[],h=Array.isArray(s.buy_items)?s.buy_items:[],u=h.length>0,k=Number(s.buy_total)||0,m=k-(Number(s.refund)||0);return e.jsxs("div",{className:"p-4 md:p-6 lg:p-8 max-w-4xl mx-auto",children:[e.jsx("div",{className:"sticky top-14 lg:top-0 z-30 -mx-4 md:-mx-6 lg:-mx-8 mb-4 px-4 md:px-6 lg:px-8 py-2.5 bg-gray-50 border-b border-gray-200",children:e.jsxs(d,{to:"/admin/returns",className:"inline-flex items-center gap-1 text-sm text-gray-500 hover:text-primary",children:[e.jsx(F,{className:"w-4 h-4"})," Quay lại danh sách trả hà ng"]})}),e.jsx(Q,{status:M,backTo:"/admin/returns"}),e.jsxs("div",{className:"rounded-2xl border border-gray-200 bg-gradient-to-r from-amber-50 to-white p-5 mb-4 flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-12 h-12 rounded-xl bg-amber-100 text-amber-600 flex items-center justify-center shrink-0",children:e.jsx(T,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-800",children:s.code}),e.jsxs("p",{className:"text-sm text-gray-500",children:["Tạo lúc ",new Date(s.created_at).toLocaleString("vi-VN")]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-gray-400",children:"Hoà n khách"}),e.jsxs("p",{className:"text-3xl font-black text-emerald-600 admin-num",children:[r(s.refund),"â«"]})]})]}),e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-200 divide-y divide-gray-100",children:[e.jsxs("div",{className:"p-5",children:[e.jsx("h3",{className:"font-semibold mb-3",children:"Thông tin phiếu trả hà ng"}),e.jsxs("dl",{className:"grid sm:grid-cols-2 gap-x-6 gap-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"text-gray-500 flex items-center gap-1",children:[e.jsx(G,{className:"w-3.5 h-3.5"})," Ngưá»i tạo:"]}),e.jsx("dd",{className:"font-medium",children:s.created_by_name&&s.created_by_name.trim()||s.created_by||"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"text-gray-500 flex items-center gap-1",children:[e.jsx(J,{className:"w-3.5 h-3.5"})," Kênh bán:"]}),e.jsx("dd",{className:"font-medium",children:s.sales_channel||"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"text-gray-500 flex items-center gap-1",children:[e.jsx(A,{className:"w-3.5 h-3.5"})," Mã hoá ÄÆ¡n:"]}),e.jsx("dd",{className:"font-medium",children:s.order_code?e.jsx(d,{to:`/admin/invoices/${s.order_code}`,className:"text-primary hover:underline",children:s.order_code}):"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsxs("dt",{className:"text-gray-500 flex items-center gap-1",children:[e.jsx(p,{className:"w-3.5 h-3.5"})," Mã phiếu:"]}),e.jsx("dd",{className:"font-medium",children:s.voucher_code?e.jsx(d,{to:String(s.voucher_code).startsWith("PT")?"/admin/receipts":"/admin/payments",className:`${String(s.voucher_code).startsWith("PT")?"text-emerald-600":"text-red-500"} hover:underline`,children:s.voucher_code}):"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-gray-500",children:"Khách hà ng:"}),e.jsx("dd",{className:"font-medium",children:s.customer_name||"â"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-gray-500",children:"SÄT:"}),e.jsx("dd",{className:"font-medium",children:s.customer_phone||"â"})]})]}),s.note&&e.jsxs("p",{className:"text-sm text-gray-600 mt-3 italic",children:["Ghi chú: ",s.note]})]}),u&&e.jsxs("div",{className:"flex",children:[e.jsxs("button",{onClick:()=>f("return"),className:`flex-1 py-3 text-sm font-semibold flex items-center justify-center gap-1.5 border-b-2 ${x==="return"?"border-primary text-primary":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[e.jsx(T,{className:"w-4 h-4"})," Trả hà ng"]}),e.jsxs("button",{onClick:()=>f("exchange"),className:`flex-1 py-3 text-sm font-semibold flex items-center justify-center gap-1.5 border-b-2 ${x==="exchange"?"border-primary text-primary":"border-transparent text-gray-500 hover:text-gray-700"}`,children:[e.jsx(O,{className:"w-4 h-4"})," Hoá ÄÆ¡n Äá»i hà ng"]})]}),(!u||x==="return")&&e.jsxs("div",{className:"p-5",children:[e.jsxs("h3",{className:"font-semibold mb-3",children:["Sản phẩm trả (",_.length,")"]}),e.jsx("div",{className:"divide-y divide-gray-100 border border-gray-100 rounded-xl overflow-hidden",children:_.map((t,a)=>{const l=Array.isArray(t.components)?t.components:[],n=l.length>0,o=n&&Number(t.qty)>0,P=o?(Number(t.price)||0)*(Number(t.qty)||0):l.reduce((c,b)=>c+(Number(b.value)||0),0);return e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg overflow-hidden bg-gray-100 shrink-0",children:t.image_url?e.jsx("img",{src:t.image_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(S,{className:"w-5 h-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm line-clamp-1 flex items-center gap-1.5",children:[t.name,n&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-0.5 text-[9px] font-bold text-amber-600 bg-amber-100 px-1.5 py-0.5 rounded",children:[e.jsx(q,{className:"w-2.5 h-2.5"})," COMBO ",l.length," món"]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:n?`Trả ${l.length} linh kiá»n`:`${r(t.price)} à ${t.qty}`})]}),e.jsx("p",{className:"font-bold text-sm",children:r(n?P:(Number(t.price)||0)*(Number(t.qty)||0))})]}),n&&e.jsx("div",{className:"mt-2 ml-14 pl-3 border-l-2 border-amber-100 space-y-1",children:l.map((c,b)=>{const N=o?(Number(c.qty)||0)*(Number(t.qty)||0):Number(c.qty)||0,g=Number(c.value)||0,$=g&&N?Math.round(g/N):0;return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-amber-300 shrink-0",children:"â³"}),e.jsxs("span",{className:"flex-1 min-w-0 truncate text-gray-600",children:[c.name||`#${c.product_id}`,c.sku?e.jsxs("span",{className:"text-gray-400",children:[" · ",c.sku]}):""]}),e.jsxs("span",{className:"shrink-0 text-gray-400 admin-num",children:[$?`${r($)} à `:"à ",N]}),!o&&e.jsx("span",{className:"shrink-0 w-20 text-right font-semibold text-gray-700 admin-num",children:r(g)})]},b)})})]},a)})}),e.jsx("div",{className:"mt-3 space-y-1 text-sm",children:e.jsxs("div",{className:"flex justify-between text-base font-bold",children:[e.jsx("span",{children:"Tá»ng giá trá» hà ng trả:"}),e.jsx("span",{className:"text-emerald-600",children:r(s.goods_total)})]})}),!u&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-1 space-y-1 text-sm",children:[Number(s.discount)>0&&e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsx("span",{children:"Giảm giá:"}),e.jsxs("span",{children:["â",r(s.discount)]})]}),Number(s.fee)>0&&e.jsxs("div",{className:"flex justify-between text-amber-600",children:[e.jsx("span",{children:"Phà trả hà ng:"}),e.jsxs("span",{children:["â",r(s.fee)]})]}),Number(s.other_refund)>0&&e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsx("span",{children:"Hoà n trả thu khác:"}),e.jsxs("span",{children:["+",r(s.other_refund)]})]}),e.jsxs("div",{className:"flex justify-between text-base font-bold pt-2 border-t border-gray-100",children:[e.jsx("span",{children:"Cần trả khách:"}),e.jsx("span",{className:"text-emerald-600",children:r(s.refund)})]}),e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{className:"text-gray-700",children:"Äã trả khách:"}),e.jsx("span",{className:"text-red-500",children:r(s.net_paid)})]}),Number(s.credit_to_order)>0&&e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{className:"text-gray-700",children:"Cấn và o nợ ÄÆ¡n gá»c:"}),e.jsx("span",{className:"text-emerald-600",children:r(s.credit_to_order)})]}),Number(s.credit_to_customer)>0&&e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{className:"text-gray-700",children:"Ghi có công nợ
1khách:"}),e.jsx("span",{className:"text-emerald-600",children:r(s.credit_to_customer)})]})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-100",children:[e.jsx("h4",{className:"font-semibold text-sm mb-2",children:"Diá»
n biến thanh toán"}),w.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"Chưa có phiếu chi nà o."}):e.jsx("ol",{className:"relative border-l border-gray-200 ml-2 space-y-3",children:w.map(t=>e.jsxs("li",{className:"ml-4",children:[e.jsx("span",{className:"absolute -left-1.5 mt-1.5 w-3 h-3 rounded-full border-2 border-white bg-red-500"}),e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[e.jsx(p,{className:"w-3.5 h-3.5 text-red-600"}),e.jsx(d,{to:"/admin/payments",className:"text-primary hover:underline",children:t.code}),e.jsx("span",{className:"text-[10px] text-red-500 font-semibold",children:"Trả khách"})]}),e.jsxs("span",{className:"font-bold text-red-500",children:["â",r(t.amount)]})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[new Date(t.created_at).toLocaleString("vi-VN")," · ",D[t.method]||t.method,t.note?` · ${t.note}`:""]})]},t.id))})]})]})]}),u&&x==="exchange"&&e.jsxs("div",{className:"p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"font-semibold",children:["Sản phẩm Äá»i (",h.length,")"]}),s.exchange_order_code&&e.jsxs(d,{to:`/admin/invoices/${s.exchange_order_code}`,className:"text-sm text-primary hover:underline flex items-center gap-1",children:[e.jsx(A,{className:"w-4 h-4"})," ",s.exchange_order_code]})]}),e.jsx("div",{className:"divide-y divide-gray-100 border border-gray-100 rounded-xl overflow-hidden",children:h.map((t,a)=>e.jsxs("div",{className:"p-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-lg overflow-hidden bg-gray-100 shrink-0",children:t.image_url?e.jsx("img",{src:t.image_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-300",children:e.jsx(S,{className:"w-5 h-5"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"font-medium text-sm line-clamp-1 flex items-center gap-1.5",children:[t.name,Array.isArray(t.components)&&t.components.length>0&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-0.5 text-[9px] font-bold text-amber-600 bg-amber-100 px-1.5 py-0.5 rounded",children:[e.jsx(q,{className:"w-2.5 h-2.5"})," COMBO ",t.components.length," món"]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:[r(t.price)," à ",t.quantity]})]}),e.jsx("p",{className:"font-bold text-sm",children:r((Number(t.price)||0)*(Number(t.quantity)||0))})]},a))}),e.jsxs("div",{className:"mt-3 space-y-1 text-sm",children:[e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsxs("span",{children:["Tá»ng tiá»n hà ng (",h.length,")"]}),e.jsx("span",{children:r(s.buy_subtotal)})]}),e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsx("span",{children:"Giảm giá hoá ÄÆ¡n"}),e.jsx("span",{children:Number(s.buy_discount)>0?`â${r(s.buy_discount)}`:"0"})]}),Number(s.buy_other)>0&&e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsx("span",{children:"Thu khác"}),e.jsxs("span",{children:["+",r(s.buy_other)]})]}),e.jsxs("div",{className:"flex justify-between font-medium",children:[e.jsx("span",{className:"text-gray-800",children:"Tá»ng tiá»n hoá ÄÆ¡n mua"}),e.jsx("span",{children:r(k)})]}),e.jsxs("div",{className:"flex justify-between text-gray-600",children:[e.jsxs("span",{children:["Tá»ng tiá»n hoá ÄÆ¡n trả ",s.code?`(${s.code})`:""]}),e.jsx("span",{children:r(s.refund)})]}),e.jsxs("div",{className:"flex justify-between text-base font-bold pt-2 border-t border-gray-100",children:[e.jsx("span",{children:m>=0?"Khách cần trả":"Cần trả khách"}),e.jsx("span",{className:"text-primary",children:r(Math.abs(m))})]}),e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsxs("span",{className:"flex items-center gap-1 text-gray-700",children:[m>=0?e.jsx(R,{className:"w-4 h-4 text-emerald-600"}):e.jsx(p,{className:"w-4 h-4 text-red-500"}),m>=0?"Khách Äã trả":"Äã trả khách"]}),e.jsx("span",{className:m>=0?"text-emerald-600":"text-red-500",children:r(s.net_paid)})]})]}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-100",children:[e.jsx("h4",{className:"font-semibold text-sm mb-2",children:"Diá»
1
n biến thanh toán"}),v.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"Chưa có phiếu thu/chi nà o."}):e.jsx("ol",{className:"relative border-l border-gray-200 ml-2 space-y-3",children:v.map(t=>{const a=t.type==="chi",l=(Array.isArray(t.allocations)?t.allocations:[]).filter(n=>String(n.order_id)===String(s.exchange_order_id)).reduce((n,o)=>n+(Number(o.amount)||0),0)||Number(t.amount);return e.jsxs("li",{className:"ml-4",children:[e.jsx("span",{className:`absolute -left-1.5 mt-1.5 w-3 h-3 rounded-full border-2 border-white ${a?"bg-red-500":"bg-green-500"}`}),e.jsxs("div",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[a?e.jsx(p,{className:"w-3.5 h-3.5 text-red-600"}):e.jsx(R,{className:"w-3.5 h-3.5 text-green-600"}),e.jsx(d,{to:a?"/admin/payments":"/admin/receipts",className:"text-primary hover:underline",children:t.code}),a&&e.jsx("span",{className:"text-[10px] text-red-500 font-semibold",children:"Trả khách"})]}),e.jsxs("span",{className:`font-bold ${a?"text-red-600":"text-green-600"}`,children:[a?"â":"+",r(l)]})]}),e.jsxs("p",{className:"text-xs text-gray-500 mt-0.5",children:[new Date(t.created_at).toLocaleString("vi-VN")," · ",D[t.method]||t.method,t.note?` · ${t.note}`:""]})]},t.id)})})]})]})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx(z,{entity:"order_returns",recordId:s.id}),e.jsx(W,{entity:"order_returns",recordId:s.id}),e.jsx(Y,{entity:"order_returns",recordId:s.id})]})]})}export{ve 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.