UNPKG

@accounter/client

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