@accounter/client
Version:
2 lines (1 loc) • 4.66 kB
JavaScript
import{r as a,j as e,D,aL as C,bU as I,bV as E,B as p,ag as T,bW as P,x as k,dB as F,dC as A,K as v,X as f,L as N,dD as S,e as B,N as G,Q as M,dE as O,bp as R,bh as L,dF as q,g as z,t as h,i as H,dG as V}from"./index-DRqooPz9.js";function U({onApprove:u,draft:o}){const[l,r]=a.useState(!1),s=t=>{u(t),r(!1)};return e.jsxs(D,{open:l,onOpenChange:r,children:[e.jsx(C,{asChild:!0,type:"button",children:e.jsxs(I,{children:[e.jsx(E,{asChild:!0,type:"button",children:e.jsx(p,{className:"size-7.5",variant:"secondary",onClick:()=>r(t=>!t),type:"button",children:e.jsx(T,{className:"size-5"})})}),e.jsx(P,{children:e.jsx("p",{children:"Edit document"})})]})}),e.jsx(k,{className:"w-7xl sm:max-w-[95%] max-h-[90vh] overflow-y-auto",children:e.jsx("div",{className:"min-h-screen bg-gray-50 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Edit Document"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Modify and preview your accounting document before issuing"})]}),e.jsx($,{onApprove:s,draft:o})]})})})]})}function $({onApprove:u,draft:o}){const[l,r]=a.useState(!1),[s,t]=a.useState(null),{previewDocument:d,fetching:i}=F(),[n,y]=a.useState(o),b=a.useCallback((c,m)=>{y(x=>({...x,[c]:m}))},[]);a.useEffect(()=>{r(!1)},[n]);const j=a.useCallback(async()=>{try{const c=await d({input:n});if(!c)throw new Error("No preview data returned");t(c),r(!0)}catch(c){console.error("Failed to generate preview:",c)}},[n,d]);a.useEffect(()=>{s||j()},[s,j]);const g=n.income?.reduce((c,m)=>{const x=m.price*m.quantity,w=x*((m.vatRate||0)/100);return c+x+w},0)||0;return e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx(A,{formData:n,updateFormData:b}),e.jsx(v,{children:e.jsxs(f,{className:"pt-6",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx(p,{onClick:j,disabled:i||l,variant:"outline",className:"flex-1 bg-transparent",children:i?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"w-4 h-4 mr-2"}),"Preview"]})}),e.jsxs(p,{onClick:()=>u(n),className:"flex-1",children:[e.jsx(B,{className:"w-4 h-4 mr-2"}),"Accept Changes"]})]}),g>0&&e.jsx("div",{className:"mt-4 p-3 bg-blue-50 rounded-lg",children:e.jsxs("div",{className:"flex justify-between items-center font-medium text-blue-900",children:[e.jsx("span",{children:"Total Document Amount:"}),e.jsxs("span",{children:[g.toFixed(2)," ",n.currency]})]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(v,{className:"h-fit",children:[e.jsx(G,{children:e.jsx(M,{children:"Document Preview"})}),e.jsx(f,{children:e.jsx("div",{className:"border-2 border-dashed border-gray-200 rounded-lg min-h-[600px] flex items-center justify-center bg-gray-50",children:i?e.jsxs("div",{className:"text-center",children:[e.jsx(N,{className:"w-8 h-8 animate-spin mx-auto mb-4 text-gray-400"}),e.jsx("p",{className:"text-gray-500",children:"Generating document preview..."})]}):s?e.jsx("div",{className:"w-full",children:e.jsx("div",{className:"bg-white shadow-lg rounded-lg overflow-hidden",children:e.jsx("div",{className:"aspect-[8.5/11] bg-white border",children:e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center p-6",children:[e.jsx(O,{src:s}),!l&&e.jsx("p",{className:"text-xs text-amber-600 mt-3 bg-amber-50 px-2 py-1 rounded",children:"Preview may be outdated"})]})})})})}):e.jsxs("div",{className:"text-center",children:[e.jsx(R,{className:"w-16 h-16 mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"text-gray-500 mb-2",children:"No preview available"}),e.jsx("p",{className:"text-sm text-gray-400",children:"Click Preview to generate document"})]})})})]}),n.client&&e.jsx(L,{businessId:n.client?.id,linkedDocumentIds:n.linkedDocumentIds??[]}),e.jsx(q,{documentType:n.type})]})]})}const K="issue-monthly-documents",W=()=>{const[{fetching:u},o]=z(V),l=a.useCallback(async r=>{const s="Error issuing monthly documents",t=K;h.loading("Issuing documents",{id:t});try{const d=await o(r),i=H(d,s,t);if(i?.issueGreenInvoiceDocuments?.success){h.success("Success",{id:t,description:"Documents issued successfully"});return}i?.issueGreenInvoiceDocuments?.errors&&console.error(i.issueGreenInvoiceDocuments.errors),h.error("Error",{id:t,description:s,duration:1e5,closeButton:!0})}catch(d){console.error(`${s}: ${d}`),h.error("Error",{id:t,description:s,duration:1e5,closeButton:!0})}},[o]);return{fetching:u,issueDocuments:l}};export{$ as E,U as a,W as u};