UNPKG

@accounter/client

Version:
2 lines • 8.95 kB
import{r as e,s as t}from"./dist-C51EwTaa.js";import{i as n,o as r}from"./utils-DdVdMk8X.js";import{Co as i,Lo as a}from"./error-handling-Dpfd9svJ.js";import{n as o}from"./routes-DUvpW9-n.js";import{ft as s,gt as c}from"./select-CrsvQyhZ.js";import{t as l}from"./funnel-BFbxpUGW.js";import{t as u}from"./button-Dzp2INW0.js";import{i as d,n as f,r as p,t as m}from"./accordion-D0VCW409.js";import{K as h,Lt as g,U as _,V as v,wt as y}from"./table--bF0wbxq.js";import{Ar as b,Dt as x,Fr as S,Ft as C,P as w,Pr as T,cn as E,fn as D,zr as O}from"./index-CL8-JoMZ.js";import{t as k}from"./use-url-query-BCNbSvLg.js";import{t as A}from"./page-layout-DoLDsSrs.js";var j=e((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.calcSlices=e.applyPatch=e.calcPatch=e.lcs=e.diff=e.diff_core=void 0;function t(e,t){let{b:n,eq:r,stack_base:i}=e,{i:a,N:o,j:s,M:c,Z:l,stack_top:u}=e;for(;;)switch(t){case 0:Z_block:for(;o>0&&c>0;){n.fill(0,0,2*l);let e=o-c,t=o+c,d=t&1,f=a+o-1,p=s+c-1,m=(t+d)/2,h;h_loop:for(let t=0;t<=m;t++){let m=2*Math.max(0,t-c)-t,g=t-2*Math.max(0,t-o);for(let f=m;f<=g;f+=2){let p=n[f-1-l*Math.floor((f-1)/l)],m=n[f+1-l*Math.floor((f+1)/l)],g=f===-t||f!==t&&p<m?m:p+1,_=g-f,v=g,y=_;for(;v<o&&y<c&&r(a+v,s+y);)v++,y++;if(n[f-l*Math.floor(f/l)]=v,d===1&&(h=e-f)>=1-t&&h<t&&v+n[l+h-l*Math.floor(h/l)]>=o)if(t>1||v!==g){i[u++]=a+v,i[u++]=o-v,i[u++]=s+y,i[u++]=c-y,o=g,c=_,l=2*(Math.min(o,c)+1);continue Z_block}else break h_loop}for(let _=m;_<=g;_+=2){let m=n[l+_-1-l*Math.floor((_-1)/l)],g=n[l+_+1-l*Math.floor((_+1)/l)],v=_===-t||_!==t&&m<g?g:m+1,y=v-_,b=v,x=y;for(;b<o&&x<c&&r(f-b,p-x);)b++,x++;if(n[l+_-l*Math.floor(_/l)]=b,d===0&&(h=e-_)>=-t&&h<=t&&b+n[h-l*Math.floor(h/l)]>=o)if(t>0||b!==v){i[u++]=a+o-v,i[u++]=v,i[u++]=s+c-y,i[u++]=y,o-=b,c-=x,l=2*(Math.min(o,c)+1);continue Z_block}else break h_loop}}if(o!==c){c>o?(a+=o,s+=o,c-=o,o=0):(a+=c,s+=c,o-=c,c=0);break}}if(o+c!==0)if(e.pxe===a||e.pye===s)e.pxe=a+o,e.pye=s+c;else{let t=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=a,e.pxe=a+o,e.pys=s,e.pye=s+c,t>=0)return e.i=a,e.N=o,e.j=s,e.M=c,e.Z=l,e.stack_top=u,1}case 1:if(u===0)return 2;c=i[--u],s=i[--u],o=i[--u],a=i[--u],l=2*(Math.min(o,c)+1),t=0}}var n=class{constructor(e){this.state=e,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){let{state:e,result:n}=this;if(this.c>1)return n.done=!0,n.value=void 0,n;let r=t(e,this.c);return this.c=r,r===1?(n.value=[e.oxs,e.oxe,e.oys,e.oye],n):e.pxs>=0?(n.value=[e.pxs,e.pxe,e.pys,e.pye],n):(n.done=!0,n.value=void 0,n)}};function r(e,t,r,i,a){let o=(Math.min(t,i)+1)*2,s=t+i;return new n({i:e,N:t,j:r,M:i,Z:o,b:new(s<256?Uint8Array:s<65536?Uint16Array:Uint32Array)(2*o),eq:a,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}e.diff_core=r;function i(e,t,n){let[i,a,o]=[0,e.length,t.length];if(typeof n==`function`){for(;i<a&&i<o&&n(i,i);)i++;if(i===a&&i===o)return[][Symbol.iterator]();for(;n(--a,--o)&&a>i&&o>i;);}else{for(;i<a&&i<o&&e[i]===t[i];)i++;if(i===a&&i===o)return[][Symbol.iterator]();for(;e[--a]===t[--o]&&a>i&&o>i;);n=(n,r)=>e[n]===t[r]}return r(i,a+1-i,i,o+1-i,n)}e.diff=i;var a=class{constructor(e,t){this.diff=e,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){let e=this.diff.next();if(e.done){let{i:t,j:n,N:r}=this;return t<r&&(e.done=!1,e.value=[t,n,r-t],this.i=r),e}let t=e.value,n=t[0],r=t[1],i=t[3],{i:a,j:o}=this;return a!==n&&(t.length--,t[0]=a,t[1]=o,t[2]=n-a),this.i=r,this.j=i,e}};function o(e,t,n){return new a(i(e,t,n),e.length)}e.lcs=o;function*s(e,t,n){let r=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let a of i(e,t,n))a[2]=r.call(t,a[2],a[3]),yield a}e.calcPatch=s;function*c(e,t){let n=0,r=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let[i,a,o]of t)n<i&&(yield r.call(e,n,i)),o.length>0&&(yield o),n=a;n<e.length&&(yield r.call(e,n))}e.applyPatch=c;function*l(e,t,n){let r=0,a=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(let[o,s,c,l]of i(e,t,n))r<o&&(yield[0,a.call(e,r,o)]),o<s&&(yield[-1,a.call(e,o,s)]),c<l&&(yield[1,a.call(t,c,l)]),r=s;r<e.length&&(yield[0,e.slice(r)])}e.calcSlices=l})),M=t(r(),1),N=j(),P=n(),F=({children:e})=>(0,P.jsx)(`span`,{className:`bg-green-100`,children:e}),I=({children:e})=>(0,P.jsx)(`span`,{className:`bg-red-100 line-through`,children:e}),L=({children:e})=>(0,P.jsx)(`span`,{children:e}),R=({content:e,contentOrigin:t,monthDate:n})=>{let r=(0,M.useMemo)(()=>{let n=[];if(!t)return n;let r=e.split(``),i=t.split(``),a=Array.from((0,N.calcPatch)(i,r)),o=[],s=0;for(let[e,t,r]of a)if(o.length===0&&e>=17&&t<=25&&r.length===t-e){if(a.length===1)return n;continue}else s<e&&o.push([i.slice(s,e).join(``),L]),t>e&&o.push([i.slice(e,t).join(``),I]),r.length>0&&o.push([r.join(``),F]),s=t;s<i.length&&o.push([i.slice(s).join(``),L]);let c=[];for(let[e,t]of o){let r=e.split(` `);r.length===1?c.push((0,P.jsx)(t,{children:e},`unchanged-${c.length}`)):r.map((e,r)=>{c.push((0,P.jsx)(t,{children:e},r)),n.push((0,P.jsx)(`div`,{children:c},n.length-1)),c=[]})}return c.length>0&&n.push((0,P.jsx)(`div`,{children:c},n.length-1)),n},[e,t]);return(0,P.jsxs)(`div`,{className:`flex flex-col`,children:[(0,P.jsxs)(`div`,{className:`text-sm text-gray-500 flex flex-row gap-2`,children:[(0,P.jsx)(`span`,{className:`font-bold`,children:`Month:`}),(0,P.jsx)(`span`,{children:n.slice(0,7)}),!r.length&&(0,P.jsx)(c,{className:`text-green-500`})]}),!!r.length&&r]})},z=({filter:e})=>{let[{data:t,fetching:n,hasNext:r}]=a({query:i,variables:e}),o=(0,M.useMemo)(()=>[...t?.pcnByDate??[]].sort((e,t)=>t.date>e.date?1:t.date<e.date?-1:0),[t?.pcnByDate]);return n?(0,P.jsx)(`div`,{className:`w-full h-full flex justify-center`,children:(0,P.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`})}):(0,P.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[!!t&&r&&(0,P.jsx)(`div`,{className:`w-full h-full flex justify-center`,children:(0,P.jsx)(s,{className:`h-10 w-10 animate-spin mr-2 self-center`})}),o.map((e,t)=>(0,P.jsx)(R,{content:e.content,contentOrigin:e.diffContent,monthDate:e.date},t))]})},B=t(y(),1);function V({filter:e,setFilter:t,closeModal:n}){let{control:r,handleSubmit:i,setValue:a}=_({defaultValues:{...e}}),{selectableBusinesses:o,fetching:s}=x();return(0,P.jsxs)(P.Fragment,{children:[s?(0,P.jsx)(`div`,{children:`Loading...`}):(0,P.jsx)(`div`,{}),(0,P.jsxs)(`form`,{onSubmit:i(e=>{t(e),n()}),children:[(0,P.jsx)(v,{name:`businessId`,control:r,defaultValue:void 0,render:({field:e,fieldState:t})=>(0,P.jsx)(D,{...e,data:o,value:e.value,disabled:s,label:`Businesses`,placeholder:`Scroll to see all options`,maxDropdownHeight:160,searchable:!0,error:t.error?.message})}),(0,P.jsx)(C,{label:`From date`,defaultValue:e?.fromMonthDate?new Date(e.fromMonthDate):new Date,defaultDate:e?.fromMonthDate?new Date(e.fromMonthDate):new Date,onChange:e=>{a(`fromMonthDate`,g(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}}),(0,P.jsx)(C,{label:`To date`,defaultValue:e?.toMonthDate?new Date(e.toMonthDate):new Date,defaultDate:e?.toMonthDate?new Date(e.toMonthDate):new Date,onChange:e=>{a(`toMonthDate`,g(new Date(e.getFullYear(),e.getMonth(),15),`yyyy-MM-dd`))},popoverProps:{withinPortal:!0}}),(0,P.jsxs)(`div`,{className:`flex justify-center mt-5 gap-3`,children:[(0,P.jsx)(u,{type:`submit`,children:`Filter`}),(0,P.jsx)(u,{type:`button`,onClick:n,children:`Cancel`})]})]})]})}function H({filter:e,setFilter:t}){let[n,r]=(0,M.useState)(!1),{get:i,set:a}=k(),{userContext:s}=(0,M.useContext)(h);function c(n){n||={businessId:s?.context.adminBusinessId??e.businessId,fromMonthDate:g(b(new Date,1),`yyyy-MM-15`),toMonthDate:g(new Date,`yyyy-MM-15`)},(0,B.default)(n,e)||t(n)}return(0,M.useEffect)(()=>{let t=o(e??{});t!==i(`validateReportsFilters`)&&a(`validateReportsFilters`,t)},[e,i,a]),(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(w,{opened:n,onClose:()=>r(!1),content:(0,P.jsx)(V,{filter:e,setFilter:c,closeModal:()=>r(!1)})}),(0,P.jsx)(u,{variant:`outline`,size:`icon`,className:`size-7.5`,onClick:()=>r(!0),children:(0,P.jsx)(l,{className:`size-5`})})]})}var U=()=>{let{get:e}=k(),{setFiltersContext:t}=(0,M.useContext)(E),[n,r]=(0,M.useState)((0,M.useMemo)(()=>{try{if(e(`validateReportsFilters`))return JSON.parse(decodeURIComponent(e(`validateReportsFilters`)))}catch(e){console.error(`Error parsing filter from URL`,e)}return{fromMonthDate:g(b(new Date,1),`yyyy-MM-15`),toMonthDate:g(new Date,`yyyy-MM-15`)}},[e]));return(0,M.useEffect)(()=>{t((0,P.jsx)(`div`,{className:`flex flex-row gap-2`,children:(0,P.jsx)(H,{filter:{...n},setFilter:r})}))},[n,t]),(0,P.jsx)(A,{title:`Report Validations`,children:(0,P.jsx)(m,{type:`single`,collapsible:!0,children:(0,P.jsx)(p,{value:`pcn874`,children:(0,P.jsxs)(T,{className:`p-4`,children:[(0,P.jsx)(d,{children:(0,P.jsx)(O,{children:`Monthly VAT (PCN874)`})}),(0,P.jsx)(f,{children:(0,P.jsx)(S,{children:(0,P.jsx)(z,{filter:n})})})]})})})})};export{U as ValidateReportsScreen};