UNPKG

@accounter/client

Version:

2 lines (1 loc) • 12.4 kB
import{j as e,ah as T,R,p as k,af as B,B as C,a9 as se,r as i,D as z,aL as H,x as _,al as $,am as q,an as J,a3 as S,ao as w,ap as I,aq as L,ar as M,as as x,bJ as te,bK as ae,bL as ne,w as O,u as Q,bM as le,aJ as ie,E as re,J as ce,c as W,W as oe,bN as de,bO as X,bP as Y,bQ as b,bR as f,bS as Z,bT as g,bU as ue,bV as me,a5 as xe,bW as he,bX as ge,H as G,aK as je,bY as pe,bZ as fe,b_ as Ce,b$ as ve,c0 as De,c1 as Ne,c2 as E,P as ye,c3 as Se,c4 as be,c5 as we,c6 as Ie,c7 as Le,aC as Me,b as Fe,c8 as Ae}from"./index-DRqooPz9.js";import{M as Re,s as Te,a as Pe}from"./modify-contract-dialog-BMTCgQ3i.js";import{D as m}from"./data-table-column-header-DDRUwuwC.js";import{F as Ve}from"./funnel-B1ZA9LM9.js";import{u as ke,a as Be}from"./use-issue-monthly-documents-Dx6_0gyN.js";import{s as Oe}from"./subMonths-CZ2djAnO.js";import"./eye-off-DtXkBVx1.js";const U=({timelessDate:s})=>e.jsx("p",{className:"text-sm font-medium",children:new Date(s).toLocaleDateString(void 0,{timeZone:"UTC"})});function Ee({id:s,name:t}){return e.jsx("div",{className:"flex flex-wrap flex-col justify-center",children:e.jsx(T,{to:R.BUSINESSES.DETAIL(s),target:"_blank",rel:"noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold",children:t})})}const K=[{id:"select",header:({table:s})=>e.jsx(k,{checked:s.getIsAllPageRowsSelected()||s.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:t=>s.toggleAllPageRowsSelected(!!t),"aria-label":"Select all"}),cell:({row:s})=>e.jsx(k,{checked:s.getIsSelected(),onCheckedChange:t=>s.toggleSelected(!!t),"aria-label":"Select row"}),enableSorting:!1,enableHiding:!1},{accessorKey:"isActive",header:({column:s})=>e.jsx(m,{column:s,title:"Is Active"}),cell:({row:s})=>s.getValue("isActive")?e.jsx(B,{variant:"default",children:"Active"}):e.jsx(B,{variant:"destructive",children:"Inactive"})},{accessorKey:"client.name",header:({column:s})=>e.jsx(m,{column:s,title:"Client"}),cell:({row:s})=>e.jsx(Ee,{id:s.original.client.id,name:s.original.client.name})},{accessorKey:"startDate",header:({column:s})=>e.jsx(m,{column:s,title:"Start"}),cell:({row:s})=>e.jsx(U,{timelessDate:s.getValue("startDate")})},{accessorKey:"endDate",header:({column:s})=>e.jsx(m,{column:s,title:"End"}),cell:({row:s})=>e.jsx(U,{timelessDate:s.getValue("endDate")})},{accessorKey:"purchaseOrder",header:({column:s})=>e.jsx(m,{column:s,title:"Purchase Order"}),cell:({row:s})=>e.jsxs("div",{className:"flex flex-row gap-1 items-center",children:[s.original.msCloud&&e.jsx(T,{to:s.original.msCloud,target:"_blank",rel:"noreferrer",className:"size-8",children:e.jsx(C,{variant:"link",size:"sm",children:e.jsx(se,{className:"size-4"})})}),e.jsx("span",{className:"text-sm font-medium",children:s.getValue("purchaseOrder")})]})},{accessorKey:"product",header:({column:s})=>e.jsx(m,{column:s,title:"Product"}),cell:({row:s})=>e.jsx("p",{className:"text-sm font-medium",children:s.getValue("product")})},{accessorKey:"plan",header:({column:s})=>e.jsx(m,{column:s,title:"Subscription Plan"}),cell:({row:s})=>e.jsx("p",{className:"text-sm font-medium",children:s.getValue("plan")})},{accessorKey:"billingCycle",header:({column:s})=>e.jsx(m,{column:s,title:"Billing Cycle"}),cell:({row:s})=>e.jsx("p",{className:"text-sm font-medium",children:s.getValue("billingCycle")})},{accessorKey:"amount.raw",header:({column:s})=>e.jsx(m,{column:s,title:"Amount"}),cell:({row:s})=>e.jsx("p",{className:"text-sm font-medium",children:s.original.amount.formatted})},{accessorKey:"operationsLimit",header:({column:s})=>e.jsx(m,{column:s,title:"Operations Limit"}),cell:({row:s})=>{const t=s.getValue("operationsLimit");return t?e.jsx("p",{className:"text-sm font-medium",children:t.toString()}):null}},{accessorKey:"edit",header:"",cell:({row:s})=>e.jsx(Re,{clientId:s.original.client.id,contractId:s.original.id}),enableSorting:!1}];function Ue({table:s}){const[t,r]=i.useState(!1);return e.jsxs(z,{open:t,onOpenChange:r,children:[e.jsx(H,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"outline",children:e.jsx(Ve,{className:"size-4"})})}),e.jsxs(_,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs($,{children:[e.jsx(q,{children:"Filter Contracts"}),e.jsx(J,{children:"Filter contracts based on various criteria"})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Product Type"}),e.jsxs(w,{onValueChange:a=>s.getColumn("product")?.setFilterValue(a==="NULL"?void 0:a),value:s.getColumn("product")?.getFilterValue(),children:[e.jsx(I,{className:"w-full",children:e.jsx(L,{})}),e.jsxs(M,{children:[e.jsx(x,{value:"NULL",className:"font-light text-xs",children:"(None)"}),Object.values(te).map(a=>e.jsx(x,{value:a,children:a},a))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Billing Cycle"}),e.jsxs(w,{onValueChange:a=>s.getColumn("billingCycle")?.setFilterValue(a==="NULL"?void 0:a),value:s.getColumn("billingCycle")?.getFilterValue(),children:[e.jsx(I,{className:"w-full",children:e.jsx(L,{})}),e.jsxs(M,{children:[e.jsx(x,{value:"NULL",className:"font-light text-xs",children:"(None)"}),Object.values(ae).map(a=>e.jsx(x,{value:a,children:Te(a)},a))]})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Subscription Plan"}),e.jsxs(w,{onValueChange:a=>s.getColumn("plan")?.setFilterValue(a==="NULL"?void 0:a),value:s.getColumn("plan")?.getFilterValue(),children:[e.jsx(I,{className:"w-full",children:e.jsx(L,{})}),e.jsxs(M,{children:[e.jsx(x,{value:"NULL",className:"font-light text-xs",children:"(None)"}),Object.values(ne).map(a=>e.jsx(x,{value:a,children:Pe(a)},a))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(S,{children:"Is Active"}),e.jsxs(w,{onValueChange:a=>s.getColumn("isActive")?.setFilterValue(a==="NULL"?void 0:a==="active"),value:Ke(s.getColumn("isActive")?.getFilterValue()),children:[e.jsx(I,{className:"w-full",children:e.jsx(L,{})}),e.jsxs(M,{children:[e.jsx(x,{value:"NULL",className:"font-light text-xs",children:"(None)"}),e.jsx(x,{value:"active",children:"Active"}),e.jsx(x,{value:"inactive",children:"Inactive"})]})]})]})]})]})]})]})}function Ke(s){return s===void 0?"NULL":s?"active":"inactive"}const ze=({contractIds:s})=>{const[t,r]=i.useState(!1),[a,v]=i.useState(O(Oe(new Date,1),"yyyy-MM-dd")),[h,D]=i.useState([]),{issueDocuments:j}=ke(),[{data:N,fetching:y},c]=Q({query:le,variables:{issueMonth:a,contractIds:s},pause:!t});i.useEffect(()=>{N?.periodicalDocumentDraftsByContracts&&D(N.periodicalDocumentDraftsByContracts.map(u=>ie(G(je,u))))},[N,D]),i.useEffect(()=>{t&&c()},[t,c]);const n=re({values:{drafts:h}}),l=i.useCallback(async u=>{await j({generateDocumentsInfo:u.drafts}),r(!1)},[j]),{fields:d,remove:F,update:ee}=ce({control:n.control,name:"drafts"}),P=n.watch("drafts"),V=i.useMemo(()=>d.map((u,o)=>({...u,...P[o],id:u.id})),[d,P]);return e.jsxs(z,{open:t,onOpenChange:r,children:[e.jsx(H,{asChild:!0,children:e.jsx(C,{size:"sm",variant:"outline",disabled:s.length===0,children:"Issue Documents"})}),e.jsxs(_,{className:"min-w-[90vw] w-full max-h-[90vh] overflow-y-auto",children:[e.jsxs($,{children:[e.jsx(q,{children:"Issue Documents for Contracts"}),e.jsx(J,{children:"Review and issue monthly documents for the selected contracts"})]}),y?e.jsx(W,{}):e.jsx(oe,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(l),className:"min-w-5xl w-full",children:[e.jsxs("div",{className:"flex gap-2 items-center mb-4",children:[e.jsx(S,{children:"Issue Month:"}),e.jsx(de,{value:new Date(a),onChange:u=>{const o=new Date(u.getFullYear(),u.getMonth(),15);v(O(o,"yyyy-MM-dd"))},popoverProps:{withinPortal:!1}})]}),e.jsxs(X,{children:[e.jsx(Y,{children:e.jsxs(b,{children:[e.jsx(f,{children:"Name"}),e.jsx(f,{children:"Document"}),e.jsx(f,{children:"Amount"}),e.jsx(f,{children:"Remark"}),e.jsx(f,{children:"Recipients"}),e.jsx(f,{})]})}),e.jsx(Z,{children:V.map(({id:u,...o},A)=>e.jsxs(b,{children:[e.jsx(g,{children:e.jsx(T,{to:o.client?.id?R.BUSINESSES.DETAIL(o.client?.id):R.BUSINESSES.ALL,target:"_blank",rel:"noreferrer",onClick:p=>p.stopPropagation(),className:"inline-flex items-center font-semibold",children:o.client?.name})}),e.jsx(g,{children:o.type}),e.jsxs(g,{children:[o.income?.[0]?.price," ",o.income?.[0]?.currency]}),e.jsx(g,{children:e.jsx("span",{className:"text-sm text-gray-500 whitespace-normal max-w-50",children:o.remarks})}),e.jsx(g,{children:e.jsx("div",{className:"flex flex-col",children:o.client?.emails?.map(p=>e.jsx("span",{className:"text-sm text-gray-500",children:p},p))})}),e.jsx(g,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(ue,{children:[e.jsx(me,{asChild:!0,type:"button",children:e.jsx(C,{className:"size-7.5",variant:"secondary",onClick:()=>F(A),children:e.jsx(xe,{size:16})})}),e.jsx(he,{children:e.jsx("p",{children:"Remove document"})})]}),e.jsx(Be,{draft:o,onApprove:p=>{n.setValue(`drafts.${A}`,p,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),ee(A,{...p})}})]})})]},u))})]}),e.jsx("div",{className:"flex justify-between items-center mt-4",children:e.jsx(ge,{onConfirm:n.handleSubmit(l),title:`Are you sure you want to issue ${V.length} documents?`,children:e.jsx(C,{children:"Issue"})})})]})})]})]})};function He(s){const t=G(Le,s);return{id:t.id,isActive:t.isActive,client:{id:t.client.id,name:t.client.originalBusiness.name},purchaseOrder:t.purchaseOrders[0],startDate:t.startDate,endDate:t.endDate,amount:{raw:t.amount.raw,formatted:t.amount.formatted},billingCycle:t.billingCycle,product:t.product??void 0,plan:t.plan??void 0,operationsLimit:t.operationsLimit,msCloud:t.msCloud?.toString()??void 0}}const _e=({data:s})=>{const[t,r]=i.useState([{id:"endDate",desc:!0},{id:"amount.raw",desc:!0}]),[a,v]=i.useState({}),[h,D]=i.useState([]),[j,N]=i.useState([]),y=i.useMemo(()=>s.map(n=>He(n)),[s]),c=pe({data:y,columns:K,getCoreRowModel:Ie(),onSortingChange:r,getSortedRowModel:we(),getPaginationRowModel:be(),onRowSelectionChange:v,onColumnFiltersChange:D,getFilteredRowModel:Se(),state:{sorting:t,rowSelection:a,columnFilters:h},initialState:{pagination:{pageIndex:0,pageSize:50}}});return i.useEffect(()=>{const n=Object.entries(a).filter(([,d])=>!!d).map(([d])=>Number(d)),l=Array.from(new Set(y.filter((d,F)=>n.includes(F)).map(d=>d.id)));(j.length!==l.length||!j.every(d=>l.includes(d)))&&N(l)},[a,y,j,h]),e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsx(Ue,{table:c}),e.jsxs(fe,{children:[e.jsx(Ce,{asChild:!0,children:e.jsxs(C,{variant:"outline",children:["Columns ",e.jsx(ve,{})]})}),e.jsx(De,{align:"end",children:c.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(Ne,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:l=>n.toggleVisibility(!!l),children:n.id},n.id))})]}),e.jsx("div",{className:"ml-auto",children:e.jsx(ze,{contractIds:j,className:"ml-auto"})})]}),e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs(X,{children:[e.jsx(Y,{children:c.getHeaderGroups().map(n=>e.jsx(b,{children:n.headers.map(l=>e.jsx(f,{colSpan:l.colSpan,children:l.isPlaceholder?null:E(l.column.columnDef.header,l.getContext())},l.id))},n.id))}),e.jsx(Z,{children:c.getRowModel().rows?.length?c.getRowModel().rows.map(n=>e.jsx(b,{children:n.getVisibleCells().map(l=>e.jsx(g,{children:E(l.column.columnDef.cell,l.getContext())},l.id))},n.id)):e.jsx(b,{children:e.jsx(g,{colSpan:K.length,className:"h-24 text-center",children:"No results."})})})]})}),e.jsxs("div",{className:"flex items-center justify-end space-x-2 py-4",children:[e.jsxs("div",{className:"text-muted-foreground flex-1 text-sm",children:[c.getFilteredSelectedRowModel().rows.length," of"," ",c.getFilteredRowModel().rows.length," row(s) selected."]}),e.jsx(ye,{className:"w-fit mx-0",currentPageIndex:c.getState().pagination.pageIndex,totalPages:c.getPageCount(),onChange:n=>c.setPageIndex(n)})]})]})},Ze=()=>{const{userContext:s}=i.useContext(Me),t=s?.context.adminBusinessId;let r;try{r=Fe()}catch{}const[{data:a,fetching:v}]=Q({query:Ae,pause:!t||!!r,variables:{adminId:t??""}}),h=r||a;return!r&&v&&!h?.contractsByAdmin?e.jsx(W,{}):!t||!h?.contractsByAdmin?e.jsx("div",{children:"Contracts not found"}):e.jsx(_e,{data:h.contractsByAdmin})};export{Ze as ContractsScreen};