@accounter/client
Version:
Accounter client application
2 lines • 11.1 kB
JavaScript
import{s as e}from"./dist-C51EwTaa.js";import{i as t,o as n}from"./utils-DdVdMk8X.js";import{J as r,Lo as i,Rn as a,X as o,Y as s,Z as c}from"./error-handling-Dpfd9svJ.js";import{s as l,t as u}from"./routes-DUvpW9-n.js";import{ht as d,mt as f}from"./select-CrsvQyhZ.js";import{t as p}from"./button-Dzp2INW0.js";import{J as m,W as h}from"./table--bF0wbxq.js";import{Pr as g,Pt as _,Sr as v,cn as y,gi as b}from"./index-CL8-JoMZ.js";import{t as x}from"./page-layout-DoLDsSrs.js";var S=e(n(),1),C=(e,t)=>v(t,{minimumFractionDigits:0}).format(e),w=t();function T(e){return{id:e.id,chargeId:e.chargeId,date:e.date,description:e.description??``,reference:e.reference??``,amountILS:e.revenueLocal.raw,amountUSD:e.revenueDefaultForeign.raw,originalAmount:e.revenueOriginal.formatted}}var E=({recordData:e})=>{let t=T(h(o,e));return(0,w.jsx)(`div`,{className:`p-2 bg-background rounded-lg border border-border/30 text-sm`,children:(0,w.jsxs)(l,{to:u.CHARGES.DETAIL(t.chargeId),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`flex items-start justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`flex-1`,children:[(0,w.jsx)(`p`,{className:`font-medium text-foreground`,children:t.reference}),(0,w.jsx)(`p`,{className:`font-medium text-foreground`,children:t.description}),(0,w.jsxs)(`div`,{className:`flex gap-4 mt-1 text-xs text-muted-foreground`,children:[(0,w.jsx)(`span`,{children:t.chargeId}),(0,w.jsx)(`span`,{children:t.date})]})]}),(0,w.jsxs)(`div`,{className:`invisible md:visible md:text-right flex-shrink-0`,children:[(0,w.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:C(t.amountILS,a.Ils)}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C(t.amountUSD,a.Usd)}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.originalAmount})]}),(0,w.jsx)(`div`,{className:`md:invisible ml-2 text-right`,children:(0,w.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:C(t.amountILS,a.Ils)})})]})})};function D(e){return{id:e.id,name:e.name,revenueILS:e.revenueLocal.raw,revenueUSD:e.revenueDefaultForeign.raw,records:e.records.map(e=>({id:e.id,data:e}))}}var O=({clientData:e})=>{let[t,n]=(0,S.useState)(!1),i=D(h(r,e)),o=()=>{n(e=>!e)},s=(0,S.useMemo)(()=>i.records.slice().sort((e,t)=>e.data.date.localeCompare(t.data.date)),[i.records]);return(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`button`,{onClick:o,className:`w-full flex items-center justify-between p-2 bg-background rounded-lg border border-border/50 hover:bg-accent/5 transition-colors`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 flex-1`,children:[t?(0,w.jsx)(d,{className:`size-4 text-muted-foreground flex-shrink-0`}):(0,w.jsx)(f,{className:`size-4 text-muted-foreground flex-shrink-0`}),(0,w.jsxs)(`div`,{className:`text-left`,children:[(0,w.jsx)(`p`,{className:`font-medium text-foreground text-sm`,children:i.name}),(0,w.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.records?.length||0,` record`,i.records?.length===1?``:`s`]})]})]}),(0,w.jsxs)(`div`,{className:`hidden md:grid grid-cols-2 gap-4 text-right flex-shrink-0`,children:[(0,w.jsx)(`div`,{children:(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C(i.revenueILS,a.Ils)})}),(0,w.jsx)(`div`,{children:(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C(i.revenueUSD,a.Usd)})})]}),(0,w.jsxs)(`div`,{className:`md:hidden ml-4 text-right`,children:[(0,w.jsx)(`p`,{className:`text-xs font-medium text-foreground`,children:C(i.revenueILS,a.Ils)}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C(i.revenueUSD,a.Usd)})]})]}),t&&s&&(0,w.jsx)(`div`,{className:`mt-3 ml-2 space-y-3 border-l-2 border-border/50 pl-2`,children:s.map(e=>(0,w.jsx)(E,{recordData:e.data},e.id))})]})};function k(e){return{code:e.code,name:e.name,revenues:{ILS:e.revenueLocal.raw,USD:e.revenueDefaultForeign.raw},clients:e.clients.map(e=>({id:e.id,data:e}))}}var A=({countryData:e})=>{let[t,n]=(0,S.useState)(!1),r=k(h(s,e)),i=()=>{n(e=>!e)},o={ILS:r.revenues.ILS,USD:r.revenues.USD},c=r.clients.slice().sort((e,t)=>t.data.revenueDefaultForeign.raw-e.data.revenueDefaultForeign.raw);return(0,w.jsxs)(g,{className:`border border-border`,children:[(0,w.jsxs)(`button`,{onClick:()=>i(),className:`w-full px-4 py-2 hover:bg-accent/5 transition-colors flex items-center justify-between`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 flex-1`,children:[t?(0,w.jsx)(d,{className:`size-5 text-muted-foreground flex-shrink-0`}):(0,w.jsx)(f,{className:`size-5 text-muted-foreground flex-shrink-0`}),(0,w.jsxs)(`div`,{className:`text-left`,children:[(0,w.jsx)(`p`,{className:`font-semibold text-foreground text-lg`,children:r.name}),(0,w.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[r.clients.length,` clients`]})]})]}),(0,w.jsxs)(`div`,{className:`hidden md:grid grid-cols-2 gap-4 text-right flex-shrink-0`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mb-1`,children:`ILS`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(r.revenues.ILS,a.Ils)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mb-1`,children:`USD`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(r.revenues.USD,a.Usd)})]})]})]}),(0,w.jsxs)(`div`,{className:`md:hidden px-2 py-2 bg-accent/5 border-t border-border flex gap-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground mb-1`,children:`ILS`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(r.revenues.ILS,a.Ils)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground mb-1`,children:`USD`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(r.revenues.USD,a.Usd)})]})]}),t&&(0,w.jsx)(`div`,{className:`border-t border-border`,children:(0,w.jsxs)(`div`,{className:`space-y-2 p-3 bg-muted/30`,children:[c.map(e=>(0,w.jsx)(O,{clientData:e.data},e.id)),(0,w.jsx)(`div`,{className:`pt-2 border-t border-border/50 mt-4`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-2`,children:[(0,w.jsx)(`p`,{className:`font-semibold text-foreground text-sm`,children:`Clients Subtotal`}),(0,w.jsxs)(`div`,{className:`hidden md:grid grid-cols-2 gap-4 text-right`,children:[(0,w.jsx)(`div`,{children:(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(o.ILS,a.Ils)})}),(0,w.jsx)(`div`,{children:(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(o.USD,a.Usd)})})]}),(0,w.jsxs)(`div`,{className:`md:hidden ml-4 text-right`,children:[(0,w.jsx)(`p`,{className:`text-sm font-semibold text-foreground`,children:C(o.ILS,a.Ils)}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C(o.USD,a.Usd)})]})]})})]})})]},r.code)},j=()=>{let[e,t]=(0,S.useState)(new Date().getFullYear()-1),[{data:n,fetching:r}]=i({query:c,variables:{filters:{year:e}}}),{setFiltersContext:o}=(0,S.useContext)(y),s=(0,S.useMemo)(()=>`Annual Revenue Report for ${e}`,[e]),{totalClients:l,totalRevenueIls:u,totalRevenueUsd:d}=(0,S.useMemo)(()=>{let e={totalClients:0,totalRevenueIls:0,totalRevenueUsd:0};return n?.annualRevenueReport?.countries?.map(t=>{e.totalClients+=t.clients.length,e.totalRevenueIls+=t.revenueLocal.raw,e.totalRevenueUsd+=t.revenueDefaultForeign.raw}),e},[n?.annualRevenueReport?.countries]),f=(0,S.useCallback)(()=>{let t=[];t.push(`Country,Client,charge ID,Date,Description,Revenue ILS,Revenue USD`),t.push(`Annual,,,,TOTAL,${u.toFixed(2)},${d.toFixed(2)}`),[...n?.annualRevenueReport?.countries??[]].sort((e,t)=>t.revenueDefaultForeign.raw-e.revenueDefaultForeign.raw).map(e=>{t.push(`${e.name},,,,TOTAL,${e.revenueLocal.raw.toFixed(2)},${e.revenueDefaultForeign.raw.toFixed(2)}`),e.clients.sort((e,t)=>t.revenueDefaultForeign.raw-e.revenueDefaultForeign.raw).map(n=>{n.records&&n.records.length>0?(t.push(`${e.name},${n.name},,,TOTAL,${n.revenueLocal.raw.toFixed(2)},${n.revenueDefaultForeign.raw.toFixed(2)}`),n.records.sort((e,t)=>e.date.localeCompare(t.date)).map(r=>{t.push(`${e.name},${n.name},${r.chargeId},${r.date},${r.description},${r.revenueLocal.raw.toFixed(2)},${r.revenueDefaultForeign.raw.toFixed(2)}`)})):t.push(`${e.name},${n.name},,,,,`)})});let r=t.join(`
`),i=new Blob([r],{type:`text/csv;charset=utf-8;`}),a=document.createElement(`a`),o=URL.createObjectURL(i);a.setAttribute(`href`,o),a.setAttribute(`download`,`annual-revenue-${e}.csv`),a.style.visibility=`hidden`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)},[e,n,u,d]);(0,S.useEffect)(()=>{o((0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,w.jsx)(_,{value:new Date(e,0,1),onChange:e=>e&&t(e?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),(0,w.jsxs)(p,{onClick:f,variant:`outline`,size:`sm`,className:`flex items-center gap-2 bg-transparent`,children:[(0,w.jsx)(b,{className:`h-4 w-4`}),(0,w.jsx)(`span`,{className:`hidden sm:inline`,children:`Export CSV`})]})]}))},[e,r,o,f]);let h=(0,S.useMemo)(()=>n?.annualRevenueReport.countries.slice().sort((e,t)=>t.revenueDefaultForeign.raw-e.revenueDefaultForeign.raw),[n]);return(0,w.jsx)(x,{title:`Annual Revenue Report`,description:s,children:r?(0,w.jsx)(m,{}):(0,w.jsx)(`div`,{className:`min-h-screen bg-background`,children:(0,w.jsx)(`main`,{className:`container mx-auto px-2 py-2 max-w-7xl`,children:(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsxs)(g,{className:`border border-border bg-accent/10`,children:[(0,w.jsxs)(`div`,{className:`w-full px-4 py-2 pl-12 transition-colors flex items-center justify-between`,children:[(0,w.jsx)(`div`,{className:`flex items-center gap-2 flex-1`,children:(0,w.jsxs)(`div`,{className:`text-left`,children:[(0,w.jsx)(`p`,{className:`font-semibold text-foreground text-lg`,children:`Total Revenue`}),(0,w.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[l,` clients`]})]})}),(0,w.jsxs)(`div`,{className:`hidden md:grid grid-cols-2 gap-4 text-right flex-shrink-0`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mb-1`,children:`ILS`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(u,a.Ils)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mb-1`,children:`USD`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(d,a.Usd)})]})]})]}),(0,w.jsxs)(`div`,{className:`md:hidden px-2 py-2 bg-accent/5 border-t border-border flex gap-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground mb-1`,children:`ILS`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(u,a.Ils)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground mb-1`,children:`USD`}),(0,w.jsx)(`p`,{className:`font-semibold text-foreground`,children:C(d,a.Usd)})]})]})]}),h?.map(e=>(0,w.jsx)(A,{countryData:e},e.id))]})})})})};export{j as AnnualRevenueReport};