1import{q as P,j as n,r as j,o as $,aZ as Q}from"./vendor-react-2cb5d109.js";import{ae as d,en as Z,eo as H,a8 as U,ep as l,d as G,dR as K,s as E,cN as O,eq as X,aZ as A,q as J,bf as ee,cP as ne}from"./vendor-vy-bde48d53.js";import{k as L,H as te}from"./vendor-misc-09f7f1da.js";import{V as ie}from"./VyPageLayout-f2c5bf34.js";import{e as k,p as V,q as F,aC as se,z as re,aF as ae,bv as oe,u as le,Z as ce,w as de,k as ue}from"./app-core-47ba8b05.js";import{A as me,u as pe}from"./ApprovedIcon-a9c60c6e.js";import{a as ge}from"./use-table-pagination-2ef45298.js";import{u as ve}from"./use-debounce-9c73162a.js";import{u as Y}from"./use-query-input-param-b882346d.js";import{i as he,o as B,T as p,b0 as I,e as xe,N as Ie}from"./vendor-mui-c34240eb.js";import{V as b}from"./vy-table-toolbar-8610b6d8.js";import{V as fe}from"./VyTable-e1c70e0c.js";import{u as Ce}from"./use-update-invoices-review-statuses-02fea29b.js";import{P as M}from"./Price-ca3b453e.js";import{V as S}from"./VyTableCell-93a365bc.js";import{U as ye}from"./papaparse.min-eac00b5a.js";import{V as be}from"./vendor-vy-ds-da93fbfd.js";import"./page-frame-c2a7254f.js";import"./VyPageLayoutTabs-bb33aa5c.js";import"./use-page-param-6119b40d.js";import"./use-state-params-e6f24508.js";import"./use-effect-once-07b631b8.js";import"./SearchInput-26e5b009.js";import"./use-table-columns-manager-476ce6ee.js";import"./vy-table-types-e576bdc1.js";import"./VyTooltip-4f1579b8.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"a44d049e7c59"};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a64c66c7-c97f-43b5-ba86-221ba35ea3b9",e._sentryDebugIdIdentifier="sentry-dbid-a64c66c7-c97f-43b5-ba86-221ba35ea3b9")}catch{}})();const Ne=10;function N(e={},t){return P(F.billingCycleInvoices(...Object.values(e)),async({signal:i})=>{const o=await k().getBillingCycleInvoices({page:d(e.page,0),pageSize:d(e.pageSize,Ne),...e},{signal:i});return V(Z,o)},{keepPreviousData:!0,...t})}function Ee(e={},t){return P({queryKey:F.billingCyclePage(...Object.values(e)),queryFn:async({signal:s})=>{const c=await k().getBillingCyclePage(e,{signal:s});return V(H,c)},keepPreviousData:!0,...t})}const R=({title:e,value:t,overcharges:i,selected:s,onClick:o,loading:c=!1})=>c?n.jsx(he,{variant:"rounded",height:60,className:"rounded-2lg"}):n.jsxs(B,{elevation:0,sx:u=>({border:"1px solid",borderColor:u.palette.divider,borderRadius:"8px"}),onClick:o,className:L("px-8 py-4 rounded-2lg cursor-pointer",{"bg-selected font-semibold":s},{"bg-white":!s}),children:[n.jsxs(p,{className:"flex items-center justify-between gap-4",children:[n.jsx(p,{variant:"body1",sx:{fontWeight:400},children:e}),n.jsx(p,{variant:"body1",children:t})]}),i?n.jsxs(p,{className:L("mt-3 flex items-center gap-2 flex-wrap w-fit justify-center rounded-2lg bg-error-light px-2 py-1 uppercase text-error-secondary text-sm",{"border-error-secondary border-[0.5px]":s}),children:[n.jsx(p,{variant:"body2",sx:{fontWeight:600},children:`$${U(i)}`}),n.jsx(p,{variant:"body2",sx:{fontWeight:600},children:"Overages"})]}):n.jsx(n.Fragment,{})]}),je=({selectedInvoiceType:e,onInvoicePreviewClick:t,regularBillingCycleInvoicesCount:i,inspectionBillingCycleInvoicesCount:s,oldBillingCycleInvoicesCount:o,overcharges:c,loading:u=!1})=>{const m=i+s+o;return n.jsxs(B,{sx:v=>({borderRadius:"8px",border:"1px solid",borderColor:v.palette.divider,padding:"24px"}),children:[n.jsxs(p,{sx:{display:"flex",columnGap:"8px",alignItems:"baseline",marginBottom:2},children:[n.jsx(p,{variant:"h5",sx:{fontWeight:600},children:m}),n.jsx(p,{variant:"h6",children:"Total invoices"})]}),n.jsxs(I,{container:!0,spacing:1,children:[n.jsx(I,{size:{xs:12,md:4,lg:12},children:n.jsx(R,{title:"Invoices",value:i,onClick:()=>t(l.REGULAR),selected:e===l.REGULAR,loading:u})}),n.jsx(I,{size:{xs:12,md:4,lg:12},children:n.jsx(R,{title:"Invoices for review",value:s,selected:e===l.INSPECTION,onClick:()=>t(l.INSPECTION),overcharges:c,loading:u})}),n.jsx(I,{size:{xs:12,md:4,lg:12},children:n.jsx(R,{title:"Older invoices",value:o,selected:e===l.OLD,onClick:()=>t(l.OLD),loading:u})})]})]})},Ae=()=>n.jsx("svg",{width:"12",height:"9",viewBox:"0 0 12 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:n.jsx("path",{d:"M5.91836 8.16602L11.5123 0.146259H0.324377L5.91836 8.16602Z",fill:"#FF154D"})}),Se=()=>n.jsx("svg",{width:"12",height:"9",viewBox:"0 0 12 9",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:n.jsx("path",{d:"M5.91836 0.472656L11.5123 8.49241H0.324377L5.91836 0.472656Z",fill:"#4FBA80"})}),Re=({oldValue:e,newValue:t})=>{const i=we(e,t),s=se(Math.abs(i),1);return n.jsxs("div",{className:"flex items-center justify-center gap-2",children:[n.jsx("div",{children:i!==0?`${s}%`:"0%"}),n.jsx("div",{children:i!==0?i<0?n.jsx(Ae,{}):n.jsx(Se,{}):n.jsx(n.Fragment,{})})]})};function we(e,t){return e===0&&t===0?0:e===0?100:(t-e)/e*100}const x=Object.freeze({EXTERNAL_ID:"customerExternalId",CUSTOMER_NAME:"customerName",INVOICE_NUMBER:"id",INVOICE_DATE:"billingCycle.startTime",AMOUNT:"revenueBreakdown.total",ERP_ID:"erpDisplayId",PREVIOUS_INVOICE_AMOUNT:"previousInvoiceAmount",CONTRACT_NAME:"contractName"}),Be=[{field:x.EXTERNAL_ID,headerName:"ID",flex:1,minWidth:60,valueGetter:(e,t)=>t.customerExternalId??"--",renderCell:({row:e})=>n.jsx(S,{value:e.customerExternalId??"--"})},{field:x.CUSTOMER_NAME,headerName:"Customer",headerAlign:"center",align:"center",minWidth:150,flex:1,renderCell:({row:e})=>n.jsx(S,{value:e.customerName??"--"})},{field:x.INVOICE_NUMBER,headerName:"Invoice",headerAlign:"center",align:"center",minWidth:90,flex:1,valueGetter:(e,t)=>t.invoiceNumber},{field:x.INVOICE_DATE,headerName:"Date",headerAlign:"center",align:"center",minWidth:100,flex:1,valueGetter:(e,t)=>t.billingCycle.startTime,valueFormatter:e=>re(e),sortComparator:ae},{field:x.AMOUNT,headerName:"Amount",headerAlign:"center",align:"center",minWidth:150,flex:1,renderCell:({row:e})=>n.jsx(M,{currency:e.currency,children:e.revenueBreakdown.total})},{field:x.ERP_ID,headerName:"ERP ID",headerAlign:"center",align:"center",minWidth:90,flex:1,valueGetter:(e,t)=>t.erpDisplayId??"--"},{field:"amountChangePercentage",headerName:"Amount change (%)",headerAlign:"center",align:"center",minWidth:170,flex:1,renderCell:({row:e})=>n.jsx(Re,{oldValue:e.previousInvoiceAmount??0,newValue:e.revenueBreakdown.total})},{field:x.PREVIOUS_INVOICE_AMOUNT,headerName:"Prev. invoice",headerAlign:"center",align:"center",minWidth:110,flex:1,renderCell:({row:e})=>G(e.previousInvoiceAmount)?n.jsx(M,{currency:e.currency,children:e.previousInvoiceAmount}):"--"},{field:x.CONTRACT_NAME,headerName:"Contract",headerAlign:"center",align:"center",minWidth:110,flex:1,renderCell:({row:e})=>n.jsx(S,{value:e.contractName??"--"})}],De=({startDay:e,endDay:t,...i})=>{const s=N({pageSize:1e4,billingCycleInvoiceType:l.REGULAR},{enabled:!1}),o=N({pageSize:1e4,billingCycleInvoiceType:l.INSPECTION},{enabled:!1}),c=j.useCallback(async()=>{var v,g;const u=await s.refetch(),m=await o.refetch();Te([...d((v=u.data)==null?void 0:v.invoices,[]),...d((g=m.data)==null?void 0:g.invoices,[])],e,t)},[t,o,s,e]);return n.jsxs(xe,{variant:"outlined",size:"small",...i,sx:{columnGap:"8px"},onClick:c,children:["Export",n.jsx(be,{icon:"Save",style:{transform:"scale(0.8)"}})]})};function Te(e,t,i){K(e);const s=e.map(Oe),o=ye.unparse(s),c=_e(t,i),u=new Blob([o],{type:"text/csv;charset=utf-8"}),m=`Billing Cycle Report - ${c}.csv`;oe.saveAs(u,m)}function _e(e,t){return E(e).format("MM/DD/YYYY")+" To "+E(t).format("MM/DD/YYYY")}function Oe(e){return{Date:E(e.billingCycle.startTime).format("MM/DD/YYYY"),Customer:e.customerName,ExternalID:e.customerExternalId,Amount:U(e.revenueBreakdown.total),Currency:e.currency,Contract:G(e.contractName)?e.contractName:"--","ERP ID":e.erpId,InvoiceNumber:e.invoiceNumber}}const w=e=>{const t=le(),[i,s]=j.useState([]),[o,c]=Y(),u=$(),m=Ce(),v=j.useCallback(async()=>{const a=O(i,"id"),f=O(i,"customerId"),h=X(a)?"invoices":"invoice";await ce(m,{customerIds:f,invoicesByNewStatus:{[A.Approved]:a}},{pending:`Approving ${h}...`,success:`Approved ${h}`,error:`Failed to approve ${h}`},{onSuccess:async()=>
1{await u.invalidateQueries({predicate:({queryKey:C})=>["billing-cycle-page","billing-cycle-invoices"].some(y=>C.includes(y))}),s([])}})},[i,m]),g=J(i)||m.isLoading,r=a=>{const f=Array.from(a.ids).map(C=>e.items.find(y=>y.id===C)),h=ee(f);s(h)};return n.jsxs(B,{sx:a=>({borderRadius:"8px",border:"1px solid",borderColor:a.palette.divider,height:"100%",position:"relative"}),children:[n.jsxs(b,{children:[n.jsx(b.Queries,{children:n.jsx(b.SearchInput,{defaultValue:d(o,""),onChange:a=>c(a.target.value),placeholder:"Search here"})}),n.jsxs(b.Actions,{children:[n.jsx(De,{endDay:E().endOf("month").toDate(),startDay:E().startOf("month").toDate()}),n.jsx(b.CtaButton,{onClick:v,disabled:g,children:"Approve"})]})]}),n.jsx(fe,{...e,columns:Be,sx:{paddingBottom:"180px",marginBottom:"200px",...e.sx},paginationClassName:"bottom-0 right-0",rowSelection:!0,checkboxSelection:!0,onRowClick:({row:a})=>a.reviewStatus===A.Approved?t(`/invoices/overview/light/${a.id}`):t(`/invoices/monthly-approval?invoiceId=${a.id}`),onRowSelectionModelChange:r,isRowSelectable:({row:a})=>a.reviewStatus!==A.Approved,slots:{baseCheckbox:a=>a.disabled?n.jsx("div",{className:"flex items-center justify-center",children:n.jsx(me,{className:"h-6 w-6"})}):n.jsx(Ie,{...a})}}),n.jsx(p,{variant:"body1",sx:{position:"absolute",bottom:"16px",left:"20px"},children:`${i.length} Invoices Selected`})]})},Le=()=>{var D,T,_;const[e,t]=j.useState(l.REGULAR),{page:i,pageSize:s,onPageChange:o,onPageSizeChange:c,setPage:u}=ge(),[m]=Y(),v=ne(m),g=ve(v),{data:r,isFetching:a}=Ee({search:g}),f=N({page:i,pageSize:s,search:g,billingCycleInvoiceType:l.REGULAR},{enabled:e===l.REGULAR}),h=N({page:i,pageSize:s,search:g,billingCycleInvoiceType:l.INSPECTION},{enabled:e===l.INSPECTION}),C=N({page:i,pageSize:s,search:g,billingCycleInvoiceType:l.OLD},{enabled:e===l.OLD}),y=d((D=f.data)==null?void 0:D.invoices,[]),W=d((T=h.data)==null?void 0:T.invoices,[]),z=d((_=C.data)==null?void 0:_.invoices,[]);return pe(["previousCycle"]),n.jsxs(n.Fragment,{children:[n.jsx(te,{children:n.jsx("title",{children:"Monthly closure"})}),n.jsx(ie,{path:[n.jsx(Q,{to:"/invoices",children:"Invoices"}),"Monthly closure"],title:"Monthly closure",children:n.jsxs(I,{container:!0,className:"flex h-full",spacing:2,children:[n.jsx(I,{size:{xs:12,lg:3},children:n.jsx(je,{selectedInvoiceType:e,onInvoicePreviewClick:q=>{t(q),u(0)},regularBillingCycleInvoicesCount:d(r==null?void 0:r.regularBillingCycleInvoicesCount,0),inspectionBillingCycleInvoicesCount:d(r==null?void 0:r.inspectionBillingCycleInvoicesCount,0),oldBillingCycleInvoicesCount:d(r==null?void 0:r.oldBillingCycleInvoicesCount,0),overcharges:d(r==null?void 0:r.overcharges,0),loading:a})}),n.jsxs(I,{className:"h-full",size:{xs:12,lg:9},sx:{overflow:"hidden"},children:[e===l.REGULAR&&n.jsx(w,{tableName:"billing-cycle-regular",items:y,itemsCount:d(r==null?void 0:r.regularBillingCycleInvoicesCount,0),loadingItems:f.isFetching,page:i,pageSize:s,onPageChange:o,onPageSizeChange:c}),e===l.INSPECTION&&n.jsx(w,{tableName:"billing-cycle-inspection",items:W,itemsCount:d(r==null?void 0:r.inspectionBillingCycleInvoicesCount,0),loadingItems:h.isFetching,page:i,pageSize:s,onPageChange:o,onPageSizeChange:c}),e===l.OLD&&n.jsx(w,{tableName:"billing-cycle-old",items:z,itemsCount:d(r==null?void 0:r.oldBillingCycleInvoicesCount,0),loadingItems:C.isFetching,page:i,pageSize:s,onPageChange:o,onPageSizeChange:c})]})]})})]})},cn=de(ue(Le));export{cn as BillingCyclePage};
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.