@burdenoff/microfe-healthybowl 2026.714.7 → 2026.714.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/healthybowl/HealthyBowlRoutes.js +99 -75
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlAccounting.js +316 -0
- package/dist/healthybowl/hooks/useHealthyBowlAccounting.js.map +1 -0
- package/dist/healthybowl/pages/financial/AccountingIntegrationsPage.js +297 -0
- package/dist/healthybowl/pages/financial/AccountingIntegrationsPage.js.map +1 -0
- package/dist/healthybowl/pages/financial/ChartOfAccountsPage.js +233 -0
- package/dist/healthybowl/pages/financial/ChartOfAccountsPage.js.map +1 -0
- package/dist/healthybowl/pages/financial/CostByCropPage.js +365 -0
- package/dist/healthybowl/pages/financial/CostByCropPage.js.map +1 -0
- package/dist/healthybowl/pages/financial/FarmAccountingPage.js +384 -0
- package/dist/healthybowl/pages/financial/FarmAccountingPage.js.map +1 -0
- package/dist/healthybowl/pages/financial/FinancialDashboardPage.js +32 -16
- package/dist/healthybowl/pages/financial/FinancialDashboardPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/GeneralLedgerPage.js +221 -0
- package/dist/healthybowl/pages/financial/GeneralLedgerPage.js.map +1 -0
- package/dist/healthybowl/pages/financial/JournalEntryModal.js +261 -0
- package/dist/healthybowl/pages/financial/JournalEntryModal.js.map +1 -0
- package/dist/healthybowl/pages/financial/ProfitLossPage.js +202 -0
- package/dist/healthybowl/pages/financial/ProfitLossPage.js.map +1 -0
- package/dist/healthybowl/utils/download.js +11 -0
- package/dist/healthybowl/utils/download.js.map +1 -0
- package/dist/healthybowl/utils/helpers.js +11 -8
- package/dist/healthybowl/utils/helpers.js.map +1 -1
- package/dist/healthybowl/utils/period.js +15 -0
- package/dist/healthybowl/utils/period.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { formatCurrency as e, todayLocalDate as t } from "../../utils/helpers.js";
|
|
2
|
+
import { Modal as n } from "../../components/Modal.js";
|
|
3
|
+
import "../../components/index.js";
|
|
4
|
+
import { useMemo as r, useState as i } from "react";
|
|
5
|
+
import { jsx as a, jsxs as o } from "react/jsx-runtime";
|
|
6
|
+
import { Button as s } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
//#region src/healthybowl/pages/financial/JournalEntryModal.tsx
|
|
8
|
+
var c = "h-9 w-full rounded-md border border-border-subtle bg-bg-surface px-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]", l = () => ({
|
|
9
|
+
accountId: "",
|
|
10
|
+
description: "",
|
|
11
|
+
debit: "",
|
|
12
|
+
credit: "",
|
|
13
|
+
costCenterId: ""
|
|
14
|
+
});
|
|
15
|
+
function u({ open: u, onClose: d, accounts: f, costCenters: p, onPost: m, onSaveDraft: h, onSuccess: g, onError: _ }) {
|
|
16
|
+
let [v, y] = i(t()), [b, x] = i(""), [S, C] = i(""), [w, T] = i([l(), l()]), [E, D] = i(!1), O = r(() => {
|
|
17
|
+
let e = w.reduce((e, t) => e + (parseFloat(t.debit) || 0), 0), t = w.reduce((e, t) => e + (parseFloat(t.credit) || 0), 0);
|
|
18
|
+
return {
|
|
19
|
+
debit: Math.round(e * 100) / 100,
|
|
20
|
+
credit: Math.round(t * 100) / 100
|
|
21
|
+
};
|
|
22
|
+
}, [w]), k = Math.abs(O.debit - O.credit) < .005 && O.debit > 0, A = () => {
|
|
23
|
+
y(t()), x(""), C(""), T([l(), l()]);
|
|
24
|
+
}, j = (e, t) => T((n) => n.map((n, r) => r === e ? {
|
|
25
|
+
...n,
|
|
26
|
+
...t
|
|
27
|
+
} : n)), M = () => w.filter((e) => e.accountId && (parseFloat(e.debit) > 0 || parseFloat(e.credit) > 0)).map((e) => ({
|
|
28
|
+
accountId: e.accountId,
|
|
29
|
+
description: e.description || null,
|
|
30
|
+
debit: parseFloat(e.debit) || 0,
|
|
31
|
+
credit: parseFloat(e.credit) || 0,
|
|
32
|
+
costCenterId: e.costCenterId || null
|
|
33
|
+
})), N = async (e) => {
|
|
34
|
+
if (!S.trim()) {
|
|
35
|
+
_("A memo / description is required.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let t = M();
|
|
39
|
+
if (t.length < 2) {
|
|
40
|
+
_("Add at least two lines with an account and an amount.");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
D(!0);
|
|
44
|
+
try {
|
|
45
|
+
let n = {
|
|
46
|
+
date: v,
|
|
47
|
+
memo: S.trim(),
|
|
48
|
+
reference: b.trim() || null,
|
|
49
|
+
lines: t
|
|
50
|
+
};
|
|
51
|
+
e ? (await h(n), g("Draft journal entry saved.")) : (await m(n), g("Journal entry posted.")), A(), d();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
_(e instanceof Error ? e.message : "Failed to save the journal entry.");
|
|
54
|
+
} finally {
|
|
55
|
+
D(!1);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return /* @__PURE__ */ a(n, {
|
|
59
|
+
open: u,
|
|
60
|
+
onClose: d,
|
|
61
|
+
title: "New Journal Entry",
|
|
62
|
+
description: "Double-entry — debits must equal credits",
|
|
63
|
+
size: "xl",
|
|
64
|
+
footer: /* @__PURE__ */ o("div", {
|
|
65
|
+
className: "flex w-full items-center justify-between gap-3",
|
|
66
|
+
children: [/* @__PURE__ */ o("div", {
|
|
67
|
+
className: "flex items-center gap-4 text-sm",
|
|
68
|
+
children: [/* @__PURE__ */ o("span", {
|
|
69
|
+
className: "text-text-secondary",
|
|
70
|
+
children: [
|
|
71
|
+
"Debits ",
|
|
72
|
+
/* @__PURE__ */ a("span", {
|
|
73
|
+
className: "font-semibold text-text-primary",
|
|
74
|
+
children: e(O.debit, "INR")
|
|
75
|
+
}),
|
|
76
|
+
" = Credits ",
|
|
77
|
+
/* @__PURE__ */ a("span", {
|
|
78
|
+
className: "font-semibold text-text-primary",
|
|
79
|
+
children: e(O.credit, "INR")
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
}), /* @__PURE__ */ a("span", {
|
|
83
|
+
className: k ? "font-semibold text-success" : "font-semibold text-destructive",
|
|
84
|
+
children: k ? "● Balanced" : "● Not balanced"
|
|
85
|
+
})]
|
|
86
|
+
}), /* @__PURE__ */ o("div", {
|
|
87
|
+
className: "flex gap-2",
|
|
88
|
+
children: [/* @__PURE__ */ a(s, {
|
|
89
|
+
variant: "outline",
|
|
90
|
+
onClick: () => N(!0),
|
|
91
|
+
disabled: E,
|
|
92
|
+
children: "Save Draft"
|
|
93
|
+
}), /* @__PURE__ */ a(s, {
|
|
94
|
+
onClick: () => N(!1),
|
|
95
|
+
disabled: E || !k,
|
|
96
|
+
children: "Post Entry"
|
|
97
|
+
})]
|
|
98
|
+
})]
|
|
99
|
+
}),
|
|
100
|
+
children: /* @__PURE__ */ o("div", {
|
|
101
|
+
className: "space-y-4",
|
|
102
|
+
children: [
|
|
103
|
+
/* @__PURE__ */ o("div", {
|
|
104
|
+
className: "grid grid-cols-1 gap-3 sm:grid-cols-3",
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ o("label", {
|
|
107
|
+
className: "text-sm",
|
|
108
|
+
children: [/* @__PURE__ */ a("span", {
|
|
109
|
+
className: "mb-1 block text-text-secondary",
|
|
110
|
+
children: "Date"
|
|
111
|
+
}), /* @__PURE__ */ a("input", {
|
|
112
|
+
type: "date",
|
|
113
|
+
value: v,
|
|
114
|
+
onChange: (e) => y(e.target.value),
|
|
115
|
+
className: c
|
|
116
|
+
})]
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ o("label", {
|
|
119
|
+
className: "text-sm",
|
|
120
|
+
children: [/* @__PURE__ */ a("span", {
|
|
121
|
+
className: "mb-1 block text-text-secondary",
|
|
122
|
+
children: "Reference No."
|
|
123
|
+
}), /* @__PURE__ */ a("input", {
|
|
124
|
+
value: b,
|
|
125
|
+
onChange: (e) => x(e.target.value),
|
|
126
|
+
placeholder: "e.g. INV-2231",
|
|
127
|
+
className: c
|
|
128
|
+
})]
|
|
129
|
+
}),
|
|
130
|
+
/* @__PURE__ */ o("label", {
|
|
131
|
+
className: "text-sm sm:col-span-1",
|
|
132
|
+
children: [/* @__PURE__ */ a("span", {
|
|
133
|
+
className: "mb-1 block text-text-secondary",
|
|
134
|
+
children: "Memo / Description"
|
|
135
|
+
}), /* @__PURE__ */ a("input", {
|
|
136
|
+
value: S,
|
|
137
|
+
onChange: (e) => C(e.target.value),
|
|
138
|
+
placeholder: "Feed purchase for dairy herd",
|
|
139
|
+
className: c
|
|
140
|
+
})]
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ a("div", {
|
|
145
|
+
className: "overflow-x-auto rounded-lg border border-border-subtle",
|
|
146
|
+
children: /* @__PURE__ */ o("table", {
|
|
147
|
+
className: "w-full min-w-[640px] text-sm",
|
|
148
|
+
children: [/* @__PURE__ */ a("thead", {
|
|
149
|
+
className: "bg-bg-sunken/50 text-left text-text-secondary",
|
|
150
|
+
children: /* @__PURE__ */ o("tr", { children: [
|
|
151
|
+
/* @__PURE__ */ a("th", {
|
|
152
|
+
className: "px-3 py-2 font-medium",
|
|
153
|
+
children: "Account"
|
|
154
|
+
}),
|
|
155
|
+
/* @__PURE__ */ a("th", {
|
|
156
|
+
className: "px-3 py-2 font-medium",
|
|
157
|
+
children: "Cost Center (Crop/Animal)"
|
|
158
|
+
}),
|
|
159
|
+
/* @__PURE__ */ a("th", {
|
|
160
|
+
className: "px-3 py-2 text-right font-medium",
|
|
161
|
+
children: "Debit (₹)"
|
|
162
|
+
}),
|
|
163
|
+
/* @__PURE__ */ a("th", {
|
|
164
|
+
className: "px-3 py-2 text-right font-medium",
|
|
165
|
+
children: "Credit (₹)"
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ a("th", { className: "px-2 py-2" })
|
|
168
|
+
] })
|
|
169
|
+
}), /* @__PURE__ */ a("tbody", { children: w.map((e, t) => /* @__PURE__ */ o("tr", {
|
|
170
|
+
className: "border-t border-border-subtle",
|
|
171
|
+
children: [
|
|
172
|
+
/* @__PURE__ */ a("td", {
|
|
173
|
+
className: "px-3 py-2",
|
|
174
|
+
children: /* @__PURE__ */ o("select", {
|
|
175
|
+
value: e.accountId,
|
|
176
|
+
onChange: (e) => j(t, { accountId: e.target.value }),
|
|
177
|
+
className: c,
|
|
178
|
+
children: [/* @__PURE__ */ a("option", {
|
|
179
|
+
value: "",
|
|
180
|
+
children: "Select account…"
|
|
181
|
+
}), f.filter((e) => e.isActive).map((e) => /* @__PURE__ */ o("option", {
|
|
182
|
+
value: e.id,
|
|
183
|
+
children: [
|
|
184
|
+
e.code,
|
|
185
|
+
" · ",
|
|
186
|
+
e.name
|
|
187
|
+
]
|
|
188
|
+
}, e.id))]
|
|
189
|
+
})
|
|
190
|
+
}),
|
|
191
|
+
/* @__PURE__ */ a("td", {
|
|
192
|
+
className: "px-3 py-2",
|
|
193
|
+
children: /* @__PURE__ */ o("select", {
|
|
194
|
+
value: e.costCenterId,
|
|
195
|
+
onChange: (e) => j(t, { costCenterId: e.target.value }),
|
|
196
|
+
className: c,
|
|
197
|
+
children: [/* @__PURE__ */ a("option", {
|
|
198
|
+
value: "",
|
|
199
|
+
children: "—"
|
|
200
|
+
}), p.filter((e) => e.isActive).map((e) => /* @__PURE__ */ a("option", {
|
|
201
|
+
value: e.id,
|
|
202
|
+
children: e.label
|
|
203
|
+
}, e.id))]
|
|
204
|
+
})
|
|
205
|
+
}),
|
|
206
|
+
/* @__PURE__ */ a("td", {
|
|
207
|
+
className: "px-3 py-2",
|
|
208
|
+
children: /* @__PURE__ */ a("input", {
|
|
209
|
+
type: "number",
|
|
210
|
+
min: "0",
|
|
211
|
+
step: "0.01",
|
|
212
|
+
value: e.debit,
|
|
213
|
+
onChange: (n) => j(t, {
|
|
214
|
+
debit: n.target.value,
|
|
215
|
+
credit: n.target.value ? "" : e.credit
|
|
216
|
+
}),
|
|
217
|
+
className: `${c} text-right`
|
|
218
|
+
})
|
|
219
|
+
}),
|
|
220
|
+
/* @__PURE__ */ a("td", {
|
|
221
|
+
className: "px-3 py-2",
|
|
222
|
+
children: /* @__PURE__ */ a("input", {
|
|
223
|
+
type: "number",
|
|
224
|
+
min: "0",
|
|
225
|
+
step: "0.01",
|
|
226
|
+
value: e.credit,
|
|
227
|
+
onChange: (n) => j(t, {
|
|
228
|
+
credit: n.target.value,
|
|
229
|
+
debit: n.target.value ? "" : e.debit
|
|
230
|
+
}),
|
|
231
|
+
className: `${c} text-right`
|
|
232
|
+
})
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ a("td", {
|
|
235
|
+
className: "px-2 py-2 text-right",
|
|
236
|
+
children: w.length > 2 && /* @__PURE__ */ a("button", {
|
|
237
|
+
type: "button",
|
|
238
|
+
onClick: () => T((e) => e.filter((e, n) => n !== t)),
|
|
239
|
+
className: "text-text-secondary hover:text-destructive",
|
|
240
|
+
"aria-label": "Remove line",
|
|
241
|
+
children: "✕"
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
]
|
|
245
|
+
}, t)) })]
|
|
246
|
+
})
|
|
247
|
+
}),
|
|
248
|
+
/* @__PURE__ */ a("button", {
|
|
249
|
+
type: "button",
|
|
250
|
+
onClick: () => T((e) => [...e, l()]),
|
|
251
|
+
className: "text-sm font-medium text-primary hover:underline",
|
|
252
|
+
children: "+ Add Line"
|
|
253
|
+
})
|
|
254
|
+
]
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
export { u as JournalEntryModal };
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=JournalEntryModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JournalEntryModal.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/JournalEntryModal.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { Modal } from '../../components';\nimport { formatCurrency, todayLocalDate } from '../../utils/helpers';\nimport type { JournalLineInput, LedgerAccount, CostCenter } from '../../hooks/useHealthyBowlAccounting';\n\nconst INPUT_CLASS =\n 'h-9 w-full rounded-md border border-border-subtle bg-bg-surface px-3 text-sm text-text-primary placeholder:text-text-secondary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\ninterface DraftLine {\n accountId: string;\n description: string;\n debit: string;\n credit: string;\n costCenterId: string;\n}\n\nconst emptyLine = (): DraftLine => ({ accountId: '', description: '', debit: '', credit: '', costCenterId: '' });\n\nexport interface JournalEntryModalProps {\n open: boolean;\n onClose: () => void;\n accounts: LedgerAccount[];\n costCenters: CostCenter[];\n onPost: (input: {\n date?: string;\n memo: string;\n reference?: string | null;\n lines: JournalLineInput[];\n }) => Promise<unknown>;\n onSaveDraft: (input: {\n date?: string;\n memo: string;\n reference?: string | null;\n lines: JournalLineInput[];\n }) => Promise<unknown>;\n onSuccess: (message: string) => void;\n onError: (message: string) => void;\n}\n\nexport function JournalEntryModal({\n open,\n onClose,\n accounts,\n costCenters,\n onPost,\n onSaveDraft,\n onSuccess,\n onError,\n}: JournalEntryModalProps) {\n const [date, setDate] = useState(todayLocalDate());\n const [reference, setReference] = useState('');\n const [memo, setMemo] = useState('');\n const [lines, setLines] = useState<DraftLine[]>([emptyLine(), emptyLine()]);\n const [busy, setBusy] = useState(false);\n\n const totals = useMemo(() => {\n const debit = lines.reduce((s, l) => s + (parseFloat(l.debit) || 0), 0);\n const credit = lines.reduce((s, l) => s + (parseFloat(l.credit) || 0), 0);\n return { debit: Math.round(debit * 100) / 100, credit: Math.round(credit * 100) / 100 };\n }, [lines]);\n const balanced = Math.abs(totals.debit - totals.credit) < 0.005 && totals.debit > 0;\n\n const reset = () => {\n setDate(todayLocalDate());\n setReference('');\n setMemo('');\n setLines([emptyLine(), emptyLine()]);\n };\n\n const setLine = (idx: number, patch: Partial<DraftLine>) =>\n setLines((prev) => prev.map((l, i) => (i === idx ? { ...l, ...patch } : l)));\n\n const toInput = (): JournalLineInput[] =>\n lines\n .filter((l) => l.accountId && (parseFloat(l.debit) > 0 || parseFloat(l.credit) > 0))\n .map((l) => ({\n accountId: l.accountId,\n description: l.description || null,\n debit: parseFloat(l.debit) || 0,\n credit: parseFloat(l.credit) || 0,\n costCenterId: l.costCenterId || null,\n }));\n\n const submit = async (asDraft: boolean) => {\n if (!memo.trim()) {\n onError('A memo / description is required.');\n return;\n }\n const payloadLines = toInput();\n if (payloadLines.length < 2) {\n onError('Add at least two lines with an account and an amount.');\n return;\n }\n setBusy(true);\n try {\n const input = { date, memo: memo.trim(), reference: reference.trim() || null, lines: payloadLines };\n if (asDraft) {\n await onSaveDraft(input);\n onSuccess('Draft journal entry saved.');\n } else {\n await onPost(input);\n onSuccess('Journal entry posted.');\n }\n reset();\n onClose();\n } catch (err) {\n onError(err instanceof Error ? err.message : 'Failed to save the journal entry.');\n } finally {\n setBusy(false);\n }\n };\n\n return (\n <Modal\n open={open}\n onClose={onClose}\n title=\"New Journal Entry\"\n description=\"Double-entry — debits must equal credits\"\n size=\"xl\"\n footer={\n <div className=\"flex w-full items-center justify-between gap-3\">\n <div className=\"flex items-center gap-4 text-sm\">\n <span className=\"text-text-secondary\">\n Debits <span className=\"font-semibold text-text-primary\">{formatCurrency(totals.debit, 'INR')}</span> =\n Credits <span className=\"font-semibold text-text-primary\">{formatCurrency(totals.credit, 'INR')}</span>\n </span>\n <span className={balanced ? 'font-semibold text-success' : 'font-semibold text-destructive'}>\n {balanced ? '● Balanced' : '● Not balanced'}\n </span>\n </div>\n <div className=\"flex gap-2\">\n <Button variant=\"outline\" onClick={() => submit(true)} disabled={busy}>\n Save Draft\n </Button>\n <Button onClick={() => submit(false)} disabled={busy || !balanced}>\n Post Entry\n </Button>\n </div>\n </div>\n }\n >\n <div className=\"space-y-4\">\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <label className=\"text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Date</span>\n <input type=\"date\" value={date} onChange={(e) => setDate(e.target.value)} className={INPUT_CLASS} />\n </label>\n <label className=\"text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Reference No.</span>\n <input\n value={reference}\n onChange={(e) => setReference(e.target.value)}\n placeholder=\"e.g. INV-2231\"\n className={INPUT_CLASS}\n />\n </label>\n <label className=\"text-sm sm:col-span-1\">\n <span className=\"mb-1 block text-text-secondary\">Memo / Description</span>\n <input\n value={memo}\n onChange={(e) => setMemo(e.target.value)}\n placeholder=\"Feed purchase for dairy herd\"\n className={INPUT_CLASS}\n />\n </label>\n </div>\n\n <div className=\"overflow-x-auto rounded-lg border border-border-subtle\">\n <table className=\"w-full min-w-[640px] text-sm\">\n <thead className=\"bg-bg-sunken/50 text-left text-text-secondary\">\n <tr>\n <th className=\"px-3 py-2 font-medium\">Account</th>\n <th className=\"px-3 py-2 font-medium\">Cost Center (Crop/Animal)</th>\n <th className=\"px-3 py-2 text-right font-medium\">Debit (₹)</th>\n <th className=\"px-3 py-2 text-right font-medium\">Credit (₹)</th>\n <th className=\"px-2 py-2\" />\n </tr>\n </thead>\n <tbody>\n {lines.map((line, idx) => (\n <tr key={idx} className=\"border-t border-border-subtle\">\n <td className=\"px-3 py-2\">\n <select\n value={line.accountId}\n onChange={(e) => setLine(idx, { accountId: e.target.value })}\n className={INPUT_CLASS}\n >\n <option value=\"\">Select account…</option>\n {accounts\n .filter((a) => a.isActive)\n .map((a) => (\n <option key={a.id} value={a.id}>\n {a.code} · {a.name}\n </option>\n ))}\n </select>\n </td>\n <td className=\"px-3 py-2\">\n <select\n value={line.costCenterId}\n onChange={(e) => setLine(idx, { costCenterId: e.target.value })}\n className={INPUT_CLASS}\n >\n <option value=\"\">—</option>\n {costCenters\n .filter((c) => c.isActive)\n .map((c) => (\n <option key={c.id} value={c.id}>\n {c.label}\n </option>\n ))}\n </select>\n </td>\n <td className=\"px-3 py-2\">\n <input\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n value={line.debit}\n onChange={(e) =>\n setLine(idx, { debit: e.target.value, credit: e.target.value ? '' : line.credit })\n }\n className={`${INPUT_CLASS} text-right`}\n />\n </td>\n <td className=\"px-3 py-2\">\n <input\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n value={line.credit}\n onChange={(e) =>\n setLine(idx, { credit: e.target.value, debit: e.target.value ? '' : line.debit })\n }\n className={`${INPUT_CLASS} text-right`}\n />\n </td>\n <td className=\"px-2 py-2 text-right\">\n {lines.length > 2 && (\n <button\n type=\"button\"\n onClick={() => setLines((prev) => prev.filter((_, i) => i !== idx))}\n className=\"text-text-secondary hover:text-destructive\"\n aria-label=\"Remove line\"\n >\n ✕\n </button>\n )}\n </td>\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n <button\n type=\"button\"\n onClick={() => setLines((prev) => [...prev, emptyLine()])}\n className=\"text-sm font-medium text-primary hover:underline\"\n >\n + Add Line\n </button>\n </div>\n </Modal>\n );\n}\n"],"mappings":";;;;;;;AAMA,IAAM,IACJ,uMAUI,WAA8B;CAAE,WAAW;CAAI,aAAa;CAAI,OAAO;CAAI,QAAQ;CAAI,cAAc;CAAI;AAuB/G,SAAgB,EAAkB,EAChC,SACA,YACA,aACA,gBACA,WACA,gBACA,cACA,cACyB;CACzB,IAAM,CAAC,GAAM,KAAW,EAAS,GAAgB,CAAC,EAC5C,CAAC,GAAW,KAAgB,EAAS,GAAG,EACxC,CAAC,GAAM,KAAW,EAAS,GAAG,EAC9B,CAAC,GAAO,KAAY,EAAsB,CAAC,GAAW,EAAE,GAAW,CAAC,CAAC,EACrE,CAAC,GAAM,KAAW,EAAS,GAAM,EAEjC,IAAS,QAAc;EAC3B,IAAM,IAAQ,EAAM,QAAQ,GAAG,MAAM,KAAK,WAAW,EAAE,MAAM,IAAI,IAAI,EAAE,EACjE,IAAS,EAAM,QAAQ,GAAG,MAAM,KAAK,WAAW,EAAE,OAA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A,EAC1B,EACE,QAAQ,MAAM,EAAE,SAAS,CACzB,KAAK,MACJ,kBAAC,UAAD;WAAmB,OAAO,EAAE;qBACzB,EAAE;WACI,EAFI,EAAE,GAEN,CACT,CACG;;SACN,CAAA;QACL,kBAAC,MAAD;SAAI,WAAU;mBACZ,kBAAC,SAAD;UACE,MAAK;UACL,KAAI;UACJ,MAAK;UACL,OAAO,EAAK;UACZ,WAAW,MACT,EAAQ,GAAK;WAAE,OAAO,EAAE,OAAO;WAAO,QAAQ,EAAE,OAAO,QAAQ,KAAK,EAAK;WAAQ,CAAC;UAEpF,WAAW,GAAG,EAAY;UAC1B,CAAA;SACC,CAAA;QACL,kBAAC,MAAD;SAAI,WAAU;mBACZ,kBAAC,SAAD;UACE,MAAK;UACL,KAAI;UACJ,MAAK;UACL,OAAO,EAAK;UACZ,WAAW,MACT,EAAQ,GAAK;WAAE,QAAQ,EAAE,OAAO;WAAO,OAAO,EAAE,OAAO,QAAQ,KAAK,EAAK;WAAO,CAAC;UAEnF,WAAW,GAAG,EAAY;UAC1B,CAAA;SACC,CAAA;QACL,kBAAC,MAAD;SAAI,WAAU;mBACX,EAAM,SAAS,KACd,kBAAC,UAAD;UACE,MAAK;UACL,eAAe,GAAU,MAAS,EAAK,QAAQ,GAAG,MAAM,MAAM,EAAI,CAAC;UACnE,WAAU;UACV,cAAW;oBACZ;UAEQ,CAAA;SAER,CAAA;QACF;SArEI,EAqEJ,CACL,EACI,CAAA,CACF;;KACJ,CAAA;IACN,kBAAC,UAAD;KACE,MAAK;KACL,eAAe,GAAU,MAAS,CAAC,GAAG,GAAM,GAAW,CAAC,CAAC;KACzD,WAAU;eACX;KAEQ,CAAA;IACL;;EACA,CAAA"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { formatCurrency as e } from "../../utils/helpers.js";
|
|
2
|
+
import { PageLayout as t } from "../../components/PageLayout.js";
|
|
3
|
+
import { EmptyState as n } from "../../components/EmptyState.js";
|
|
4
|
+
import { ErrorState as r } from "../../components/ErrorState.js";
|
|
5
|
+
import { ToastContainer as i } from "../../components/Toast.js";
|
|
6
|
+
import { LoadingSkeleton as a } from "../../components/LoadingSkeleton.js";
|
|
7
|
+
import { useToast as o } from "../../hooks/useToast.js";
|
|
8
|
+
import "../../components/index.js";
|
|
9
|
+
import { useHealthyBowlAccounting as s } from "../../hooks/useHealthyBowlAccounting.js";
|
|
10
|
+
import { financialYearRange as c } from "../../utils/period.js";
|
|
11
|
+
import { downloadBase64 as l } from "../../utils/download.js";
|
|
12
|
+
import { useState as u } from "react";
|
|
13
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
14
|
+
import { Button as p } from "@burdenoff/fe-libs/ui";
|
|
15
|
+
//#region src/healthybowl/pages/financial/ProfitLossPage.tsx
|
|
16
|
+
var m = "h-9 rounded-md border border-border-subtle bg-bg-surface px-3 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]";
|
|
17
|
+
function h() {
|
|
18
|
+
let { toasts: h, toast: _, dismiss: v } = o(), y = c(), [b, x] = u(y.startDate), [S, C] = u(y.endDate), w = s({
|
|
19
|
+
profitAndLoss: !0,
|
|
20
|
+
pnlRange: {
|
|
21
|
+
startDate: b,
|
|
22
|
+
endDate: S
|
|
23
|
+
}
|
|
24
|
+
}), T = w.profitAndLoss, E = async (e) => {
|
|
25
|
+
try {
|
|
26
|
+
let t = await w.exportProfitAndLoss(b, S, e);
|
|
27
|
+
if (!t) throw Error("Export produced no content.");
|
|
28
|
+
l(t.contentBase64, t.filename, t.mimeType), _({
|
|
29
|
+
title: `Exported as ${e}`,
|
|
30
|
+
variant: "success"
|
|
31
|
+
});
|
|
32
|
+
} catch (e) {
|
|
33
|
+
_({
|
|
34
|
+
title: "Export failed",
|
|
35
|
+
description: e instanceof Error ? e.message : void 0,
|
|
36
|
+
variant: "error"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ f(t, {
|
|
41
|
+
title: "Profit & Loss",
|
|
42
|
+
description: "Audit-ready income statement for a chosen period.",
|
|
43
|
+
actions: /* @__PURE__ */ f("div", {
|
|
44
|
+
className: "flex flex-wrap items-end gap-2",
|
|
45
|
+
children: [
|
|
46
|
+
/* @__PURE__ */ f("label", {
|
|
47
|
+
className: "text-xs text-text-secondary",
|
|
48
|
+
children: [/* @__PURE__ */ d("span", {
|
|
49
|
+
className: "mb-1 block",
|
|
50
|
+
children: "From"
|
|
51
|
+
}), /* @__PURE__ */ d("input", {
|
|
52
|
+
type: "date",
|
|
53
|
+
value: b,
|
|
54
|
+
onChange: (e) => x(e.target.value),
|
|
55
|
+
className: m
|
|
56
|
+
})]
|
|
57
|
+
}),
|
|
58
|
+
/* @__PURE__ */ f("label", {
|
|
59
|
+
className: "text-xs text-text-secondary",
|
|
60
|
+
children: [/* @__PURE__ */ d("span", {
|
|
61
|
+
className: "mb-1 block",
|
|
62
|
+
children: "To"
|
|
63
|
+
}), /* @__PURE__ */ d("input", {
|
|
64
|
+
type: "date",
|
|
65
|
+
value: S,
|
|
66
|
+
onChange: (e) => C(e.target.value),
|
|
67
|
+
className: m
|
|
68
|
+
})]
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ d(p, {
|
|
71
|
+
variant: "outline",
|
|
72
|
+
onClick: () => E("PDF"),
|
|
73
|
+
children: "Export PDF"
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ d(p, {
|
|
76
|
+
variant: "outline",
|
|
77
|
+
onClick: () => E("CSV"),
|
|
78
|
+
children: "Export CSV"
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ d(p, {
|
|
81
|
+
variant: "outline",
|
|
82
|
+
onClick: () => window.print(),
|
|
83
|
+
children: "Print"
|
|
84
|
+
})
|
|
85
|
+
]
|
|
86
|
+
}),
|
|
87
|
+
children: [/* @__PURE__ */ d(i, {
|
|
88
|
+
toasts: h,
|
|
89
|
+
onDismiss: v
|
|
90
|
+
}), w.error && !T ? /* @__PURE__ */ d(r, {
|
|
91
|
+
title: "Could not load the P&L",
|
|
92
|
+
description: w.error.message
|
|
93
|
+
}) : w.loading && !T ? /* @__PURE__ */ d(a, {
|
|
94
|
+
variant: "card",
|
|
95
|
+
count: 1
|
|
96
|
+
}) : T ? /* @__PURE__ */ f("div", {
|
|
97
|
+
className: "mx-auto max-w-2xl rounded-xl border border-border-subtle bg-bg-surface p-8",
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ f("div", {
|
|
100
|
+
className: "mb-6 text-center",
|
|
101
|
+
children: [/* @__PURE__ */ d("h2", {
|
|
102
|
+
className: "text-xl font-bold text-text-primary",
|
|
103
|
+
children: "Profit & Loss Statement"
|
|
104
|
+
}), /* @__PURE__ */ f("p", {
|
|
105
|
+
className: "text-sm text-text-secondary",
|
|
106
|
+
children: ["For the period ", T.periodLabel]
|
|
107
|
+
})]
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ f("section", {
|
|
110
|
+
className: "mb-6",
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ d("h3", {
|
|
113
|
+
className: "mb-2 text-sm font-bold uppercase tracking-wide text-text-secondary",
|
|
114
|
+
children: "Income"
|
|
115
|
+
}),
|
|
116
|
+
T.income.length === 0 ? /* @__PURE__ */ d(g, {
|
|
117
|
+
label: "No income recorded",
|
|
118
|
+
value: e(0, "INR")
|
|
119
|
+
}) : T.income.map((t) => /* @__PURE__ */ d(g, {
|
|
120
|
+
label: t.name,
|
|
121
|
+
value: e(t.amount, "INR")
|
|
122
|
+
}, t.code)),
|
|
123
|
+
/* @__PURE__ */ d(g, {
|
|
124
|
+
label: "Total Revenue",
|
|
125
|
+
value: e(T.totalRevenue, "INR"),
|
|
126
|
+
bold: !0,
|
|
127
|
+
border: !0
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}),
|
|
131
|
+
/* @__PURE__ */ f("section", {
|
|
132
|
+
className: "mb-6",
|
|
133
|
+
children: [
|
|
134
|
+
/* @__PURE__ */ d("h3", {
|
|
135
|
+
className: "mb-2 text-sm font-bold uppercase tracking-wide text-text-secondary",
|
|
136
|
+
children: "Expenses"
|
|
137
|
+
}),
|
|
138
|
+
T.expenses.length === 0 ? /* @__PURE__ */ d(g, {
|
|
139
|
+
label: "No expenses recorded",
|
|
140
|
+
value: e(0, "INR")
|
|
141
|
+
}) : T.expenses.map((t) => /* @__PURE__ */ d(g, {
|
|
142
|
+
label: t.name,
|
|
143
|
+
value: e(t.amount, "INR")
|
|
144
|
+
}, t.code)),
|
|
145
|
+
/* @__PURE__ */ d(g, {
|
|
146
|
+
label: "Total Expenses",
|
|
147
|
+
value: e(T.totalExpenses, "INR"),
|
|
148
|
+
bold: !0,
|
|
149
|
+
border: !0
|
|
150
|
+
})
|
|
151
|
+
]
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ f("div", {
|
|
154
|
+
className: "flex items-center justify-between rounded-lg border border-border-subtle bg-bg-sunken/40 px-4 py-3",
|
|
155
|
+
children: [/* @__PURE__ */ f("div", { children: [/* @__PURE__ */ d("div", {
|
|
156
|
+
className: "text-xs font-semibold uppercase text-text-secondary",
|
|
157
|
+
children: "Net Profit"
|
|
158
|
+
}), /* @__PURE__ */ d("div", {
|
|
159
|
+
className: `text-2xl font-bold ${T.netProfit >= 0 ? "text-success" : "text-destructive"}`,
|
|
160
|
+
children: e(T.netProfit, "INR")
|
|
161
|
+
})] }), /* @__PURE__ */ f("div", {
|
|
162
|
+
className: "text-right",
|
|
163
|
+
children: [/* @__PURE__ */ d("div", {
|
|
164
|
+
className: "text-xs font-semibold uppercase text-text-secondary",
|
|
165
|
+
children: "Gross Margin"
|
|
166
|
+
}), /* @__PURE__ */ f("div", {
|
|
167
|
+
className: "text-2xl font-bold text-text-primary",
|
|
168
|
+
children: [T.grossMarginPct, "%"]
|
|
169
|
+
})]
|
|
170
|
+
})]
|
|
171
|
+
}),
|
|
172
|
+
/* @__PURE__ */ f("p", {
|
|
173
|
+
className: "mt-4 text-center text-xs text-text-secondary",
|
|
174
|
+
children: [
|
|
175
|
+
"Generated ",
|
|
176
|
+
new Date(T.generatedAt).toISOString().slice(0, 10),
|
|
177
|
+
" · Audit-ready"
|
|
178
|
+
]
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
}) : /* @__PURE__ */ d(n, {
|
|
182
|
+
title: "No data",
|
|
183
|
+
description: "No posted entries in this period."
|
|
184
|
+
})]
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function g({ label: e, value: t, bold: n, border: r }) {
|
|
188
|
+
return /* @__PURE__ */ f("div", {
|
|
189
|
+
className: `flex items-center justify-between py-1.5 ${r ? "mt-1 border-t border-border-subtle pt-2" : ""}`,
|
|
190
|
+
children: [/* @__PURE__ */ d("span", {
|
|
191
|
+
className: n ? "font-semibold text-text-primary" : "text-text-primary",
|
|
192
|
+
children: e
|
|
193
|
+
}), /* @__PURE__ */ d("span", {
|
|
194
|
+
className: n ? "font-semibold text-text-primary" : "text-text-primary",
|
|
195
|
+
children: t
|
|
196
|
+
})]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
export { h as ProfitLossPage };
|
|
201
|
+
|
|
202
|
+
//# sourceMappingURL=ProfitLossPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProfitLossPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/ProfitLossPage.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { PageLayout, LoadingSkeleton, ErrorState, EmptyState, ToastContainer } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { formatCurrency } from '../../utils/helpers';\nimport { downloadBase64 } from '../../utils/download';\nimport { financialYearRange } from '../../utils/period';\nimport { useHealthyBowlAccounting } from '../../hooks/useHealthyBowlAccounting';\n\nconst INPUT_CLASS =\n 'h-9 rounded-md border border-border-subtle bg-bg-surface px-3 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\nexport function ProfitLossPage() {\n const { toasts, toast, dismiss } = useToast();\n const initial = financialYearRange();\n const [startDate, setStartDate] = useState(initial.startDate);\n const [endDate, setEndDate] = useState(initial.endDate);\n const acc = useHealthyBowlAccounting({ profitAndLoss: true, pnlRange: { startDate, endDate } });\n const pnl = acc.profitAndLoss;\n\n const doExport = async (format: 'CSV' | 'PDF') => {\n try {\n const out = await acc.exportProfitAndLoss(startDate, endDate, format);\n if (!out) throw new Error('Export produced no content.');\n downloadBase64(out.contentBase64, out.filename, out.mimeType);\n toast({ title: `Exported as ${format}`, variant: 'success' });\n } catch (err) {\n toast({ title: 'Export failed', description: err instanceof Error ? err.message : undefined, variant: 'error' });\n }\n };\n\n return (\n <PageLayout\n title=\"Profit & Loss\"\n description=\"Audit-ready income statement for a chosen period.\"\n actions={\n <div className=\"flex flex-wrap items-end gap-2\">\n <label className=\"text-xs text-text-secondary\">\n <span className=\"mb-1 block\">From</span>\n <input\n type=\"date\"\n value={startDate}\n onChange={(e) => setStartDate(e.target.value)}\n className={INPUT_CLASS}\n />\n </label>\n <label className=\"text-xs text-text-secondary\">\n <span className=\"mb-1 block\">To</span>\n <input type=\"date\" value={endDate} onChange={(e) => setEndDate(e.target.value)} className={INPUT_CLASS} />\n </label>\n <Button variant=\"outline\" onClick={() => doExport('PDF')}>\n Export PDF\n </Button>\n <Button variant=\"outline\" onClick={() => doExport('CSV')}>\n Export CSV\n </Button>\n <Button variant=\"outline\" onClick={() => window.print()}>\n Print\n </Button>\n </div>\n }\n >\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n {acc.error && !pnl ? (\n <ErrorState title=\"Could not load the P&L\" description={acc.error.message} />\n ) : acc.loading && !pnl ? (\n <LoadingSkeleton variant=\"card\" count={1} />\n ) : !pnl ? (\n <EmptyState title=\"No data\" description=\"No posted entries in this period.\" />\n ) : (\n <div className=\"mx-auto max-w-2xl rounded-xl border border-border-subtle bg-bg-surface p-8\">\n <div className=\"mb-6 text-center\">\n <h2 className=\"text-xl font-bold text-text-primary\">Profit & Loss Statement</h2>\n <p className=\"text-sm text-text-secondary\">For the period {pnl.periodLabel}</p>\n </div>\n\n <section className=\"mb-6\">\n <h3 className=\"mb-2 text-sm font-bold uppercase tracking-wide text-text-secondary\">Income</h3>\n {pnl.income.length === 0 ? (\n <Row label=\"No income recorded\" value={formatCurrency(0, 'INR')} />\n ) : (\n pnl.income.map((l) => <Row key={l.code} label={l.name} value={formatCurrency(l.amount, 'INR')} />)\n )}\n <Row label=\"Total Revenue\" value={formatCurrency(pnl.totalRevenue, 'INR')} bold border />\n </section>\n\n <section className=\"mb-6\">\n <h3 className=\"mb-2 text-sm font-bold uppercase tracking-wide text-text-secondary\">Expenses</h3>\n {pnl.expenses.length === 0 ? (\n <Row label=\"No expenses recorded\" value={formatCurrency(0, 'INR')} />\n ) : (\n pnl.expenses.map((l) => <Row key={l.code} label={l.name} value={formatCurrency(l.amount, 'INR')} />)\n )}\n <Row label=\"Total Expenses\" value={formatCurrency(pnl.totalExpenses, 'INR')} bold border />\n </section>\n\n <div className=\"flex items-center justify-between rounded-lg border border-border-subtle bg-bg-sunken/40 px-4 py-3\">\n <div>\n <div className=\"text-xs font-semibold uppercase text-text-secondary\">Net Profit</div>\n <div className={`text-2xl font-bold ${pnl.netProfit >= 0 ? 'text-success' : 'text-destructive'}`}>\n {formatCurrency(pnl.netProfit, 'INR')}\n </div>\n </div>\n <div className=\"text-right\">\n <div className=\"text-xs font-semibold uppercase text-text-secondary\">Gross Margin</div>\n <div className=\"text-2xl font-bold text-text-primary\">{pnl.grossMarginPct}%</div>\n </div>\n </div>\n <p className=\"mt-4 text-center text-xs text-text-secondary\">\n Generated {new Date(pnl.generatedAt).toISOString().slice(0, 10)} · Audit-ready\n </p>\n </div>\n )}\n </PageLayout>\n );\n}\n\nfunction Row({ label, value, bold, border }: { label: string; value: string; bold?: boolean; border?: boolean }) {\n return (\n <div\n className={`flex items-center justify-between py-1.5 ${border ? 'mt-1 border-t border-border-subtle pt-2' : ''}`}\n >\n <span className={bold ? 'font-semibold text-text-primary' : 'text-text-primary'}>{label}</span>\n <span className={bold ? 'font-semibold text-text-primary' : 'text-text-primary'}>{value}</span>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AASA,IAAM,IACJ;AAEF,SAAgB,IAAiB;CAC/B,IAAM,EAAE,WAAQ,UAAO,eAAY,GAAU,EACvC,IAAU,GAAoB,EAC9B,CAAC,GAAW,KAAgB,EAAS,EAAQ,UAAU,EACvD,CAAC,GAAS,KAAc,EAAS,EAAQ,QAAQ,EACjD,IAAM,EAAyB;EAAE,eAAe;EAAM,UAAU;GAAE;GAAW;GAAS;EAAE,CAAC,EACzF,IAAM,EAAI,eAEV,IAAW,OAAO,MAA0B;AAChD,MAAI;GACF,IAAM,IAAM,MAAM,EAAI,oBAAoB,GAAW,GAAS,EAAO;AACrE,OAAI,CAAC,EAAK,OAAU,MAAM,8BAA8B;AAExD,GADA,EAAe,EAAI,eAAe,EAAI,UAAU,EAAI,SAAS,EAC7D,EAAM;IAAE,OAAO,eAAe;IAAU,SAAS;IAAW,CAAC;WACtD,GAAK;AACZ,KAAM;IAAE,OAAO;IAAiB,aAAa,aAAe,QAAQ,EAAI,UAAU,KAAA;IAAW,SAAS;IAAS,CAAC;;;AAIpH,QACE,kBAAC,GAAD;EACE,OAAM;EACN,aAAY;EACZ,SACE,kBAAC,OAAD;GAAK,WAAU;aAAf;IACE,kBAAC,SAAD;KAAO,WAAU;eAAjB,CACE,kBAAC,QAAD;MAAM,WAAU;gBAAa;MAAW,CAAA,EACxC,kBAAC,SAAD;MACE,MAAK;MACL,OAAO;MACP,WAAW,MAAM,EAAa,EAAE,OAAO,MAAM;MAC7C,WAAW;MACX,CAAA,CACI;;IACR,kBAAC,SAAD;KAAO,WAAU;eAAjB,CACE,kBAAC,QAAD;MAAM,WAAU;gBAAa;MAAS,CAAA,EACtC,kBAAC,S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M,WAAW,IAAO,oCAAoC;aAAsB;GAAa,CAAA,CAC3F"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/healthybowl/utils/download.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
let r = atob(e), i = new Uint8Array(r.length);
|
|
4
|
+
for (let e = 0; e < r.length; e += 1) i[e] = r.charCodeAt(e);
|
|
5
|
+
let a = new Blob([i], { type: n }), o = URL.createObjectURL(a), s = document.createElement("a");
|
|
6
|
+
s.href = o, s.download = t, document.body.appendChild(s), s.click(), document.body.removeChild(s), URL.revokeObjectURL(o);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as downloadBase64 };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","names":[],"sources":["../../../src/healthybowl/utils/download.ts"],"sourcesContent":["/** Decode a base64 payload (from a server-generated export) into a downloaded file. */\nexport function downloadBase64(base64: string, filename: string, mimeType: string): void {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);\n const blob = new Blob([bytes], { type: mimeType });\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n}\n\n/** Trigger a client-side CSV download from rows (used by the ledger/cost tables). */\nexport function downloadCsv(filename: string, headers: string[], rows: (string | number)[][]): void {\n const esc = (v: string | number): string => {\n const s = String(v ?? '');\n return /[\",\\n]/.test(s) ? `\"${s.replace(/\"/g, '\"\"')}\"` : s;\n };\n const csv = [headers.map(esc).join(','), ...rows.map((r) => r.map(esc).join(','))].join('\\n');\n const blob = new Blob([csv], { type: 'text/csv' });\n const url = URL.createObjectURL(blob);\n const a = document.createElement('a');\n a.href = url;\n a.download = filename;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n URL.revokeObjectURL(url);\n}\n"],"mappings":";AACA,SAAgB,EAAe,GAAgB,GAAkB,GAAwB;CACvF,IAAM,IAAS,KAAK,EAAO,EACrB,IAAQ,IAAI,WAAW,EAAO,OAAO;AAC3C,MAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAAK,EAAG,GAAM,KAAK,EAAO,WAAW,EAAE;CAC1E,IAAM,IAAO,IAAI,KAAK,CAAC,EAAM,EAAE,EAAE,MAAM,GAAU,CAAC,EAC5C,IAAM,IAAI,gBAAgB,EAAK,EAC/B,IAAI,SAAS,cAAc,IAAI;AAMrC,CALA,EAAE,OAAO,GACT,EAAE,WAAW,GACb,SAAS,KAAK,YAAY,EAAE,EAC5B,EAAE,OAAO,EACT,SAAS,KAAK,YAAY,EAAE,EAC5B,IAAI,gBAAgB,EAAI"}
|
|
@@ -4,26 +4,29 @@ import { twMerge as t } from "../../node_modules/tailwind-merge/dist/bundle-mjs.
|
|
|
4
4
|
function n(...n) {
|
|
5
5
|
return t(e(n));
|
|
6
6
|
}
|
|
7
|
-
function r(e) {
|
|
7
|
+
function r(e, t) {
|
|
8
|
+
return (e.endsWith("/") ? e.slice(0, -1) : e) + (t.startsWith("/") ? t : `/${t}`);
|
|
9
|
+
}
|
|
10
|
+
function i(e) {
|
|
8
11
|
return e.endsWith("/") ? e.slice(0, -1) || "/" : e;
|
|
9
12
|
}
|
|
10
|
-
function
|
|
13
|
+
function a(e, t = "USD") {
|
|
11
14
|
return new Intl.NumberFormat("en-US", {
|
|
12
15
|
style: "currency",
|
|
13
16
|
currency: t
|
|
14
17
|
}).format(e);
|
|
15
18
|
}
|
|
16
|
-
function
|
|
19
|
+
function o(e) {
|
|
17
20
|
return new Intl.NumberFormat("en-US").format(e);
|
|
18
21
|
}
|
|
19
|
-
function
|
|
22
|
+
function s(e) {
|
|
20
23
|
return new Date(e).toLocaleDateString("en-US", {
|
|
21
24
|
year: "numeric",
|
|
22
25
|
month: "short",
|
|
23
26
|
day: "numeric"
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
|
-
function
|
|
29
|
+
function c(e) {
|
|
27
30
|
let t = /^(\d{4})-(\d{2})-(\d{2})/.exec(e);
|
|
28
31
|
if (!t) return e;
|
|
29
32
|
let [, n, r, i] = t;
|
|
@@ -33,15 +36,15 @@ function s(e) {
|
|
|
33
36
|
day: "numeric"
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
|
-
function
|
|
39
|
+
function l() {
|
|
37
40
|
let e = /* @__PURE__ */ new Date();
|
|
38
41
|
return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
|
|
39
42
|
}
|
|
40
|
-
function
|
|
43
|
+
function u(e) {
|
|
41
44
|
let t = new Date(e), n = (/* @__PURE__ */ new Date()).getTime() - t.getTime(), r = Math.floor(n / (1e3 * 60 * 60 * 24));
|
|
42
45
|
return r === 0 ? "Today" : r === 1 ? "Yesterday" : r < 7 ? `${r} days ago` : r < 30 ? `${Math.floor(r / 7)} weeks ago` : r < 365 ? `${Math.floor(r / 30)} months ago` : `${Math.floor(r / 365)} years ago`;
|
|
43
46
|
}
|
|
44
47
|
//#endregion
|
|
45
|
-
export { n as cn,
|
|
48
|
+
export { n as cn, a as formatCurrency, s as formatDate, c as formatDateOnly, o as formatNumber, u as getRelativeTime, r as joinPath, i as normalizeBasePath, l as todayLocalDate };
|
|
46
49
|
|
|
47
50
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","names":[],"sources":["../../../src/healthybowl/utils/helpers.ts"],"sourcesContent":["/**\n * HealthyBowl Utility Helpers\n * @module healthybowl\n */\n\nimport { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Merge Tailwind classes safely */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/** Join path segments safely */\nexport function joinPath(base: string, path: string): string {\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return cleanBase + cleanPath;\n}\n\n/**\n * Normalize a base path: strip a trailing slash but keep '/' for the root.\n * (e.g. '/healthybowl/' → '/healthybowl', '/' → '/'). Shared by useBasePath\n * and HealthyBowlRoot so the rule lives in one place.\n */\nexport function normalizeBasePath(base: string): string {\n return base.endsWith('/') ? base.slice(0, -1) || '/' : base;\n}\n\n/** Format currency */\nexport function formatCurrency(amount: number, currency = 'USD'): string {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount);\n}\n\n/** Format number with commas */\nexport function formatNumber(num: number): string {\n return new Intl.NumberFormat('en-US').format(num);\n}\n\n/** Format date */\nexport function formatDate(dateStr: string): string {\n return new Date(dateStr).toLocaleDateString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Format a date-only string (YYYY-MM-DD) without timezone conversion.\n * Using `new Date('2026-06-06')` parses as UTC midnight and shifts backward a\n * day in western (negative-offset) zones. Parsing the parts into a local Date\n * keeps the calendar date intact.\n */\nexport function formatDateOnly(dateStr: string): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})/.exec(dateStr);\n if (!match) return dateStr;\n const [, year, month, day] = match;\n return new Date(Number(year), Number(month) - 1, Number(day)).toLocaleDateString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Today's calendar date as YYYY-MM-DD in the user's *local* timezone.\n * `new Date().toISOString()` is UTC, so for users west of UTC in the evening it has\n * already rolled to tomorrow — using it as a date-input `min` then wrongly blocks today.\n */\nexport function todayLocalDate(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\n/** Get relative time string */\nexport function getRelativeTime(dateStr: string): string {\n const date = new Date(dateStr);\n const now = new Date();\n const diffMs = now.getTime() - date.getTime();\n const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n\n if (diffDays === 0) return 'Today';\n if (diffDays === 1) return 'Yesterday';\n if (diffDays < 7) return `${diffDays} days ago`;\n if (diffDays < 30) return `${Math.floor(diffDays / 7)} weeks ago`;\n if (diffDays < 365) return `${Math.floor(diffDays / 30)} months ago`;\n return `${Math.floor(diffDays / 365)} years ago`;\n}\n\n/** Get percentage change */\nexport function getPercentChange(current: number, previous: number): number {\n if (previous === 0) return current > 0 ? 100 : 0;\n return Math.round(((current - previous) / previous) * 100);\n}\n\n/** Truncate text */\nexport function truncate(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text;\n return text.slice(0, maxLength) + '...';\n}\n\n/** Simulate async delay (for mock data) */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;AASA,SAAgB,EAAG,GAAG,GAAsB;AAC1C,QAAO,EAAQ,EAAK,EAAO,CAAC;;
|
|
1
|
+
{"version":3,"file":"helpers.js","names":[],"sources":["../../../src/healthybowl/utils/helpers.ts"],"sourcesContent":["/**\n * HealthyBowl Utility Helpers\n * @module healthybowl\n */\n\nimport { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\n/** Merge Tailwind classes safely */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n\n/** Join path segments safely */\nexport function joinPath(base: string, path: string): string {\n const cleanBase = base.endsWith('/') ? base.slice(0, -1) : base;\n const cleanPath = path.startsWith('/') ? path : `/${path}`;\n return cleanBase + cleanPath;\n}\n\n/**\n * Normalize a base path: strip a trailing slash but keep '/' for the root.\n * (e.g. '/healthybowl/' → '/healthybowl', '/' → '/'). Shared by useBasePath\n * and HealthyBowlRoot so the rule lives in one place.\n */\nexport function normalizeBasePath(base: string): string {\n return base.endsWith('/') ? base.slice(0, -1) || '/' : base;\n}\n\n/** Format currency */\nexport function formatCurrency(amount: number, currency = 'USD'): string {\n return new Intl.NumberFormat('en-US', { style: 'currency', currency }).format(amount);\n}\n\n/** Format number with commas */\nexport function formatNumber(num: number): string {\n return new Intl.NumberFormat('en-US').format(num);\n}\n\n/** Format date */\nexport function formatDate(dateStr: string): string {\n return new Date(dateStr).toLocaleDateString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Format a date-only string (YYYY-MM-DD) without timezone conversion.\n * Using `new Date('2026-06-06')` parses as UTC midnight and shifts backward a\n * day in western (negative-offset) zones. Parsing the parts into a local Date\n * keeps the calendar date intact.\n */\nexport function formatDateOnly(dateStr: string): string {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})/.exec(dateStr);\n if (!match) return dateStr;\n const [, year, month, day] = match;\n return new Date(Number(year), Number(month) - 1, Number(day)).toLocaleDateString('en-US', {\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n });\n}\n\n/**\n * Today's calendar date as YYYY-MM-DD in the user's *local* timezone.\n * `new Date().toISOString()` is UTC, so for users west of UTC in the evening it has\n * already rolled to tomorrow — using it as a date-input `min` then wrongly blocks today.\n */\nexport function todayLocalDate(): string {\n const now = new Date();\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0');\n const day = String(now.getDate()).padStart(2, '0');\n return `${year}-${month}-${day}`;\n}\n\n/** Get relative time string */\nexport function getRelativeTime(dateStr: string): string {\n const date = new Date(dateStr);\n const now = new Date();\n const diffMs = now.getTime() - date.getTime();\n const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));\n\n if (diffDays === 0) return 'Today';\n if (diffDays === 1) return 'Yesterday';\n if (diffDays < 7) return `${diffDays} days ago`;\n if (diffDays < 30) return `${Math.floor(diffDays / 7)} weeks ago`;\n if (diffDays < 365) return `${Math.floor(diffDays / 30)} months ago`;\n return `${Math.floor(diffDays / 365)} years ago`;\n}\n\n/** Get percentage change */\nexport function getPercentChange(current: number, previous: number): number {\n if (previous === 0) return current > 0 ? 100 : 0;\n return Math.round(((current - previous) / previous) * 100);\n}\n\n/** Truncate text */\nexport function truncate(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text;\n return text.slice(0, maxLength) + '...';\n}\n\n/** Simulate async delay (for mock data) */\nexport function delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"],"mappings":";;;AASA,SAAgB,EAAG,GAAG,GAAsB;AAC1C,QAAO,EAAQ,EAAK,EAAO,CAAC;;AAI9B,SAAgB,EAAS,GAAc,GAAsB;AAG3D,SAFkB,EAAK,SAAS,IAAI,GAAG,EAAK,MAAM,GAAG,GAAG,GAAG,MACzC,EAAK,WAAW,IAAI,GAAG,IAAO,IAAI;;AAStD,SAAgB,EAAkB,GAAsB;AACtD,QAAO,EAAK,SAAS,IAAI,GAAG,EAAK,MAAM,GAAG,GAAG,IAAI,MAAM;;AAIzD,SAAgB,EAAe,GAAgB,IAAW,OAAe;AACvE,QAAO,IAAI,KAAK,aAAa,SAAS;EAAE,OAAO;EAAY;EAAU,CAAC,CAAC,OAAO,EAAO;;AAIvF,SAAgB,EAAa,GAAqB;AAChD,QAAO,IAAI,KAAK,aAAa,QAAQ,CAAC,OAAO,EAAI;;AAInD,SAAgB,EAAW,GAAyB;AAClD,QAAO,IAAI,KAAK,EAAQ,CAAC,mBAAmB,SAAS;EACnD,MAAM;EACN,OAAO;EACP,KAAK;EACN,CAAC;;AASJ,SAAgB,EAAe,GAAyB;CACtD,IAAM,IAAQ,2BAA2B,KAAK,EAAQ;AACtD,KAAI,CAAC,EAAO,QAAO;CACnB,IAAM,GAAG,GAAM,GAAO,KAAO;AAC7B,QAAO,IAAI,KAAK,OAAO,EAAK,EAAE,OAAO,EAAM,GAAG,GAAG,OAAO,EAAI,CAAC,CAAC,mBAAmB,SAAS;EACxF,MAAM;EACN,OAAO;EACP,KAAK;EACN,CAAC;;AAQJ,SAAgB,IAAyB;CACvC,IAAM,oBAAM,IAAI,MAAM;AAItB,QAAO,GAHM,EAAI,aAAa,CAGf,GAFD,OAAO,EAAI,UAAU,GAAG,EAAE,CAAC,SAAS,GAAG,IAAI,CAEjC,GADZ,OAAO,EAAI,SAAS,CAAC,CAAC,SAAS,GAAG,IAAI;;AAKpD,SAAgB,EAAgB,GAAyB;CACvD,IAAM,IAAO,IAAI,KAAK,EAAQ,EAExB,qBADM,IAAI,MAAM,EACH,SAAS,GAAG,EAAK,SAAS,EACvC,IAAW,KAAK,MAAM,KAAU,MAAO,KAAK,KAAK,IAAI;AAO3D,QALI,MAAa,IAAU,UACvB,MAAa,IAAU,cACvB,IAAW,IAAU,GAAG,EAAS,aACjC,IAAW,KAAW,GAAG,KAAK,MAAM,IAAW,EAAE,CAAC,cAClD,IAAW,MAAY,GAAG,KAAK,MAAM,IAAW,GAAG,CAAC,eACjD,GAAG,KAAK,MAAM,IAAW,IAAI,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/healthybowl/utils/period.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e.toISOString().slice(0, 10);
|
|
4
|
+
}
|
|
5
|
+
function t(t = /* @__PURE__ */ new Date()) {
|
|
6
|
+
let n = t.getUTCFullYear();
|
|
7
|
+
return {
|
|
8
|
+
startDate: `${t.getUTCMonth() >= 3 ? n : n - 1}-04-01`,
|
|
9
|
+
endDate: e(t)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { t as financialYearRange };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=period.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.js","names":[],"sources":["../../../src/healthybowl/utils/period.ts"],"sourcesContent":["/** Date-range helpers for the accounting reports (ISO yyyy-mm-dd, UTC-safe). */\n\nfunction iso(d: Date): string {\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * The Indian financial year (1 Apr – 31 Mar) that contains today, with the end\n * clamped to today so the default report is a year-to-date view.\n */\nexport function financialYearRange(now: Date = new Date()): { startDate: string; endDate: string } {\n const year = now.getUTCFullYear();\n const fyStartYear = now.getUTCMonth() >= 3 ? year : year - 1; // April = month index 3\n return { startDate: `${fyStartYear}-04-01`, endDate: iso(now) };\n}\n\n/** The full calendar year containing `now`. */\nexport function calendarYearRange(now: Date = new Date()): { startDate: string; endDate: string } {\n const year = now.getUTCFullYear();\n return { startDate: `${year}-01-01`, endDate: `${year}-12-31` };\n}\n"],"mappings":";AAEA,SAAS,EAAI,GAAiB;AAC5B,QAAO,EAAE,aAAa,CAAC,MAAM,GAAG,GAAG;;AAOrC,SAAgB,EAAmB,oBAAY,IAAI,MAAM,EAA0C;CACjG,IAAM,IAAO,EAAI,gBAAgB;AAEjC,QAAO;EAAE,WAAW,GADA,EAAI,aAAa,IAAI,IAAI,IAAO,IAAO,EACxB;EAAS,SAAS,EAAI,EAAI;EAAE"}
|
package/package.json
CHANGED