@accounter/client 0.0.8-alpha-20251022162652-6facbcde08fdda0fb354ba7105432df320367509 → 0.0.8-alpha-20251023070808-bdd9d09db3d693f2c0061a2bbd66a4bfe5224012

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +26 -2
  2. package/dist/assets/Checkbox-Bm30-WRa.js +6 -0
  3. package/dist/assets/Progress-DxcT-wYo.js +1 -0
  4. package/dist/assets/Typography-CZLHs9y2.js +1 -0
  5. package/dist/assets/accordion-_VaDHoQb.js +1 -0
  6. package/dist/assets/accountant-approvals-C7GnMLyl.js +1 -0
  7. package/dist/assets/all-charges-DS-mdep6.js +1 -0
  8. package/dist/assets/arrow-up-down-Bt3_puEZ.js +6 -0
  9. package/dist/assets/business-Db4PzgLz.js +42 -0
  10. package/dist/assets/business-transactions-single-Canul8rR.js +1 -0
  11. package/dist/assets/business-trip-x8lljSMP.js +1 -0
  12. package/dist/assets/charges-filters-DkO9FBdC.js +1 -0
  13. package/dist/assets/charges-ledger-validation-wla_aWIc.js +1 -0
  14. package/dist/assets/chart-2uS7cQLX.js +74 -0
  15. package/dist/assets/data-table-pagination-CQQBbtVE.js +11 -0
  16. package/dist/assets/editable-business-trip-D50scoPo.js +16 -0
  17. package/dist/assets/graphql-document-dedupe-fragments-ByT8-wlV.js +1 -0
  18. package/dist/assets/index-B20Tn_iF.js +6 -0
  19. package/dist/assets/index-BJ63UrPP.js +24 -0
  20. package/dist/assets/index-BNPAKzBY.js +137 -0
  21. package/dist/assets/index-BP2Hv2J-.js +1 -0
  22. package/dist/assets/index-BTiGhl3N.js +11 -0
  23. package/dist/assets/index-BaDl3RPI.js +1 -0
  24. package/dist/assets/index-BmSAw35b.js +1 -0
  25. package/dist/assets/index-BsGG-RLV.js +876 -0
  26. package/dist/assets/index-Bskia9ol.js +1 -0
  27. package/dist/assets/index-C4JVZBO-.js +1 -0
  28. package/dist/assets/index-CDHKPA0l.js +1 -0
  29. package/dist/assets/index-CqZy7PVr.js +17 -0
  30. package/dist/assets/index-CzzfC-dD.css +1 -0
  31. package/dist/assets/index-D2w9iaKk.js +1 -0
  32. package/dist/assets/index-D5CFY1GF.js +1 -0
  33. package/dist/assets/index-DBjj2AmF.js +1 -0
  34. package/dist/assets/index-DJ33tRZ1.js +1 -0
  35. package/dist/assets/index-DKS2QKOQ.js +1 -0
  36. package/dist/assets/index-DOKYSdGb.js +1 -0
  37. package/dist/assets/index-D_PykgGt.js +2 -0
  38. package/dist/assets/index-Dk4NeG4m.js +1 -0
  39. package/dist/assets/index-Dkqd5T8J.js +2 -0
  40. package/dist/assets/index-IN8Kpfsx.js +6 -0
  41. package/dist/assets/index-OqG78rNq.js +9 -0
  42. package/dist/assets/{index.es-Bh5tff8R.js → index.es-DKjfxgqg.js} +5 -5
  43. package/dist/assets/issue-document-BFOjGS-U.js +1 -0
  44. package/dist/assets/login-page-CpRailN7.js +1 -0
  45. package/dist/assets/missing-info-charges-BnYMeatL.js +1 -0
  46. package/dist/assets/page-not-found-BLrYvmf4.js +1 -0
  47. package/dist/assets/pencil-DC6M9VTY.js +6 -0
  48. package/dist/assets/report-commentary-row-DJPRyQur.js +1 -0
  49. package/dist/assets/save-Dr3CNkcl.js +11 -0
  50. package/dist/assets/sequential-CAnleQny.js +1 -0
  51. package/dist/assets/similar-charges-by-business-modal-CCw5opHn.js +1 -0
  52. package/dist/assets/sub-DKnwnbwx.js +1 -0
  53. package/dist/assets/subMonths-B44KizJf.js +1 -0
  54. package/dist/index.html +2 -2
  55. package/package.json +2 -2
  56. package/src/components/business-transactions/business-extended-info.tsx +13 -15
  57. package/src/components/business-transactions/business-transactions-single.tsx +3 -3
  58. package/src/components/business-transactions/index.tsx +12 -1
  59. package/src/components/business-trips/business-trip.tsx +3 -3
  60. package/src/components/charges/cells/business-trip.tsx +6 -8
  61. package/src/components/charges/cells/counterparty.tsx +7 -5
  62. package/src/components/common/accounter-table.tsx +6 -5
  63. package/src/components/common/business-trip-report/parts/core-expense-row.tsx +11 -9
  64. package/src/components/common/business-trip-report/parts/uncategorized-transactions.tsx +11 -13
  65. package/src/components/common/buttons/index.ts +0 -2
  66. package/src/components/common/buttons/logout-button.tsx +7 -6
  67. package/src/components/common/documents-to-charge-matcher/selection-handler/index.tsx +4 -2
  68. package/src/components/common/documents-to-charge-matcher/selection-handler/wide-filtered-selection.tsx +5 -7
  69. package/src/components/common/forms/edit-document.tsx +21 -10
  70. package/src/components/common/new-documents-list.tsx +10 -8
  71. package/src/components/documents-table/cells/creditor.tsx +11 -4
  72. package/src/components/documents-table/cells/debtor.tsx +11 -4
  73. package/src/components/error-boundary.tsx +189 -0
  74. package/src/components/layout/breadcrumbs.tsx +72 -0
  75. package/src/components/layout/dashboard-layout.tsx +4 -0
  76. package/src/components/layout/document-title.tsx +26 -0
  77. package/src/components/layout/navigation-progress.tsx +52 -0
  78. package/src/components/layout/page-skeleton.tsx +49 -0
  79. package/src/components/layout/sidelinks.tsx +28 -27
  80. package/src/components/ledger-table/counterparty-cell.tsx +19 -13
  81. package/src/components/login-page.tsx +2 -1
  82. package/src/components/reports/corporate-tax-ruling-compliance-report/index.tsx +3 -3
  83. package/src/components/reports/profit-and-loss-report/index.tsx +3 -3
  84. package/src/components/reports/tax-report/index.tsx +3 -3
  85. package/src/components/screens/businesses/business.tsx +21 -9
  86. package/src/components/screens/charges/charge.tsx +22 -9
  87. package/src/components/transactions-table/cells/counterparty.tsx +9 -2
  88. package/src/components/transactions-table/cells-legacy/counterparty.tsx +9 -2
  89. package/src/index.tsx +4 -22
  90. package/src/providers/auth-guard.tsx +14 -23
  91. package/src/providers/index.tsx +7 -2
  92. package/src/providers/urql-client.ts +86 -0
  93. package/src/providers/urql.tsx +7 -12
  94. package/src/providers/user-provider.tsx +3 -2
  95. package/src/router/config.tsx +534 -0
  96. package/src/router/layouts/dashboard-layout.tsx +20 -0
  97. package/src/router/layouts/root-layout.tsx +69 -0
  98. package/src/router/loaders/auth-loader.ts +32 -0
  99. package/src/router/loaders/business-loader.ts +25 -0
  100. package/src/router/loaders/charge-loader.ts +25 -0
  101. package/src/router/loaders/index.ts +17 -0
  102. package/src/router/routes.ts +88 -0
  103. package/src/router/types.ts +68 -0
  104. package/dist/assets/index-B2UYAO1O.css +0 -1
  105. package/dist/assets/index-D312yRtG.js +0 -1229
  106. package/src/components/common/buttons/button-with-label.tsx +0 -41
  107. package/src/components/common/buttons/button.tsx +0 -44
