UNPKG

@accounter/client

Version:
1 lines 29.6 kB
import{s as e}from"./dist-BbgEzppd.js";import{i as t,o as n}from"./utils-BUNz070n.js";import{Br as r,H as i,Hr as a,Ja as o,Sr as s,Ya as c,Yt as l,_r as u,a as d,br as f,gr as p,r as m,s as h,t as g,xr as _,y as v,yr as y}from"./error-handling-AQOG1RNy.js";import{t as b,x,y as S}from"./routes-BXbESQBe.js";import{a as C,dt as w,gt as T,i as E,mt as D,n as O,pt as k,r as ee,t as te}from"./select-6mBYg_R6.js";import{a as ne}from"./charges-table-CIcrjmB2.js";import{Gn as re,Jr as A,Kn as ie,Kr as j,Nr as M,Qr as N,er as ae,rt as oe}from"./common-Cy-x5Vhe.js";import{t as se}from"./circle-check-BVW9CkQn.js";import{t as P}from"./button-CBTN3XMQ.js";import{a as ce,n as F,o as le,r as ue,t as I}from"./card-I9-5Y7H7.js";import{E as de,G as fe,O as pe,S as L,Y as me,at as he,h as R,q as z,v as B}from"./table-tK8pMUMS.js";import{C as ge,E as V,I as H,L as U,R as W,S as _e,T as G,w as ve}from"./index-B8E5XsZe.js";import{t as ye}from"./page-layout-BO3YzLcj.js";import{n as be}from"./charges-ledger-validation-PX4pxLb0.js";var xe=T(`circle-plus`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),Se=T(`lock`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`,key:`fwvmzm`}]]),Ce=T(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),we=T(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),Te=T(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),Ee=Object.defineProperty,De=Object.defineProperties,Oe=Object.getOwnPropertyDescriptors,K=Object.getOwnPropertySymbols,ke=Object.prototype.hasOwnProperty,Ae=Object.prototype.propertyIsEnumerable,je=(e,t,n)=>t in e?Ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,q=(e,t)=>{for(var n in t||={})ke.call(t,n)&&je(e,n,t[n]);if(K)for(var n of K(t))Ae.call(t,n)&&je(e,n,t[n]);return e},Me=(e,t)=>De(e,Oe(t)),Ne=[`filled`,`light`,`subtle`];function Pe({theme:e,variant:t,color:n}){if(!Ne.includes(t))return null;let r=e.fn.variant({variant:t,color:n});return{"&[data-active]":q({backgroundColor:r.background,color:r.color},e.fn.hover({backgroundColor:r.hover}))}}var Fe=de((e,{noWrap:t,childrenOffset:n,alignIcon:r,color:i},{variant:a})=>({root:Me(q(q({display:`flex`,alignItems:`center`,width:`100%`,padding:`${z(8)} ${e.spacing.sm}`,userSelect:`none`},Pe({theme:e,variant:a,color:i})),e.fn.hover({backgroundColor:e.colorScheme===`dark`?e.colors.dark[6]:e.colors.gray[0]})),{"&[data-disabled]":{opacity:.4,pointerEvents:`none`}}),icon:{marginRight:e.spacing.sm,display:`flex`,justifyContent:`center`,alignItems:`center`,alignSelf:r===`center`?`center`:`flex-start`,paddingTop:r===`center`?void 0:z(4)},rightSection:{marginLeft:e.spacing.sm,display:`flex`,justifyContent:`center`,alignItems:`center`,transition:`transform 150ms ${e.transitionTimingFunction}`,"&[data-rotate]":{transform:`rotate(90deg)`}},body:{flex:1,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:t?`nowrap`:void 0},label:{},description:{display:`block`,"&[data-active]":{color:`inherit`}},children:{paddingLeft:fe({size:n,sizes:e.spacing})}})),J=e(n()),Ie=Object.defineProperty,Y=Object.getOwnPropertySymbols,Le=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,ze=(e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Be=(e,t)=>{for(var n in t||={})Le.call(t,n)&&ze(e,n,t[n]);if(Y)for(var n of Y(t))Re.call(t,n)&&ze(e,n,t[n]);return e},Ve=(e,t)=>{var n={};for(var r in e)Le.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Y)for(var r of Y(e))t.indexOf(r)<0&&Re.call(e,r)&&(n[r]=e[r]);return n},He={variant:`light`,childrenOffset:`lg`},Ue=(0,J.forwardRef)((e,t)=>{let n=pe(`NavLink`,He,e),{label:r,description:i,icon:a,rightSection:o,className:s,classNames:c,styles:l,unstyled:u,active:d,color:f,variant:p,noWrap:m,children:h,opened:g,defaultOpened:_,onChange:v,disableRightSectionRotation:y,childrenOffset:b,disabled:x,onClick:S}=n,C=Ve(n,[`label`,`description`,`icon`,`rightSection`,`className`,`classNames`,`styles`,`unstyled`,`active`,`color`,`variant`,`noWrap`,`children`,`opened`,`defaultOpened`,`onChange`,`disableRightSectionRotation`,`childrenOffset`,`disabled`,`onClick`]),{classes:w,cx:T}=Fe({color:f,noWrap:m,childrenOffset:b,alignIcon:i?`top`:`center`},{name:`NavLink`,classNames:c,styles:l,unstyled:u,variant:p}),[E,D]=ae({value:g,defaultValue:_,finalValue:!1,onChange:v}),O=!!h,k=e=>{O?(e.preventDefault(),S?.(e),D(!E)):S?.(e)};return J.createElement(J.Fragment,null,J.createElement(ie,Be({ref:t,className:T(w.root,s),"data-active":d||void 0,onClick:k,unstyled:u,"data-expanded":E||void 0,"data-disabled":x||void 0,disabled:x},C),a&&J.createElement(`span`,{className:w.icon},a),J.createElement(`span`,{className:w.body},J.createElement(L,{component:`span`,size:`sm`,className:w.label},r),J.createElement(L,{component:`span`,color:`dimmed`,size:`xs`,"data-active":d||void 0,className:w.description},i)),(O||o)&&J.createElement(`span`,{className:w.rightSection,"data-rotate":E&&!y||void 0},O?o||J.createElement(re,{width:z(14),height:z(14),style:{transform:`rotate(-90deg)`}}):o)),J.createElement(ne,{in:E},J.createElement(`div`,{className:w.children},h)))});Ue.displayName=`@mantine/core/NavLink`;var We=me(Ue),X=t(),Ge=e=>{switch(e){case`completed`:return(0,X.jsx)(se,{className:`h-5 w-5 text-green-600`});case`in-progress`:return(0,X.jsx)(N,{className:`h-5 w-5 text-blue-600`});case`pending`:return(0,X.jsx)(N,{className:`h-5 w-5 text-gray-400`});case`blocked`:return(0,X.jsx)(U,{className:`h-5 w-5 text-red-600`});case`loading`:return(0,X.jsx)(w,{className:`h-5 w-5 text-gray-400 animate-spin`})}},Ke=e=>(0,X.jsx)(R,{variant:{completed:`default`,"in-progress":`secondary`,pending:`outline`,blocked:`destructive`,loading:`outline`}[e],children:{completed:`Completed`,"in-progress":`In Progress`,pending:`Pending`,blocked:`Blocked`,loading:`Loading...`}[e]});function Z({id:e,ref:t,title:n,description:r,icon:i,status:a,actions:o,children:s,hasSubsteps:c=!1,isExpanded:l=!1,onToggleExpanded:u,level:d=0,disabled:f=!1}){return(0,X.jsxs)(`div`,{ref:t,className:`${d>0?`ml-6 border-l-2 border-gray-200 pl-4`:``} relative`,children:[(0,X.jsxs)(I,{className:`mb-4`,children:[(0,X.jsx)(ce,{className:`pb-3`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[c?(0,X.jsx)(P,{disabled:f,variant:`ghost`,size:`sm`,onClick:u,className:`p-0 h-auto`,children:l?(0,X.jsx)(D,{className:`h-4 w-4`}):(0,X.jsx)(k,{className:`h-4 w-4`})}):(0,X.jsx)(`div`,{className:`w-4`}),Ge(a),i,(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(le,{className:`text-lg`,children:[e,`. `,n]}),r&&(0,X.jsx)(ue,{className:`mt-1`,children:r})]})]}),Ke(a)]})}),o&&o.length>0&&(0,X.jsx)(F,{className:`pt-0`,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:o.map((e,t)=>(0,X.jsx)(P,{variant:`outline`,size:`sm`,disabled:e.disabled||f,onClick:e.onClick,asChild:!!e.href&&!f,children:e.href?(0,X.jsx)(`a`,{href:e.href,children:e.label}):e.label},t))})}),s]}),f&&(0,X.jsx)(I,{className:`absolute inset-0 bg-gray-500 opacity-50 pointer-events-auto z-10 ${d>0?`ml-4`:``}`})]})}function qe(e){let[t,n]=(0,J.useState)(`loading`),[r,i]=(0,J.useState)({approvedPercentage:0,pendingPercentage:0,unapprovedPercentage:100,totalCharges:1,approvedCount:0,pendingCount:0,unapprovedCount:1}),[a,o]=(0,J.useState)(!1),[s,u]=(0,J.useState)(!1),{adminBusinessId:f,id:p,onStatusChange:m,year:g}=e;(0,J.useEffect)(()=>{m&&m(p,t),t===`completed`&&!s?u(!0):t!==`completed`&&s&&u(!1)},[t,m,p,s]);let[{data:_,fetching:v},y]=c({query:d,variables:{fromDate:`${g}-01-01`,toDate:`${g}-12-31`}});(0,J.useEffect)(()=>{f?v&&n(`loading`):n(`blocked`)},[f,v]),(0,J.useEffect)(()=>{if(_?.accountantApprovalStatus){let{totalCharges:e,approvedCount:t,pendingCount:r,unapprovedCount:a}=_.accountantApprovalStatus,o={approvedPercentage:t/e*100||0,pendingPercentage:r/e*100||0,unapprovedPercentage:a/e*100||0,totalCharges:e,approvedCount:t,pendingCount:r,unapprovedCount:a};i(o),o.pendingPercentage===0&&o.unapprovedPercentage===0?n(`completed`):o.pendingPercentage+o.unapprovedPercentage<30?n(`in-progress`):n(`pending`)}},[_]);let x=[{label:`Review Charges`,href:(0,J.useMemo)(()=>b.CHARGES.ALL({byOwners:f?[f]:void 0,fromAnyDate:`${g}-01-01`,toAnyDate:`${g}-12-31`,accountantStatus:[h.Pending,h.Unapproved],sortBy:{field:l.Date,asc:!1}}),[f,g])}],S=async()=>{await y()};return(0,X.jsx)(Z,{...e,status:t,icon:(0,X.jsx)(A,{className:`h-4 w-4`}),actions:x,children:(0,X.jsxs)(G,{open:a,children:[(0,X.jsx)(F,{className:`pt-0 border-t`,children:(0,X.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>o(!a),className:`w-full justify-between p-2 h-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`Charge Validation Details`}),(0,X.jsxs)(R,{variant:`outline`,className:`text-xs`,children:[r.pendingCount+r.unapprovedCount,` need attention`]})]}),a?(0,X.jsx)(D,{className:`h-4 w-4`}):(0,X.jsx)(k,{className:`h-4 w-4`})]})}),(0,X.jsx)(V,{children:(0,X.jsx)(F,{className:`pt-0`,children:(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:`Charge Review Progress`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[r.totalCharges.toLocaleString(),` total charges`]}),(0,X.jsx)(P,{variant:`ghost`,size:`sm`,onClick:S,disabled:t===`loading`,children:`Refresh`})]})]}),(0,X.jsxs)(`div`,{className:`relative h-6 bg-gray-200 rounded-full overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`absolute left-0 top-0 h-full bg-green-500 transition-all duration-300`,style:{width:`${r.approvedPercentage}%`}}),(0,X.jsx)(`div`,{className:`absolute top-0 h-full bg-orange-500 transition-all duration-300`,style:{left:`${r.approvedPercentage}%`,width:`${r.pendingPercentage}%`}}),(0,X.jsx)(`div`,{className:`absolute top-0 h-full bg-red-500 transition-all duration-300`,style:{left:`${r.approvedPercentage+r.pendingPercentage}%`,width:`${r.unapprovedPercentage}%`}})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-sm`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`w-3 h-3 bg-green-500 rounded-full`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`font-medium text-green-700`,children:[`Approved (`,r.approvedPercentage.toFixed(2),`%)`]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[r.approvedCount.toLocaleString(),` charges`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`w-3 h-3 bg-orange-500 rounded-full`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`font-medium text-orange-700`,children:[`Pending (`,r.pendingPercentage.toFixed(2),`%)`]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[r.pendingCount.toLocaleString(),` charges`]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`w-3 h-3 bg-red-500 rounded-full`}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`font-medium text-red-700`,children:[`Unapproved (`,r.unapprovedPercentage.toFixed(2),`%)`]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[r.unapprovedCount.toLocaleString(),` charges`]})]})]})]})]}),(r.pendingPercentage>0||r.unapprovedPercentage>0)&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-3 bg-orange-50 rounded-lg border border-orange-200`,children:[(0,X.jsx)(U,{className:`h-4 w-4 text-orange-600`}),(0,X.jsxs)(`span`,{className:`text-sm text-orange-800`,children:[r.pendingCount+r.unapprovedCount,` charges need review before proceeding`]})]})]})})})]})})}function Je(e){let[t,n]=(0,J.useState)(`blocked`),[r,i]=(0,J.useState)(1/0),{year:o,adminBusinessId:s,onStatusChange:u,id:d}=e,[{data:f,fetching:p},m]=c({query:a,variables:{filters:{byOwners:s?[s]:[],fromAnyDate:`${o}-01-01`,toAnyDate:`${o}-12-31`}},pause:!0});(0,J.useEffect)(()=>{!f&&!p&&s&&m()}),(0,J.useEffect)(()=>{p&&n(`loading`)},[p]),(0,J.useEffect)(()=>{u&&u(d,t)},[t,u,d]),(0,J.useEffect)(()=>{if(f?.chargesWithLedgerChanges){let e=f.chargesWithLedgerChanges.filter(e=>!!e.charge?.id).length;i(e),n(e===0?`completed`:`in-progress`)}},[f]);let h=[{label:`View Ledger Status`,href:(0,J.useMemo)(()=>be({byOwners:s?[s]:void 0,fromAnyDate:`${o}-01-01`,toAnyDate:`${o}-12-31`,sortBy:{field:l.Date,asc:!1}}),[s,o])}];return(0,X.jsx)(Z,{...e,status:t,icon:(0,X.jsx)(M,{className:`h-4 w-4`}),actions:h,children:r>0&&(0,X.jsx)(F,{className:`pt-3 border-t`,children:p?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-3 bg-gray-50 rounded-lg border border-gray-200 animate-pulse`,children:[(0,X.jsx)(M,{className:`h-4 w-4 text-gray-400`}),(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsx)(`span`,{className:`text-sm text-gray-600 font-medium`,children:`Checking for pending ledger changes...`})})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-3 bg-red-50 rounded-lg border border-red-200`,children:[(0,X.jsx)(Ce,{className:`h-4 w-4 text-red-600`}),(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsxs)(`span`,{className:`text-sm text-red-800 font-medium`,children:[r,` pending ledger changes detected`]})}),(0,X.jsx)(R,{variant:`destructive`,className:`text-xs`,children:`Action Required`})]})})})}function Ye({level:e,year:t,adminBusinessId:n,disabled:r}){let i=b.REPORTS.CONTO({fromDate:`${t-1}-01-01`,toDate:`${t-1}-12-31`,ownerIds:[n]}),[a,o]=(0,J.useState)(!1);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Z,{id:`3a`,title:`Migrating Users`,description:`Create balance charge and dynamic report`,status:`pending`,level:e,actions:[{label:`Create Balance Charge`,onClick:()=>o(!0)},{label:`Generate Dynamic Report`,href:i}],disabled:r}),(0,X.jsx)(ge,{open:a,onOpenChange:o,onClose:()=>o(!1)})]})}function Xe({level:e,year:t,adminBusinessId:n,disabled:r}){return(0,X.jsx)(Z,{id:`3b`,title:`Continuing Users`,description:`Compare with previous year final trial balance`,status:`pending`,level:e,actions:[{label:`View Previous Year Ending Balance`,href:b.REPORTS.TRIAL_BALANCE({toDate:`${t-1}-12-31`,ownerIds:[n]})}],disabled:r})}function Ze(e){let[t,n]=(0,J.useState)(`loading`),[r,i]=(0,J.useState)(null),[a,o]=(0,J.useState)(!1),{adminBusinessId:s,id:c,onStatusChange:l}=e;return(0,J.useEffect)(()=>{s||n(`blocked`)},[s]),(0,J.useEffect)(()=>{l&&l(c,t)},[t,l,c]),(0,J.useEffect)(()=>{(async()=>{try{await new Promise(e=>setTimeout(e,600));let e={type:`continuing`,balanceStatus:`pending`};i(e),e.type===`new`||e.balanceStatus===`verified`?n(`completed`):n(`pending`)}catch(e){console.error(`Error fetching user type:`,e),n(`blocked`)}})()},[]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Z,{...e,status:t,icon:(0,X.jsx)(W,{className:`h-4 w-4`}),hasSubsteps:!0,isExpanded:a,onToggleExpanded:()=>o(!a)}),e.adminBusinessId&&(0,X.jsx)(G,{open:a,children:(0,X.jsxs)(V,{className:`space-y-2`,children:[(0,X.jsx)(Ye,{level:1,year:e.year,adminBusinessId:e.adminBusinessId,disabled:r?.type!==`migrating`}),(0,X.jsx)(Xe,{level:1,year:e.year,adminBusinessId:e.adminBusinessId,disabled:r?.type!==`continuing`})]})})]})}var Qe=({chargeId:e,label:t})=>(0,X.jsx)(We,{label:t,onClick:t=>{t.stopPropagation(),window.open(b.CHARGES.DETAIL(e),`_blank`,`noreferrer`)}},e),Q=function(e){return e.Revaluation=`Revaluation`,e.BankDeposits=`BankDeposits`,e.TaxExpenses=`TaxExpenses`,e.Depreciation=`Depreciation`,e.RecoveryReserve=`RecoveryReserve`,e.VacationReserve=`VacationReserve`,e}({}),$e=`generateFinancialCharge`,et=()=>{let[{fetching:e},t]=o(f),[{fetching:n},r]=o(p),[{fetching:i},a]=o(_),[{fetching:c},l]=o(u),[{fetching:d},h]=o(y),[{fetching:v},b]=o(s);return{fetching:e||n||i||c||d||v,generateFinancialCharge:(0,J.useCallback)(async e=>{let{type:n,...i}=e,o=`Error generating financial charge [${n}]`,s=`${$e}-${n}`;m.loading(`Generating financial charge`,{id:s});let c;try{switch(n){case Q.Revaluation:c=await t(i).then(e=>g(e,o,s)?.generateRevaluationCharge);break;case Q.BankDeposits:c=await r(i).then(e=>g(e,o,s)?.generateBankDepositsRevaluationCharge);break;case Q.TaxExpenses:c=await a(i).then(e=>g(e,o,s)?.generateTaxExpensesCharge);break;case Q.Depreciation:c=await l(i).then(e=>g(e,o,s)?.generateDepreciationCharge);break;case Q.RecoveryReserve:c=await h(i).then(e=>g(e,o,s)?.generateRecoveryReserveCharge);break;case Q.VacationReserve:c=await b(i).then(e=>g(e,o,s)?.generateVacationReserveCharge);break;default:throw Error(`Unknown financial charge type: ${n}`)}if(c?.id)return m.success(`Success`,{id:s,description:Qe({chargeId:c.id,label:`New ${n} charge created`})}),!0}catch(e){return console.error(`${o}: ${e}`),m.error(`Error`,{id:s,description:o,duration:1e5,closeButton:!0}),!1}return!1},[r,l,h,t,a,b])}},tt=[{key:`revaluationCharge`,label:`Revaluation Charge`,generateType:Q.Revaluation,required:!0},{key:`taxExpensesCharge`,label:`Tax Expenses Charge`,generateType:Q.TaxExpenses,required:!0},{key:`bankDepositsRevaluationCharge`,label:`Bank Deposits Revaluation Charge`,generateType:Q.BankDeposits,required:!1},{key:`depreciationCharge`,label:`Depreciation Charge`,generateType:Q.Depreciation,required:!1},{key:`recoveryReserveCharge`,label:`Recovery Reserve Charge`,generateType:Q.RecoveryReserve,required:!1},{key:`vacationReserveCharge`,label:`Vacation Reserve Charge`,generateType:Q.VacationReserve,required:!1}];function nt(e){let[t,n]=(0,J.useState)(`loading`),[r,a]=(0,J.useState)(!1),{adminBusinessId:o,id:s,onStatusChange:l,year:u}=e,d=`${u}-12-31`,{fetching:f,generateFinancialCharge:p}=et(),[{data:m,fetching:h,error:g},_]=c({query:i,variables:{ownerId:o,year:d}});(0,J.useEffect)(()=>l?.(s,t),[t,l,s]);let v=(0,J.useMemo)(()=>{let e=m?.annualFinancialCharges;return tt.map(t=>{let n=e?.[t.key]?.id;return{...t,chargeId:n,exists:!!n}})},[m]);(0,J.useEffect)(()=>{if(!o){n(`blocked`);return}if(h||f){n(`loading`);return}if(g||!m?.annualFinancialCharges){n(`blocked`);return}let e=v.filter(e=>e.required),t=e.filter(e=>e.exists).length;t===e.length?n(`completed`):n(t>0?`in-progress`:`pending`)},[o,v,m,g,h,f]);let y=(0,J.useCallback)(async e=>{o&&await p({type:e,ownerId:o,date:d})&&await _()},[o,p,_,d]),x=e=>e.exists?(0,X.jsx)(se,{className:`h-4 w-4 text-green-600`}):e.required?(0,X.jsx)(U,{className:`h-4 w-4 text-orange-600`}):(0,X.jsx)(U,{className:`h-4 w-4 text-gray-400`}),S=e=>e.exists?(0,X.jsx)(R,{variant:`default`,children:`Exists`}):e.required?(0,X.jsx)(R,{variant:`outline`,children:`Missing`}):(0,X.jsx)(R,{variant:`secondary`,children:`Optional`});return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Z,{...e,status:t,hasSubsteps:!0,isExpanded:r,onToggleExpanded:()=>a(e=>!e)}),o&&(0,X.jsx)(G,{open:r,children:(0,X.jsx)(V,{children:(0,X.jsx)(F,{className:`pt-0 border-t`,children:(0,X.jsx)(`div`,{className:`space-y-2 mt-3`,children:v.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 p-3 rounded-lg border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x(e),(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:e.label}),S(e)]}),e.exists&&e.chargeId?(0,X.jsx)(P,{variant:`outline`,size:`sm`,asChild:!0,children:(0,X.jsx)(`a`,{href:b.CHARGES.DETAIL(e.chargeId),children:`View`})}):(0,X.jsxs)(P,{variant:`outline`,size:`sm`,onClick:()=>y(e.generateType),disabled:f||t===`loading`,children:[(0,X.jsx)(xe,{className:`h-4 w-4 mr-1`}),`Generate`]})]},e.key))})})})})]})}var rt=`ledgerLock`,it=()=>{let[{fetching:e},t]=o(r);return{fetching:e,ledgerLock:(0,J.useCallback)(async e=>{let n=`Error locking ledger`,r=`${rt}-${e.date}`;m.loading(`Locking ledger`,{id:r});try{let i=g(await t(e),n,r,`lockLedgerRecords`);if(i?.lockLedgerRecords)return m.success(`Success`,{id:r,description:`Payroll file added`}),i.lockLedgerRecords;throw Error(`Server error`)}catch(e){console.error(`${n}: ${e}`),m.error(`Error`,{id:r,description:n,duration:1e5,closeButton:!0})}return!1},[t])}};function at(e){let[t,n]=(0,J.useState)(`pending`),[r,i]=(0,J.useState)(!1),{fetching:a,ledgerLock:o}=it(),{adminBusinessId:s,id:l,onStatusChange:u,year:d}=e,f=`${d}-12-31`,[{data:p,fetching:m},h]=c({query:v,variables:{ownerId:s}});(0,J.useEffect)(()=>u?.(l,t),[t,u,l]),(0,J.useEffect)(()=>{m||a?n(`loading`):p?!p.adminContext?.ledgerLock||p.adminContext.ledgerLock<f?n(`pending`):n(`completed`):n(`blocked`)},[p,m,f,a]);let g=(0,J.useCallback)(async()=>{o({date:f}).then(()=>h())},[f,o,h]),{userContext:_}=(0,J.useContext)(B),y=_?.context.ledgerLock;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Z,{...e,status:t,actions:[{label:`Lock Ledger`,onClick:()=>i(!0),disabled:!!y&&y>=f}]}),(0,X.jsx)(oe,{onConfirm:g,title:`Are you sure you want to lock all ledger records until ${he(new Date(f),`MMMM do, yyy`)}?`,open:r,setOpen:i})]})}function $({defaultStatus:e=`pending`,actions:t=[],fetchStatus:n,onStatusChange:r,...i}){let[a,o]=(0,J.useState)(n?`loading`:e);return(0,J.useEffect)(()=>{o(e)},[e]),(0,J.useEffect)(()=>{r&&r(i.id,a)},[a,r,i.id]),(0,J.useEffect)(()=>{n&&n().then(o).catch(()=>o(`blocked`))},[n]),(0,X.jsx)(Z,{...i,status:a,actions:t,onStatusChange:r})}var ot=2e3,st=new Date().getFullYear();function ct(e,t,n){return Math.min(Math.max(e,t),n)}function lt({value:e,onChange:t,minYear:n=ot,maxYear:r=st}){let i=typeof e==`number`?ct(e,n,r):void 0,a=Array.from({length:r-n+1},(e,t)=>String(r-t));return(0,X.jsxs)(te,{value:i?String(i):void 0,onValueChange:e=>t(Number(e)),children:[(0,X.jsx)(E,{className:`w-full`,children:(0,X.jsx)(C,{placeholder:`Select year (${n}-${r})`})}),(0,X.jsx)(O,{children:a.map(e=>(0,X.jsx)(ee,{value:e,children:e},e))})]})}var ut=()=>{let{setFiltersContext:e}=(0,J.useContext)(ve),{userContext:t}=(0,J.useContext)(B),n=t?.context.adminBusinessId,{year:r}=x(),i=S(),a=new Date().getFullYear(),o=a-1,s=r?Number(r):o,c=!Number.isNaN(s)&&s>=2e3&&s<=a,l=c?s:o;(0,J.useEffect)(()=>{c||i(b.WORKFLOWS.ANNUAL_AUDIT(o),{replace:!0})},[c,i,o]);let u=(0,J.useCallback)(e=>{e!==l&&i(b.WORKFLOWS.ANNUAL_AUDIT(e))},[l,i]);(0,J.useEffect)(()=>{e((0,X.jsx)(`div`,{className:`flex flex-row gap-x-5`,children:(0,X.jsx)(lt,{value:l,onChange:u})}))},[l,e,u]);let d=(0,J.useRef)(new Map),[f,p]=(0,J.useState)(0),[m,h]=(0,J.useState)(`pending`),g=(0,J.useCallback)(()=>{let e=d.current.get(`1`),t=d.current.get(`2`),n=e===`completed`&&t===`completed`?`completed`:`pending`;d.current.get(`7`)!==n&&(d.current.set(`7`,n),h(n))},[]),_=(0,J.useCallback)((e,t)=>{if(d.current.get(e)!==t){d.current.set(e,t);let n=Array.from(d.current.values()).filter(e=>e===`completed`).length;p(n)}(e===`1`||e===`2`)&&g()},[g]),v=f/21*100,y=(0,J.useRef)(null),C=(0,J.useRef)(null);return(0,J.useEffect)(()=>{g()},[g]),c?(0,X.jsx)(ye,{title:`Annual Audit Flow - ${l}`,description:`Complete audit process for annual financial reporting and compliance`,children:(0,X.jsxs)(`div`,{className:`container mx-auto p-6 max-w-6xl`,children:[(0,X.jsx)(`div`,{className:`mb-8`,children:(0,X.jsxs)(I,{className:`mb-6`,children:[(0,X.jsx)(ce,{children:(0,X.jsx)(le,{className:`text-lg`,children:`Progress Overview`})}),(0,X.jsx)(F,{children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,X.jsx)(`span`,{children:`Completed Steps`}),(0,X.jsxs)(`span`,{children:[f,` of `,21]})]}),(0,X.jsx)(_e,{value:v,className:`h-2`}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[v.toFixed(1),`% Complete`]})]})})]})}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsx)(qe,{id:`1`,ref:y,year:l,adminBusinessId:n,title:`Validate All Charges`,description:`Ensure all charges of the year were reviewed, handle pending charges`,onStatusChange:_}),(0,X.jsx)(Je,{id:`2`,ref:C,year:l,adminBusinessId:n,title:`Check Pending Ledger Changes`,description:`Ensure no pending ledger changes exist`,onStatusChange:_}),(0,X.jsx)(Ze,{id:`3`,year:l,adminBusinessId:n,title:`Verify Opening Balance`,description:`Handle opening balance verification based on user type`,onStatusChange:_}),(0,X.jsx)(nt,{id:`4`,title:`Generate Financial Charges`,description:`Create various financial charges and reserves`,icon:(0,X.jsx)(W,{className:`h-4 w-4`}),onStatusChange:_,year:l,adminBusinessId:n}),(0,X.jsx)($,{id:`5`,title:`Audit Main Process`,description:`Task management system for comprehensive audit checks`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Manage Conto Tree`,href:`/conto/tree`},{label:`Open Checklist`,href:`/validations/checklist`},{label:`Compare VAT`,href:`/vat/comparison`},{label:`Generate Draft`,href:`/depreciation/draft`},{label:`Manage Audit Checks`,href:`/audit/checks`},{label:`Review Tax Report`,href:`/tax/review`},{label:`Cash Flow Analysis`,href:`/cashflow/analysis`}]}),(0,X.jsx)($,{id:`6`,title:`Add Shareholders Data (1214)`,description:`For 1214 report preparation`,icon:(0,X.jsx)(Te,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Manage Shareholders`,href:`/shareholders/manage`},{label:`Import Data`,href:`/shareholders/import`}]}),(0,X.jsx)($,{id:`7`,title:`Revalidate Pending Items`,description:`Ensure no charges approval or ledger regeneration pending`,icon:(0,X.jsx)(A,{className:`h-4 w-4`}),onStatusChange:_,defaultStatus:m,actions:[{label:`Check Pending Approvals`,onClick:()=>{y.current?.scrollIntoView({behavior:`smooth`,block:`start`})}},{label:`Ledger Status`,onClick:()=>{C.current?.scrollIntoView({behavior:`smooth`,block:`start`})}}]}),(0,X.jsx)(at,{id:`8`,title:`Lock Ledger`,description:`Lock ledger by records and by date`,year:l,icon:(0,X.jsx)(Se,{className:`h-4 w-4`}),onStatusChange:_}),(0,X.jsx)($,{id:`9`,title:`Save Final Dynamic Report Template`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Save Template`,href:`/reports/save-template`}]}),(0,X.jsx)($,{id:`10`,title:`Export Year-end Trial Balance`,description:`For future validations`,icon:(0,X.jsx)(H,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Export Trial Balance`,href:`/export/trial-balance`}]}),(0,X.jsx)($,{id:`11`,title:`Generate Final Depreciation Report`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate Report`,href:`/depreciation/final`}]}),(0,X.jsx)($,{id:`12`,title:`Generate Financial Reports`,description:`With comparison numbers from last year`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate Reports`,href:`/reports/financial`}]}),(0,X.jsx)($,{id:`13`,title:`Generate Tax Report`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate Tax Report`,href:`/tax/generate`}]}),(0,X.jsx)($,{id:`14`,title:`Generate Tax Compliance Reports`,description:`For Yossi's review`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate Report`,href:`/compliance/clients-country`}]}),(0,X.jsx)($,{id:`15`,title:`Generate Tax Compliance Report`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate 973`,href:`/reports/973`},{label:`Generate 901א`,href:`/reports/901a`}]}),(0,X.jsx)($,{id:`16`,title:`Generate 6111 Report`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate 6111`,href:`/reports/6111`}]}),(0,X.jsx)($,{id:`17`,title:`Generate Dividend Report 1214ב`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate Dividend Report`,href:`/reports/dividend-1214b`}]}),(0,X.jsx)($,{id:`18`,title:`Generate 1214 Report`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Generate 1214`,href:`/reports/1214`}]}),(0,X.jsx)($,{id:`19`,title:`Compare Tax Expenses`,description:`Compare 1214 tax expenses with ledger tax expenses`,icon:(0,X.jsx)(W,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Compare Expenses`,href:`/tax/compare-expenses`}]}),(0,X.jsx)($,{id:`20`,title:`Signing Process`,description:`Handle signing process and accompanying documents`,icon:(0,X.jsx)(j,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Prepare Documents`,href:`/signing/prepare`},{label:`Digital Signing`,href:`/signing/digital`}]}),(0,X.jsx)($,{id:`21`,title:`File Annual Report`,description:`Submit annual report to companies government office`,icon:(0,X.jsx)(we,{className:`h-4 w-4`}),onStatusChange:_,actions:[{label:`Prepare Filing`,href:`/filing/prepare`},{label:`Submit Report`,href:`/filing/submit`}]})]}),(0,X.jsxs)(`div`,{className:`mt-8 p-4 bg-muted rounded-lg`,children:[(0,X.jsx)(`h3`,{className:`font-semibold mb-2`,children:`Quick Actions`}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(P,{variant:`outline`,size:`sm`,children:[(0,X.jsx)(H,{className:`h-4 w-4 mr-2`}),`Export Progress Report`]}),(0,X.jsxs)(P,{variant:`outline`,size:`sm`,children:[(0,X.jsx)(M,{className:`h-4 w-4 mr-2`}),`Configure Workflow`]}),(0,X.jsxs)(P,{variant:`outline`,size:`sm`,children:[(0,X.jsx)(A,{className:`h-4 w-4 mr-2`}),`View All Reports`]})]})]})]})}):null};export{ut as AnnualAuditFlow};