@burdenoff/microfe-healthybowl 2026.714.6 → 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 +135 -95
- 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/hooks/useWeatherIntelligence.js +224 -0
- package/dist/healthybowl/hooks/useWeatherIntelligence.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/pages/weather/FrostRiskCalendarPage.js +258 -0
- package/dist/healthybowl/pages/weather/FrostRiskCalendarPage.js.map +1 -0
- package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js +255 -0
- package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js.map +1 -0
- package/dist/healthybowl/pages/weather/WeatherAnomalyReportPage.js +387 -0
- package/dist/healthybowl/pages/weather/WeatherAnomalyReportPage.js.map +1 -0
- package/dist/healthybowl/pages/weather/WeatherHistoryPage.js +313 -114
- package/dist/healthybowl/pages/weather/WeatherHistoryPage.js.map +1 -1
- package/dist/healthybowl/pages/weather/WeatherOverviewPage.js +554 -213
- package/dist/healthybowl/pages/weather/WeatherOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/weather/WeatherSettingsPage.js +457 -0
- package/dist/healthybowl/pages/weather/WeatherSettingsPage.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,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CostByCropPage.js","names":[],"sources":["../../../../src/healthybowl/pages/financial/CostByCropPage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { Bar, BarChart, Cell, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport {\n PageLayout,\n StatCard,\n ChartCard,\n DataTable,\n Modal,\n LoadingSkeleton,\n ErrorState,\n EmptyState,\n ToastContainer,\n} from '../../components';\nimport type { Column } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { formatCurrency, formatNumber } from '../../utils/helpers';\nimport { financialYearRange } from '../../utils/period';\nimport { useHealthyBowlAccounting } from '../../hooks/useHealthyBowlAccounting';\nimport type { CropProfitability } 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 ALLOC_COLORS = [\n 'var(--color-chart-1)',\n 'var(--color-chart-2)',\n 'var(--color-chart-3)',\n 'var(--color-chart-4)',\n 'var(--color-chart-5)',\n 'var(--color-chart-6)',\n];\n\nexport function CostByCropPage() {\n const { toasts, toast, dismiss } = useToast();\n const period = useMemo(() => financialYearRange(), []);\n const acc = useHealthyBowlAccounting({\n costByCrop: true,\n costByCropParams: { startDate: period.startDate, endDate: period.endDate },\n costCenters: true,\n });\n const report = acc.costByCrop;\n const [addOpen, setAddOpen] = useState(false);\n const [label, setLabel] = useState('');\n const [kind, setKind] = useState('CROP');\n const [yieldQuantity, setYieldQuantity] = useState('');\n const [yieldUnit, setYieldUnit] = useState('kg');\n const [busy, setBusy] = useState(false);\n\n const addCostCenter = async () => {\n if (!label.trim()) {\n toast({ title: 'A label is required', variant: 'error' });\n return;\n }\n setBusy(true);\n try {\n await acc.createCostCenter({\n label: label.trim(),\n kind,\n yieldQuantity: parseFloat(yieldQuantity) || 0,\n yieldUnit,\n });\n toast({ title: 'Cost center created', variant: 'success' });\n setAddOpen(false);\n setLabel('');\n setYieldQuantity('');\n } catch (err) {\n toast({\n title: 'Could not create cost center',\n description: err instanceof Error ? err.message : undefined,\n variant: 'error',\n });\n } finally {\n setBusy(false);\n }\n };\n\n const barData = (report?.rows ?? []).map((r) => ({ name: r.label, margin: r.grossMarginPct ?? 0 }));\n const allocData = (report?.allocation ?? []).map((a) => ({ name: a.label, value: a.amount, percent: a.percent }));\n\n const columns: Column<CropProfitability>[] = [\n { key: 'label', header: 'Crop / Animal', render: (r) => r.label },\n {\n key: 'yield',\n header: 'Yield',\n className: 'text-right',\n render: (r) => (r.yieldQuantity ? `${formatNumber(r.yieldQuantity)} ${r.yieldUnit}` : '—'),\n },\n {\n key: 'totalCost',\n header: 'Total Cost (₹)',\n className: 'text-right',\n render: (r) => formatCurrency(r.totalCost, 'INR'),\n },\n { key: 'revenue', header: 'Revenue (₹)', className: 'text-right', render: (r) => formatCurrency(r.revenue, 'INR') },\n {\n key: 'costPerKg',\n header: 'Cost/kg (₹)',\n className: 'text-right',\n render: (r) => (r.costPerKg == null ? '—' : formatCurrency(r.costPerKg, 'INR')),\n },\n {\n key: 'revenuePerKg',\n header: 'Revenue/kg (₹)',\n className: 'text-right',\n render: (r) => (r.revenuePerKg == null ? '—' : formatCurrency(r.revenuePerKg, 'INR')),\n },\n {\n key: 'grossMarginPct',\n header: 'Gross Margin %',\n className: 'text-right',\n render: (r) =>\n r.grossMarginPct == null ? (\n '—'\n ) : (\n <span className={r.grossMarginPct >= 0 ? 'text-success' : 'text-destructive'}>{r.grossMarginPct}%</span>\n ),\n },\n ];\n\n return (\n <PageLayout\n title=\"Cost by Crop & Per-Animal Profitability\"\n description=\"Cost/kg, revenue/kg and gross margin, derived from your general-ledger cost allocations.\"\n actions={<Button onClick={() => setAddOpen(true)}>Add cost center</Button>}\n >\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n {acc.error && !report ? (\n <ErrorState title=\"Could not load cost-by-crop data\" description={acc.error.message} />\n ) : acc.loading && !report ? (\n <LoadingSkeleton variant=\"table\" count={5} />\n ) : !report || report.rows.length === 0 ? (\n <EmptyState\n title=\"No cost allocations yet\"\n description=\"Create a crop/animal cost center, then allocate journal-entry lines to it to see per-crop profitability.\"\n action={<Button onClick={() => setAddOpen(true)}>Add cost center</Button>}\n />\n ) : (\n <div className=\"space-y-6\">\n <div className=\"grid grid-cols-2 gap-4 lg:grid-cols-4\">\n <StatCard hero label=\"Gross Margin\" value={`${report.grossMarginPct}%`} />\n <StatCard label=\"Revenue\" value={formatCurrency(report.totalRevenue, 'INR')} />\n <StatCard label=\"Total Cost\" value={formatCurrency(report.totalCost, 'INR')} />\n <StatCard\n label={report.bestMarginLabel ? `Best Margin — ${report.bestMarginLabel}` : 'Best Margin'}\n value={report.bestMarginPct == null ? '—' : `${report.bestMarginPct}%`}\n />\n </div>\n\n <div className=\"grid grid-cols-1 gap-6 xl:grid-cols-2\">\n <ChartCard title=\"Gross Margin % by Crop & Animal\">\n <ResponsiveContainer width=\"100%\" height={280}>\n <BarChart data={barData} layout=\"vertical\" margin={{ left: 12, right: 24 }}>\n <XAxis type=\"number\" tick={{ fill: 'var(--color-text-secondary)', fontSize: 12 }} unit=\"%\" />\n <YAxis\n type=\"category\"\n dataKey=\"name\"\n width={110}\n tick={{ fill: 'var(--color-text-secondary)', fontSize: 12 }}\n />\n <Tooltip\n contentStyle={{\n background: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: 8,\n color: 'var(--color-foreground)',\n }}\n formatter={(v: number) => [`${v}%`, 'Margin']}\n />\n <Bar dataKey=\"margin\" radius={[0, 4, 4, 0]}>\n {barData.map((d, i) => (\n <Cell key={i} fill={d.margin >= 0 ? 'var(--color-accent-teal)' : 'var(--color-destructive)'} />\n ))}\n </Bar>\n </BarChart>\n </ResponsiveContainer>\n </ChartCard>\n\n <ChartCard title=\"Cost Allocation\">\n {allocData.length > 0 ? (\n <ResponsiveContainer width=\"100%\" height={280}>\n <PieChart>\n <Pie\n data={allocData}\n dataKey=\"value\"\n nameKey=\"name\"\n innerRadius={60}\n outerRadius={100}\n paddingAngle={2}\n >\n {allocData.map((_, i) => (\n <Cell key={i} fill={ALLOC_COLORS[i % ALLOC_COLORS.length]} />\n ))}\n </Pie>\n <Tooltip\n contentStyle={{\n background: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: 8,\n color: 'var(--color-foreground)',\n }}\n formatter={(v: number, n: string) => [formatCurrency(v, 'INR'), n]}\n />\n </PieChart>\n </ResponsiveContainer>\n ) : (\n <EmptyState\n title=\"No expense allocations\"\n description=\"Allocate expense lines to cost centers to see the breakdown.\"\n />\n )}\n </ChartCard>\n </div>\n\n <ChartCard title=\"Per-Crop Economics\" description=\"Figures derived from General Ledger cost allocations\">\n <DataTable columns={columns} data={report.rows} keyField=\"costCenterId\" pageSize={15} />\n </ChartCard>\n </div>\n )}\n\n <Modal\n open={addOpen}\n onClose={() => setAddOpen(false)}\n title=\"Add cost center\"\n description=\"A crop cycle or animal group to attribute costs and revenue to.\"\n size=\"md\"\n footer={\n <div className=\"flex justify-end gap-2\">\n <Button variant=\"outline\" onClick={() => setAddOpen(false)}>\n Cancel\n </Button>\n <Button onClick={addCostCenter} disabled={busy}>\n Create\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\">Label</span>\n <input\n value={label}\n onChange={(e) => setLabel(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"Tomato — Cycle T-14\"\n />\n </label>\n <div className=\"grid grid-cols-3 gap-3\">\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Kind</span>\n <select value={kind} onChange={(e) => setKind(e.target.value)} className={INPUT_CLASS}>\n <option value=\"CROP\">Crop</option>\n <option value=\"ANIMAL\">Animal</option>\n <option value=\"OTHER\">Other</option>\n </select>\n </label>\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Yield</span>\n <input\n type=\"number\"\n min=\"0\"\n step=\"0.01\"\n value={yieldQuantity}\n onChange={(e) => setYieldQuantity(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"3200\"\n />\n </label>\n <label className=\"block text-sm\">\n <span className=\"mb-1 block text-text-secondary\">Unit</span>\n <input\n value={yieldUnit}\n onChange={(e) => setYieldUnit(e.target.value)}\n className={INPUT_CLASS}\n placeholder=\"kg\"\n />\n </label>\n </div>\n </div>\n </Modal>\n </PageLayout>\n );\n}\n"],"mappings":";;;;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