PageSourceSearch

https://www.menubrain.ai/assets/js/BalanceSheetPage-BnIIPOKu.js

js menubrain.ai collected 2026-10-05 13:31:09 UTC 19,199 bytes, 2 lines download raw bytes

1!function(){try{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{}).SENTRY_RELEASE={id:"3d629276bea5e88869c8100128741c6d108b87d4"}}catch(e){}}();try{e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},(s=(new e.Error).stack)&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="74845b46-be41-4ea0-b361-70a212bb4e87",e._sentryDebugIdIdentifier="sentry-dbid-74845b46-be41-4ea0-b361-70a212bb4e87")}catch(e){}var e,s;import{j as t}from"./ui-vendor-CzcNn6SD.js";import{r as a}from"./react-vendor-BRXY0zL1.js";import{s as n,a0 as i,b6 as l,B as r,a1 as o,a2 as d,a3 as c,L as m,n as u,r as x,t as p,v as h,w as f,I as b,h as j,$ as y,C as N,H as g,J as v,j as w,al as L,am as C,an as q,ao as E,k as S}from"./onboarding-CryYNyDg.js";import{u as A,a as I}from"./query-vendor-DrUFZEd1.js";import{C as T,a as _,b as D}from"./collapsible-DkHwycYQ.js";import{k as O,bD as k,C as F}from"./vendor-misc-BHwpSTVC.js";import{T as $,h as M,a as B}from"./dashboard-BVpi9SDK.js";import"./supabase-vendor-BrPA4caR.js";const Y=({subsection:e,onSuccess:s})=>{const[N,g]=a.useState(!1),[v,w]=a.useState(!1),[L,C]=a.useState({item_type:"",description:"",amount:"",date:(new Date).toISOString().split("T")[0]});return t.jsxs(i,{open:N,onOpenChange:g,children:[t.jsx(l,{asChild:!0,children:t.jsxs(r,{variant:"outline",size:"sm",children:[t.jsx(O,{className:"h-4 w-4 mr-2"}),"Add ",e]})}),t.jsxs(o,{children:[t.jsx(d,{children:t.jsxs(c,{children:["Add ",e," Item"]})}),t.jsxs("form",{onSubmit:async t=>{t.preventDefault(),w(!0);try{const t=await j();if(!t)return void y.error("Company not found");const{error:a}=await n.from("balance_sheet_items").insert({company_id:t,subsection:e,item_type:L.item_type,description:L.description,amount:parseFloat(L.amount),date:L.date});if(a)throw a;y.success(`${e} item added successfully`),g(!1),C({item_type:"",description:"",amount:"",date:(new Date).toISOString().split("T")[0]}),s()}catch(a){y.error("Failed to add item")}finally{w(!1)}},className:"space-y-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(m,{htmlFor:"item_type",children:"Type"}),t.jsxs(u,{value:L.item_type,onValueChange:e=>C({...L,item_type:e}),children:[t.jsx(x,{children:t.jsx(p,{placeholder:"Select type"})}),t.jsx(h,{children:(()=>{switch(e){case"Assets":return["Cash","Accounts Receivable","Inventory","Equipment","Property","Other Assets"];case"Liabilities":return["Accounts Payable","Loans Payable","Credit Card Debt","Accrued Expenses","Other Liabilities"];case"Equity":return["Owner's Capital","Retained Earnings","Drawings","Other Equity"];default:return[]}})().map(e=>t.jsx(f,{value:e,children:e},e))})]})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(m,{htmlFor:"description",children:"Description"}),t.jsx(b,{id:"description",value:L.description,onChange:e=>C({...L,description:e.target.value}),placeholder:"Enter description",required:!0})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(m,{htmlFor:"amount",children:"Amount"}),t.jsx(b,{id:"amount",type:"number",step:"0.01",value:L.amount,onChange:e=>C({...L,amount:e.target.value}),placeholder:"0.00",required:!0})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(m,{htmlFor:"date",children:"Date"}),t.jsx(b,{id:"date",type:"date",value:L.date,onChange:e=>C({...L,date:e.target.value}),required:!0})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(r,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),t.jsx(r,{type:"submit",disabled:v,children:v?"Adding...":"Add Item"})]})]})]})]})},J=["January","February","March","April","May","June","July","August","September","October","November","December"],R=()=>{const e=M(B);return{preset:B,startDate:e.start,endDate:e.end}},P=()=>{const e=I(),[s,i]=a.useState(),[l,o]=a.useState(R),[d,c]=a.useState(()=>{const e=localStorage.getItem("balance-sheet-selected-months");return e?JSON.parse(e):(()=>{const e=new Date,s=[];for(let t=2;t>=0;t--){const a=new Date(e.getFullYear(),e.getMonth()-t,1),n=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0");s.push(`${n}-${i}`)}return s})()}),m=()=>
1{e.invalidateQueries({queryKey:["real-balance-sheet"]})};a.useEffect(()=>{j().then(i)},[]),a.useEffect(()=>{localStorage.setItem("balance-sheet-selected-months",JSON.stringify(d))},[d]);const u=(()=>{const e=(new Date).getFullYear();return Array.from({length:12},(s,t)=>{const a=String(t+1).padStart(2,"0");return`${e}-${a}`})})(),x=d.length>0?d:u,p=x.length>0?`${x[0]}-01`:`${(new Date).getFullYear()}-01-01`,h=x.length>0?(()=>{const e=x[x.length-1],[s,t]=e.split("-");return`${e}-${new Date(parseInt(s),parseInt(t),0).getDate()}`})():(new Date).toISOString().split("T")[0],{data:f,isLoading:b}=((e,s,t)=>A({queryKey:["real-balance-sheet",e,s,t],queryFn:async()=>{if(!e)return null;const[a,i,l]=await Promise.all([n.from("bank_statements").select("*").eq("company_id",e).gte("transaction_date",s).lte("transaction_date",t),n.from("balance_sheet_items").select("*").eq("company_id",e).gte("date",s).lte("date",t),n.from("bank_accounts").select("*").eq("company_id",e).eq("is_active",!0)]),r=a.data,o=i.data,d=l.data;if(!r&&!o&&!d)return null;const c=new Map,m=(null==r?void 0:r.filter(e=>{var s,t;return"balance sheet"===(null==(s=e.category)?void 0:s.toLowerCase())&&"assets"===(null==(t=e.bucket)?void 0:t.toLowerCase())}))||[],u=new Map;m.forEach(e=>{const s=e.type||"Other Assets",t=u.get(s),a=e.transaction_date||"";(!t||a>t.date)&&u.set(s,{amount:Number(e.amount),date:a})}),u.forEach(({amount:e},s)=>{c.set(s,(c.get(s)||0)+e)});const x=(null==o?void 0:o.filter(e=>{var s;return"assets"===(null==(s=e.subsection)?void 0:s.toLowerCase())}))||[],p=new Map;x.forEach(e=>{const s=e.item_type||"Other Assets",t=p.get(s),a=e.date||"";(!t||a>t.date)&&p.set(s,{amount:Number(e.amount),date:a})}),p.forEach(({amount:e},s)=>{c.set(s,(c.get(s)||0)+e)});const h=(d||[]).reduce((e,s)=>e+(Number(s.current_balance)||0),0);h>0&&c.set("Cash and Bank Accounts",(c.get("Cash and Bank Accounts")||0)+h);const f=Array.from(c.entries()).map(([e,s])=>({type:e,amount:s})),b=f.reduce((e,s)=>e+s.amount,0),j=new Map,y=(null==r?void 0:r.filter(e=>{var s,t,a;return"balance sheet"===(null==(s=e.category)?void 0:s.toLowerCase())&&("debt service"===(null==(t=e.bucket)?void 0:t.toLowerCase())||"liabilities"===(null==(a=e.bucket)?void 0:a.toLowerCase()))}))||[],N=new Map;y.forEach(e=>{const s=e.type||"Other Liabilities",t=N.get(s),a=e.transaction_date||"";(!t||a>t.date)&&N.set(s,{amount:Math.abs(Number(e.amount)),date:a})}),N.forEach(({amount:e},s)=>{j.set(s,(j.get(s)||0)+e)});const g=(null==o?void 0:o.filter(e=>{var s;return"liabilities"===(null==(s=e.subsection)?void 0:s.toLowerCase())}))||[],v=new Map;g.forEach(e=>{const s=e.item_type||"Other Liabilities",t=v.get(s),a=e.date||"";(!t||a>t.date)&&v.set(s,{amount:Number(e.amount),date:a})}),v.forEach(({amount:e},s)=>{j.set(s,(j.get(s)||0)+e)});const w=Array.from(j.entries()).map(([e,s])=>({type:e,amount:s})),L=w.reduce((e,s)=>e+s.amount,0);return{assets:{items:f,totalAssets:b},liabilities:{items:w,totalLiabilities:L},equity:{totalEquity:b-L}}},enabled:!!e}))(s,p,h),y=e=>{const[,s]=e.split("-");return J[parseInt(s)-1]},O=()=>t.jsx(S,{className:"h-6 w-24 inline-block"}),M=e=>b?t.jsx(O,{}):(e=>{const s=Math.abs(e).toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0});return e<0?`($${s})`:`$${s}`})(e);if(!f&&!b)return t.jsx("div",{className:"flex items-center justify-center h-96",children:t.jsx("div",{className:"text-muted-foreground",children:"No balance sheet data available"})});const B=f||{assets:{items:[],totalAssets:0},liabilities:{items:[],totalLiabilities:0},equity:{totalEquity:0}},P=B.assets.items.filter(e=>e.type.toLowerCase().includes("cash")||e.type.toLowerCase().includes("receivable")||e.type.toLowerCase().includes("inventory")||e.type.toLowerCase().includes("prepaid")),U=B.assets.items.filter(e=>e.type.toLowerCase().includes("equipment")||e.type.toLowerCase().includes("property")||e.type.toLowerCase().includes("ppe")||e.type.toLowerCase().includes("intangible")||e.type.toLowerCase().includes("long-term")),z=P.reduce((e,s)=>e+s.amount,0),Q=U.reduce((e,s)=>e+s.amount,0),K=B.liabilities.items.filter(e=>e.type.toLowerCase().includes("payable")||e.type.toLowerCase().includes("accrued")||e.type.toLowerCase().includes("current")),V=B.liabilities.items.filter(e=>e.type.toLowerCase().includes("long-term")||e.type.toLowerCase().includes("debt")||e.type.toLowerCase().includes("loan")),H=K.reduce((e,s)=>e+s.amount,0),G=V.reduce((e,s)=>e+s.amount,0),W=Math.abs(B.assets.totalAssets-(B.liabilities.totalLiabilities+B.equity.totalEquity))<1;return t.jsxs("div",{className:"p-6 space-y-6",children:[t.jsxs("div",{className:"flex flex-wrap justify-between items-start gap-4",children:[t.jsxs("div",{children:[t.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[t.jsx(k,{className:"h-8 w-8"}),"Balance Sheet"]}),t.jsx("p",{className:"text-muted-foreground mt-1",children:x.length>0?`As of ${y(x[x.length-1])} ${(new Date).getFullYear()}`:"No data"})]}
1),t.jsx($,{value:l,onChange:o})]}),t.jsxs(N,{children:[t.jsx(g,{children:t.jsx(v,{className:"text-base",children:"Select Months"})}),t.jsxs(w,{children:[t.jsx("div",{className:"flex flex-wrap gap-2 mb-3",children:u.map(e=>t.jsx(r,{variant:d.includes(e)?"default":"outline",size:"sm",onClick:()=>(e=>{c(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e].sort())})(e),className:"min-w-[80px]",children:y(e)},e))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(r,{onClick:()=>{c(u)},variant:"secondary",size:"sm",children:"Select YTD"}),t.jsx(r,{onClick:()=>{c([])},variant:"outline",size:"sm",children:"Clear Selection"})]})]})]}),t.jsxs(N,{children:[t.jsx(g,{children:t.jsx(v,{className:"text-2xl",children:"Financial Position"})}),t.jsxs(w,{children:[t.jsxs(L,{type:"multiple",defaultValue:["assets","liabilities","equity"],className:"space-y-2",children:[t.jsxs(C,{value:"assets",className:"border rounded-lg px-4 bg-card",children:[t.jsx(q,{className:"hover:no-underline py-4",children:t.jsxs("div",{className:"flex justify-between items-center w-full pr-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"font-bold text-xl text-primary",children:"ASSETS"}),t.jsx(Y,{subsection:"Assets",onSuccess:m})]}),t.jsx("span",{className:"font-bold text-xl text-profit",children:M(B.assets.totalAssets)})]})}),t.jsxs(E,{className:"space-y-3 pb-4",children:[t.jsxs(T,{defaultOpen:!0,children:[t.jsx(_,{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-green-50/50 px-4 py-3 hover:bg-green-50/70 transition-colors",children:[t.jsx(F,{className:"h-4 w-4 transition-transform duration-200"}),t.jsxs("div",{className:"flex-1 flex justify-between",children:[t.jsx("span",{className:"font-semibold",children:"Current Assets"}),t.jsx("span",{className:"font-semibold text-profit",children:M(z)})]})]})}),t.jsxs(D,{className:"pl-8 pt-2 space-y-1",children:[P.length>0?P.map((e,s)=>t.jsxs("div",{className:"flex justify-between text-sm py-1",children:[t.jsx("span",{className:"text-muted-foreground",children:e.type}),t.jsx("span",{className:"font-medium min-w-[100px] text-right",children:M(e.amount)})]},s)):t.jsx("div",{className:"text-xs text-muted-foreground",children:"No current assets recorded"}),t.jsxs("div",{className:"flex justify-between text-sm py-2 border-t mt-2",children:[t.jsx("span",{className:"font-semibold",children:"Total Current Assets"}),t.jsx("span",{className:"font-semibold",children:M(z)})]})]})]}),t.jsxs(T,{defaultOpen:!0,children:[t.jsx(_,{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-emerald-50/50 px-4 py-3 hover:bg-emerald-50/70 transition-colors",children:[t.jsx(F,{className:"h-4 w-4 transition-transform duration-200"}),t.jsxs("div",{className:"flex-1 flex justify-between",children:[t.jsx("span",{className:"font-semibold",children:"Non-Current Assets"}),t.jsx("span",{className:"font-semibold text-profit",children:M(Q)})]})]})}),t.jsxs(D,{className:"pl-8 pt-2 space-y-1",children:[U.length>0?U.map((e,s)=>t.jsxs("div",{className:"flex justify-between text-sm py-1",children:[t.jsx("span",{className:"text-muted-foreground",children:e.type}),t.jsx("span",{className:"font-medium min-w-[100px] text-right",children:M(e.amount)})]},s)):t.jsx("div",{className:"text-xs text-muted-foreground",children:"No non-current assets recorded"}),t.jsxs("div",{className:"flex justify-between text-sm py-2 border-t mt-2",children:[t.jsx("span",{className:"font-semibold",children:"Total Non-Current Assets"}),t.jsx("span",{className:"font-semibold",children:M(Q)})]})]})]}),t.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-t mt-2 pt-3 bg-slate-100 rounded-md",children:[t.jsx("span",{className:"font-bold text-lg",children:"TOTAL ASSETS"}),t.jsx("span",{className:"font-bold text-lg text-profit",children:M(B.assets.totalAssets)})]})]})]}),t.jsxs(C,{value:"liabilities",className:"border rounded-lg px-4 bg-card",children:[t.jsx(q,{className:"hover:no-underline py-4",children:t.jsxs("div",{className:"flex justify-between items-center w-full pr-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"font-bold text-xl text-primary",children:"LIABILITIES"}),t.jsx(Y,{subsection:"Liabilities",onSuccess:m})]}),t.jsx("span",{className:"font-bold text-xl text-loss",children:M(B.liabilities.totalLiabilities)})]})}),t.jsxs(E,{className:"space-y-3 pb-4",children:[t.jsxs(T,{defaultOpen:!0,children:[t.jsx(_,{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-red-50/50 px-4 py-3 hover:bg-red-50/70 transition-colors",children:[t.jsx(F,{className:"h-4 w-4 transition-transform duration-200"}),t.jsxs("div",{className:"flex-1 flex justify-between",children:[t.jsx("span",{className:"font-semibold",children:"Current Liabilities"}),t.jsx("span",{className:"font-semibold text-loss",children:M(H)})]})]})}),t.jsxs(D,{className:"pl-8 pt-2 space-y-1",children:[K.length>0?K.map((e,s)=>t.jsxs("div",{className:"flex justify-between text-sm py-1",children:[t.jsx("span",{className:"text-muted-foreground",children:e.type}),t.jsx("span",{className:"font-medium min-w-[100px] text-right",children:M(e.amount)})]},s)):t.jsx("div",{className:"text-xs text-muted-foreground",children:"No current liabilities recorded"}),t.jsxs("div",{className:"flex justify-between text-sm py-2 border-t mt
1-2",children:[t.jsx("span",{className:"font-semibold",children:"Total Current Liabilities"}),t.jsx("span",{className:"font-semibold",children:M(H)})]})]})]}),t.jsxs(T,{defaultOpen:!0,children:[t.jsx(_,{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-rose-50/50 px-4 py-3 hover:bg-rose-50/70 transition-colors",children:[t.jsx(F,{className:"h-4 w-4 transition-transform duration-200"}),t.jsxs("div",{className:"flex-1 flex justify-between",children:[t.jsx("span",{className:"font-semibold",children:"Non-Current Liabilities"}),t.jsx("span",{className:"font-semibold text-loss",children:M(G)})]})]})}),t.jsxs(D,{className:"pl-8 pt-2 space-y-1",children:[V.length>0?V.map((e,s)=>t.jsxs("div",{className:"flex justify-between text-sm py-1",children:[t.jsx("span",{className:"text-muted-foreground",children:e.type}),t.jsx("span",{className:"font-medium min-w-[100px] text-right",children:M(e.amount)})]},s)):t.jsx("div",{className:"text-xs text-muted-foreground",children:"No non-current liabilities recorded"}),t.jsxs("div",{className:"flex justify-between text-sm py-2 border-t mt-2",children:[t.jsx("span",{className:"font-semibold",children:"Total Non-Current Liabilities"}),t.jsx("span",{className:"font-semibold",children:M(G)})]})]})]}),t.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-t mt-2 pt-3 bg-slate-100 rounded-md",children:[t.jsx("span",{className:"font-bold text-lg",children:"TOTAL LIABILITIES"}),t.jsx("span",{className:"font-bold text-lg text-loss",children:M(B.liabilities.totalLiabilities)})]})]})]}),t.jsxs(C,{value:"equity",className:"border rounded-lg px-4 bg-card",children:[t.jsx(q,{className:"hover:no-underline py-4",children:t.jsxs("div",{className:"flex justify-between items-center w-full pr-4",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("h3",{className:"font-bold text-xl text-primary",children:"EQUITY"}),t.jsx(Y,{subsection:"Equity",onSuccess:m})]}),t.jsx("span",{className:"font-bold text-xl "+(B.equity.totalEquity>=0?"text-profit":"text-loss"),children:M(B.equity.totalEquity)})]})}),t.jsxs(E,{className:"space-y-3 pb-4",children:[t.jsxs(T,{defaultOpen:!0,children:[t.jsx(_,{className:"w-full",children:t.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-blue-50/50 px-4 py-3 hover:bg-blue-50/70 transition-colors",children:[t.jsx(F,{className:"h-4 w-4 transition-transform duration-200"}),t.jsxs("div",{className:"flex-1 flex justify-between",children:[t.jsx("span",{className:"font-semibold",children:"Owner's Equity"}),t.jsx("span",{className:"font-semibold "+(B.equity.totalEquity>=0?"text-profit":"text-loss"),children:M(B.equity.totalEquity)})]})]})}),t.jsxs(D,{className:"pl-8 pt-2 space-y-1",children:[t.jsxs("div",{className:"flex justify-between text-sm py-1",children:[t.jsx("span",{className:"text-muted-foreground",children:"Retained Earnings (Assets - Liabilities)"}),t.jsx("span",{className:"font-medium "+(B.equity.totalEquity>=0?"text-profit":"text-loss"),children:M(B.equity.totalEquity)})]}),t.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:"Represents the cumulative net income retained in the business"})]})]}),t.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-t mt-2 pt-3 bg-slate-100 rounded-md",children:[t.jsx("span",{className:"font-bold text-lg",children:"TOTAL EQUITY"}),t.jsx("span",{className:"font-bold text-lg "+(B.equity.totalEquity>=0?"text-profit":"text-loss"),children:M(B.equity.totalEquity)})]})]})]})]}),t.jsxs("div",{className:"mt-4 flex justify-between items-center px-4 py-3 bg-slate-200 rounded-md border-2 border-double",children:[t.jsx("span",{className:"font-bold text-xl",children:"TOTAL LIABILITIES & EQUITY"}),t.jsx("span",{className:"font-bold text-xl",children:M(B.liabilities.totalLiabilities+B.equity.totalEquity)})]}),t.jsxs("div",{className:"mt-6 p-4 rounded-lg bg-muted/30 border",children:[t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsx("span",{className:"font-semibold",children:"Balance Check:"}),t.jsx("span",{className:"font-bold "+(W?"text-profit":"text-loss"),children:W?"✓ Balanced":"✗ Not Balanced"})]}),t.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:"Assets = Liabilities + Equity"}),t.jsxs("div",{className:"text-sm text-muted-foreground",children:[M(B.assets.totalAssets)," = ",M(B.liabilities.totalLiabilities)," + ",M(B.equity.totalEquity)]})]})]})]})]})};export{P as BalanceSheetPage};
2//# sourceMappingURL=BalanceSheetPage-BnIIPOKu.js.map

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.