@fayz-ai/plugin-financial 0.9.0 → 0.9.2
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/README.md +3 -3
- package/dist/components/PersonStatementWidget.d.ts +1 -1
- package/dist/components/PersonStatementWidget.d.ts.map +1 -1
- package/dist/{FinancialContext.d.ts → context.d.ts} +4 -2
- package/dist/context.d.ts.map +1 -0
- package/dist/data/registries.d.ts.map +1 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1426 -1426
- package/dist/index.js.map +1 -1
- package/dist/integrations/stripe/connectorDef.d.ts +14 -0
- package/dist/integrations/stripe/connectorDef.d.ts.map +1 -0
- package/dist/integrations/stripe/data.d.ts +43 -0
- package/dist/integrations/stripe/data.d.ts.map +1 -0
- package/dist/lib/message-events.d.ts +12 -0
- package/dist/lib/message-events.d.ts.map +1 -0
- package/dist/{quick-add.d.ts → lib/quick-add.d.ts} +1 -1
- package/dist/lib/quick-add.d.ts.map +1 -0
- package/dist/locales/en.d.ts.map +1 -1
- package/dist/locales/pt-BR.d.ts.map +1 -1
- package/dist/{FinancialPage.d.ts → views/FinancialPage.d.ts} +3 -3
- package/dist/views/FinancialPage.d.ts.map +1 -0
- package/dist/views/InvoiceDetailView.d.ts.map +1 -1
- package/dist/views/InvoiceFormView.d.ts.map +1 -1
- package/dist/views/InvoiceListView.d.ts.map +1 -1
- package/dist/views/PayablesView.d.ts +1 -1
- package/dist/views/PayablesView.d.ts.map +1 -1
- package/dist/views/ReceivablesView.d.ts +1 -1
- package/dist/views/ReceivablesView.d.ts.map +1 -1
- package/dist/views/StatementsView.d.ts.map +1 -1
- package/dist/views/dashboardWidgets.d.ts +1 -1
- package/dist/views/dashboardWidgets.d.ts.map +1 -1
- package/package.json +12 -14
- package/dist/FinancialContext.d.ts.map +0 -1
- package/dist/FinancialPage.d.ts.map +0 -1
- package/dist/contract.test.d.ts +0 -2
- package/dist/contract.test.d.ts.map +0 -1
- package/dist/quick-add.d.ts.map +0 -1
- package/dist/registries.d.ts.map +0 -1
- package/src/FinancialContext.tsx +0 -59
- package/src/FinancialPage.tsx +0 -413
- package/src/README.md +0 -155
- package/src/components/FinancialGeneralSettings.tsx +0 -39
- package/src/components/FinancialOnboarding.tsx +0 -87
- package/src/components/FinancialSettings.tsx +0 -31
- package/src/components/PaymentModal.tsx +0 -369
- package/src/components/PersonStatementWidget.tsx +0 -133
- package/src/components/TransferModal.tsx +0 -150
- package/src/contract.test.ts +0 -58
- package/src/data/capability.test.ts +0 -135
- package/src/data/index.ts +0 -3
- package/src/data/mock.ts +0 -842
- package/src/data/supabase.ts +0 -968
- package/src/data/tables.ts +0 -13
- package/src/data/types.ts +0 -86
- package/src/index.ts +0 -487
- package/src/lib/tenant.ts +0 -3
- package/src/locales/en.ts +0 -493
- package/src/locales/index.ts +0 -7
- package/src/locales/pt-BR.ts +0 -493
- package/src/migrations/000_plg_rename.sql +0 -30
- package/src/migrations/001_financial_base.sql +0 -109
- package/src/migrations/002_chart_of_accounts.sql +0 -28
- package/src/migrations/003_card_brands.sql +0 -12
- package/src/migrations/004_order_to_cash.sql +0 -178
- package/src/migrations/005_seed_defaults.sql +0 -38
- package/src/migrations/006_rls_policies.sql +0 -37
- package/src/migrations/006b_extract_fee_amount.sql +0 -20
- package/src/migrations/007_reconciliation.sql +0 -32
- package/src/migrations/007b_movement_payment_method_type.sql +0 -6
- package/src/migrations/008_split_payment_movements.sql +0 -29
- package/src/migrations/009_agent_rpcs.sql +0 -165
- package/src/migrations/010_invoice_internal.sql +0 -133
- package/src/migrations/011_nfe.sql +0 -58
- package/src/migrations/index.ts +0 -923
- package/src/quick-add.ts +0 -58
- package/src/registries.ts +0 -308
- package/src/store.ts +0 -329
- package/src/types.ts +0 -592
- package/src/views/CardsView.tsx +0 -213
- package/src/views/CashRegistersView.tsx +0 -597
- package/src/views/CommissionsView.tsx +0 -18
- package/src/views/InvoiceDetailView.tsx +0 -616
- package/src/views/InvoiceFormView.tsx +0 -945
- package/src/views/InvoiceListView.tsx +0 -323
- package/src/views/NotasFiscaisView.tsx +0 -209
- package/src/views/PayablesView.tsx +0 -48
- package/src/views/QuickTransactionForm.tsx +0 -548
- package/src/views/ReceivablesView.tsx +0 -48
- package/src/views/ReconciliationView.tsx +0 -211
- package/src/views/StatementsView.tsx +0 -335
- package/src/views/SummaryView.tsx +0 -203
- package/src/views/dashboardWidgets.tsx +0 -437
- package/src/views/navReferrer.ts +0 -24
- /package/dist/{registries.d.ts → data/registries.d.ts} +0 -0
package/src/store.ts
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
import { createStore, type StoreApi } from 'zustand/vanilla'
|
|
2
|
-
import { dedup } from '@fayz-ai/saas'
|
|
3
|
-
import { toast } from '@fayz-ai/ui'
|
|
4
|
-
import type { FinancialDataProvider } from './data/types'
|
|
5
|
-
import type {
|
|
6
|
-
Invoice, FinancialMovement, BankAccount, CashSession,
|
|
7
|
-
PaymentMethod, PaymentMethodType, CardTransaction,
|
|
8
|
-
FinancialSummary, StatementResult,
|
|
9
|
-
InvoiceQuery, MovementQuery, StatementQuery,
|
|
10
|
-
CreateInvoiceInput, PayMovementInput, CreateTransferInput,
|
|
11
|
-
OpenCashSessionInput, CloseCashSessionInput,
|
|
12
|
-
QuickTransactionInput,
|
|
13
|
-
DateRange,
|
|
14
|
-
} from './types'
|
|
15
|
-
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Store state
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
export interface FinancialUIState {
|
|
21
|
-
// Data cache
|
|
22
|
-
invoices: Invoice[]
|
|
23
|
-
invoicesTotal: number
|
|
24
|
-
invoicesLoading: boolean
|
|
25
|
-
invoiceQuery: InvoiceQuery
|
|
26
|
-
|
|
27
|
-
movements: FinancialMovement[]
|
|
28
|
-
movementsTotal: number
|
|
29
|
-
movementsLoading: boolean
|
|
30
|
-
|
|
31
|
-
bankAccounts: BankAccount[]
|
|
32
|
-
bankAccountsLoading: boolean
|
|
33
|
-
|
|
34
|
-
cashSessions: CashSession[]
|
|
35
|
-
cashSessionsLoading: boolean
|
|
36
|
-
|
|
37
|
-
paymentMethods: PaymentMethod[]
|
|
38
|
-
paymentMethodTypes: PaymentMethodType[]
|
|
39
|
-
|
|
40
|
-
summary: FinancialSummary | null
|
|
41
|
-
summaryLoading: boolean
|
|
42
|
-
|
|
43
|
-
statement: StatementResult | null
|
|
44
|
-
statementLoading: boolean
|
|
45
|
-
statementQuery: StatementQuery | null
|
|
46
|
-
|
|
47
|
-
cardTransactions: CardTransaction[]
|
|
48
|
-
cardsLoading: boolean
|
|
49
|
-
|
|
50
|
-
// Actions
|
|
51
|
-
fetchSummary(dateRange?: DateRange): Promise<void>
|
|
52
|
-
fetchInvoices(query: InvoiceQuery): Promise<void>
|
|
53
|
-
fetchBankAccounts(): Promise<void>
|
|
54
|
-
fetchCashSessions(bankAccountId?: string): Promise<void>
|
|
55
|
-
fetchPaymentMethods(): Promise<void>
|
|
56
|
-
fetchStatement(query: StatementQuery): Promise<void>
|
|
57
|
-
fetchCardTransactions(dateRange?: DateRange): Promise<void>
|
|
58
|
-
createInvoice(input: CreateInvoiceInput): Promise<Invoice>
|
|
59
|
-
/** FAY-1225 "log money in a few taps": one call → the right provider plumbing + full surface refresh. */
|
|
60
|
-
createQuickTransaction(input: QuickTransactionInput): Promise<void>
|
|
61
|
-
payMovement(input: PayMovementInput): Promise<void>
|
|
62
|
-
createTransfer(input: CreateTransferInput): Promise<void>
|
|
63
|
-
cancelInvoice(invoiceId: string): Promise<void>
|
|
64
|
-
openCashSession(input: OpenCashSessionInput): Promise<CashSession>
|
|
65
|
-
closeCashSession(input: CloseCashSessionInput): Promise<CashSession>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
// Store factory
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
|
|
72
|
-
export function createFinancialStore(provider: FinancialDataProvider): StoreApi<FinancialUIState> {
|
|
73
|
-
return createStore<FinancialUIState>((set, get) => ({
|
|
74
|
-
invoices: [],
|
|
75
|
-
invoicesTotal: 0,
|
|
76
|
-
invoicesLoading: false,
|
|
77
|
-
invoiceQuery: {},
|
|
78
|
-
|
|
79
|
-
movements: [],
|
|
80
|
-
movementsTotal: 0,
|
|
81
|
-
movementsLoading: false,
|
|
82
|
-
|
|
83
|
-
bankAccounts: [],
|
|
84
|
-
bankAccountsLoading: false,
|
|
85
|
-
|
|
86
|
-
cashSessions: [],
|
|
87
|
-
cashSessionsLoading: false,
|
|
88
|
-
|
|
89
|
-
paymentMethods: [],
|
|
90
|
-
paymentMethodTypes: [],
|
|
91
|
-
|
|
92
|
-
summary: null,
|
|
93
|
-
summaryLoading: false,
|
|
94
|
-
|
|
95
|
-
statement: null,
|
|
96
|
-
statementLoading: false,
|
|
97
|
-
statementQuery: null,
|
|
98
|
-
|
|
99
|
-
cardTransactions: [],
|
|
100
|
-
cardsLoading: false,
|
|
101
|
-
|
|
102
|
-
async fetchSummary(dateRange) {
|
|
103
|
-
return dedup('fin:summary', async () => {
|
|
104
|
-
set({ summaryLoading: true })
|
|
105
|
-
const summary = await provider.getSummary(dateRange)
|
|
106
|
-
set({ summary, summaryLoading: false })
|
|
107
|
-
})
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
async fetchInvoices(query) {
|
|
111
|
-
return dedup('fin:invoices:' + JSON.stringify(query), async () => {
|
|
112
|
-
set({ invoicesLoading: true, invoiceQuery: query })
|
|
113
|
-
const result = await provider.getInvoices(query)
|
|
114
|
-
set({ invoices: result.data, invoicesTotal: result.total, invoicesLoading: false })
|
|
115
|
-
})
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
async fetchBankAccounts() {
|
|
119
|
-
return dedup('fin:bankAccounts', async () => {
|
|
120
|
-
set({ bankAccountsLoading: true })
|
|
121
|
-
const bankAccounts = await provider.getBankAccounts()
|
|
122
|
-
set({ bankAccounts, bankAccountsLoading: false })
|
|
123
|
-
})
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
async fetchCashSessions(bankAccountId) {
|
|
127
|
-
return dedup('fin:cashSessions:' + (bankAccountId ?? ''), async () => {
|
|
128
|
-
set({ cashSessionsLoading: true })
|
|
129
|
-
const cashSessions = await provider.getCashSessions(bankAccountId)
|
|
130
|
-
set({ cashSessions, cashSessionsLoading: false })
|
|
131
|
-
})
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
async fetchPaymentMethods() {
|
|
135
|
-
return dedup('fin:paymentMethods', async () => {
|
|
136
|
-
const [paymentMethods, paymentMethodTypes] = await Promise.all([
|
|
137
|
-
provider.getPaymentMethods(),
|
|
138
|
-
provider.getPaymentMethodTypes(),
|
|
139
|
-
])
|
|
140
|
-
set({ paymentMethods, paymentMethodTypes })
|
|
141
|
-
})
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
async fetchStatement(query) {
|
|
145
|
-
return dedup('fin:statement:' + JSON.stringify(query), async () => {
|
|
146
|
-
set({ statementLoading: true, statementQuery: query })
|
|
147
|
-
const statement = await provider.getStatement(query)
|
|
148
|
-
set({ statement, statementLoading: false })
|
|
149
|
-
})
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
async fetchCardTransactions(dateRange) {
|
|
153
|
-
return dedup('fin:cards', async () => {
|
|
154
|
-
set({ cardsLoading: true })
|
|
155
|
-
const cardTransactions = await provider.getCardTransactions(dateRange)
|
|
156
|
-
set({ cardTransactions, cardsLoading: false })
|
|
157
|
-
})
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
async createInvoice(input) {
|
|
161
|
-
try {
|
|
162
|
-
const invoice = await provider.createInvoice(input)
|
|
163
|
-
const query = get().invoiceQuery
|
|
164
|
-
const result = await provider.getInvoices(query)
|
|
165
|
-
const summary = await provider.getSummary()
|
|
166
|
-
set({ invoices: result.data, invoicesTotal: result.total, summary })
|
|
167
|
-
toast.success('Invoice created')
|
|
168
|
-
return invoice
|
|
169
|
-
} catch (err: any) {
|
|
170
|
-
toast.error('Failed to create invoice', { description: err?.message })
|
|
171
|
-
throw err
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
async createQuickTransaction(input) {
|
|
176
|
-
try {
|
|
177
|
-
if (input.type === 'transfer') {
|
|
178
|
-
if (!input.bankAccountId || !input.toAccountId) {
|
|
179
|
-
throw new Error('Select source and destination accounts')
|
|
180
|
-
}
|
|
181
|
-
await provider.createTransfer({
|
|
182
|
-
fromAccountId: input.bankAccountId,
|
|
183
|
-
toAccountId: input.toAccountId,
|
|
184
|
-
amount: input.amount,
|
|
185
|
-
date: input.date,
|
|
186
|
-
notes: input.description?.trim() || undefined,
|
|
187
|
-
})
|
|
188
|
-
} else {
|
|
189
|
-
const direction: 'debit' | 'credit' = input.type === 'income' ? 'credit' : 'debit'
|
|
190
|
-
const desc = input.description?.trim() || (input.type === 'income' ? 'Receita' : 'Despesa')
|
|
191
|
-
// 1. The obligation (invoice + bill movement).
|
|
192
|
-
// Persist the recurring flag + the snapped-receipt data URL (FAY-1226)
|
|
193
|
-
// on the invoice metadata so the transaction feed can indicate/preview it.
|
|
194
|
-
const invoiceMeta: Record<string, unknown> = {}
|
|
195
|
-
if (input.recurring) invoiceMeta.recurring = true
|
|
196
|
-
if (input.receiptUrl) invoiceMeta.receiptUrl = input.receiptUrl
|
|
197
|
-
const invoice = await provider.createInvoice({
|
|
198
|
-
direction,
|
|
199
|
-
invoiceDate: input.date,
|
|
200
|
-
contactName: desc,
|
|
201
|
-
metadata: Object.keys(invoiceMeta).length > 0 ? invoiceMeta : undefined,
|
|
202
|
-
items: [{
|
|
203
|
-
itemKind: 'other',
|
|
204
|
-
description: desc,
|
|
205
|
-
quantity: 1,
|
|
206
|
-
unitPrice: input.amount,
|
|
207
|
-
accountId: input.categoryId,
|
|
208
|
-
}],
|
|
209
|
-
installments: [{
|
|
210
|
-
direction,
|
|
211
|
-
movementKind: 'bill',
|
|
212
|
-
amount: input.amount,
|
|
213
|
-
dueDate: input.date,
|
|
214
|
-
installmentNumber: 1,
|
|
215
|
-
bankAccountId: input.bankAccountId,
|
|
216
|
-
notes: desc,
|
|
217
|
-
}],
|
|
218
|
-
})
|
|
219
|
-
// 2. Settle it now when marked paid → a realized cash event that shows in
|
|
220
|
-
// the statement/extract and feeds the monthly cash-flow KPIs.
|
|
221
|
-
if (input.paid) {
|
|
222
|
-
const movements = await provider.getMovements({ direction, status: 'pending' })
|
|
223
|
-
const bill = movements.data.find((m) => m.invoiceId === invoice.id && m.movementKind === 'bill')
|
|
224
|
-
if (bill) {
|
|
225
|
-
await provider.payMovement({
|
|
226
|
-
movementId: bill.id,
|
|
227
|
-
amount: input.amount,
|
|
228
|
-
paymentDate: input.date,
|
|
229
|
-
bankAccountId: input.bankAccountId,
|
|
230
|
-
notes: desc,
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// Refresh every surface this store feeds: Home/Resumo KPIs (summary),
|
|
236
|
-
// the mobile transaction list (statement), balances, and the payables/
|
|
237
|
-
// receivables tables (invoices).
|
|
238
|
-
const invoiceQuery = get().invoiceQuery
|
|
239
|
-
const statementQuery = get().statementQuery
|
|
240
|
-
const [summary, bankAccounts, invoicesRes, statement] = await Promise.all([
|
|
241
|
-
provider.getSummary(),
|
|
242
|
-
provider.getBankAccounts(),
|
|
243
|
-
provider.getInvoices(invoiceQuery),
|
|
244
|
-
statementQuery ? provider.getStatement(statementQuery) : Promise.resolve(get().statement),
|
|
245
|
-
])
|
|
246
|
-
set({
|
|
247
|
-
summary,
|
|
248
|
-
bankAccounts,
|
|
249
|
-
invoices: invoicesRes.data,
|
|
250
|
-
invoicesTotal: invoicesRes.total,
|
|
251
|
-
statement,
|
|
252
|
-
})
|
|
253
|
-
toast.success('Transaction saved')
|
|
254
|
-
} catch (err: any) {
|
|
255
|
-
toast.error('Failed to save transaction', { description: err?.message })
|
|
256
|
-
throw err
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
|
|
260
|
-
async payMovement(input) {
|
|
261
|
-
try {
|
|
262
|
-
await provider.payMovement(input)
|
|
263
|
-
const query = get().invoiceQuery
|
|
264
|
-
const [result, summary] = await Promise.all([provider.getInvoices(query), provider.getSummary()])
|
|
265
|
-
set({ invoices: result.data, invoicesTotal: result.total, summary })
|
|
266
|
-
toast.success('Payment recorded')
|
|
267
|
-
} catch (err: any) {
|
|
268
|
-
toast.error('Failed to record payment', { description: err?.message })
|
|
269
|
-
throw err
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
async createTransfer(input) {
|
|
274
|
-
try {
|
|
275
|
-
await provider.createTransfer(input)
|
|
276
|
-
const query = get().statementQuery
|
|
277
|
-
const [bankAccounts, summary, statement] = await Promise.all([
|
|
278
|
-
provider.getBankAccounts(),
|
|
279
|
-
provider.getSummary(),
|
|
280
|
-
query ? provider.getStatement(query) : Promise.resolve(get().statement),
|
|
281
|
-
])
|
|
282
|
-
set({ bankAccounts, summary, statement })
|
|
283
|
-
toast.success('Transfer recorded')
|
|
284
|
-
} catch (err: any) {
|
|
285
|
-
toast.error('Failed to record transfer', { description: err?.message })
|
|
286
|
-
throw err
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
async cancelInvoice(invoiceId) {
|
|
291
|
-
try {
|
|
292
|
-
await provider.cancelInvoice(invoiceId)
|
|
293
|
-
const query = get().invoiceQuery
|
|
294
|
-
const [result, summary] = await Promise.all([provider.getInvoices(query), provider.getSummary()])
|
|
295
|
-
set({ invoices: result.data, invoicesTotal: result.total, summary })
|
|
296
|
-
toast.success('Invoice cancelled')
|
|
297
|
-
} catch (err: any) {
|
|
298
|
-
toast.error('Failed to cancel invoice', { description: err?.message })
|
|
299
|
-
throw err
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
async openCashSession(input) {
|
|
304
|
-
try {
|
|
305
|
-
const session = await provider.openCashSession(input)
|
|
306
|
-
const cashSessions = await provider.getCashSessions()
|
|
307
|
-
set({ cashSessions })
|
|
308
|
-
toast.success('Cash session opened')
|
|
309
|
-
return session
|
|
310
|
-
} catch (err: any) {
|
|
311
|
-
toast.error('Failed to open session', { description: err?.message })
|
|
312
|
-
throw err
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
async closeCashSession(input) {
|
|
317
|
-
try {
|
|
318
|
-
const session = await provider.closeCashSession(input)
|
|
319
|
-
const cashSessions = await provider.getCashSessions()
|
|
320
|
-
set({ cashSessions })
|
|
321
|
-
toast.success('Cash session closed')
|
|
322
|
-
return session
|
|
323
|
-
} catch (err: any) {
|
|
324
|
-
toast.error('Failed to close session', { description: err?.message })
|
|
325
|
-
throw err
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
}))
|
|
329
|
-
}
|