@accounter/client
Version:
Accounter client application
1 lines • 13.1 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{c as r,t as i}from"./chunk-62JRHF6Z-CBbOZODe.js";import{Or as a,Tt as o,U as s,h as c,n as l,nt as u,vt as d}from"./common-CXB0UgWw.js";import{n as f,r as p,t as m}from"./modify-contract-dialog-CGGChp02.js";import{a as h,c as g,f as _,ft as v,i as y,l as b,lt as ee,m as x,n as S,o as C,p as w,r as T,t as E,u as D}from"./select-DrAHsHyM.js";import{d as O,h as k,l as te,u as ne}from"./separator-CQBUMn7G.js";import{t as A}from"./funnel-CtGZVesZ.js";import{t as j}from"./routes-4W-duEv9.js";import{t as M}from"./button-DUNsVBiu.js";import{Bc as N,Fl as P,Il as F,Kl as I,Rl as L,Vc as R,Xc as re,Zc as ie,a as z,c as ae,d as B,el as V,i as H,il as U,n as W,nl as G,o as K,r as q,s as oe,t as J}from"./table-Dje35oxp.js";import{Bi as se,Cn as ce,Fi as le,Pa as ue,Sn as de,Tn as fe,at as pe,us as Y}from"./graphql-BIob9ctl.js";import{t as me}from"./subMonths-D3tEnDXZ.js";import{r as he,t as ge}from"./use-issue-monthly-documents-DmDm2el8.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 _e({id:e,name:t}){return(0,Z.jsx)(`div`,{className:`flex flex-wrap flex-col justify-center`,children:(0,Z.jsx)(i,{to:j.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)(u,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,Z.jsx)(u,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t),"aria-label":`Select row`}),enableSorting:!1,enableHiding:!1},{accessorKey:`isActive`,header:({column:e})=>(0,Z.jsx)(o,{column:e,title:`Is Active`}),cell:({row:e})=>e.getValue(`isActive`)?(0,Z.jsx)(N,{variant:`default`,children:`Active`}):(0,Z.jsx)(N,{variant:`destructive`,children:`Inactive`})},{accessorKey:`client.name`,header:({column:e})=>(0,Z.jsx)(o,{column:e,title:`Client`}),cell:({row:e})=>(0,Z.jsx)(_e,{id:e.original.client.id,name:e.original.client.name})},{accessorKey:`startDate`,header:({column:e})=>(0,Z.jsx)(o,{column:e,title:`Start`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`startDate`)})},{accessorKey:`endDate`,header:({column:e})=>(0,Z.jsx)(o,{column:e,title:`End`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`endDate`)})},{accessorKey:`purchaseOrder`,header:({column:e})=>(0,Z.jsx)(o,{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)(i,{to:e.original.msCloud,target:`_blank`,rel:`noreferrer`,className:`size-8`,children:(0,Z.jsx)(M,{variant:`link`,size:`sm`,children:(0,Z.jsx)(a,{className:`size-4`})})}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e.getValue(`purchaseOrder`)})]})},{accessorKey:`product`,header:({column:e})=>(0,Z.jsx)(o,{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)(o,{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)(o,{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)(o,{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)(o,{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)(m,{clientId:e.original.client.id,contractId:e.original.id}),enableSorting:!1}];function ve({table:e}){let[t,n]=(0,X.useState)(!1);return(0,Z.jsxs)(g,{open:t,onOpenChange:n,children:[(0,Z.jsx)(x,{asChild:!0,children:(0,Z.jsx)(M,{size:`sm`,variant:`outline`,children:(0,Z.jsx)(A,{className:`size-4`})})}),(0,Z.jsxs)(b,{className:`max-w-2xl max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(_,{children:[(0,Z.jsx)(w,{children:`Filter Contracts`}),(0,Z.jsx)(D,{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)(C,{children:`Product Type`}),(0,Z.jsxs)(E,{onValueChange:t=>e.getColumn(`product`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`product`)?.getFilterValue(),children:[(0,Z.jsx)(y,{className:`w-full`,children:(0,Z.jsx)(h,{})}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(T,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(se).map(e=>(0,Z.jsx)(T,{value:e,children:e},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(C,{children:`Billing Cycle`}),(0,Z.jsxs)(E,{onValueChange:t=>e.getColumn(`billingCycle`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`billingCycle`)?.getFilterValue(),children:[(0,Z.jsx)(y,{className:`w-full`,children:(0,Z.jsx)(h,{})}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(T,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(pe).map(e=>(0,Z.jsx)(T,{value:e,children:f(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)(C,{children:`Subscription Plan`}),(0,Z.jsxs)(E,{onValueChange:t=>e.getColumn(`plan`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`plan`)?.getFilterValue(),children:[(0,Z.jsx)(y,{className:`w-full`,children:(0,Z.jsx)(h,{})}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(T,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(ue).map(e=>(0,Z.jsx)(T,{value:e,children:p(e)},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(C,{children:`Is Active`}),(0,Z.jsxs)(E,{onValueChange:t=>e.getColumn(`isActive`)?.setFilterValue(t===`NULL`?void 0:t===`active`),value:ye(e.getColumn(`isActive`)?.getFilterValue()),children:[(0,Z.jsx)(y,{className:`w-full`,children:(0,Z.jsx)(h,{})}),(0,Z.jsxs)(S,{children:[(0,Z.jsx)(T,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),(0,Z.jsx)(T,{value:`active`,children:`Active`}),(0,Z.jsx)(T,{value:`inactive`,children:`Inactive`})]})]})]})]})]})]})]})}function ye(e){return e===void 0?`NULL`:e?`active`:`inactive`}var be=({contractIds:e})=>{let[t,n]=(0,X.useState)(!1),[r,a]=(0,X.useState)(I(me(new Date,1),`yyyy-MM-dd`)),[o,l]=(0,X.useState)([]),{issueDocuments:u}=ge(),[{data:f,fetching:p},m]=Y({query:de,variables:{issueMonth:r,contractIds:e},pause:!t});(0,X.useEffect)(()=>{f?.periodicalDocumentDraftsByContracts&&l(f.periodicalDocumentDraftsByContracts.map(e=>c(V(le,e))))},[f,l]),(0,X.useEffect)(()=>{t&&m()},[t,m]);let h=ie({values:{drafts:o}}),v=(0,X.useCallback)(async e=>{await u({generateDocumentsInfo:e.drafts}),n(!1)},[u]),{fields:y,remove:S,update:T}=re({control:h.control,name:`drafts`}),E=h.watch(`drafts`),O=(0,X.useMemo)(()=>y.map((e,t)=>({...e,...E[t],id:e.id})),[y,E]);return(0,Z.jsxs)(g,{open:t,onOpenChange:n,children:[(0,Z.jsx)(x,{asChild:!0,children:(0,Z.jsx)(M,{size:`sm`,variant:`outline`,disabled:e.length===0,children:`Issue Documents`})}),(0,Z.jsxs)(b,{className:`min-w-[90vw] w-full max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(_,{children:[(0,Z.jsx)(w,{children:`Issue Documents for Contracts`}),(0,Z.jsx)(D,{children:`Review and issue monthly documents for the selected contracts`})]}),p?(0,Z.jsx)(U,{}):(0,Z.jsx)(R,{...h,children:(0,Z.jsxs)(`form`,{onSubmit:h.handleSubmit(v),className:`min-w-5xl w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,Z.jsx)(C,{children:`Issue Month:`}),(0,Z.jsx)(d,{value:new Date(r),onChange:e=>{let t=new Date(e.getFullYear(),e.getMonth(),15);a(I(t,`yyyy-MM-dd`))},popoverProps:{withinPortal:!1}})]}),(0,Z.jsxs)(J,{children:[(0,Z.jsx)(z,{children:(0,Z.jsxs)(K,{children:[(0,Z.jsx)(H,{children:`Name`}),(0,Z.jsx)(H,{children:`Document`}),(0,Z.jsx)(H,{children:`Amount`}),(0,Z.jsx)(H,{children:`Remark`}),(0,Z.jsx)(H,{children:`Recipients`}),(0,Z.jsx)(H,{})]})}),(0,Z.jsx)(W,{children:O.map(({id:e,...t},n)=>(0,Z.jsxs)(K,{children:[(0,Z.jsx)(q,{children:(0,Z.jsx)(i,{to:t.client?.id?j.BUSINESSES.DETAIL(t.client?.id):j.BUSINESSES.ALL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.client?.name})}),(0,Z.jsx)(q,{children:t.type}),(0,Z.jsxs)(q,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,Z.jsx)(q,{children:(0,Z.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,Z.jsx)(q,{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)(q,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsx)(L,{asChild:!0,type:`button`,children:(0,Z.jsx)(M,{className:`size-7.5`,variant:`secondary`,onClick:()=>S(n),children:(0,Z.jsx)(ee,{size:16})})}),(0,Z.jsx)(F,{children:(0,Z.jsx)(`p`,{children:`Remove document`})})]}),(0,Z.jsx)(he,{draft:t,onApprove:e=>{h.setValue(`drafts.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),T(n,{...e})}})]})})]},e))})]}),(0,Z.jsx)(`div`,{className:`flex justify-between items-center mt-4`,children:(0,Z.jsx)(s,{onConfirm:h.handleSubmit(v),title:`Are you sure you want to issue ${O.length} documents?`,children:(0,Z.jsx)(M,{children:`Issue`})})})]})})]})]})};function xe(e){let t=V(ce,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 Se=({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)([]),u=(0,X.useMemo)(()=>e.map(e=>xe(e)),[e]),d=ae({features:oe,data:u,columns:$,onSortingChange:n,onRowSelectionChange:i,onColumnFiltersChange:o,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(u.filter((t,n)=>e.includes(n)).map(e=>e.id)));(s.length!==t.length||!s.every(e=>t.includes(e)))&&c(t)},[r,u,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)(ve,{table:d}),(0,Z.jsxs)(te,{children:[(0,Z.jsx)(k,{asChild:!0,children:(0,Z.jsxs)(M,{variant:`outline`,children:[`Columns `,(0,Z.jsx)(v,{})]})}),(0,Z.jsx)(O,{align:`end`,children:d.getAllColumns().filter(e=>e.getCanHide()).map(e=>(0,Z.jsx)(ne,{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)(be,{contractIds:s,className:`ml-auto`})})]}),(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,Z.jsxs)(J,{children:[(0,Z.jsx)(z,{children:d.getHeaderGroups().map(e=>(0,Z.jsx)(K,{children:e.headers.map(e=>(0,Z.jsx)(H,{colSpan:e.colSpan,children:e.isPlaceholder?null:B(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,Z.jsx)(W,{children:d.getRowModel().rows?.length?d.getRowModel().rows.map(e=>(0,Z.jsx)(K,{children:e.getVisibleCells().map(e=>(0,Z.jsx)(q,{children:B(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,Z.jsx)(K,{children:(0,Z.jsx)(q,{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:[d.getFilteredSelectedRowModel().rows.length,` of`,` `,d.getFilteredRowModel().rows.length,` row(s) selected.`]}),(0,Z.jsx)(l,{className:`w-fit mx-0`,currentPageIndex:d.state.pagination.pageIndex,totalPages:d.getPageCount(),onChange:e=>d.setPageIndex(e)})]})]})},Ce=()=>{let{userContext:e}=(0,X.useContext)(G),t=e?.context.adminBusinessId,n;try{n=r()}catch{}let[{data:i,fetching:a}]=Y({query:fe,pause:!t||!!n,variables:{adminId:t??``}}),o=n||i;return!n&&a&&!o?.contractsByAdmin?(0,Z.jsx)(U,{}):!t||!o?.contractsByAdmin?(0,Z.jsx)(`div`,{children:`Contracts not found`}):(0,Z.jsx)(Se,{data:o.contractsByAdmin})};export{Ce as ContractsScreen};