@fayz-ai/plugin-financial 0.1.7 → 0.8.0

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 (72) hide show
  1. package/README.md +2 -0
  2. package/dist/FinancialContext.d.ts +2 -0
  3. package/dist/FinancialContext.d.ts.map +1 -1
  4. package/dist/FinancialPage.d.ts.map +1 -1
  5. package/dist/data/index.d.ts +1 -0
  6. package/dist/data/index.d.ts.map +1 -1
  7. package/dist/data/mock.d.ts +15 -0
  8. package/dist/data/mock.d.ts.map +1 -1
  9. package/dist/data/supabase.d.ts.map +1 -1
  10. package/dist/data/tables.d.ts +11 -0
  11. package/dist/data/tables.d.ts.map +1 -0
  12. package/dist/data/types.d.ts +2 -1
  13. package/dist/data/types.d.ts.map +1 -1
  14. package/dist/index.cjs +1594 -252
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +13 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1456 -131
  19. package/dist/index.js.map +1 -1
  20. package/dist/locales/en.d.ts.map +1 -1
  21. package/dist/locales/pt-BR.d.ts.map +1 -1
  22. package/dist/migrations/index.d.ts +16 -0
  23. package/dist/migrations/index.d.ts.map +1 -0
  24. package/dist/quick-add.d.ts +13 -0
  25. package/dist/quick-add.d.ts.map +1 -0
  26. package/dist/registries.d.ts.map +1 -1
  27. package/dist/store.d.ts +3 -1
  28. package/dist/store.d.ts.map +1 -1
  29. package/dist/types.d.ts +42 -0
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/views/CardsView.d.ts.map +1 -1
  32. package/dist/views/InvoiceListView.d.ts.map +1 -1
  33. package/dist/views/QuickTransactionForm.d.ts +16 -0
  34. package/dist/views/QuickTransactionForm.d.ts.map +1 -0
  35. package/dist/views/SummaryView.d.ts +5 -4
  36. package/dist/views/SummaryView.d.ts.map +1 -1
  37. package/dist/views/dashboardWidgets.d.ts.map +1 -1
  38. package/package.json +7 -4
  39. package/src/FinancialContext.tsx +2 -0
  40. package/src/FinancialPage.tsx +86 -7
  41. package/src/README.md +5 -5
  42. package/src/contract.test.ts +1 -1
  43. package/src/data/capability.test.ts +45 -0
  44. package/src/data/index.ts +1 -0
  45. package/src/data/mock.ts +50 -10
  46. package/src/data/supabase.ts +95 -49
  47. package/src/data/tables.ts +12 -0
  48. package/src/data/types.ts +2 -1
  49. package/src/index.ts +24 -4
  50. package/src/locales/en.ts +75 -0
  51. package/src/locales/pt-BR.ts +75 -0
  52. package/src/migrations/000_plg_rename.sql +30 -0
  53. package/src/migrations/001_financial_base.sql +30 -30
  54. package/src/migrations/002_chart_of_accounts.sql +10 -10
  55. package/src/migrations/003_card_brands.sql +4 -4
  56. package/src/migrations/004_order_to_cash.sql +28 -28
  57. package/src/migrations/005_seed_defaults.sql +6 -6
  58. package/src/migrations/006_rls_policies.sql +5 -5
  59. package/src/migrations/{006_extract_fee_amount.sql → 006b_extract_fee_amount.sql} +4 -4
  60. package/src/migrations/007_reconciliation.sql +9 -9
  61. package/src/migrations/007b_movement_payment_method_type.sql +6 -0
  62. package/src/migrations/008_split_payment_movements.sql +5 -5
  63. package/src/migrations/index.ts +544 -0
  64. package/src/quick-add.ts +58 -0
  65. package/src/registries.ts +8 -7
  66. package/src/store.ts +88 -0
  67. package/src/types.ts +45 -0
  68. package/src/views/CardsView.tsx +186 -50
  69. package/src/views/InvoiceListView.tsx +60 -3
  70. package/src/views/QuickTransactionForm.tsx +537 -0
  71. package/src/views/SummaryView.tsx +197 -6
  72. package/src/views/dashboardWidgets.tsx +251 -5
@@ -8,11 +8,11 @@ DO $$
8
8
  DECLARE t_id uuid;
9
9
  BEGIN
10
10
  FOR t_id IN (
11
- SELECT id FROM saas_core.tenants
12
- WHERE id NOT IN (SELECT DISTINCT tenant_id FROM public.payment_method_types)
11
+ SELECT id FROM public.tenants
12
+ WHERE id NOT IN (SELECT DISTINCT tenant_id FROM public.plg_financial_payment_method_types)
13
13
  )
14
14
  LOOP
15
- INSERT INTO public.payment_method_types (tenant_id, name, transaction_type) VALUES
15
+ INSERT INTO public.plg_financial_payment_method_types (tenant_id, name, transaction_type) VALUES
16
16
  (t_id, 'Cash', 'cash'),
