@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.
Files changed (95) hide show
  1. package/README.md +3 -3
  2. package/dist/components/PersonStatementWidget.d.ts +1 -1
  3. package/dist/components/PersonStatementWidget.d.ts.map +1 -1
  4. package/dist/{FinancialContext.d.ts → context.d.ts} +4 -2
  5. package/dist/context.d.ts.map +1 -0
  6. package/dist/data/registries.d.ts.map +1 -0
  7. package/dist/index.d.ts +13 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1426 -1426
  10. package/dist/index.js.map +1 -1
  11. package/dist/integrations/stripe/connectorDef.d.ts +14 -0
  12. package/dist/integrations/stripe/connectorDef.d.ts.map +1 -0
  13. package/dist/integrations/stripe/data.d.ts +43 -0
  14. package/dist/integrations/stripe/data.d.ts.map +1 -0
  15. package/dist/lib/message-events.d.ts +12 -0
  16. package/dist/lib/message-events.d.ts.map +1 -0
  17. package/dist/{quick-add.d.ts → lib/quick-add.d.ts} +1 -1
  18. package/dist/lib/quick-add.d.ts.map +1 -0
  19. package/dist/locales/en.d.ts.map +1 -1
  20. package/dist/locales/pt-BR.d.ts.map +1 -1
  21. package/dist/{FinancialPage.d.ts → views/FinancialPage.d.ts} +3 -3
  22. package/dist/views/FinancialPage.d.ts.map +1 -0
  23. package/dist/views/InvoiceDetailView.d.ts.map +1 -1
  24. package/dist/views/InvoiceFormView.d.ts.map +1 -1
  25. package/dist/views/InvoiceListView.d.ts.map +1 -1
  26. package/dist/views/PayablesView.d.ts +1 -1
  27. package/dist/views/PayablesView.d.ts.map +1 -1
  28. package/dist/views/ReceivablesView.d.ts +1 -1
  29. package/dist/views/ReceivablesView.d.ts.map +1 -1
  30. package/dist/views/StatementsView.d.ts.map +1 -1
  31. package/dist/views/dashboardWidgets.d.ts +1 -1
  32. package/dist/views/dashboardWidgets.d.ts.map +1 -1
  33. package/package.json +12 -14
  34. package/dist/FinancialContext.d.ts.map +0 -1
  35. package/dist/FinancialPage.d.ts.map +0 -1
  36. package/dist/contract.test.d.ts +0 -2
  37. package/dist/contract.test.d.ts.map +0 -1
  38. package/dist/quick-add.d.ts.map +0 -1
  39. package/dist/registries.d.ts.map +0 -1
  40. package/src/FinancialContext.tsx +0 -59
  41. package/src/FinancialPage.tsx +0 -413
  42. package/src/README.md +0 -155
  43. package/src/components/FinancialGeneralSettings.tsx +0 -39
  44. package/src/components/FinancialOnboarding.tsx +0 -87
  45. package/src/components/FinancialSettings.tsx +0 -31
  46. package/src/components/PaymentModal.tsx +0 -369
  47. package/src/components/PersonStatementWidget.tsx +0 -133
  48. package/src/components/TransferModal.tsx +0 -150
  49. package/src/contract.test.ts +0 -58
  50. package/src/data/capability.test.ts +0 -135
  51. package/src/data/index.ts +0 -3
  52. package/src/data/mock.ts +0 -842
  53. package/src/data/supabase.ts +0 -968
  54. package/src/data/tables.ts +0 -13
  55. package/src/data/types.ts +0 -86
  56. package/src/index.ts +0 -487
  57. package/src/lib/tenant.ts +0 -3
  58. package/src/locales/en.ts +0 -493
  59. package/src/locales/index.ts +0 -7
  60. package/src/locales/pt-BR.ts +0 -493
  61. package/src/migrations/000_plg_rename.sql +0 -30
  62. package/src/migrations/001_financial_base.sql +0 -109
  63. package/src/migrations/002_chart_of_accounts.sql +0 -28
  64. package/src/migrations/003_card_brands.sql +0 -12
  65. package/src/migrations/004_order_to_cash.sql +0 -178
  66. package/src/migrations/005_seed_defaults.sql +0 -38
  67. package/src/migrations/006_rls_policies.sql +0 -37
  68. package/src/migrations/006b_extract_fee_amount.sql +0 -20
  69. package/src/migrations/007_reconciliation.sql +0 -32
  70. package/src/migrations/007b_movement_payment_method_type.sql +0 -6
  71. package/src/migrations/008_split_payment_movements.sql +0 -29
  72. package/src/migrations/009_agent_rpcs.sql +0 -165
  73. package/src/migrations/010_invoice_internal.sql +0 -133
  74. package/src/migrations/011_nfe.sql +0 -58
  75. package/src/migrations/index.ts +0 -923
  76. package/src/quick-add.ts +0 -58
  77. package/src/registries.ts +0 -308
  78. package/src/store.ts +0 -329
  79. package/src/types.ts +0 -592
  80. package/src/views/CardsView.tsx +0 -213
  81. package/src/views/CashRegistersView.tsx +0 -597
  82. package/src/views/CommissionsView.tsx +0 -18
  83. package/src/views/InvoiceDetailView.tsx +0 -616
  84. package/src/views/InvoiceFormView.tsx +0 -945
  85. package/src/views/InvoiceListView.tsx +0 -323
  86. package/src/views/NotasFiscaisView.tsx +0 -209
  87. package/src/views/PayablesView.tsx +0 -48
  88. package/src/views/QuickTransactionForm.tsx +0 -548
  89. package/src/views/ReceivablesView.tsx +0 -48
  90. package/src/views/ReconciliationView.tsx +0 -211
  91. package/src/views/StatementsView.tsx +0 -335
  92. package/src/views/SummaryView.tsx +0 -203
  93. package/src/views/dashboardWidgets.tsx +0 -437
  94. package/src/views/navReferrer.ts +0 -24
  95. /package/dist/{registries.d.ts → data/registries.d.ts} +0 -0
