1import{r as C,j as e,L as T,a as p,s as Q,P as B}from"./index-EB60i8_b.js";import{u as D}from"./useQuery-CD633ads.js";import{u as ee}from"./auth-middleware-BXg-s9l0.js";import{u as se}from"./brand-context-jy_uMzVx.js";import{C as j,c as N,a as ce,b as de}from"./card-CKGYtlGw.js";import{B as P}from"./badge-CppVMURX.js";import{B as A}from"./button-vMBgSq5N.js";import{f as l}from"./finance-Cn4saD38.js";import{g as me,a as xe}from"./finance-overview.functions-DbXc8o4y.js";import{S as pe,b as ue,c as he,d as ge,e as be}from"./sheet-0mMrLO_w.js";import{a as fe}from"./excel-CId9GjC7.js";import{D as je}from"./download-CXyrNcW9.js";import{A as E}from"./arrow-right-BkyhOXqX.js";import{C as Ne}from"./chevron-left-BFrO02ex.js";import{C as ve}from"./chevron-right-tHQZp40I.js";import{a as X}from"./apply-brand-scope-D0CwghzU.js";import{C as ye}from"./coins-CY1owQSX.js";import{S as K}from"./smartphone-C1_D3U61.js";import{L as te}from"./landmark-BpY5yu48.js";import{W as R}from"./wallet-BPFjTZVM.js";import{A as $}from"./arrow-down-right-DG0t4f7j.js";import{A as O}from"./arrow-up-right-OBA_Jewa.js";import{b as ke,D as we}from"./date-range-picker-B6dEgM0U.js";import{u as Ce}from"./erp-quick-actions-Bn2SOA9c.js";import{A as ze}from"./account-form-Bnas0bQR.js";import{B as ae}from"./building-2-Dts8MA6J.js";import{C as re}from"./calendar-B39T2JGV.js";import{A as Ae}from"./transfer-dialog-BYlp_7zW.js";import{B as _e}from"./book-open-BAq27ja1.js";import{R as H}from"./receipt-CYBr2hSC.js";import{R as Te}from"./rotate-ccw-DJov7mhM.js";import{A as F}from"./activity-BnJFWnQQ.js";import{R as W,T as U,X as Se,Y as Re,L as Be,B as Y,C as $e}from"./generateCategoricalChart-b0mQpMb6.js";import{A as Oe}from"./AreaChart-B_zsXVZI.js";import{A as Le}from"./Area-Cm5kizp7.js";import{T as V}from"./trending-up-CKeVRNSP.js";import{B as ne}from"./banknote-YsmjNiBn.js";import{P as Me}from"./piggy-bank-y-xZQVBq.js";import{C as De}from"./ComposedChart-VoK9HS2U.js";import{C as Pe}from"./CartesianGrid-CngCoq84.js";import{L as Ee}from"./Line-6LSTp-V6.js";import{P as Fe,a as Ie}from"./PieChart-C-7FP_v0.js";import{F as qe}from"./file-text-Ae3gmFrk.js";import{T as Ke}from"./trending-down-Bk2ouUEm.js";import{T as We}from"./triangle-alert-BXBiVDuy.js";import{T as Ue}from"./truck-zATajgQD.js";import{U as Ge}from"./users-BvQur8iH.js";import"./use-my-access-profile-eX8ffDWv.js";import"./index-CJtd0Bml.js";import"./index-DPrYYZ34.js";import"./index-BGNpujc9.js";import"./x-rtEj0dnA.js";import"./xlsx-BojT3SgY.js";import"./en-US-IVrGvTxk.js";import"./format-CdF6Rsce.js";import"./endOfMonth-DBg3kuNh.js";import"./chevron-down-BpeL8prt.js";import"./input-D8MgPrVN.js";import"./label-B_revbFK.js";import"./check-BfMNAkIe.js";import"./use-finance-query-B9y-UCLq.js";import"./useMutation-B66l_5Oh.js";import"./index-B1qPRzBi.js";import"./dialog-CQs09mcw.js";import"./textarea-BXC_JKsL.js";import"./select-DhyoRdYW.js";import"./index-BdQq_4o_.js";import"./index-ix3cE_J2.js";import"./index--KVnfuxa.js";import"./index-Dl9hlz3A.js";import"./index-BuMx1jGY.js";import"./chevron-up-WDwjygZr.js";import"./command-BTuM-32v.js";import"./search-BTjv1bAl.js";import"./settings-2-KkxE38Fp.js";import"./circle-arrow-down-CLKX8ehg.js";import"./circle-arrow-up-jqP3-8x2.js";import"./tag-50b3fwqu.js";import"./chevrons-up-down-C8DCFmP4.js";import"./plus-erq3DUUs.js";const J=25;function He({open:n,onOpenChange:a,title:s,subtitle:r,brandIds:t,from:i,to:o,type:c="all",accountIds:v}){const[d,f]=C.useState(1),S=ee(me),g=D({queryKey:["finance_drilldown",t.join(","),i,o,c,(v??[]).join(","),d],enabled:n&&t.length>0,queryFn:()=>S({data:{brandIds:t,from:i,to:o,type:c,accountIds:v,page:d,pageSize:J}})}),h=g.data?.rows??[],m=g.data?.total??0,u=Math.max(1,Math.ceil(m/J)),b=g.data?.sum??0,z=()=>{const x=h.map(y=>({Date:y.date,Type:y.type,Description:y.description??"",Account:y.account??"",Category:y.category??"",Reference:y.reference??"",Amount:y.amount})),le=`${s.toLowerCase().replace(/[^a-z0-9]+/g,"_")}_${i}_${o}.xlsx`;fe(x,"Transactions",le)};return e.jsx(pe,{open:n,onOpenChange:a,children:e.jsxs(ue,{side:"right",className:"w-full sm:max-w-2xl overflow-y-auto",children:[e.jsxs(he,{className:"space-y-1",children:[e.jsx(ge,{children:s}),e.jsxs(be,{children:[i," â ",o,r?` · ${r}`:""]})]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Total (",m," txns):"]})," ",e.jsx("span",{className:"font-mono font-semibold",children:l(b)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(A,{size:"sm",variant:"outline",onClick:z,disabled:!h.length,children:[e.jsx(je,{className:"h-3.5 w-3.5 mr-1"})," CSV/Excel"]}),e.jsx(A,{size:"sm",variant:"ghost",asChild:!0,children:e.jsxs(T,{to:"/erp/finance/journal",children:["View All ",e.jsx(E,{className:"h-3.5 w-3.5 ml-1"})]})})]})]}),e.jsxs("div",{className:"mt-3 rounded-md border bg-card",children:[g.isLoading&&e.jsx("div",{className:"p-6 text-center text-sm text-muted-foreground",children:"Loadingâ¦"}),!g.isLoading&&h.length===0&&e.jsx("div",{className:"p-6 text-center text-sm text-muted-foreground",children:"No transactions in range."}),!g.isLoading&&h.length>0&&e.jsx("div",{className:"divide-y divide-border/60",children:h.map(x=>e.jsxs("div",{className:"flex items-start gap-3 px-3 py-2 text-sm",children:[e.jsx(P,{variant:x.type==="income"?"default":x.type==="expense"?"destructive":"secondary",className:"text-[10px] capitalize shrink-0",children:x.type}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate",children:x.description||e.jsx("span",{className:"text-muted-foreground italic",children:"No description"})}),e.jsxs("div",{className:"text-[11px] text-muted-foreground truncate",children:[x.date,x.account&&` · ${x.account}`,x.category&&` · ${x.category}`,x.reference&&` · ${x.reference}`]})]}),e.jsxs("div",{className:`tabular-nums font-medium shrink-0 ${x.type==="income"?"text-emerald-600 dark:text-emerald-400":x.type==="expense"?"text-rose-600 dar
1k:text-rose-400":""}`,children:[x.type==="expense"?"-":x.type==="income"?"+":"",l(x.amount)]})]},x.id))})]}),u>1&&e.jsxs("div",{className:"mt-3 flex items-center justify-between text-xs",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Page ",d," of ",u]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(A,{size:"sm",variant:"outline",className:"h-7",disabled:d<=1,onClick:()=>f(d-1),children:e.jsx(Ne,{className:"h-3.5 w-3.5"})}),e.jsx(A,{size:"sm",variant:"outline",className:"h-7",disabled:d>=u,onClick:()=>f(d+1),children:e.jsx(ve,{className:"h-3.5 w-3.5"})})]})]})]})})}const Ve=[{key:"cash",label:"Cash",icon:ye,iconColor:"text-emerald-600",bg:"bg-emerald-50 dark:bg-emerald-950/40",ring:"ring-emerald-200/60 dark:ring-emerald-900/60",subtypes:["cash"]},{key:"bkash",label:"bKash",icon:K,iconColor:"text-pink-600",bg:"bg-pink-50 dark:bg-pink-950/40",ring:"ring-pink-200/60 dark:ring-pink-900/60",subtypes:["bkash"]},{key:"nagad",label:"Nagad",icon:K,iconColor:"text-orange-600",bg:"bg-orange-50 dark:bg-orange-950/40",ring:"ring-orange-200/60 dark:ring-orange-900/60",subtypes:["nagad","rocket"]},{key:"bank",label:"Bank",icon:te,iconColor:"text-blue-600",bg:"bg-blue-50 dark:bg-blue-950/40",ring:"ring-blue-200/60 dark:ring-blue-900/60",subtypes:["bank"]}];function ie(n){return(n.account_subtype??n.account_type??"").toLowerCase()}function Z(n){const a=ie(n);return["cash","petty_cash"].includes(a)?"cash":["bkash"].includes(a)?"bkash":["nagad","rocket","upay"].includes(a)?"nagad":["bank","bank_savings","bank_current"].includes(a)?"bank":null}function Qe(){const{brandIds:n}=se(),a=new Date().toISOString().slice(0,10),s=D({queryKey:["bd_wallets_widget",n.join(",")],enabled:n.length>0,queryFn:async()=>{const{data:o,error:c}=await X(Q.from("erp_accounts").select("id,brand_id,name,account_subtype,account_type,current_balance"),n,"brand_id",{includeNull:!0}).eq("is_active",!0);if(c)throw c;return o??[]}}),r=D({queryKey:["bd_wallets_today",n.join(","),a],enabled:n.length>0,queryFn:async()=>{const{data:o,error:c}=await X(Q.from("erp_transactions").select("id,txn_type,amount,account_id,to_account_id"),n).eq("transaction_date",a);if(c)throw c;return o??[]}}),t=C.useMemo(()=>{const o=s.data??[],c=r.data??[],v=new Map;for(const d of o){ie(d);const f=Z(d);f&&v.set(d.id,f)}return Ve.map(d=>{const f=o.filter(m=>Z(m)===d.key),S=f.reduce((m,u)=>m+Number(u.current_balance||0),0);let g=0,h=0;for(const m of c){const u=Number(m.amount||0),b=m.account_id&&v.get(m.account_id),z=m.to_account_id&&v.get(m.to_account_id);m.txn_type==="income"&&b===d.key?g+=u:m.txn_type==="expense"&&b===d.key?h+=u:m.txn_type==="transfer"?(b===d.key&&(h+=u),z===d.key&&(g+=u)):m.txn_type==="adjustment"&&b===d.key&&(u>=0?g+=u:h+=-u)}return{...d,balance:S,inflow:g,outflow:h,count:f.length}})},[s.data,r.data]);return t.some(o=>o.count>0)?e.jsx(j,{children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(R,{className:"h-4 w-4 text-muted-foreground"})," Accounts & Wallets · Today"]}),e.jsx(T,{to:"/erp/finance/accounts",className:"text-xs text-primary hover:underline",children:"View all â"})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:t.map(o=>{const c=o.icon;return o.count===0?e.jsxs("div",{className:"rounded-lg p-3 border border-dashed text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{children:o.label}),e.jsx(c,{className:"h-3.5 w-3.5 opacity-50"})]}),e.jsx("div",{className:"text-sm mt-1",children:"No wallet"})]},o.key):e.jsxs("div",{className:p("rounded-lg p-3 ring-1",o.bg,o.ring),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium",children:o.label}),e.jsx(c,{className:p("h-4 w-4",o.iconColor)})]}),e.jsx("div",{className:"text-lg font-bold tabular-nums mt-0.5",children:l(o.balance)}),o.inflow>0||o.outflow>0?e.jsxs("div",{className:"flex gap-2 text-[11px] mt-1",children:[o.inflow>0&&e.jsxs("span",{className:"text-emerald-700 dark:text-emerald-400 inline-flex items-center gap-0.5",children:[e.jsx($,{className:"h-3 w-3"}),l(o.inflow)]}),o.outflow>0&&e.jsxs("span",{className:"text-rose-700 dark:text-rose-400 inline-flex items-center gap-0.5",children:[e.jsx(O,{className:"h-3 w-3"}),l(o.outflow)]})]}):e.jsx("div",{className:"text-[11px] text-muted-foreground mt-1",children:"No movement today"})]},o.key)})})]})}):null}const Xe={pathao:"Pathao",steadfast:"SteadFast",redx:"RedX",paperfly:"Paperfly",ecourier:"eCourier",no_shipment:"No shipment",unknown:"Other"},L=["#6366f1","#ec4899","#f59e0b","#10b981","#06b6d4","#8b5cf6","#ef4444","#84cc16"],G={background:"var(--card)",border:"1px solid var(--border)",borderRadius:10,fontSize:12,boxShadow:"0 12px 32px -16px rgb(0 0 0 / 0.35)"};function Bt(){const{activeBrand:n,brands:a,brandIds:s,isAllBrands:r}=se(),[t,i]=C.useState(()=>ke("this_month")),{from:o,to:c}=t,v=ee(xe),{openTxn:d,openTransfer:f}=Ce(),[S,g]=C.useState(!1),h=D({queryKey:["finance_overview",s.join(","),o,c],enabled:s.length>0,queryFn:()=>v({data:{brandIds:s,from:o,to:c}})}),[m,u]=C.useState(null);if(s.length===0)return e.jsx("div",{className:"p-6 text-muted-foreground",children:"Loading brandsâ¦"});const b=h.data;return e.jsxs("div",{className:"pb-10",children:[e.jsx("header",{className:"sticky top-0 z-20 border-b border-border/60 bg-background/80 backdrop-blur-xl supports-[backdrop-filter]:bg-background/60",children:e.jsxs("div",{className:"px-4 md:px-6 py-3 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 mr-auto",children:[e.jsx("span",{className:"grid place-items-center size-9 rounded-xl bg-primary/10 text-primary ring-1 ring-primary/20",children:e.jsx(te,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-[15px] font-semibold tracking-tight leading-tight",children:"Finance & Accounting"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground flex items-center gap-1.5 mt-0.5",children:[e.jsx(ae,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{className:"truncate",children:r?`All brands · ${a.length}`:n?.name??"â"}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx(re,{className:"h-3 w-3 shrink-0"}),e.jsxs("span",{className:"tabular-nums",children:[o," â ",c]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx(we,{value:t,onChange:i}),e.jsx("span",{className:"hidden md:block h-6 w-px bg-border mx-1","aria-hidden":!0}),e.jsx(I,{tone:"emerald",icon:e.jsx($,{className:"size-3.5"}),label:"Income",onClick:()=>d("income")}),e.jsx(I,{tone:"rose",icon:e.jsx(O,{className:"size-3.5"}),label:"Expense",onClick:()=>d("expense")}),e.jsx(I,{tone:"sky",icon:e.jsx(Ae,{className:"size-3.5"}),label:"Transfer",onClick:()=>f()}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-8 gap-1.5 text-xs",asChild:!0,children:e.jsxs(T,{to:"/erp/finance/accounts",children:[e.jsx(_e,{className:"size-3.5"})," Accounts"]})})]})]})}),e.jsxs("div",{className:"px-4 md:px-6 pt-4 space-y-4",children:[h.isLoading&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"h-56 rounded-2xl border bg-muted/30 animate-pulse"}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:Array.from({length:4}).map((z,x)=>e.jsx("div",{className:"h-24 rounded-xl border bg-muted/30 animate-pulse"},x))})]}),h.error&&e.jsx("div",{className:"rounded-xl border border-destructive/30 bg-destructive/5 px-4 py-3 text-sm text-destructive",children:h.error.message}),b&&e.jsxs(e.Fragment,{children:[e.jsx(rs,{}),e.jsx(Ye,{data:b,onDrill:u}),e.jsx(Je,{data:b,onDrill:u}),e.jsx(as,{data:b}),e.jsx(Ze,{data:b}),e.jsxs("section",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4 items-start",children:[e.jsx("div",{className:"lg:col-span-8 min-w-0",children:e.jsx(ns,{data:b})}),e.jsx("div",{className:"lg:col-span-4 min-w-0",children:e.jsx(Qe,{})})]})]})]}),e.jsx(He,{open:!!m,onOpenChange:z=>{z||u(null)},title:m?.title??"",subtitle:m?.subtitle,brandIds:s,from:o,to:c,type:m?.type,accountIds:m?.accountIds}),e.jsx(ze,{open:S,onClose:()=>g(!1),brandId:r?null:n?.id??null,brands:a})]})}function I({icon:n,label:a,tone:s,onClick:r}){const t={emerald:"border-emerald-500/30 text-emerald-700 dark:text-emerald-400 hover:bg-emerald-500/10 hover:border-emerald-500/50",rose:"border-rose-500/30 text-rose-700 dark:text-rose-400 hover:bg-rose-500/10 hover:border-rose-500/50",sky:"border-sky-500/30 text-sky-700 dark:text-sky-400 hover:bg-sky-500/10 hover:border-sky-500/50"}[s];return e.jsxs(A,{variant:"outline",size:"sm",onClick:r,className:p("h-8 gap-1.5 text-xs font-semibold",t),children:[n,a]})}function Ye({data:n,onDrill:a}){const{pnl:s}=n,r=s.net>=0,t=C.useMemo(()=>{const i=Math.max(s.revenue,1),o=c=>Math.min(100,Math.max(0,Math.abs(c)/i*100));return[{key:"cogs",label:"COGS",value:s.cogs,pct:o(s.cogs),bar:"bg-
1amber-500",text:"text-amber-600 dark:text-amber-400",icon:e.jsx(B,{className:"size-3.5"})},{key:"opex",label:"Operating",value:s.expense,pct:o(s.expense),bar:"bg-rose-500",text:"text-rose-600 dark:text-rose-400",icon:e.jsx(H,{className:"size-3.5"}),drill:{title:"Operating expenses",type:"expense"}},{key:"refund",label:"Refund loss",value:s.refundLoss,pct:o(s.refundLoss),bar:"bg-violet-500",text:"text-violet-600 dark:text-violet-400",icon:e.jsx(Te,{className:"size-3.5"})},{key:"net",label:"Net profit",value:s.net,pct:o(s.net),bar:r?"bg-emerald-500":"bg-rose-600",text:r?"text-emerald-600 dark:text-emerald-400":"text-rose-600 dark:text-rose-400",icon:e.jsx(F,{className:"size-3.5"})}]},[s,r]);return e.jsx(j,{className:"overflow-hidden border-border/60 p-0",children:e.jsxs(N,{className:"p-0 grid grid-cols-1 lg:grid-cols-12",children:[e.jsxs("div",{className:p("relative lg:col-span-4 p-5 cursor-pointer transition overflow-hidden border-b lg:border-b-0 lg:border-r border-border/60",r?"bg-gradient-to-br from-emerald-500/10 via-emerald-500/5 to-transparent hover:from-emerald-500/15":"bg-gradient-to-br from-rose-500/10 via-rose-500/5 to-transparent hover:from-rose-500/15"),onClick:()=>a({title:"Net profit â all transactions",type:"all"}),role:"button",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.14em] font-semibold text-muted-foreground",children:"Net profit"}),e.jsxs(P,{variant:"outline",className:p("text-[10px] font-semibold border-0 tabular-nums",r?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-400":"bg-rose-500/15 text-rose-700 dark:text-rose-400"),children:[s.margin.toFixed(1),"% margin"]})]}),e.jsxs("div",{className:p("mt-3 text-[38px] leading-none font-bold tabular-nums tracking-tighter",r?"text-emerald-600 dark:text-emerald-400":"text-rose-600 dar
1k:text-rose-400"),children:[r?"+":"",l(s.net)]}),e.jsxs("div",{className:"mt-1.5 text-[11px] text-muted-foreground tabular-nums",children:["Revenue ",l(s.revenue)," · ",n.range.from," â ",n.range.to]}),e.jsx("div",{className:"mt-3 h-16 -mx-1",children:e.jsx(W,{width:"100%",height:"100%",children:e.jsxs(Oe,{data:s.dailySeries,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"netGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:r?"#10b981":"#f43f5e",stopOpacity:.5}),e.jsx("stop",{offset:"100%",stopColor:r?"#10b981":"#f43f5e",stopOpacity:0})]})}),e.jsx(Le,{type:"monotone",dataKey:"net",stroke:r?"#10b981":"#f43f5e",fill:"url(#netGrad)",strokeWidth:1.75}),e.jsx(U,{formatter:i=>l(i),labelFormatter:i=>`${i}`,contentStyle:G})]})})}),(s.otherIncome>0||s.capitalOutflow>0||s.cogsMissingUnits>0)&&e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[s.otherIncome>0&&e.jsxs(q,{children:["Other income ",l(s.otherIncome)]}),s.capitalOutflow>0&&e.jsxs(q,{title:"Stock purchase & ad-wallet top-ups â asset, not expense",children:["Capital out ",l(s.capitalOutflow)]}),s.cogsMissingUnits>0&&e.jsxs(q,{warn:!0,children:[s.cogsMissingUnits," units without cost"]})]})]}),e.jsxs("div",{className:"lg:col-span-8 p-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.14em] font-semibold text-muted-foreground",children:"Where revenue went"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground tabular-nums",children:["Base · ",l(s.revenue)," revenue"]})]}),e.jsx("div",{className:"mt-3 flex h-2.5 w-full overflow-hidden rounded-full bg-muted",children:t.map(i=>e.jsx("div",{className:p(i.bar,"h-full"),style:{width:`${i.pct}%`},title:`${i.label} · ${l(i.value)}`},i.key))}),e.jsx("div",{className:"mt-4 grid grid-cols-2 md:grid-cols-4 gap-3",children:t.map(i=>e.jsxs("div",{className:p("group rounded-xl border border-border/60 bg-muted/20 p-3 transition",i.drill&&"cursor-pointer hover:bg-muted/50 hover:border-foreground
1/15"),onClick:i.drill?()=>a(i.drill):void 0,role:i.drill?"button":void 0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider font-semibold text-muted-foreground",children:[e.jsx("span",{className:i.text,children:i.icon}),i.label]}),e.jsx("div",{className:p("mt-2 text-lg font-bold tabular-nums tracking-tight",i.text),children:l(i.value)}),e.jsx("div",{className:"mt-2 h-1 w-full rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:p(i.bar,"h-full rounded-full"),style:{width:`${i.pct}%`}})}),e.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground tabular-nums",children:[i.pct.toFixed(1),"% of revenue"]})]},i.key))}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-x-4 gap-y-1 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(V,{className:"size-3.5 text-emerald-500"})," Gross ",e.jsx("span",{className:"font-semibold text-foreground tabular-nums",children:l(s.gross)})]}),e.jsxs("button",{className:"inline-flex items-center gap-1.5 hover:text-foreground transition",onClick:()=>a({title:"Revenue (orders & income)",type:"income"}),children:[e.jsx(ne,{className:"size-3.5"})," Revenue detail ",e.jsx(E,{className:"size-3"})]})]})]})]})})}function q({children:n,warn:a,title:s}){return e.jsx("span",{title:s,className:p("inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium tabular-nums border",a?"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400":"border-border/70 bg-muted/50 text-muted-foreground"),children:n})}function Je({data:n,onDrill:a}){const{capital:s}=n,r=n.accounts.filter(t=>["cash","bank","bkash","nagad","rocket","mfs"].includes(t.type)).map(t=>t.id);return e.jsxs("section",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(M,{icon:e.jsx(Me,{className:"size-4"}),label:"Total Capital",value:s.total,tone:"primary",hint:"Liquid + Inventory + Receivables â Payables",onClick:()=>a({title:"All transactions",type:"all"})}),e.jsx(M,{icon:e.jsx(R,{className:"size-4"}),label:"Liquid Cash",value:s.liquid,tone:"emerald",hint:`Cash ${l(s.breakdown.cash)} · Bank ${l(s.breakdown.bank)} · MFS ${l(s.breakdown.mfs)}`,onClick:()=>a({title:"Liquid cash movements",subtitle:"Cash + Bank + MFS accounts",type:"all",accountIds:r})}),e.jsx(M,{icon:e.jsx(B,{className:"size-4"}),label:"Inventory Value",value:s.inventory,tone:"amber",hint:s.productsMissingCost>0?`${s.productsMissingCost} product(s) missing cost`:"All stock costed",warn:s.productsMissingCost>0}),e.jsx(M,{icon:s.receivableNet>=0?e.jsx($,{className:"size-4"}):e.jsx(O,{className:"size-4"}),label:s.receivableNet>=0?"Net Receivable":"Net Payable",value:Math.abs(s.receivableNet),tone:s.receivableNet>=0?"sky":"rose",hint:`COD ${l(s.breakdown.codReceivable)} + AR ${l(s.breakdown.arDue)} â Pay ${l(s.breakdown.supplierPayable+s.breakdown.importsDue)}`})]})}function M({icon:n,label:a,value:s,hint:r,tone:t,warn:i,onClick:o}){const c={primary:{icon:"bg-primary/10 text-primary ring-primary/20",glow:"from-primary/10"},emerald:{icon:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 ring-emerald-500/20",glow:"from-emerald-500/10"},amber:{icon:"bg-amber-500/10 text-amber-600 dark:text-amber-400 ring-amber-500/20",glow:"from-amber-500/10"},sky:{icon:"bg-sky-500/10 text-sky-600 dark:text-sky-400 ring-sky-500/20",glow:"from-sky-500/10"}
1,rose:{icon:"bg-rose-500/10 text-rose-600 dark:text-rose-400 ring-rose-500/20",glow:"from-rose-500/10"}}[t];return e.jsxs(j,{className:p("relative overflow-hidden border-border/60 bg-card p-0 transition-all duration-200",o&&"cursor-pointer hover:border-foreground/20 hover:shadow-md hover:-translate-y-0.5"),children:[e.jsx("div",{className:p("pointer-events-none absolute -right-8 -top-10 size-28 rounded-full bg-gradient-to-b to-transparent blur-2xl",c.glow),"aria-hidden":!0}),e.jsxs(N,{className:"relative p-4",onClick:o,role:o?"button":void 0,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:p("grid place-items-center size-7 rounded-lg ring-1 shrink-0",c.icon),children:n}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.12em] text-muted-foreground truncate",children:a})]}),e.jsx("div",{className:"mt-3 text-[26px] leading-none font-bold tabular-nums tracking-tighter text-foreground",children:l(s)}),r&&e.jsxs("div",{className:p("mt-2.5 text-[10.5px] truncate",i?"text-amber-600 dark:text-amber-400 flex items-center gap-1":"text-muted-foreground"),title:r,children:[i&&e.jsx(We,{className:"size-3 shrink-0"}),r]})]})]})}function Ze({data:n}){return e.jsxs("section",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4 items-start",children:[e.jsx(es,{data:n}),e.jsx(ss,{data:n}),e.jsx(ts,{data:n})]})}function _({icon:n,title:a,tone:s,action:r}){const t={sky:"bg-sky-500/10 text-sky-600 dark:text-sky-400",emerald:"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",rose:"bg-rose-500/10 text-rose-600 dar
1k:text-rose-400",primary:"bg-primary/10 text-primary",violet:"bg-violet-500/10 text-violet-600 dark:text-violet-400",slate:"bg-slate-500/10 text-slate-600 dark:text-slate-300"}[s];return e.jsxs(ce,{className:"pb-3 flex flex-row items-center justify-between space-y-0 border-b border-border/50",children:[e.jsxs(de,{className:"text-[13px] font-semibold flex items-center gap-2",children:[e.jsx("span",{className:p("grid place-items-center size-6 rounded-md",t),children:n}),a]}),r]})}function es({data:n}){const a=C.useMemo(()=>{const r={cash:{name:"Cash",balance:0,icon:e.jsx(ne,{className:"size-3.5"}),items:[]},bank:{name:"Bank",balance:0,icon:e.jsx(ae,{className:"size-3.5"}),items:[]},mfs:{name:"Mobile Wallet",balance:0,icon:e.jsx(K,{className:"size-3.5"}),items:[]},other:{name:"Other",balance:0,icon:e.jsx(R,{className:"size-3.5"}),items:[]}};for(const t of n.accounts){const i=t.type==="cash"?"cash":t.type==="bank"?"bank":["bkash","nagad","rocket","mfs"].includes(t.type)?"mfs":"other";r[i].balance+=t.balance,r[i].items.push(t)}return r},[n.accounts]),s=Math.max(n.capital.liquid,1);return e.jsxs(j,{className:"border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx(R,{className:"size-3.5"}),title:"Where my money is",tone:"sky",action:e.jsxs(T,{to:"/erp/finance/accounts",className:"text-[11px] font-medium text-primary inline-flex items-center gap-1 hover:gap-2 transition-all",children:["All ",e.jsx(E,{className:"size-3"})]})}),e.jsxs(N,{className:"p-4 space-y-3",children:[Object.entries(a).filter(([,r])=>r.items.length>0).map(([r,t])=>e.jsxs("div",{className:"rounded-lg border border-border/50 bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-[13px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",children:[t.icon,t.name]}),e.jsx("span",{className:"tabular-nums font-bold",children:l(t.balance)})]}),e.jsx("div",{className:"mt-1.5 h-1 w-full rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-sky-500",style:{width:`${Math.min(100,Math.max(0,t.balance/s*100))}%`}})}),e.jsxs("div",{className:"mt-1.5 space-y-0.5",children:[t.items.slice(0,5).map(i=>e.jsxs("div",{className:"flex justify-between text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"truncate",children:i.name}),e.jsx("span",{className:"tabular-nums",children:l(i.balance)})]},i.id)),t.items.length>5&&e.jsxs("div",{className:"text-[10px] text-muted-foreground/70",children:["+",t.items.length-5," more"]})]})]},r)),n.inventoryByBrand.length>0&&e.jsxs("div",{className:"pt-2 border-t border-border/60",children:[e.jsxs("div",{className:"text-[13px] font-medium flex items-center gap-1.5 mb-1",children:[e.jsx(B,{className:"size-3.5"})," Inventory by brand"]}),n.inventoryByBrand.slice(0,6).map(r=>e.jsxs("div",{className:"flex justify-between text-[11px]",children:[e.jsxs("span",{className:"truncate text-muted-foreground",children:[r.brand," · ",r.units," units"]}),e.jsx("span",{className:"tabular-nums",children:l(r.value)})]},r.brand_id))]})]})]})}function ss({data:n}){const{receivables:a,capital:s,pnl:r}=n;return e.jsxs(j,{className:"border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx($,{className:"size-3.5"}),title:"Money coming in",tone:"emerald"}),e.jsxs(N,{className:"p-4 space-y-3",children:[e.jsx(k,{title:"COD from courier",total:s.breakdown.codReceivable,icon:e.jsx(Ue,{className:"size-3.5"}),children:a.codByCourier.length===0?e.jsx(oe,{children:"No shipped orders"}):a.codByCourier.map(t=>e.jsx(w,{label:`${Xe[t.provider]??t.provider} · ${t.orders}`,value:t.amount},t.provider))}),a.arTop.length>0&&e.jsx(k,{title:"AR â top customers",total:s.breakdown.arDue,icon:e.jsx(Ge,{className:"size-3.5"}),children:a.arTop.map(t=>e.jsx(w,{label:`${t.name} · ${t.orders}`,value:t.amount,sub:t.phone??void 0},t.phone??t.name))}),a.importsAdvanceTop.length>0&&e.jsx(k,{title:"Imports advance",total:s.breakdown.importsAdvance,icon:e.jsx(B,{className:"size-3.5"}),children:a.importsAdvanceTop.map(t=>e.jsx(w,{label:`${t.po} · ${t.supplier}`,value:t.amount},t.po))}),r.otherIncome>0&&e.jsxs("div",{className:"flex justify-between text-[13px] pt-2 border-t border-border/60",children:[e.jsx("span",{className:"text-muted-foreground",children:"Other income (range)"}),e.jsx("span",{className:"tabular-nums font-medium",children:l(r.otherIncome)})]})]})]})}function ts({data:n}
1){const{payables:a,capital:s}=n;return e.jsxs(j,{className:"border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx(O,{className:"size-3.5"}),title:"Money going out",tone:"rose"}),e.jsxs(N,{className:"p-4 space-y-3",children:[e.jsx(k,{title:"Supplier payable",total:s.breakdown.supplierPayable,icon:e.jsx(H,{className:"size-3.5"}),rightBadge:a.overdueBills>0?e.jsxs(P,{variant:"destructive",className:"text-[10px]",children:[l(a.overdueBills)," overdue"]}):void 0,children:a.supplierTop.length===0?e.jsx(oe,{children:"No open bills"}):a.supplierTop.map(r=>e.jsx(w,{label:r.name,value:r.due},r.name))}),a.importsDueTop.length>0&&e.jsx(k,{title:"Imports due",total:s.breakdown.importsDue,icon:e.jsx(B,{className:"size-3.5"}),children:a.importsDueTop.map(r=>e.jsx(w,{label:`${r.po} · ${r.supplier}`,value:r.due,sub:r.status},r.po))}),a.upcomingRecurring.length>0&&e.jsx(k,{title:"Upcoming recurring (30d)",total:a.upcomingRecurring.reduce((r,t)=>r+t.amount,0),icon:e.jsx(re,{className:"size-3.5"}),children:a.upcomingRecurring.slice(0,6).map(r=>e.jsx(w,{label:r.name,value:r.amount,sub:new Date(r.next_run).toLocaleDateString("en-GB",{day:"2-digit",month:"short"})},r.id))}),a.topExpenseCats.length>0&&e.jsx(k,{title:"Top expense categories",icon:e.jsx(F,{className:"size-3.5"}),children:a.topExpenseCats.map(r=>e.jsx(w,{label:r.name,value:r.amount},r.name))})]})]})}function k({title:n,total:a,icon:s,children:r,rightBadge:t}){return e.jsxs("div",{className:"rounded-lg border border-border/50 bg-muted/20 p-2.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-[13px] font-medium",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[s,n]}),e.jsxs("span",{className:"flex items-center gap-2",children:[t,a!=null&&e.jsx("span",{className:"tabular-nums font-bold",children:l(a)})]})]}),e.jsx("div",{className:"mt-1.5 space-y-0.5 pl-5",children:r})]})}function w({label:n,value:a,sub:s}){return e.jsxs("div",{className:"flex justify-between text-[11.5px] gap-2",children:[e.jsxs("span",{className:"truncate text-muted-foreground",children:[n,s&&e.jsxs("span",{className:"opacity-70",children:[" · ",s]})]}),e.jsx("span",{className:"tabular-nums shrink-0",children:l(a)})]})}function oe({children:n}){return e.jsx("div",{className:"text-[11.5px] text-muted-foreground italic",children:n})}function as({data:n}){const a=n.monthlySeries.map(t=>({month:t.month.slice(5),Revenue:t.revenue,Expense:t.expense,Net:t.net})),s=n.payables.topExpenseCats.map(t=>({name:t.name,value:t.amount})),r=s.reduce((t,i)=>t+i.value,0);return e.jsxs("section",{className:"grid grid-cols-1 lg:grid-cols-12 gap-4 items-start",children:[e.jsxs(j,{className:"lg:col-span-8 min-w-0 border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx(V,{className:"size-3.5"}),title:"12 months · Revenue vs Expense vs Net",tone:"primary"}),e.jsx(N,{className:"h-72 p-4",children:e.jsx(W,{width:"100%",height:"100%",children:e.jsxs(De,{data:a,margin:{left:-10,top:6},children:[e.jsx(Pe,{strokeDasharray:"3 3",stroke:"var(--border)",vertical:!1}),e.jsx(Se,{dataKey:"month",tick:{fontSize:11},stroke:"var(--muted-foreground)",tickLine:!1,axisLine:!1}),e.jsx(Re,{tick:{fontSize:11},stroke:"var(--muted-foreground)",tickLine:!1,axisLine:!1,tickFormatter:t=>t>=1e3?`${Math.round(t/1e3)}k`:`${t}`}),e.jsx(U,{formatter:t=>l(t),contentStyle:G,cursor:{fill:"var(--muted)",opacity:.35}}),e.jsx(Be,{wrapperStyle:{fontSize:12},iconType:"circle"}),e.jsx(Y,{dataKey:"Revenue",fill:"#6366f1",radius:[6,6,0,0],maxBarSize:26}),e.jsx(Y,{dataKey:"Expense",fill:"#f43f5e",radius:[6,6,0,0],maxBarSize:26}),e.jsx(Ee,{type:"monotone",dataKey:"Net",stroke:"#10b981",strokeWidth:2.5,dot:{r:3,fill:"#10b981",strokeWidth:0},activeDot:{r:5}})]})})})]}),e.jsxs(j,{className:"lg:col-span-4 min-w-0 border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx(H,{className:"size-3.5"}),title:"Expense breakdown",tone:"violet"}),e.jsx(N,{className:"p-4",children:s.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-16",children:"No expenses in range"}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-40",children:e.jsx(W,{width:"100%",height:"100%",children:e.jsxs(Fe,{children:[e.jsx(Ie,{data:s,dataKey:"value",nameKey:"name",innerRadius:44,outerRadius:70,paddingAngle:3,stroke:"var(--card)",strokeWidth:2,children:s.map((t,i)=>e.jsx($e,{fill:L[i%L.length]},i))}),e.jsx(U,{formatter:t=>l(t),contentStyle:G})]})})}),e.jsx("div",{className:"mt-2 space-y-1.5",children:s.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-[11.5px]",children:[e.jsx("span",{className:"size-2 roun
1ded-full shrink-0",style:{background:L[i%L.length]}}),e.jsx("span",{className:"truncate text-muted-foreground",children:t.name}),e.jsx("span",{className:"ml-auto tabular-nums font-medium",children:l(t.value)}),e.jsx("span",{className:"tabular-nums text-muted-foreground w-10 text-right",children:r>0?`${(t.value/r*100).toFixed(0)}%`:"â"})]},t.name))})]})})]})]})}function rs(){const n=[{to:"/erp/finance/accounts",label:"Accounts",icon:e.jsx(R,{className:"size-3.5"})},{to:"/erp/finance/receivables",label:"Receivables",icon:e.jsx($,{className:"size-3.5"})},{to:"/erp/finance/journal",label:"Journal",icon:e.jsx(qe,{className:"size-3.5"})},{to:"/erp/finance/dollar-purchase",label:"Dollar Purchase",icon:e.jsx(O,{className:"size-3.5"})},{to:"/erp/finance/reports",label:"Reports",icon:e.jsx(F,{className:"size-3.5"})},{to:"/erp/finance/budgets",label:"Budgets",icon:e.jsx(V,{className:"size-3.5"})},{to:"/erp/finance/taxes",label:"Taxes",icon:e.jsx(Ke,{className:"size-3.5"})}];return e.jsx("nav",{className:"-mx-1 flex gap-2 overflow-x-auto px-1 pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:n.map(a=>e.jsxs(T,{to:a.to,className:"group shrink-0 rounded-full border border-border/60 bg-card hover:bg-muted/50 hover:border-foreground
1/20 transition-all pl-1.5 pr-3 py-1.5 text-[11.5px] flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full p-1.5 bg-muted text-foreground/70 transition group-hover:bg-primary/10 group-hover:text-primary",children:a.icon}),e.jsx("span",{className:"font-medium whitespace-nowrap",children:a.label})]},a.to))})}function ns({data:n}){return n.recentTxns.length===0?null:e.jsxs(j,{className:"border-border/60 overflow-hidden p-0",children:[e.jsx(_,{icon:e.jsx(F,{className:"size-3.5"}),title:"Recent transactions",tone:"slate",action:e.jsxs(T,{to:"/erp/finance/journal",className:"text-[11px] font-medium text-primary inline-flex items-center gap-1 hover:gap-2 transition-all",children:["View journal ",e.jsx(E,{className:"size-3"})]})}),e.jsx(N,{className:"p-0",children:e.jsx("div",{className:"divide-y divide-border/50",children:n.recentTxns.map(a=>e.jsxs("div",{className:"group relative flex items-center gap-3 px-4 py-2.5 text-[13px] hover:bg-muted/40 transition",children:[e.jsx("span",{className:p("absolute left-0 top-0 h-full w-0.5",a.type==="income"?"bg-emerald-500":a.type==="expense"?"bg-rose-500":"bg-slate-400"),"aria-hidden":!0}),e.jsx(P,{variant:"outline",className:p("text-[10px] capitalize border-0 font-semibold",a.type==="income"&&"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",a.type==="expense"&&"bg-rose-500/10 text-rose-700 dark:text-rose-400",a.type!=="income"&&a.type!=="expense"&&"bg-muted text-muted-foreground"),children:a.type}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:a.description||e.jsx("span",{className:"text-muted-foreground font-normal",children:"â"})}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[a.date,a.account&&` · ${a.account}`,a.category&&` · ${a.category}`]})]}),e.jsxs("div",{className:p("tabular-nums font-bold",a.type==="income"&&"text-emerald-600 dark:text-emerald-400",a.type==="expense"&&"text-rose-600 dar
1k:text-rose-400"),children:[a.type==="expense"?"-":a.type==="income"?"+":"",l(a.amount)]})]},a.id))})})]})}export{Bt as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.