17
17
  (t_id, 'PIX', 'pix'),
18
18
  (t_id, 'Credit Card', 'credit_card'),
@@ -26,11 +26,11 @@ DO $$
26
26
  DECLARE t_id uuid;
27
27
  BEGIN
28
28
  FOR t_id IN (
29
- SELECT id FROM saas_core.tenants
30
- WHERE id NOT IN (SELECT DISTINCT tenant_id FROM public.card_brands)
29
+ SELECT id FROM public.tenants
30
+ WHERE id NOT IN (SELECT DISTINCT tenant_id FROM public.plg_financial_card_brands)
31
31
  )
32
32
  LOOP
33
- INSERT INTO public.card_brands (tenant_id, name) VALUES
33
+ INSERT INTO public.plg_financial_card_brands (tenant_id, name) VALUES
34
34
  (t_id, 'Visa'), (t_id, 'Mastercard'), (t_id, 'American Express'),
35
35
  (t_id, 'Elo'), (t_id, 'Hipercard'), (t_id, 'Diners Club'),
36
36
  (t_id, 'Discover'), (t_id, 'JCB'), (t_id, 'Aura'), (t_id, 'Hiper');
@@ -3,10 +3,10 @@
3
3
  -- The base migrations (001/002/003) ENABLE row-level security but relied on an
4
4
  -- external `project_rls.sql` auto-detection step to create the actual policies.
5
5
  -- That step does not run in the Drizzle/companion pipeline, so every table
6
- -- except financial_movements was RLS-enabled with NO policy → all inserts denied
6
+ -- except plg_financial_movements was RLS-enabled with NO policy → all inserts denied
7
7
  -- ("new row violates row-level security policy"). This creates the canonical
8
8
  -- per-tenant policies idempotently. Re-running is a no-op (IF NOT EXISTS guards;
9
- -- financial_movements policies from 004 are skipped).
9
+ -- plg_financial_movements policies from 004 are skipped).
10
10
  --
11
11
  -- Canonical RLS form: tenant_id IN (SELECT public.user_tenant_ids()).
12
12
 
@@ -14,9 +14,9 @@ DO $$
14
14
  DECLARE t text;
15
15
  BEGIN
16
16
  FOR t IN SELECT unnest(ARRAY[
17
- 'payment_method_types','payment_methods','bank_accounts',
18
- 'cash_register_sessions','financial_movements',
19
- 'chart_of_accounts','cost_centers','card_brands'
17
+ 'plg_financial_payment_method_types','plg_financial_payment_methods','plg_financial_bank_accounts',
18
+ 'plg_financial_cash_register_sessions','plg_financial_movements',
19
+ 'plg_financial_chart_of_accounts','plg_financial_cost_centers','plg_financial_card_brands'
20
20
  ])
21
21
  LOOP
22
22
  EXECUTE format('ALTER TABLE public.%I ENABLE ROW LEVEL SECURITY', t);
@@ -5,14 +5,14 @@
5
5
  -- the running balance reflects the NET cash that actually lands in the account.
6
6
  -- gross = paid_amount (settles the receivable/payable)
7
7
  -- net cash = paid_amount - fee_amount (credits only; v1 has no fee on debits)
8
- ALTER TABLE public.financial_movements
8
+ ALTER TABLE public.plg_financial_movements
9
9
  ADD COLUMN IF NOT EXISTS fee_amount numeric(14,2) NOT NULL DEFAULT 0;
10
10
 
11
- COMMENT ON COLUMN public.financial_movements.fee_amount IS
11
+ COMMENT ON COLUMN public.plg_financial_movements.fee_amount IS
12
12
  'Processing/MDR fee deducted at settlement. Net cash impact = paid_amount - fee_amount (credit). v1: same-day net, no D+N settlement-date modeling.';
13
13
 
14
- CREATE INDEX IF NOT EXISTS idx_financial_movements_statement
15
- ON public.financial_movements (bank_account_id, payment_date)
14
+ CREATE INDEX IF NOT EXISTS idx_plg_financial_movements_statement
15
+ ON public.plg_financial_movements (bank_account_id, payment_date)
16
16
  WHERE status IN ('paid', 'partial');
17
17
 
18
18
  -- Transfers between accounts = a debit row (source) + credit row (destination),
@@ -2,31 +2,31 @@
2
2
  -- Reconciliation (conciliação): bank-statement lines ↔ internal movements
3
3
  -- ---------------------------------------------------------------------------
4
4
  -- An integration (e.g. open banking) imports bank-statement lines as
5
- -- financial_movements tagged with (external_source, external_id). The matching
5
+ -- plg_financial_movements tagged with (external_source, external_id). The matching
6
6
  -- UI then links each imported line to the internal movement it settles, or
7
7
  -- accepts it standalone. These columns make a movement carry its bank-line
8
8
  -- identity and its reconciliation state.
