@hed-hog/finance 0.0.274 → 0.0.276
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 +228 -126
- package/dist/dto/create-bank-reconciliation.dto.d.ts +8 -0
- package/dist/dto/create-bank-reconciliation.dto.d.ts.map +1 -0
- package/dist/dto/create-bank-reconciliation.dto.js +43 -0
- package/dist/dto/create-bank-reconciliation.dto.js.map +1 -0
- package/dist/finance-data.controller.d.ts +2 -0
- package/dist/finance-data.controller.d.ts.map +1 -1
- package/dist/finance-statements.controller.d.ts +42 -0
- package/dist/finance-statements.controller.d.ts.map +1 -1
- package/dist/finance-statements.controller.js +13 -0
- package/dist/finance-statements.controller.js.map +1 -1
- package/dist/finance.service.d.ts +44 -0
- package/dist/finance.service.d.ts.map +1 -1
- package/dist/finance.service.js +98 -9
- package/dist/finance.service.js.map +1 -1
- package/hedhog/data/route.yaml +9 -0
- package/hedhog/frontend/app/_components/person-field-with-create.tsx.ejs +126 -126
- package/hedhog/frontend/app/accounts-payable/approvals/page.tsx.ejs +373 -373
- package/hedhog/frontend/app/accounts-payable/installments/[id]/page.tsx.ejs +1270 -1270
- package/hedhog/frontend/app/accounts-receivable/installments/[id]/page.tsx.ejs +982 -982
- package/hedhog/frontend/app/cash-and-banks/bank-accounts/page.tsx.ejs +686 -686
- package/hedhog/frontend/app/cash-and-banks/bank-reconciliation/page.tsx.ejs +152 -32
- package/hedhog/frontend/app/cash-and-banks/statements/page.tsx.ejs +986 -986
- package/hedhog/frontend/app/cash-and-banks/transfers/page.tsx.ejs +492 -492
- package/hedhog/frontend/app/page.tsx.ejs +372 -372
- package/hedhog/frontend/app/planning/cash-flow-forecast/page.tsx.ejs +329 -329
- package/hedhog/frontend/app/planning/receivables-calendar/page.tsx.ejs +227 -227
- package/hedhog/frontend/app/planning/scenarios/page.tsx.ejs +408 -408
- package/hedhog/frontend/messages/en.json +15 -5
- package/hedhog/frontend/messages/pt.json +15 -5
- package/package.json +7 -7
- package/src/dto/create-bank-reconciliation.dto.ts +24 -0
- package/src/finance-statements.controller.ts +14 -0
- package/src/finance.module.ts +43 -43
- package/src/finance.service.ts +118 -0
- package/src/index.ts +14 -14
- package/dist/finance.controller.d.ts +0 -276
- package/dist/finance.controller.d.ts.map +0 -1
- package/dist/finance.controller.js +0 -110
- package/dist/finance.controller.js.map +0 -1
|
@@ -1,408 +1,408 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Page, PageHeader } from '@/components/entity-list';
|
|
4
|
-
import { Badge } from '@/components/ui/badge';
|
|
5
|
-
import { Button } from '@/components/ui/button';
|
|
6
|
-
import {
|
|
7
|
-
Card,
|
|
8
|
-
CardContent,
|
|
9
|
-
CardDescription,
|
|
10
|
-
CardHeader,
|
|
11
|
-
CardTitle,
|
|
12
|
-
} from '@/components/ui/card';
|
|
13
|
-
import { Label } from '@/components/ui/label';
|
|
14
|
-
import { Money } from '@/components/ui/money';
|
|
15
|
-
import { Slider } from '@/components/ui/slider';
|
|
16
|
-
import { useApp } from '@hed-hog/next-app-provider';
|
|
17
|
-
import {
|
|
18
|
-
Check,
|
|
19
|
-
Lightbulb,
|
|
20
|
-
Loader2,
|
|
21
|
-
Target,
|
|
22
|
-
TrendingDown,
|
|
23
|
-
TrendingUp,
|
|
24
|
-
} from 'lucide-react';
|
|
25
|
-
import { useTranslations } from 'next-intl';
|
|
26
|
-
import { useEffect, useState } from 'react';
|
|
27
|
-
import { formatarMoeda } from '../../_lib/formatters';
|
|
28
|
-
import { useFinanceData } from '../../_lib/use-finance-data';
|
|
29
|
-
|
|
30
|
-
export default function CenariosPage() {
|
|
31
|
-
const t = useTranslations('finance.ScenariosPage');
|
|
32
|
-
const { request, showToastHandler } = useApp();
|
|
33
|
-
const { data, isFetching, refetch } = useFinanceData();
|
|
34
|
-
const { cenarios, kpis } = data;
|
|
35
|
-
|
|
36
|
-
const [cenarioAtivo, setCenarioAtivo] = useState('base');
|
|
37
|
-
const [isSaving, setIsSaving] = useState(false);
|
|
38
|
-
const [premissas, setPremissas] = useState({
|
|
39
|
-
atrasoMedio: 5,
|
|
40
|
-
taxaInadimplencia: 3,
|
|
41
|
-
crescimentoReceita: 5,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
if (!cenarios?.length) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const selected = cenarios.find((c) => c.id === cenarioAtivo);
|
|
50
|
-
if (selected) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const defaultScenario = cenarios.find((c) => c.padrao) || cenarios[0];
|
|
55
|
-
|
|
56
|
-
if (!defaultScenario) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
setCenarioAtivo(defaultScenario.id);
|
|
61
|
-
setPremissas({
|
|
62
|
-
atrasoMedio: defaultScenario.atrasoMedio,
|
|
63
|
-
taxaInadimplencia: defaultScenario.taxaInadimplencia,
|
|
64
|
-
crescimentoReceita: defaultScenario.crescimentoReceita,
|
|
65
|
-
});
|
|
66
|
-
}, [cenarios, cenarioAtivo]);
|
|
67
|
-
|
|
68
|
-
const cenarioSelecionado = cenarios.find((c) => c.id === cenarioAtivo);
|
|
69
|
-
|
|
70
|
-
const impactoSaldo =
|
|
71
|
-
kpis.saldoCaixa * (1 + premissas.crescimentoReceita / 100);
|
|
72
|
-
const impactoInadimplencia =
|
|
73
|
-
kpis.inadimplencia * (1 + premissas.taxaInadimplencia / 10);
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Page>
|
|
77
|
-
<PageHeader
|
|
78
|
-
title={t('header.title')}
|
|
79
|
-
description={t('header.description')}
|
|
80
|
-
breadcrumbs={[
|
|
81
|
-
{ label: t('breadcrumbs.home'), href: '/' },
|
|
82
|
-
{ label: t('breadcrumbs.finance'), href: '/finance' },
|
|
83
|
-
{ label: t('breadcrumbs.current') },
|
|
84
|
-
]}
|
|
85
|
-
/>
|
|
86
|
-
|
|
87
|
-
<div className="grid gap-4 md:grid-cols-3">
|
|
88
|
-
{cenarios.map((cenario) => {
|
|
89
|
-
const isAtivo = cenario.id === cenarioAtivo;
|
|
90
|
-
const Icon =
|
|
91
|
-
cenario.nome === 'Otimista'
|
|
92
|
-
? TrendingUp
|
|
93
|
-
: cenario.nome === 'Pessimista'
|
|
94
|
-
? TrendingDown
|
|
95
|
-
: Target;
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<Card
|
|
99
|
-
key={cenario.id}
|
|
100
|
-
className={`cursor-pointer transition-all ${
|
|
101
|
-
isAtivo
|
|
102
|
-
? 'border-primary ring-2 ring-primary/20'
|
|
103
|
-
: 'hover:border-muted-foreground/50'
|
|
104
|
-
}`}
|
|
105
|
-
onClick={() => {
|
|
106
|
-
setCenarioAtivo(cenario.id);
|
|
107
|
-
setPremissas({
|
|
108
|
-
atrasoMedio: cenario.atrasoMedio,
|
|
109
|
-
taxaInadimplencia: cenario.taxaInadimplencia,
|
|
110
|
-
crescimentoReceita: cenario.crescimentoReceita,
|
|
111
|
-
});
|
|
112
|
-
}}
|
|
113
|
-
>
|
|
114
|
-
<CardHeader>
|
|
115
|
-
<div className="flex items-center justify-between">
|
|
116
|
-
<div className="flex items-center gap-3">
|
|
117
|
-
<div
|
|
118
|
-
className={`flex h-10 w-10 items-center justify-center rounded-lg ${
|
|
119
|
-
cenario.nome === 'Otimista'
|
|
120
|
-
? 'bg-green-100'
|
|
121
|
-
: cenario.nome === 'Pessimista'
|
|
122
|
-
? 'bg-red-100'
|
|
123
|
-
: 'bg-blue-100'
|
|
124
|
-
}`}
|
|
125
|
-
>
|
|
126
|
-
<Icon
|
|
127
|
-
className={`h-5 w-5 ${
|
|
128
|
-
cenario.nome === 'Otimista'
|
|
129
|
-
? 'text-green-600'
|
|
130
|
-
: cenario.nome === 'Pessimista'
|
|
131
|
-
? 'text-red-600'
|
|
132
|
-
: 'text-blue-600'
|
|
133
|
-
}`}
|
|
134
|
-
/>
|
|
135
|
-
</div>
|
|
136
|
-
<div>
|
|
137
|
-
<CardTitle className="text-base">
|
|
138
|
-
{cenario.nome}
|
|
139
|
-
</CardTitle>
|
|
140
|
-
<CardDescription>{cenario.descricao}</CardDescription>
|
|
141
|
-
</div>
|
|
142
|
-
</div>
|
|
143
|
-
{isAtivo && (
|
|
144
|
-
<Badge className="bg-primary text-primary-foreground">
|
|
145
|
-
<Check className="mr-1 h-3 w-3" />
|
|
146
|
-
{t('cards.active')}
|
|
147
|
-
</Badge>
|
|
148
|
-
)}
|
|
149
|
-
</div>
|
|
150
|
-
</CardHeader>
|
|
151
|
-
<CardContent>
|
|
152
|
-
<div className="grid grid-cols-3 gap-4 text-center">
|
|
153
|
-
<div>
|
|
154
|
-
<p className="text-xs text-muted-foreground">
|
|
155
|
-
{t('cards.delay')}
|
|
156
|
-
</p>
|
|
157
|
-
<p className="font-semibold">
|
|
158
|
-
{t('cards.days', { value: cenario.atrasoMedio })}
|
|
159
|
-
</p>
|
|
160
|
-
</div>
|
|
161
|
-
<div>
|
|
162
|
-
<p className="text-xs text-muted-foreground">
|
|
163
|
-
{t('cards.defaultRate')}
|
|
164
|
-
</p>
|
|
165
|
-
<p className="font-semibold">
|
|
166
|
-
{cenario.taxaInadimplencia}%
|
|
167
|
-
</p>
|
|
168
|
-
</div>
|
|
169
|
-
<div>
|
|
170
|
-
<p className="text-xs text-muted-foreground">
|
|
171
|
-
{t('cards.growth')}
|
|
172
|
-
</p>
|
|
173
|
-
<p
|
|
174
|
-
className={`font-semibold ${
|
|
175
|
-
cenario.crescimentoReceita >= 0
|
|
176
|
-
? 'text-green-600'
|
|
177
|
-
: 'text-red-600'
|
|
178
|
-
}`}
|
|
179
|
-
>
|
|
180
|
-
{cenario.crescimentoReceita > 0 && '+'}
|
|
181
|
-
{cenario.crescimentoReceita}%
|
|
182
|
-
</p>
|
|
183
|
-
</div>
|
|
184
|
-
</div>
|
|
185
|
-
</CardContent>
|
|
186
|
-
</Card>
|
|
187
|
-
);
|
|
188
|
-
})}
|
|
189
|
-
</div>
|
|
190
|
-
|
|
191
|
-
<div className="grid gap-6 lg:grid-cols-2">
|
|
192
|
-
<Card>
|
|
193
|
-
<CardHeader>
|
|
194
|
-
<CardTitle className="flex items-center gap-2">
|
|
195
|
-
<Lightbulb className="h-4 w-4" />
|
|
196
|
-
{t('assumptions.title')}
|
|
197
|
-
</CardTitle>
|
|
198
|
-
<CardDescription>
|
|
199
|
-
{t('assumptions.description', {
|
|
200
|
-
scenario: cenarioSelecionado?.nome ?? '',
|
|
201
|
-
})}
|
|
202
|
-
</CardDescription>
|
|
203
|
-
</CardHeader>
|
|
204
|
-
<CardContent className="space-y-6">
|
|
205
|
-
<div className="space-y-4">
|
|
206
|
-
<div className="space-y-2">
|
|
207
|
-
<div className="flex items-center justify-between">
|
|
208
|
-
<Label>{t('assumptions.averageDelay')}</Label>
|
|
209
|
-
<span className="text-sm font-medium">
|
|
210
|
-
{t('cards.days', { value: premissas.atrasoMedio })}
|
|
211
|
-
</span>
|
|
212
|
-
</div>
|
|
213
|
-
<Slider
|
|
214
|
-
value={[premissas.atrasoMedio]}
|
|
215
|
-
disabled={isSaving || isFetching}
|
|
216
|
-
onValueChange={([value]) =>
|
|
217
|
-
setPremissas({
|
|
218
|
-
...premissas,
|
|
219
|
-
atrasoMedio: value ?? premissas.atrasoMedio,
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
max={30}
|
|
223
|
-
step={1}
|
|
224
|
-
/>
|
|
225
|
-
</div>
|
|
226
|
-
|
|
227
|
-
<div className="space-y-2">
|
|
228
|
-
<div className="flex items-center justify-between">
|
|
229
|
-
<Label>{t('assumptions.defaultRate')}</Label>
|
|
230
|
-
<span className="text-sm font-medium">
|
|
231
|
-
{premissas.taxaInadimplencia}%
|
|
232
|
-
</span>
|
|
233
|
-
</div>
|
|
234
|
-
<Slider
|
|
235
|
-
value={[premissas.taxaInadimplencia]}
|
|
236
|
-
disabled={isSaving || isFetching}
|
|
237
|
-
onValueChange={([value]) =>
|
|
238
|
-
setPremissas({
|
|
239
|
-
...premissas,
|
|
240
|
-
taxaInadimplencia: value ?? premissas.taxaInadimplencia,
|
|
241
|
-
})
|
|
242
|
-
}
|
|
243
|
-
max={15}
|
|
244
|
-
step={0.5}
|
|
245
|
-
/>
|
|
246
|
-
</div>
|
|
247
|
-
|
|
248
|
-
<div className="space-y-2">
|
|
249
|
-
<div className="flex items-center justify-between">
|
|
250
|
-
<Label>{t('assumptions.revenueGrowth')}</Label>
|
|
251
|
-
<span
|
|
252
|
-
className={`text-sm font-medium ${
|
|
253
|
-
premissas.crescimentoReceita >= 0
|
|
254
|
-
? 'text-green-600'
|
|
255
|
-
: 'text-red-600'
|
|
256
|
-
}`}
|
|
257
|
-
>
|
|
258
|
-
{premissas.crescimentoReceita > 0 && '+'}
|
|
259
|
-
{premissas.crescimentoReceita}%
|
|
260
|
-
</span>
|
|
261
|
-
</div>
|
|
262
|
-
<Slider
|
|
263
|
-
value={[premissas.crescimentoReceita + 10]} // Offset para permitir valores negativos
|
|
264
|
-
disabled={isSaving || isFetching}
|
|
265
|
-
onValueChange={([value]) =>
|
|
266
|
-
setPremissas({
|
|
267
|
-
...premissas,
|
|
268
|
-
crescimentoReceita:
|
|
269
|
-
(value ?? premissas.crescimentoReceita + 10) - 10,
|
|
270
|
-
})
|
|
271
|
-
}
|
|
272
|
-
max={25}
|
|
273
|
-
step={1}
|
|
274
|
-
/>
|
|
275
|
-
</div>
|
|
276
|
-
</div>
|
|
277
|
-
|
|
278
|
-
<div className="flex justify-end gap-2 pt-4">
|
|
279
|
-
<Button
|
|
280
|
-
variant="outline"
|
|
281
|
-
disabled={isSaving || isFetching || !cenarioSelecionado}
|
|
282
|
-
onClick={() => {
|
|
283
|
-
if (cenarioSelecionado) {
|
|
284
|
-
setPremissas({
|
|
285
|
-
atrasoMedio: cenarioSelecionado.atrasoMedio,
|
|
286
|
-
taxaInadimplencia: cenarioSelecionado.taxaInadimplencia,
|
|
287
|
-
crescimentoReceita: cenarioSelecionado.crescimentoReceita,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}}
|
|
291
|
-
>
|
|
292
|
-
{t('assumptions.restore')}
|
|
293
|
-
</Button>
|
|
294
|
-
<Button
|
|
295
|
-
disabled={isSaving || isFetching || !cenarioSelecionado}
|
|
296
|
-
onClick={async () => {
|
|
297
|
-
if (!cenarioSelecionado || isSaving) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
try {
|
|
302
|
-
setIsSaving(true);
|
|
303
|
-
|
|
304
|
-
await request({
|
|
305
|
-
url: `/finance/scenarios/${cenarioSelecionado.id}`,
|
|
306
|
-
method: 'PATCH',
|
|
307
|
-
data: {
|
|
308
|
-
atrasoMedio: premissas.atrasoMedio,
|
|
309
|
-
taxaInadimplencia: premissas.taxaInadimplencia,
|
|
310
|
-
crescimentoReceita: premissas.crescimentoReceita,
|
|
311
|
-
setAsDefault: true,
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
await refetch();
|
|
316
|
-
showToastHandler?.('success', 'Cenário salvo com sucesso');
|
|
317
|
-
} catch {
|
|
318
|
-
showToastHandler?.('error', 'Erro ao salvar cenário');
|
|
319
|
-
} finally {
|
|
320
|
-
setIsSaving(false);
|
|
321
|
-
}
|
|
322
|
-
}}
|
|
323
|
-
>
|
|
324
|
-
{isSaving ? (
|
|
325
|
-
<>
|
|
326
|
-
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
327
|
-
{t('assumptions.apply')}
|
|
328
|
-
</>
|
|
329
|
-
) : (
|
|
330
|
-
t('assumptions.apply')
|
|
331
|
-
)}
|
|
332
|
-
</Button>
|
|
333
|
-
</div>
|
|
334
|
-
</CardContent>
|
|
335
|
-
</Card>
|
|
336
|
-
|
|
337
|
-
<Card>
|
|
338
|
-
<CardHeader>
|
|
339
|
-
<CardTitle>{t('impact.title')}</CardTitle>
|
|
340
|
-
<CardDescription>{t('impact.description')}</CardDescription>
|
|
341
|
-
</CardHeader>
|
|
342
|
-
<CardContent>
|
|
343
|
-
<div className="space-y-6">
|
|
344
|
-
<div className="rounded-lg border p-4">
|
|
345
|
-
<p className="text-sm text-muted-foreground">
|
|
346
|
-
{t('impact.projectedBalance30d')}
|
|
347
|
-
</p>
|
|
348
|
-
<p className="text-3xl font-bold">
|
|
349
|
-
<Money value={impactoSaldo} />
|
|
350
|
-
</p>
|
|
351
|
-
<p
|
|
352
|
-
className={`text-sm ${
|
|
353
|
-
impactoSaldo >= kpis.saldoCaixa
|
|
354
|
-
? 'text-green-600'
|
|
355
|
-
: 'text-red-600'
|
|
356
|
-
}`}
|
|
357
|
-
>
|
|
358
|
-
{impactoSaldo >= kpis.saldoCaixa ? '+' : ''}
|
|
359
|
-
{t('impact.vsCurrent', {
|
|
360
|
-
value: formatarMoeda(impactoSaldo - kpis.saldoCaixa),
|
|
361
|
-
})}
|
|
362
|
-
</p>
|
|
363
|
-
</div>
|
|
364
|
-
|
|
365
|
-
<div className="rounded-lg border p-4">
|
|
366
|
-
<p className="text-sm text-muted-foreground">
|
|
367
|
-
{t('impact.projectedDefault')}
|
|
368
|
-
</p>
|
|
369
|
-
<p className="text-3xl font-bold text-red-600">
|
|
370
|
-
<Money value={impactoInadimplencia} />
|
|
371
|
-
</p>
|
|
372
|
-
<p className="text-sm text-muted-foreground">
|
|
373
|
-
{t('impact.vsCurrent', {
|
|
374
|
-
value: formatarMoeda(
|
|
375
|
-
impactoInadimplencia - kpis.inadimplencia
|
|
376
|
-
),
|
|
377
|
-
})}
|
|
378
|
-
</p>
|
|
379
|
-
</div>
|
|
380
|
-
|
|
381
|
-
<div className="rounded-lg border p-4">
|
|
382
|
-
<p className="text-sm text-muted-foreground">
|
|
383
|
-
{t('impact.cashFlowForecast')}
|
|
384
|
-
</p>
|
|
385
|
-
<p
|
|
386
|
-
className={`text-3xl font-bold ${
|
|
387
|
-
premissas.crescimentoReceita >= 0
|
|
388
|
-
? 'text-green-600'
|
|
389
|
-
: 'text-red-600'
|
|
390
|
-
}`}
|
|
391
|
-
>
|
|
392
|
-
{premissas.crescimentoReceita >= 0
|
|
393
|
-
? t('impact.positive')
|
|
394
|
-
: t('impact.negative')}
|
|
395
|
-
</p>
|
|
396
|
-
<p className="text-sm text-muted-foreground">
|
|
397
|
-
{t('impact.withGrowth', {
|
|
398
|
-
value: premissas.crescimentoReceita,
|
|
399
|
-
})}
|
|
400
|
-
</p>
|
|
401
|
-
</div>
|
|
402
|
-
</div>
|
|
403
|
-
</CardContent>
|
|
404
|
-
</Card>
|
|
405
|
-
</div>
|
|
406
|
-
</Page>
|
|
407
|
-
);
|
|
408
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Page, PageHeader } from '@/components/entity-list';
|
|
4
|
+
import { Badge } from '@/components/ui/badge';
|
|
5
|
+
import { Button } from '@/components/ui/button';
|
|
6
|
+
import {
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle,
|
|
12
|
+
} from '@/components/ui/card';
|
|
13
|
+
import { Label } from '@/components/ui/label';
|
|
14
|
+
import { Money } from '@/components/ui/money';
|
|
15
|
+
import { Slider } from '@/components/ui/slider';
|
|
16
|
+
import { useApp } from '@hed-hog/next-app-provider';
|
|
17
|
+
import {
|
|
18
|
+
Check,
|
|
19
|
+
Lightbulb,
|
|
20
|
+
Loader2,
|
|
21
|
+
Target,
|
|
22
|
+
TrendingDown,
|
|
23
|
+
TrendingUp,
|
|
24
|
+
} from 'lucide-react';
|
|
25
|
+
import { useTranslations } from 'next-intl';
|
|
26
|
+
import { useEffect, useState } from 'react';
|
|
27
|
+
import { formatarMoeda } from '../../_lib/formatters';
|
|
28
|
+
import { useFinanceData } from '../../_lib/use-finance-data';
|
|
29
|
+
|
|
30
|
+
export default function CenariosPage() {
|
|
31
|
+
const t = useTranslations('finance.ScenariosPage');
|
|
32
|
+
const { request, showToastHandler } = useApp();
|
|
33
|
+
const { data, isFetching, refetch } = useFinanceData();
|
|
34
|
+
const { cenarios, kpis } = data;
|
|
35
|
+
|
|
36
|
+
const [cenarioAtivo, setCenarioAtivo] = useState('base');
|
|
37
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
38
|
+
const [premissas, setPremissas] = useState({
|
|
39
|
+
atrasoMedio: 5,
|
|
40
|
+
taxaInadimplencia: 3,
|
|
41
|
+
crescimentoReceita: 5,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!cenarios?.length) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const selected = cenarios.find((c) => c.id === cenarioAtivo);
|
|
50
|
+
if (selected) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const defaultScenario = cenarios.find((c) => c.padrao) || cenarios[0];
|
|
55
|
+
|
|
56
|
+
if (!defaultScenario) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setCenarioAtivo(defaultScenario.id);
|
|
61
|
+
setPremissas({
|
|
62
|
+
atrasoMedio: defaultScenario.atrasoMedio,
|
|
63
|
+
taxaInadimplencia: defaultScenario.taxaInadimplencia,
|
|
64
|
+
crescimentoReceita: defaultScenario.crescimentoReceita,
|
|
65
|
+
});
|
|
66
|
+
}, [cenarios, cenarioAtivo]);
|
|
67
|
+
|
|
68
|
+
const cenarioSelecionado = cenarios.find((c) => c.id === cenarioAtivo);
|
|
69
|
+
|
|
70
|
+
const impactoSaldo =
|
|
71
|
+
kpis.saldoCaixa * (1 + premissas.crescimentoReceita / 100);
|
|
72
|
+
const impactoInadimplencia =
|
|
73
|
+
kpis.inadimplencia * (1 + premissas.taxaInadimplencia / 10);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Page>
|
|
77
|
+
<PageHeader
|
|
78
|
+
title={t('header.title')}
|
|
79
|
+
description={t('header.description')}
|
|
80
|
+
breadcrumbs={[
|
|
81
|
+
{ label: t('breadcrumbs.home'), href: '/' },
|
|
82
|
+
{ label: t('breadcrumbs.finance'), href: '/finance' },
|
|
83
|
+
{ label: t('breadcrumbs.current') },
|
|
84
|
+
]}
|
|
85
|
+
/>
|
|
86
|
+
|
|
87
|
+
<div className="grid gap-4 md:grid-cols-3">
|
|
88
|
+
{cenarios.map((cenario) => {
|
|
89
|
+
const isAtivo = cenario.id === cenarioAtivo;
|
|
90
|
+
const Icon =
|
|
91
|
+
cenario.nome === 'Otimista'
|
|
92
|
+
? TrendingUp
|
|
93
|
+
: cenario.nome === 'Pessimista'
|
|
94
|
+
? TrendingDown
|
|
95
|
+
: Target;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Card
|
|
99
|
+
key={cenario.id}
|
|
100
|
+
className={`cursor-pointer transition-all ${
|
|
101
|
+
isAtivo
|
|
102
|
+
? 'border-primary ring-2 ring-primary/20'
|
|
103
|
+
: 'hover:border-muted-foreground/50'
|
|
104
|
+
}`}
|
|
105
|
+
onClick={() => {
|
|
106
|
+
setCenarioAtivo(cenario.id);
|
|
107
|
+
setPremissas({
|
|
108
|
+
atrasoMedio: cenario.atrasoMedio,
|
|
109
|
+
taxaInadimplencia: cenario.taxaInadimplencia,
|
|
110
|
+
crescimentoReceita: cenario.crescimentoReceita,
|
|
111
|
+
});
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<CardHeader>
|
|
115
|
+
<div className="flex items-center justify-between">
|
|
116
|
+
<div className="flex items-center gap-3">
|
|
117
|
+
<div
|
|
118
|
+
className={`flex h-10 w-10 items-center justify-center rounded-lg ${
|
|
119
|
+
cenario.nome === 'Otimista'
|
|
120
|
+
? 'bg-green-100'
|
|
121
|
+
: cenario.nome === 'Pessimista'
|
|
122
|
+
? 'bg-red-100'
|
|
123
|
+
: 'bg-blue-100'
|
|
124
|
+
}`}
|
|
125
|
+
>
|
|
126
|
+
<Icon
|
|
127
|
+
className={`h-5 w-5 ${
|
|
128
|
+
cenario.nome === 'Otimista'
|
|
129
|
+
? 'text-green-600'
|
|
130
|
+
: cenario.nome === 'Pessimista'
|
|
131
|
+
? 'text-red-600'
|
|
132
|
+
: 'text-blue-600'
|
|
133
|
+
}`}
|
|
134
|
+
/>
|
|
135
|
+
</div>
|
|
136
|
+
<div>
|
|
137
|
+
<CardTitle className="text-base">
|
|
138
|
+
{cenario.nome}
|
|
139
|
+
</CardTitle>
|
|
140
|
+
<CardDescription>{cenario.descricao}</CardDescription>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
{isAtivo && (
|
|
144
|
+
<Badge className="bg-primary text-primary-foreground">
|
|
145
|
+
<Check className="mr-1 h-3 w-3" />
|
|
146
|
+
{t('cards.active')}
|
|
147
|
+
</Badge>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
</CardHeader>
|
|
151
|
+
<CardContent>
|
|
152
|
+
<div className="grid grid-cols-3 gap-4 text-center">
|
|
153
|
+
<div>
|
|
154
|
+
<p className="text-xs text-muted-foreground">
|
|
155
|
+
{t('cards.delay')}
|
|
156
|
+
</p>
|
|
157
|
+
<p className="font-semibold">
|
|
158
|
+
{t('cards.days', { value: cenario.atrasoMedio })}
|
|
159
|
+
</p>
|
|
160
|
+
</div>
|
|
161
|
+
<div>
|
|
162
|
+
<p className="text-xs text-muted-foreground">
|
|
163
|
+
{t('cards.defaultRate')}
|
|
164
|
+
</p>
|
|
165
|
+
<p className="font-semibold">
|
|
166
|
+
{cenario.taxaInadimplencia}%
|
|
167
|
+
</p>
|
|
168
|
+
</div>
|
|
169
|
+
<div>
|
|
170
|
+
<p className="text-xs text-muted-foreground">
|
|
171
|
+
{t('cards.growth')}
|
|
172
|
+
</p>
|
|
173
|
+
<p
|
|
174
|
+
className={`font-semibold ${
|
|
175
|
+
cenario.crescimentoReceita >= 0
|
|
176
|
+
? 'text-green-600'
|
|
177
|
+
: 'text-red-600'
|
|
178
|
+
}`}
|
|
179
|
+
>
|
|
180
|
+
{cenario.crescimentoReceita > 0 && '+'}
|
|
181
|
+
{cenario.crescimentoReceita}%
|
|
182
|
+
</p>
|
|
183
|
+
</div>
|
|
184
|
+
</div>
|
|
185
|
+
</CardContent>
|
|
186
|
+
</Card>
|
|
187
|
+
);
|
|
188
|
+
})}
|
|
189
|
+
</div>
|
|
190
|
+
|
|
191
|
+
<div className="grid gap-6 lg:grid-cols-2">
|
|
192
|
+
<Card>
|
|
193
|
+
<CardHeader>
|
|
194
|
+
<CardTitle className="flex items-center gap-2">
|
|
195
|
+
<Lightbulb className="h-4 w-4" />
|
|
196
|
+
{t('assumptions.title')}
|
|
197
|
+
</CardTitle>
|
|
198
|
+
<CardDescription>
|
|
199
|
+
{t('assumptions.description', {
|
|
200
|
+
scenario: cenarioSelecionado?.nome ?? '',
|
|
201
|
+
})}
|
|
202
|
+
</CardDescription>
|
|
203
|
+
</CardHeader>
|
|
204
|
+
<CardContent className="space-y-6">
|
|
205
|
+
<div className="space-y-4">
|
|
206
|
+
<div className="space-y-2">
|
|
207
|
+
<div className="flex items-center justify-between">
|
|
208
|
+
<Label>{t('assumptions.averageDelay')}</Label>
|
|
209
|
+
<span className="text-sm font-medium">
|
|
210
|
+
{t('cards.days', { value: premissas.atrasoMedio })}
|
|
211
|
+
</span>
|
|
212
|
+
</div>
|
|
213
|
+
<Slider
|
|
214
|
+
value={[premissas.atrasoMedio]}
|
|
215
|
+
disabled={isSaving || isFetching}
|
|
216
|
+
onValueChange={([value]) =>
|
|
217
|
+
setPremissas({
|
|
218
|
+
...premissas,
|
|
219
|
+
atrasoMedio: value ?? premissas.atrasoMedio,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
max={30}
|
|
223
|
+
step={1}
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<div className="space-y-2">
|
|
228
|
+
<div className="flex items-center justify-between">
|
|
229
|
+
<Label>{t('assumptions.defaultRate')}</Label>
|
|
230
|
+
<span className="text-sm font-medium">
|
|
231
|
+
{premissas.taxaInadimplencia}%
|
|
232
|
+
</span>
|
|
233
|
+
</div>
|
|
234
|
+
<Slider
|
|
235
|
+
value={[premissas.taxaInadimplencia]}
|
|
236
|
+
disabled={isSaving || isFetching}
|
|
237
|
+
onValueChange={([value]) =>
|
|
238
|
+
setPremissas({
|
|
239
|
+
...premissas,
|
|
240
|
+
taxaInadimplencia: value ?? premissas.taxaInadimplencia,
|
|
241
|
+
})
|
|
242
|
+
}
|
|
243
|
+
max={15}
|
|
244
|
+
step={0.5}
|
|
245
|
+
/>
|
|
246
|
+
</div>
|
|
247
|
+
|
|
248
|
+
<div className="space-y-2">
|
|
249
|
+
<div className="flex items-center justify-between">
|
|
250
|
+
<Label>{t('assumptions.revenueGrowth')}</Label>
|
|
251
|
+
<span
|
|
252
|
+
className={`text-sm font-medium ${
|
|
253
|
+
premissas.crescimentoReceita >= 0
|
|
254
|
+
? 'text-green-600'
|
|
255
|
+
: 'text-red-600'
|
|
256
|
+
}`}
|
|
257
|
+
>
|
|
258
|
+
{premissas.crescimentoReceita > 0 && '+'}
|
|
259
|
+
{premissas.crescimentoReceita}%
|
|
260
|
+
</span>
|
|
261
|
+
</div>
|
|
262
|
+
<Slider
|
|
263
|
+
value={[premissas.crescimentoReceita + 10]} // Offset para permitir valores negativos
|
|
264
|
+
disabled={isSaving || isFetching}
|
|
265
|
+
onValueChange={([value]) =>
|
|
266
|
+
setPremissas({
|
|
267
|
+
...premissas,
|
|
268
|
+
crescimentoReceita:
|
|
269
|
+
(value ?? premissas.crescimentoReceita + 10) - 10,
|
|
270
|
+
})
|
|
271
|
+
}
|
|
272
|
+
max={25}
|
|
273
|
+
step={1}
|
|
274
|
+
/>
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
<div className="flex justify-end gap-2 pt-4">
|
|
279
|
+
<Button
|
|
280
|
+
variant="outline"
|
|
281
|
+
disabled={isSaving || isFetching || !cenarioSelecionado}
|
|
282
|
+
onClick={() => {
|
|
283
|
+
if (cenarioSelecionado) {
|
|
284
|
+
setPremissas({
|
|
285
|
+
atrasoMedio: cenarioSelecionado.atrasoMedio,
|
|
286
|
+
taxaInadimplencia: cenarioSelecionado.taxaInadimplencia,
|
|
287
|
+
crescimentoReceita: cenarioSelecionado.crescimentoReceita,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}}
|
|
291
|
+
>
|
|
292
|
+
{t('assumptions.restore')}
|
|
293
|
+
</Button>
|
|
294
|
+
<Button
|
|
295
|
+
disabled={isSaving || isFetching || !cenarioSelecionado}
|
|
296
|
+
onClick={async () => {
|
|
297
|
+
if (!cenarioSelecionado || isSaving) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
try {
|
|
302
|
+
setIsSaving(true);
|
|
303
|
+
|
|
304
|
+
await request({
|
|
305
|
+
url: `/finance/scenarios/${cenarioSelecionado.id}`,
|
|
306
|
+
method: 'PATCH',
|
|
307
|
+
data: {
|
|
308
|
+
atrasoMedio: premissas.atrasoMedio,
|
|
309
|
+
taxaInadimplencia: premissas.taxaInadimplencia,
|
|
310
|
+
crescimentoReceita: premissas.crescimentoReceita,
|
|
311
|
+
setAsDefault: true,
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
await refetch();
|
|
316
|
+
showToastHandler?.('success', 'Cenário salvo com sucesso');
|
|
317
|
+
} catch {
|
|
318
|
+
showToastHandler?.('error', 'Erro ao salvar cenário');
|
|
319
|
+
} finally {
|
|
320
|
+
setIsSaving(false);
|
|
321
|
+
}
|
|
322
|
+
}}
|
|
323
|
+
>
|
|
324
|
+
{isSaving ? (
|
|
325
|
+
<>
|
|
326
|
+
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
|
327
|
+
{t('assumptions.apply')}
|
|
328
|
+
</>
|
|
329
|
+
) : (
|
|
330
|
+
t('assumptions.apply')
|
|
331
|
+
)}
|
|
332
|
+
</Button>
|
|
333
|
+
</div>
|
|
334
|
+
</CardContent>
|
|
335
|
+
</Card>
|
|
336
|
+
|
|
337
|
+
<Card>
|
|
338
|
+
<CardHeader>
|
|
339
|
+
<CardTitle>{t('impact.title')}</CardTitle>
|
|
340
|
+
<CardDescription>{t('impact.description')}</CardDescription>
|
|
341
|
+
</CardHeader>
|
|
342
|
+
<CardContent>
|
|
343
|
+
<div className="space-y-6">
|
|
344
|
+
<div className="rounded-lg border p-4">
|
|
345
|
+
<p className="text-sm text-muted-foreground">
|
|
346
|
+
{t('impact.projectedBalance30d')}
|
|
347
|
+
</p>
|
|
348
|
+
<p className="text-3xl font-bold">
|
|
349
|
+
<Money value={impactoSaldo} />
|
|
350
|
+
</p>
|
|
351
|
+
<p
|
|
352
|
+
className={`text-sm ${
|
|
353
|
+
impactoSaldo >= kpis.saldoCaixa
|
|
354
|
+
? 'text-green-600'
|
|
355
|
+
: 'text-red-600'
|
|
356
|
+
}`}
|
|
357
|
+
>
|
|
358
|
+
{impactoSaldo >= kpis.saldoCaixa ? '+' : ''}
|
|
359
|
+
{t('impact.vsCurrent', {
|
|
360
|
+
value: formatarMoeda(impactoSaldo - kpis.saldoCaixa),
|
|
361
|
+
})}
|
|
362
|
+
</p>
|
|
363
|
+
</div>
|
|
364
|
+
|
|
365
|
+
<div className="rounded-lg border p-4">
|
|
366
|
+
<p className="text-sm text-muted-foreground">
|
|
367
|
+
{t('impact.projectedDefault')}
|
|
368
|
+
</p>
|
|
369
|
+
<p className="text-3xl font-bold text-red-600">
|
|
370
|
+
<Money value={impactoInadimplencia} />
|
|
371
|
+
</p>
|
|
372
|
+
<p className="text-sm text-muted-foreground">
|
|
373
|
+
{t('impact.vsCurrent', {
|
|
374
|
+
value: formatarMoeda(
|
|
375
|
+
impactoInadimplencia - kpis.inadimplencia
|
|
376
|
+
),
|
|
377
|
+
})}
|
|
378
|
+
</p>
|
|
379
|
+
</div>
|
|
380
|
+
|
|
381
|
+
<div className="rounded-lg border p-4">
|
|
382
|
+
<p className="text-sm text-muted-foreground">
|
|
383
|
+
{t('impact.cashFlowForecast')}
|
|
384
|
+
</p>
|
|
385
|
+
<p
|
|
386
|
+
className={`text-3xl font-bold ${
|
|
387
|
+
premissas.crescimentoReceita >= 0
|
|
388
|
+
? 'text-green-600'
|
|
389
|
+
: 'text-red-600'
|
|
390
|
+
}`}
|
|
391
|
+
>
|
|
392
|
+
{premissas.crescimentoReceita >= 0
|
|
393
|
+
? t('impact.positive')
|
|
394
|
+
: t('impact.negative')}
|
|
395
|
+
</p>
|
|
396
|
+
<p className="text-sm text-muted-foreground">
|
|
397
|
+
{t('impact.withGrowth', {
|
|
398
|
+
value: premissas.crescimentoReceita,
|
|
399
|
+
})}
|
|
400
|
+
</p>
|
|
401
|
+
</div>
|
|
402
|
+
</div>
|
|
403
|
+
</CardContent>
|
|
404
|
+
</Card>
|
|
405
|
+
</div>
|
|
406
|
+
</Page>
|
|
407
|
+
);
|
|
408
|
+
}
|