@accounter/client
Version:
Accounter client application
1 lines • 12.9 kB
JavaScript
import{t as e}from"./modify-contract-dialog-NUEsqc-t.js";import{t}from"./funnel-CDY9d08i.js";import{t as n}from"./subMonths-BpBa52PH.js";import{$ as r,$u as i,Al as a,An as o,B as s,C as c,Ci as l,Cn as u,Cu as d,Dn as f,Du as p,En as m,F as ee,Fi as h,G as g,H as _,Id as v,K as y,Kt as b,Li as x,Ml as S,Ni as C,Nu as w,Oi as T,On as E,Pi as D,Pt as te,Q as O,Rc as k,Ri as A,Sd as j,Si as ne,Ti as M,U as N,V as P,W as F,Wa as I,Wl as L,Xi as re,Xn as R,Y as ie,Z as ae,Zi as oe,bi as se,es as ce,fn as le,ic as z,jd as B,ji as V,jn as H,kn as U,md as W,nr as G,oc as ue,q as de,rs as fe,tr as pe,ts as me,tt as K,un as he,wi as q,wn as ge,xd as J,yi as _e,zi as Y}from"./index-CSYTUOOk.js";import{r as ve,t as ye}from"./use-issue-monthly-documents-pWq2dcmW.js";var X=v(B(),1),Z=d(),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)(J,{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)(K,{checked:e.getIsAllPageRowsSelected()||e.getIsSomePageRowsSelected()&&`indeterminate`,onCheckedChange:t=>e.toggleAllPageRowsSelected(!!t),"aria-label":`Select all`}),cell:({row:e})=>(0,Z.jsx)(K,{checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(!!t),"aria-label":`Select row`}),enableSorting:!1,enableHiding:!1},{accessorKey:`isActive`,header:({column:e})=>(0,Z.jsx)(H,{column:e,title:`Is Active`}),cell:({row:e})=>e.getValue(`isActive`)?(0,Z.jsx)(b,{variant:`default`,children:`Active`}):(0,Z.jsx)(b,{variant:`destructive`,children:`Inactive`})},{accessorKey:`client.name`,header:({column:e})=>(0,Z.jsx)(H,{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)(H,{column:e,title:`Start`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`startDate`)})},{accessorKey:`endDate`,header:({column:e})=>(0,Z.jsx)(H,{column:e,title:`End`}),cell:({row:e})=>(0,Z.jsx)(Q,{timelessDate:e.getValue(`endDate`)})},{accessorKey:`purchaseOrder`,header:({column:e})=>(0,Z.jsx)(H,{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)(J,{to:e.original.msCloud,target:`_blank`,rel:`noreferrer`,className:`size-8`,children:(0,Z.jsx)(L,{variant:`link`,size:`sm`,children:(0,Z.jsx)(i,{className:`size-4`})})}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:e.getValue(`purchaseOrder`)})]})},{accessorKey:`product`,header:({column:e})=>(0,Z.jsx)(H,{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)(H,{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)(H,{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)(H,{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)(H,{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:t})=>(0,Z.jsx)(e,{clientId:t.original.client.id,contractId:t.original.id}),enableSorting:!1}];function xe({table:e}){let[n,r]=(0,X.useState)(!1);return(0,Z.jsxs)(C,{open:n,onOpenChange:r,children:[(0,Z.jsx)(Y,{asChild:!0,children:(0,Z.jsx)(L,{size:`sm`,variant:`outline`,children:(0,Z.jsx)(t,{className:`size-4`})})}),(0,Z.jsxs)(D,{className:`max-w-2xl max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(x,{children:[(0,Z.jsx)(A,{children:`Filter Contracts`}),(0,Z.jsx)(h,{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)(V,{children:`Product Type`}),(0,Z.jsxs)(m,{onValueChange:t=>e.getColumn(`product`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`product`)?.getFilterValue(),children:[(0,Z.jsx)(U,{className:`w-full`,children:(0,Z.jsx)(o,{})}),(0,Z.jsxs)(f,{children:[(0,Z.jsx)(E,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(ue).map(e=>(0,Z.jsx)(E,{value:e,children:e},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(V,{children:`Billing Cycle`}),(0,Z.jsxs)(m,{onValueChange:t=>e.getColumn(`billingCycle`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`billingCycle`)?.getFilterValue(),children:[(0,Z.jsx)(U,{className:`w-full`,children:(0,Z.jsx)(o,{})}),(0,Z.jsxs)(f,{children:[(0,Z.jsx)(E,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(I).map(e=>(0,Z.jsx)(E,{value:e,children:re(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)(V,{children:`Subscription Plan`}),(0,Z.jsxs)(m,{onValueChange:t=>e.getColumn(`plan`)?.setFilterValue(t===`NULL`?void 0:t),value:e.getColumn(`plan`)?.getFilterValue(),children:[(0,Z.jsx)(U,{className:`w-full`,children:(0,Z.jsx)(o,{})}),(0,Z.jsxs)(f,{children:[(0,Z.jsx)(E,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),Object.values(k).map(e=>(0,Z.jsx)(E,{value:e,children:oe(e)},e))]})]})]}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(V,{children:`Is Active`}),(0,Z.jsxs)(m,{onValueChange:t=>e.getColumn(`isActive`)?.setFilterValue(t===`NULL`?void 0:t===`active`),value:Se(e.getColumn(`isActive`)?.getFilterValue()),children:[(0,Z.jsx)(U,{className:`w-full`,children:(0,Z.jsx)(o,{})}),(0,Z.jsxs)(f,{children:[(0,Z.jsx)(E,{value:`NULL`,className:`font-light text-xs`,children:`(None)`}),(0,Z.jsx)(E,{value:`active`,children:`Active`}),(0,Z.jsx)(E,{value:`inactive`,children:`Inactive`})]})]})]})]})]})]})]})}function Se(e){return e===void 0?`NULL`:e?`active`:`inactive`}var Ce=({contractIds:e})=>{let[t,r]=(0,X.useState)(!1),[i,o]=(0,X.useState)(S(n(new Date,1),`yyyy-MM-dd`)),[c,l]=(0,X.useState)([]),{issueDocuments:d}=ye(),[{data:f,fetching:m},v]=a({query:ce,variables:{issueMonth:i,contractIds:e},pause:!t});(0,X.useEffect)(()=>{f?.periodicalDocumentDraftsByContracts&&l(f.periodicalDocumentDraftsByContracts.map(e=>ee(R(z,e))))},[f,l]),(0,X.useEffect)(()=>{t&&v()},[t,v]);let y=ge({values:{drafts:c}}),b=(0,X.useCallback)(async e=>{await d({generateDocumentsInfo:e.drafts}),r(!1)},[d]),{fields:T,remove:E,update:O}=u({control:y.control,name:`drafts`}),k=y.watch(`drafts`),j=(0,X.useMemo)(()=>T.map((e,t)=>({...e,...k[t],id:e.id})),[T,k]);return(0,Z.jsxs)(C,{open:t,onOpenChange:r,children:[(0,Z.jsx)(Y,{asChild:!0,children:(0,Z.jsx)(L,{size:`sm`,variant:`outline`,disabled:e.length===0,children:`Issue Documents`})}),(0,Z.jsxs)(D,{className:`min-w-[90vw] w-full max-h-[90vh] overflow-y-auto`,children:[(0,Z.jsxs)(x,{children:[(0,Z.jsx)(A,{children:`Issue Documents for Contracts`}),(0,Z.jsx)(h,{children:`Review and issue monthly documents for the selected contracts`})]}),m?(0,Z.jsx)(G,{}):(0,Z.jsx)(le,{...y,children:(0,Z.jsxs)(`form`,{onSubmit:y.handleSubmit(b),className:`min-w-5xl w-full`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,Z.jsx)(V,{children:`Issue Month:`}),(0,Z.jsx)(he,{value:new Date(i),onChange:e=>{o(S(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!1}})]}),(0,Z.jsxs)(s,{children:[(0,Z.jsx)(F,{children:(0,Z.jsxs)(g,{children:[(0,Z.jsx)(N,{children:`Name`}),(0,Z.jsx)(N,{children:`Document`}),(0,Z.jsx)(N,{children:`Amount`}),(0,Z.jsx)(N,{children:`Remark`}),(0,Z.jsx)(N,{children:`Recipients`}),(0,Z.jsx)(N,{})]})}),(0,Z.jsx)(P,{children:j.map(({id:e,...t},n)=>(0,Z.jsxs)(g,{children:[(0,Z.jsx)(_,{children:(0,Z.jsx)(J,{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)(_,{children:t.type}),(0,Z.jsxs)(_,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,Z.jsx)(_,{children:(0,Z.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,Z.jsx)(_,{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)(_,{children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Z.jsxs)(_e,{children:[(0,Z.jsx)(ne,{asChild:!0,type:`button`,children:(0,Z.jsx)(L,{className:`size-7.5`,variant:`secondary`,onClick:()=>E(n),children:(0,Z.jsx)(w,{size:16})})}),(0,Z.jsx)(se,{children:(0,Z.jsx)(`p`,{children:`Remove document`})})]}),(0,Z.jsx)(ve,{draft:t,onApprove:e=>{y.setValue(`drafts.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),O(n,{...e})}})]})})]},e))})]}),(0,Z.jsx)(`div`,{className:`flex justify-between items-center mt-4`,children:(0,Z.jsx)(te,{onConfirm:y.handleSubmit(b),title:`Are you sure you want to issue ${j.length} documents?`,children:(0,Z.jsx)(L,{children:`Issue`})})})]})})]})]})};function we(e){let t=R(me,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}]),[i,a]=(0,X.useState)({}),[o,u]=(0,X.useState)([]),[d,f]=(0,X.useState)([]),p=(0,X.useMemo)(()=>e.map(e=>we(e)),[e]),m=de({data:p,columns:$,getCoreRowModel:ie(),onSortingChange:n,getSortedRowModel:r(),getPaginationRowModel:O(),onRowSelectionChange:a,onColumnFiltersChange:u,getFilteredRowModel:ae(),state:{sorting:t,rowSelection:i,columnFilters:o},initialState:{pagination:{pageIndex:0,pageSize:50}}});return(0,X.useEffect)(()=>{let e=Object.entries(i).filter(([,e])=>!!e).map(([e])=>Number(e)),t=Array.from(new Set(p.filter((t,n)=>e.includes(n)).map(e=>e.id)));(d.length!==t.length||!d.every(e=>t.includes(e)))&&f(t)},[i,p,d,o]),(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:m}),(0,Z.jsxs)(l,{children:[(0,Z.jsx)(T,{asChild:!0,children:(0,Z.jsxs)(L,{variant:`outline`,children:[`Columns `,(0,Z.jsx)(W,{})]})}),(0,Z.jsx)(M,{align:`end`,children:m.getAllColumns().filter(e=>e.getCanHide()).map(e=>(0,Z.jsx)(q,{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:d,className:`ml-auto`})})]}),(0,Z.jsx)(`div`,{className:`overflow-hidden rounded-md border`,children:(0,Z.jsxs)(s,{children:[(0,Z.jsx)(F,{children:m.getHeaderGroups().map(e=>(0,Z.jsx)(g,{children:e.headers.map(e=>(0,Z.jsx)(N,{colSpan:e.colSpan,children:e.isPlaceholder?null:y(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,Z.jsx)(P,{children:m.getRowModel().rows?.length?m.getRowModel().rows.map(e=>(0,Z.jsx)(g,{children:e.getVisibleCells().map(e=>(0,Z.jsx)(_,{children:y(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,Z.jsx)(g,{children:(0,Z.jsx)(_,{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:[m.getFilteredSelectedRowModel().rows.length,` of`,` `,m.getFilteredRowModel().rows.length,` row(s) selected.`]}),(0,Z.jsx)(c,{className:`w-fit mx-0`,currentPageIndex:m.getState().pagination.pageIndex,totalPages:m.getPageCount(),onChange:e=>m.setPageIndex(e)})]})]})},Ee=()=>{let{userContext:e}=(0,X.useContext)(pe),t=e?.context.adminBusinessId,n;try{n=j()}catch{}let[{data:r,fetching:i}]=a({query:fe,pause:!t||!!n,variables:{adminId:t??``}}),o=n||r;return!n&&i&&!o?.contractsByAdmin?(0,Z.jsx)(G,{}):!t||!o?.contractsByAdmin?(0,Z.jsx)(`div`,{children:`Contracts not found`}):(0,Z.jsx)(Te,{data:o.contractsByAdmin})};export{Ee as ContractsScreen};