UNPKG

@accounter/client

Version:
1 lines • 10.4 kB
import{s as e}from"./dist-ypP48_Ax.js";import{i as t,o as n}from"./utils-CbS-oR5I.js";import{s as r,t as i}from"./routes-Cawu7UJi.js";import{n as a}from"./common-D-vYt_Yl.js";import{dt as o,pt as s}from"./select-Zdatwv1b.js";import{t as c}from"./button-DUNsVBiu.js";import{Bc as l,Ul as u,Zc as d,a as f,c as p,d as m,i as h,n as g,o as _,r as v,s as y,t as b}from"./table-AJA7Uyxy.js";import{Pn as x,Zr as S}from"./graphql-DC5GYCFE.js";var C=e(n(),1),w=t(),T=({foreignAmount:e,localAmount:t,diff:n})=>{let r=e!=null&&e.currency!==x.Ils,i=n&&n.localAmount?.formatted!==t?.formatted,a=n&&n.foreignAmount?.formatted!==e?.formatted;return(0,w.jsx)(`div`,{className:`flex flex-col`,children:(t||i)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[r&&(0,w.jsx)(`p`,{className:a?`line-through`:``,children:e.formatted}),a&&n.foreignAmount&&(0,w.jsx)(`p`,{className:`border-2 border-yellow-500 rounded-md`,children:n.foreignAmount.formatted})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[t!=null&&(0,w.jsx)(`p`,{className:i?`line-through`:``,children:t.formatted}),i&&n.localAmount&&(0,w.jsx)(`p`,{className:`border-2 border-yellow-500 rounded-md`,children:n.localAmount.formatted})]})]})})},E=({account:e,diffAccount:t})=>{let n=t&&t?.id!==e?.id;return(0,w.jsx)(`div`,{className:`flex flex-col whitespace-normal`,children:(e||n)&&(0,w.jsxs)(w.Fragment,{children:[e&&(0,w.jsx)(r,{to:i.BUSINESSES.DETAIL(e.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold ${n?`line-through`:``}`,children:e.name}),n&&t&&(0,w.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:(0,w.jsx)(r,{to:i.BUSINESSES.DETAIL(t.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.name})})]})})},D=({date:e,diff:t})=>{let n=e?u(new Date(e),`dd/MM/yy`):void 0,r=t?u(new Date(t),`dd/MM/yy`):void 0,i=r&&n!==r;return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`p`,{className:i?`line-through`:``,children:n??`Missing Data`}),i&&(0,w.jsx)(`div`,{className:`flex flex-col border-2 border-yellow-500 rounded-md`,children:r})]})},O=(e,t)=>{let n=e.original[t],r=e.original.diff?.[t];return!n&&!r},k=[{accessorKey:`invoiceDate`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Invoice Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(D,{date:e.original.invoiceDate,diff:e.original.diff?.invoiceDate})},{accessorKey:`valueDate`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Value Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(D,{date:e.original.valueDate,diff:e.original.diff?.valueDate})},{header:`Debit Account (Main)`,columns:[{accessorKey:`debitAccount1.name`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(E,{account:e.original.debitAccount1,diffAccount:e.original.diff?.debitAccount1})},{accessorKey:`localCurrencyDebitAmount1.raw`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>O(e,`debitAccount1`)?null:(0,w.jsx)(T,{foreignAmount:e.original.debitAmount1,localAmount:e.original.localCurrencyDebitAmount1,diff:e.original.diff?{foreignAmount:e.original.diff.debitAmount1,localAmount:e.original.diff.localCurrencyDebitAmount1}:void 0})}]},{header:`Credit Account (Main)`,columns:[{accessorKey:`creditAccount1.name`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(E,{account:e.original.creditAccount1,diffAccount:e.original.diff?.creditAccount1})},{accessorKey:`localCurrencyCreditAmount1.raw`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>O(e,`creditAccount1`)?null:(0,w.jsx)(T,{foreignAmount:e.original.creditAmount1,localAmount:e.original.localCurrencyCreditAmount1,diff:e.original.diff?{foreignAmount:e.original.diff.creditAmount1,localAmount:e.original.diff.localCurrencyCreditAmount1}:void 0})}]},{header:`Debit Account (Secondary)`,columns:[{accessorKey:`debitAccount2.name`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(E,{account:e.original.debitAccount2,diffAccount:e.original.diff?.debitAccount2})},{accessorKey:`localCurrencyDebitAmount2.raw`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>O(e,`debitAccount2`)?null:(0,w.jsx)(T,{foreignAmount:e.original.debitAmount2,localAmount:e.original.localCurrencyDebitAmount2,diff:e.original.diff?{foreignAmount:e.original.diff.debitAmount2,localAmount:e.original.diff.localCurrencyDebitAmount2}:void 0})}]},{header:`Credit Account (Secondary)`,columns:[{accessorKey:`creditAccount2.name`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,w.jsx)(E,{account:e.original.creditAccount2,diffAccount:e.original.diff?.creditAccount2})},{accessorKey:`localCurrencyCreditAmount2.raw`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>O(e,`creditAccount2`)?null:(0,w.jsx)(T,{foreignAmount:e.original.creditAmount2,localAmount:e.original.localCurrencyCreditAmount2,diff:e.original.diff?{foreignAmount:e.original.diff.creditAmount2,localAmount:e.original.diff.localCurrencyCreditAmount2}:void 0})}]},{accessorKey:`description`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Details`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:e}})=>{let t=e.diff&&e.diff.description!==e.description;return(0,w.jsxs)(`div`,{className:`flex flex-col whitespace-normal`,children:[(0,w.jsx)(`p`,{className:t?`line-through`:``,children:e.description}),t&&(0,w.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:e.diff?.description})]})}},{accessorKey:`reference`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Reference`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:e}})=>{let t=e.diff&&e.diff.reference!==e.reference;return(0,w.jsxs)(`div`,{className:`flex flex-col whitespace-normal`,children:[(0,w.jsx)(`p`,{className:t?`line-through`:``,children:e.reference}),t&&(0,w.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:e.diff?.reference})]})}},{accessorKey:`matchingStatus`,header:({column:e})=>(0,w.jsxs)(c,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Status`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,w.jsx)(o,{className:`ml-2 h-4 w-4`}):(0,w.jsx)(s,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:{matchingStatus:e}}})=>e?(0,w.jsx)(l,{variant:`default`,className:e===`Deleted`?`bg-red-500`:e===`Diff`?`bg-yellow-500`:`bg-green-500`,children:e}):null}];function A(e){let t=``;switch(e){case`New`:t=`bg-green-100/30`;break;case`Deleted`:t=`bg-red-100/30`;break;case`Diff`:t=`bg-yellow-100/30`}return t}var j=({ledgerRecordsData:e,ledgerDiffData:t,matches:n})=>{let[r,i]=(0,C.useState)([]),o=(0,C.useMemo)(()=>{let r=e.map(e=>d(S,e)),i=t?.map(e=>d(S,e)),a=r.map(e=>{let t=i?.find(t=>t.id===e.id);return{...e,matchingStatus:!n||n?.includes(e.id)?void 0:t?`Diff`:`Deleted`,diff:t}}),o=i?.filter(e=>e.id===`00000000-0000-0000-0000-000000000000`).map(e=>({...e,matchingStatus:`New`}))??[];return a.push(...o),a},[e,t,n]),s=p({features:y,data:o,columns:k,onSortingChange:i,state:{sorting:r},initialState:{pagination:{pageIndex:0,pageSize:100},sorting:[{id:`invoiceDate`,desc:!0}]}});return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(b,{children:[(0,w.jsx)(f,{children:s.getHeaderGroups().map(e=>(0,w.jsx)(_,{children:e.headers.map(e=>(0,w.jsx)(h,{className:`text-center`,colSpan:e.colSpan,children:e.isPlaceholder?null:m(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,w.jsx)(g,{children:s.getRowModel().rows?.length?s.getRowModel().rows.map(e=>(0,w.jsx)(_,{"data-state":e.getIsSelected()&&`selected`,className:A(e.original.matchingStatus),children:e.getVisibleCells().map(e=>(0,w.jsx)(v,{children:m(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,w.jsx)(_,{children:(0,w.jsx)(v,{colSpan:k.length,className:`h-24 text-center`,children:`No results.`})})})]}),(0,w.jsx)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:(0,w.jsx)(a,{currentPageIndex:s.state.pagination.pageIndex,totalPages:s.getPageCount(),onChange:e=>s.setPageIndex(e)})})]})};export{j as t};