1import{c as W,l as L,Q as J,a0 as U,s as M,r as f,j as e,m as b,b as w,S as X,n as Y,o as Z,q as ee,t as T,I as se,B as te,u as P,i as re,P as ae,e as ne}from"./index-BCH4IFx8.js";import{B as v}from"./BpSpinner-Bqvfph1h.js";import{C as O,b as R,c as q,d as E,a as H}from"./card-DaE3Hwfn.js";import{T as S,a as C,b as j,c as a,d as k,e as n}from"./table-BgVITkDQ.js";import{O as ie}from"./OrganizationBadge-C2rDZhgC.js";import{O as de}from"./OrgPayoutsCard-DWOzHJqJ.js";import{P as oe}from"./PayoutStatusBanner-BvR45_NY.js";import{C as B}from"./checkbox-D7mWENF4.js";import{T as le}from"./textarea-C9Po2OuC.js";import{A as ce,b as me,c as xe,d as he,e as ue,f as fe,g as je,h as pe}from"./alert-dialog-CJdQZTQ5.js";import{E as I}from"./external-link-C5SQDLFH.js";import{f as p}from"./format-ybceeo2k.js";import"./building-2-DCnXAUm3.js";import"./usePayoutSchedule-wHtE8DVS.js";import"./useOrgStripeAccount-OJw6A_Z0.js";import"./banknote-CPxVp1Z4.js";import"./circle-alert-BU1rIcjn.js";import"./calendar-clock-BiSYhr8S.js";import"./triangle-alert-m5K6MENR.js";import"./info-D-iSIGln.js";import"./en-US-CGO0aXMi.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ge=W("Store",[["path",{d:"m2 7 4.41-4.41A2 2 0 0 1 7.83 2h8.34a2 2 0 0 1 1.42.59L22 7",key:"ztvudi"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}],["path",{d:"M15 22v-4a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4",key:"2ebpfo"}],["path",{d:"M2 7h20",key:"1fcdvo"}],["path",{d:"M22 7v3a2 2 0 0 1-2 2a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 16 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 12 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 8 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 4 12a2 2 0 0 1-2-2V7",key:"6c3vgh"}]]);function Ne(d){return L({queryKey:["goods-balance",d],enabled:!!d,queryFn:async()=>{const{data:i,error:r}=await M.functions.invoke("pos-goods-settlement-preview",{body:{organization_id:d}});if(r)throw r;if(i!=null&&i.error)throw new Error(i.error);return i}})}function ye(){const d=J();return U({mutationFn:async i=>{var x;const{data:r,error:m}=await M.functions.invoke("pos-goods-settlement-execute",{body:i});if(m){const l=m==null?void 0:m.context;let t=m.message;try{const o=await((x=l==null?void 0:l.json)==null?void 0:x.call(l));o!=null&&o.error&&(t=o.error)}catch{}throw new Error(t)}if(r!=null&&r.error)throw new Error(r.error);return r},onSuccess:(i,r)=>{d.invalidateQueries({queryKey:["goods-balance",r.organization_id]})}})}const c=d=>`$${Number(d||0).toFixed(2)}`;function _e({organizationId:d,canSettle:i=!1}){const{data:r,isLoading:m}=Ne(d),x=ye(),[l,t]=f.useState(new Set),[o,V]=f.useState("offline"),[A,$]=f.useState(""),[F,D]=f.useState(""),[z,_]=f.useState(!1),N=f.useMemo(()=>((r==null?void 0:r.items)||[]).filter(s=>s.status==="open"),[r]),u=N.filter(s=>l.has(s.id)),g=+u.reduce((s,h)=>s+h.amount,0).toFixed(2),G=s=>{t(h=>{const y=new Set(h);return y.has(s)?y.delete(s):y.add(s),y})},Q=N.length>0&&l.size===N.length;async function K(){if(d)try{const s=await x.mutateAsync({organization_id:d,item_ids:u.map(h=>h.id),confirm_total:g,method:o,reference:A||void 0,note:F||void 0});P.success(`Settled ${c(s.total)} across ${s.settled_count} line${s.settled_count===1?"":"s"}.`),t(new Set),$(""),D(""),_(!1)}catch(s){P.error(s.message||"Settlement failed")}}return d?e.jsxs(O,{"data-guide":"goods-settlements",children:[e.jsx(R,{children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4"})," Store Credit Spent at the Counter"]}),e.jsx(E,{children:"Wallet credit riders spent on parts and merchandise. Beyond Pro is holding this money, so it is paid back separately from race payouts."})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Owed now"}),e.jsx("div",{className:"text-2xl font-semibold",children:c((r==null?void 0:r.open_total)||0)})]})]})}),e.jsx(H,{className:"space-y-5",children:m?e.jsx(v,{className:"h-5 w-5 animate-spin"}):((r==null?void 0:r.items)||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"No store credit has been spent at the counter yet."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(S,{children:[e.jsx(C,{children:e.jsxs(j,{children:[i&&e.jsx(a,{className:"w-10",children:e.jsx(B,{checked:Q,onCheckedChange:s=>t(s?new Set(N.map(h=>h.id)):new Set),"aria-label":"Select all open lines"})}),e.jsx(a,{children:"Date"}),e.jsx(a,{children:"Rider"}),e.jsx(a,{children:"Taken by"}),e.jsx(a,{children:"Location"}),e.jsx(a,{className:"text-right",children:"Amount"}),e.jsx(a,{children:"Status"})]})}),e.jsx(k,{children:r.items.map(s=>e.jsxs(j,{children:[i&&e.jsx(n,{children:s.status==="open"?e.jsx(B,{checked:l.has(s.id),onCheckedChange:()=>G(s.id),"aria-label":`Select ${c(s.amount)}`}):null}),e.jsx(n,{className:"text-xs whitespace-nowrap",children:p(new Date(s.occurred_at),"MMM d, yyyy h:mm a")}),e.jsx(n,{children:s.rider_name||"â"}),e.jsx(n,{className:"text-muted-foreground",children:s.pos_user||"â"}),e.jsx(n,{className:"text-muted-foreground",children:s.pos_location||"â"}),e.jsx(n,{className:"text-right font-medium",children:c(s.amount)}),e.jsx(n,{children:e.jsx(b,{variant:s.status==="open"?"secondary":s.status==="settled"?"default":"outline",children:s.status==="open"?"Owed":s.status==="settled"?"Paid back":"Voided"})})]},s.id))})]})}),i&&e.jsxs("div",{className:"rounded-lg border p-4 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-3 items-end",children:[e.jsxs("div",{className:"w-56",children:[e.jsx(w,{className:"text-xs",children:"How is it being paid?"}),e.jsxs(X,{value:o,onValueChange:s=>V(s),children:[e.jsx(Y,{children:e.jsx(Z,{})}),e.jsxs(ee,{children:[e.jsx(T,{value:"offline",children:"Recorded outside Str
6ipe (check / credit)"}),e.jsx(T,{value:"stripe_transfer",children:"Transfer to connected account"})]})]})]}),e.jsxs("div",{className:"w-56",children:[e.jsx(w,{className:"text-xs",htmlFor:"goods-ref",children:"Reference"}),e.jsx(se,{id:"goods-ref",value:A,onChange:s=>$(s.target.value),placeholder:"Check #, memo"})]}),e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsx(w,{className:"text-xs",htmlFor:"goods-note",children:"Note"}),e.jsx(le,{id:"goods-note",rows:1,value:F,onChange:s=>D(s.target.value)})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[u.length," line",u.length===1?"":"s"," selected ·"," ",e.jsx("span",{className:"font-semibold text-foreground",children:c(g)})]}),e.jsx(te,{disabled:u.length===0||x.isPending,onClick:()=>_(!0),children:x.isPending?"Workingâ¦":`Pay back ${c(g)}`})]})]}),((r==null?void 0:r.settlements)||[]).length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Payments already made"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(S,{children:[e.jsx(C,{children:e.jsxs(j,{children:[e.jsx(a,{children:"Date"}),e.jsx(a,{className:"text-right",children:"Amount"}),e.jsx(a,{children:"Method"}),e.jsx(a,{children:"Reference"}),e.jsx(a,{children:"Status"})]})}),e.jsx(k,{children:r.settlements.map(s=>e.jsxs(j,{children:[e.jsx(n,{className:"text-xs whitespace-nowrap",children:p(new Date(s.paid_at||s.created_at),"MMM d, yyyy")}),e.jsx(n,{className:"text-right font-medium",children:c(s.total_amount)}),e.jsxs(n,{className:"text-muted-foreground",children:[s.method==="str
6ipe_transfer"?"Bank transfer":"Outside Stripe",s.stripe_transfer_id&&e.jsx("a",{href:`https://dashboard.stripe.com/transfers/${s.stripe_transfer_id}`,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center ml-1",children:e.jsx(I,{className:"h-3 w-3"})})]}),e.jsx(n,{className:"text-muted-foreground",children:s.reference||"â"}),e.jsx(n,{children:e.jsx(b,{variant:s.status==="paid"?"default":"destructive",children:s.status})})]},s.id))})]})})]})]})}),e.jsx(ce,{open:z,onOpenChange:_,children:e.jsxs(me,{children:[e.jsxs(xe,{children:[e.jsxs(he,{children:["Pay back ",c(g),"?"]}),e.jsx(ue,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{children:o==="stripe_transfer"?"This sends real money to the connected bank account.":"This records the payment as already made outside Stripe. No money moves automatically."}),e.jsx("ul",{className:"max-h-56 overflow-y-auto space-y-1",children:u.map(s=>e.jsxs("li",{className:"flex justify-between gap-4",children:[e.jsxs("span",{children:[s.rider_name||"Rider"," · ",p(new Date(s.occurred_at),"MMM d")]}),e.jsx("span",{className:"font-medium",children:c(s.amount)})]},s.id))})]})})]}),e.jsxs(fe,{children:[e.jsx(je,{children:"Cancel"}),e.jsxs(pe,{onClick:s=>{s.preventDefault(),K()},children:["Confirm ",c(g)]})]})]})})]}):null}function we(d){return d==="paid"?"default":d==="failed"?"destructive":d==="draft"||d==="approved"||d==="processing"?"secondary":"outline"}function ze(){const d=re(),{currentOrganization:i,isLoading:r}=ae(),{isSuperAdmin:m}=ne(),{data:x,isLoading:l}=L({queryKey:["admin-payouts-page",i==null?void 0:i.id],enabled:!!(i!=null&&i.id),queryFn:async()=>{const{data:t,error:o}=await M.from("organization_payouts").select("id, period_start, period_end, gross_revenue, refunds_deducted, platform_fee_cost, stripe_fee_cost, timing_cost, messaging_cost, ai_cost, manual_adjustment, carry_forward_amount, transfer_fee_cost, net_before_transfer_fee, net_amount, status, paid_at, failure_message, stripe_transfer_id").eq("organization_id",i.id).order("created_at",{ascending:!1}).limit(100);if(o)throw o;return t||[]}});return r||!i?e.jsx("div",{className:"flex items-center justify-center p-12",children:e.jsx(v,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"container max-w-6xl py-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Payouts"}),e.jsx(ie,{})]}),e.jsx(oe,{organizationId:i.id}),e.jsx("div",{"data-guide":"payouts-connection",children:e.jsx(de,{organizationId:i.id})}),e.jsx(_e,{organizationId:i.id,canSettle:m}),e.jsxs(O,{"data-guide":"payouts-breakdown",children:[e.jsxs(R,{children:[e.jsx(q,{children:"Fee Breakdown"}),e.jsx(E,{children:"Itemized deductions for each payout, including the Stripe ACH transfer fee ($0.25 + 0.25%)."})]}),e.jsx(H,{children:l?e.jsx(v,{className:"h-5 w-5 animate-spin"}):(x||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-8 text-center",children:"No payouts yet. Once a weekly run completes, the breakdown will appear here."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(S,{children:[e.jsx(C,{children:e.jsxs(j,{children:[e.jsx(a,{children:"Period"}),e.jsx(a,{className:"text-right",children:"Gross"}),e.jsx(a,{className:"text-right",children:"Refunds"}),e.jsx(a,{className:"text-right",children:"Platform"}),e.jsx(a,{className:"text-right",children:"Stripe Fees"}),e.jsx(a,{className:"text-right",children:"Timing"}),e.jsx(a,{className:"text-right",children:"Messaging"}),e.jsx(a,{className:"text-right",children:"AI"}),e.jsx(a,{className:"text-right",children:"Adjust."}),e.jsx(a,{className:"text-right",children:"Carry-fwd"}),e.jsx(a,{className:"text-right",children:"ACH Fee"}),e.jsx(a,{className:"text-right font-semibold",children:"Net"}),e.jsx(a,{children:"Status"}),e.jsx(a,{children:"Paid"})]})}),e.jsx(k,{children:x.map(t=>{const o=Number(t.carry_forward_amount||0);return e.jsxs(j,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>d(`/admin/payouts/${t.id}`),children:[e.jsxs(n,{className:"text-xs whitespace-nowrap",children:[p(new Date(t.period_start),"MMM d")," â ",p(new Date(t.period_end),"MMM d, yyyy")]}),e.jsxs(n,{className:"text-right",children:["$",Number(t.gross_revenue).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.refunds_deducted).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.platform_fee_cost).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.stripe_fee_cost||0).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.timing_cost).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.messaging_cost).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.ai_cost).toFixed(2)]}),e.jsxs(n,{className:"text-right text-muted-foreground",children:[Number(t.manual_adjustment)>=0?"+":"â","$",Math.abs(Number(t.manual_adjustment)).toFixed(2)]}),e.jsx(n,{className:"text-right text-muted-foreground",children:o===0?"â":`${o>0?"+":"â"}$${Math.abs(o).toFixed(2)}`}),e.jsxs(n,{className:"text-right text-muted-foreground",children:["â$",Number(t.transfer_fee_cost||0).toFixed(2)]}),e.jsxs(n,{className:"text-right font-semibold",children:["$",Number(t.
6net_amount).toFixed(2)]}),e.jsx(n,{children:e.jsx(b,{variant:we(t.status),children:t.status})}),e.jsx(n,{className:"text-xs whitespace-nowrap",children:t.paid_at?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:p(new Date(t.paid_at),"MMM d, yyyy")}),t.stripe_transfer_id&&e.jsx("a",{href:`https://dashboard.stripe.com/transfers/${t.stripe_transfer_id}`,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline inline-flex items-center",title:"View transfer in Stripe",children:e.jsx(I,{className:"h-3 w-3"})})]}):"â"})]},t.id)})})]})})})]})]})}export{ze 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.