@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,316 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t, useMemo as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ import { useMutation as i, useQuery as a } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useHealthyBowlAccounting.ts
6
+ var o = "00000000-0000-0000-0000-000000000001", s = "id code name accountType normalBalance description isActive isSystem sortOrder balance createdAt updatedAt", c = "id entryNumber date memo reference status source totalDebit totalCredit balanced billingOrderId billingSyncStatus postedAt lines { id accountId accountCode accountName accountType description debit credit costCenterId costCenterLabel lineOrder } createdAt updatedAt", l = "rows { id entryId entryNumber date accountCode accountName accountType description reference debit credit runningBalance costCenterLabel } totalDebit totalCredit rowCount hasMore", u = "periodLabel currency income { code name amount } expenses { code name amount } totalRevenue totalExpenses netProfit grossMarginPct generatedAt", d = "id code label kind refType refId season yieldQuantity yieldUnit isActive createdAt updatedAt", f = "rows { costCenterId code label kind yieldQuantity yieldUnit totalCost revenue costPerKg revenuePerKg grossMarginPct } allocation { label amount percent } totalRevenue totalCost grossMarginPct bestMarginLabel bestMarginPct", p = "integrations { id provider status displayName endpoint organizationRef lastSyncedAt entriesPushed autoSyncDaily pushInvoices syncCoaMapping } syncLogs { id provider entriesCount status message batchRef syncedAt } autoSyncDaily pushInvoices syncCoaMapping", m = r`query HbChartOfAccounts($context: ContextInput!, $accountType: String, $activeOnly: Boolean) {
7
+ getHealthyBowlChartOfAccounts(context: $context, accountType: $accountType, activeOnly: $activeOnly) { ${s} } }`, h = r`query HbGeneralLedger($context: ContextInput!, $accountType: String, $accountId: ID, $startDate: String, $endDate: String, $search: String, $limit: Int, $offset: Int) {
8
+ getHealthyBowlGeneralLedger(context: $context, accountType: $accountType, accountId: $accountId, startDate: $startDate, endDate: $endDate, search: $search, limit: $limit, offset: $offset) { ${l} } }`, g = r`query HbJournalEntries($context: ContextInput!, $status: String, $startDate: String, $endDate: String, $limit: Int, $offset: Int) {
9
+ getHealthyBowlJournalEntries(context: $context, status: $status, startDate: $startDate, endDate: $endDate, limit: $limit, offset: $offset) { ${c} } }`, _ = r`query HbProfitAndLoss($context: ContextInput!, $startDate: String!, $endDate: String!) {
10
+ getHealthyBowlProfitAndLoss(context: $context, startDate: $startDate, endDate: $endDate) { ${u} } }`, ee = r`
11
+ query HbPnlExport($context: ContextInput!, $startDate: String!, $endDate: String!, $format: String!) {
12
+ getHealthyBowlProfitAndLossExport(context: $context, startDate: $startDate, endDate: $endDate, format: $format) {
13
+ format
14
+ filename
15
+ mimeType
16
+ contentBase64
17
+ byteSize
18
+ }
19
+ }
20
+ `, v = r`query HbCostByCrop($context: ContextInput!, $startDate: String, $endDate: String, $kind: String) {
21
+ getHealthyBowlCostByCrop(context: $context, startDate: $startDate, endDate: $endDate, kind: $kind) { ${f} } }`, y = r`query HbCostCenters($context: ContextInput!, $kind: String, $activeOnly: Boolean) {
22
+ getHealthyBowlCostCenters(context: $context, kind: $kind, activeOnly: $activeOnly) { ${d} } }`, b = r`query HbAccountingIntegrations($context: ContextInput!) {
23
+ getHealthyBowlAccountingIntegrations(context: $context) { ${p} } }`, x = r`mutation HbEnsureCoa($context: ContextInput!) { ensureHealthyBowlChartOfAccounts(context: $context) { ${s} } }`, S = r`mutation HbCreateAccount($input: CreateHealthyBowlLedgerAccountInput!) { createHealthyBowlLedgerAccount(input: $input) { ${s} } }`, C = r`mutation HbUpdateAccount($input: UpdateHealthyBowlLedgerAccountInput!) { updateHealthyBowlLedgerAccount(input: $input) { ${s} } }`, w = r`
24
+ mutation HbDeleteAccount($id: ID!, $context: ContextInput!) {
25
+ deleteHealthyBowlLedgerAccount(id: $id, context: $context)
26
+ }
27
+ `, T = r`mutation HbPostEntry($input: PostHealthyBowlJournalEntryInput!) { postHealthyBowlJournalEntry(input: $input) { ${c} } }`, E = r`mutation HbSaveDraft($input: PostHealthyBowlJournalEntryInput!) { saveHealthyBowlJournalEntryDraft(input: $input) { ${c} } }`, D = r`mutation HbVoidEntry($id: ID!, $context: ContextInput!) { voidHealthyBowlJournalEntry(id: $id, context: $context) { ${c} } }`, te = r`mutation HbPushBilling($id: ID!, $context: ContextInput!) { pushHealthyBowlJournalEntryToBilling(id: $id, context: $context) { ${c} } }`, O = r`mutation HbCreateCostCenter($input: CreateHealthyBowlCostCenterInput!) { createHealthyBowlCostCenter(input: $input) { ${d} } }`, k = r`mutation HbUpdateCostCenter($input: UpdateHealthyBowlCostCenterInput!) { updateHealthyBowlCostCenter(input: $input) { ${d} } }`, A = r`
28
+ mutation HbDeleteCostCenter($id: ID!, $context: ContextInput!) {
29
+ deleteHealthyBowlCostCenter(id: $id, context: $context)
30
+ }
31
+ `, ne = r`
32
+ mutation HbConnect($input: ConnectHealthyBowlAccountingIntegrationInput!) {
33
+ connectHealthyBowlAccountingIntegration(input: $input) {
34
+ id
35
+ provider
36
+ status
37
+ }
38
+ }
39
+ `, re = r`
40
+ mutation HbDisconnect($provider: String!, $context: ContextInput!) {
41
+ disconnectHealthyBowlAccountingIntegration(provider: $provider, context: $context) {
42
+ id
43
+ provider
44
+ status
45
+ }
46
+ }
47
+ `, ie = r`mutation HbSyncSettings($input: UpdateHealthyBowlAccountingSyncSettingsInput!) { updateHealthyBowlAccountingSyncSettings(input: $input) { ${p} } }`, j = r`
48
+ mutation HbSync($input: SyncHealthyBowlAccountingInput!) {
49
+ syncHealthyBowlAccountingIntegration(input: $input) {
50
+ provider
51
+ status
52
+ entriesCount
53
+ message
54
+ log {
55
+ id
56
+ provider
57
+ entriesCount
58
+ status
59
+ message
60
+ batchRef
61
+ syncedAt
62
+ }
63
+ integration {
64
+ id
65
+ provider
66
+ status
67
+ entriesPushed
68
+ lastSyncedAt
69
+ }
70
+ }
71
+ }
72
+ `;
73
+ function M(r = {}) {
74
+ let { workspaceId: s } = e(), c = s || o, l = n(() => ({ workspaceId: c }), [c]), u = t((e) => ({
75
+ ...e,
76
+ context: l
77
+ }), [l]), d = a(m, {
78
+ variables: {
79
+ context: l,
80
+ accountType: r.chartOfAccountsType ?? null,
81
+ activeOnly: !1
82
+ },
83
+ fetchPolicy: "cache-and-network",
84
+ skip: !r.chartOfAccounts
85
+ }), f = a(h, {
86
+ variables: {
87
+ context: l,
88
+ ...r.ledgerFilters
89
+ },
90
+ fetchPolicy: "cache-and-network",
91
+ skip: !r.generalLedger
92
+ }), p = a(g, {
93
+ variables: {
94
+ context: l,
95
+ limit: 50
96
+ },
97
+ fetchPolicy: "cache-and-network",
98
+ skip: !r.journalEntries
99
+ }), M = a(_, {
100
+ variables: {
101
+ context: l,
102
+ startDate: r.pnlRange?.startDate ?? "",
103
+ endDate: r.pnlRange?.endDate ?? ""
104
+ },
105
+ fetchPolicy: "cache-and-network",
106
+ skip: !r.profitAndLoss || !r.pnlRange
107
+ }), N = a(v, {
108
+ variables: {
109
+ context: l,
110
+ startDate: r.costByCropParams?.startDate ?? null,
111
+ endDate: r.costByCropParams?.endDate ?? null,
112
+ kind: r.costByCropParams?.kind ?? null
113
+ },
114
+ fetchPolicy: "cache-and-network",
115
+ skip: !r.costByCrop
116
+ }), P = a(y, {
117
+ variables: {
118
+ context: l,
119
+ activeOnly: !1
120
+ },
121
+ fetchPolicy: "cache-and-network",
122
+ skip: !r.costCenters
123
+ }), F = a(b, {
124
+ variables: { context: l },
125
+ fetchPolicy: "cache-and-network",
126
+ skip: !r.integrations
127
+ }), I = t(async () => {
128
+ let e = [];
129
+ r.chartOfAccounts && e.push(d.refetch()), r.generalLedger && e.push(f.refetch()), r.journalEntries && e.push(p.refetch()), r.profitAndLoss && r.pnlRange && e.push(M.refetch()), r.costByCrop && e.push(N.refetch()), r.costCenters && e.push(P.refetch()), r.integrations && e.push(F.refetch()), await Promise.all(e);
130
+ }, [
131
+ r,
132
+ d,
133
+ f,
134
+ p,
135
+ M,
136
+ N,
137
+ P,
138
+ F
139
+ ]), [L] = i(x), [R] = i(S), [z] = i(C), [B] = i(w), [V] = i(T), [H] = i(E), [U] = i(D), [W] = i(te), [G] = i(O), [K] = i(k), [q] = i(A), [J] = i(ne), [Y] = i(re), [X] = i(ie), [Z] = i(j), [Q] = i(ee), ae = t(async () => {
140
+ let e = await L({ variables: { context: l } });
141
+ if (e.error) throw e.error;
142
+ return await I(), e.data?.ensureHealthyBowlChartOfAccounts ?? [];
143
+ }, [
144
+ L,
145
+ l,
146
+ I
147
+ ]), oe = t(async (e) => {
148
+ let t = await R({ variables: { input: u(e) } });
149
+ if (t.error) throw t.error;
150
+ await I();
151
+ }, [
152
+ R,
153
+ u,
154
+ I
155
+ ]), se = t(async (e) => {
156
+ let t = await z({ variables: { input: u(e) } });
157
+ if (t.error) throw t.error;
158
+ await I();
159
+ }, [
160
+ z,
161
+ u,
162
+ I
163
+ ]), ce = t(async (e) => {
164
+ let t = await B({ variables: {
165
+ id: e,
166
+ context: l
167
+ } });
168
+ if (t.error) throw t.error;
169
+ await I();
170
+ }, [
171
+ B,
172
+ l,
173
+ I
174
+ ]), le = t(async (e) => {
175
+ let t = await V({ variables: { input: u(e) } });
176
+ if (t.error) throw t.error;
177
+ return await I(), t.data?.postHealthyBowlJournalEntry ?? null;
178
+ }, [
179
+ V,
180
+ u,
181
+ I
182
+ ]), ue = t(async (e) => {
183
+ let t = await H({ variables: { input: u(e) } });
184
+ if (t.error) throw t.error;
185
+ return await I(), t.data?.saveHealthyBowlJournalEntryDraft ?? null;
186
+ }, [
187
+ H,
188
+ u,
189
+ I
190
+ ]), de = t(async (e) => {
191
+ let t = await U({ variables: {
192
+ id: e,
193
+ context: l
194
+ } });
195
+ if (t.error) throw t.error;
196
+ await I();
197
+ }, [
198
+ U,
199
+ l,
200
+ I
201
+ ]), fe = t(async (e) => {
202
+ let t = await W({ variables: {
203
+ id: e,
204
+ context: l
205
+ } });
206
+ if (t.error) throw t.error;
207
+ return await I(), t.data?.pushHealthyBowlJournalEntryToBilling ?? null;
208
+ }, [
209
+ W,
210
+ l,
211
+ I
212
+ ]), pe = t(async (e) => {
213
+ let t = await G({ variables: { input: u(e) } });
214
+ if (t.error) throw t.error;
215
+ await I();
216
+ }, [
217
+ G,
218
+ u,
219
+ I
220
+ ]), $ = t(async (e) => {
221
+ let t = await K({ variables: { input: u(e) } });
222
+ if (t.error) throw t.error;
223
+ await I();
224
+ }, [
225
+ K,
226
+ u,
227
+ I
228
+ ]), me = t(async (e) => {
229
+ let t = await q({ variables: {
230
+ id: e,
231
+ context: l
232
+ } });
233
+ if (t.error) throw t.error;
234
+ await I();
235
+ }, [
236
+ q,
237
+ l,
238
+ I
239
+ ]), he = t(async (e) => {
240
+ let t = await J({ variables: { input: u(e) } });
241
+ if (t.error) throw t.error;
242
+ await I();
243
+ }, [
244
+ J,
245
+ u,
246
+ I
247
+ ]), ge = t(async (e) => {
248
+ let t = await Y({ variables: {
249
+ provider: e,
250
+ context: l
251
+ } });
252
+ if (t.error) throw t.error;
253
+ await I();
254
+ }, [
255
+ Y,
256
+ l,
257
+ I
258
+ ]), _e = t(async (e) => {
259
+ let t = await X({ variables: { input: u(e) } });
260
+ if (t.error) throw t.error;
261
+ await I();
262
+ }, [
263
+ X,
264
+ u,
265
+ I
266
+ ]), ve = t(async (e) => {
267
+ let t = await Z({ variables: { input: u({ provider: e }) } });
268
+ if (t.error) throw t.error;
269
+ return await I(), t.data?.syncHealthyBowlAccountingIntegration ?? null;
270
+ }, [
271
+ Z,
272
+ u,
273
+ I
274
+ ]), ye = t(async (e, t, n) => {
275
+ let r = await Q({ variables: {
276
+ context: l,
277
+ startDate: e,
278
+ endDate: t,
279
+ format: n
280
+ } });
281
+ if (r.error) throw r.error;
282
+ return r.data?.getHealthyBowlProfitAndLossExport ?? null;
283
+ }, [Q, l]);
284
+ return {
285
+ chartOfAccounts: d.data?.getHealthyBowlChartOfAccounts ?? [],
286
+ generalLedger: f.data?.getHealthyBowlGeneralLedger ?? null,
287
+ journalEntries: p.data?.getHealthyBowlJournalEntries ?? [],
288
+ profitAndLoss: M.data?.getHealthyBowlProfitAndLoss ?? null,
289
+ costByCrop: N.data?.getHealthyBowlCostByCrop ?? null,
290
+ costCenters: P.data?.getHealthyBowlCostCenters ?? [],
291
+ integrations: F.data?.getHealthyBowlAccountingIntegrations ?? null,
292
+ loading: d.loading || f.loading || p.loading || M.loading || N.loading || P.loading || F.loading,
293
+ error: d.error || f.error || p.error || M.error || N.error || P.error || F.error || null,
294
+ reconcile: I,
295
+ ensureChartOfAccounts: ae,
296
+ createAccount: oe,
297
+ updateAccount: se,
298
+ deleteAccount: ce,
299
+ postJournalEntry: le,
300
+ saveDraft: ue,
301
+ voidEntry: de,
302
+ pushEntryToBilling: fe,
303
+ createCostCenter: pe,
304
+ updateCostCenter: $,
305
+ deleteCostCenter: me,
306
+ connectIntegration: he,
307
+ disconnectIntegration: ge,
308
+ updateSyncSettings: _e,
309
+ syncIntegration: ve,
310
+ exportProfitAndLoss: ye
311
+ };
312
+ }
313
+ //#endregion
314
+ export { M as useHealthyBowlAccounting };
315
+
316
+ //# sourceMappingURL=useHealthyBowlAccounting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHealthyBowlAccounting.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlAccounting.ts"],"sourcesContent":["/**\n * Farm Accounting — data hook (BOFF-2888 · roadmap 16).\n *\n * Chart of accounts, double-entry general ledger, Profit & Loss (+ CSV/PDF export),\n * cost-by-crop / per-animal profitability, and Tally/Zoho/QuickBooks integrations.\n * Documents are declared inline with `gql` (not `src/operations/wspace/*.graphql`)\n * because codegen validates operations against the committed `graphql/wspace.graphql`\n * snapshot, which can't know about these fields until the accounting subgraph is live\n * in the supergraph — the same escape hatch `useHealthyBowlDistribution` uses. Types\n * mirror `wspace-healthybowl-svc/src/modules/healthybowl/schema/accounting.gql`.\n *\n * Reads use `cache-and-network`; pages opt into only the sections they render (all\n * default off). Every write throws on error then reconciles the reads it invalidates.\n */\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\n// ── types (mirror accounting.gql) ─────────────────────────────────────────────\nexport type AccountType = 'ASSET' | 'LIABILITY' | 'EQUITY' | 'INCOME' | 'EXPENSE';\nexport type AccountingProvider = 'TALLY' | 'ZOHO_BOOKS' | 'QUICKBOOKS';\nexport type CostCenterKind = 'CROP' | 'ANIMAL' | 'OTHER';\n\nexport interface LedgerAccount {\n id: string;\n code: string;\n name: string;\n accountType: string;\n normalBalance: string;\n description: string | null;\n isActive: boolean;\n isSystem: boolean;\n sortOrder: number;\n balance: number;\n createdAt: string;\n updatedAt: string;\n}\nexport interface JournalLine {\n id: string;\n accountId: string;\n accountCode: string;\n accountName: string;\n accountType: string;\n description: string | null;\n debit: number;\n credit: number;\n costCenterId: string | null;\n costCenterLabel: string | null;\n lineOrder: number;\n}\nexport interface JournalEntry {\n id: string;\n entryNumber: string;\n date: string;\n memo: string;\n reference: string | null;\n status: string;\n source: string;\n totalDebit: number;\n totalCredit: number;\n balanced: boolean;\n billingOrderId: string | null;\n billingSyncStatus: string | null;\n postedAt: string | null;\n lines: JournalLine[];\n createdAt: string;\n updatedAt: string;\n}\nexport interface GeneralLedgerRow {\n id: string;\n entryId: string;\n entryNumber: string;\n date: string;\n accountCode: string;\n accountName: string;\n accountType: string;\n description: string | null;\n reference: string | null;\n debit: number;\n credit: number;\n runningBalance: number;\n costCenterLabel: string | null;\n}\nexport interface GeneralLedger {\n rows: GeneralLedgerRow[];\n totalDebit: number;\n totalCredit: number;\n rowCount: number;\n hasMore: boolean;\n}\nexport interface PnlLine {\n code: string;\n name: string;\n amount: number;\n}\nexport interface ProfitAndLoss {\n periodLabel: string;\n currency: string;\n income: PnlLine[];\n expenses: PnlLine[];\n totalRevenue: number;\n totalExpenses: number;\n netProfit: number;\n grossMarginPct: number;\n generatedAt: string;\n}\nexport interface AccountingExport {\n format: string;\n filename: string;\n mimeType: string;\n contentBase64: string;\n byteSize: number;\n}\nexport interface CostCenter {\n id: string;\n code: string;\n label: string;\n kind: string;\n refType: string | null;\n refId: string | null;\n season: string | null;\n yieldQuantity: number;\n yieldUnit: string;\n isActive: boolean;\n createdAt: string;\n updatedAt: string;\n}\nexport interface CropProfitability {\n costCenterId: string;\n code: string;\n label: string;\n kind: string;\n yieldQuantity: number;\n yieldUnit: string;\n totalCost: number;\n revenue: number;\n costPerKg: number | null;\n revenuePerKg: number | null;\n grossMarginPct: number | null;\n}\nexport interface CostAllocationSlice {\n label: string;\n amount: number;\n percent: number;\n}\nexport interface CostByCropReport {\n rows: CropProfitability[];\n allocation: CostAllocationSlice[];\n totalRevenue: number;\n totalCost: number;\n grossMarginPct: number;\n bestMarginLabel: string | null;\n bestMarginPct: number | null;\n}\nexport interface AccountingIntegration {\n id: string;\n provider: string;\n status: string;\n displayName: string | null;\n endpoint: string | null;\n organizationRef: string | null;\n lastSyncedAt: string | null;\n entriesPushed: number;\n autoSyncDaily: boolean;\n pushInvoices: boolean;\n syncCoaMapping: boolean;\n}\nexport interface AccountingSyncLog {\n id: string;\n provider: string;\n entriesCount: number;\n status: string;\n message: string | null;\n batchRef: string | null;\n syncedAt: string;\n}\nexport interface IntegrationsPayload {\n integrations: AccountingIntegration[];\n syncLogs: AccountingSyncLog[];\n autoSyncDaily: boolean;\n pushInvoices: boolean;\n syncCoaMapping: boolean;\n}\n\ninterface HbContext {\n workspaceId: string;\n}\nexport interface JournalLineInput {\n accountId?: string | null;\n accountCode?: string | null;\n description?: string | null;\n debit?: number;\n credit?: number;\n costCenterId?: string | null;\n}\n\n// ── fragments ──────────────────────────────────────────────────────────────────\nconst ACCOUNT_FIELDS = `id code name accountType normalBalance description isActive isSystem sortOrder balance createdAt updatedAt`;\nconst LINE_FIELDS = `id accountId accountCode accountName accountType description debit credit costCenterId costCenterLabel lineOrder`;\nconst ENTRY_FIELDS = `id entryNumber date memo reference status source totalDebit totalCredit balanced billingOrderId billingSyncStatus postedAt lines { ${LINE_FIELDS} } createdAt updatedAt`;\nconst GL_FIELDS = `rows { id entryId entryNumber date accountCode accountName accountType description reference debit credit runningBalance costCenterLabel } totalDebit totalCredit rowCount hasMore`;\nconst PNL_FIELDS = `periodLabel currency income { code name amount } expenses { code name amount } totalRevenue totalExpenses netProfit grossMarginPct generatedAt`;\nconst COST_CENTER_FIELDS = `id code label kind refType refId season yieldQuantity yieldUnit isActive createdAt updatedAt`;\nconst COST_BY_CROP_FIELDS = `rows { costCenterId code label kind yieldQuantity yieldUnit totalCost revenue costPerKg revenuePerKg grossMarginPct } allocation { label amount percent } totalRevenue totalCost grossMarginPct bestMarginLabel bestMarginPct`;\nconst INTEGRATIONS_FIELDS = `integrations { id provider status displayName endpoint organizationRef lastSyncedAt entriesPushed autoSyncDaily pushInvoices syncCoaMapping } syncLogs { id provider entriesCount status message batchRef syncedAt } autoSyncDaily pushInvoices syncCoaMapping`;\n\n// ── queries ─────────────────────────────────────────────────────────────────────\nconst GET_CHART_OF_ACCOUNTS = gql`query HbChartOfAccounts($context: ContextInput!, $accountType: String, $activeOnly: Boolean) {\n getHealthyBowlChartOfAccounts(context: $context, accountType: $accountType, activeOnly: $activeOnly) { ${ACCOUNT_FIELDS} } }`;\nconst GET_GENERAL_LEDGER = gql`query HbGeneralLedger($context: ContextInput!, $accountType: String, $accountId: ID, $startDate: String, $endDate: String, $search: String, $limit: Int, $offset: Int) {\n getHealthyBowlGeneralLedger(context: $context, accountType: $accountType, accountId: $accountId, startDate: $startDate, endDate: $endDate, search: $search, limit: $limit, offset: $offset) { ${GL_FIELDS} } }`;\nconst GET_JOURNAL_ENTRIES = gql`query HbJournalEntries($context: ContextInput!, $status: String, $startDate: String, $endDate: String, $limit: Int, $offset: Int) {\n getHealthyBowlJournalEntries(context: $context, status: $status, startDate: $startDate, endDate: $endDate, limit: $limit, offset: $offset) { ${ENTRY_FIELDS} } }`;\nconst GET_PROFIT_AND_LOSS = gql`query HbProfitAndLoss($context: ContextInput!, $startDate: String!, $endDate: String!) {\n getHealthyBowlProfitAndLoss(context: $context, startDate: $startDate, endDate: $endDate) { ${PNL_FIELDS} } }`;\nconst GET_PNL_EXPORT = gql`\n query HbPnlExport($context: ContextInput!, $startDate: String!, $endDate: String!, $format: String!) {\n getHealthyBowlProfitAndLossExport(context: $context, startDate: $startDate, endDate: $endDate, format: $format) {\n format\n filename\n mimeType\n contentBase64\n byteSize\n }\n }\n`;\nconst GET_COST_BY_CROP = gql`query HbCostByCrop($context: ContextInput!, $startDate: String, $endDate: String, $kind: String) {\n getHealthyBowlCostByCrop(context: $context, startDate: $startDate, endDate: $endDate, kind: $kind) { ${COST_BY_CROP_FIELDS} } }`;\nconst GET_COST_CENTERS = gql`query HbCostCenters($context: ContextInput!, $kind: String, $activeOnly: Boolean) {\n getHealthyBowlCostCenters(context: $context, kind: $kind, activeOnly: $activeOnly) { ${COST_CENTER_FIELDS} } }`;\nconst GET_INTEGRATIONS = gql`query HbAccountingIntegrations($context: ContextInput!) {\n getHealthyBowlAccountingIntegrations(context: $context) { ${INTEGRATIONS_FIELDS} } }`;\n\n// ── mutations ─────────────────────────────────────────────────────────────────\nconst ENSURE_COA = gql`mutation HbEnsureCoa($context: ContextInput!) { ensureHealthyBowlChartOfAccounts(context: $context) { ${ACCOUNT_FIELDS} } }`;\nconst CREATE_ACCOUNT = gql`mutation HbCreateAccount($input: CreateHealthyBowlLedgerAccountInput!) { createHealthyBowlLedgerAccount(input: $input) { ${ACCOUNT_FIELDS} } }`;\nconst UPDATE_ACCOUNT = gql`mutation HbUpdateAccount($input: UpdateHealthyBowlLedgerAccountInput!) { updateHealthyBowlLedgerAccount(input: $input) { ${ACCOUNT_FIELDS} } }`;\nconst DELETE_ACCOUNT = gql`\n mutation HbDeleteAccount($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlLedgerAccount(id: $id, context: $context)\n }\n`;\nconst POST_ENTRY = gql`mutation HbPostEntry($input: PostHealthyBowlJournalEntryInput!) { postHealthyBowlJournalEntry(input: $input) { ${ENTRY_FIELDS} } }`;\nconst SAVE_DRAFT = gql`mutation HbSaveDraft($input: PostHealthyBowlJournalEntryInput!) { saveHealthyBowlJournalEntryDraft(input: $input) { ${ENTRY_FIELDS} } }`;\nconst VOID_ENTRY = gql`mutation HbVoidEntry($id: ID!, $context: ContextInput!) { voidHealthyBowlJournalEntry(id: $id, context: $context) { ${ENTRY_FIELDS} } }`;\nconst PUSH_TO_BILLING = gql`mutation HbPushBilling($id: ID!, $context: ContextInput!) { pushHealthyBowlJournalEntryToBilling(id: $id, context: $context) { ${ENTRY_FIELDS} } }`;\nconst CREATE_COST_CENTER = gql`mutation HbCreateCostCenter($input: CreateHealthyBowlCostCenterInput!) { createHealthyBowlCostCenter(input: $input) { ${COST_CENTER_FIELDS} } }`;\nconst UPDATE_COST_CENTER = gql`mutation HbUpdateCostCenter($input: UpdateHealthyBowlCostCenterInput!) { updateHealthyBowlCostCenter(input: $input) { ${COST_CENTER_FIELDS} } }`;\nconst DELETE_COST_CENTER = gql`\n mutation HbDeleteCostCenter($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlCostCenter(id: $id, context: $context)\n }\n`;\nconst CONNECT_INTEGRATION = gql`\n mutation HbConnect($input: ConnectHealthyBowlAccountingIntegrationInput!) {\n connectHealthyBowlAccountingIntegration(input: $input) {\n id\n provider\n status\n }\n }\n`;\nconst DISCONNECT_INTEGRATION = gql`\n mutation HbDisconnect($provider: String!, $context: ContextInput!) {\n disconnectHealthyBowlAccountingIntegration(provider: $provider, context: $context) {\n id\n provider\n status\n }\n }\n`;\nconst UPDATE_SYNC_SETTINGS = gql`mutation HbSyncSettings($input: UpdateHealthyBowlAccountingSyncSettingsInput!) { updateHealthyBowlAccountingSyncSettings(input: $input) { ${INTEGRATIONS_FIELDS} } }`;\nconst SYNC_INTEGRATION = gql`\n mutation HbSync($input: SyncHealthyBowlAccountingInput!) {\n syncHealthyBowlAccountingIntegration(input: $input) {\n provider\n status\n entriesCount\n message\n log {\n id\n provider\n entriesCount\n status\n message\n batchRef\n syncedAt\n }\n integration {\n id\n provider\n status\n entriesPushed\n lastSyncedAt\n }\n }\n }\n`;\n\nexport interface UseAccountingOptions {\n chartOfAccounts?: boolean;\n chartOfAccountsType?: string | null;\n generalLedger?: boolean;\n ledgerFilters?: {\n accountType?: string | null;\n accountId?: string | null;\n startDate?: string | null;\n endDate?: string | null;\n search?: string | null;\n limit?: number | null;\n offset?: number | null;\n };\n journalEntries?: boolean;\n profitAndLoss?: boolean;\n pnlRange?: { startDate: string; endDate: string };\n costByCrop?: boolean;\n costByCropParams?: { startDate?: string | null; endDate?: string | null; kind?: string | null };\n costCenters?: boolean;\n integrations?: boolean;\n}\n\nexport function useHealthyBowlAccounting(options: UseAccountingOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const context = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n const withCtx = useCallback(<T extends object>(input: T) => ({ ...input, context }), [context]);\n\n const coaQuery = useQuery<{ getHealthyBowlChartOfAccounts: LedgerAccount[] }>(GET_CHART_OF_ACCOUNTS, {\n variables: { context, accountType: options.chartOfAccountsType ?? null, activeOnly: false },\n fetchPolicy: 'cache-and-network',\n skip: !options.chartOfAccounts,\n });\n const glQuery = useQuery<{ getHealthyBowlGeneralLedger: GeneralLedger }>(GET_GENERAL_LEDGER, {\n variables: { context, ...options.ledgerFilters },\n fetchPolicy: 'cache-and-network',\n skip: !options.generalLedger,\n });\n const entriesQuery = useQuery<{ getHealthyBowlJournalEntries: JournalEntry[] }>(GET_JOURNAL_ENTRIES, {\n variables: { context, limit: 50 },\n fetchPolicy: 'cache-and-network',\n skip: !options.journalEntries,\n });\n const pnlQuery = useQuery<{ getHealthyBowlProfitAndLoss: ProfitAndLoss }>(GET_PROFIT_AND_LOSS, {\n variables: { context, startDate: options.pnlRange?.startDate ?? '', endDate: options.pnlRange?.endDate ?? '' },\n fetchPolicy: 'cache-and-network',\n skip: !options.profitAndLoss || !options.pnlRange,\n });\n const cbcQuery = useQuery<{ getHealthyBowlCostByCrop: CostByCropReport }>(GET_COST_BY_CROP, {\n variables: {\n context,\n startDate: options.costByCropParams?.startDate ?? null,\n endDate: options.costByCropParams?.endDate ?? null,\n kind: options.costByCropParams?.kind ?? null,\n },\n fetchPolicy: 'cache-and-network',\n skip: !options.costByCrop,\n });\n const centersQuery = useQuery<{ getHealthyBowlCostCenters: CostCenter[] }>(GET_COST_CENTERS, {\n variables: { context, activeOnly: false },\n fetchPolicy: 'cache-and-network',\n skip: !options.costCenters,\n });\n const integrationsQuery = useQuery<{ getHealthyBowlAccountingIntegrations: IntegrationsPayload }>(GET_INTEGRATIONS, {\n variables: { context },\n fetchPolicy: 'cache-and-network',\n skip: !options.integrations,\n });\n\n const reconcile = useCallback(async () => {\n const jobs: Promise<unknown>[] = [];\n if (options.chartOfAccounts) jobs.push(coaQuery.refetch());\n if (options.generalLedger) jobs.push(glQuery.refetch());\n if (options.journalEntries) jobs.push(entriesQuery.refetch());\n if (options.profitAndLoss && options.pnlRange) jobs.push(pnlQuery.refetch());\n if (options.costByCrop) jobs.push(cbcQuery.refetch());\n if (options.costCenters) jobs.push(centersQuery.refetch());\n if (options.integrations) jobs.push(integrationsQuery.refetch());\n await Promise.all(jobs);\n }, [options, coaQuery, glQuery, entriesQuery, pnlQuery, cbcQuery, centersQuery, integrationsQuery]);\n\n const [ensureCoaM] = useMutation(ENSURE_COA);\n const [createAccountM] = useMutation(CREATE_ACCOUNT);\n const [updateAccountM] = useMutation(UPDATE_ACCOUNT);\n const [deleteAccountM] = useMutation(DELETE_ACCOUNT);\n const [postEntryM] = useMutation(POST_ENTRY);\n const [saveDraftM] = useMutation(SAVE_DRAFT);\n const [voidEntryM] = useMutation(VOID_ENTRY);\n const [pushBillingM] = useMutation(PUSH_TO_BILLING);\n const [createCenterM] = useMutation(CREATE_COST_CENTER);\n const [updateCenterM] = useMutation(UPDATE_COST_CENTER);\n const [deleteCenterM] = useMutation(DELETE_COST_CENTER);\n const [connectM] = useMutation(CONNECT_INTEGRATION);\n const [disconnectM] = useMutation(DISCONNECT_INTEGRATION);\n const [syncSettingsM] = useMutation(UPDATE_SYNC_SETTINGS);\n const [syncM] = useMutation(SYNC_INTEGRATION);\n const [pnlExportM] = useMutation(GET_PNL_EXPORT); // query-shaped, but invoked imperatively via useMutation for on-demand fetch\n\n const ensureChartOfAccounts = useCallback(async () => {\n const res = await ensureCoaM({ variables: { context } });\n if (res.error) throw res.error;\n await reconcile();\n return (\n (res.data as { ensureHealthyBowlChartOfAccounts: LedgerAccount[] } | undefined)\n ?.ensureHealthyBowlChartOfAccounts ?? []\n );\n }, [ensureCoaM, context, reconcile]);\n\n const createAccount = useCallback(\n async (input: {\n code: string;\n name: string;\n accountType: string;\n description?: string | null;\n sortOrder?: number;\n }) => {\n const res = await createAccountM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [createAccountM, withCtx, reconcile]\n );\n const updateAccount = useCallback(\n async (input: {\n id: string;\n name?: string;\n accountType?: string;\n description?: string | null;\n isActive?: boolean;\n sortOrder?: number;\n }) => {\n const res = await updateAccountM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [updateAccountM, withCtx, reconcile]\n );\n const deleteAccount = useCallback(\n async (id: string) => {\n const res = await deleteAccountM({ variables: { id, context } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [deleteAccountM, context, reconcile]\n );\n\n const postJournalEntry = useCallback(\n async (input: {\n date?: string;\n memo: string;\n reference?: string | null;\n source?: string;\n lines: JournalLineInput[];\n }) => {\n const res = await postEntryM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n return (\n (res.data as { postHealthyBowlJournalEntry: JournalEntry } | undefined)?.postHealthyBowlJournalEntry ?? null\n );\n },\n [postEntryM, withCtx, reconcile]\n );\n const saveDraft = useCallback(\n async (input: {\n date?: string;\n memo: string;\n reference?: string | null;\n source?: string;\n lines: JournalLineInput[];\n }) => {\n const res = await saveDraftM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n return (\n (res.data as { saveHealthyBowlJournalEntryDraft: JournalEntry } | undefined)\n ?.saveHealthyBowlJournalEntryDraft ?? null\n );\n },\n [saveDraftM, withCtx, reconcile]\n );\n const voidEntry = useCallback(\n async (id: string) => {\n const res = await voidEntryM({ variables: { id, context } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [voidEntryM, context, reconcile]\n );\n const pushEntryToBilling = useCallback(\n async (id: string) => {\n const res = await pushBillingM({ variables: { id, context } });\n if (res.error) throw res.error;\n await reconcile();\n return (\n (res.data as { pushHealthyBowlJournalEntryToBilling: JournalEntry } | undefined)\n ?.pushHealthyBowlJournalEntryToBilling ?? null\n );\n },\n [pushBillingM, context, reconcile]\n );\n\n const createCostCenter = useCallback(\n async (input: {\n code?: string;\n label: string;\n kind: string;\n refType?: string | null;\n refId?: string | null;\n season?: string | null;\n yieldQuantity?: number;\n yieldUnit?: string;\n }) => {\n const res = await createCenterM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [createCenterM, withCtx, reconcile]\n );\n const updateCostCenter = useCallback(\n async (input: {\n id: string;\n label?: string;\n kind?: string;\n season?: string | null;\n yieldQuantity?: number;\n yieldUnit?: string;\n isActive?: boolean;\n }) => {\n const res = await updateCenterM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [updateCenterM, withCtx, reconcile]\n );\n const deleteCostCenter = useCallback(\n async (id: string) => {\n const res = await deleteCenterM({ variables: { id, context } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [deleteCenterM, context, reconcile]\n );\n\n const connectIntegration = useCallback(\n async (input: {\n provider: string;\n displayName?: string | null;\n endpoint?: string | null;\n organizationRef?: string | null;\n }) => {\n const res = await connectM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [connectM, withCtx, reconcile]\n );\n const disconnectIntegration = useCallback(\n async (provider: string) => {\n const res = await disconnectM({ variables: { provider, context } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [disconnectM, context, reconcile]\n );\n const updateSyncSettings = useCallback(\n async (input: { autoSyncDaily?: boolean; pushInvoices?: boolean; syncCoaMapping?: boolean }) => {\n const res = await syncSettingsM({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile();\n },\n [syncSettingsM, withCtx, reconcile]\n );\n const syncIntegration = useCallback(\n async (provider: string) => {\n const res = await syncM({ variables: { input: withCtx({ provider }) } });\n if (res.error) throw res.error;\n await reconcile();\n return (\n (\n res.data as\n | { syncHealthyBowlAccountingIntegration: { status: string; entriesCount: number; message: string } }\n | undefined\n )?.syncHealthyBowlAccountingIntegration ?? null\n );\n },\n [syncM, withCtx, reconcile]\n );\n\n const exportProfitAndLoss = useCallback(\n async (startDate: string, endDate: string, format: 'CSV' | 'PDF'): Promise<AccountingExport | null> => {\n const res = await pnlExportM({ variables: { context, startDate, endDate, format } });\n if (res.error) throw res.error;\n return (\n (res.data as { getHealthyBowlProfitAndLossExport: AccountingExport } | undefined)\n ?.getHealthyBowlProfitAndLossExport ?? null\n );\n },\n [pnlExportM, context]\n );\n\n return {\n // data\n chartOfAccounts: coaQuery.data?.getHealthyBowlChartOfAccounts ?? [],\n generalLedger: glQuery.data?.getHealthyBowlGeneralLedger ?? null,\n journalEntries: entriesQuery.data?.getHealthyBowlJournalEntries ?? [],\n profitAndLoss: pnlQuery.data?.getHealthyBowlProfitAndLoss ?? null,\n costByCrop: cbcQuery.data?.getHealthyBowlCostByCrop ?? null,\n costCenters: centersQuery.data?.getHealthyBowlCostCenters ?? [],\n integrations: integrationsQuery.data?.getHealthyBowlAccountingIntegrations ?? null,\n // status\n loading:\n coaQuery.loading ||\n glQuery.loading ||\n entriesQuery.loading ||\n pnlQuery.loading ||\n cbcQuery.loading ||\n centersQuery.loading ||\n integrationsQuery.loading,\n error:\n coaQuery.error ||\n glQuery.error ||\n entriesQuery.error ||\n pnlQuery.error ||\n cbcQuery.error ||\n centersQuery.error ||\n integrationsQuery.error ||\n null,\n reconcile,\n // mutations\n ensureChartOfAccounts,\n createAccount,\n updateAccount,\n deleteAccount,\n postJournalEntry,\n saveDraft,\n voidEntry,\n pushEntryToBilling,\n createCostCenter,\n updateCostCenter,\n deleteCostCenter,\n connectIntegration,\n disconnectIntegration,\n updateSyncSettings,\n syncIntegration,\n exportProfitAndLoss,\n };\n}\n"],"mappings":";;;;;AAmBA,IAAM,IAAwB,wCAqLxB,IAAiB,8GAEjB,IAAe,6QACf,IAAY,sLACZ,IAAa,kJACb,IAAqB,gGACrB,IAAsB,iOACtB,IAAsB,kQAGtB,IAAwB,CAAG;2GAC0E,EAAe,OACpH,IAAqB,CAAG;kMACoK,EAAU,OACtM,IAAsB,CAAG;iJACkH,EAAa,OACxJ,IAAsB,CAAG;+FACgE,EAAW,OACpG,KAAiB,CAAG;;;;;;;;;;GAWpB,IAAmB,CAAG;yGAC6E,EAAoB,OACvH,IAAmB,CAAG;yFAC6D,EAAmB,OACtG,IAAmB,CAAG;8DACkC,EAAoB,OAG5E,IAAa,CAAG,yGAAyG,EAAe,OACxI,IAAiB,CAAG,4HAA4H,EAAe,OAC/J,IAAiB,CAAG,4HAA4H,EAAe,OAC/J,IAAiB,CAAG;;;;GAKpB,IAAa,CAAG,kHAAkH,EAAa,OAC/I,IAAa,CAAG,uHAAuH,EAAa,OACpJ,IAAa,CAAG,uHAAuH,EAAa,OACpJ,KAAkB,CAAG,kIAAkI,EAAa,OACpK,IAAqB,CAAG,yHAAyH,EAAmB,OACpK,IAAqB,CAAG,yHAAyH,EAAmB,OACpK,IAAqB,CAAG;;;;GAKxB,KAAsB,CAAG;;;;;;;;GASzB,KAAyB,CAAG;;;;;;;;GAS5B,KAAuB,CAAG,6IAA6I,EAAoB,OAC3L,IAAmB,CAAG;;;;;;;;;;;;;;;;;;;;;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;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,297 @@
1
+ import { formatDate 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 { ChartCard as o } from "../../components/ChartCard.js";
8
+ import { ToastContainer as s } from "../../components/Toast.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 { useState as f } from "react";
15
+ import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
16
+ import { Button as g, Switch as _ } from "@burdenoff/fe-libs/ui";
17
+ //#region src/healthybowl/pages/financial/AccountingIntegrationsPage.tsx
18
+ var v = "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)]", y = [
19
+ {
20
+ id: "TALLY",
21
+ label: "Tally",
22
+ blurb: "Push journal entries to Tally via its XML import gateway."
23
+ },
24
+ {
25
+ id: "ZOHO_BOOKS",
26
+ label: "Zoho Books",
27
+ blurb: "Sync journals and invoices with your Zoho Books organization."
28
+ },
29
+ {
30
+ id: "QUICKBOOKS",
31
+ label: "QuickBooks",
32
+ blurb: "Export journal entries to QuickBooks Online."
33
+ }
34
+ ];
35
+ function b() {
36
+ let { toasts: b, toast: x, dismiss: S } = u(), C = d({ integrations: !0 }), w = C.integrations, [T, E] = f(null), [D, O] = f(""), [k, A] = f(""), [j, M] = f(""), [N, P] = f(""), F = async () => {
37
+ if (T) {
38
+ P("connect");
39
+ try {
40
+ await C.connectIntegration({
41
+ provider: T,
42
+ displayName: D || null,
43
+ endpoint: k || null,
44
+ organizationRef: j || null
45
+ }), x({
46
+ title: `${T} connected`,
47
+ variant: "success"
48
+ }), E(null), O(""), A(""), M("");
49
+ } catch (e) {
50
+ x({
51
+ title: "Connect failed",
52
+ description: e instanceof Error ? e.message : void 0,
53
+ variant: "error"
54
+ });
55
+ } finally {
56
+ P("");
57
+ }
58
+ }
59
+ }, I = async (e) => {
60
+ P(e);
61
+ try {
62
+ let t = await C.syncIntegration(e);
63
+ x({
64
+ title: t?.message ?? "Sync complete",
65
+ variant: t?.status === "FAILED" ? "warning" : "success"
66
+ });
67
+ } catch (e) {
68
+ x({
69
+ title: "Sync failed",
70
+ description: e instanceof Error ? e.message : void 0,
71
+ variant: "error"
72
+ });
73
+ } finally {
74
+ P("");
75
+ }
76
+ }, L = async (e) => {
77
+ P(e);
78
+ try {
79
+ await C.disconnectIntegration(e), x({
80
+ title: `${e} disconnected`,
81
+ variant: "success"
82
+ });
83
+ } catch (e) {
84
+ x({
85
+ title: "Disconnect failed",
86
+ description: e instanceof Error ? e.message : void 0,
87
+ variant: "error"
88
+ });
89
+ } finally {
90
+ P("");
91
+ }
92
+ }, R = async (e) => {
93
+ try {
94
+ await C.updateSyncSettings(e);
95
+ } catch (e) {
96
+ x({
97
+ title: "Could not save setting",
98
+ description: e instanceof Error ? e.message : void 0,
99
+ variant: "error"
100
+ });
101
+ }
102
+ };
103
+ return /* @__PURE__ */ h(t, {
104
+ title: "Accounting Integrations",
105
+ description: "Sync your HealthyBowl ledger with external accounting software.",
106
+ children: [
107
+ /* @__PURE__ */ m(s, {
108
+ toasts: b,
109
+ onDismiss: S
110
+ }),
111
+ C.error && !w ? /* @__PURE__ */ m(a, {
112
+ title: "Could not load integrations",
113
+ description: C.error.message
114
+ }) : C.loading && !w ? /* @__PURE__ */ m(c, {
115
+ variant: "table",
116
+ count: 4
117
+ }) : /* @__PURE__ */ h("div", {
118
+ className: "space-y-6",
119
+ children: [
120
+ /* @__PURE__ */ m("div", {
121
+ className: "grid grid-cols-1 gap-4 md:grid-cols-3",
122
+ children: y.map((t) => {
123
+ let n = w?.integrations.find((e) => e.provider === t.id), i = n?.status ?? "NOT_CONNECTED", a = i === "CONNECTED" ? "Connected" : i === "SYNC_READY" ? "Sync ready" : "Not connected";
124
+ return /* @__PURE__ */ h("div", {
125
+ className: "rounded-xl border border-border-subtle bg-bg-surface p-4",
126
+ children: [
127
+ /* @__PURE__ */ m("div", {
128
+ className: "mb-1 text-base font-semibold text-text-primary",
129
+ children: t.label
130
+ }),
131
+ /* @__PURE__ */ m("p", {
132
+ className: "mb-3 text-sm text-text-secondary",
133
+ children: t.blurb
134
+ }),
135
+ /* @__PURE__ */ h("div", {
136
+ className: "mb-3",
137
+ children: [/* @__PURE__ */ m(r, {
138
+ variant: i === "CONNECTED" ? "success" : i === "SYNC_READY" ? "warning" : "muted",
139
+ label: a
140
+ }), n && /* @__PURE__ */ h("div", {
141
+ className: "mt-2 text-xs text-text-secondary",
142
+ children: [
143
+ n.lastSyncedAt ? `Last synced ${e(n.lastSyncedAt)} · ` : "",
144
+ n.entriesPushed,
145
+ " entries pushed"
146
+ ]
147
+ })]
148
+ }),
149
+ /* @__PURE__ */ m("div", {
150
+ className: "flex gap-2",
151
+ children: i === "NOT_CONNECTED" ? /* @__PURE__ */ m(g, {
152
+ size: "sm",
153
+ onClick: () => E(t.id),
154
+ children: "Connect"
155
+ }) : /* @__PURE__ */ h(p, { children: [/* @__PURE__ */ m(g, {
156
+ size: "sm",
157
+ onClick: () => I(t.id),
158
+ disabled: N === t.id,
159
+ children: N === t.id ? "Syncing…" : "Sync now"
160
+ }), /* @__PURE__ */ m(g, {
161
+ size: "sm",
162
+ variant: "outline",
163
+ onClick: () => L(t.id),
164
+ disabled: N === t.id,
165
+ children: "Disconnect"
166
+ })] })
167
+ })
168
+ ]
169
+ }, t.id);
170
+ })
171
+ }),
172
+ /* @__PURE__ */ m(o, {
173
+ title: "Sync Settings",
174
+ children: /* @__PURE__ */ m("div", {
175
+ className: "space-y-3",
176
+ children: [
177
+ ["autoSyncDaily", "Auto-sync journal entries daily"],
178
+ ["pushInvoices", "Push invoices to accounting system"],
179
+ ["syncCoaMapping", "Sync chart of accounts mapping"]
180
+ ].map(([e, t]) => /* @__PURE__ */ h("div", {
181
+ className: "flex items-center justify-between",
182
+ children: [/* @__PURE__ */ m("span", {
183
+ className: "text-sm text-text-primary",
184
+ children: t
185
+ }), /* @__PURE__ */ m(_, {
186
+ checked: !!w?.[e],
187
+ onCheckedChange: (t) => R({ [e]: t })
188
+ })]
189
+ }, e))
190
+ })
191
+ }),
192
+ /* @__PURE__ */ m(o, {
193
+ title: "Recent Sync Log",
194
+ children: w && w.syncLogs.length > 0 ? /* @__PURE__ */ m(n, {
195
+ columns: [
196
+ {
197
+ key: "syncedAt",
198
+ header: "When",
199
+ render: (t) => e(t.syncedAt)
200
+ },
201
+ {
202
+ key: "provider",
203
+ header: "Provider",
204
+ render: (e) => e.provider === "ZOHO_BOOKS" ? "Zoho Books" : e.provider === "QUICKBOOKS" ? "QuickBooks" : "Tally"
205
+ },
206
+ {
207
+ key: "entriesCount",
208
+ header: "Entries",
209
+ className: "text-right",
210
+ render: (e) => e.entriesCount
211
+ },
212
+ {
213
+ key: "status",
214
+ header: "Status",
215
+ render: (e) => /* @__PURE__ */ m(r, {
216
+ variant: e.status === "SUCCESS" ? "success" : e.status === "FAILED" ? "error" : "warning",
217
+ label: e.status
218
+ })
219
+ }
220
+ ],
221
+ data: w.syncLogs,
222
+ keyField: "id",
223
+ pageSize: 10
224
+ }) : /* @__PURE__ */ m(i, {
225
+ title: "No syncs yet",
226
+ description: "Connect a provider and run a sync to see the log here."
227
+ })
228
+ })
229
+ ]
230
+ }),
231
+ /* @__PURE__ */ m(l, {
232
+ open: T !== null,
233
+ onClose: () => E(null),
234
+ title: `Connect ${T === "ZOHO_BOOKS" ? "Zoho Books" : T === "QUICKBOOKS" ? "QuickBooks" : "Tally"}`,
235
+ description: "Store the non-secret connection details for this provider.",
236
+ size: "md",
237
+ footer: /* @__PURE__ */ h("div", {
238
+ className: "flex justify-end gap-2",
239
+ children: [/* @__PURE__ */ m(g, {
240
+ variant: "outline",
241
+ onClick: () => E(null),
242
+ children: "Cancel"
243
+ }), /* @__PURE__ */ m(g, {
244
+ onClick: F,
245
+ disabled: N === "connect",
246
+ children: "Connect"
247
+ })]
248
+ }),
249
+ children: /* @__PURE__ */ h("div", {
250
+ className: "space-y-3",
251
+ children: [
252
+ /* @__PURE__ */ h("label", {
253
+ className: "block text-sm",
254
+ children: [/* @__PURE__ */ m("span", {
255
+ className: "mb-1 block text-text-secondary",
256
+ children: "Display name (optional)"
257
+ }), /* @__PURE__ */ m("input", {
258
+ value: D,
259
+ onChange: (e) => O(e.target.value),
260
+ className: v,
261
+ placeholder: "Green Valley Books"
262
+ })]
263
+ }),
264
+ /* @__PURE__ */ h("label", {
265
+ className: "block text-sm",
266
+ children: [/* @__PURE__ */ m("span", {
267
+ className: "mb-1 block text-text-secondary",
268
+ children: "API endpoint / gateway URL (optional)"
269
+ }), /* @__PURE__ */ m("input", {
270
+ value: k,
271
+ onChange: (e) => A(e.target.value),
272
+ className: v,
273
+ placeholder: "https://…"
274
+ })]
275
+ }),
276
+ /* @__PURE__ */ h("label", {
277
+ className: "block text-sm",
278
+ children: [/* @__PURE__ */ m("span", {
279
+ className: "mb-1 block text-text-secondary",
280
+ children: "Organization id (optional)"
281
+ }), /* @__PURE__ */ m("input", {
282
+ value: j,
283
+ onChange: (e) => M(e.target.value),
284
+ className: v,
285
+ placeholder: "Zoho organization id"
286
+ })]
287
+ })
288
+ ]
289
+ })
290
+ })
291
+ ]
292
+ });
293
+ }
294
+ //#endregion
295
+ export { b as AccountingIntegrationsPage };
296
+
297
+ //# sourceMappingURL=AccountingIntegrationsPage.js.map