package/src/quick-add.ts DELETED
@@ -1,58 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // Global quick-add trigger (FAY-1242).
3
- //
4
- // A tiny module-level store so a "log a transaction" request can be fired from
5
- // ANYWHERE in the app (e.g. the app shell's elevated center "+" bottom-nav
6
- // button) without a shared React context. The FinancialPage subscribes and
7
- // opens its QuickTransactionForm when a request arrives; the request is a
8
- // one-shot (consumed on read) so re-mounting /financial doesn't re-open it.
9
- //
10
- // Flow: center "+" → openQuickAdd() → navigate to /financial → FinancialPage
11
- // mounts, sees the pending request, opens the sheet. If already on /financial
12
- // the subscription fires and the sheet opens instantly.
13
- // ---------------------------------------------------------------------------
14
-
15
- import * as React from 'react'
16
- import type { QuickTransactionType } from './types'
17
-
18
- export interface QuickAddRequest {
19
- type: QuickTransactionType
20
- /** Foreground the receipt/attachment step + auto-open the picker. */
21
- receipt: boolean
22
- }
23
-
24
- let pending: QuickAddRequest | null = null
25
- const listeners = new Set<() => void>()
26
-
27
- function emit() {
28
- for (const l of listeners) l()
29
- }
30
-
31
- /** Fire a quick-add request from anywhere. Default = an expense. */
32
- export function openQuickAdd(type: QuickTransactionType = 'expense', receipt = false): void {
33
- pending = { type, receipt }
34
- emit()
35
- }
36
-
37
- /** Read + clear the pending request (one-shot). */
38
- export function consumeQuickAdd(): QuickAddRequest | null {
39
- const req = pending
40
- pending = null
41
- return req
42
- }
43
-
44
- function subscribe(cb: () => void): () => void {
45
- listeners.add(cb)
46
- return () => {
47
- listeners.delete(cb)
48
- }
49
- }
50
-
51
- function getSnapshot(): QuickAddRequest | null {
52
- return pending
53
- }
54
-
55
- /** React binding — returns the pending request (null when none). */
56
- export function usePendingQuickAdd(): QuickAddRequest | null {
57
- return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot)
58
- }
package/src/registries.ts DELETED
@@ -1,308 +0,0 @@
1
- import type { PluginRegistryDef } from '@fayz-ai/core'
2
- import type { EntityDef } from '@fayz-ai/core'
3
- import { T } from './data/tables'
4
-
5
- // ---------------------------------------------------------------------------
6
- // Payment Method Types (seeded — Cash, PIX, Credit Card, etc.)
7
- // ---------------------------------------------------------------------------
8
-
9
- const paymentMethodTypeEntity: EntityDef = {
10
- name: 'Payment Type',
11
- namePlural: 'Payment Types',
12
- icon: 'CreditCard',
13
- displayField: 'name',
14
- defaultSort: 'name',
15
- fields: [
16
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
17
- { key: 'transactionType', label: 'Transaction Type', type: 'select', options: ['cash', 'credit_card', 'debit_card', 'pix', 'bank_transfer', 'check', 'voucher'], showInTable: true, required: true },
18
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
19
- ],
20
- data: { table: T.paymentMethodTypes, tenantScoped: true },
21
- }
22
-
23
- // ---------------------------------------------------------------------------
24
- // Payment Methods (user-created — e.g. "Visa 2x", "PIX Store")
25
- // ---------------------------------------------------------------------------
26
-
27
- const paymentMethodEntity: EntityDef = {
28
- name: 'Payment Method',
29
- namePlural: 'Payment Methods',
30
- icon: 'CreditCard',
31
- displayField: 'name',
32
- defaultSort: 'name',
33
- fields: [
34
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
35
- // FK to the seeded payment_method_types catalog — load real ids at runtime
36
- // (a static enum select would write the string into the uuid column).
37
- { key: 'paymentMethodTypeId', label: 'Type', type: 'relation', relation: { table: T.paymentMethodTypes, labelField: 'name' }, showInTable: true, required: true },
38
- { key: 'discountValue', label: 'Discount %', type: 'number', showInTable: true },
39
- { key: 'interestValue', label: 'Interest %', type: 'number', showInTable: true },
40
- { key: 'minInstallments', label: 'Min Installments', type: 'number', defaultValue: 1 },
41
- { key: 'maxInstallments', label: 'Max Installments', type: 'number', defaultValue: 1, showInTable: true },
42
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
43
- ],
44
- data: { table: T.paymentMethods, tenantScoped: true },
45
- }
46
-
47
- // ---------------------------------------------------------------------------
48
- // Chart of Accounts (tree structure)
49
- // ---------------------------------------------------------------------------
50
-
51
- const chartOfAccountsEntity: EntityDef = {
52
- name: 'Ledger Account',
53
- namePlural: 'Chart of Accounts',
54
- icon: 'BookOpen',
55
- displayField: 'name',
56
- defaultSort: 'code',
57
- fields: [
58
- { key: 'code', label: 'Code', type: 'text', required: true, showInTable: true },
59
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
60
- { key: 'nodeType', label: 'Type', type: 'select', options: ['group', 'leaf'], showInTable: true, required: true, defaultValue: 'leaf' },
61
- { key: 'parentId', label: 'Parent', type: 'text', showInTable: false },
62
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
63
- ],
64
- data: { table: T.chartOfAccounts, tenantScoped: true },
65
- }
66
-
67
- // ---------------------------------------------------------------------------
68
- // Cost Centers
69
- // ---------------------------------------------------------------------------
70
-
71
- const costCenterEntity: EntityDef = {
72
- name: 'Cost Center',
73
- namePlural: 'Cost Centers',
74
- icon: 'Target',
75
- displayField: 'name',
76
- defaultSort: 'code',
77
- fields: [
78
- { key: 'code', label: 'Code', type: 'text', required: true, showInTable: true },
79
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
80
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
81
- ],
82
- data: { table: T.costCenters, tenantScoped: true },
83
- }
84
-
85
- // ---------------------------------------------------------------------------
86
- // Bank Accounts (physical cash, bank, credit card, digital wallet)
87
- // ---------------------------------------------------------------------------
88
-
89
- const bankAccountEntity: EntityDef = {
90
- name: 'Bank Account',
91
- namePlural: 'Bank Accounts',
92
- icon: 'Landmark',
93
- displayField: 'name',
94
- defaultSort: 'name',
95
- fields: [
96
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
97
- { key: 'accountType', label: 'Type', type: 'select', options: [
98
- { label: 'Bank Account', value: 'bank_account' },
99
- { label: 'Cash Register', value: 'cash_register' },
100
- { label: 'Credit Card', value: 'credit_card' },
101
- { label: 'Digital Wallet', value: 'digital_wallet' },
102
- ], showInTable: true, required: true },
103
- { key: 'bankName', label: 'Bank', type: 'text', showInTable: true },
104
- { key: 'accountNumber', label: 'Account Number', type: 'text' },
105
- { key: 'agencyNumber', label: 'Agency', type: 'text' },
106
- { key: 'initialBalance', label: 'Initial Balance', type: 'currency', defaultValue: 0 },
107
- { key: 'creditLimit', label: 'Credit Limit', type: 'currency' },
108
- { key: 'closingDay', label: 'Closing Day', type: 'number' },
109
- { key: 'dueDay', label: 'Due Day', type: 'number' },
110
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
111
- ],
112
- data: { table: T.bankAccounts, tenantScoped: true },
113
- }
114
-
115
- // ---------------------------------------------------------------------------
116
- // Card Brands (seeded)
117
- // ---------------------------------------------------------------------------
118
-
119
- const cardBrandEntity: EntityDef = {
120
- name: 'Card Brand',
121
- namePlural: 'Card Brands',
122
- icon: 'CreditCard',
123
- displayField: 'name',
124
- defaultSort: 'name',
125
- fields: [
126
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
127
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
128
- ],
129
- data: { table: T.cardBrands, tenantScoped: true },
130
- }
131
-
132
- // ---------------------------------------------------------------------------
133
- // Commission Rules
134
- // ---------------------------------------------------------------------------
135
-
136
- const commissionRuleEntity: EntityDef = {
137
- name: 'Commission Rule',
138
- namePlural: 'Commission Rules',
139
- icon: 'TrendingUp',
140
- displayField: 'name',
141
- defaultSort: 'priority',
142
- defaultSortDir: 'desc',
143
- fields: [
144
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
145
- { key: 'priority', label: 'Priority', type: 'number', required: true, showInTable: true, defaultValue: 1 },
146
- { key: 'valueType', label: 'Type', type: 'select', options: ['percentage', 'fixed'], required: true, showInTable: true, defaultValue: 'percentage' },
147
- { key: 'value', label: 'Value', type: 'number', required: true, showInTable: true },
148
- { key: 'description', label: 'Description', type: 'textarea' },
149
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
150
- ],
151
- data: { table: 'commission_rules', tenantScoped: true },
152
- }
153
-
154
- // ---------------------------------------------------------------------------
155
- // Price Tables
156
- // ---------------------------------------------------------------------------
157
-
158
- const priceTableEntity: EntityDef = {
159
- name: 'Price Table',
160
- namePlural: 'Price Tables',
161
- icon: 'Tag',
162
- displayField: 'description',
163
- defaultSort: 'createdAt',
164
- defaultSortDir: 'desc',
165
- fields: [
166
- { key: 'description', label: 'Description', type: 'text', required: true, showInTable: true },
167
- { key: 'type', label: 'Type', type: 'select', options: ['sale', 'cost'], required: true, showInTable: true, defaultValue: 'sale' },
168
- { key: 'validFrom', label: 'Valid From', type: 'date', showInTable: true },
169
- { key: 'validUntil', label: 'Valid Until', type: 'date', showInTable: true },
170
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
171
- ],
172
- data: { table: 'price_tables', tenantScoped: true },
173
- }
174
-
175
- // ---------------------------------------------------------------------------
176
- // Price Variations
177
- // ---------------------------------------------------------------------------
178
-
179
- const priceVariationEntity: EntityDef = {
180
- name: 'Price Variation',
181
- namePlural: 'Price Variations',
182
- icon: 'Percent',
183
- displayField: 'name',
184
- defaultSort: 'createdAt',
185
- defaultSortDir: 'desc',
186
- fields: [
187
- { key: 'name', label: 'Name', type: 'text', required: true, showInTable: true },
188
- { key: 'variationType', label: 'Type', type: 'select', options: ['discount', 'increase'], required: true, showInTable: true },
189
- { key: 'valueType', label: 'Value Type', type: 'select', options: ['percentage', 'fixed'], required: true, showInTable: true },
190
- { key: 'value', label: 'Value', type: 'number', required: true, showInTable: true },
191
- { key: 'firstAppointmentOnly', label: 'First Appointment Only', type: 'boolean', defaultValue: false },
192
- { key: 'isActive', label: 'Active', type: 'boolean', showInTable: true, defaultValue: true },
193
- ],
194
- data: { table: 'price_variations', tenantScoped: true },
195
- }
196
-
197
- // ---------------------------------------------------------------------------
198
- // Export all registries
199
- // ---------------------------------------------------------------------------
200
-
201
- export const financialRegistries: PluginRegistryDef[] = [
202
- // --- Editable registries (user manages) ---
203
- {
204
- id: 'payment-methods',
205
- entity: paymentMethodEntity,
206
- icon: 'Wallet',
207
- description: 'Configured payment methods with fees and installment rules',
208
- display: 'table',
209
- },
210
- {
211
- id: 'chart-of-accounts',
212
- entity: chartOfAccountsEntity,
213
- icon: 'BookOpen',
214
- description: 'Hierarchical chart of accounts for categorizing transactions',
215
- display: 'tree',
216
- seedData: [
217
- { id: 'coa-1', code: '1', name: 'Revenue', nodeType: 'group', isActive: true },
218
- { id: 'coa-1.1', code: '1.1', name: 'Sales Revenue', nodeType: 'group', parentId: 'coa-1', isActive: true },
219
- { id: 'coa-1.1.01', code: '1.1.01', name: 'Services', nodeType: 'leaf', parentId: 'coa-1.1', isActive: true },
220
- { id: 'coa-1.1.02', code: '1.1.02', name: 'Products', nodeType: 'leaf', parentId: 'coa-1.1', isActive: true },
221
- { id: 'coa-2', code: '2', name: 'Other Revenue', nodeType: 'group', isActive: true },
222
- { id: 'coa-2.1', code: '2.1', name: 'Financial Income', nodeType: 'leaf', parentId: 'coa-2', isActive: true },
223
- { id: 'coa-3', code: '3', name: 'Operational Costs', nodeType: 'group', isActive: true },
224
- { id: 'coa-3.1', code: '3.1', name: 'Materials & Supplies', nodeType: 'group', parentId: 'coa-3', isActive: true },
225
- { id: 'coa-3.1.01', code: '3.1.01', name: 'Raw Materials', nodeType: 'leaf', parentId: 'coa-3.1', isActive: true },
226
- { id: 'coa-3.1.02', code: '3.1.02', name: 'Consumables', nodeType: 'leaf', parentId: 'coa-3.1', isActive: true },
227
- { id: 'coa-4', code: '4', name: 'Expenses', nodeType: 'group', isActive: true },
228
- { id: 'coa-4.1', code: '4.1', name: 'Rent', nodeType: 'leaf', parentId: 'coa-4', isActive: true },
229
- { id: 'coa-4.2', code: '4.2', name: 'Utilities', nodeType: 'leaf', parentId: 'coa-4', isActive: true },
230
- { id: 'coa-4.3', code: '4.3', name: 'Payroll', nodeType: 'leaf', parentId: 'coa-4', isActive: true },
231
- ],
232
- },
233
- {
234
- id: 'cost-centers',
235
- entity: costCenterEntity,
236
- icon: 'Target',
237
- description: 'Cost centers for expense tracking and departmental budgets',
238
- display: 'table',
239
- seedData: [
240
- { id: 'cc-001', code: '001', name: 'General', isActive: true },
241
- ],
242
- },
243
- {
244
- id: 'bank-accounts',
245
- entity: bankAccountEntity,
246
- icon: 'Landmark',
247
- description: 'Bank accounts, cash registers, credit cards, and digital wallets',
248
- display: 'table',
249
- },
250
- {
251
- id: 'commission-rules',
252
- entity: commissionRuleEntity,
253
- icon: 'TrendingUp',
254
- description: 'Commission rules for service and product revenue sharing',
255
- display: 'table',
256
- },
257
- {
258
- id: 'price-tables',
259
- entity: priceTableEntity,
260
- icon: 'Tag',
261
- description: 'Price tables for sale and cost pricing',
262
- display: 'table',
263
- },
264
- {
265
- id: 'price-variations',
266
- entity: priceVariationEntity,
267
- icon: 'Percent',
268
- description: 'Discount and surcharge rules for pricing',
269
- display: 'table',
270
- },
271
- // --- Read-only registries (system / seeded data) ---
272
- {
273
- id: 'payment-method-types',
274
- entity: paymentMethodTypeEntity,
275
- icon: 'CreditCard',
276
- description: 'System payment types (cash, card, PIX, etc.)',
277
- display: 'table',
278
- readOnly: true,
279
- seedData: [
280
- { id: 'pmt-cash', name: 'Cash', transactionType: 'cash', isActive: true },
281
- { id: 'pmt-pix', name: 'PIX', transactionType: 'pix', isActive: true },
282
- { id: 'pmt-credit', name: 'Credit Card', transactionType: 'credit_card', isActive: true },
283
- { id: 'pmt-debit', name: 'Debit Card', transactionType: 'debit_card', isActive: true },
284
- { id: 'pmt-transfer', name: 'Bank Transfer', transactionType: 'bank_transfer', isActive: true },
285
- { id: 'pmt-check', name: 'Check', transactionType: 'check', isActive: true },
286
- ],
287
- },
288
- {
289
- id: 'card-brands',
290
- entity: cardBrandEntity,
291
- icon: 'CreditCard',
292
- description: 'Credit and debit card brands',
293
- display: 'table',
294
- readOnly: true,
295
- seedData: [
296
- { id: 'cb-visa', name: 'Visa', isActive: true },
297
- { id: 'cb-mastercard', name: 'Mastercard', isActive: true },
298
- { id: 'cb-amex', name: 'American Express', isActive: true },
299
- { id: 'cb-elo', name: 'Elo', isActive: true },
300
- { id: 'cb-hipercard', name: 'Hipercard', isActive: true },
301
- { id: 'cb-diners', name: 'Diners Club', isActive: true },
302
- { id: 'cb-discover', name: 'Discover', isActive: true },
303
- { id: 'cb-jcb', name: 'JCB', isActive: true },
304
- { id: 'cb-aura', name: 'Aura', isActive: true },
305
- { id: 'cb-hiper', name: 'Hiper', isActive: true },
306
- ],
307
- },
308
- ]