@accounter/client
Version:
Accounter client application
1 lines • 4.84 kB
JavaScript
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-B2RspeJ4.js";import{Jo as r,N as i,Ti as a,bi as o,ot as s,yi as c}from"./error-handling-Cuo-eyoB.js";import{s as l,t as u}from"./routes-IrFQohJc.js";import{a as d,c as f,f as p,i as m,l as h,lt as g,m as _,n as v,o as y,p as b,r as x,t as S,ut as C}from"./select-BjpA6f80.js";import{H as w,_t as T,h as E}from"./common-sM_dV9vy.js";import{c as D}from"./separator-DxJbp2hY.js";import{t as O}from"./button-C8JBQ3Ly.js";import{$c as k,Fl as A,Il as j,Kl as M,Qc as N,Rl as P,Wc as F,a as I,el as L,i as R,il as z,n as B,o as V,r as H,t as U}from"./table-BlmyO-VE.js";import{t as W}from"./subMonths-CKUAFqDv.js";import{r as G,t as K}from"./use-issue-monthly-documents-Du2Vbf-M.js";var q=e(n(),1),J=t();function Y({issueMonth:e,clients:t,onAdd:n}){let[i,o]=(0,q.useState)(!1),[s,l]=(0,q.useState)(``),[{data:u},g]=r({query:c,variables:{issueMonth:e,clientId:s},pause:!i}),y=(0,q.useCallback)(e=>{l(e),g()},[g,l]);return(0,q.useEffect)(()=>{s!==``&&u&&(n(E(L(a,u.clientMonthlyChargeDraft))),o(!1))},[s,u,n]),(0,J.jsxs)(f,{open:i,onOpenChange:o,children:[(0,J.jsx)(_,{asChild:!0,children:(0,J.jsx)(O,{variant:`outline`,size:`icon`,children:(0,J.jsx)(C,{})})}),(0,J.jsxs)(h,{className:`w-[400px] max-w-screen-md`,children:[(0,J.jsx)(p,{children:(0,J.jsx)(b,{children:`Select document recipient`})}),(0,J.jsxs)(S,{onValueChange:y,children:[(0,J.jsx)(m,{children:(0,J.jsx)(d,{placeholder:`Recipient`})}),(0,J.jsx)(v,{children:t.map(e=>(0,J.jsx)(x,{value:e.id,children:e.name},e.id))})]})]})]})}var X=({drafts:e})=>{let[t,n]=(0,q.useState)(e.map(e=>E(L(a,e)))),c=M(W(new Date,1),`yyyy-MM-dd`),[d,f]=(0,q.useState)(c),[{data:p},m]=r({query:o,variables:{issueMonth:d},pause:!0});(0,q.useEffect)(()=>{p?.periodicalDocumentDrafts&&n(p.periodicalDocumentDrafts.map(e=>E(L(a,e))))},[p,n]),(0,q.useEffect)(()=>{m()},[d,m]);let h=k({values:{generateDocumentsInfo:t}}),{issueDocuments:_}=K(),[{data:v}]=r({query:i}),{fields:b,append:x,remove:S,update:C}=N({control:h.control,name:`generateDocumentsInfo`}),D=h.watch(`generateDocumentsInfo`),z=(0,q.useMemo)(()=>b.map((e,t)=>({...e,...D[t],id:e.client?.id})),[b,D]),X=(0,q.useCallback)(e=>{_(e)},[_]),Z=(0,q.useMemo)(()=>v?.allOpenContracts.filter(e=>e.billingCycle===s.Monthly&&!z.some(t=>t.client?.id===e.client.id)),[z,v]);return(0,J.jsx)(`div`,{className:`p-2`,children:(0,J.jsx)(F,{...h,children:(0,J.jsxs)(`form`,{onSubmit:h.handleSubmit(X),children:[(0,J.jsxs)(`div`,{className:`flex gap-2 items-center mb-4`,children:[(0,J.jsx)(y,{children:`Issue Month:`}),(0,J.jsx)(T,{value:new Date(d),onChange:e=>{let t=new Date(e.getFullYear(),e.getMonth(),15);f(M(t,`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}})]}),(0,J.jsxs)(U,{children:[(0,J.jsx)(I,{children:(0,J.jsxs)(V,{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)(B,{children:z.map(({id:e,...t},n)=>(0,J.jsxs)(V,{children:[(0,J.jsx)(H,{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)(H,{children:t.type}),(0,J.jsxs)(H,{children:[t.income?.[0]?.price,` `,t.income?.[0]?.currency]}),(0,J.jsx)(H,{children:(0,J.jsx)(`span`,{className:`text-sm text-gray-500 whitespace-normal max-w-50`,children:t.remarks})}),(0,J.jsx)(H,{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)(H,{children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,J.jsxs)(A,{children:[(0,J.jsx)(P,{asChild:!0,type:`button`,children:(0,J.jsx)(O,{className:`size-7.5`,variant:`secondary`,onClick:()=>S(n),children:(0,J.jsx)(g,{size:16})})}),(0,J.jsx)(j,{children:(0,J.jsx)(`p`,{children:`Remove document`})})]}),(0,J.jsx)(G,{draft:t,onApprove:e=>{h.setValue(`generateDocumentsInfo.${n}`,e,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0}),C(n,{...e})}})]})})]},e))})]}),(0,J.jsxs)(`div`,{className:`flex justify-between items-center mt-4`,children:[(0,J.jsx)(Y,{clients:Z?.map(e=>({id:e.client.originalBusiness.id,name:e.client.originalBusiness.name}))??[],onAdd:x,issueMonth:d}),(0,J.jsx)(w,{onConfirm:h.handleSubmit(X),title:`Are you sure you want to issue ${z.length} documents?`,children:(0,J.jsx)(O,{children:`Issue`})})]})]})})})},Z=()=>{let{setFiltersContext:e}=(0,q.useContext)(D),[{data:t,fetching:n}]=r({query:o,variables:{issueMonth:M(W(new Date,1),`yyyy-MM-dd`)}});return(0,q.useEffect)(()=>{t?.periodicalDocumentDrafts||e(null)},[t,e]),n?(0,J.jsx)(z,{}):(0,J.jsx)(X,{drafts:t?.periodicalDocumentDrafts??[]})};export{Z as IssueDocuments};