PageSourceSearch

https://cpaautomation.ai/_next/static/chunks/9412.75636864297e8832.js

js cpaautomation.ai collected 2026-10-05 15:33:33 UTC 28,477 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9412],{14556:(e,t,n)=>{n.d(t,{AF:()=>c,YD:()=>u,MS:()=>m,lO:()=>s,QJ:()=>d,xc:()=>p,Vf:()=>o});var r=n(69992);function a(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return e.reduce((e,r)=>{var a;let l=r.currency.toUpperCase(),i=r.amount;if(t&&l!==t.toUpperCase()&&r.fxQuoteId){let e=n.find(e=>e.id===r.fxQuoteId);e&&e.baseCurrency===l&&e.quoteCurrency===t.toUpperCase()&&(l=t.toUpperCase(),i*=e.rate)}return e[l]=Math.round(((null!=(a=e[l])?a:0)+i+Number.EPSILON)*100)/100,e},{})}let l=new Set(["approved","submitted"]),i=new Set(["approved","submitted"]);function o(e,t){return e.filter(e=>{var t;return e.billable&&!e.invoiceId&&l.has(null!=(t=e.status)?t:"draft")&&(e.approved||"submitted"===e.status||"approved"===e.status)}).reduce((e,t)=>{var n,a;return e+(null!=(a=t.amount)?a:(null!=(n=t.rateSnapshot)?n:0)*(0,r.G9)(t))},0)+t.filter(e=>{var t;return e.billable&&!e.invoiceId&&i.has(null!=(t=e.status)?t:"draft")}).reduce((e,t)=>{var n,r;
1return e+(null!=(r=null!=(n=t.billableAmount)?n:t.totalAmount)?r:t.amount)},0)}function s(e){let t=e.filter(e=>"billed"===e.status),n=t.reduce((e,t)=>{var n;return e+(null!=(n=t.rateSnapshot)?n:0)*(0,r.G9)(t)},0),a=t.reduce((e,t)=>{var n;return e+(null!=(n=t.amount)?n:0)},0);return n>0?a/n:0}function d(e,t){return t>0?e/t*100:0}function u(e){let t=e.filter(e=>e.billable&&"billed"===e.status),n=t.reduce((e,t)=>e+(0,r.G9)(t),0),a=t.reduce((e,t)=>{var n;return e+(null!=(n=t.amount)?n:0)},0);return n>0?a/n:0}function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date,n={Current:{},"1-30":{},"31-60":{},"61-90":{},"90+":{}},r=t.toISOString().slice(0,10);for(let t of e){var l,i,o;let e=null!=(i=t.amountOutstanding)?i:t.amount-(null!=(l=t.amountPaid)?l:0);if(e<=0||["void","paid","written_off"].includes(t.status))continue;let s=Math.floor((new Date(r).getTime()-new Date(t.dueOn).getTime())/864e5),d=s<=0?"Current":s<=30?"1-30":s<=60?"31-60":s<=90?"61-90":"90+";n[d]=a([...Object.entries(n[d]).map(e=>{let[t,n]=e;return{currency:t,amount:n}}),{currency:null!=(o=t.currency)?o:"USD",amount:e,fxQuoteId:t.fxQuoteId}])}return n}function m(e){return a(e.filter(e=>!["void","paid","written_off"].includes(e.status)).map(e=>{var t,n,r;return{currency:null!=(t=e.currency)?t:"USD",amount:null!=(r=e.amountOutstanding)?r:e.amount-(null!=(n=e.amountPaid)?n:0),fxQuoteId:e.fxQuoteId}}))}function p(e,t){return a([...e.filter(e=>{var t;return e.billable&&!e.invoiceId&&l.has(null!=(t=e.status)?t:"draft")}).map(e=>{var t,n,a;return{currency:null!=(t=e.currency)?t:"USD",amount:null!=(a=e.amount)?a:(null!=(n=e.rateSnapshot)?n:0)*(0,r.G9)(e)}}),...t.filter(e=>{var t;return e.billable&&!e.invoiceId&&i.has(null!=(t=e.status)?t:"draft")}).map(e=>{var t,n,r;return{currency:null!=(t=e.currency)?t:"USD",amount:null!=(r=null!=(n=e.billableAmou
1nt)?n:e.totalAmount)?r:e.amount}})])}},21812:(e,t,n)=>{n.d(t,{Z:()=>r,u:()=>a});let r={draft:"Draft",pending_approval:"Pending approval",approved:"Approved",sent:"Sent",paid:"Paid",partial:"Partial",overdue:"Overdue",void:"Void",written_off:"Written off"};function a(e){return"".concat(e," ").concat(1===e?"invoice":"invoices")}},27656:(e,t,n)=>{n.d(t,{He:()=>p,JD:()=>d,Jq:()=>s,UA:()=>c,ZM:()=>v,eE:()=>u,kQ:()=>h,om:()=>m,zv:()=>g});var r=n(70935),a=n(54727),l=n(25139);let i=()=>({"Idempotency-Key":crypto.randomUUID()});async function o(e){var t,n;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};await (null==(t=(n=(0,a.T)()).refreshSnapshot)?void 0:t.call(n,e)),await Promise.all([l.Xv.getState().hydrate(),l.r7.getState().hydrate(),l.cA.getState().hydrate(),r.sources?l.ik.getState().hydrate():Promise.resolve(),r.sources?l.iL.getState().hydrate():Promise.resolve(),r.payments?l.gH.getState().hydrate():Promise.resolve(),r.trust?l.KC.getState().hydrate():Promise.resolve(),r.trust?l.bR.getState().hydrate():Promise.resolve(),r.fx?l.EV.getState().hydrate():Promise.resolve()])}async function s(e,t){let n=await (0,r.ZU)("/billing/invoices:generate",{method:"POST",headers:i(),body:JSON.stringify({workspaceId:e,...t})});return await o(e,{sources:!0}),n.invoice}async function d(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},l=await (0,r.ZU)("/billing/invoices/".concat(e,":").concat(t),{method:"POST",headers:i(),body:JSON.stringify({workspaceId:n,...a})});return await o(n,{sources:"void"===t}),l.invoice}async function u(e,t,n){let a=await (0,r.ZU)("/billing/invoices/".concat(e,":payment"),{method:"POST",headers:i(),body:JSON.stringify({workspaceId:t,...n})});return await o(t,{payments:!0,trust:"trust_application"===n.method}),a}async function c(e,t,n){await (0,r.ZU)("/billing/payments/".concat(e,":reverse"),{method:"POST",headers:i(),body:JSON.stringify({workspaceId:t,reason:n})}),await o(t,{payments:!0,trust:!0})}async function m(e,t){let n=await (0,r.ZU)("/billing/trust:record",{method:"POST",headers:i(),body:JSON.stringify({workspaceId:e,...t})});return await o(e,{trust:!0}),n.transaction}async function p(e,t,n){await (0,r.ZU)("/billing/trust/".concat(e,":reverse"),{method:"POST",headers:i(),body:JSON.stringify({workspaceId:t,reason:n})}),await o(t,{trust:!0})}async function v(e,t){let n=await (0,r.ZU)("/billing/fx:quote",{method:"POST",headers:i(),body:JSON.stringify({workspaceId:e,...t})});return await o(e,{fx:!0}),n.quote}async function h(e){let t=await (0,r.LX)("/billing/invoices/".concat(e.id,"/pdf?workspace_id=").concat(encodeURIComponent(e.workspaceId)),{headers:{Accept:"application/pdf"}});if(!t.ok)throw Error("Invoice PDF failed: ".concat(t.status));let n=URL.createObjectURL(await t.blob()),a=document.createElement("a");a.href=n,a.download="".concat(e.invoiceNumber,".pdf"),a.click(),URL.revokeObjectURL(n)}async function g(e){return(await (0,r.ZU)("/billing/invoices/".concat(e.id,":payment-link"),{method:"POST",body:JSON.stringify({workspaceId:e.workspaceId,successUrl:"".concat(window.location.origin,"/dashboard/project-management?payment=success"),cancelUrl:window.location.href})})).url}},67812:(e,t,n)=>{n.d(t,{E:()=>o});var r=n(95155);n(12115);var a=n(83101),l=n(25016);let i=(0,a.F)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function o(e){let{className:t,variant:n,...a}=e;return(0,r.jsx)("div",{className:(0,l.cn)(i({variant:n}),t),...a})}},69992:(e,t,n)=>{function r(e){return null!=e.durationMinutes?e.durationMinutes/60:e.hours}function a(e){let t=Math.round(60*e),n=Math.floor(t/60);return"".concat(n,":").concat(String(t%60).padStart(2,"0"))}function l(e){let t=e.trim();if(!t)return null;let n=parseFloat(t);if(!Number.isNaN(n)&&/^\d+(\.\d+)?$/.test(t))return n;let r=t.match(/^(\d+):(\d{1,2})$/);if(r)return parseInt(r[1],10)+parseInt(r[2],10)/60;let a=t.match(/(?:(\d+(?:\.\d+)?)\s*h)?\s*(?:(\d+)\s*m)?/i);return a&&(a[1]||a[2])?(a[1]?parseFloat(a[1]):0)+(a[2]?parseInt(a[2],10)/60:0):null}function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"monday",n=new Date(e),r=n.getDay();n.setDate(n.getDate()+("monday"===t?0===r?-6:1-r:-r));let a=n.toISOString().slice(0,10),l=new Date(n);return l.setDate(l.getDate()+6),{start:a,end:l.toISOString().slice(0,10)}}function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"monday",{start:n}=i(e,t),r=[],a=new Date(n);for(let e=0;e<7;e++)r.push(a.toISOString().slice(0,10)),a.setDate(a.getDate()+1);return r}n.d(t,{AX:()=>i,Bg:()=>a,G9:()=>r,Mq:()=>o,ew:()=>l})},87031:(e,t,n)=>{n.r(t),n.d(t,{InvoicingPage:()=>M});var r=n(95155),a=n(12115),l=n(52619),i=n.n(l),o=n(6191),s=n(97003),d=n(67812),u=n(3637),c=n(69995),m=n(48850),p=n(25139),v=n(70934),h=n(21812),g=n(14556),f=n(46395),x=n(33789),b=n(90235),y=n(47507),j=n(54679),S=n(67001),N=n(38585),I=n(87460),w=n(69992),C=n(27656),D=n(70935);let k=/^(\d{4})-(\d{2})-(\d{2})$/;function O(e){let t=k.exec(e);if(!t)return!1;let[,n,r,a]=t;return new Date(Date.UTC(Number(n),Number(r)-1,Number(a))).toISOString().slice(0,10)===e}function P(e,t){return O(e)&&e>=t.start&&e<=t.end}function A(e,t){if(e.startsWith("matter:"))return t.find(t=>
1t.id===e.slice(7))}function U(e,t,n){if("all"===t)return!0;if(t.startsWith("project:"))return e.projectId===t.slice(8);let r=A(t,n);return!!(r&&(e.matterId===r.id||e.projectId===r.projectId))}var E=n(29297);function L(e){var t,n,l,i,o,d,u,c,h,g,f,k,L,M,T,J,B,_;let{open:F,onOpenChange:q,workspaceId:Z}=e,z=(0,p.bR)(e=>e.list().filter(e=>e.workspaceId===Z&&!e.archived)),$=(0,p.ik)(e=>e.list()),G=(0,p.iL)(e=>e.list()),R=(0,p.f8)(e=>e.list().filter(e=>e.workspaceId===Z)),Q=(0,p.bs)(e=>e.list().filter(e=>e.workspaceId===Z)),V=(0,p.BN)(e=>e.getById(Z)),W=(0,m.nc)(e=>e.currentUserId),[X,H]=(0,a.useState)(1),[K,Y]=(0,a.useState)(""),[ee,et]=(0,a.useState)("all"),[en,er]=(0,a.useState)(""),[ea,el]=(0,a.useState)(""),[ei,eo]=(0,a.useState)("0"),[es,ed]=(0,a.useState)("0"),[eu,ec]=(0,a.useState)(""),[em,ep]=(0,a.useState)(""),[ev,eh]=(0,a.useState)(""),[eg,ef]=(0,a.useState)(new Date().toISOString().slice(0,10)),[ex,eb]=(0,a.useState)(null!=(f=null==V||null==(t=V.billingSettings)?void 0:t.defaultLinePresentation)?f:(null==V?void 0:V.psaMode)==="legal"?"detailed":"summary"),[ey,ej]=(0,a.useState)(""),[eS,eN]=(0,a.useState)(""),[eI,ew]=(0,a.useState)(""),[eC,eD]=(0,a.useState)(""),[ek,eO]=(0,a.useState)(""),[eP,eA]=(0,a.useState)(""),[eU,eE]=(0,a.useState)(new Set),[eL,eM]=(0,a.useState)(new Set),[eT,eJ]=(0,a.useState)(""),[eB,e_]=(0,a.useState)({}),[eF,eq]=(0,a.useState)(!1),[eZ,ez]=(0,a.useState)(""),[e$,eG]=(0,a.useState)([]),[eR,eQ]=(0,a.useState)(!1),eV=z.find(e=>e.id===K),eW=A(ee,R),eX=(0,a.useMemo)(()=>$.filter(e=>e.workspaceId===Z&&e.clientId===K&&e.billable&&("approved"===e.status||e.approved)&&!e.invoiceId),[$,Z,K]),eH=(0,a.useMemo)(()=>G.filter(e=>e.workspaceId===Z&&e.clientId===K&&e.billable&&("approved"===e.status||e.approved)&&!e.invoiceId),[G,Z,K]),eK=(0,a.useMemo)(()=>eX.filter(e=>U(e,ee,R)),[eX,ee,R]),eY=(0,a.useMemo)(()=>eH.filter(e=>U(e,ee,R)),[eH,ee,R]),e0=(0,a.useMemo)(()=>(function(e,t,n){if(!e)return{period:null,error:"Select a period start date.",sourceCount:0};if(!t)return{period:null,error:"Select a period end date.",sourceCount:0};if(!O(e)||!O(t))return{period:null,error:"Enter a valid invoice period.",sourceCount:0};if(e>t)return{period:null,error:"Period start must be on or before period end.",sourceCount:0};let r={start:e,end:t},a=n.filter(e=>P(e.date,r)).length;return 0===a?{period:null,error:"No approved, unbilled time or expenses fall within this period.",sourceCount:a}:{period:r,error:null,sourceCount:a}})(en,ea,[...eK,...eY]),[en,ea,eK,eY]),e1=e0.period,e2=(0,a.useMemo)(()=>e1?eK.filter(e=>P(e.date,e1)):[],[e1,eK]),e9=(0,a.useMemo)(()=>e1?eY.filter(e=>P(e.date,e1)):[],[e1,eY]),e3=eW&&e1?eX.filter(e=>P(e.date,e1)).length+eH.filter(e=>P(e.date,e1)).length-e2.length-e9.length:0;(0,a.useEffect)(()=>{var e,t,n,r,a,l;let i=p.bR.getState().getById(K);et("all"),er(""),el(""),eE(new Set),eM(new Set),e_({}),ej(null!=(e=null==i?void 0:i.name)?e:""),eN(null!=(t=null==i?void 0:i.contactName)?t:""),ew(null!=(n=null==i?void 0:i.contactEmail)?n:""),eD(null!=(r=null==i?void 0:i.contactPhone)?r:""),eO(null!=(a=null==i?void 0:i.billingAddress)?a:""),eA(null!=(l=null==i?void 0:i.taxId)?l:"")},[K]);let e5=(0,a.useMemo)(()=>e2.filter(e=>!eU.has(e.id)&&!eL.has(e.id)),[e2,eU,eL]),e6=(0,a.useMemo)(()=>e9.filter(e=>!eU.has(e.id)&&!eL.has(e.id)),[e9,eU,eL]),e4=(0,a.useMemo)(()=>{var e,t;if(!eV||!e1)return null;let n=p.Xv.getState().list().filter(e=>e.workspaceId===Z),r="".concat(null!=(e=null==V?void 0:V.invoicePrefix)?e:"INV-").concat(String((null!=(t=null==V?void 0:V.invoiceStartNumber)?t:1e3)+n.length));return function(e){var t,n,r,a;let l=[],i=0,o=0;e.timeEntries.forEach(e=>{var t,n;let r=(0,w.G9)(e),a=null!=(t=e.rateSnapshot)?t:0,o=null!=(n=e.amount)?n:a*r;i+=o,l.push({description:e.description,quantity:r,rate:a,type:"time",sourceId:e.id})}),e.expenses.forEach(e=>{var t,n;
1let r=null!=(n=null!=(t=e.billableAmount)?t:e.totalAmount)?n:e.amount;o+=r,l.push({description:"".concat(e.description," (").concat(e.category,")"),quantity:1,rate:r,type:"expense",sourceId:e.id})});let s=null!=(t=e.discountAmount)?t:0,d=null!=(n=e.taxAmount)?n:0,u=null!=(r=e.trustApplied)?r:0,c=i+o-s+d-u,m=new Date;return m.setDate(m.getDate()+30),{id:(0,N.S)(),workspaceId:e.workspaceId,clientId:e.clientId,clientName:e.clientName,matterId:e.matterId,invoiceNumber:e.invoiceNumber,issueDate:(0,I.$$)(new Date),status:"draft",amount:c,total:c,dueOn:(0,I.$$)(m),periodStart:e.periodStart,periodEnd:e.periodEnd,timeEntryIds:e.timeEntries.map(e=>e.id),expenseIds:e.expenses.map(e=>e.id),subtotalFees:i,subtotalExpenses:o,discountAmount:s,taxAmount:d,trustApplied:u,amountPaid:0,amountOutstanding:c,currency:null!=(a=e.currency)?a:"USD",lineItems:l,createdAt:(0,I.tB)()}}({workspaceId:Z,clientId:K,clientName:eV.name,periodStart:e1.start,periodEnd:e1.end,timeEntries:e5,expenses:e6,invoiceNumber:r,currency:eV.defaultCurrency,taxAmount:parseFloat(ei)||0,discountAmount:parseFloat(es)||0})},[eV,K,e5,e6,e1,ei,es,V,Z]),e7=(0,a.useMemo)(()=>{let e=[...e5.map(e=>{var t,n,r,a,l,i,o;return{id:e.id,serviceDate:e.date,description:null!=(n=eB[e.id])?n:e.description,professionalCategory:"Professional services",matterProjectLabel:null!=(r=null==(t=Q.find(t=>t.id===e.projectId))?void 0:t.name)?r:"General",quantity:e.hours,rate:null!=(l=e.rateSnapshot)?l:(null!=(a=e.amount)?a:0)/(e.hours||1),amount:null!=(o=e.amount)?o:e.hours*(null!=(i=e.rateSnapshot)?i:0)}}),...e6.map(e=>{var t,n,r,a,l,i,o;return{id:e.id,serviceDate:e.date,description:null!=(n=eB[e.id])?n:e.description,professionalCategory:e.category.replace(/_/g," "),matterProjectLabel:null!=(r=null==(t=Q.find(t=>t.id===e.projectId))?void 0:t.name)?r:"General",quantity:1,rate:null!=(l=null!=(a=e.billableAmou
1nt)?a:e.totalAmount)?l:e.amount,amount:null!=(o=null!=(i=e.billableAmount)?i:e.totalAmount)?o:e.amount}})];if("detailed"===ex)return e;let t=new Map;return e.forEach(e=>{let n="".concat(e.matterProjectLabel,":").concat("Professional services"===e.professionalCategory?"services":"expenses"),r=t.get(n);t.set(n,r?{...r,amount:r.amount+e.amount,description:"Professional services"===r.professionalCategory?"Professional services":"Reimbursable expenses"}:{...e,id:n,description:"Professional services"===e.professionalCategory?"Professional services":"Reimbursable expenses"})}),[...t.values()]},[e6,e5,ex,eB,Q]),e8=async()=>{if(!e4||!W||!e1)return;let e=e1.start,t=e1.end;eq(!0),ez(""),eG([]),eQ(!1);try{var n,r,a,l,i,o;let s=null!=(l=null!=(a=null==eV?void 0:eV.defaultCurrency)?a:null==V?void 0:V.defaultCurrency)?l:"USD",d=new Set([...e2.filter(e=>!eU.has(e.id)).map(e=>{var t;return null!=(t=e.currency)?t:s}),...e9.filter(e=>!eU.has(e.id)).map(e=>{var t;return null!=(t=e.currency)?t:s})]),u=[];for(let e of d){if(e===s)continue;let n=await (0,C.ZM)(Z,{baseCurrency:e,quoteCurrency:s,rateDate:t});u.push(n.id)}await (0,C.Jq)(Z,{clientId:K,matterId:null==eW?void 0:eW.id,timeEntryIds:e2.filter(e=>!eU.has(e.id)).map(e=>e.id),expenseIds:e9.filter(e=>!eU.has(e.id)).map(e=>e.id),writeOffIds:[...eL],writeOffReason:eT,narratives:eB,currency:s,fxQuoteIds:u,periodStart:e,periodEnd:t,issueDate:eg,dueOn:ev||void 0,taxAmount:Number(ei)||0,discountAmount:Number(es)||0,discountReason:eu,notes:em,linePresentation:ex,pageSize:null!=(i=null==V||null==(n=V.billingSettings)?void 0:n.pageSize)?i:"letter",taxLabel:null!=(o=null==V||null==(r=V.billingSettings)?void 0:r.taxLabel)?o:"Tax",billTo:{name:ey,contactName:eS,email:eI,phone:eC,address:ek,taxId:eP}}),q(!1),H(1)}catch(i){let n=i instanceof D.J3?i.sourceId:void 0,r=n?$.find(e=>e.id===n):void 0,a=n?G.find(e=>e.id===n):void 0,l=null!=r?r:a;ez((0,D.k_)(i,l?{sourceLabel:"".concat(r?"Time entry":"Expense"," “").concat(l.description,"”"),sourceDate:l.date,periodStart:e,periodEnd:t}:{})),eG((0,D.BM)(i)),i instanceof D.J3&&"source_outside_invoice_period"===i.code&&(eQ(!0),H(3))}finally{eq(!1)}};return(0,r.jsx)(j.lG,{open:F,onOpenChange:q,children:(0,r.jsxs)(j.Cf,{"aria-describedby":void 0,className:"max-h-[92vh] max-w-5xl overflow-y-auto",children:[(0,r.jsx)(j.c7,{children:(0,r.jsxs)(j.L3,{className:"font-sans text-xl",children:["Generate invoice — step ",X,"/5"]})}),1===X&&(0,r.jsxs)("div",{className:"grid gap-3 py-2",children:[(0,r.jsx)(b.J,{children:"Client"}),(0,r.jsxs)(y.l6,{value:K,onValueChange:Y,children:[(0,r.jsx)(y.bq,{className:"rounded-md border border-input bg-background text-foreground",children:(0,r.jsx)(y.yv,{placeholder:"Select client"})}),(0,r.jsx)(y.gC,{className:"z-[100]",children:z.map(e=>(0,r.jsx)(y.eb,{value:e.id,children:e.name},e.id))})]})]}),2===X&&(0,r.jsxs)("div",{className:"grid gap-3 py-2",children:[(0,r.jsx)(b.J,{children:"Billing scope"}),(0,r.jsxs)(y.l6,{value:ee,onValueChange:e=>{et(e),er(""),el(""),eE(new Set),eM(new Set),e_({})},children:[(0,r.jsx)(y.bq,{className:"rounded-md border border-input bg-background text-foreground",children:(0,r.jsx)(y.yv,{})}),(0,r.jsxs)(y.gC,{className:"z-[100]",children:[(0,r.jsx)(y.eb,{value:"all",children:"All open work for client"}),R.filter(e=>e.clientId===K).map(e=>{var t,n;return(0,r.jsxs)(y.eb,{value:"matter:".concat(e.id),children:["Matter ",e.matterNumber," — ",null!=(n=null==(t=Q.find(t=>t.id===e.projectId))?void 0:t.name)?n:"Linked project unavailable"]},e.id)}),Q.filter(e=>e.clientId===K&&!R.some(t=>t.projectId===e.id)).map(e=>(0,r.jsx)(y.eb,{value:"project:".concat(e.id),children:e.name},e.id))]})]})]}),3===X&&(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-3 py-2",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{htmlFor:"invoice-period-start",children:"Period start"}),(0,r.jsx)(x.p,{id:"invoice-period-start",type:"date",value:en,"aria-invalid":eR||!!e0.error,"aria-describedby":eR?"invoice-generation-error":e0.error?"invoice-period-error":void 0,onChange:e=>{er(e.target.value),eQ(!1)},className:eR?"border-destructive focus-visible:ring-destructive":""})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{htmlFor:"invoice-period-end",children:"Period end"}),(0,r.jsx)(x.p,{id:"invoice-period-end",type:"date",value:ea,"aria-invalid":eR||!!e0.error,"aria-describedby":eR?"invoice-generation-error":e0.error?"invoice-period-error":void 0,onChange:e=>{el(e.target.value),eQ(!1)},className:eR?"border-destructive focus-visible:ring-destructive":""})]}),e0.error&&(0,r.jsx)("p",{id:"invoice-period-error",role:"alert",className:"col-span-2 text-sm text-destructive",children:e0.error})]}),4===X&&e4&&(0,r.jsxs)("div",{className:"max-h-64 space-y-2 overflow-y-auto py-2 text-sm",children:[e3>0&&(0,r.jsxs)("p",{className:"text-muted-foreground",children:[e3," approved billing ",1===e3?"source is":"sources are"," excluded because ",1===e3?"it is":"they are"," not linked to this matter or its project."]}),[...e2,...e9].map(e=>{var t;return(0,r.jsxs)("div",{className:"grid grid-cols-[auto_1fr_auto] items-center gap-2 border-b pb-2",children:[(0,r.jsx)("input",{"aria-label":"Include ".concat(e.description),type:"checkbox",checked:!eU.has(e.id),onChange:()=>eE(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})}),(0,r.jsx)(x.p,{"aria-label":"Narrative ".concat(e.description),value:null!=(t=eB[e.id])?t:e.description,onChange:t=>e_(n=>({...n,[e.id]:t.target.value}))}),(0,r.jsxs)("label",{className:"text-xs",children:[(0,r.jsx)("input",{type:"checkbox",checked:eL.has(e.id),onChange:()=>eM(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n})})," Write off"]})]},e.id)}),(0,r.jsxs)("div",{className:"flex justify-between border-t pt-2 font-medium",children:[(0,r.jsx)("span",{children:"Total"}),(0,r.jsx)("span",{className:"font-mono tabular-nums",children:(0,v.u)(null!=(k=e4.total)?k:e4.amount)})]}),eL.size>0&&(0,r.jsx)(x.p,{"aria-label":"Write-off reason",placeholder:"Write-off reason",value:eT,onChange:e=>eJ(e.target.value)}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{htmlFor:"invoice-tax-amount",children:"Tax"}),(0,r.jsx)(x.p,{id:"invoice-tax-amount",value:ei,onChange:e=>eo(e.target.value),className:"rounded-md border border-input bg-background text-foreground font-mono tabular-nums"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{htmlFor:"invoice-discount",children:"Discount"}),(0,r.jsx)(x.p,{id:"invoice-discount",value:es,onChange:e=>ed(e.target.value),className:"rounded-md border border-input bg-background text-foreground font-mono tabular-nums"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{htmlFor:"invoice-discount-reason",children:"Discount reason"}),(0,r.jsx)(x.p,{id:"invoice-discount-reason",value:eu,onChange:e=>ec(e.target.value),className:"rounded-md border border-input bg-background text-foreground"})]})]}),5===X&&e4&&(0,r.jsxs)("div",{className:"grid gap-5 py-2 lg:grid-cols-[20rem_1fr]",children:[(0,r.jsxs)("div",{className:"grid content-start gap-3",children:[(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{children:"Issue date"}),(0,r.jsx)(x.p,{"aria-label":"Issue date",type:"date",value:eg,onChange:e=>ef(e.target.value)})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{children:"Due date"}),(0,r.jsx)(x.p,{"aria-label":"Due date",type:"date",value:ev,min:eg,onChange:e=>eh(e.target.value)})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{children:"Line presentation"}),(0,r.jsxs)("select",{"aria-label":"Line presentation",className:"h-10 w-full rounded-md border border-input bg-background px-3",value:ex,onChange:e=>eb(e.target.value),children:[(0,r.jsx)("option",{value:"detailed",children:"Detailed"}),(0,r.jsx)("option",{value:"summary",children:"Summarized"})]})]}),(0,r.jsx)(x.p,{"aria-label":"Bill-to name",placeholder:"Bill-to name",maxLength:300,value:ey,onChange:e=>ej(e.target.value)}),(0,r.jsx)(x.p,{"aria-label":"Bill-to contact",placeholder:"Contact name",maxLength:200,value:eS,onChange:e=>eN(e.target.value)}),(0,r.jsx)(x.p,{"aria-label":"Bill-to email",placeholder:"Email",maxLength:320,type:"email",value:eI,onChange:e=>ew(e.target.value)}),(0,r.jsx)(x.p,{"aria-label":"Bill-to phone",placeholder:"Phone",maxLength:100,value:eC,onChange:e=>eD(e.target.value)}),(0,r.jsx)(S.T,{"aria-label":"Bill-to address",placeholder:"Billing address",maxLength:1e3,value:ek,onChange:e=>eO(e.target.value)}),(0,r.jsx)(x.p,{"aria-label":"Bill-to tax ID",placeholder:"Tax ID",maxLength:200,value:eP,onChange:e=>eA(e.target.value)}),(0,r.jsxs)("div",{children:[(0,r.jsx)(b.J,{children:"Invoice notes"}),(0,r.jsx)(S.T,{maxLength:1e4,value:em,onChange:e=>ep(e.target.value)})]}),(0,r.jsx)("p",{className:"text-sm",children:"This creates an editable draft. Submission freezes the client-ready document."})]}),(0,r.jsx)(E.z,{issuerName:null!=(T=null!=(M=null!=(L=null==V||null==(n=V.billingSettings)?void 0:n.issuerDisplayName)?L:null==V||null==(l=V.billingSettings)?void 0:l.brandedHeader)?M:null==V?void 0:V.name)?T:"Invoice",issuerDetails:[null==V||null==(i=V.billingSettings)?void 0:i.issuerAddress,null==V||null==(o=V.billingSettings)?void 0:o.issuerEmail,null==V||null==(d=V.billingSettings)?void 0:d.issuerPhone].filter(
1Boolean).join("\n"),billToName:ey,billToDetails:[eS,ek,eI,eC,eP?"Tax ID: ".concat(eP):""].filter(Boolean).join("\n"),invoiceNumber:e4.invoiceNumber,issueDate:eg,dueOn:ev,periodStart:null==e1?void 0:e1.start,periodEnd:null==e1?void 0:e1.end,currency:e4.currency,accentColor:null==V||null==(u=V.billingSettings)?void 0:u.accentColor,linePresentation:ex,lines:e7,subtotal:(null!=(J=e4.subtotalFees)?J:0)+(null!=(B=e4.subtotalExpenses)?B:0),discount:Number(es)||0,tax:Number(ei)||0,taxLabel:null==V||null==(c=V.billingSettings)?void 0:c.taxLabel,total:null!=(_=e4.total)?_:e4.amount,notes:em,paymentInstructions:null==V||null==(h=V.billingSettings)?void 0:h.paymentInstructions,footer:null==V||null==(g=V.billingSettings)?void 0:g.defaultFooter})]}),eZ&&(0,r.jsxs)("div",{id:"invoice-generation-error",role:"alert",className:"space-y-1 text-sm text-destructive",children:[(0,r.jsx)("p",{children:eZ}),e$.length>0&&(0,r.jsx)("p",{className:"font-mono text-xs",children:e$.join(" \xb7 ")})]}),(0,r.jsxs)(j.Es,{children:[X>1&&(0,r.jsx)(s.$,{variant:"ghost",onClick:()=>H(e=>e-1),children:"Back"}),X<5?(0,r.jsx)(s.$,{className:" border-0",disabled:1===X&&!K||3===X&&!e1,onClick:()=>{if(2===X&&(!en||!ea)){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date().toISOString().slice(0,10),n=e.map(e=>e.date).filter(O).sort();if(n.length>0)return{start:n[0],end:n[n.length-1]};let r="".concat(t.slice(0,7),"-01"),[a,l]=r.split("-").map(Number);return{start:r,end:new Date(Date.UTC(a,l,0)).toISOString().slice(0,10)}}([...eK,...eY]);er(e.start),el(e.end)}H(e=>e+1)},children:"Next"}):(0,r.jsx)(s.$,{className:" border-0",disabled:eF||!e4||!!(ev&&ev<eg)||eL.size>0&&!eT||Number(es)>0&&!eu,onClick:()=>void e8(),children:"Create invoice"})]})]})})}function M(){let{workspaceId:e,workspace:t}=(0,c.k)(),n=(0,m.nc)(e=>e.currentUserId),l=(0,p.Bk)(e=>n?e.getById(n):void 0),x=(0,p.Xv)(t=>t.list().filter(t=>t.workspaceId===e)),[b,y]=(0,a.useState)(!1),j=(0,f.rZ)(l,t,"bill");(0,u.C)({breadcrumbs:[{label:"Invoicing"}]});let S=(0,a.useMemo)(()=>(0,g.MS)(x),[x]);return e&&n?(0,r.jsxs)("div",{className:"space-y-4","data-tour-page":"invoicing",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h1",{className:"font-sans text-2xl",children:"Invoicing"}),(0,r.jsxs)("p",{className:"text-sm font-mono tabular-nums",style:{color:"hsl(var(--foreground-muted))"},children:[Object.entries(S).map(e=>{let[t,n]=e;return(0,v.u)(n,t)}).join(" + ")||(0,v.u)(0,null==t?void 0:t.defaultCurrency)," outstanding \xb7 ",(0,h.u)(x.length)]})]}),j&&(0,r.jsxs)(s.$,{className:" border-0",size:"sm",onClick:()=>y(!0),children:[(0,r.jsx)(o.A,{className:"mr-1 h-4 w-4"})," Generate invoice"]})]}),(0,r.jsx)("div",{className:"rounded-lg border border-border bg-card text-card-foreground overflow-hidden shadow-sm",children:(0,r.jsxs)("table",{className:"w-full text-sm",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b text-left",style:{borderColor:"hsl(var(--border))",color:"hsl(var(--foreground-muted))"},children:[(0,r.jsx)("th",{className:"px-4 py-2",children:"Invoice #"}),(0,r.jsx)("th",{className:"px-4 py-2",children:"Client"}),(0,r.jsx)("th",{className:"px-4 py-2",children:"Status"}),(0,r.jsx)("th",{className:"px-4 py-2",children:"Due"}),(0,r.jsx)("th",{className:"px-4 py-2 text-right",children:"Total"}),(0,r.jsx)("th",{className:"px-4 py-2 text-right",children:"Outstanding"}),(0,r.jsx)("th",{className:"px-4 py-2"})]})}),(0,r.jsx)("tbody",{children:0===x.length?(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:7,className:"px-4 py-8 text-center",style:{color:"hsl(var(--foreground-muted))"},children:"No invoices yet."})}):x.sort((e,t)=>t.createdAt.localeCompare(e.createdAt)).map(t=>{var n,a,l;return(0,r.jsxs)("tr",{className:"border-b",style:{borderColor:"hsl(var(--border))"},children:[(0,r.jsx)("td",{className:"px-4 py-2 font-medium",children:(0,r.jsx)(i(),{className:"hover:underline",href:"/dashboard/project-management/w/".concat(e,"/psa/invoicing/").concat(t.id),children:t.invoiceNumber})}),(0,r.jsx)("td",{className:"px-4 py-2",children:t.clientName}),(0,r.jsx)("td",{className:"px-4 py-2",children:(0,r.jsx)(d.E,{variant:"outline",children:h.Z[t.status]})}),(0,r.jsx)("td",{className:"px-4 py-2 font-mono tabular-nums",children:t.dueOn}),(0,r.jsx)("td",{className:"px-4 py-2 text-right font-mono tabular-nums",children:(0,v.u)(null!=(n=t.total)?n:t.amount,t.currency)}),(0,r.jsx)("td",{className:"px-4 py-2 text-right font-mono tabular-nums",children:(0,v.u)(null!=(l=t.amountOutstanding)?l:t.amount-(null!=(a=t.amountPaid)?a:0),t.currency)}),(0,r.jsx)("td",{className:"px-4 py-2",children:(0,r.jsx)(s.$,{asChild:!0,variant:"ghost",size:"sm",children:(0,r.jsx)(i(),{href:"/dashboard/project-management/w/".concat(e,"/psa/invoicing/").concat(t.id),children:"Open"})})})]},t.id)})})]})}),(0,r.jsx)(L,{open:b,onOpenChange:y,workspaceId:e})]}):null}}}]);

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.