@@ -0,0 +1 @@
1
+ import{p as v,fY as B,r as u,t as m,s as F,aM as H,j as e,a4 as C,a5 as j,a6 as f,a7 as p,Q as L,a8 as y,a9 as S,bR as K,bS as Q,aQ as V,aK as _,ao as D,ap as E,B as h,ar as M,as as R,at as A,k,l as $,fZ as z,ca as G,a as O,f_ as Y,L as P,F as Z,dm as J,c as W,dq as X,dr as ee,ds as T,dt as se,du as b,dv as te,dw as w,f$ as ae,dC as re,dD as oe,dE as ne}from"./index-BsGG-RLV.js";import{D as ie}from"./data-table-pagination-CQQBbtVE.js";import{A as N}from"./arrow-up-down-Bt3_puEZ.js";const de="insertTaxCategory",ce=()=>{const[{fetching:s},n]=v(B),t=u.useCallback(async a=>{const d="Error creating tax category",r=de;m.loading("Adding Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r);if(l)return m.success("Success",{id:r,description:`${l.insertTaxCategory.name} was created`}),l.insertTaxCategory}catch(i){console.error(`${d}: ${i}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,insertTaxCategory:t}};function q({formManager:s,setFetching:n,isInsert:t}){const{control:a,watch:d,setValue:r}=s,{selectableSortCodes:i,fetching:l,sortCodes:x}=H();u.useEffect(()=>{n(l)},[n,l]);const c=d("sortCode");return u.useEffect(()=>{if(c){const o=x.find(g=>g.key===c);o?.defaultIrsCode&&r("irsCode",o.defaultIrsCode,{shouldDirty:!0})}},[c,x,r]),e.jsxs(e.Fragment,{children:[e.jsx(C,{name:"name",control:a,rules:{required:"Required",minLength:{value:2,message:"Must be at least 2 characters"}},render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"Name"}),e.jsx(p,{children:e.jsx(L,{...o,value:o.value??void 0,required:!0,className:t?"":y(g)})}),e.jsx(S,{})]})}),e.jsx(K,{name:"sortCode",control:a,render:({field:o,fieldState:g})=>e.jsx(Q,{...o,onChange:U=>{o.onChange(Number(U))},data:i,value:o.value?.toString(),disabled:l,label:"Sort Code",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,className:t?"":y(g)})}),e.jsx(C,{name:"irsCode",control:a,render:({field:o,fieldState:g})=>e.jsxs(j,{children:[e.jsx(f,{children:"IRS Code"}),e.jsx(p,{children:e.jsx(V,{...o,className:t?"":y(g),value:o.value??void 0,hideControls:!0,decimalScale:0})}),e.jsx(S,{})]})}),e.jsx(C,{control:a,name:"taxExcluded",render:({field:o})=>e.jsxs(j,{className:"flex flex-row items-center justify-between",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(f,{children:"Tax excluded category"})}),e.jsx(p,{children:e.jsx(_,{onCheckedChange:o.onChange,checked:o.value??void 0})})]})})]})}function le({onAdd:s}){const[n,t]=u.useState(!1);return e.jsxs(D,{open:n,onOpenChange:t,children:[e.jsx(E,{asChild:!0,children:e.jsx(h,{children:"Add Tax Category"})}),e.jsxs(M,{className:"w-[90vw] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Add New Tax Category"})}),e.jsx(xe,{close:()=>t(!1),onAdd:s})]})]})}function xe({close:s,onAdd:n}){const t=k({}),{handleSubmit:a}=t,[d,r]=u.useState(!1),{insertTaxCategory:i,fetching:l}=ce(),x=c=>{c.sortCode&&=parseInt(c.sortCode.toString()),i({fields:c}).then(o=>{o?.id&&(n?.(o.id),s())})};return e.jsx($,{...t,children:e.jsxs("form",{onSubmit:a(x),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(q,{isInsert:!0,formManager:t,setFetching:r})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(h,{type:"submit",disabled:l||d,children:"Add Tax Category"})})]})})}const ue="updateTaxCategory",ge=()=>{const[{fetching:s},n]=v(z),t=u.useCallback(async a=>{const d="Error updating tax category",r=`${ue}-${a.taxCategoryId}`;m.loading("Uploading Tax Category",{id:r});try{const i=await n(a),l=F(i,d,r,"updateTaxCategory");if(l)return m.success("Success",{id:r,description:`${l.updateTaxCategory.name} was updated`}),l.updateTaxCategory}catch(i){console.error(`${d}: ${i}`),m.error("Error",{id:r,description:d,duration:1e5,closeButton:!0})}},[n]);return{fetching:s,updateTaxCategory:t}};function me({taxCategoryId:s,onAdd:n}){const[t,a]=u.useState(!1);return e.jsxs(D,{open:t,onOpenChange:a,children:[e.jsx(E,{asChild:!0,children:e.jsx(h,{variant:"outline",size:"icon",children:e.jsx(G,{})})}),e.jsxs(M,{className:"w-[400px] max-w-screen-md",children:[e.jsx(R,{children:e.jsx(A,{children:"Edit Tax Category"})}),e.jsx(he,{taxCategoryId:s,close:()=>a(!1),onAdd:n})]})]})}function he({taxCategoryId:s,close:n,onAdd:t}){const[{data:a,fetching:d}]=O({query:Y,variables:{id:s}}),r=a?.taxCategory;return!r&&!d&&m.error("Error",{description:"Couldn'nt find tax category"}),d?e.jsx(P,{className:"h-10 w-10 animate-spin"}):e.jsx(Ce,{taxCategory:r,close:n,onAdd:t})}function Ce({taxCategory:s,close:n,onAdd:t}){const a=k({defaultValues:{sortCode:s.sortCode?.key,name:s.name,irsCode:s.irsCode}}),{handleSubmit:d}=a,[r,i]=u.useState(!1),{updateTaxCategory:l,fetching:x}=ge(),c=o=>{o.sortCode&&=parseInt(o.sortCode.toString()),l({fields:o,taxCategoryId:s.id}).then(g=>{g?.id&&(t?.(g.id),n())})};return e.jsx($,{...a,children:e.jsxs("form",{onSubmit:d(c),children:[e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx(q,{isInsert:!1,formManager:a,setFetching:i})}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsx(h,{type:"submit",disabled:x||r,children:"Update"})})]})})}const je=({data:s})=>e.jsx("td",{children:s.name}),fe=({data:s})=>e.jsx("td",{children:s.sortCode?e.jsxs("span",{children:[s.sortCode?.name," (",s.sortCode?.id,")"]}):"N/A"}),I=[{id:"name",accessorKey:"name",cell:({row:s})=>e.jsx(je,{data:s.original}),header:({column:s})=>e.jsxs(h,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Name",e.jsx(N,{})]})},{id:"sortCode",accessorKey:"sortCode.key",cell:({row:s})=>e.jsx(fe,{data:s.original}),header:({column:s})=>e.jsxs(h,{variant:"ghost",onClick:()=>s.toggleSorting(s.getIsSorted()==="asc"),children:["Sort Code",e.jsx(N,{})]})},{id:"edit",cell:({row:s})=>e.jsx(me,{taxCategoryId:s.original.id})}],Se=()=>{const[{data:s,fetching:n,error:t},a]=O({query:ae}),{setFiltersContext:d}=u.useContext(Z),r=s?.taxCategories??[],i=J({data:r,columns:I,getCoreRowModel:ne(),getPaginationRowModel:oe(),getSortedRowModel:re(),initialState:{pagination:{pageSize:30}}}),l=i.getPageOptions();return u.useEffect(()=>{d(e.jsx("div",{className:"flex items-center justify-end gap-10 space-x-2 py-4",children:e.jsx("div",{className:"flex items-center justify-between px-2",children:e.jsx(ie,{table:i})})}))},[d,i,l]),u.useEffect(()=>{t&&m.error("Error",{description:"Error fetching tax categories"})},[t]),e.jsx(W,{title:`Tax Categories (${r.length})`,description:"All tax categories",headerActions:e.jsx(le,{onAdd:()=>a()}),children:n?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(P,{className:"h-10 w-10 animate-spin mr-2"})}):e.jsx("div",{className:"flex flex-col gap-4 rounded-md border",children:e.jsxs(X,{children:[e.jsx(ee,{children:i.getHeaderGroups().map(x=>e.jsx(T,{children:x.headers.map(c=>e.jsx(se,{children:c.isPlaceholder?null:b(c.column.columnDef.header,c.getContext())},c.id))},x.id))}),e.jsx(te,{children:i.getRowModel().rows.length===0?e.jsx(T,{children:e.jsx(w,{colSpan:I.length,className:"text-center py-8",children:"No tax categories found"})}):i.getRowModel().rows.map(x=>e.jsx(T,{children:x.getVisibleCells().map(c=>e.jsx(w,{children:b(c.column.columnDef.cell,c.getContext())},c.id))},x.id))})]})})})};export{Se as TaxCategories};
@@ -0,0 +1,11 @@
1
+ import{V,p as B,eC as q,r,t as k,s as F,a as $,eD as _,j as s,w as L,eE as R,x as H,B as Q,y as X,z as G}from"./index-BsGG-RLV.js";import{C as J,M as K}from"./Checkbox-Bm30-WRa.js";/**
2
+ * @license lucide-react v0.546.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const U=[["path",{d:"M21 10.656V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.344",key:"2acyp4"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]],g=V("square-check-big",U);/**
7
+ * @license lucide-react v0.546.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const W=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]],N=V("square-x",W),Y="mergeCharges",Z=()=>{const[{fetching:C},a]=B(q),c=r.useCallback(async x=>{const u=`Error merging into charge ID [${x.baseChargeID}]`,l=`${Y}-${x.baseChargeID}`;k.loading("Merging Charges",{id:l});try{const d=await a(x),n=F(d,u,l,"mergeCharges");if(n)return k.success("Success",{id:l,description:"Charges were merged"}),n.mergeCharges.charge}catch(d){console.error(`${u}: ${d}`),k.error("Error",{id:l,description:u,duration:1e5,closeButton:!0})}},[a]);return{fetching:C,mergeCharges:c}};function ee({chargeIds:C,onDone:a,resetMerge:c}){const{mergeCharges:x,fetching:u}=Z(),l=Array.from(new Set(C)),[{data:d,fetching:n}]=$({query:_,variables:{chargeIds:l}}),[i,w]=r.useState(d?.chargesByIDs[0]),[m,p]=r.useState(void 0),[f,z]=r.useState(void 0),[j,I]=r.useState(void 0),[v,M]=r.useState(void 0),[D,T]=r.useState(void 0),[y,A]=r.useState(void 0),[b,O]=r.useState(void 0),[h,P]=r.useState(void 0),S=d?.chargesByIDs.length!==l.length&&"Some charges were not Found"||void 0,o=d?.chargesByIDs||[],E=r.useCallback(async()=>{if(!i){k.error("Error",{description:"No main charge selected"});return}if(l.length<2){k.error("Error",{description:"At least 2 charges are required to execute a merge"});return}let e;return m&&m.value!==i.userDescription&&(e??={},e={...e,userDescription:m.value}),f&&f.value!==i.owner.id&&(e??={},e={...e,ownerId:f.value}),y&&y.value!==i.conversion&&(e??={},e={...e,isConversion:y.value}),j&&j.value!==i.property&&(e??={},e={...e,isProperty:j.value}),v&&v.value!==i.optionalVAT&&(e??={},e={...e,optionalVAT:v.value}),D&&D.value!==i.optionalDocuments&&(e??={},e={...e,optionalDocuments:D.value}),h&&h.value!==i.tags.map(t=>t.name).join(",")&&(e??={},e={...e,tags:h.value.split(",").filter(t=>t!=="").map(t=>({id:t}))}),b&&b.value!==i.isInvoicePaymentDifferentCurrency&&(e??={},e={...e,isInvoicePaymentDifferentCurrency:b.value}),await x({baseChargeID:i.id,chargeIdsToMerge:l.filter(t=>t!==i.id),fields:e}),c(),a()},[i,l,x,m,f,y,j,v,b,h,a,c]);return s.jsxs(s.Fragment,{children:[n&&s.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:s.jsx(L,{})}),!n&&S&&s.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:s.jsx("h3",{className:"sm:text-2xl text-xl font-medium title-font mb-6 text-gray-900",children:S})}),!n&&!S&&s.jsxs(s.Fragment,{children:[s.jsxs("table",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:"Main"}),o.map(e=>s.jsx("td",{children:s.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-b-0 rounded-t-xl",children:s.jsx(J,{checked:e.id===i?.id,size:"xl",onClick:()=>{w(e),p({id:e.id,value:e.userDescription??""}),z({id:e.id,value:e.owner.id}),I({id:e.id,value:e.property??!1}),M({id:e.id,value:e.optionalVAT??!1}),T({id:e.id,value:e.optionalDocuments??!1}),O({id:e.id,value:e.isInvoicePaymentDifferentCurrency??!1}),A({id:e.id,value:e.conversion??!1}),P({id:e.id,value:(e.tags.map(t=>t.name)??[]).join(",")})}})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Description"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:!e.userDescription||m?.value===e.userDescription,onClick:()=>p({id:e.id,value:e.userDescription??""}),children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:m?.id===e.id?{background:"#228be633"}:{},children:e.userDescription})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Owner"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:f?.value===e.owner.id,onClick:()=>z({id:e.id,value:e.owner.id}),children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:f?.id===e.id?{background:"#228be633"}:{},children:e.owner.name})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Is Property"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.property==null||e.property===j?.value,onClick:()=>{I({id:e.id,value:e.property??!1})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:j?.id===e.id?{background:"#228be633"}:{},children:e.property?s.jsx(g,{size:20,color:"green"}):s.jsx(N,{size:20,color:"red"})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Is Conversion"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.conversion==null||e.conversion===y?.value,onClick:()=>{A({id:e.id,value:e.conversion??!1})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:y?.id===e.id?{background:"#228be633"}:{},children:e.conversion?s.jsx(g,{size:20,color:"green"}):s.jsx(N,{size:20,color:"red"})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Optional VAT"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.optionalVAT==null||e.optionalVAT===v?.value,onClick:()=>{M({id:e.id,value:e.optionalVAT??!1})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:v?.id===e.id?{background:"#228be633"}:{},children:e.optionalVAT?s.jsx(g,{size:20,color:"green"}):s.jsx(N,{size:20,color:"red"})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Optional Documents"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.optionalDocuments==null||e.optionalDocuments===D?.value,onClick:()=>{T({id:e.id,value:e.optionalDocuments??!1})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:D?.id===e.id?{background:"#228be633"}:{},children:e.optionalDocuments?s.jsx(g,{size:20,color:"green"}):s.jsx(N,{size:20,color:"red"})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Invoice-Payment Currency Difference"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.isInvoicePaymentDifferentCurrency==null||e.isInvoicePaymentDifferentCurrency===b?.value,onClick:()=>{I({id:e.id,value:e.isInvoicePaymentDifferentCurrency??!1})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:b?.id===e.id?{background:"#228be633"}:{},children:e.isInvoicePaymentDifferentCurrency?s.jsx(g,{size:20,color:"green"}):s.jsx(N,{size:20,color:"red"})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Tags"}),o.map(e=>s.jsx("td",{children:s.jsx("button",{className:"w-full px-2",disabled:e.tags==null||e.tags.map(t=>t.name).join(",")===h?.value,onClick:()=>{P({id:e.id,value:(e.tags.map(t=>t.name)??[]).join(",")})},children:s.jsx("div",{className:"flex items-center justify-center px-2 py-2 border-x-2",style:h?.id===e.id?{background:"#228be633"}:{},children:s.jsx(R,{items:e.tags.map(t=>s.jsxs("div",{className:"flex flex-col items-center",children:[s.jsx("div",{children:t.name}),t.namePath&&s.jsx("div",{children:t.namePath.join(" > ")})]},t.id))})})})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Transactions"}),o.map(e=>s.jsx("td",{children:s.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-x-2",children:e.metadata?.transactionsCount??0})},e.id))]}),s.jsxs("tr",{children:[s.jsx("th",{children:"Invoices"}),o.map(e=>s.jsx("td",{children:s.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-t-0 rounded-b-xl",children:e.metadata?.invoicesCount??0})},e.id))]})]}),s.jsxs("div",{className:"flex justify-center gap-5 mt-5",children:[s.jsx("button",{type:"button",className:" text-white bg-blue-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-blue-600 rounded-sm text-lg",disabled:n||u,onClick:E,children:"Accept"}),s.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:a,children:"Cancel"}),s.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:()=>{c(),a()},children:"Reset Merge"})]})]})]})}function ie(C){const[a,{close:c,open:x}]=H(!1),{selected:u,resetMerge:l}=C,d=new Set(u.map(({id:p})=>p)),n=d.size>=1,[i,w]=r.useState(n?"default":"outline");r.useEffect(()=>{w(n?"default":"outline")},[n]);const m=r.useCallback(()=>{c(),u.map(({onChange:p})=>p())},[u,c]);return s.jsxs(s.Fragment,{children:[s.jsx(Q,{onClick:()=>{n&&x()},disabled:!n,variant:i,className:X("size-7.5",n?" bg-blue-500 hover:bg-blue-500/90":""),size:"icon",children:s.jsx(K,{className:"size-5"})}),s.jsx(G,{opened:a,onClose:c,size:"auto",centered:!0,children:s.jsx(ee,{chargeIds:Array.from(d),onDone:m,resetMerge:l})})]})}export{ie as M};
@@ -0,0 +1 @@
1
+ import{r as c,a as N,i as k,j as e,e as w,U as E,k as z,l as D,m as L,n as A,o as T,p as O,q as P,t as B,s as R,v as U,w as $,x as q,B as C,y as S,z as H,D as v,G as _,H as Q,P as F,b as I,J as V,K as G,N as J,u as M,O as K,Q as W,F as X,T as Y,c as Z,L as ee,R as se,S as te}from"./index-BsGG-RLV.js";import{C as ne,M as ie}from"./Checkbox-Bm30-WRa.js";import{u as ae,S as re}from"./similar-charges-by-business-modal-CCw5opHn.js";function oe({businessID:t,updateBusiness:n}){const[r,u]=c.useState(void 0),[{data:o,fetching:i},l]=N({query:k,variables:{id:t}});return c.useEffect(()=>{i?u(void 0):o&&o.business.__typename==="LtdFinancialEntity"&&u(o.business)},[o,i]),c.useEffect(()=>{r&&n(r)},[r,n]),e.jsx("div",{className:"flex flex-col gap-5",children:r?e.jsx(le,{business:r,refetchBusiness:l}):i?e.jsx(w,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}):e.jsx("p",{children:"Error fetching extended information for this business"})})}function le({business:t,refetchBusiness:n}){const[r,u]=c.useState(!1),[o,i]=c.useState(!1),[l,d]=c.useState(void 0),{userContext:g}=c.useContext(E),{updateBusiness:f,fetching:a}=ae(),x=z({defaultValues:{...t,taxCategory:t.taxCategory?.id,sortCode:t?.sortCode?.key,irsCode:t?.irsCode}}),{handleSubmit:p,formState:{dirtyFields:h}}=x,b=async j=>{if(!t||!g?.context.adminBusinessId)return;const s=T(j,h);s&&Object.keys(s).length>0&&(s.sortCode&&=parseInt(s.sortCode.toString()),s.suggestions?.tags&&(s.suggestions.tags=s.suggestions.tags.map(m=>({id:m.id}))),s.suggestions?.phrases&&(s.suggestions.phrases=j.suggestions.phrases.map(m=>m)),s.suggestions?.emails&&(s.suggestions.emails=j.suggestions.emails.map(m=>m)),s.suggestions?.emailListener&&(s.suggestions.emailListener.attachments&&=j.suggestions.emailListener.attachments.map(m=>m),s.suggestions.emailListener.internalEmailLinks&&=j.suggestions.emailListener.internalEmailLinks.map(m=>m)),await f({businessId:t.id,ownerId:g.context.adminBusinessId,fields:s}),s.suggestions?.tags?.length||s.suggestions?.description?(d({tagIds:s.suggestions?.tags?.map(m=>({id:m.id})),description:s.suggestions?.description??void 0}),i(!0)):n())};return e.jsxs(e.Fragment,{children:[r&&e.jsx(w,{className:"flex self-center my-5",color:"dark",size:"xl",variant:"dots"}),e.jsx("div",{className:"flex flex-row gap-5",children:e.jsx(D,{...x,children:e.jsxs("form",{onSubmit:p(b),children:[e.jsxs("div",{className:"flex flex-row mx-3 pt-3 sm:text-1xl gap-10",children:[e.jsx("h1",{className:"sm:text-2xl font-small text-gray-900",children:"Edit Business:"}),e.jsxs("div",{className:"flex flex-row gap-2",children:["ID: ",t.id,e.jsx(L,{content:t.id})]})]}),e.jsx("div",{className:"flex-row px-10 h-max justify-start block",children:e.jsx(A,{isInsert:!1,formManager:x,setFetching:u})}),e.jsx("div",{className:"mt-10 mb-5 flex justify-center gap-5",children:e.jsx("button",{type:"submit",onClick:()=>p(b),className:"mt-8 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",disabled:a||Object.keys(h).length===0,children:"Update"})})]})})}),e.jsx(re,{businessId:t.id,tagIds:l?.tagIds,description:l?.description,open:o,onOpenChange:i,onClose:n})]})}const ce="mergeBusinesses",de=()=>{const[{fetching:t},n]=O(P),r=c.useCallback(async u=>{const o=`Error merging into business ID [${u.targetBusinessId}]`,i=`${ce}-${u.targetBusinessId}`;B.loading("Merging Businesses",{id:i});try{const l=await n(u),d=R(l,o,i);if(d)return B.success("Success",{id:i,description:"Businesses merged"}),d.mergeBusinesses.id}catch(l){console.error(`${o}: ${l}`),B.error("Error",{id:i,description:o,duration:1e5,closeButton:!0})}},[n]);return{fetching:t,mergeBusinesses:r}};function ue({businessIds:t,onDone:n,resetMerge:r}){const{mergeBusinesses:u,fetching:o}=de(),i=Array.from(new Set(t)),[{data:l,fetching:d}]=N({query:U,variables:{businessIds:i}}),[g,f]=c.useState(l?.businesses[0]),a=l?.businesses.length!==i.length&&"Some businesses were not Found"||void 0,x=l?.businesses||[],p=c.useCallback(async()=>{if(!g){B.error("Error",{description:"No main business selected"});return}if(i.length<2){B.error("Error",{description:"At least 2 businesses are required to execute a merge"});return}return await u({targetBusinessId:g.id,businessIdsToMerge:i.filter(h=>h!==g.id)}),r(),n()},[g,i,u,n,r]);return e.jsxs(e.Fragment,{children:[d&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx($,{})}),!d&&a&&e.jsx("div",{className:"flex flex-col text-center w-full mb-1",children:e.jsx("h3",{className:"sm:text-2xl text-xl font-medium title-font mb-6 text-gray-900",children:a})}),!d&&!a&&e.jsxs(e.Fragment,{children:[e.jsxs("table",{children:[e.jsxs("tr",{children:[e.jsx("th",{children:"Main"}),x.map(h=>e.jsx("td",{children:e.jsx("div",{className:"flex items-center justify-center mx-2 px-2 py-2 border-2 border-b-0 rounded-t-xl",children:e.jsx(ne,{checked:h.id===g?.id,size:"xl",onClick:()=>{f(h)}})})},h.id))]}),e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),x.map(h=>e.jsx("td",{children:h.name},h.id))]})]}),e.jsxs("div",{className:"flex justify-center gap-5 mt-5",children:[e.jsx("button",{type:"button",className:" text-white bg-blue-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-blue-600 rounded-sm text-lg",disabled:d||o,onClick:p,children:"Accept"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:n,children:"Cancel"}),e.jsx("button",{type:"button",className:" text-white bg-red-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-red-600 rounded-sm text-lg",onClick:()=>{r(),n()},children:"Reset Merge"})]})]})]})}function ge(t){const[n,{close:r,open:u}]=q(!1),{selected:o,resetMerge:i}=t,l=new Set(o.map(({id:x})=>x)),d=l.size>=1,[g,f]=c.useState(d?"default":"outline");c.useEffect(()=>{f(d?"default":"outline")},[d]);const a=c.useCallback(()=>{r(),o.map(({onChange:x})=>x())},[o,r]);return e.jsxs(e.Fragment,{children:[e.jsx(C,{onClick:()=>{d&&u()},disabled:!d,variant:g,className:S("size-7.5",d?" bg-blue-500 hover:bg-blue-500/90":""),size:"icon",children:e.jsx(ie,{className:"size-5"})}),e.jsx(H,{opened:n,onClose:r,size:"auto",centered:!0,children:e.jsx(ue,{businessIds:Array.from(l),onDone:a,resetMerge:i})})]})}const me=({data:t})=>{const n=v(_,t);return e.jsx("td",{children:e.jsx("div",{style:{whiteSpace:"nowrap"},children:n.hebrewName})})},xe=({data:t})=>{const n=v(Q,t);return e.jsx("td",{children:e.jsx("div",{style:{whiteSpace:"nowrap"},children:n.name})})},he=({data:t,isAllOpened:n,toggleMergeBusiness:r,isSelectedForMerge:u})=>{const[o,i]=c.useState(!1),[l,d]=c.useState(v(J,t));return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx(xe,{data:l}),e.jsx(me,{data:l}),e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(C,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>{i(g=>!g)},children:n||o?e.jsx(F,{className:"size-5"}):e.jsx(I,{className:"size-5"})}),r&&e.jsx(V,{toggleMergeSelected:()=>r(()=>{}),mergeSelected:u})]})})]}),(n||o)&&e.jsx("tr",{children:e.jsx("td",{colSpan:12,children:e.jsx(G,{style:{width:"100%"},withBorder:!0,shadow:"lg",children:e.jsx(oe,{businessID:l.id,updateBusiness:d})})})})]})};function fe({activePage:t,setPage:n,totalPages:r=1,businessName:u,setBusinessName:o}){const{get:i,set:l}=M(),[d,g]=c.useState(u);c.useEffect(()=>{const a=t>1?t.toFixed(0):void 0,x=i("page");a!==x&&a!=="1"&&l("page",a)},[t,i,l]),c.useEffect(()=>{const a=setTimeout(()=>{o(d)},600);return()=>{clearTimeout(a)}},[d,o]);const f=a=>{g(a)};return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(K,{className:"flex-auto",value:t,onChange:n,total:r}),e.jsx(W,{className:"w-72",placeholder:"Business Name",defaultValue:u??void 0,onChange:a=>f(a.target.value===""?void 0:a.target.value)})]})}const Be=()=>{const{get:t}=M(),[n,r]=c.useState(!1),[u,o]=c.useState(t("page")?Number(t("page")):1),[i,l]=c.useState(t("name")?t("page"):void 0),{setFiltersContext:d}=c.useContext(X),[{data:g,fetching:f}]=N({query:te,variables:{page:u,limit:100,name:i}}),[a,x]=c.useState([]),p=c.useCallback((s,m)=>{a.map(y=>y.id).includes(s)?x(a.filter(y=>y.id!==s)):x([...a,{id:s,onChange:m}])},[a]);function h(){x([])}c.useEffect(()=>{d(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(fe,{activePage:u,setPage:o,businessName:i,setBusinessName:l,totalPages:g?.allBusinesses?.pageInfo.totalPages}),e.jsx(Y,{label:"Expand all businesses",children:e.jsx(C,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>r(s=>!s),children:n?e.jsx(F,{className:"size-5"}):e.jsx(I,{className:"size-5"})})}),e.jsx(ge,{selected:a,resetMerge:h})]}))},[g,u,i,n,d,o,l,r,a]);const b=g?.allBusinesses?.nodes.filter(s=>s.__typename==="LtdFinancialEntity").sort((s,m)=>s.name.toLowerCase()>m.name.toLowerCase()?1:-1)??[],j=new Set(a.map(s=>s.id));return e.jsx(Z,{title:`Businesses (${b.length})`,description:"All businesses",children:f?e.jsx("div",{className:"flex flex-row justify-center",children:e.jsx(ee,{className:S("h-10 w-10 animate-spin mr-2")})}):e.jsxs(se,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"px-10 py-10 title-font tracking-wider font-medium text-gray-900 text-sm bg-gray-100 rounded-tl rounded-bl",children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Hebrew Name"}),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:b.map(s=>e.jsx(he,{data:s,isAllOpened:n,toggleMergeBusiness:p?m=>p(s.id,m):void 0,isSelectedForMerge:j.has(s.id)??!1},s.id))})]})})};export{Be as Businesses};
@@ -0,0 +1 @@
1
+ import{r as l,d0 as w,u as P,d3 as K,j as e,d1 as A,bC as O,B as d,d2 as U,U as z,k as B,Y as b,dk as _,l as H,dl as L,bR as D,cj as M,bW as I,bX as k,a4 as q,a5 as G,a6 as J,a7 as Q,aK as X,bx as W,F as Y,a as Z,dm as $,c as ee,L as te,dn as se,dp as ae,dq as ne,dr as le,ds as S,dt as re,du as T,dv as ie,dw as R,dx as oe,dy as de,dz as ce,dA as me,dB as ue,dC as ge,dD as xe,dE as he}from"./index-BsGG-RLV.js";import{D as je}from"./data-table-pagination-CQQBbtVE.js";import{s as pe}from"./sub-DKnwnbwx.js";import{A as v}from"./arrow-up-down-Bt3_puEZ.js";import"./subMonths-B44KizJf.js";function fe({filter:t,setFilter:s,closeModal:h}){const{userContext:j}=l.useContext(z),x=B({defaultValues:{ownerIDs:j?.context.adminBusinessId?[j.context.adminBusinessId]:void 0,toDate:b(new Date,"yyyy-MM-dd"),fromDate:b(pe(new Date,{years:1}),"yyyy-MM-dd"),...t}}),{control:o,handleSubmit:y}=x,{selectableFinancialEntities:r,fetching:c}=_(),C=a=>{s(a),h()};function m(){s({}),h()}return e.jsxs(e.Fragment,{children:[c?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(H,{...x,children:e.jsxs("form",{onSubmit:y(C),children:[e.jsxs(L,{cols:2,children:[e.jsx(D,{name:"ownerIDs",control:o,defaultValue:t.ownerIDs,render:({field:a,fieldState:g})=>e.jsx(M,{...a,data:r,value:a.value??[],disabled:c,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"businessIDs",control:o,defaultValue:t.businessIDs,render:({field:a,fieldState:g})=>e.jsx(M,{...a,data:r,value:a.value??[],disabled:c,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"fromDate",control:o,defaultValue:t.fromDate,rules:{pattern:{value:I,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(k,{...a,onChange:i=>{const p=i?typeof i=="string"?i:b(i,"yyyy-MM-dd"):void 0;p!==a.value&&a.onChange(p)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(D,{name:"toDate",control:o,defaultValue:t.toDate,rules:{pattern:{value:I,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(k,{...a,onChange:i=>{const p=i?typeof i=="string"?i:b(i,"yyyy-MM-dd"):void 0;p!==a.value&&a.onChange(p)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(q,{name:"unmatched",control:o,render:({field:a})=>e.jsxs(G,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(J,{children:"Unmatched only"})}),e.jsx(Q,{children:e.jsx(X,{defaultChecked:t.unmatched??!1,onCheckedChange:a.onChange})})]})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:c,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:m,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:h,children:"Cancel"})]})]})})]})}function ve({filter:t={},setFilter:s,initiallyOpened:h=!1}){const[j,x]=l.useState(h),[o,y]=l.useState(!w(t)),{get:r,set:c}=P();l.useEffect(()=>{const m=w(t)?null:encodeURIComponent(JSON.stringify(t)),a=r("documentsFilters");m!==a&&c("documentsFilters",m)},[t,r,c]);const C=l.useCallback(m=>{K(m,t)||(s(m),y(!w(m)))},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(A,{opened:j,onClose:()=>x(!1),content:e.jsx(fe,{filter:t,setFilter:C,closeModal:()=>x(!1)}),modalSize:"xl"}),e.jsx(O,{inline:!0,size:16,disabled:!o,children:e.jsx(d,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(U,{className:"size-5"})})})]})}const E=[{accessorKey:"__typename",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Type"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>{const{__typename:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s})}},{accessorKey:"image",header:()=>e.jsx("div",{className:"text-left",children:"Image"}),cell:({row:t})=>{const{image:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s?e.jsx("img",{alt:"missing img",src:s?.toString(),height:80,width:80}):"No image"})}},{accessorKey:"file",header:()=>e.jsx("div",{className:"text-left",children:"File"}),cell:({row:t})=>{const{file:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s&&e.jsx(d,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("a",{target:"_blank",rel:"noreferrer",href:s?.toString(),children:"Open"})})})}},{accessorKey:"date",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Date"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"date"in t.original&&t.original.date?e.jsx("div",{className:"text-left font-medium",children:b(new Date(t.original.date),"dd/MM/yy")}):null},{accessorKey:"serialNumber",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Serial Number"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"serialNumber"in t.original&&t.original.serialNumber?e.jsx("div",{className:"text-left font-medium",children:t.original.serialNumber}):null},{accessorKey:"vat.raw",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"VAT"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"vat"in t.original&&t.original.vat?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.vat.formatted}):null},{accessorKey:"amount.raw",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Amount"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"amount"in t.original&&t.original.amount?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.amount.formatted}):null},{accessorKey:"creditor.name",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Creditor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"creditor"in t.original&&t.original.creditor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.creditor.name}):null},{accessorKey:"debtor.name",header:({column:t})=>e.jsxs(d,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Debtor"}),e.jsx(v,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"debtor"in t.original&&t.original.debtor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.debtor.name}):null},{accessorKey:"charge.transactions[0].id",header:()=>e.jsx("div",{className:"text-left",children:"Related Transaction"}),cell:({row:t})=>t.original.charge?.transactions?.[0]?.id?e.jsx(W,{items:t.original.charge?.transactions??[],columns:[{title:"Transaction Amount",value:s=>s?.amount.formatted},{title:"Transaction Created At",value:s=>s?.eventDate?b(new Date(s.eventDate),"dd/MM/yy"):null},{title:"Transaction Effective Date",value:s=>s?.effectiveDate?b(new Date(s.effectiveDate),"dd/MM/yy"):null},{title:"Transaction Description",value:s=>s?.sourceDescription}]}):"No Related Transaction"}],we=()=>{const[t,s]=l.useState(null),[h,j]=l.useState(!1),{get:x}=P(),o=x("documentsFilters"),y=l.useMemo(()=>{if(o)try{return JSON.parse(decodeURIComponent(o))}catch{return}},[o]),[r,c]=l.useState(y),[C,m]=l.useState([]),[a,g]=l.useState({}),{setFiltersContext:i}=l.useContext(Y),[{data:p,fetching:F},N]=Z({query:ue,variables:{filters:r??{}},pause:!0});l.useEffect(()=>{r&&N()},[r,N]);const f=$({data:p?.documentsByFilters??[],columns:E,getCoreRowModel:he(),getPaginationRowModel:xe(),onSortingChange:m,getSortedRowModel:ge(),onColumnVisibilityChange:g,state:{sorting:C,columnVisibility:a}}),V=f.getState().pagination.pageIndex;return l.useEffect(()=>{i(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(je,{table:f}),e.jsx(ve,{filter:r,setFilter:c,initiallyOpened:!r})]}))},[f,F,r,i,c,y,V]),e.jsx(ee,{title:"Documents",description:"All documents",headerActions:e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsxs(oe,{children:[e.jsx(de,{asChild:!0,children:e.jsx(d,{className:"ml-auto",children:"Columns"})}),e.jsx(ce,{align:"end",children:f.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(me,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:u=>n.toggleVisibility(!!u),children:n.id},n.id))})]}),e.jsx(d,{onClick:()=>j(!0),children:"Upload Documents"})]}),children:F?e.jsx(te,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx(se,{open:h,onOpenChange:j,onChange:N}),t&&e.jsx(A,{modalSize:"45%",content:e.jsx(ae,{src:t}),opened:!!t,onClose:()=>s(null)}),e.jsxs(ne,{children:[e.jsx(le,{children:f.getHeaderGroups().map(n=>e.jsx(S,{children:n.headers.map(u=>e.jsx(re,{children:u.isPlaceholder?null:T(u.column.columnDef.header,u.getContext())},u.id))},n.id))}),e.jsx(ie,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(n=>e.jsx(S,{"data-state":n.getIsSelected()&&"selected",children:n.getVisibleCells().map(u=>e.jsx(R,{children:T(u.column.columnDef.cell,u.getContext())},u.id))},n.id)):e.jsx(S,{children:e.jsx(R,{colSpan:E.length,className:"h-24 text-center",children:"No results."})})})]})]})})};export{we as DocumentsReport,E as columns};