UNPKG

@accounter/client

Version:
1 lines • 10.5 kB
import{s as e}from"./dist-BmACi7k_.js";import{i as t,o as n}from"./utils-BxkqV8PM.js";import{In as r,Qr as i}from"./error-handling-sQ-z99nE.js";import{s as a,t as o}from"./routes-C4NpBRv7.js";import{ft as s,mt as c}from"./select-KYQbDWZT.js";import{n as l}from"./common-DtK-TFhT.js";import{t as u}from"./button-BZ6z_NAl.js";import{Kl as d,Uc as f,a as p,c as m,el as h,i as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w}from"./table-D4eAFW7G.js";var T=e(n(),1),E=t(),D=({foreignAmount:e,localAmount:t,diff:n})=>{let i=e!=null&&e.currency!==r.Ils,a=n&&n.localAmount?.formatted!==t?.formatted,o=n&&n.foreignAmount?.formatted!==e?.formatted;return(0,E.jsx)(`div`,{className:`flex flex-col`,children:(t||a)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[i&&(0,E.jsx)(`p`,{className:o?`line-through`:``,children:e.formatted}),o&&n.foreignAmount&&(0,E.jsx)(`p`,{className:`border-2 border-yellow-500 rounded-md`,children:n.foreignAmount.formatted})]}),(0,E.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[t!=null&&(0,E.jsx)(`p`,{className:a?`line-through`:``,children:t.formatted}),a&&n.localAmount&&(0,E.jsx)(`p`,{className:`border-2 border-yellow-500 rounded-md`,children:n.localAmount.formatted})]})]})})},O=({account:e,diffAccount:t})=>{let n=t&&t?.id!==e?.id;return(0,E.jsx)(`div`,{className:`flex flex-col whitespace-normal`,children:(e||n)&&(0,E.jsxs)(E.Fragment,{children:[e&&(0,E.jsx)(a,{to:o.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,E.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:(0,E.jsx)(a,{to:o.BUSINESSES.DETAIL(t.id),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`inline-flex items-center font-semibold`,children:t.name})})]})})},k=({date:e,diff:t})=>{let n=e?d(new Date(e),`dd/MM/yy`):void 0,r=t?d(new Date(t),`dd/MM/yy`):void 0,i=r&&n!==r;return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`p`,{className:i?`line-through`:``,children:n??`Missing Data`}),i&&(0,E.jsx)(`div`,{className:`flex flex-col border-2 border-yellow-500 rounded-md`,children:r})]})},A=(e,t)=>{let n=e.original[t],r=e.original.diff?.[t];return!n&&!r},j=[{accessorKey:`invoiceDate`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Invoice Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(k,{date:e.original.invoiceDate,diff:e.original.diff?.invoiceDate})},{accessorKey:`valueDate`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Value Date`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(k,{date:e.original.valueDate,diff:e.original.diff?.valueDate})},{header:`Debit Account (Main)`,columns:[{accessorKey:`debitAccount1.name`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(O,{account:e.original.debitAccount1,diffAccount:e.original.diff?.debitAccount1})},{accessorKey:`localCurrencyDebitAmount1.raw`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>A(e,`debitAccount1`)?null:(0,E.jsx)(D,{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,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(O,{account:e.original.creditAccount1,diffAccount:e.original.diff?.creditAccount1})},{accessorKey:`localCurrencyCreditAmount1.raw`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>A(e,`creditAccount1`)?null:(0,E.jsx)(D,{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,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(O,{account:e.original.debitAccount2,diffAccount:e.original.diff?.debitAccount2})},{accessorKey:`localCurrencyDebitAmount2.raw`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>A(e,`debitAccount2`)?null:(0,E.jsx)(D,{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,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Account`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>(0,E.jsx)(O,{account:e.original.creditAccount2,diffAccount:e.original.diff?.creditAccount2})},{accessorKey:`localCurrencyCreditAmount2.raw`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Amount`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:e})=>A(e,`creditAccount2`)?null:(0,E.jsx)(D,{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,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Details`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:e}})=>{let t=e.diff&&e.diff.description!==e.description;return(0,E.jsxs)(`div`,{className:`flex flex-col whitespace-normal`,children:[(0,E.jsx)(`p`,{className:t?`line-through`:``,children:e.description}),t&&(0,E.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:e.diff?.description})]})}},{accessorKey:`reference`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Reference`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:e}})=>{let t=e.diff&&e.diff.reference!==e.reference;return(0,E.jsxs)(`div`,{className:`flex flex-col whitespace-normal`,children:[(0,E.jsx)(`p`,{className:t?`line-through`:``,children:e.reference}),t&&(0,E.jsx)(`div`,{className:`border-2 border-yellow-500 rounded-md`,children:e.diff?.reference})]})}},{accessorKey:`matchingStatus`,header:({column:e})=>(0,E.jsxs)(u,{variant:`ghost`,onClick:()=>e.toggleSorting(e.getIsSorted()===`asc`),children:[`Status`,e.getIsSorted()&&(e.getIsSorted()===`asc`?(0,E.jsx)(s,{className:`ml-2 h-4 w-4`}):(0,E.jsx)(c,{className:`ml-2 h-4 w-4`}))]}),cell:({row:{original:{matchingStatus:e}}})=>e?(0,E.jsx)(f,{variant:`default`,className:e===`Deleted`?`bg-red-500`:e===`Diff`?`bg-yellow-500`:`bg-green-500`,children:e}):null}];function M(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`;break}return t}var N=({ledgerRecordsData:e,ledgerDiffData:t,matches:n})=>{let[r,a]=(0,T.useState)([]),o=m({data:(0,T.useMemo)(()=>{let r=e.map(e=>h(i,e)),a=t?.map(e=>h(i,e)),o=r.map(e=>{let t=a?.find(t=>t.id===e.id);return{...e,matchingStatus:!n||n?.includes(e.id)?void 0:t?`Diff`:`Deleted`,diff:t}}),s=a?.filter(e=>e.id===`00000000-0000-0000-0000-000000000000`).map(e=>({...e,matchingStatus:`New`}))??[];return o.push(...s),o},[e,t,n]),columns:j,getCoreRowModel:w(),onSortingChange:a,getSortedRowModel:_(),getPaginationRowModel:b(),state:{sorting:r},initialState:{pagination:{pageIndex:0,pageSize:100},sorting:[{id:`invoiceDate`,desc:!0}]}});return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(C,{children:[(0,E.jsx)(p,{children:o.getHeaderGroups().map(e=>(0,E.jsx)(y,{children:e.headers.map(e=>(0,E.jsx)(g,{className:`text-center`,colSpan:e.colSpan,children:e.isPlaceholder?null:S(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,E.jsx)(v,{children:o.getRowModel().rows?.length?o.getRowModel().rows.map(e=>(0,E.jsx)(y,{"data-state":e.getIsSelected()&&`selected`,className:M(e.original.matchingStatus),children:e.getVisibleCells().map(e=>(0,E.jsx)(x,{children:S(e.column.columnDef.cell,e.getContext())},e.id))},e.id)):(0,E.jsx)(y,{children:(0,E.jsx)(x,{colSpan:j.length,className:`h-24 text-center`,children:`No results.`})})})]}),(0,E.jsx)(`div`,{className:`flex items-center justify-end space-x-2 py-4`,children:(0,E.jsx)(l,{currentPageIndex:o.getState().pagination.pageIndex,totalPages:o.getPageCount(),onChange:e=>o.setPageIndex(e)})})]})};export{N as t};