@accounter/client
Version:
Accounter client application
1 lines • 13.1 kB
JavaScript
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{Dn as r,Lo as i,Tn as a,at as o,da as s,gi as c,wn as l,xi as u}from"./error-handling-Dpfd9svJ.js";import{m as d,s as f,t as p}from"./routes-DUvpW9-n.js";import{a as m,c as h,f as g,ht as _,i as v,l as y,m as b,n as x,o as S,p as C,r as w,t as T,u as E,ut as ee}from"./select-CrsvQyhZ.js";import{t as D}from"./modify-contract-dialog-Ek2tQK5a.js";import{t as O}from"./funnel-BFbxpUGW.js";import{t as k}from"./button-Dzp2INW0.js";import{Et as te,H as A,J as j,K as M,Lt as N,N as P,Ot as F,P as ne,Tt as re,U as ie,W as I,a as L,c as R,f as ae,i as z,m as oe,n as B,o as V,p as H,r as U,s as W,t as G,u as K}from"./table--bF0wbxq.js";import{t as se}from"./subMonths-DGtu7gB6.js";import{Cr as ce,Ft as le,H as q,I as ue,Vt as J,cr as de,dr as fe,or as pe,ot as me,si as Y,sr as he,w as ge,wr as _e}from"./index-CL8-JoMZ.js";import{r as ve,t as ye}from"./use-issue-monthly-documents-dWFCMZVs.js";var X=e(n(),1),Z=t(),Q=({timelessDate:e})=>(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:new Date(e).toLocaleDateString(void 0,{timeZone:`UTC`})});function be({id:e,name:t}){return(0,Z.jsx)(`div`,{className:`flex flex-wrap flex-col justify-center`,children:(0,Z.jsx)(f,{to:p.BUSINESSES.DETAIL(e),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t})})}var $=[{id:`select`,header:({table:e})=>(0,Z.jsx)(q,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,Z.jsx)(q,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t),"aria-label":`Select row`}),enableSorting:!1,enableHiding:!1},{accessorKey:`isActive`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Is Active`}),cell:({row:e})=>e.getValue(`isActive`)?(0,Z.jsx)(P,{variant:`default`,children:`Active`}):(0,Z.jsx)(P,{variant:`destructive`,children:`Inactive`})},{accessorKey:`client.name`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Client`}),cell:({row:e})=>(0,Z.jsx)(be,{id:e.original.client.id,name:e.original.client.name})},{accessorKey:`startDate`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Start`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`startDate`)})},{accessorKey:`endDate`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`End`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`endDate`)})},{accessorKey:`purchaseOrder`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Purchase Order`}),cell:({row:e})=>(0,Z.jsxs)(`div`,{className:`flex flex-row gap-1 items-center`,children:[e.original.msCloud&&(0,Z.jsx)(f,{to:e.original.msCloud,target:`_blank`,rel:`noreferrer`,className:`size-8`,children:(0,Z.jsx)(k,{variant:`link`,size:`sm`,children:(0,Z.jsx)(Y,{className:`size-4`})})}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e.getValue(`purchaseOrder`)})]})},{accessorKey:`product`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Product`}),cell:({row:e})=>(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e.getValue(`product`)})},{accessorKey:`plan`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Subscription Plan`}),cell:({row:e})=>(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e.getValue(`plan`)})},{accessorKey:`billingCycle`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Billing Cycle`}),cell:({row:e})=>(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e.getValue(`billingCycle`)})},{accessorKey:`amount.raw`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Amount`}),cell:({row:e})=>(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:e.original.amount.formatted})},{accessorKey:`operationsLimit`,header:({column:e})=>(0,Z.jsx)(J,{column:e,title:`Operations Limit`}),cell:({row:e})=>{let t=e.getValue(`operationsLimit`);return t?(0,Z.jsx)(`p`,{className:`text-sm font-medium`,children:t.toString()}):null}},{accessorKey:`edit`,header:``,cell:({row:e})=>(0,Z.jsx)(D,{clientId:e.original.client.id,contractId:e.original.id}),enableSorting:!1}];function xe({table:e}){let[t,n]=(0,X.useState)(!1);return(0,Z.jsxs)(h,{open:t,onOpenChange:n,children:[(0,Z.jsx)(b,{asChild:!0,children:(0,Z.jsx)(k,{size:`sm`,variant:`outline`,children:(0,Z.jsx)(O,{className:`size-4`})})}),(0,Z.jsxs)(y,{className:`max-w-2xl max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(g,{children:[(0,Z.jsx)(C,{children:`Filter Contracts`}),(0,Z.jsx)(E,{children:`Filter contracts based on various criteria`})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(S,{children:`Product Type`}),(0,Z.jsxs)(T,{onValueChange:t=>e.getColumn(`product`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`product`)?.getFilterValue(),children:[(0,Z.jsx)(v,{className:`w-full`,children:(0,Z.jsx)(m,{})}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(w,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(u).map(e=>(0,Z.jsx)(w,{value:e,children:e},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(S,{children:`Billing Cycle`}),(0,Z.jsxs)(T,{onValueChange:t=>e.getColumn(`billingCycle`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`billingCycle`)?.getFilterValue(),children:[(0,Z.jsx)(v,{className:`w-full`,children:(0,Z.jsx)(m,{})}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(w,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(o).map(e=>(0,Z.jsx)(w,{value:e,children:ce(e)},e))]})]})]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(S,{children:`Subscription Plan`}),(0,Z.jsxs)(T,{onValueChange:t=>e.getColumn(`plan`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`plan`)?.getFilterValue(),children:[(0,Z.jsx)(v,{className:`w-full`,children:(0,Z.jsx)(m,{})}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(w,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(s).map(e=>(0,Z.jsx)(w,{value:e,children:_e(e)},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(S,{children:`Is Active`}),(0,Z.jsxs)(T,{onValueChange:t=>e.getColumn(`isActive`)?.setFilterValue(t===`NULL`?void 0:t===`active`),value:Se(e.getColumn(`isActive`)?.getFilterValue()),children:[(0,Z.jsx)(v,{className:`w-full`,children:(0,Z.jsx)(m,{})}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(w,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),(0,Z.jsx)(w,{value:`active`,children:`Active`}),(0,Z.jsx)(w,{value:`inactive`,children:`Inactive`})]})]})]})]})]})]})]})}function Se(e){return e===void 0?`NULL`:e?`active`:`inactive`}var Ce=({contractIds:e})=>{let[t,n]=(0,X.useState)(!1),[r,a]=(0,X.useState)(N(se(new Date,1),`yyyy-MM-dd`)),[o,s]=(0,X.useState)([]),{issueDocuments:u}=ye(),[{data:d,fetching:m},_]=i({query:l,variables:{issueMonth:r,contractIds:e},pause:!t});(0,X.useEffect)(()=>{d?.periodicalDocumentDraftsByContracts&&s(d.periodicalDocumentDraftsByContracts.map(e=>ue(I(c,e))))},[d,s]),(0,X.useEffect)(()=>{t&&_()},[t,_]);let v=ie({values:{drafts:o}}),x=(0,X.useCallback)(async e=>{await u({generateDocumentsInfo:e.drafts}),n(!1)},[u]),{fields:w,remove:T,update:D}=A({control:v.control,name:`drafts`}),O=v.watch(`drafts`),M=(0,X.useMemo)(()=>w.map((e,t)=>({...e,...O[t],id:e.id})),[w,O]);return(0,Z.jsxs)(h,{open:t,onOpenChange:n,children:[(0,Z.jsx)(b,{asChild:!0,children:(0,Z.jsx)(k,{size:`sm`,variant:`outline`,disabled:e.length===0,children:`Issue Documents`})}),(0,Z.jsxs)(y,{className:`min-w-[90vw] w-full max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(g,{children:[(0,Z.jsx)(C,{children:`Issue Documents for Contracts`}),(0,Z.jsx)(E,{children:`Review and issue monthly documents for the selected contracts`})]}),m?(0,Z.jsx)(j,{}):(0,Z.jsx)(ne,{...v,children:(0,Z.jsxs)(`form`,{onSubmit:v.handleSubmit(x),className:`min-w-5xl w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,Z.jsx)(S,{children:`Issue Month:`}),(0,Z.jsx)(le,{value:new Date(r),onChange:e=>{a(N(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!1}})]}),(0,Z.jsxs)(G,{children:[(0,Z.jsx)(L,{children:(0,Z.jsxs)(V,{children:[(0,Z.jsx)(z,{children:`Name`}),(0,Z.jsx)(z,{children:`Document`}),(0,Z.jsx)(z,{children:`Amount`}),(0,Z.jsx)(z,{children:`Remark`}),(0,Z.jsx)(z,{children:`Recipients`}),(0,Z.jsx)(z,{})]})}),(0,Z.jsx)(B,{children:M.map(({id:e,...t},n)=>(0,Z.jsxs)(V,{children:[(0,Z.jsx)(U,{children:(0,Z.jsx)(f,{to:t.client?.id?p.BUSINESSES.DETAIL(t.client?.id):p.BUSINESSES.ALL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.client?.name})}),(0,Z.jsx)(U,{children:t.type}),(0,Z.jsxs)(U,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,Z.jsx)(U,{children:(0,Z.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,Z.jsx)(U,{children:(0,Z.jsx)(`div`,{className:`flex flex-col`,children:t.client?.emails?.map(e=>(0,Z.jsx)(`span`,{className:`text-sm text-gray-500`,children:e},e))})}),(0,Z.jsx)(U,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(re,{children:[(0,Z.jsx)(F,{asChild:!0,type:`button`,children:(0,Z.jsx)(k,{className:`size-7.5`,variant:`secondary`,onClick:()=>T(n),children:(0,Z.jsx)(ee,{size:16})})}),(0,Z.jsx)(te,{children:(0,Z.jsx)(`p`,{children:`Remove document`})})]}),(0,Z.jsx)(ve,{draft:t,onApprove:e=>{v.setValue(`drafts.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),D(n,{...e})}})]})})]},e))})]}),(0,Z.jsx)(`div`,{className:`flex justify-between items-center mt-4`,children:(0,Z.jsx)(me,{onConfirm:v.handleSubmit(x),title:`Are you sure you want to issue ${M.length} documents?`,children:(0,Z.jsx)(k,{children:`Issue`})})})]})})]})]})};function we(e){let t=I(a,e);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}}var Te=({data:e})=>{let[t,n]=(0,X.useState)([{id:`endDate`,desc:!0},{id:`amount.raw`,desc:!0}]),[r,i]=(0,X.useState)({}),[a,o]=(0,X.useState)([]),[s,c]=(0,X.useState)([]),l=(0,X.useMemo)(()=>e.map(e=>we(e)),[e]),u=R({data:l,columns:$,getCoreRowModel:K(),onSortingChange:n,getSortedRowModel:oe(),getPaginationRowModel:H(),onRowSelectionChange:i,onColumnFiltersChange:o,getFilteredRowModel:ae(),state:{sorting:t,rowSelection:r,columnFilters:a},initialState:{pagination:{pageIndex:0,pageSize:50}}});return(0,X.useEffect)(()=>{let e=Object.entries(r).filter(([,e])=>!!e).map(([e])=>Number(e)),t=Array.from(new Set(l.filter((t,n)=>e.includes(n)).map(e=>e.id)));(s.length!==t.length||!s.every(e=>t.includes(e)))&&c(t)},[r,l,s,a]),(0,Z.jsxs)(`div`,{className:`w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center py-4 gap-4`,children:[(0,Z.jsx)(xe,{table:u}),(0,Z.jsxs)(pe,{children:[(0,Z.jsx)(fe,{asChild:!0,children:(0,Z.jsxs)(k,{variant:`outline`,children:[`Columns `,(0,Z.jsx)(_,{})]})}),(0,Z.jsx)(de,{align:`end`,children:u.getAllColumns().filter(e=>e.getCanHide()).map(e=>(0,Z.jsx)(he,{className:`capitalize`,checked:e.getIsVisible(),onCheckedChange:t=>e.toggleVisibility(!!t),children:e.id},e.id))})]}),(0,Z.jsx)(`div`,{className:`ml-auto`,children:(0,Z.jsx)(Ce,{contractIds:s,className:`ml-auto`})})]}),(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,Z.jsxs)(G,{children:[(0,Z.jsx)(L,{children:u.getHeaderGroups().map(e=>(0,Z.jsx)(V,{children:e.headers.map(e=>(0,Z.jsx)(z,{colSpan:e.colSpan,children:e.isPlaceholder?null:W(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,Z.jsx)(B,{children:u.getRowModel().rows?.length?u.getRowModel().rows.map(e=>(0,Z.jsx)(V,{children:e.getVisibleCells().map(e=>(0,Z.jsx)(U,{children:W(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,Z.jsx)(V,{children:(0,Z.jsx)(U,{colSpan:$.length,className:`h-24 text-center`,children:`No results.`})})})]})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:[(0,Z.jsxs)(`div`,{className:`text-muted-foreground flex-1 text-sm`,children:[u.getFilteredSelectedRowModel().rows.length,` of`,` `,u.getFilteredRowModel().rows.length,` row(s) selected.`]}),(0,Z.jsx)(ge,{className:`w-fit mx-0`,currentPageIndex:u.getState().pagination.pageIndex,totalPages:u.getPageCount(),onChange:e=>u.setPageIndex(e)})]})]})},Ee=()=>{let{userContext:e}=(0,X.useContext)(M),t=e?.context.adminBusinessId,n;try{n=d()}catch{}let[{data:a,fetching:o}]=i({query:r,pause:!t||!!n,variables:{adminId:t??``}}),s=n||a;return!n&&o&&!s?.contractsByAdmin?(0,Z.jsx)(j,{}):!t||!s?.contractsByAdmin?(0,Z.jsx)(`div`,{children:`Contracts not found`}):(0,Z.jsx)(Te,{data:s.contractsByAdmin})};export{Ee as ContractsScreen};