@accounter/client
Version:
Accounter client application
1 lines • 4.86 kB
JavaScript
import{s as e}from"./dist-BbgEzppd.js";import{i as t,o as n}from"./utils-BUNz070n.js";import{N as r,Xr as i,Ya as a,Yr as o,et as s,ti as c}from"./error-handling-AQOG1RNy.js";import{l,t as u}from"./routes-BXbESQBe.js";import{a as d,c as f,d as p,f as m,i as h,n as g,o as _,p as v,r as y,s as b,t as x,ut as S}from"./select-6mBYg_R6.js";import{At as C,Bt as w,Et as T,Vt as E,ar as D,cr as O,h as k,or as A,rt as j}from"./common-Cy-x5Vhe.js";import{y as M}from"./separator-EFzchRgs.js";import{t as N}from"./button-CBTN3XMQ.js";import{a as P,at as F,b as I,g as L,i as R,n as z,o as B,r as V,t as H}from"./table-tK8pMUMS.js";import{t as U}from"./subMonths-ah6YOt4d.js";import{w as W}from"./index-B8E5XsZe.js";import{r as G,t as K}from"./use-issue-monthly-documents-vpQ2hpr8.js";var q=e(n(),1),J=t();function Y({issueMonth:e,clients:t,onAdd:n}){let[r,i]=(0,q.useState)(!1),[s,l]=(0,q.useState)(``),[{data:u},_]=a({query:o,variables:{issueMonth:e,clientId:s},pause:!r}),S=(0,q.useCallback)(e=>{l(e),_()},[_,l]);return(0,q.useEffect)(()=>{s!==``&&u&&(n(k(L(c,u.clientMonthlyChargeDraft))),i(!1))},[s,u,n]),(0,J.jsxs)(b,{open:r,onOpenChange:i,children:[(0,J.jsx)(v,{asChild:!0,children:(0,J.jsx)(N,{variant:`outline`,size:`icon`,children:(0,J.jsx)(M,{})})}),(0,J.jsxs)(f,{className:`w-[400px] max-w-screen-md`,children:[(0,J.jsx)(p,{children:(0,J.jsx)(m,{children:`Select document recipient`})}),(0,J.jsxs)(x,{onValueChange:S,children:[(0,J.jsx)(h,{children:(0,J.jsx)(d,{placeholder:`Recipient`})}),(0,J.jsx)(g,{children:t.map(e=>(0,J.jsx)(y,{value:e.id,children:e.name},e.id))})]})]})]})}var X=({drafts:e})=>{let[t,n]=(0,q.useState)(e.map(e=>k(L(c,e)))),[o,d]=(0,q.useState)(F(U(new Date,1),`yyyy-MM-dd`)),[{data:f},p]=a({query:i,variables:{issueMonth:o},pause:!0});(0,q.useEffect)(()=>{f?.periodicalDocumentDrafts&&n(f.periodicalDocumentDrafts.map(e=>k(L(c,e))))},[f,n]),(0,q.useEffect)(()=>{p()},[o,p]);let m=E({values:{generateDocumentsInfo:t}}),{issueDocuments:h}=K(),[{data:g}]=a({query:r}),{fields:v,append:y,remove:b,update:x}=w({control:m.control,name:`generateDocumentsInfo`}),M=m.watch(`generateDocumentsInfo`),I=(0,q.useMemo)(()=>v.map((e,t)=>({...e,...M[t],id:e.client?.id})),[v,M]),W=(0,q.useCallback)(e=>{h(e)},[h]),X=(0,q.useMemo)(()=>g?.allOpenContracts.filter(e=>e.billingCycle===s.Monthly&&!I.some(t=>t.client?.id===e.client.id)),[I,g]);return(0,J.jsx)(`div`,{className:`p-2`,children:(0,J.jsx)(C,{...m,children:(0,J.jsxs)(`form`,{onSubmit:m.handleSubmit(W),children:[(0,J.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,J.jsx)(_,{children:`Issue Month:`}),(0,J.jsx)(T,{value:new Date(o),onChange:e=>{d(F(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}})]}),(0,J.jsxs)(H,{children:[(0,J.jsx)(P,{children:(0,J.jsxs)(B,{children:[(0,J.jsx)(R,{children:`Name`}),(0,J.jsx)(R,{children:`Document`}),(0,J.jsx)(R,{children:`Amount`}),(0,J.jsx)(R,{children:`Remark`}),(0,J.jsx)(R,{children:`Recipients`}),(0,J.jsx)(R,{})]})}),(0,J.jsx)(z,{children:I.map(({id:e,...t},n)=>(0,J.jsxs)(B,{children:[(0,J.jsx)(V,{children:(0,J.jsx)(l,{to:e?u.BUSINESSES.DETAIL(e):u.BUSINESSES.ALL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.client?.name})}),(0,J.jsx)(V,{children:t.type}),(0,J.jsxs)(V,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,J.jsx)(V,{children:(0,J.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,J.jsx)(V,{children:(0,J.jsx)(`div`,{className:`flex flex-col`,children:t.client?.emails?.map(e=>(0,J.jsx)(`span`,{className:`text-sm text-gray-500`,children:e},e))})}),(0,J.jsx)(V,{children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(D,{children:[(0,J.jsx)(O,{asChild:!0,type:`button`,children:(0,J.jsx)(N,{className:`size-7.5`,variant:`secondary`,onClick:()=>b(n),children:(0,J.jsx)(S,{size:16})})}),(0,J.jsx)(A,{children:(0,J.jsx)(`p`,{children:`Remove document`})})]}),(0,J.jsx)(G,{draft:t,onApprove:e=>{m.setValue(`generateDocumentsInfo.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),x(n,{...e})}})]})})]},e))})]}),(0,J.jsxs)(`div`,{className:`flex justify-between items-center mt-4`,children:[(0,J.jsx)(Y,{clients:X?.map(e=>({id:e.client.originalBusiness.id,name:e.client.originalBusiness.name}))??[],onAdd:y,issueMonth:o}),(0,J.jsx)(j,{onConfirm:m.handleSubmit(W),title:`Are you sure you want to issue ${I.length} documents?`,children:(0,J.jsx)(N,{children:`Issue`})})]})]})})})},Z=()=>{let{setFiltersContext:e}=(0,q.useContext)(W),[{data:t,fetching:n}]=a({query:i,variables:{issueMonth:F(U(new Date,1),`yyyy-MM-dd`)}});return(0,q.useEffect)(()=>{t?.periodicalDocumentDrafts||e(null)},[t,e]),n?(0,J.jsx)(I,{}):(0,J.jsx)(X,{drafts:t?.periodicalDocumentDrafts??[]})};export{Z as IssueDocuments};