@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.
Files changed (27) hide show
  1. package/dist/healthybowl/HealthyBowlRoutes.js +99 -75
  2. package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
  3. package/dist/healthybowl/hooks/useHealthyBowlAccounting.js +316 -0
  4. package/dist/healthybowl/hooks/useHealthyBowlAccounting.js.map +1 -0
  5. package/dist/healthybowl/pages/financial/AccountingIntegrationsPage.js +297 -0
  6. package/dist/healthybowl/pages/financial/AccountingIntegrationsPage.js.map +1 -0
  7. package/dist/healthybowl/pages/financial/ChartOfAccountsPage.js +233 -0
  8. package/dist/healthybowl/pages/financial/ChartOfAccountsPage.js.map +1 -0
  9. package/dist/healthybowl/pages/financial/CostByCropPage.js +365 -0
  10. package/dist/healthybowl/pages/financial/CostByCropPage.js.map +1 -0
  11. package/dist/healthybowl/pages/financial/FarmAccountingPage.js +384 -0
  12. package/dist/healthybowl/pages/financial/FarmAccountingPage.js.map +1 -0
  13. package/dist/healthybowl/pages/financial/FinancialDashboardPage.js +32 -16
  14. package/dist/healthybowl/pages/financial/FinancialDashboardPage.js.map +1 -1
  15. package/dist/healthybowl/pages/financial/GeneralLedgerPage.js +221 -0
  16. package/dist/healthybowl/pages/financial/GeneralLedgerPage.js.map +1 -0
  17. package/dist/healthybowl/pages/financial/JournalEntryModal.js +261 -0
  18. package/dist/healthybowl/pages/financial/JournalEntryModal.js.map +1 -0
  19. package/dist/healthybowl/pages/financial/ProfitLossPage.js +202 -0
  20. package/dist/healthybowl/pages/financial/ProfitLossPage.js.map +1 -0
  21. package/dist/healthybowl/utils/download.js +11 -0
  22. package/dist/healthybowl/utils/download.js.map +1 -0
  23. package/dist/healthybowl/utils/helpers.js +11 -8
  24. package/dist/healthybowl/utils/helpers.js.map +1 -1
  25. package/dist/healthybowl/utils/period.js +15 -0
  26. package/dist/healthybowl/utils/period.js.map +1 -0
  27. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountingIntegrationsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/AccountingIntegrationsPage.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { Button, Switch } from '@burdenoff/fe-libs/ui';\nimport {\n PageLayout,\n ChartCard,\n DataTable,\n StatusBadge,\n LoadingSkeleton,\n ErrorState,\n EmptyState,\n Modal,\n ToastContainer,\n} from '../../components';\nimport type { Column } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { formatDate } from '../../utils/helpers';\nimport { useHealthyBowlAccounting } from '../../hooks/useHealthyBowlAccounting';\nimport type { AccountingSyncLog } 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\nconst PROVIDERS: Array<{ id: 'TALLY' | 'ZOHO_BOOKS' | 'QUICKBOOKS'; label: string; blurb: string }> = [\n { id: 'TALLY', label: 'Tally', blurb: 'Push journal entries to Tally via its XML import gateway.' },\n { id: 'ZOHO_BOOKS', label: 'Zoho Books', blurb: 'Sync journals and invoices with your Zoho Books organization.' },\n { id: 'QUICKBOOKS', label: 'QuickBooks', blurb: 'Export journal entries to QuickBooks Online.' },\n];\n\nexport function AccountingIntegrationsPage() {\n const { toasts, toast, dismiss } = useToast();\n const acc = useHealthyBowlAccounting({ integrations: true });\n const payload = acc.integrations;\n const [connectFor, setConnectFor] = useState<null | 'TALLY' | 'ZOHO_BOOKS' | 'QUICKBOOKS'>(null);\n const [displayName, setDisplayName] = useState('');\n const [endpoint, setEndpoint] = useState('');\n const [organizationRef, setOrganizationRef] = useState('');\n const [busy, setBusy] = useState('');\n\n const submitConnect = async () => {\n if (!connectFor) return;\n setBusy('connect');\n try {\n await acc.connectIntegration({\n provider: connectFor,\n displayName: displayName || null,\n endpoint: endpoint || null,\n organizationRef: organizationRef || null,\n });\n toast({ title: `${connectFor} connected`, variant: 'success' });\n setConnectFor(null);\n setDisplayName('');\n setEndpoint('');\n setOrganizationRef('');\n } catch (err) {\n toast({ title: 'Connect failed', description: err instanceof Error ? err.message : undefined, variant: 'error' });\n } finally {\n setBusy('');\n }\n };\n\n const sync = async (provider: string) => {\n setBusy(provider);\n try {\n const res = await acc.syncIntegration(provider);\n toast({ title: res?.message ?? 'Sync complete', variant: res?.status === 'FAILED' ? 'warning' : 'success' });\n } catch (err) {\n toast({ title: 'Sync failed', description: err instanceof Error ? err.message : undefined, variant: 'error' });\n } finally {\n setBusy('');\n }\n };\n\n const disconnect = async (provider: string) => {\n setBusy(provider);\n try {\n await acc.disconnectIntegration(provider);\n toast({ title: `${provider} disconnected`, variant: 'success' });\n } catch (err) {\n toast({\n title: 'Disconnect failed',\n description: err instanceof Error ? err.message : undefined,\n variant: 'error',\n });\n } finally {\n setBusy('');\n }\n };\n\n const setSetting = async (patch: { autoSyncDaily?: boolean; pushInvoices?: boolean; syncCoaMapping?: boolean }) => {\n try {\n await acc.updateSyncSettings(patch);\n } catch (err) {\n toast({\n title: 'Could not save setting',\n description: err instanceof Error ? err.message : undefined,\n variant: 'error',\n });\n }\n };\n\n const logColumns: Column<AccountingSyncLog>[] = [\n { key: 'syncedAt', header: 'When', render: (r) => formatDate(r.syncedAt) },\n {\n key: 'provider',\n header: 'Provider',\n render: (r) =>\n r.provider === 'ZOHO_BOOKS' ? 'Zoho Books' : r.provider === 'QUICKBOOKS' ? 'QuickBooks' : 'Tally',\n },\n { key: 'entriesCount', header: 'Entries', className: 'text-right', render: (r) => r.entriesCount },\n {\n key: 'status',\n header: 'Status',\n render: (r) => (\n <StatusBadge\n variant={r.status === 'SUCCESS' ? 'success' : r.status === 'FAILED' ? 'error' : 'warning'}\n label={r.status}\n />\n ),\n },\n ];\n\n return (\n <PageLayout\n title=\"Accounting Integrations\"\n description=\"Sync your HealthyBowl ledger with external accounting software.\"\n >\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n {acc.error && !payload ? (\n <ErrorState title=\"Could not load integrations\" description={acc.error.message} />\n ) : acc.loading && !payload ? (\n <LoadingSkeleton variant=\"table\" count={4} />\n ) : (\n <div className=\"space-y-6\">\n <div className=\"grid grid-cols-1 gap-4 md:grid-cols-3\">\n {PROVIDERS.map((p) => {\n const found = payload?.integrations.find((i) => i.provider === p.id);\n const status = found?.status ?? 'NOT_CONNECTED';\n const statusLabel =\n status === 'CONNECTED' ? 'Connected' : status === 'SYNC_READY' ? 'Sync ready' : 'Not connected';\n return (\n <div key={p.id} className=\"rounded-xl border border-border-subtle bg-bg-surface p-4\">\n <div className=\"mb-1 text-base font-semibold text-text-primary\">{p.label}</div>\n <p className=\"mb-3 text-sm text-text-secondary\">{p.blurb}</p>\n <div className=\"mb-3\">\n <StatusBadge\n variant={status === 'CONNECTED' ? 'success' : status === 'SYNC_READY' ? 'warning' : 'muted'}\n label={statusLabel}\n />\n {found && (\n <div className=\"mt-2 text-xs text-text-secondary\">\n {found.lastSyncedAt ? `Last synced ${formatDate(found.lastSyncedAt)} · ` : ''}\n {found.entriesPushed} entries pushed\n </div>\n )}\n </div>\n <div className=\"flex gap-2\">\n {status === 'NOT_CONNECTED' ? (\n <Button size=\"sm\" onClick={() => setConnectFor(p.id)}>\n Connect\n </Button>\n ) : (\n <>\n <Button size=\"sm\" onClick={() => sync(p.id)} disabled={busy === p.id}>\n {busy === p.id ? 'Syncing…' : 'Sync now'}\n </Button>\n <Button size=\"sm\" variant=\"outline\" onClick={() => disconnect(p.id)} disabled={busy === p.id}>\n Disconnect\n </Button>\n </>\n )}\n </div>\n </div>\n );\n })}\n </div>\n\n <ChartCard title=\"Sync Settings\">\n <div className=\"space-y-3\">\n {(\n [\n ['autoSyncDaily', 'Auto-sync journal entries daily'],\n ['pushInvoices', 'Push invoices to accounting system'],\n ['syncCoaMapping', 'Sync chart of accounts mapping'],\n ] as const\n ).map(([key, label]) => (\n <div key={key} className=\"flex items-center justify-between\">\n <span className=\"text-sm text-text-primary\">{label}</span>\n <Switch\n checked={Boolean(payload?.[key])}\n onCheckedChange={(v: boolean) => setSetting({ [key]: v })}\n />\n </div>\n ))}\n </div>\n </ChartCard>\n\n <ChartCard title=\"Recent Sync Log\">\n {payload && payload.syncLogs.length > 0 ? (\n <DataTable columns={logColumns} data={payload.syncLogs} keyField=\"id\" pageSize={10} />\n ) : (\n <EmptyState title=\"No syncs yet\" description=\"Connect a provider and run a sync to see the log here.\" />\n )}\n </ChartCard>\n </div>\n )}\n\n <Modal\n open={connectFor !== null}\n onClose={() => setConnectFor(null)}\n title={`Connect ${connectFor === 'ZOHO_BOOKS' ? 'Zoho Books' : connectFor === 'QUICKBOOKS' ? 'QuickBooks' : 'Tally'}`}\n description=\"Store the non-secret connection details for this provider.\"\n size=\"md\"\n footer={\n <div className=\"flex justify-end gap-2\">\n <Button variant=\"outline\" onClick={() => setConnectFor(null)}>\n Cancel\n </Button>\n <Button onClick={submitConnect} disabled={busy === 'connect'}>\n Connect\n </Button>\n </div>\n }\n >\n <div className=\"space-y-3\">\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Display name (optional)</span>\n <input\n value={displayName}\n onChange={(e) => setDisplayName(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"Green Valley Books\"\n />\n </label>\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">API endpoint / gateway URL (optional)</span>\n <input\n value={endpoint}\n onChange={(e) => setEndpoint(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"https://…\"\n />\n </label>\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Organization id (optional)</span>\n <input\n value={organizationRef}\n onChange={(e) => setOrganizationRef(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"Zoho organization id\"\n />\n </label>\n </div>\n </Modal>\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,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QACZ,CAAA,CACI;;MACR,kBAAC,SAAD;OAAO,WAAU;iBAAjB,CACE,kBAAC,QAAD;QAAM,WAAU;kBAAiC;QAAiC,CAAA,EAClF,kBAAC,SAAD;QACE,OAAO;QACP,WAAW,MAAM,EAAmB,EAAE,OAAO,MAAM;QACnD,WAAW;QACX,aAAY;QACZ,CAAA,CACI;;MACJ;;IACA,CAAA;GACG"}
@@ -0,0 +1,233 @@
1
+ import { formatCurrency as e } from "../../utils/helpers.js";
2
+ import { PageLayout as t } from "../../components/PageLayout.js";
3
+ import { DataTable as n } from "../../components/DataTable.js";
4
+ import { StatusBadge as r } from "../../components/StatusBadge.js";
5
+ import { EmptyState as i } from "../../components/EmptyState.js";
6
+ import { ErrorState as a } from "../../components/ErrorState.js";
7
+ import { ToastContainer as o } from "../../components/Toast.js";
8
+ import { useConfirm as s } from "../../components/ConfirmDialog.js";
9
+ import { LoadingSkeleton as c } from "../../components/LoadingSkeleton.js";
10
+ import { Modal as l } from "../../components/Modal.js";
11
+ import { useToast as u } from "../../hooks/useToast.js";
12
+ import "../../components/index.js";
13
+ import { useHealthyBowlAccounting as d } from "../../hooks/useHealthyBowlAccounting.js";
14
+ import { useEffect as f, useState as p } from "react";
15
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
16
+ import { Button as g } from "@burdenoff/fe-libs/ui";
17
+ //#region src/healthybowl/pages/financial/ChartOfAccountsPage.tsx
18
+ var _ = "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)]", v = [
19
+ "ASSET",
20
+ "LIABILITY",
21
+ "EQUITY",
22
+ "INCOME",
23
+ "EXPENSE"
24
+ ];
25
+ function y() {
26
+ let { toasts: y, toast: b, dismiss: x } = u(), S = s(), C = d({ chartOfAccounts: !0 }), [w, T] = p(!1), [E, D] = p(!1), [O, k] = p(null), [A, j] = p(""), [M, N] = p(""), [P, F] = p("EXPENSE"), [I, L] = p(!1);
27
+ f(() => {
28
+ w || !C.loading && C.chartOfAccounts.length === 0 && !C.error && (T(!0), C.ensureChartOfAccounts().catch(() => void 0));
29
+ }, [C, w]);
30
+ let R = () => {
31
+ k(null), j(""), N(""), F("EXPENSE"), D(!0);
32
+ }, z = (e) => {
33
+ k(e), j(e.code), N(e.name), F(e.accountType), D(!0);
34
+ }, B = async () => {
35
+ if (!M.trim() || !O && !A.trim()) {
36
+ b({
37
+ title: "Code and name are required",
38
+ variant: "error"
39
+ });
40
+ return;
41
+ }
42
+ L(!0);
43
+ try {
44
+ O ? (await C.updateAccount({
45
+ id: O.id,
46
+ name: M.trim(),
47
+ accountType: P
48
+ }), b({
49
+ title: "Account updated",
50
+ variant: "success"
51
+ })) : (await C.createAccount({
52
+ code: A.trim(),
53
+ name: M.trim(),
54
+ accountType: P
55
+ }), b({
56
+ title: "Account created",
57
+ variant: "success"
58
+ })), D(!1);
59
+ } catch (e) {
60
+ b({
61
+ title: "Save failed",
62
+ description: e instanceof Error ? e.message : void 0,
63
+ variant: "error"
64
+ });
65
+ } finally {
66
+ L(!1);
67
+ }
68
+ }, V = async (e) => {
69
+ if (await S({
70
+ title: "Delete account?",
71
+ message: `Delete "${e.code} · ${e.name}"? Accounts used by entries cannot be deleted.`
72
+ })) try {
73
+ await C.deleteAccount(e.id), b({
74
+ title: "Account deleted",
75
+ variant: "success"
76
+ });
77
+ } catch (e) {
78
+ b({
79
+ title: "Delete failed",
80
+ description: e instanceof Error ? e.message : void 0,
81
+ variant: "error"
82
+ });
83
+ }
84
+ };
85
+ return /* @__PURE__ */ h(t, {
86
+ title: "Chart of Accounts",
87
+ description: "The accounts your double-entry ledger posts to.",
88
+ actions: /* @__PURE__ */ m(g, {
89
+ onClick: R,
90
+ children: "New account"
91
+ }),
92
+ children: [
93
+ /* @__PURE__ */ m(o, {
94
+ toasts: y,
95
+ onDismiss: x
96
+ }),
97
+ C.error && C.chartOfAccounts.length === 0 ? /* @__PURE__ */ m(a, {
98
+ title: "Could not load accounts",
99
+ description: C.error.message
100
+ }) : C.loading && C.chartOfAccounts.length === 0 ? /* @__PURE__ */ m(c, {
101
+ variant: "table",
102
+ count: 8
103
+ }) : C.chartOfAccounts.length === 0 ? /* @__PURE__ */ m(i, {
104
+ title: "No accounts yet",
105
+ description: "A default chart of accounts is being set up…"
106
+ }) : /* @__PURE__ */ m(n, {
107
+ columns: [
108
+ {
109
+ key: "code",
110
+ header: "Code",
111
+ render: (e) => e.code
112
+ },
113
+ {
114
+ key: "name",
115
+ header: "Name",
116
+ render: (e) => e.name
117
+ },
118
+ {
119
+ key: "accountType",
120
+ header: "Type",
121
+ render: (e) => e.accountType
122
+ },
123
+ {
124
+ key: "normalBalance",
125
+ header: "Normal",
126
+ render: (e) => e.normalBalance
127
+ },
128
+ {
129
+ key: "balance",
130
+ header: "Balance (₹)",
131
+ className: "text-right",
132
+ render: (t) => e(t.balance, "INR")
133
+ },
134
+ {
135
+ key: "isActive",
136
+ header: "Active",
137
+ render: (e) => /* @__PURE__ */ m(r, {
138
+ variant: e.isActive ? "success" : "muted",
139
+ label: e.isActive ? "Active" : "Inactive"
140
+ })
141
+ },
142
+ {
143
+ key: "actions",
144
+ header: "",
145
+ render: (e) => /* @__PURE__ */ h("div", {
146
+ className: "flex justify-end gap-1",
147
+ children: [/* @__PURE__ */ m(g, {
148
+ variant: "ghost",
149
+ size: "sm",
150
+ onClick: () => z(e),
151
+ children: "Edit"
152
+ }), !e.isSystem && /* @__PURE__ */ m(g, {
153
+ variant: "ghost",
154
+ size: "sm",
155
+ onClick: () => V(e),
156
+ children: "Delete"
157
+ })]
158
+ })
159
+ }
160
+ ],
161
+ data: C.chartOfAccounts,
162
+ keyField: "id",
163
+ pageSize: 20
164
+ }),
165
+ /* @__PURE__ */ m(l, {
166
+ open: E,
167
+ onClose: () => D(!1),
168
+ title: O ? "Edit account" : "New account",
169
+ size: "md",
170
+ footer: /* @__PURE__ */ h("div", {
171
+ className: "flex justify-end gap-2",
172
+ children: [/* @__PURE__ */ m(g, {
173
+ variant: "outline",
174
+ onClick: () => D(!1),
175
+ children: "Cancel"
176
+ }), /* @__PURE__ */ m(g, {
177
+ onClick: B,
178
+ disabled: I,
179
+ children: "Save"
180
+ })]
181
+ }),
182
+ children: /* @__PURE__ */ h("div", {
183
+ className: "space-y-3",
184
+ children: [/* @__PURE__ */ h("div", {
185
+ className: "grid grid-cols-3 gap-3",
186
+ children: [/* @__PURE__ */ h("label", {
187
+ className: "block text-sm",
188
+ children: [/* @__PURE__ */ m("span", {
189
+ className: "mb-1 block text-text-secondary",
190
+ children: "Code"
191
+ }), /* @__PURE__ */ m("input", {
192
+ value: A,
193
+ onChange: (e) => j(e.target.value),
194
+ className: _,
195
+ placeholder: "5100",
196
+ disabled: !!O
197
+ })]
198
+ }), /* @__PURE__ */ h("label", {
199
+ className: "col-span-2 block text-sm",
200
+ children: [/* @__PURE__ */ m("span", {
201
+ className: "mb-1 block text-text-secondary",
202
+ children: "Name"
203
+ }), /* @__PURE__ */ m("input", {
204
+ value: M,
205
+ onChange: (e) => N(e.target.value),
206
+ className: _,
207
+ placeholder: "Seeds & Inputs"
208
+ })]
209
+ })]
210
+ }), /* @__PURE__ */ h("label", {
211
+ className: "block text-sm",
212
+ children: [/* @__PURE__ */ m("span", {
213
+ className: "mb-1 block text-text-secondary",
214
+ children: "Type"
215
+ }), /* @__PURE__ */ m("select", {
216
+ value: P,
217
+ onChange: (e) => F(e.target.value),
218
+ className: _,
219
+ children: v.map((e) => /* @__PURE__ */ m("option", {
220
+ value: e,
221
+ children: e.charAt(0) + e.slice(1).toLowerCase()
222
+ }, e))
223
+ })]
224
+ })]
225
+ })
226
+ })
227
+ ]
228
+ });
229
+ }
230
+ //#endregion
231
+ export { y as ChartOfAccountsPage };
232
+
233
+ //# sourceMappingURL=ChartOfAccountsPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartOfAccountsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/ChartOfAccountsPage.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport {\n PageLayout,\n DataTable,\n StatusBadge,\n Modal,\n LoadingSkeleton,\n ErrorState,\n EmptyState,\n ToastContainer,\n useConfirm,\n} from '../../components';\nimport type { Column } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { formatCurrency } from '../../utils/helpers';\nimport { useHealthyBowlAccounting } from '../../hooks/useHealthyBowlAccounting';\nimport type { LedgerAccount } 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)]';\nconst TYPES = ['ASSET', 'LIABILITY', 'EQUITY', 'INCOME', 'EXPENSE'];\n\nexport function ChartOfAccountsPage() {\n const { toasts, toast, dismiss } = useToast();\n const confirm = useConfirm();\n const acc = useHealthyBowlAccounting({ chartOfAccounts: true });\n const [seeded, setSeeded] = useState(false);\n const [open, setOpen] = useState(false);\n const [editing, setEditing] = useState<LedgerAccount | null>(null);\n const [code, setCode] = useState('');\n const [name, setName] = useState('');\n const [accountType, setAccountType] = useState('EXPENSE');\n const [busy, setBusy] = useState(false);\n\n useEffect(() => {\n if (seeded) return;\n if (!acc.loading && acc.chartOfAccounts.length === 0 && !acc.error) {\n setSeeded(true);\n acc.ensureChartOfAccounts().catch(() => undefined);\n }\n }, [acc, seeded]);\n\n const openCreate = () => {\n setEditing(null);\n setCode('');\n setName('');\n setAccountType('EXPENSE');\n setOpen(true);\n };\n const openEdit = (a: LedgerAccount) => {\n setEditing(a);\n setCode(a.code);\n setName(a.name);\n setAccountType(a.accountType);\n setOpen(true);\n };\n\n const save = async () => {\n if (!name.trim() || (!editing && !code.trim())) {\n toast({ title: 'Code and name are required', variant: 'error' });\n return;\n }\n setBusy(true);\n try {\n if (editing) {\n await acc.updateAccount({ id: editing.id, name: name.trim(), accountType });\n toast({ title: 'Account updated', variant: 'success' });\n } else {\n await acc.createAccount({ code: code.trim(), name: name.trim(), accountType });\n toast({ title: 'Account created', variant: 'success' });\n }\n setOpen(false);\n } catch (err) {\n toast({ title: 'Save failed', description: err instanceof Error ? err.message : undefined, variant: 'error' });\n } finally {\n setBusy(false);\n }\n };\n\n const remove = async (a: LedgerAccount) => {\n const ok = await confirm({\n title: 'Delete account?',\n message: `Delete \"${a.code} · ${a.name}\"? Accounts used by entries cannot be deleted.`,\n });\n if (!ok) return;\n try {\n await acc.deleteAccount(a.id);\n toast({ title: 'Account deleted', variant: 'success' });\n } catch (err) {\n toast({ title: 'Delete failed', description: err instanceof Error ? err.message : undefined, variant: 'error' });\n }\n };\n\n const columns: Column<LedgerAccount>[] = [\n { key: 'code', header: 'Code', render: (a) => a.code },\n { key: 'name', header: 'Name', render: (a) => a.name },\n { key: 'accountType', header: 'Type', render: (a) => a.accountType },\n { key: 'normalBalance', header: 'Normal', render: (a) => a.normalBalance },\n { key: 'balance', header: 'Balance (₹)', className: 'text-right', render: (a) => formatCurrency(a.balance, 'INR') },\n {\n key: 'isActive',\n header: 'Active',\n render: (a) => (\n <StatusBadge variant={a.isActive ? 'success' : 'muted'} label={a.isActive ? 'Active' : 'Inactive'} />\n ),\n },\n {\n key: 'actions',\n header: '',\n render: (a) => (\n <div className=\"flex justify-end gap-1\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => openEdit(a)}>\n Edit\n </Button>\n {!a.isSystem && (\n <Button variant=\"ghost\" size=\"sm\" onClick={() => remove(a)}>\n Delete\n </Button>\n )}\n </div>\n ),\n },\n ];\n\n return (\n <PageLayout\n title=\"Chart of Accounts\"\n description=\"The accounts your double-entry ledger posts to.\"\n actions={<Button onClick={openCreate}>New account</Button>}\n >\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n {acc.error && acc.chartOfAccounts.length === 0 ? (\n <ErrorState title=\"Could not load accounts\" description={acc.error.message} />\n ) : acc.loading && acc.chartOfAccounts.length === 0 ? (\n <LoadingSkeleton variant=\"table\" count={8} />\n ) : acc.chartOfAccounts.length === 0 ? (\n <EmptyState title=\"No accounts yet\" description=\"A default chart of accounts is being set up…\" />\n ) : (\n <DataTable columns={columns} data={acc.chartOfAccounts} keyField=\"id\" pageSize={20} />\n )}\n\n <Modal\n open={open}\n onClose={() => setOpen(false)}\n title={editing ? 'Edit account' : 'New account'}\n size=\"md\"\n footer={\n <div className=\"flex justify-end gap-2\">\n <Button variant=\"outline\" onClick={() => setOpen(false)}>\n Cancel\n </Button>\n <Button onClick={save} disabled={busy}>\n Save\n </Button>\n </div>\n }\n >\n <div className=\"space-y-3\">\n <div className=\"grid grid-cols-3 gap-3\">\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Code</span>\n <input\n value={code}\n onChange={(e) => setCode(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"5100\"\n disabled={!!editing}\n />\n </label>\n <label className=\"col-span-2 block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Name</span>\n <input\n value={name}\n onChange={(e) => setName(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"Seeds & Inputs\"\n />\n </label>\n </div>\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Type</span>\n <select value={accountType} onChange={(e) => setAccountType(e.target.value)} className={INPUT_CLASS}>\n {TYPES.map((t) => (\n <option key={t} value={t}>\n {t.charAt(0) + t.slice(1).toLowerCase()}\n </option>\n ))}\n </select>\n </label>\n </div>\n </Modal>\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,IAAM,IACJ,uMACI,IAAQ;CAAC;CAAS;CAAa;CAAU;CAAU;CAAU;AAEnE,SAAgB,IAAsB;CACpC,IAAM,EAAE,WAAQ,UAAO,eAAY,GAAU,EACvC,IAAU,GAAY,EACtB,IAAM,EAAyB,EAAE,iBAAiB,IAAM,CAAC,EACzD,CAAC,GAAQ,KAAa,EAAS,GAAM,EACr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J;SACN,kBAAC,SAAD;MAAO,WAAU;gBAAjB,CACE,kBAAC,QAAD;OAAM,WAAU;iBAAiC;OAAW,CAAA,EAC5D,kBAAC,UAAD;OAAQ,OAAO;OAAa,WAAW,MAAM,EAAe,EAAE,OAAO,MAAM;OAAE,WAAW;iBACrF,EAAM,KAAK,MACV,kBAAC,UAAD;QAAgB,OAAO;kBACpB,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,aAAa;QAChC,EAFI,EAEJ,CACT;OACK,CAAA,CACH;QACJ;;IACA,CAAA;GACG"}
@@ -0,0 +1,365 @@
1
+ import { formatCurrency as e, formatNumber as t } from "../../utils/helpers.js";
2
+ import { PageLayout as n } from "../../components/PageLayout.js";
3
+ import { StatCard as r } from "../../components/StatCard.js";
4
+ import { DataTable as i } from "../../components/DataTable.js";
5
+ import { EmptyState as a } from "../../components/EmptyState.js";
6
+ import { ErrorState as o } from "../../components/ErrorState.js";
7
+ import { ChartCard as s } from "../../components/ChartCard.js";
8
+ import { ToastContainer as c } from "../../components/Toast.js";
9
+ import { LoadingSkeleton as l } from "../../components/LoadingSkeleton.js";
10
+ import { Modal as u } from "../../components/Modal.js";
11
+ import { useToast as d } from "../../hooks/useToast.js";
12
+ import "../../components/index.js";
13
+ import { Tooltip as f } from "../../../node_modules/recharts/es6/component/Tooltip.js";
14
+ import { ResponsiveContainer as p } from "../../../node_modules/recharts/es6/component/ResponsiveContainer.js";
15
+ import { Cell as m } from "../../../node_modules/recharts/es6/component/Cell.js";
16
+ import { Pie as h } from "../../../node_modules/recharts/es6/polar/Pie.js";
17
+ import { Bar as g } from "../../../node_modules/recharts/es6/cartesian/Bar.js";
18
+ import { XAxis as _ } from "../../../node_modules/recharts/es6/cartesian/XAxis.js";
19
+ import { YAxis as v } from "../../../node_modules/recharts/es6/cartesian/YAxis.js";
20
+ import { BarChart as y } from "../../../node_modules/recharts/es6/chart/BarChart.js";
21
+ import { PieChart as b } from "../../../node_modules/recharts/es6/chart/PieChart.js";
22
+ import { useHealthyBowlAccounting as x } from "../../hooks/useHealthyBowlAccounting.js";
23
+ import { financialYearRange as S } from "../../utils/period.js";
24
+ import { useMemo as C, useState as w } from "react";
25
+ import { jsx as T, jsxs as E } from "react/jsx-runtime";
26
+ import { Button as D } from "@burdenoff/fe-libs/ui";
27
+ //#region src/healthybowl/pages/financial/CostByCropPage.tsx
28
+ var O = "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)]", k = [
29
+ "var(--color-chart-1)",
30
+ "var(--color-chart-2)",
31
+ "var(--color-chart-3)",
32
+ "var(--color-chart-4)",
33
+ "var(--color-chart-5)",
34
+ "var(--color-chart-6)"
35
+ ];
36
+ function A() {
37
+ let { toasts: A, toast: j, dismiss: M } = d(), N = C(() => S(), []), P = x({
38
+ costByCrop: !0,
39
+ costByCropParams: {
40
+ startDate: N.startDate,
41
+ endDate: N.endDate
42
+ },
43
+ costCenters: !0
44
+ }), F = P.costByCrop, [I, L] = w(!1), [R, z] = w(""), [B, V] = w("CROP"), [H, U] = w(""), [W, G] = w("kg"), [K, q] = w(!1), J = async () => {
45
+ if (!R.trim()) {
46
+ j({
47
+ title: "A label is required",
48
+ variant: "error"
49
+ });
50
+ return;
51
+ }
52
+ q(!0);
53
+ try {
54
+ await P.createCostCenter({
55
+ label: R.trim(),
56
+ kind: B,
57
+ yieldQuantity: parseFloat(H) || 0,
58
+ yieldUnit: W
59
+ }), j({
60
+ title: "Cost center created",
61
+ variant: "success"
62
+ }), L(!1), z(""), U("");
63
+ } catch (e) {
64
+ j({
65
+ title: "Could not create cost center",
66
+ description: e instanceof Error ? e.message : void 0,
67
+ variant: "error"
68
+ });
69
+ } finally {
70
+ q(!1);
71
+ }
72
+ }, Y = (F?.rows ?? []).map((e) => ({
73
+ name: e.label,
74
+ margin: e.grossMarginPct ?? 0
75
+ })), X = (F?.allocation ?? []).map((e) => ({
76
+ name: e.label,
77
+ value: e.amount,
78
+ percent: e.percent
79
+ }));
80
+ return /* @__PURE__ */ E(n, {
81
+ title: "Cost by Crop & Per-Animal Profitability",
82
+ description: "Cost/kg, revenue/kg and gross margin, derived from your general-ledger cost allocations.",
83
+ actions: /* @__PURE__ */ T(D, {
84
+ onClick: () => L(!0),
85
+ children: "Add cost center"
86
+ }),
87
+ children: [
88
+ /* @__PURE__ */ T(c, {
89
+ toasts: A,
90
+ onDismiss: M
91
+ }),
92
+ P.error && !F ? /* @__PURE__ */ T(o, {
93
+ title: "Could not load cost-by-crop data",
94
+ description: P.error.message
95
+ }) : P.loading && !F ? /* @__PURE__ */ T(l, {
96
+ variant: "table",
97
+ count: 5
98
+ }) : !F || F.rows.length === 0 ? /* @__PURE__ */ T(a, {
99
+ title: "No cost allocations yet",
100
+ description: "Create a crop/animal cost center, then allocate journal-entry lines to it to see per-crop profitability.",
101
+ action: /* @__PURE__ */ T(D, {
102
+ onClick: () => L(!0),
103
+ children: "Add cost center"
104
+ })
105
+ }) : /* @__PURE__ */ E("div", {
106
+ className: "space-y-6",
107
+ children: [
108
+ /* @__PURE__ */ E("div", {
109
+ className: "grid grid-cols-2 gap-4 lg:grid-cols-4",
110
+ children: [
111
+ /* @__PURE__ */ T(r, {
112
+ hero: !0,
113
+ label: "Gross Margin",
114
+ value: `${F.grossMarginPct}%`
115
+ }),
116
+ /* @__PURE__ */ T(r, {
117
+ label: "Revenue",
118
+ value: e(F.totalRevenue, "INR")
119
+ }),
120
+ /* @__PURE__ */ T(r, {
121
+ label: "Total Cost",
122
+ value: e(F.totalCost, "INR")
123
+ }),
124
+ /* @__PURE__ */ T(r, {
125
+ label: F.bestMarginLabel ? `Best Margin — ${F.bestMarginLabel}` : "Best Margin",
126
+ value: F.bestMarginPct == null ? "—" : `${F.bestMarginPct}%`
127
+ })
128
+ ]
129
+ }),
130
+ /* @__PURE__ */ E("div", {
131
+ className: "grid grid-cols-1 gap-6 xl:grid-cols-2",
132
+ children: [/* @__PURE__ */ T(s, {
133
+ title: "Gross Margin % by Crop & Animal",
134
+ children: /* @__PURE__ */ T(p, {
135
+ width: "100%",
136
+ height: 280,
137
+ children: /* @__PURE__ */ E(y, {
138
+ data: Y,
139
+ layout: "vertical",
140
+ margin: {
141
+ left: 12,
142
+ right: 24
143
+ },
144
+ children: [
145
+ /* @__PURE__ */ T(_, {
146
+ type: "number",
147
+ tick: {
148
+ fill: "var(--color-text-secondary)",
149
+ fontSize: 12
150
+ },
151
+ unit: "%"
152
+ }),
153
+ /* @__PURE__ */ T(v, {
154
+ type: "category",
155
+ dataKey: "name",
156
+ width: 110,
157
+ tick: {
158
+ fill: "var(--color-text-secondary)",
159
+ fontSize: 12
160
+ }
161
+ }),
162
+ /* @__PURE__ */ T(f, {
163
+ contentStyle: {
164
+ background: "var(--color-card)",
165
+ border: "1px solid var(--color-border)",
166
+ borderRadius: 8,
167
+ color: "var(--color-foreground)"
168
+ },
169
+ formatter: (e) => [`${e}%`, "Margin"]
170
+ }),
171
+ /* @__PURE__ */ T(g, {
172
+ dataKey: "margin",
173
+ radius: [
174
+ 0,
175
+ 4,
176
+ 4,
177
+ 0
178
+ ],
179
+ children: Y.map((e, t) => /* @__PURE__ */ T(m, { fill: e.margin >= 0 ? "var(--color-accent-teal)" : "var(--color-destructive)" }, t))
180
+ })
181
+ ]
182
+ })
183
+ })
184
+ }), /* @__PURE__ */ T(s, {
185
+ title: "Cost Allocation",
186
+ children: X.length > 0 ? /* @__PURE__ */ T(p, {
187
+ width: "100%",
188
+ height: 280,
189
+ children: /* @__PURE__ */ E(b, { children: [/* @__PURE__ */ T(h, {
190
+ data: X,
191
+ dataKey: "value",
192
+ nameKey: "name",
193
+ innerRadius: 60,
194
+ outerRadius: 100,
195
+ paddingAngle: 2,
196
+ children: X.map((e, t) => /* @__PURE__ */ T(m, { fill: k[t % k.length] }, t))
197
+ }), /* @__PURE__ */ T(f, {
198
+ contentStyle: {
199
+ background: "var(--color-card)",
200
+ border: "1px solid var(--color-border)",
201
+ borderRadius: 8,
202
+ color: "var(--color-foreground)"
203
+ },
204
+ formatter: (t, n) => [e(t, "INR"), n]
205
+ })] })
206
+ }) : /* @__PURE__ */ T(a, {
207
+ title: "No expense allocations",
208
+ description: "Allocate expense lines to cost centers to see the breakdown."
209
+ })
210
+ })]
211
+ }),
212
+ /* @__PURE__ */ T(s, {
213
+ title: "Per-Crop Economics",
214
+ description: "Figures derived from General Ledger cost allocations",
215
+ children: /* @__PURE__ */ T(i, {
216
+ columns: [
217
+ {
218
+ key: "label",
219
+ header: "Crop / Animal",
220
+ render: (e) => e.label
221
+ },
222
+ {
223
+ key: "yield",
224
+ header: "Yield",
225
+ className: "text-right",
226
+ render: (e) => e.yieldQuantity ? `${t(e.yieldQuantity)} ${e.yieldUnit}` : "—"
227
+ },
228
+ {
229
+ key: "totalCost",
230
+ header: "Total Cost (₹)",
231
+ className: "text-right",
232
+ render: (t) => e(t.totalCost, "INR")
233
+ },
234
+ {
235
+ key: "revenue",
236
+ header: "Revenue (₹)",
237
+ className: "text-right",
238
+ render: (t) => e(t.revenue, "INR")
239
+ },
240
+ {
241
+ key: "costPerKg",
242
+ header: "Cost/kg (₹)",
243
+ className: "text-right",
244
+ render: (t) => t.costPerKg == null ? "—" : e(t.costPerKg, "INR")
245
+ },
246
+ {
247
+ key: "revenuePerKg",
248
+ header: "Revenue/kg (₹)",
249
+ className: "text-right",
250
+ render: (t) => t.revenuePerKg == null ? "—" : e(t.revenuePerKg, "INR")
251
+ },
252
+ {
253
+ key: "grossMarginPct",
254
+ header: "Gross Margin %",
255
+ className: "text-right",
256
+ render: (e) => e.grossMarginPct == null ? "—" : /* @__PURE__ */ E("span", {
257
+ className: e.grossMarginPct >= 0 ? "text-success" : "text-destructive",
258
+ children: [e.grossMarginPct, "%"]
259
+ })
260
+ }
261
+ ],
262
+ data: F.rows,
263
+ keyField: "costCenterId",
264
+ pageSize: 15
265
+ })
266
+ })
267
+ ]
268
+ }),
269
+ /* @__PURE__ */ T(u, {
270
+ open: I,
271
+ onClose: () => L(!1),
272
+ title: "Add cost center",
273
+ description: "A crop cycle or animal group to attribute costs and revenue to.",
274
+ size: "md",
275
+ footer: /* @__PURE__ */ E("div", {
276
+ className: "flex justify-end gap-2",
277
+ children: [/* @__PURE__ */ T(D, {
278
+ variant: "outline",
279
+ onClick: () => L(!1),
280
+ children: "Cancel"
281
+ }), /* @__PURE__ */ T(D, {
282
+ onClick: J,
283
+ disabled: K,
284
+ children: "Create"
285
+ })]
286
+ }),
287
+ children: /* @__PURE__ */ E("div", {
288
+ className: "space-y-3",
289
+ children: [/* @__PURE__ */ E("label", {
290
+ className: "block text-sm",
291
+ children: [/* @__PURE__ */ T("span", {
292
+ className: "mb-1 block text-text-secondary",
293
+ children: "Label"
294
+ }), /* @__PURE__ */ T("input", {
295
+ value: R,
296
+ onChange: (e) => z(e.target.value),
297
+ className: O,
298
+ placeholder: "Tomato — Cycle T-14"
299
+ })]
300
+ }), /* @__PURE__ */ E("div", {
301
+ className: "grid grid-cols-3 gap-3",
302
+ children: [
303
+ /* @__PURE__ */ E("label", {
304
+ className: "block text-sm",
305
+ children: [/* @__PURE__ */ T("span", {
306
+ className: "mb-1 block text-text-secondary",
307
+ children: "Kind"
308
+ }), /* @__PURE__ */ E("select", {
309
+ value: B,
310
+ onChange: (e) => V(e.target.value),
311
+ className: O,
312
+ children: [
313
+ /* @__PURE__ */ T("option", {
314
+ value: "CROP",
315
+ children: "Crop"
316
+ }),
317
+ /* @__PURE__ */ T("option", {
318
+ value: "ANIMAL",
319
+ children: "Animal"
320
+ }),
321
+ /* @__PURE__ */ T("option", {
322
+ value: "OTHER",
323
+ children: "Other"
324
+ })
325
+ ]
326
+ })]
327
+ }),
328
+ /* @__PURE__ */ E("label", {
329
+ className: "block text-sm",
330
+ children: [/* @__PURE__ */ T("span", {
331
+ className: "mb-1 block text-text-secondary",
332
+ children: "Yield"
333
+ }), /* @__PURE__ */ T("input", {
334
+ type: "number",
335
+ min: "0",
336
+ step: "0.01",
337
+ value: H,
338
+ onChange: (e) => U(e.target.value),
339
+ className: O,
340
+ placeholder: "3200"
341
+ })]
342
+ }),
343
+ /* @__PURE__ */ E("label", {
344
+ className: "block text-sm",
345
+ children: [/* @__PURE__ */ T("span", {
346
+ className: "mb-1 block text-text-secondary",
347
+ children: "Unit"
348
+ }), /* @__PURE__ */ T("input", {
349
+ value: W,
350
+ onChange: (e) => G(e.target.value),
351
+ className: O,
352
+ placeholder: "kg"
353
+ })]
354
+ })
355
+ ]
356
+ })]
357
+ })
358
+ })
359
+ ]
360
+ });
361
+ }
362
+ //#endregion
363
+ export { A as CostByCropPage };
364
+
365
+ //# sourceMappingURL=CostByCropPage.js.map