1import{j as e}from"./ui-vendor-B12AOeKi.js";import{r as i}from"./react-vendor-DZt7wVAJ.js";import{j as U,l as m,s as H,q as v,v as P,w as E,B as q,P as M,y as $,g as z,a6 as K,i as O}from"./index-BZo64Z7H.js";import{T as V}from"./TimeframeSelector-BW0RA7ac.js";import{C as W}from"./CommissionTabsNav-C2msRlia.js";import{u as G}from"./useCommissionSettings-By2Lw2Cq.js";import{u as J}from"./useUnifiedCommissionTotals-CAmcOaBC.js";import{u as Q}from"./useInternetSalesSheets-CaEmYHkK.js";import{C as X}from"./circle-check-BmAvJLJ8.js";import"./charts-vendor-B6q1L48j.js";import"./supabase-vendor-dOy44Gxq.js";import"./animation-vendor-BAVy02gd.js";import"./calendar-Coi13cMa.js";import"./startOfMonth-DfZBZCut.js";import"./endOfMonth-Nvm-8vcq.js";import"./isSameMonth-DMl9Rcgm.js";import"./differenceInCalendarMonths-iM3p2kUt.js";import"./isBefore-DXiNDavF.js";import"./isSameDay-CKSdjr0s.js";import"./addDays-ChKiAedE.js";import"./subDays-BDE3YX0d.js";import"./chevron-left-CP12o6-_.js";import"./layout-dashboard-DvAedGcl.js";import"./globe-CjSiEoEQ.js";import"./tv-C87PQC1U.js";import"./clipboard-check-DOlT3YWq.js";import"./useCommissionData-BmTBwgVg.js";import"./useReconciliations-DXgx4vjW.js";import"./useScoreboardMetrics-OtCwyr22.js";const x=c=>`$${(c||0).toFixed(2)}`;function Ee(){const{isAdmin:c,isManager:T}=U(),A=c||T,{getPayPeriodDates:h,isLoading:y}=G(),{reviewSheet:D,fetchSubmittedSheets:u}=Q(),[r,f]=i.useState(""),[n,j]=i.useState(""),[g,I]=i.useState("Current Pay Period"),[o,L]=i.useState([]),[k,N]=i.useState({}),[b,w]=i.useState(!1);i.useEffect(()=>{if(y)return;const{start:s,end:a}=h("current");f(m(s,"yyyy-MM-dd")),j(m(a,"yyyy-MM-dd"))},[y,h]);const p=i.useCallback(async()=>{if(!r||!n)return;const a=(await u()).filter(t=>t.status==="submitted"&&t.pay_period_start>=r&&t.pay_period_end<=n);L(a);const l=[...new Set(a.map(t=>t.salesperson_id))];if(l.length){const{data:t}=await H.from("registration_users").select("id, name").in("id",l),C={};(t||[]).forEach(S=>C[S.id]=S.name),N(C)}else N({})},[r,n,u]);i.useEffect(()=>{p()},[p]);const{rows:d,isLoading:_}=J(r||null,n||null),B=i.useCallback((s,a,l)=>{s&&a&&(f(m(s,"yyyy-MM-dd")),j(m(a,"yyyy-MM-dd")),I(l))},[]),F=async()=>{if(o.length===0)return;w(!0);let s=0;for(const a of o)await D(a.id,"approved")&&s++;w(!1),O.success(`${s} of ${o.length} sheets approved`),await p()},R=i.useMemo(()=>{const a=[["Employee","Pay Period Start","Pay Period End","Sales Deals","Sales Commission","Internet Entries","Internet Commission","Total"].join(",")];d.forEach(t=>{a.push([`"${t.name.replace(/"/g,'""')}"`,r,n,t.salesDeals,t.salesCommission.toFixed(2),t.internetEntries,t.internetCommission.toFixed(2),t.total.toFixed(2)].join(","))});const l=new Blob([a.join(` 2`)],{type:"text/csv"});return URL.createObjectURL(l)},[d,r,n]);return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(W,{}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 p-4 border-b",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Accounting · Payroll Export"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[g," ·"," ",r&&n&&`${m(new Date(r+"T00:00:00"),"MMM d")} â ${m(new Date(n+"T00:00:00"),"MMM d, yyyy")}`]})]}),e.jsx(V,{onDateRangeChange:B,currentLabel:g,showPayPeriods:!0})]}),e.jsxs("div",{className:"p-4 max-w-7xl mx-auto space-y-4",children:[e.jsxs(v,{children:[e.jsxs(P,{className:"pb-2 flex-row items-center justify-between",children:[e.jsx(E,{className:"text-base",children:"Pending Internet Sales Approvals"}),A&&o.length>0&&e.jsxs(q,{onClick:F,disabled:b,size:"sm",children:[b?e.jsx(M,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(X,{className:"h-4 w-4 mr-1"}),"Approve All (",o.length,")"]})]}),e.jsx($,{children:o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No pending sheets in this pay period."}):e.jsx("ul",{className:"text-sm divide-y",children:o.map(s=>e.jsxs("li",{className:"py-2 flex items-center justify-between",children:[e.jsx("span",{children:k[s.salesperson_id]||"Unknown"}),e.jsx(z,{variant:"secondary",children:"Submitted"})]},s.id))})})]}),e.jsxs(v,{children:[e.jsxs(P,{className:"pb-2 flex-row items-center justify-between",children:[e.jsx(E,{className:"text-base",children:"Combined Payroll Summary"}),e.jsxs("a",{href:R,download:`commission-payroll-${r}-to-${n}.csv`,className:"inline-flex items-center gap-1 text-sm bg-primary text-primary-foreground px-3 py-1.5 rounded-md hover:opacity-90",children:[e.jsx(K,{className:"h-4 w-4"})," Export CSV"]})]}),e.jsx($,{children:_?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(M,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No commission data in this period."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-xs text-muted-foreground",children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-2",children:"Employee"}),e.jsx("th",{className:"text-right py-2",children:"Sales Deals"}),e.jsx("th",{className:"text-right py-2",children:"Sales $"}
2),e.jsx("th",{className:"text-right py-2",children:"ISC Entries"}),e.jsx("th",{className:"text-right py-2",children:"Internet $"}),e.jsx("th",{className:"text-right py-2",children:"Total Pay"})]})}),e.jsx("tbody",{children:d.map(s=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"py-2 font-medium",children:s.name}),e.jsx("td",{className:"py-2 text-right",children:s.salesDeals}),e.jsx("td",{className:"py-2 text-right",children:x(s.salesCommission)}),e.jsx("td",{className:"py-2 text-right",children:s.internetEntries}),e.jsx("td",{className:"py-2 text-right",children:x(s.internetCommission)}),e.jsx("td",{className:"py-2 text-right font-semibold",children:x(s.total)})]},s.employeeKey))})]})})})]})]})]})}export{Ee 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.