@hed-hog/finance 0.0.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 +488 -0
- package/dist/finance.module.d.ts +3 -0
- package/dist/finance.module.d.ts.map +1 -0
- package/dist/finance.module.js +28 -0
- package/dist/finance.module.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/hedhog/frontend/app/page.tsx.ejs +17 -0
- package/hedhog/frontend/messages/en.json +6 -0
- package/hedhog/frontend/messages/pt.json +6 -0
- package/hedhog/table/audit_log.yaml +39 -0
- package/hedhog/table/bank_account.yaml +45 -0
- package/hedhog/table/bank_reconciliation.yaml +39 -0
- package/hedhog/table/bank_statement.yaml +40 -0
- package/hedhog/table/bank_statement_line.yaml +41 -0
- package/hedhog/table/branch.yaml +18 -0
- package/hedhog/table/cashflow_projection.yaml +26 -0
- package/hedhog/table/company_profile.yaml +23 -0
- package/hedhog/table/cost_center.yaml +18 -0
- package/hedhog/table/finance_category.yaml +29 -0
- package/hedhog/table/financial_installment.yaml +34 -0
- package/hedhog/table/financial_installment_tag.yaml +23 -0
- package/hedhog/table/financial_title.yaml +61 -0
- package/hedhog/table/financial_title_attachment.yaml +32 -0
- package/hedhog/table/forecast_scenario.yaml +18 -0
- package/hedhog/table/installment_allocation.yaml +26 -0
- package/hedhog/table/payment_method.yaml +21 -0
- package/hedhog/table/period_close.yaml +30 -0
- package/hedhog/table/receivable_schedule.yaml +31 -0
- package/hedhog/table/settlement.yaml +66 -0
- package/hedhog/table/settlement_allocation.yaml +35 -0
- package/package.json +39 -0
- package/src/finance.module.ts +15 -0
- package/src/index.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
# Finance Library - Estrutura de Banco de Dados
|
|
2
|
+
|
|
3
|
+
Este documento explica, de forma didática e técnica, como funciona a estrutura de dados do módulo financeiro em `libraries/finance`.
|
|
4
|
+
|
|
5
|
+
## 1) Objetivo do módulo
|
|
6
|
+
|
|
7
|
+
O módulo financeiro foi modelado para cobrir o ciclo completo de gestão financeira:
|
|
8
|
+
|
|
9
|
+
- cadastro base (filiais, categorias, centros de custo, contas bancárias, meios de pagamento);
|
|
10
|
+
- planejamento (título e parcelas);
|
|
11
|
+
- execução financeira (liquidação/baixa real);
|
|
12
|
+
- conciliação bancária (extrato x liquidação);
|
|
13
|
+
- governança (auditoria e fechamento de período);
|
|
14
|
+
- projeções futuras (cenários, fluxo projetado e agenda de recebíveis).
|
|
15
|
+
|
|
16
|
+
## 2) Convenções gerais
|
|
17
|
+
|
|
18
|
+
### 2.1 Escopo atual (sem tenant)
|
|
19
|
+
|
|
20
|
+
Nesta versão, o módulo **não usa separação por tenant** nas tabelas novas.
|
|
21
|
+
Ou seja, não existem colunas `company_person_id` ou `person_company_id` nas tabelas do módulo financeiro.
|
|
22
|
+
|
|
23
|
+
### 2.2 Tabelas já existentes usadas pelo módulo
|
|
24
|
+
|
|
25
|
+
O módulo reutiliza tabelas de outras libraries:
|
|
26
|
+
|
|
27
|
+
- `person`: contraparte de títulos e liquidações (cliente/fornecedor).
|
|
28
|
+
- `user`: autoria e rastreabilidade (`created_by`, `matched_by`, `closed_by`, etc.).
|
|
29
|
+
- `tag`: classificação analítica de parcelas.
|
|
30
|
+
- `file`: anexos de títulos.
|
|
31
|
+
|
|
32
|
+
### 2.3 Padrões recomendados de domínio
|
|
33
|
+
|
|
34
|
+
- Valores monetários em centavos (`*_cents`) para evitar erro de precisão.
|
|
35
|
+
- Datas de competência e vencimento separadas para análises corretas.
|
|
36
|
+
- Histórico imutável de eventos financeiros: não apagar histórico; corrigir por estorno/ajuste.
|
|
37
|
+
|
|
38
|
+
## 3) Visão macro das relações
|
|
39
|
+
|
|
40
|
+
Fluxo principal de operação:
|
|
41
|
+
|
|
42
|
+
1. Cadastra `financial_title` (documento pai).
|
|
43
|
+
2. Gera `financial_installment` (parcelas).
|
|
44
|
+
3. Registra `settlement` (dinheiro real).
|
|
45
|
+
4. Liga settlement às parcelas em `settlement_allocation`.
|
|
46
|
+
5. Importa extrato (`bank_statement` e `bank_statement_line`).
|
|
47
|
+
6. Concilia extrato x settlement em `bank_reconciliation`.
|
|
48
|
+
|
|
49
|
+
Relações de suporte:
|
|
50
|
+
|
|
51
|
+
- `financial_installment_tag`: N:N entre parcela e tag.
|
|
52
|
+
- `installment_allocation`: rateio de parcela por centro de custo.
|
|
53
|
+
- `financial_title_attachment`: documentos anexos.
|
|
54
|
+
- `audit_log`: trilha de auditoria de ações.
|
|
55
|
+
- `period_close`: bloqueio operacional por período.
|
|
56
|
+
|
|
57
|
+
## 4) Dicionário de tabelas (objetivo, colunas e uso)
|
|
58
|
+
|
|
59
|
+
## 4.1 company_profile
|
|
60
|
+
|
|
61
|
+
**Objetivo:** guardar configurações globais do contexto financeiro (status, moeda e timezone).
|
|
62
|
+
|
|
63
|
+
**Colunas:**
|
|
64
|
+
|
|
65
|
+
- `id`: chave primária.
|
|
66
|
+
- `code`: identificador curto/estável para integração e referência.
|
|
67
|
+
- `status`: `active|inactive`.
|
|
68
|
+
- `default_currency`: moeda padrão (ex.: `BRL`).
|
|
69
|
+
- `timezone`: timezone padrão (ex.: `America/Sao_Paulo`).
|
|
70
|
+
- `created_at`, `updated_at`: auditoria temporal.
|
|
71
|
+
|
|
72
|
+
**Uso comum:** inicialização de regras de data/moeda em UI, API e relatórios.
|
|
73
|
+
|
|
74
|
+
## 4.2 branch
|
|
75
|
+
|
|
76
|
+
**Objetivo:** representar filiais/unidades operacionais.
|
|
77
|
+
|
|
78
|
+
**Colunas:**
|
|
79
|
+
|
|
80
|
+
- `id`: chave primária.
|
|
81
|
+
- `code`: código único da filial.
|
|
82
|
+
- `name`: nome exibível da filial.
|
|
83
|
+
- `status`: `active|inactive`.
|
|
84
|
+
- `created_at`, `updated_at`.
|
|
85
|
+
|
|
86
|
+
**Relações:**
|
|
87
|
+
|
|
88
|
+
- Referenciada por `financial_title.branch_id`.
|
|
89
|
+
- Referenciada por `bank_account.branch_id`.
|
|
90
|
+
- Referenciada por `settlement.branch_id`.
|
|
91
|
+
|
|
92
|
+
## 4.3 finance_category
|
|
93
|
+
|
|
94
|
+
**Objetivo:** plano de categorias financeiras para classificação analítica.
|
|
95
|
+
|
|
96
|
+
**Colunas:**
|
|
97
|
+
|
|
98
|
+
- `id`: chave primária.
|
|
99
|
+
- `parent_id`: auto-relacionamento para hierarquia (nullable).
|
|
100
|
+
- `code`: código da categoria.
|
|
101
|
+
- `name`: nome da categoria.
|
|
102
|
+
- `kind`: `revenue|expense|transfer|adjustment|other`.
|
|
103
|
+
- `status`: `active|inactive`.
|
|
104
|
+
- `created_at`, `updated_at`.
|
|
105
|
+
|
|
106
|
+
**Relações:**
|
|
107
|
+
|
|
108
|
+
- Auto-relacionamento por `parent_id`.
|
|
109
|
+
- Referenciada por `financial_title.finance_category_id`.
|
|
110
|
+
|
|
111
|
+
## 4.4 cost_center
|
|
112
|
+
|
|
113
|
+
**Objetivo:** centro de custo/projeto para rateio gerencial.
|
|
114
|
+
|
|
115
|
+
**Colunas:**
|
|
116
|
+
|
|
117
|
+
- `id`: chave primária.
|
|
118
|
+
- `code`: código do centro de custo.
|
|
119
|
+
- `name`: nome exibível.
|
|
120
|
+
- `status`: `active|inactive`.
|
|
121
|
+
- `created_at`, `updated_at`.
|
|
122
|
+
|
|
123
|
+
**Relações:**
|
|
124
|
+
|
|
125
|
+
- Referenciada por `installment_allocation.cost_center_id`.
|
|
126
|
+
|
|
127
|
+
## 4.5 payment_method
|
|
128
|
+
|
|
129
|
+
**Objetivo:** catálogo configurável de meios de pagamento/recebimento.
|
|
130
|
+
|
|
131
|
+
**Colunas:**
|
|
132
|
+
|
|
133
|
+
- `id`: chave primária.
|
|
134
|
+
- `code`: identificador do método.
|
|
135
|
+
- `name`: nome exibível.
|
|
136
|
+
- `type`: `pix|boleto|ted|doc|card|cash|other`.
|
|
137
|
+
- `status`: `active|inactive`.
|
|
138
|
+
- `created_at`, `updated_at`.
|
|
139
|
+
|
|
140
|
+
**Relações:**
|
|
141
|
+
|
|
142
|
+
- Referenciada por `settlement.payment_method_id`.
|
|
143
|
+
|
|
144
|
+
## 4.6 bank_account
|
|
145
|
+
|
|
146
|
+
**Objetivo:** contas bancárias/caixa usadas nos movimentos reais.
|
|
147
|
+
|
|
148
|
+
**Colunas:**
|
|
149
|
+
|
|
150
|
+
- `id`: chave primária.
|
|
151
|
+
- `branch_id`: FK para `branch.id` (nullable).
|
|
152
|
+
- `code`: código da conta.
|
|
153
|
+
- `name`: nome exibível.
|
|
154
|
+
- `bank_name`, `bank_code`: metadados bancários (nullable).
|
|
155
|
+
- `agency`, `account_number`: metadados bancários (nullable).
|
|
156
|
+
- `account_type`: `checking|savings|investment|cash|other`.
|
|
157
|
+
- `status`: `active|inactive`.
|
|
158
|
+
- `created_at`, `updated_at`.
|
|
159
|
+
|
|
160
|
+
**Relações:**
|
|
161
|
+
|
|
162
|
+
- Referenciada por `bank_statement.bank_account_id`.
|
|
163
|
+
- Referenciada por `bank_statement_line.bank_account_id`.
|
|
164
|
+
- Referenciada por `settlement.bank_account_id`.
|
|
165
|
+
|
|
166
|
+
## 4.7 financial_title
|
|
167
|
+
|
|
168
|
+
**Objetivo:** documento pai de contas a pagar/receber.
|
|
169
|
+
|
|
170
|
+
**Colunas:**
|
|
171
|
+
|
|
172
|
+
- `id`: chave primária.
|
|
173
|
+
- `branch_id`: FK para filial (nullable).
|
|
174
|
+
- `person_id`: FK para contraparte (`person.id`).
|
|
175
|
+
- `title_type`: `payable|receivable`.
|
|
176
|
+
- `status`: `draft|approved|open|partial|settled|canceled|overdue`.
|
|
177
|
+
- `document_number`: número do documento (nullable).
|
|
178
|
+
- `description`: histórico/observações (nullable).
|
|
179
|
+
- `competence_date`: competência macro (nullable).
|
|
180
|
+
- `issue_date`: emissão (nullable).
|
|
181
|
+
- `total_amount_cents`: total previsto no título.
|
|
182
|
+
- `finance_category_id`: FK para categoria (nullable).
|
|
183
|
+
- `created_by_user_id`: FK para `user.id` (nullable).
|
|
184
|
+
- `created_at`, `updated_at`.
|
|
185
|
+
|
|
186
|
+
**Relações:**
|
|
187
|
+
|
|
188
|
+
- 1:N com `financial_installment`.
|
|
189
|
+
- 1:N com `financial_title_attachment`.
|
|
190
|
+
|
|
191
|
+
## 4.8 financial_installment
|
|
192
|
+
|
|
193
|
+
**Objetivo:** parcelas planejadas de cada título.
|
|
194
|
+
|
|
195
|
+
**Colunas:**
|
|
196
|
+
|
|
197
|
+
- `id`: chave primária.
|
|
198
|
+
- `title_id`: FK para `financial_title.id`.
|
|
199
|
+
- `installment_number`: número sequencial da parcela por título.
|
|
200
|
+
- `competence_date`: competência contábil/gerencial.
|
|
201
|
+
- `due_date`: vencimento.
|
|
202
|
+
- `amount_cents`: valor original da parcela.
|
|
203
|
+
- `open_amount_cents`: saldo em aberto.
|
|
204
|
+
- `status`: `open|partial|settled|canceled|overdue`.
|
|
205
|
+
- `notes`: observações (nullable).
|
|
206
|
+
- `created_at`, `updated_at`.
|
|
207
|
+
|
|
208
|
+
**Relações:**
|
|
209
|
+
|
|
210
|
+
- N:1 com `financial_title`.
|
|
211
|
+
- N:N com `tag` via `financial_installment_tag`.
|
|
212
|
+
- 1:N com `installment_allocation`.
|
|
213
|
+
- 1:N com `settlement_allocation`.
|
|
214
|
+
|
|
215
|
+
## 4.9 financial_title_attachment
|
|
216
|
+
|
|
217
|
+
**Objetivo:** anexar arquivos ao título sem armazenar binário na tabela.
|
|
218
|
+
|
|
219
|
+
**Colunas:**
|
|
220
|
+
|
|
221
|
+
- `id`: chave primária.
|
|
222
|
+
- `title_id`: FK para `financial_title.id`.
|
|
223
|
+
- `file_id`: FK para `file.id`.
|
|
224
|
+
- `uploaded_by_user_id`: FK para `user.id` (nullable).
|
|
225
|
+
- `created_at`, `updated_at`.
|
|
226
|
+
|
|
227
|
+
## 4.10 financial_installment_tag
|
|
228
|
+
|
|
229
|
+
**Objetivo:** classificação por tags em nível de parcela.
|
|
230
|
+
|
|
231
|
+
**Colunas:**
|
|
232
|
+
|
|
233
|
+
- `id`: chave primária.
|
|
234
|
+
- `installment_id`: FK para `financial_installment.id`.
|
|
235
|
+
- `tag_id`: FK para `tag.id`.
|
|
236
|
+
- `created_at`, `updated_at`.
|
|
237
|
+
|
|
238
|
+
**Observação:** possui unicidade (`installment_id`, `tag_id`) para evitar duplicidade.
|
|
239
|
+
|
|
240
|
+
## 4.11 installment_allocation
|
|
241
|
+
|
|
242
|
+
**Objetivo:** ratear uma parcela entre centros de custo.
|
|
243
|
+
|
|
244
|
+
**Colunas:**
|
|
245
|
+
|
|
246
|
+
- `id`: chave primária.
|
|
247
|
+
- `installment_id`: FK para `financial_installment.id`.
|
|
248
|
+
- `cost_center_id`: FK para `cost_center.id`.
|
|
249
|
+
- `allocated_amount_cents`: valor alocado.
|
|
250
|
+
- `created_at`, `updated_at`.
|
|
251
|
+
|
|
252
|
+
**Observação:** possui unicidade (`installment_id`, `cost_center_id`).
|
|
253
|
+
|
|
254
|
+
## 4.12 settlement
|
|
255
|
+
|
|
256
|
+
**Objetivo:** representar o evento financeiro real (pagamento/recebimento/transferência/ajuste).
|
|
257
|
+
|
|
258
|
+
**Colunas:**
|
|
259
|
+
|
|
260
|
+
- `id`: chave primária.
|
|
261
|
+
- `branch_id`: FK para `branch.id` (nullable).
|
|
262
|
+
- `person_id`: FK para `person.id` (nullable).
|
|
263
|
+
- `bank_account_id`: FK para `bank_account.id` (nullable).
|
|
264
|
+
- `payment_method_id`: FK para `payment_method.id` (nullable).
|
|
265
|
+
- `settlement_type`: `payable|receivable|transfer|adjustment`.
|
|
266
|
+
- `status`: `pending|confirmed|reversed`.
|
|
267
|
+
- `settled_at`: data/hora do evento financeiro.
|
|
268
|
+
- `amount_cents`: valor do evento.
|
|
269
|
+
- `description`: histórico (nullable).
|
|
270
|
+
- `external_reference`: referência externa (nullable).
|
|
271
|
+
- `created_by_user_id`: FK para `user.id` (nullable).
|
|
272
|
+
- `created_at`, `updated_at`.
|
|
273
|
+
|
|
274
|
+
**Relações:**
|
|
275
|
+
|
|
276
|
+
- 1:N com `settlement_allocation`.
|
|
277
|
+
- 1:1 com `bank_reconciliation` (por restrição de unicidade).
|
|
278
|
+
|
|
279
|
+
## 4.13 settlement_allocation
|
|
280
|
+
|
|
281
|
+
**Objetivo:** distribuir um settlement em uma ou várias parcelas.
|
|
282
|
+
|
|
283
|
+
**Colunas:**
|
|
284
|
+
|
|
285
|
+
- `id`: chave primária.
|
|
286
|
+
- `settlement_id`: FK para `settlement.id`.
|
|
287
|
+
- `installment_id`: FK para `financial_installment.id`.
|
|
288
|
+
- `allocated_amount_cents`: valor aplicado na parcela.
|
|
289
|
+
- `discount_cents`: desconto aplicado.
|
|
290
|
+
- `interest_cents`: juros aplicado.
|
|
291
|
+
- `penalty_cents`: multa aplicada.
|
|
292
|
+
- `created_at`, `updated_at`.
|
|
293
|
+
|
|
294
|
+
**Observação:** possui unicidade (`settlement_id`, `installment_id`).
|
|
295
|
+
|
|
296
|
+
## 4.14 bank_statement
|
|
297
|
+
|
|
298
|
+
**Objetivo:** lote de importação de extrato bancário.
|
|
299
|
+
|
|
300
|
+
**Colunas:**
|
|
301
|
+
|
|
302
|
+
- `id`: chave primária.
|
|
303
|
+
- `bank_account_id`: FK para `bank_account.id`.
|
|
304
|
+
- `source_type`: `ofx|csv|manual`.
|
|
305
|
+
- `idempotency_key`: evita reimportação do mesmo lote (nullable).
|
|
306
|
+
- `period_start`, `period_end`: intervalo coberto no extrato (nullable).
|
|
307
|
+
- `imported_at`: data/hora da importação.
|
|
308
|
+
- `imported_by_user_id`: FK para `user.id` (nullable).
|
|
309
|
+
- `created_at`, `updated_at`.
|
|
310
|
+
|
|
311
|
+
**Relações:**
|
|
312
|
+
|
|
313
|
+
- 1:N com `bank_statement_line`.
|
|
314
|
+
|
|
315
|
+
## 4.15 bank_statement_line
|
|
316
|
+
|
|
317
|
+
**Objetivo:** transações individuais do extrato (a prova bancária).
|
|
318
|
+
|
|
319
|
+
**Colunas:**
|
|
320
|
+
|
|
321
|
+
- `id`: chave primária.
|
|
322
|
+
- `bank_statement_id`: FK para `bank_statement.id`.
|
|
323
|
+
- `bank_account_id`: FK para `bank_account.id`.
|
|
324
|
+
- `external_id`: identificador externo do banco (nullable).
|
|
325
|
+
- `posted_date`: data efetiva.
|
|
326
|
+
- `amount_cents`: valor da linha.
|
|
327
|
+
- `description`: histórico do banco.
|
|
328
|
+
- `status`: `imported|pending|reconciled|reversed|adjusted`.
|
|
329
|
+
- `dedupe_key`: chave de deduplicação (única).
|
|
330
|
+
- `created_at`, `updated_at`.
|
|
331
|
+
|
|
332
|
+
**Relações:**
|
|
333
|
+
|
|
334
|
+
- 1:1 com `bank_reconciliation` (por restrição de unicidade).
|
|
335
|
+
|
|
336
|
+
## 4.16 bank_reconciliation
|
|
337
|
+
|
|
338
|
+
**Objetivo:** vínculo auditável entre linha de extrato e settlement.
|
|
339
|
+
|
|
340
|
+
**Colunas:**
|
|
341
|
+
|
|
342
|
+
- `id`: chave primária.
|
|
343
|
+
- `bank_statement_line_id`: FK para `bank_statement_line.id` (único).
|
|
344
|
+
- `settlement_id`: FK para `settlement.id` (único).
|
|
345
|
+
- `status`: `pending|reconciled|reversed|adjusted`.
|
|
346
|
+
- `matched_at`: data/hora da conciliação (nullable).
|
|
347
|
+
- `matched_by_user_id`: FK para `user.id` (nullable).
|
|
348
|
+
- `created_at`, `updated_at`.
|
|
349
|
+
|
|
350
|
+
**Observação:** modelado como 1:1 para simplificar conciliação de eventos.
|
|
351
|
+
|
|
352
|
+
## 4.17 audit_log
|
|
353
|
+
|
|
354
|
+
**Objetivo:** trilha de auditoria funcional do módulo.
|
|
355
|
+
|
|
356
|
+
**Colunas:**
|
|
357
|
+
|
|
358
|
+
- `id`: chave primária.
|
|
359
|
+
- `actor_user_id`: FK para `user.id` (nullable).
|
|
360
|
+
- `action`: ação executada (ex.: `SETTLEMENT_CREATE`).
|
|
361
|
+
- `entity_table`: tabela afetada.
|
|
362
|
+
- `entity_id`: id da entidade afetada (string).
|
|
363
|
+
- `summary`: resumo legível (nullable).
|
|
364
|
+
- `before_data`: snapshot anterior (nullable).
|
|
365
|
+
- `after_data`: snapshot posterior (nullable).
|
|
366
|
+
- `ip_address`: origem da ação (nullable).
|
|
367
|
+
- `created_at`, `updated_at`.
|
|
368
|
+
|
|
369
|
+
## 4.18 period_close
|
|
370
|
+
|
|
371
|
+
**Objetivo:** controlar fechamento operacional de período.
|
|
372
|
+
|
|
373
|
+
**Colunas:**
|
|
374
|
+
|
|
375
|
+
- `id`: chave primária.
|
|
376
|
+
- `period_start`: início do período.
|
|
377
|
+
- `period_end`: fim do período.
|
|
378
|
+
- `status`: `open|closed`.
|
|
379
|
+
- `closed_at`: data/hora do fechamento (nullable).
|
|
380
|
+
- `closed_by_user_id`: FK para `user.id` (nullable).
|
|
381
|
+
- `notes`: observações (nullable).
|
|
382
|
+
- `created_at`, `updated_at`.
|
|
383
|
+
|
|
384
|
+
**Uso comum:** bloquear operações diretas em períodos fechados e permitir apenas estornos sob regra.
|
|
385
|
+
|
|
386
|
+
## 4.19 forecast_scenario
|
|
387
|
+
|
|
388
|
+
**Objetivo:** cenários de planejamento financeiro futuro.
|
|
389
|
+
|
|
390
|
+
**Colunas:**
|
|
391
|
+
|
|
392
|
+
- `id`: chave primária.
|
|
393
|
+
- `name`: nome do cenário (ex.: Base, Conservador).
|
|
394
|
+
- `status`: `active|inactive`.
|
|
395
|
+
- `is_default`: cenário padrão.
|
|
396
|
+
- `created_at`, `updated_at`.
|
|
397
|
+
|
|
398
|
+
**Relações:**
|
|
399
|
+
|
|
400
|
+
- 1:N com `cashflow_projection`.
|
|
401
|
+
- 1:N com `receivable_schedule`.
|
|
402
|
+
|
|
403
|
+
## 4.20 cashflow_projection
|
|
404
|
+
|
|
405
|
+
**Objetivo:** linhas de projeção de fluxo por data e tipo.
|
|
406
|
+
|
|
407
|
+
**Colunas:**
|
|
408
|
+
|
|
409
|
+
- `id`: chave primária.
|
|
410
|
+
- `scenario_id`: FK para `forecast_scenario.id`.
|
|
411
|
+
- `projection_date`: data projetada.
|
|
412
|
+
- `projection_type`: `inflow|outflow|net`.
|
|
413
|
+
- `amount_cents`: valor projetado.
|
|
414
|
+
- `notes`: observações (nullable).
|
|
415
|
+
- `created_at`, `updated_at`.
|
|
416
|
+
|
|
417
|
+
## 4.21 receivable_schedule
|
|
418
|
+
|
|
419
|
+
**Objetivo:** agenda de recebíveis previstos quando ainda não há título lançado.
|
|
420
|
+
|
|
421
|
+
**Colunas:**
|
|
422
|
+
|
|
423
|
+
- `id`: chave primária.
|
|
424
|
+
- `scenario_id`: FK para `forecast_scenario.id`.
|
|
425
|
+
- `person_id`: FK para `person.id` (nullable).
|
|
426
|
+
- `expected_date`: data esperada.
|
|
427
|
+
- `amount_cents`: valor esperado.
|
|
428
|
+
- `description`: descrição (nullable).
|
|
429
|
+
- `created_at`, `updated_at`.
|
|
430
|
+
|
|
431
|
+
## 5) Fluxos operacionais essenciais
|
|
432
|
+
|
|
433
|
+
## 5.1 Contas a pagar/receber
|
|
434
|
+
|
|
435
|
+
1. Criar `financial_title`.
|
|
436
|
+
2. Criar parcelas em `financial_installment`.
|
|
437
|
+
3. Registrar liquidação em `settlement`.
|
|
438
|
+
4. Alocar liquidação em `settlement_allocation`.
|
|
439
|
+
5. Atualizar saldo em aberto e status da parcela/título na regra de negócio.
|
|
440
|
+
|
|
441
|
+
## 5.2 Conciliação bancária
|
|
442
|
+
|
|
443
|
+
1. Importar lote em `bank_statement`.
|
|
444
|
+
2. Inserir linhas em `bank_statement_line` com `dedupe_key`.
|
|
445
|
+
3. Associar linha e settlement em `bank_reconciliation`.
|
|
446
|
+
4. Atualizar status de conciliação e registrar auditoria.
|
|
447
|
+
|
|
448
|
+
## 5.3 Estorno
|
|
449
|
+
|
|
450
|
+
1. Não apagar dados históricos.
|
|
451
|
+
2. Marcar `settlement.status = reversed`.
|
|
452
|
+
3. Reprocessar saldo em aberto das parcelas relacionadas.
|
|
453
|
+
4. Registrar no `audit_log`.
|
|
454
|
+
|
|
455
|
+
## 5.4 Fechamento de período
|
|
456
|
+
|
|
457
|
+
1. Definir janela em `period_close`.
|
|
458
|
+
2. Marcar `status = closed`.
|
|
459
|
+
3. Bloquear lançamentos/alterações do período fechado via regra da aplicação.
|
|
460
|
+
|
|
461
|
+
## 6) Invariantes recomendados de regra de negócio
|
|
462
|
+
|
|
463
|
+
Para manter consistência financeira, o ideal é garantir (na aplicação e, quando possível, no banco):
|
|
464
|
+
|
|
465
|
+
- `financial_installment.open_amount_cents >= 0`.
|
|
466
|
+
- `financial_installment.open_amount_cents <= financial_installment.amount_cents`.
|
|
467
|
+
- soma de `settlement_allocation.allocated_amount_cents` por parcela não excede o valor permitido pela política da parcela.
|
|
468
|
+
- soma de `installment_allocation.allocated_amount_cents` coerente com a política de rateio da parcela.
|
|
469
|
+
- `period_end >= period_start` em `period_close`.
|
|
470
|
+
- unicidade respeitada em tabelas de vínculo N:N para evitar duplicidades.
|
|
471
|
+
|
|
472
|
+
## 7) Diretrizes para novos desenvolvedores
|
|
473
|
+
|
|
474
|
+
- Trate `financial_title` como agregador de documento e `financial_installment` como unidade operacional de cobrança/baixa.
|
|
475
|
+
- Considere `settlement` como evento imutável de dinheiro real; prefira estorno/ajuste em vez de edição destrutiva.
|
|
476
|
+
- Use `audit_log` sempre que houver alteração relevante de estado.
|
|
477
|
+
- Ao importar extrato, monte `dedupe_key` estável para evitar duplicidade.
|
|
478
|
+
- Ao evoluir schema, preserve compatibilidade de índices e FKs com os fluxos descritos neste documento.
|
|
479
|
+
|
|
480
|
+
## 8) Resumo rápido da arquitetura
|
|
481
|
+
|
|
482
|
+
- **Cadastro:** `company_profile`, `branch`, `finance_category`, `cost_center`, `payment_method`, `bank_account`.
|
|
483
|
+
- **Operação:** `financial_title`, `financial_installment`, `settlement`, `settlement_allocation`.
|
|
484
|
+
- **Conciliação:** `bank_statement`, `bank_statement_line`, `bank_reconciliation`.
|
|
485
|
+
- **Governança:** `audit_log`, `period_close`.
|
|
486
|
+
- **Planejamento:** `forecast_scenario`, `cashflow_projection`, `receivable_schedule`.
|
|
487
|
+
|
|
488
|
+
Com essa estrutura, o módulo cobre planejamento, execução, rastreabilidade e projeção financeira de forma consistente e extensível.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finance.module.d.ts","sourceRoot":"","sources":["../src/finance.module.ts"],"names":[],"mappings":"AAMA,qBAQa,aAAa;CAAG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FinanceModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const config_1 = require("@nestjs/config");
|
|
12
|
+
const api_locale_1 = require("@hed-hog/api-locale");
|
|
13
|
+
const api_pagination_1 = require("@hed-hog/api-pagination");
|
|
14
|
+
const api_prisma_1 = require("@hed-hog/api-prisma");
|
|
15
|
+
let FinanceModule = class FinanceModule {
|
|
16
|
+
};
|
|
17
|
+
exports.FinanceModule = FinanceModule;
|
|
18
|
+
exports.FinanceModule = FinanceModule = __decorate([
|
|
19
|
+
(0, common_1.Module)({
|
|
20
|
+
imports: [
|
|
21
|
+
config_1.ConfigModule.forRoot(),
|
|
22
|
+
(0, common_1.forwardRef)(() => api_pagination_1.PaginationModule),
|
|
23
|
+
(0, common_1.forwardRef)(() => api_prisma_1.PrismaModule),
|
|
24
|
+
(0, common_1.forwardRef)(() => api_locale_1.LocaleModule)
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
], FinanceModule);
|
|
28
|
+
//# sourceMappingURL=finance.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finance.module.js","sourceRoot":"","sources":["../src/finance.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoD;AACpD,2CAA8C;AAC9C,oDAAmD;AACnD,4DAA2D;AAC3D,oDAAmD;AAU5C,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,sCAAa;wBAAb,aAAa;IARzB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY,CAAC,OAAO,EAAE;YACtB,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,iCAAgB,CAAC;YAClC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,yBAAY,CAAC;SAC/B;KACF,CAAC;GACW,aAAa,CAAG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./finance.module"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PageHeader } from '@/components/entity-list';
|
|
2
|
+
import { useTranslations } from 'next-intl';
|
|
3
|
+
|
|
4
|
+
export const Page = () => {
|
|
5
|
+
const t = useTranslations('finance.Home');
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div className="flex flex-col h-screen px-4">
|
|
9
|
+
<PageHeader
|
|
10
|
+
breadcrumbs={[{ label: 'Home', href: '/' }, { label: t('title') }]}
|
|
11
|
+
title={t('title')}
|
|
12
|
+
description={t('description')}
|
|
13
|
+
/>
|
|
14
|
+
Finance
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
columns:
|
|
2
|
+
- type: pk
|
|
3
|
+
- name: actor_user_id
|
|
4
|
+
type: fk
|
|
5
|
+
isNullable: true
|
|
6
|
+
references:
|
|
7
|
+
table: user
|
|
8
|
+
column: id
|
|
9
|
+
onDelete: SET NULL
|
|
10
|
+
onUpdate: CASCADE
|
|
11
|
+
- name: action
|
|
12
|
+
type: varchar
|
|
13
|
+
length: 80
|
|
14
|
+
- name: entity_table
|
|
15
|
+
type: varchar
|
|
16
|
+
length: 80
|
|
17
|
+
- name: entity_id
|
|
18
|
+
type: varchar
|
|
19
|
+
length: 36
|
|
20
|
+
- name: summary
|
|
21
|
+
type: text
|
|
22
|
+
isNullable: true
|
|
23
|
+
- name: before_data
|
|
24
|
+
type: text
|
|
25
|
+
isNullable: true
|
|
26
|
+
- name: after_data
|
|
27
|
+
type: text
|
|
28
|
+
isNullable: true
|
|
29
|
+
- name: ip_address
|
|
30
|
+
type: varchar
|
|
31
|
+
length: 64
|
|
32
|
+
isNullable: true
|
|
33
|
+
- type: created_at
|
|
34
|
+
- type: updated_at
|
|
35
|
+
|
|
36
|
+
indices:
|
|
37
|
+
- columns: [entity_table, entity_id]
|
|
38
|
+
- columns: [actor_user_id]
|
|
39
|
+
- columns: [action]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
columns:
|
|
2
|
+
- type: pk
|
|
3
|
+
- name: branch_id
|
|
4
|
+
type: fk
|
|
5
|
+
isNullable: true
|
|
6
|
+
references:
|
|
7
|
+
table: branch
|
|
8
|
+
column: id
|
|
9
|
+
onDelete: SET NULL
|
|
10
|
+
onUpdate: CASCADE
|
|
11
|
+
- name: code
|
|
12
|
+
type: varchar
|
|
13
|
+
length: 32
|
|
14
|
+
- name: name
|
|
15
|
+
type: varchar
|
|
16
|
+
length: 180
|
|
17
|
+
- name: bank_name
|
|
18
|
+
type: varchar
|
|
19
|
+
length: 120
|
|
20
|
+
isNullable: true
|
|
21
|
+
- name: bank_code
|
|
22
|
+
type: varchar
|
|
23
|
+
length: 10
|
|
24
|
+
isNullable: true
|
|
25
|
+
- name: agency
|
|
26
|
+
type: varchar
|
|
27
|
+
length: 20
|
|
28
|
+
isNullable: true
|
|
29
|
+
- name: account_number
|
|
30
|
+
type: varchar
|
|
31
|
+
length: 34
|
|
32
|
+
isNullable: true
|
|
33
|
+
- name: account_type
|
|
34
|
+
type: enum
|
|
35
|
+
values: [checking, savings, investment, cash, other]
|
|
36
|
+
- name: status
|
|
37
|
+
type: enum
|
|
38
|
+
values: [active, inactive]
|
|
39
|
+
- type: created_at
|
|
40
|
+
- type: updated_at
|
|
41
|
+
|
|
42
|
+
indices:
|
|
43
|
+
- columns: [code]
|
|
44
|
+
isUnique: true
|
|
45
|
+
- columns: [status]
|