9
9
  -- external_source / external_id : the bank line's provider + unique id
10
10
  -- reconciled_at : when the line was matched/accepted (NULL = pending)
11
11
  -- matched_movement_id : the internal movement this line reconciles (NULL = standalone)
12
- ALTER TABLE public.financial_movements
12
+ ALTER TABLE public.plg_financial_movements
13
13
  ADD COLUMN IF NOT EXISTS external_id text,
14
14
  ADD COLUMN IF NOT EXISTS external_source text,
15
15
  ADD COLUMN IF NOT EXISTS reconciled_at timestamptz,
16
16
  ADD COLUMN IF NOT EXISTS matched_movement_id uuid
17
- REFERENCES public.financial_movements(id) ON DELETE SET NULL;
17
+ REFERENCES public.plg_financial_movements(id) ON DELETE SET NULL;
18
18
 
19
- COMMENT ON COLUMN public.financial_movements.external_source IS
19
+ COMMENT ON COLUMN public.plg_financial_movements.external_source IS
20
20
  'Provider of an imported bank-statement line (e.g. plugbank, inter). NULL for app-native movements.';
21
- COMMENT ON COLUMN public.financial_movements.external_id IS
21
+ COMMENT ON COLUMN public.plg_financial_movements.external_id IS
22
22
  'Provider-unique id of the imported bank line. Forms the import idempotency key with external_source.';
23
23
 
24
24
  -- Idempotency: a given bank line imports at most once per tenant.
25
- CREATE UNIQUE INDEX IF NOT EXISTS uq_financial_movements_external
26
- ON public.financial_movements (tenant_id, external_source, external_id)
25
+ CREATE UNIQUE INDEX IF NOT EXISTS uq_plg_financial_movements_external
26
+ ON public.plg_financial_movements (tenant_id, external_source, external_id)
27
27
  WHERE external_id IS NOT NULL AND external_source IS NOT NULL;
28
28
 
29
29
  -- Fast lookup of imported-but-unreconciled lines for the matching screen.
30
- CREATE INDEX IF NOT EXISTS idx_financial_movements_unreconciled
31
- ON public.financial_movements (tenant_id, payment_date)
30
+ CREATE INDEX IF NOT EXISTS idx_plg_financial_movements_unreconciled
31
+ ON public.plg_financial_movements (tenant_id, payment_date)
32
32
  WHERE external_source IS NOT NULL AND reconciled_at IS NULL;
@@ -0,0 +1,6 @@
1
+ -- payment_method_type_id existed on pre-pool installs (added out-of-band on
2
+ -- the salon/beauty DB) but was never captured in the file series; 008 requires
3
+ -- it on plg_financial_movements. No-op where the column already exists.
4
+
5
+ ALTER TABLE public.plg_financial_movements
6
+ ADD COLUMN IF NOT EXISTS payment_method_type_id uuid REFERENCES public.plg_financial_payment_method_types(id);
@@ -3,9 +3,9 @@
3
3
  -- two payments on one installment show as two extract rows instead of one summed row.
4
4
  -- Bills stay pure obligations; v_invoice_balances already filters movement_kind='bill',
5
5
  -- so the new payment rows don't affect invoice balances. Backfill is idempotent.
6
- -- Requires fee_amount (006_extract_fee_amount.sql).
6
+ -- Requires fee_amount (006b_extract_fee_amount.sql).
7
7
 
8
- INSERT INTO public.financial_movements
8
+ INSERT INTO public.plg_financial_movements
9
9
  (tenant_id, invoice_id, direction, movement_kind, amount, paid_amount, fee_amount, status,
10
10
  due_date, payment_date, installment_number, payment_method_id, payment_method_type_id,
11
11
  bank_account_id, cash_session_id, card_brand, card_installments, notes, metadata)
@@ -16,14 +16,14 @@ SELECT
16
16
  b.payment_method_id, b.payment_method_type_id, b.bank_account_id, b.cash_session_id,
17
17
  b.card_brand, b.card_installments, b.notes,
18
18
  jsonb_build_object('backfilledFromBill', b.id)
19
- FROM public.financial_movements b
19
+ FROM public.plg_financial_movements b
20
20
  WHERE b.movement_kind = 'bill' AND b.paid_amount > 0
21
21
  AND NOT EXISTS (
22
- SELECT 1 FROM public.financial_movements p
22
+ SELECT 1 FROM public.plg_financial_movements p
23
23
  WHERE p.movement_kind = 'payment' AND p.metadata->>'backfilledFromBill' = b.id::text
24
24
  );
25
25
 
26
- UPDATE public.financial_movements
26
+ UPDATE public.plg_financial_movements
27
27
  SET payment_date = NULL, bank_account_id = NULL, payment_method_id = NULL,
28
28
  payment_method_type_id = NULL, cash_session_id = NULL, card_brand = NULL, card_installments = NULL
29
29
  WHERE movement_kind = 'bill';