@hed-hog/finance 0.0.325 → 0.0.327

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.
@@ -0,0 +1,274 @@
1
+ - slug: finance.payable.created_from_contract
2
+ name: Finance payable created from contract
3
+ module: finance
4
+ aggregate_type: financial_title
5
+ description: Disparado quando um título de contas a pagar é criado a partir de um contrato ativado.
6
+ status: active
7
+ payload_schema:
8
+ correlationId:
9
+ type: string
10
+ description: ID de correlação para rastreamento entre eventos
11
+ contractId:
12
+ type: number
13
+ description: ID do contrato de origem
14
+ proposalId:
15
+ type: number
16
+ nullable: true
17
+ description: ID da proposta de origem (quando aplicável)
18
+ personId:
19
+ type: number
20
+ description: ID da pessoa (fornecedor/credor)
21
+ financialTitle:
22
+ type: object
23
+ description: Dados do título financeiro criado
24
+ installments:
25
+ type: array
26
+ description: Lista de parcelas geradas
27
+ contract:
28
+ type: object
29
+ description: Dados do contrato de origem
30
+ metadata_schema: null
31
+
32
+ - slug: finance.receivable.created_from_contract
33
+ name: Finance receivable created from contract
34
+ module: finance
35
+ aggregate_type: financial_title
36
+ description: Disparado quando um título de contas a receber é criado a partir de um contrato ativado.
37
+ status: active
38
+ payload_schema:
39
+ correlationId:
40
+ type: string
41
+ description: ID de correlação para rastreamento entre eventos
42
+ contractId:
43
+ type: number
44
+ description: ID do contrato de origem
45
+ proposalId:
46
+ type: number
47
+ nullable: true
48
+ description: ID da proposta de origem (quando aplicável)
49
+ personId:
50
+ type: number
51
+ description: ID da pessoa (cliente/devedor)
52
+ financialTitle:
53
+ type: object
54
+ description: Dados do título financeiro criado
55
+ installments:
56
+ type: array
57
+ description: Lista de parcelas geradas
58
+ contract:
59
+ type: object
60
+ description: Dados do contrato de origem
61
+ metadata_schema: null
62
+
63
+ - slug: finance.payable.created
64
+ name: Finance payable created
65
+ module: finance
66
+ aggregate_type: financial_title
67
+ description: Disparado quando um título a pagar é criado manualmente.
68
+ status: active
69
+ payload_schema:
70
+ id:
71
+ type: number
72
+ description: ID do título a pagar criado
73
+ personId:
74
+ type: number
75
+ description: ID da pessoa (fornecedor/credor)
76
+ totalAmount:
77
+ type: number
78
+ description: Valor total do título
79
+ dueDate:
80
+ type: string
81
+ format: date-time
82
+ description: Data de vencimento
83
+ status:
84
+ type: string
85
+ description: Status do título
86
+ metadata_schema: null
87
+
88
+ - slug: finance.payable.updated
89
+ name: Finance payable updated
90
+ module: finance
91
+ aggregate_type: financial_title
92
+ description: Disparado quando um título a pagar é atualizado.
93
+ status: active
94
+ payload_schema:
95
+ id:
96
+ type: number
97
+ description: ID do título atualizado
98
+ status:
99
+ type: string
100
+ nullable: true
101
+ description: Novo status do título
102
+ totalAmount:
103
+ type: number
104
+ nullable: true
105
+ description: Novo valor total
106
+ metadata_schema: null
107
+
108
+ - slug: finance.receivable.created
109
+ name: Finance receivable created
110
+ module: finance
111
+ aggregate_type: financial_title
112
+ description: Disparado quando um título a receber é criado manualmente.
113
+ status: active
114
+ payload_schema:
115
+ id:
116
+ type: number
117
+ description: ID do título a receber criado
118
+ personId:
119
+ type: number
120
+ description: ID da pessoa (cliente/devedor)
121
+ totalAmount:
122
+ type: number
123
+ description: Valor total do título
124
+ dueDate:
125
+ type: string
126
+ format: date-time
127
+ description: Data de vencimento
128
+ status:
129
+ type: string
130
+ description: Status do título
131
+ metadata_schema: null
132
+
133
+ - slug: finance.receivable.updated
134
+ name: Finance receivable updated
135
+ module: finance
136
+ aggregate_type: financial_title
137
+ description: Disparado quando um título a receber é atualizado.
138
+ status: active
139
+ payload_schema:
140
+ id:
141
+ type: number
142
+ description: ID do título atualizado
143
+ status:
144
+ type: string
145
+ nullable: true
146
+ description: Novo status do título
147
+ totalAmount:
148
+ type: number
149
+ nullable: true
150
+ description: Novo valor total
151
+ metadata_schema: null
152
+
153
+ - slug: finance.bank_account.created
154
+ name: Finance bank account created
155
+ module: finance
156
+ aggregate_type: bank_account
157
+ description: Disparado quando uma conta bancária é criada.
158
+ status: active
159
+ payload_schema:
160
+ id:
161
+ type: number
162
+ description: ID da conta bancária criada
163
+ name:
164
+ type: string
165
+ description: Nome da conta bancária
166
+ bankCode:
167
+ type: string
168
+ nullable: true
169
+ description: Código do banco
170
+ accountNumber:
171
+ type: string
172
+ nullable: true
173
+ description: Número da conta
174
+ metadata_schema: null
175
+
176
+ - slug: finance.bank_account.updated
177
+ name: Finance bank account updated
178
+ module: finance
179
+ aggregate_type: bank_account
180
+ description: Disparado quando uma conta bancária é atualizada.
181
+ status: active
182
+ payload_schema:
183
+ id:
184
+ type: number
185
+ description: ID da conta bancária atualizada
186
+ name:
187
+ type: string
188
+ nullable: true
189
+ description: Novo nome da conta
190
+ metadata_schema: null
191
+
192
+ - slug: finance.bank_account.deleted
193
+ name: Finance bank account deleted
194
+ module: finance
195
+ aggregate_type: bank_account
196
+ description: Disparado quando uma conta bancária é excluída.
197
+ status: active
198
+ payload_schema:
199
+ id:
200
+ type: number
201
+ description: ID da conta bancária excluída
202
+ metadata_schema: null
203
+
204
+ - slug: finance.cost_center.created
205
+ name: Finance cost center created
206
+ module: finance
207
+ aggregate_type: cost_center
208
+ description: Disparado quando um centro de custo é criado.
209
+ status: active
210
+ payload_schema:
211
+ id:
212
+ type: number
213
+ description: ID do centro de custo criado
214
+ name:
215
+ type: string
216
+ description: Nome do centro de custo
217
+ code:
218
+ type: string
219
+ nullable: true
220
+ description: Código do centro de custo
221
+ metadata_schema: null
222
+
223
+ - slug: finance.cost_center.updated
224
+ name: Finance cost center updated
225
+ module: finance
226
+ aggregate_type: cost_center
227
+ description: Disparado quando um centro de custo é atualizado.
228
+ status: active
229
+ payload_schema:
230
+ id:
231
+ type: number
232
+ description: ID do centro de custo atualizado
233
+ name:
234
+ type: string
235
+ nullable: true
236
+ description: Novo nome do centro de custo
237
+ metadata_schema: null
238
+
239
+ - slug: finance.cost_center.deleted
240
+ name: Finance cost center deleted
241
+ module: finance
242
+ aggregate_type: cost_center
243
+ description: Disparado quando um centro de custo é excluído.
244
+ status: active
245
+ payload_schema:
246
+ id:
247
+ type: number
248
+ description: ID do centro de custo excluído
249
+ metadata_schema: null
250
+
251
+ - slug: finance.transfer.created
252
+ name: Finance transfer created
253
+ module: finance
254
+ aggregate_type: transfer
255
+ description: Disparado quando uma transferência entre contas é registrada.
256
+ status: active
257
+ payload_schema:
258
+ id:
259
+ type: number
260
+ description: ID da transferência criada
261
+ fromAccountId:
262
+ type: number
263
+ description: ID da conta de origem
264
+ toAccountId:
265
+ type: number
266
+ description: ID da conta de destino
267
+ amount:
268
+ type: number
269
+ description: Valor transferido
270
+ transferDate:
271
+ type: string
272
+ format: date-time
273
+ description: Data da transferência
274
+ metadata_schema: null
@@ -300,7 +300,7 @@ function CategoriaSheet({
300
300
 
301
301
  return (
302
302
  <Sheet open={open} onOpenChange={handleOpenChange}>
303
- <SheetContent className="w-full sm:max-w-lg">
303
+ <SheetContent className="w-full overflow-y-auto sm:max-w-lg">
304
304
  <SheetHeader>
305
305
  <SheetTitle>
306
306
  {editing ? t('sheet.editTitle') : t('sheet.newTitle')}
@@ -216,7 +216,7 @@ function CentroCustoSheet({
216
216
 
217
217
  return (
218
218
  <Sheet open={open} onOpenChange={handleOpenChange}>
219
- <SheetContent className="w-full sm:max-w-lg">
219
+ <SheetContent className="w-full overflow-y-auto sm:max-w-lg">
220
220
  <SheetHeader>
221
221
  <SheetTitle>
222
222
  {editingCostCenter ? t('sheet.editTitle') : t('sheet.newTitle')}
@@ -225,7 +225,7 @@ function CurrencySheet({
225
225
 
226
226
  return (
227
227
  <Sheet open={open} onOpenChange={handleOpenChange}>
228
- <SheetContent className="w-full sm:max-w-lg">
228
+ <SheetContent className="w-full overflow-y-auto sm:max-w-lg">
229
229
  <SheetHeader>
230
230
  <SheetTitle>
231
231
  {editingCurrency ? t('sheet.editTitle') : t('sheet.newTitle')}
@@ -212,7 +212,7 @@ function ClosePeriodSheet({
212
212
  onOpenChange(nextOpen);
213
213
  }}
214
214
  >
215
- <SheetContent className="w-full sm:max-w-lg">
215
+ <SheetContent className="w-full overflow-y-auto sm:max-w-lg">
216
216
  <SheetHeader>
217
217
  <SheetTitle>{t('sheet.title')}</SheetTitle>
218
218
  <SheetDescription>{t('sheet.description')}</SheetDescription>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hed-hog/finance",
3
- "version": "0.0.325",
3
+ "version": "0.0.327",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {
@@ -10,13 +10,13 @@
10
10
  "@nestjs/jwt": "^11",
11
11
  "@nestjs/mapped-types": "*",
12
12
  "@hed-hog/api": "0.0.8",
13
+ "@hed-hog/api-pagination": "0.0.7",
13
14
  "@hed-hog/api-locale": "0.0.14",
15
+ "@hed-hog/contact": "0.0.327",
14
16
  "@hed-hog/api-prisma": "0.0.6",
15
- "@hed-hog/contact": "0.0.325",
16
- "@hed-hog/tag": "0.0.325",
17
+ "@hed-hog/tag": "0.0.327",
17
18
  "@hed-hog/api-types": "0.0.1",
18
- "@hed-hog/api-pagination": "0.0.7",
19
- "@hed-hog/core": "0.0.325"
19
+ "@hed-hog/core": "0.0.327"
20
20
  },
21
21
  "exports": {
22
22
  ".": {
@@ -1,19 +1,19 @@
1
1
  import { getLocaleText } from '@hed-hog/api-locale';
2
2
  import {
3
- PageOrderDirection,
4
- PaginationDTO,
5
- PaginationService,
3
+ PageOrderDirection,
4
+ PaginationDTO,
5
+ PaginationService,
6
6
  } from '@hed-hog/api-pagination';
7
7
  import { PrismaService } from '@hed-hog/api-prisma';
8
- import { AiService, FileService, SettingService } from '@hed-hog/core';
8
+ import { AiService, FileService, IntegrationDeveloperApiService, SettingService } from '@hed-hog/core';
9
9
  import {
10
- BadRequestException,
11
- ConflictException,
12
- forwardRef,
13
- Inject,
14
- Injectable,
15
- Logger,
16
- NotFoundException,
10
+ BadRequestException,
11
+ ConflictException,
12
+ forwardRef,
13
+ Inject,
14
+ Injectable,
15
+ Logger,
16
+ NotFoundException,
17
17
  } from '@nestjs/common';
18
18
  import { createHash } from 'node:crypto';
19
19
  import { readFile } from 'node:fs/promises';
@@ -87,6 +87,8 @@ export class FinanceService {
87
87
  private readonly settingService: SettingService,
88
88
  @Inject(forwardRef(() => FileService))
89
89
  private readonly fileService: FileService,
90
+ @Inject(forwardRef(() => IntegrationDeveloperApiService))
91
+ private readonly integrationApi: IntegrationDeveloperApiService,
90
92
  ) {}
91
93
 
92
94
  async getAgentExtractInfoFromFile(
@@ -3093,7 +3095,7 @@ export class FinanceService {
3093
3095
  });
3094
3096
  });
3095
3097
 
3096
- return {
3098
+ const transferResult = {
3097
3099
  id: transferReference.replace('transfer:', ''),
3098
3100
  contaOrigemId: String(sourceAccountId),
3099
3101
  contaDestinoId: String(destinationAccountId),
@@ -3101,6 +3103,16 @@ export class FinanceService {
3101
3103
  valor: amount,
3102
3104
  descricao: description,
3103
3105
  };
3106
+
3107
+ await this.integrationApi.publishEvent({
3108
+ eventName: 'finance.transfer.created',
3109
+ sourceModule: 'finance',
3110
+ aggregateType: 'transfer',
3111
+ aggregateId: transferResult.id,
3112
+ payload: { id: transferResult.id, sourceAccountId, destinationAccountId, amount, date: postedDate.toISOString() },
3113
+ }).catch(() => null);
3114
+
3115
+ return transferResult;
3104
3116
  }
3105
3117
 
3106
3118
  async listCostCenters() {
@@ -4526,7 +4538,17 @@ export class FinanceService {
4526
4538
  },
4527
4539
  });
4528
4540
 
4529
- return this.mapBankAccountToFront(account);
4541
+ const mapped = this.mapBankAccountToFront(account);
4542
+
4543
+ await this.integrationApi.publishEvent({
4544
+ eventName: 'finance.bank_account.created',
4545
+ sourceModule: 'finance',
4546
+ aggregateType: 'bank_account',
4547
+ aggregateId: String(createdAccount.id),
4548
+ payload: { id: createdAccount.id, name, bank: data.bank, accountType: this.mapAccountTypeFromPt(data.type) },
4549
+ }).catch(() => null);
4550
+
4551
+ return mapped;
4530
4552
  }
4531
4553
 
4532
4554
  async createCostCenter(data: CreateCostCenterDto) {
@@ -4540,6 +4562,14 @@ export class FinanceService {
4540
4562
  },
4541
4563
  });
4542
4564
 
4565
+ await this.integrationApi.publishEvent({
4566
+ eventName: 'finance.cost_center.created',
4567
+ sourceModule: 'finance',
4568
+ aggregateType: 'cost_center',
4569
+ aggregateId: String(created.id),
4570
+ payload: { id: created.id, code, name: data.name.trim() },
4571
+ }).catch(() => null);
4572
+
4543
4573
  return this.mapCostCenterToFront(created);
4544
4574
  }
4545
4575
 
@@ -4622,7 +4652,7 @@ export class FinanceService {
4622
4652
  throw new NotFoundException('Bank account not found');
4623
4653
  }
4624
4654
 
4625
- const updated = await this.prisma.bank_account.update({
4655
+ const updatedBankAccount = await this.prisma.bank_account.update({
4626
4656
  where: { id },
4627
4657
  data: {
4628
4658
  bank_name: data.bank,
@@ -4656,7 +4686,15 @@ export class FinanceService {
4656
4686
  },
4657
4687
  });
4658
4688
 
4659
- return this.mapBankAccountToFront(updated);
4689
+ await this.integrationApi.publishEvent({
4690
+ eventName: 'finance.bank_account.updated',
4691
+ sourceModule: 'finance',
4692
+ aggregateType: 'bank_account',
4693
+ aggregateId: String(id),
4694
+ payload: { id, name: data.description, status: data.status },
4695
+ }).catch(() => null);
4696
+
4697
+ return this.mapBankAccountToFront(updatedBankAccount);
4660
4698
  }
4661
4699
 
4662
4700
  async updateCostCenter(id: number, data: UpdateCostCenterDto) {
@@ -4669,7 +4707,7 @@ export class FinanceService {
4669
4707
  throw new NotFoundException('Cost center not found');
4670
4708
  }
4671
4709
 
4672
- const updated = await this.prisma.cost_center.update({
4710
+ const updatedCostCenter = await this.prisma.cost_center.update({
4673
4711
  where: { id },
4674
4712
  data: {
4675
4713
  name: data.name?.trim(),
@@ -4677,7 +4715,15 @@ export class FinanceService {
4677
4715
  },
4678
4716
  });
4679
4717
 
4680
- return this.mapCostCenterToFront(updated);
4718
+ await this.integrationApi.publishEvent({
4719
+ eventName: 'finance.cost_center.updated',
4720
+ sourceModule: 'finance',
4721
+ aggregateType: 'cost_center',
4722
+ aggregateId: String(id),
4723
+ payload: { id, name: data.name, status: data.status },
4724
+ }).catch(() => null);
4725
+
4726
+ return this.mapCostCenterToFront(updatedCostCenter);
4681
4727
  }
4682
4728
 
4683
4729
  async updateFinanceCategory(id: number, data: UpdateFinanceCategoryDto) {
@@ -4769,11 +4815,17 @@ export class FinanceService {
4769
4815
 
4770
4816
  await this.prisma.bank_account.update({
4771
4817
  where: { id },
4772
- data: {
4773
- status: 'inactive',
4774
- },
4818
+ data: { status: 'inactive' },
4775
4819
  });
4776
4820
 
4821
+ await this.integrationApi.publishEvent({
4822
+ eventName: 'finance.bank_account.deleted',
4823
+ sourceModule: 'finance',
4824
+ aggregateType: 'bank_account',
4825
+ aggregateId: String(id),
4826
+ payload: { id },
4827
+ }).catch(() => null);
4828
+
4777
4829
  return { success: true };
4778
4830
  }
4779
4831
 
@@ -4789,11 +4841,17 @@ export class FinanceService {
4789
4841
 
4790
4842
  await this.prisma.cost_center.update({
4791
4843
  where: { id },
4792
- data: {
4793
- status: 'inactive',
4794
- },
4844
+ data: { status: 'inactive' },
4795
4845
  });
4796
4846
 
4847
+ await this.integrationApi.publishEvent({
4848
+ eventName: 'finance.cost_center.deleted',
4849
+ sourceModule: 'finance',
4850
+ aggregateType: 'cost_center',
4851
+ aggregateId: String(id),
4852
+ payload: { id },
4853
+ }).catch(() => null);
4854
+
4797
4855
  return { success: true };
4798
4856
  }
4799
4857