1import{u as re,r as f,g as S,i as ne,j as e,bu as le,_ as ie,bK as ce,Y as R,J as de,bG as oe,c1 as xe,e as I,cj as me,f as A,c3 as ue,K as he}from"./vendor-BeA4siBz.js";import{u as je,B as g,C as o,a as N,b,c as pe,d as x,I as O,D as fe,h as ge,j as Ne,k as be,l as ve,g as m,f as ye,q as U}from"./index-C2NQ_9nj.js";import{T as V,a as z,b as l,c as r,d as _,e as a}from"./table-SGlooQdN.js";import{S as Q,a as $,b as G,c as J,d}from"./select-26Ep3yy3.js";import{A as we}from"./AdminLayout-zgeex3qo.js";import"./harbor-shoppers-logo-BwiOLETu.js";import"./textarea-BzoSp81z.js";function ke(){const[,X]=re(),{toast:q}=je(),[D,Y]=f.useState("all"),[T,W]=f.useState("all"),[v,Z]=f.useState(""),[t,E]=f.useState(null),[y,B]=f.useState(""),{data:w}=S({queryKey:["/api/admin/site-settings"]}),F=w!=null&&w.boatzhub_invoice_fee_percent?(parseInt(w.boatzhub_invoice_fee_percent)/100).toFixed(0):"10",P=ne({mutationFn:async s=>{await ye("PUT","/api/admin/site-settings/boatzhub_invoice_fee_percent",{value:String(Math.round(s*100))})},onSuccess:()=>{U.invalidateQueries({queryKey:["/api/admin/site-settings"]}),U.invalidateQueries({queryKey:["/api/public/site-settings"]}),q({title:"BoatzHub fee updated",description:`Platform fee set to ${y||F}%`}),B("")},onError:()=>q({title:"Error",description:"Could not update fee.",variant:"destructive"})}),{data:j=[],isLoading:ee}=S({queryKey:["/api/admin/invoices"]}),{data:k=[]}=S({queryKey:["/api/admin/vendors"],queryFn:async()=>{const s=await fetch("/api/admin/users?role=vendor");return s.ok?s.json():[]}}),{data:u}=S({queryKey:["/api/invoices",t==null?void 0:t.id],enabled:!!t}),L=j.filter(s=>{const n=D==="all"||s.status===D,p=T==="all"||s.vendorId.toString()===T,M=s.invoiceNumber.toLowerCase().includes(v.toLowerCase())||s.customerName.toLowerCase().includes(v.toLowerCase())||s.customerEmail.toLowerCase().includes(v.toLowerCase());return n&&p&&M}),C={totalInvoiced:j.reduce((s,n)=>s+n.total,0),totalCollected:j.reduce((s,n)=>s+n.paidAmount,0),outstanding:j.reduce((s,n)=>s+(n.total-n.paidAmount),0),overdueCount:j.filter(s=>s.status==="overdue").length},i=s=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(s/100),H=s=>{switch(s){case"draft":return e.jsx(m,{variant:"outline",children:"Draft"});case"sent":return e.jsx(m,{variant:"secondary",children:"Sent"});case"paid":return e.jsx(m,{className:"bg-green-500 hover:bg-green-600 text-white",children:"Paid"});case"partial":return e.jsx(m,{className:"bg-blue-500 hover:bg-blue-600 text-white",children:"Partial"});case"overdue":return e.jsx(m,{variant:"destructive",children:"Overdue"});case"void":return e.jsx(m,{variant:"outline",className:"opacity-50",children:"Void"});default:return e.jsx(m,{variant:"outline",children:s})}},se=()=>{const s=["Invoice #","Vendor","Customer","Total","Paid","Status","Date"],n=L.map(c=>{var K;return[c.invoiceNumber,((K=k.find(ae=>ae.id===c.vendorId))==null?void 0:K.fullName)||c.vendorId,c.customerName,(c.total/100).toFixed(2),(c.paidAmount/100).toFixed(2),c.status,c.createdAt?A(new Date(c.createdAt),"yyyy-MM-dd"):""]}),p=[s.join(","),...n.map(c=>c.join(","))].join(` 2`),M=new Blob([p],{type:"text/csv;charset=utf-8;"}),h=document.createElement("a"),te=URL.createObjectURL(M);h.setAttribute("href",te),h.setAttribute("download",`invoices_export_${A(new Date,"yyyy-MM-dd")}.csv`),h.style.visibility="hidden",document.body.appendChild(h),h.click(),document.body.removeChild(h)};return e.jsx(we,{children:e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-3",children:[e.jsx(le,{className:"h-8 w-8 text-primary"}),"Invoice Management"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Monitor and manage all vendor invoices across the platform"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{onClick:()=>X("/vendor/invoices/new"),className:"gap-2",children:[e.jsx(ie,{className:"h-4 w-4"}),"Create Invoice"]}),e.jsxs(g,{onClick:se,variant:"outline",className:"gap-2",children:[e.jsx(ce,{className:"h-4 w-4"}),"Export CSV"]})]})]}),e.jsxs(o,{className:"border-blue-100 bg-blue-50/40",children:[e.jsxs(N,{className:"pb-3",children:[e.jsxs(b,{className:"text-base flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4 text-blue-600"}),"BoatzHub Platform Fee"]}),e.jsxs(pe,{children:["This fee is deducted from vendor earnings on BoatzHub-branded invoices processed through Harbor OS. Current rate: ",e.jsxs("strong",{children:[F,"%"]})]})]}),e.jsxs(x,{children:[e.jsxs("div",{className:"flex items-center gap-3 max-w-sm",children:[e.jsx(O,{type:"number",min:"0",max:"50",step:"0.5",placeholder:F,value:y,onChange:s=>B(s.target.value),className:"w-28"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"%"}),e.jsx(g,{size:"sm",disabled:!y||P.isPending,onClick:()=>{const s=parseFloat(y);!isNaN(s)&&s>=0&&s<=50&&P.mutate(s)},children:P.isPending?"Savingâ¦":"Update Fee"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Enter a percentage between 0â50. Example: 10 = 10% platform commission on BoatzHub service invoices."})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(o,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Total Invoiced"}),e.jsx(R,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(x,{children:[e.jsx("div",{className:"text-2xl font-bold",children:i(C.totalInvoiced)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Lifetime across all vendors"})]})]}),e.jsxs(o,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Total Collected"}),e.jsx(de,{className:"h-4 w-4 text-green-500"})]}),e.jsxs(x,{children:[e.jsx("div",{className:"text-2xl font-bold",children:i(C.totalCollected)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Payments received"})]})]}),e.jsxs(o,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Outstanding"}),e.jsx(oe,{className:"h-4 w-4 text-amber-500"})]}),e.jsxs(x,{children:[e.jsx("div",{className:"text-2xl font-bold",children:i(C.outstanding)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Unpaid balance"})]})]}),e.jsxs(o,{children:[e.jsxs(N,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(b,{className:"text-sm font-medium",children:"Overdue"}),e.jsx(xe,{className:"h-4 w-4 text-destructive"})]}),e.jsxs(x,{children:[e.jsx("div",{className:"text-2xl font-bold text-destructive",children:C.overdueCount}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Requires attention"})]})]})]}),e.jsx(o,{children:e.jsx(x,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(I,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(O,{placeholder:"Search by invoice #, customer name or email...",value:v,onCh
2ange:s=>Z(s.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs(Q,{value:D,onValueChange:Y,children:[e.jsx($,{className:"w-[150px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(G,{placeholder:"Status"})]})}),e.jsxs(J,{children:[e.jsx(d,{value:"all",children:"All Statuses"}),e.jsx(d,{value:"draft",children:"Draft"}),e.jsx(d,{value:"sent",children:"Sent"}),e.jsx(d,{value:"paid",children:"Paid"}),e.jsx(d,{value:"partial",children:"Partial"}),e.jsx(d,{value:"overdue",children:"Overdue"}),e.jsx(d,{value:"void",children:"Void"})]})]}),e.jsxs(Q,{value:T,onValueChange:W,children:[e.jsx($,{className:"w-[200px]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(G,{placeholder:"Vendor"})]})}),e.jsxs(J,{children:[e.jsx(d,{value:"all",children:"All Vendors"}),k.map(s=>e.jsx(d,{value:s.id.toString(),children:s.fullName},s.id))]})]})]})]})})}),e.jsx(o,{children:e.jsx(x,{className:"p-0",children:e.jsxs(V,{children:[e.jsx(z,{children:e.jsxs(l,{children:[e.jsx(r,{children:"Invoice #"}),e.jsx(r,{children:"Vendor"}),e.jsx(r,{children:"Customer"}),e.jsx(r,{children:"Total"}),e.jsx(r,{children:"Status"}),e.jsx(r,{children:"Date"}),e.jsx(r,{className:"text-right",children:"Actions"})]})}),e.jsx(_,{children:ee?e.jsx(l,{children:e.jsx(a,{colSpan:7,className:"text-center py-8 text-muted-foreground italic",children:"Loading invoices..."})}):L.length===0?e.jsx(l,{children:e.jsx(a,{colSpan:7,className:"text-center py-8 text-muted-foreground italic",children:"No invoices found matching the criteria"})}):L.map(s=>{var n;return e.jsxs(l,{children:[e.jsx(a,{className:"font-medium",children:s.invoiceNumber}),e.jsx(a,{children:((n=k.find(p=>p.id===s.vendorId))==null?void 0:n.fullName)||`Vendor #${s.vendorId}`}),e.jsx(a,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.customerName}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.customerEmail})]})}),e.jsx(a,{children:i(s.total)}),e.jsx(a,{children:H(s.status)}),e.jsx(a,{children:s.createdAt?A(new Date(s.createdAt),"MMM d, yyyy"):"-"}),e.jsx(a,{className:"text-right",children:e.jsx(g,{variant:"ghost",size:"icon",onClick:()=>E(s),children:e.jsx(ue,{className:"h-4 w-4"})})})]},s.id)})})]})})}),e.jsx(fe,{open:!!t,onOpenChange:s=>!s&&E(null),children:e.jsxs(ge,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ne,{children:[e.jsxs(be,{className:"flex items-center justify-between",children:[e.jsxs("span",{children:["Invoice ",t==null?void 0:t.invoiceNumber]}),t&&H(t.status)]}),e.jsx(ve,{children:"Detailed view of invoice items and payment history"})]}),u?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:"Vendor"}),e.jsx("p",{className:"font-medium",children:u.vendor.fullName}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u.vendor.email})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:"Customer"}),e.jsx("p",{className:"font-medium",children:t==null?void 0:t.customerName}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==null?void 0:t.customerEmail}),(t==null?void 0:t.customerPhone)&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.customerPhone}),(t==null?void 0:t.customerAddress)&&e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.customerAddress})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:"Items"}),e.jsxs(V,{children:[e.jsx(z,{children:e.jsxs(l,{children:[e.jsx(r,{children:"Description"}),e.jsx(r,{className:"text-right",children:"Qty"}),e.jsx(r,{className:"text-right",children:"Price"}),e.jsx(r,{className:"text-right",children:"Total"})]})}),e.jsxs(_,{children:[u.items.map(s=>e.jsxs(l,{children:[e.jsx(a,{children:s.description}),e.jsx(a,{className:"text-right",children:s.quantity}),e.jsx(a,{className:"text-right",children:i(s.unitPrice)}),e.jsx(a,{className:"text-right",children:i(s.total)})]},s.id)),e.jsxs(l,{children:[e.jsx(a,{colSpan:3,className:"text-right font-medium",children:"Subtotal"}),e.jsx(a,{className:"text-right",children:i((t==null?void 0:t.subtotal)||0)})]}),t!=null&&t.taxAmount?e.jsxs(l,{children:[e.jsxs(a,{colSpan:3,className:"text-right font-medium text-muted-foreground",children:["Tax (",t.taxRate/100,"%)"]}),e.jsx(a,{className:"text-right text-muted-foreground",children:i(t.taxAmount)})]}):null,t!=null&&t.discountAmount?e.jsxs(l,{children:[e.jsx(a,{colSpan:3,className:"text-right font-medium text-destructive",children:"Discount"}),e.jsxs(a,{className:"text-right text-destructive",children:["-",
2i(t.discountAmount)]})]}):null,e.jsxs(l,{className:"text-lg",children:[e.jsx(a,{colSpan:3,className:"text-right font-bold",children:"Total"}),e.jsx(a,{className:"text-right font-bold",children:i((t==null?void 0:t.total)||0)})]})]})]})]}),u.payments.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:"Payment History"}),e.jsxs(V,{children:[e.jsx(z,{children:e.jsxs(l,{children:[e.jsx(r,{children:"Date"}),e.jsx(r,{children:"Method"}),e.jsx(r,{children:"Reference"}),e.jsx(r,{className:"text-right",children:"Amount"})]})}),e.jsx(_,{children:u.payments.map(s=>e.jsxs(l,{children:[e.jsx(a,{children:s.paidAt?A(new Date(s.paidAt),"MMM d, yyyy"):"-"}),e.jsx(a,{className:"capitalize",children:s.method.replace("_"," ")}),e.jsx(a,{className:"font-mono text-xs",children:s.referenceId||"-"}),e.jsx(a,{className:"text-right font-medium text-green-600",children:i(s.amount)})]},s.id))})]})]}),e.jsx("div",{className:"flex justify-end gap-3 pt-4 border-t",children:e.jsxs(g,{variant:"destructive",className:"gap-2",disabled:(t==null?void 0:t.status)==="void",onClick:async()=>{confirm("Are you sure you want to void this invoice?")},children:[e.jsx(he,{className:"h-4 w-4"}),"Void Invoice"]})})]}):e.jsx("div",{className:"py-8 text-center text-muted-foreground italic",children:"Loading details..."})]})})]})})}export{ke 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.