1import{r as n,j as e}from"./react-vendor-DDlTsOEd.js";import{A as C}from"./AdminLayout-C0t6TWD9.js";import{d as r,K as c,R as k,I as z,ad as i,l as A,A as P}from"./index-dMYrr1t8.js";import"./megaphone-CG_Y22E9.js";import"./clipboard-check-H9MOfMyT.js";import"./database-BMcpOIuo.js";import"./tag-CsU2rQcC.js";import"./credit-card-CV_Lm4ZC.js";function M(){const[a,m]=n.useState("ledger"),[p,h]=n.useState([]),[f,g]=n.useState([]),[j,v]=n.useState([]),[y,u]=n.useState(!1),[l,N]=n.useState("");n.useEffect(()=>{d()},[a]);function d(){u(!0),(a==="ledger"?r.get(`/admin/finance/payment-ledger${l?`?status=${encodeURIComponent(l)}`:""}`):a==="refunds"?r.get("/admin/finance/refunds"):r.get("/admin/finance/invoices")).then(s=>{a==="ledger"&&h(s.data??[]),a==="refunds"&&g(s.data??[]),a==="invoices"&&v(s.data??[])}).catch(()=>{}).finally(()=>u(!1))}async function b(t){const s=window.prompt('Settlement status: "unsettled" | "settled" | "reconciled" | "flagged"',"settled"),x=window.prompt("Razorpay settlement / transfer ref (optional)","")??"";if(s)try{await r.patch(`/admin/finance/payments/${t}/settlement`,{settlementStatus:s,razorpaySettlementRef:x||null,reconciliationNote:"Manual reconciliation via finance ops UI"}),i({title:"Settlement updated"}),d()}catch{i({title:"Update failed",variant:"destructive"})}}async function S(t){try{await r.post("/admin/finance/invoices/from-payment",{paymentId:t}),i({title:"Invoice issued"}),m("invoices"),d()}catch{i({title:"Could not issue invoice",variant:"destructive"})}}async function w(t){const s=A();if(!s){i({title:"Not signed in",variant:"destructive"});return}const I=await(await fetch(`${P}/finance/invoices/${encodeURIComponent(t)}/receipt`,{headers:{Authorization:`Bearer ${s}`}})).text(),o=window.open("","_blank");o&&(o.document.write(I),o.document.close())}async function R(){const t=Number(window.prompt("Payment ID","")),s=Number(window.prompt("Amount rupees",""));if(!(!t||!s||s<=0))try{await r.post("/admin/finance/refunds",{paymentId:t,amountPaise:Math.round(s*100),reason:"Manual refund logged from finance dashboard"}),i({title:"Refund logged"}),d()}catch{i({title:"Refund log failed",variant:"destructive"})}}return e.jsx(C,{children:e.jsxs("div",{className:"max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Finance operations"}),e.jsx("p",{className:"text-sm text-gray-900 mt-1",children:"Settlement markers, Razorpay reconciliation notes, refunds, and GST-ready invoices."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 border-b border-gray-200 pb-3",children:[["ledger","refunds","invoices"].map(t=>e.jsx("button",{onClick:()=>m(t),className:`px-4 py-2 rounded-xl text-sm font-medium transition-colors ${a===t?"bg-indigo-600 text-white":"bg-gray-100 text-gray-900 hover:bg-gray-200"}`,children:t==="ledger"?"Payment ledger":t==="refunds"?"Refunds":"Invoices"},t)),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>d(),className:"ml-auto gap-1",children:[e.jsx(k,{size:14})," Refresh"]})]}),a==="ledger"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsxs("select",{value:l,onChange:t=>N(t.target.value),className:"text-sm border rounded-lg px-2 py-1.5 bg-white",children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"paid",children:"Paid"}),e.jsx("option",{value:"created",children:"Created"}),e.jsx("option",{value:"failed",children:"Failed"}),e.jsx("option",{value:"cancelled",children:"Cancelled"})]}),e.jsx(c,{size:"sm",variant:"secondary",onClick:()=>d(),children:"Apply"})]}),y?e.jsx("p",{className:"text-sm text-gray-900",children:"Loadingâ¦"}):e.jsx("div",{className:"bg-white rounded-xl border shadow-sm overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 text-left text-xs uppercase text-gray-900",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"ID"}),e.jsx("th",{className:"p-3",children:"Student"}),e.jsx("th",{className:"p-3",children:"Course"}),e.jsx("th",{className:"p-3",children:"Status"}),e.jsx("th",{className:"p-3",children:"Settlement"}),e.jsx("th",{className:"p-3",children:"Amount"}),e.jsx("th",{className:"p-3"})]})}),e.jsx("tbody",{children:p.map(t=>e.jsxs("tr",{className:"border-t border-gray-100",children:[e.jsx("td",{className:"p-3 font-mono text-xs",children:t.payment.id}),e.jsxs("td",{className:"p-3",children:[e.jsx("div",{className:"font-medium",children:t.studentName??t.studentEmail}),e.jsx("div",{className:"text-xs text-gray-900",children:t.studentEmail})]}),e.jsx("td",{className:"p-3 max-w-[200px] truncate",children:t.courseTitle}),e.jsx("td",{className:"p-3",children:t.payment.status}),e.jsx("td",{className:"p-3 text-xs",children:t.payment.settlementStatus??"â"}),e.jsxs("td",{className:"p-3 font-semibold flex items-center gap-0.5",children:[e.jsx(z,{size:12}
1),(t.payment.amountPaise/100).toLocaleString("en-IN")]}),e.jsxs("td",{className:"p-3 space-x-2 whitespace-nowrap",children:[e.jsx(c,{size:"sm",variant:"outline",onClick:()=>b(t.payment.id),children:"Reconcile"}),t.payment.status==="paid"&&e.jsx(c,{size:"sm",onClick:()=>S(t.payment.id),children:"Invoice"})]})]},t.payment.id))})]})})]}),a==="refunds"&&e.jsxs("div",{children:[e.jsx(c,{className:"mb-3",onClick:R,children:"Log refund"}),e.jsx("div",{className:"bg-white rounded-xl border shadow-sm divide-y max-h-[480px] overflow-y-auto",children:f.map((t,s)=>e.jsxs("div",{className:"p-3 text-sm",children:[e.jsxs("strong",{children:["Refund #",String(t.refund.id)]})," â â¹",Number(t.refund.amountPaise??0)/100," â",t.refund.status]},s))})]}),a==="invoices"&&e.jsx("div",{className:"bg-white rounded-xl border shadow-sm divide-y",children:j.map(t=>e.jsxs("div",{className:"p-3 flex justify-between text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:String(t.invoiceNumber)}),e.jsxs("div",{className:"text-xs text-gray-800",children:["Issued ",String(t.issuedAt)]})]}),e.jsx(c,{variant:"outline",size:"sm",type:"button",onClick:()=>w(String(t.invoiceNumber)),children:"Receipt"})]},String(t.invoiceNumber)))})]})})}export{M 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.