@hed-hog/finance 0.0.256 → 0.0.260
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/dist/dto/create-bank-statement-adjustment.dto.d.ts +8 -0
- package/dist/dto/create-bank-statement-adjustment.dto.d.ts.map +1 -0
- package/dist/dto/create-bank-statement-adjustment.dto.js +50 -0
- package/dist/dto/create-bank-statement-adjustment.dto.js.map +1 -0
- package/dist/dto/create-transfer.dto.d.ts +8 -0
- package/dist/dto/create-transfer.dto.d.ts.map +1 -0
- package/dist/dto/create-transfer.dto.js +52 -0
- package/dist/dto/create-transfer.dto.js.map +1 -0
- package/dist/dto/register-collection-agreement.dto.d.ts +7 -0
- package/dist/dto/register-collection-agreement.dto.d.ts.map +1 -0
- package/dist/dto/register-collection-agreement.dto.js +37 -0
- package/dist/dto/register-collection-agreement.dto.js.map +1 -0
- package/dist/dto/send-collection.dto.d.ts +5 -0
- package/dist/dto/send-collection.dto.d.ts.map +1 -0
- package/dist/dto/send-collection.dto.js +29 -0
- package/dist/dto/send-collection.dto.js.map +1 -0
- package/dist/dto/settle-installment.dto.d.ts +1 -0
- package/dist/dto/settle-installment.dto.d.ts.map +1 -1
- package/dist/dto/settle-installment.dto.js +6 -0
- package/dist/dto/settle-installment.dto.js.map +1 -1
- package/dist/finance-collections.controller.d.ts +35 -0
- package/dist/finance-collections.controller.d.ts.map +1 -0
- package/dist/finance-collections.controller.js +65 -0
- package/dist/finance-collections.controller.js.map +1 -0
- package/dist/finance-data.controller.d.ts +4 -0
- package/dist/finance-data.controller.d.ts.map +1 -1
- package/dist/finance-installments.controller.d.ts +44 -0
- package/dist/finance-installments.controller.d.ts.map +1 -1
- package/dist/finance-statements.controller.d.ts +16 -2
- package/dist/finance-statements.controller.d.ts.map +1 -1
- package/dist/finance-statements.controller.js +34 -6
- package/dist/finance-statements.controller.js.map +1 -1
- package/dist/finance-transfers.controller.d.ts +23 -0
- package/dist/finance-transfers.controller.d.ts.map +1 -0
- package/dist/finance-transfers.controller.js +56 -0
- package/dist/finance-transfers.controller.js.map +1 -0
- package/dist/finance.module.d.ts.map +1 -1
- package/dist/finance.module.js +4 -0
- package/dist/finance.module.js.map +1 -1
- package/dist/finance.service.d.ts +115 -2
- package/dist/finance.service.d.ts.map +1 -1
- package/dist/finance.service.js +632 -8
- package/dist/finance.service.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/hedhog/data/route.yaml +63 -0
- package/hedhog/frontend/app/accounts-receivable/collections-default/page.tsx.ejs +643 -440
- package/hedhog/frontend/app/cash-and-banks/bank-reconciliation/page.tsx.ejs +825 -477
- package/hedhog/frontend/app/cash-and-banks/statements/page.tsx.ejs +367 -43
- package/hedhog/frontend/app/cash-and-banks/transfers/page.tsx.ejs +315 -75
- package/package.json +6 -6
- package/src/dto/create-bank-statement-adjustment.dto.ts +38 -0
- package/src/dto/create-transfer.dto.ts +46 -0
- package/src/dto/register-collection-agreement.dto.ts +27 -0
- package/src/dto/send-collection.dto.ts +14 -0
- package/src/dto/settle-installment.dto.ts +5 -0
- package/src/finance-collections.controller.ts +34 -0
- package/src/finance-statements.controller.ts +29 -1
- package/src/finance-transfers.controller.ts +26 -0
- package/src/finance.module.ts +4 -0
- package/src/finance.service.ts +775 -5
- package/src/index.ts +2 -0
|
@@ -1,440 +1,643 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { Page, PageHeader } from '@/components/entity-list';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '@/components/ui/
|
|
21
|
-
import { Input } from '@/components/ui/input';
|
|
22
|
-
import { InputMoney } from '@/components/ui/input-money';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} from '@/components/ui/
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
t: ReturnType<typeof useTranslations>;
|
|
106
|
-
}) {
|
|
107
|
-
return (
|
|
108
|
-
<
|
|
109
|
-
<
|
|
110
|
-
<Button size="sm">
|
|
111
|
-
<
|
|
112
|
-
{t('actions.
|
|
113
|
-
</Button>
|
|
114
|
-
</
|
|
115
|
-
<
|
|
116
|
-
<
|
|
117
|
-
<
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
className="
|
|
130
|
-
>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
<
|
|
309
|
-
<
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
<
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
<
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Page, PageHeader } from '@/components/entity-list';
|
|
4
|
+
import { RichTextEditor } from '@/components/rich-text-editor';
|
|
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 {
|
|
14
|
+
Form,
|
|
15
|
+
FormControl,
|
|
16
|
+
FormField,
|
|
17
|
+
FormItem,
|
|
18
|
+
FormLabel,
|
|
19
|
+
FormMessage,
|
|
20
|
+
} from '@/components/ui/form';
|
|
21
|
+
import { Input } from '@/components/ui/input';
|
|
22
|
+
import { InputMoney } from '@/components/ui/input-money';
|
|
23
|
+
import { Money } from '@/components/ui/money';
|
|
24
|
+
import {
|
|
25
|
+
Sheet,
|
|
26
|
+
SheetContent,
|
|
27
|
+
SheetDescription,
|
|
28
|
+
SheetHeader,
|
|
29
|
+
SheetTitle,
|
|
30
|
+
SheetTrigger,
|
|
31
|
+
} from '@/components/ui/sheet';
|
|
32
|
+
import {
|
|
33
|
+
Table,
|
|
34
|
+
TableBody,
|
|
35
|
+
TableCell,
|
|
36
|
+
TableHead,
|
|
37
|
+
TableHeader,
|
|
38
|
+
TableRow,
|
|
39
|
+
} from '@/components/ui/table';
|
|
40
|
+
import { Textarea } from '@/components/ui/textarea';
|
|
41
|
+
import { useApp, useQuery } from '@hed-hog/next-app-provider';
|
|
42
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
43
|
+
import { AlertTriangle, FileText, Send } from 'lucide-react';
|
|
44
|
+
import { useTranslations } from 'next-intl';
|
|
45
|
+
import { useState } from 'react';
|
|
46
|
+
import { useForm } from 'react-hook-form';
|
|
47
|
+
import {
|
|
48
|
+
Bar,
|
|
49
|
+
BarChart,
|
|
50
|
+
CartesianGrid,
|
|
51
|
+
ResponsiveContainer,
|
|
52
|
+
Tooltip,
|
|
53
|
+
XAxis,
|
|
54
|
+
YAxis,
|
|
55
|
+
} from 'recharts';
|
|
56
|
+
import { z } from 'zod';
|
|
57
|
+
import { formatarMoeda } from '../../_lib/formatters';
|
|
58
|
+
|
|
59
|
+
type AgingItem = {
|
|
60
|
+
clienteId: string;
|
|
61
|
+
cliente: string;
|
|
62
|
+
bucket0_30: number;
|
|
63
|
+
bucket31_60: number;
|
|
64
|
+
bucket61_90: number;
|
|
65
|
+
bucket90plus: number;
|
|
66
|
+
total: number;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type HistoricoContato = {
|
|
70
|
+
clienteId: string;
|
|
71
|
+
tipo: string;
|
|
72
|
+
data: string;
|
|
73
|
+
descricao: string;
|
|
74
|
+
responsavel: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type CollectionsDefaultData = {
|
|
78
|
+
agingInadimplencia: AgingItem[];
|
|
79
|
+
historicoContatos: HistoricoContato[];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const EMPTY_DATA: CollectionsDefaultData = {
|
|
83
|
+
agingInadimplencia: [],
|
|
84
|
+
historicoContatos: [],
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const sendCollectionSchema = z.object({
|
|
88
|
+
message: z.string().min(5),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const registerAgreementSchema = z.object({
|
|
92
|
+
amount: z.number().min(0.01),
|
|
93
|
+
installments: z.coerce.number().int().min(1).max(120),
|
|
94
|
+
first_due_date: z.string().min(1),
|
|
95
|
+
notes: z.string().optional(),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
function HistoricoContatosSheet({
|
|
99
|
+
cliente,
|
|
100
|
+
historicoContatos,
|
|
101
|
+
t,
|
|
102
|
+
}: {
|
|
103
|
+
cliente: string;
|
|
104
|
+
historicoContatos: HistoricoContato[];
|
|
105
|
+
t: ReturnType<typeof useTranslations>;
|
|
106
|
+
}) {
|
|
107
|
+
return (
|
|
108
|
+
<Sheet>
|
|
109
|
+
<SheetTrigger asChild>
|
|
110
|
+
<Button variant="outline" size="sm">
|
|
111
|
+
<FileText className="mr-2 h-4 w-4" />
|
|
112
|
+
{t('actions.history')}
|
|
113
|
+
</Button>
|
|
114
|
+
</SheetTrigger>
|
|
115
|
+
<SheetContent>
|
|
116
|
+
<SheetHeader>
|
|
117
|
+
<SheetTitle>{t('history.title')}</SheetTitle>
|
|
118
|
+
<SheetDescription>{cliente}</SheetDescription>
|
|
119
|
+
</SheetHeader>
|
|
120
|
+
<div className="mt-6 space-y-4 px-4">
|
|
121
|
+
{historicoContatos.length === 0 ? (
|
|
122
|
+
<div className="rounded-lg border p-4 text-sm text-muted-foreground">
|
|
123
|
+
-
|
|
124
|
+
</div>
|
|
125
|
+
) : (
|
|
126
|
+
historicoContatos.map((contato, i) => (
|
|
127
|
+
<div
|
|
128
|
+
key={`${contato.data}-${i}`}
|
|
129
|
+
className="rounded-lg border p-4"
|
|
130
|
+
>
|
|
131
|
+
<div className="flex items-center justify-between">
|
|
132
|
+
<span className="font-medium">{contato.tipo}</span>
|
|
133
|
+
<span className="text-sm text-muted-foreground">
|
|
134
|
+
{new Date(contato.data).toLocaleString()}
|
|
135
|
+
</span>
|
|
136
|
+
</div>
|
|
137
|
+
<p className="mt-2 text-sm">{contato.descricao}</p>
|
|
138
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
139
|
+
{t('history.by')} {contato.responsavel}
|
|
140
|
+
</p>
|
|
141
|
+
</div>
|
|
142
|
+
))
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
</SheetContent>
|
|
146
|
+
</Sheet>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function EnviarCobrancaDialog({
|
|
151
|
+
cliente,
|
|
152
|
+
clienteId,
|
|
153
|
+
onSuccess,
|
|
154
|
+
t,
|
|
155
|
+
}: {
|
|
156
|
+
cliente: string;
|
|
157
|
+
clienteId: string;
|
|
158
|
+
onSuccess: () => Promise<unknown>;
|
|
159
|
+
t: ReturnType<typeof useTranslations>;
|
|
160
|
+
}) {
|
|
161
|
+
const { request, showToastHandler } = useApp();
|
|
162
|
+
const [open, setOpen] = useState(false);
|
|
163
|
+
|
|
164
|
+
const form = useForm<z.infer<typeof sendCollectionSchema>>({
|
|
165
|
+
resolver: zodResolver(sendCollectionSchema),
|
|
166
|
+
defaultValues: {
|
|
167
|
+
message: t('send.defaultMessage'),
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
const onSubmit = async (values: z.infer<typeof sendCollectionSchema>) => {
|
|
172
|
+
try {
|
|
173
|
+
await request({
|
|
174
|
+
url: `/finance/accounts-receivable/collections-default/${clienteId}/send`,
|
|
175
|
+
method: 'POST',
|
|
176
|
+
data: {
|
|
177
|
+
message: values.message,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
await onSuccess();
|
|
182
|
+
showToastHandler?.('success', t('send.submit'));
|
|
183
|
+
setOpen(false);
|
|
184
|
+
form.reset({
|
|
185
|
+
message: t('send.defaultMessage'),
|
|
186
|
+
});
|
|
187
|
+
} catch {
|
|
188
|
+
showToastHandler?.('error', t('send.submit'));
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Sheet open={open} onOpenChange={setOpen}>
|
|
194
|
+
<SheetTrigger asChild>
|
|
195
|
+
<Button size="sm">
|
|
196
|
+
<Send className="mr-2 h-4 w-4" />
|
|
197
|
+
{t('actions.collect')}
|
|
198
|
+
</Button>
|
|
199
|
+
</SheetTrigger>
|
|
200
|
+
<SheetContent side="right" className="w-[90vw] sm:max-w-xl">
|
|
201
|
+
<SheetHeader>
|
|
202
|
+
<SheetTitle>{t('send.title')}</SheetTitle>
|
|
203
|
+
<SheetDescription>
|
|
204
|
+
{t('send.description', { cliente })}
|
|
205
|
+
</SheetDescription>
|
|
206
|
+
</SheetHeader>
|
|
207
|
+
|
|
208
|
+
<Form {...form}>
|
|
209
|
+
<form
|
|
210
|
+
className="space-y-4 px-4"
|
|
211
|
+
onSubmit={form.handleSubmit(onSubmit)}
|
|
212
|
+
>
|
|
213
|
+
<FormField
|
|
214
|
+
control={form.control}
|
|
215
|
+
name="message"
|
|
216
|
+
render={({ field }) => (
|
|
217
|
+
<FormItem className="space-y-2">
|
|
218
|
+
<FormLabel>{t('send.message')}</FormLabel>
|
|
219
|
+
<FormControl>
|
|
220
|
+
<RichTextEditor
|
|
221
|
+
className="w-full max-w-full min-w-0 overflow-hidden [&_.ProseMirror]:max-w-full [&_.ProseMirror]:mx-0"
|
|
222
|
+
value={field.value ?? ''}
|
|
223
|
+
onChange={field.onChange}
|
|
224
|
+
/>
|
|
225
|
+
</FormControl>
|
|
226
|
+
<FormMessage />
|
|
227
|
+
</FormItem>
|
|
228
|
+
)}
|
|
229
|
+
/>
|
|
230
|
+
|
|
231
|
+
<div className="flex flex-col gap-2">
|
|
232
|
+
<Button
|
|
233
|
+
type="submit"
|
|
234
|
+
className="w-full"
|
|
235
|
+
disabled={form.formState.isSubmitting}
|
|
236
|
+
>
|
|
237
|
+
{t('send.submit')}
|
|
238
|
+
</Button>
|
|
239
|
+
</div>
|
|
240
|
+
</form>
|
|
241
|
+
</Form>
|
|
242
|
+
</SheetContent>
|
|
243
|
+
</Sheet>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function RegistrarAcordoDialog({
|
|
248
|
+
cliente,
|
|
249
|
+
clienteId,
|
|
250
|
+
onSuccess,
|
|
251
|
+
t,
|
|
252
|
+
}: {
|
|
253
|
+
cliente: string;
|
|
254
|
+
clienteId: string;
|
|
255
|
+
onSuccess: () => Promise<unknown>;
|
|
256
|
+
t: ReturnType<typeof useTranslations>;
|
|
257
|
+
}) {
|
|
258
|
+
const { request, showToastHandler } = useApp();
|
|
259
|
+
const [open, setOpen] = useState(false);
|
|
260
|
+
|
|
261
|
+
const form = useForm<z.infer<typeof registerAgreementSchema>>({
|
|
262
|
+
resolver: zodResolver(registerAgreementSchema),
|
|
263
|
+
defaultValues: {
|
|
264
|
+
amount: 0,
|
|
265
|
+
installments: 1,
|
|
266
|
+
first_due_date: '',
|
|
267
|
+
notes: '',
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const onSubmit = async (values: z.infer<typeof registerAgreementSchema>) => {
|
|
272
|
+
try {
|
|
273
|
+
await request({
|
|
274
|
+
url: `/finance/accounts-receivable/collections-default/${clienteId}/agreements`,
|
|
275
|
+
method: 'POST',
|
|
276
|
+
data: values,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
await onSuccess();
|
|
280
|
+
showToastHandler?.('success', t('agreement.submit'));
|
|
281
|
+
setOpen(false);
|
|
282
|
+
form.reset({
|
|
283
|
+
amount: 0,
|
|
284
|
+
installments: 1,
|
|
285
|
+
first_due_date: '',
|
|
286
|
+
notes: '',
|
|
287
|
+
});
|
|
288
|
+
} catch {
|
|
289
|
+
showToastHandler?.('error', t('agreement.submit'));
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<Sheet open={open} onOpenChange={setOpen}>
|
|
295
|
+
<SheetTrigger asChild>
|
|
296
|
+
<Button variant="outline" size="sm">
|
|
297
|
+
{t('actions.registerAgreement')}
|
|
298
|
+
</Button>
|
|
299
|
+
</SheetTrigger>
|
|
300
|
+
<SheetContent side="right" className="w-[90vw] sm:max-w-xl">
|
|
301
|
+
<SheetHeader>
|
|
302
|
+
<SheetTitle>{t('agreement.title')}</SheetTitle>
|
|
303
|
+
<SheetDescription>
|
|
304
|
+
{t('agreement.description', { cliente })}
|
|
305
|
+
</SheetDescription>
|
|
306
|
+
</SheetHeader>
|
|
307
|
+
|
|
308
|
+
<Form {...form}>
|
|
309
|
+
<form
|
|
310
|
+
className="space-y-4 px-4"
|
|
311
|
+
onSubmit={form.handleSubmit(onSubmit)}
|
|
312
|
+
>
|
|
313
|
+
<div className="grid grid-cols-2 gap-4">
|
|
314
|
+
<FormField
|
|
315
|
+
control={form.control}
|
|
316
|
+
name="amount"
|
|
317
|
+
render={({ field }) => (
|
|
318
|
+
<FormItem className="space-y-2">
|
|
319
|
+
<FormLabel>{t('agreement.value')}</FormLabel>
|
|
320
|
+
<FormControl>
|
|
321
|
+
<InputMoney
|
|
322
|
+
placeholder="0,00"
|
|
323
|
+
value={field.value ?? 0}
|
|
324
|
+
onValueChange={(value) => field.onChange(value ?? 0)}
|
|
325
|
+
/>
|
|
326
|
+
</FormControl>
|
|
327
|
+
<FormMessage />
|
|
328
|
+
</FormItem>
|
|
329
|
+
)}
|
|
330
|
+
/>
|
|
331
|
+
|
|
332
|
+
<FormField
|
|
333
|
+
control={form.control}
|
|
334
|
+
name="installments"
|
|
335
|
+
render={({ field }) => (
|
|
336
|
+
<FormItem className="space-y-2">
|
|
337
|
+
<FormLabel>{t('agreement.installments')}</FormLabel>
|
|
338
|
+
<FormControl>
|
|
339
|
+
<Input
|
|
340
|
+
type="number"
|
|
341
|
+
min={1}
|
|
342
|
+
max={120}
|
|
343
|
+
value={field.value}
|
|
344
|
+
onChange={field.onChange}
|
|
345
|
+
/>
|
|
346
|
+
</FormControl>
|
|
347
|
+
<FormMessage />
|
|
348
|
+
</FormItem>
|
|
349
|
+
)}
|
|
350
|
+
/>
|
|
351
|
+
</div>
|
|
352
|
+
|
|
353
|
+
<FormField
|
|
354
|
+
control={form.control}
|
|
355
|
+
name="first_due_date"
|
|
356
|
+
render={({ field }) => (
|
|
357
|
+
<FormItem className="space-y-2">
|
|
358
|
+
<FormLabel>{t('agreement.firstDueDate')}</FormLabel>
|
|
359
|
+
<FormControl>
|
|
360
|
+
<Input type="date" {...field} />
|
|
361
|
+
</FormControl>
|
|
362
|
+
<FormMessage />
|
|
363
|
+
</FormItem>
|
|
364
|
+
)}
|
|
365
|
+
/>
|
|
366
|
+
|
|
367
|
+
<FormField
|
|
368
|
+
control={form.control}
|
|
369
|
+
name="notes"
|
|
370
|
+
render={({ field }) => (
|
|
371
|
+
<FormItem className="space-y-2">
|
|
372
|
+
<FormLabel>{t('agreement.notes')}</FormLabel>
|
|
373
|
+
<FormControl>
|
|
374
|
+
<Textarea
|
|
375
|
+
placeholder={t('agreement.notesPlaceholder')}
|
|
376
|
+
{...field}
|
|
377
|
+
/>
|
|
378
|
+
</FormControl>
|
|
379
|
+
<FormMessage />
|
|
380
|
+
</FormItem>
|
|
381
|
+
)}
|
|
382
|
+
/>
|
|
383
|
+
|
|
384
|
+
<div className="flex flex-col gap-2">
|
|
385
|
+
<Button
|
|
386
|
+
type="submit"
|
|
387
|
+
className="w-full"
|
|
388
|
+
disabled={form.formState.isSubmitting}
|
|
389
|
+
>
|
|
390
|
+
{t('agreement.submit')}
|
|
391
|
+
</Button>
|
|
392
|
+
</div>
|
|
393
|
+
</form>
|
|
394
|
+
</Form>
|
|
395
|
+
</SheetContent>
|
|
396
|
+
</Sheet>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export default function CobrancaPage() {
|
|
401
|
+
const t = useTranslations('finance.CollectionsDefaultPage');
|
|
402
|
+
const { request } = useApp();
|
|
403
|
+
|
|
404
|
+
const { data = EMPTY_DATA, refetch } = useQuery<CollectionsDefaultData>({
|
|
405
|
+
queryKey: ['finance-collections-default'],
|
|
406
|
+
queryFn: async () => {
|
|
407
|
+
const response = await request({
|
|
408
|
+
url: '/finance/accounts-receivable/collections-default',
|
|
409
|
+
method: 'GET',
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
...EMPTY_DATA,
|
|
414
|
+
...(response?.data || {}),
|
|
415
|
+
};
|
|
416
|
+
},
|
|
417
|
+
staleTime: 0,
|
|
418
|
+
refetchOnMount: 'always',
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const { agingInadimplencia, historicoContatos } = data;
|
|
422
|
+
|
|
423
|
+
const chartData = [
|
|
424
|
+
{
|
|
425
|
+
name: t('chart.range0to30'),
|
|
426
|
+
valor: agingInadimplencia.reduce(
|
|
427
|
+
(acc, c) => acc + (c.bucket0_30 || 0),
|
|
428
|
+
0
|
|
429
|
+
),
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
name: t('chart.range31to60'),
|
|
433
|
+
valor: agingInadimplencia.reduce(
|
|
434
|
+
(acc, c) => acc + (c.bucket31_60 || 0),
|
|
435
|
+
0
|
|
436
|
+
),
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
name: t('chart.range61to90'),
|
|
440
|
+
valor: agingInadimplencia.reduce(
|
|
441
|
+
(acc, c) => acc + (c.bucket61_90 || 0),
|
|
442
|
+
0
|
|
443
|
+
),
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
name: t('chart.range90plus'),
|
|
447
|
+
valor: agingInadimplencia.reduce(
|
|
448
|
+
(acc, c) => acc + (c.bucket90plus || 0),
|
|
449
|
+
0
|
|
450
|
+
),
|
|
451
|
+
},
|
|
452
|
+
];
|
|
453
|
+
|
|
454
|
+
const totalInadimplencia = agingInadimplencia.reduce(
|
|
455
|
+
(acc, c) => acc + c.total,
|
|
456
|
+
0
|
|
457
|
+
);
|
|
458
|
+
const totalClientes = agingInadimplencia.length;
|
|
459
|
+
|
|
460
|
+
return (
|
|
461
|
+
<Page>
|
|
462
|
+
<PageHeader
|
|
463
|
+
title={t('header.title')}
|
|
464
|
+
description={t('header.description')}
|
|
465
|
+
breadcrumbs={[
|
|
466
|
+
{ label: t('breadcrumbs.home'), href: '/' },
|
|
467
|
+
{ label: t('breadcrumbs.finance'), href: '/finance' },
|
|
468
|
+
{ label: t('breadcrumbs.current') },
|
|
469
|
+
]}
|
|
470
|
+
/>
|
|
471
|
+
|
|
472
|
+
<div className="grid gap-4 md:grid-cols-3">
|
|
473
|
+
<Card>
|
|
474
|
+
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
475
|
+
<CardTitle className="text-sm font-medium">
|
|
476
|
+
{t('cards.totalDefault')}
|
|
477
|
+
</CardTitle>
|
|
478
|
+
<AlertTriangle className="h-4 w-4 text-destructive" />
|
|
479
|
+
</CardHeader>
|
|
480
|
+
<CardContent>
|
|
481
|
+
<div className="text-2xl font-bold">
|
|
482
|
+
<Money value={totalInadimplencia} />
|
|
483
|
+
</div>
|
|
484
|
+
</CardContent>
|
|
485
|
+
</Card>
|
|
486
|
+
<Card>
|
|
487
|
+
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
488
|
+
<CardTitle className="text-sm font-medium">
|
|
489
|
+
{t('cards.lateClients')}
|
|
490
|
+
</CardTitle>
|
|
491
|
+
</CardHeader>
|
|
492
|
+
<CardContent>
|
|
493
|
+
<div className="text-2xl font-bold">{totalClientes}</div>
|
|
494
|
+
</CardContent>
|
|
495
|
+
</Card>
|
|
496
|
+
<Card>
|
|
497
|
+
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
|
498
|
+
<CardTitle className="text-sm font-medium">
|
|
499
|
+
{t('cards.maxDelay')}
|
|
500
|
+
</CardTitle>
|
|
501
|
+
</CardHeader>
|
|
502
|
+
<CardContent>
|
|
503
|
+
<div className="text-2xl font-bold text-destructive">
|
|
504
|
+
{t('cards.maxDelayValue')}
|
|
505
|
+
</div>
|
|
506
|
+
</CardContent>
|
|
507
|
+
</Card>
|
|
508
|
+
</div>
|
|
509
|
+
|
|
510
|
+
<Card>
|
|
511
|
+
<CardHeader>
|
|
512
|
+
<CardTitle>{t('aging.title')}</CardTitle>
|
|
513
|
+
<CardDescription>{t('aging.description')}</CardDescription>
|
|
514
|
+
</CardHeader>
|
|
515
|
+
<CardContent>
|
|
516
|
+
<ResponsiveContainer width="100%" height={250}>
|
|
517
|
+
<BarChart data={chartData}>
|
|
518
|
+
<CartesianGrid strokeDasharray="3 3" className="stroke-muted" />
|
|
519
|
+
<XAxis dataKey="name" tick={{ fontSize: 12 }} />
|
|
520
|
+
<YAxis
|
|
521
|
+
tick={{ fontSize: 12 }}
|
|
522
|
+
tickFormatter={(value) => `${(value / 1000).toFixed(0)}k`}
|
|
523
|
+
/>
|
|
524
|
+
<Tooltip
|
|
525
|
+
formatter={(value: number) => formatarMoeda(value)}
|
|
526
|
+
contentStyle={{
|
|
527
|
+
backgroundColor: 'var(--background)',
|
|
528
|
+
border: '1px solid var(--border)',
|
|
529
|
+
borderRadius: '8px',
|
|
530
|
+
color: 'var(--foreground)',
|
|
531
|
+
}}
|
|
532
|
+
labelStyle={{ color: 'var(--foreground)' }}
|
|
533
|
+
itemStyle={{ color: 'var(--foreground)' }}
|
|
534
|
+
/>
|
|
535
|
+
<Bar
|
|
536
|
+
dataKey="valor"
|
|
537
|
+
radius={[4, 4, 0, 0]}
|
|
538
|
+
fill="var(--primary)"
|
|
539
|
+
/>
|
|
540
|
+
</BarChart>
|
|
541
|
+
</ResponsiveContainer>
|
|
542
|
+
</CardContent>
|
|
543
|
+
</Card>
|
|
544
|
+
|
|
545
|
+
<Card>
|
|
546
|
+
<CardHeader>
|
|
547
|
+
<CardTitle>{t('table.title')}</CardTitle>
|
|
548
|
+
<CardDescription>{t('table.description')}</CardDescription>
|
|
549
|
+
</CardHeader>
|
|
550
|
+
<CardContent>
|
|
551
|
+
<Table>
|
|
552
|
+
<TableHeader>
|
|
553
|
+
<TableRow>
|
|
554
|
+
<TableHead>{t('table.headers.client')}</TableHead>
|
|
555
|
+
<TableHead className="text-right">
|
|
556
|
+
{t('table.headers.range0to30')}
|
|
557
|
+
</TableHead>
|
|
558
|
+
<TableHead className="text-right">
|
|
559
|
+
{t('table.headers.range31to60')}
|
|
560
|
+
</TableHead>
|
|
561
|
+
<TableHead className="text-right">
|
|
562
|
+
{t('table.headers.range61to90')}
|
|
563
|
+
</TableHead>
|
|
564
|
+
<TableHead className="text-right">
|
|
565
|
+
{t('table.headers.range90plus')}
|
|
566
|
+
</TableHead>
|
|
567
|
+
<TableHead className="text-right">
|
|
568
|
+
{t('table.headers.total')}
|
|
569
|
+
</TableHead>
|
|
570
|
+
<TableHead className="text-right">
|
|
571
|
+
{t('table.headers.actions')}
|
|
572
|
+
</TableHead>
|
|
573
|
+
</TableRow>
|
|
574
|
+
</TableHeader>
|
|
575
|
+
<TableBody>
|
|
576
|
+
{agingInadimplencia.map((item) => (
|
|
577
|
+
<TableRow key={item.clienteId}>
|
|
578
|
+
<TableCell className="font-medium">{item.cliente}</TableCell>
|
|
579
|
+
<TableCell className="text-right">
|
|
580
|
+
{item.bucket0_30 > 0 ? (
|
|
581
|
+
<Money value={item.bucket0_30} />
|
|
582
|
+
) : (
|
|
583
|
+
'-'
|
|
584
|
+
)}
|
|
585
|
+
</TableCell>
|
|
586
|
+
<TableCell className="text-right">
|
|
587
|
+
{item.bucket31_60 > 0 ? (
|
|
588
|
+
<Money value={item.bucket31_60} />
|
|
589
|
+
) : (
|
|
590
|
+
'-'
|
|
591
|
+
)}
|
|
592
|
+
</TableCell>
|
|
593
|
+
<TableCell className="text-right">
|
|
594
|
+
{item.bucket61_90 > 0 ? (
|
|
595
|
+
<Money value={item.bucket61_90} />
|
|
596
|
+
) : (
|
|
597
|
+
'-'
|
|
598
|
+
)}
|
|
599
|
+
</TableCell>
|
|
600
|
+
<TableCell className="text-right">
|
|
601
|
+
{item.bucket90plus > 0 ? (
|
|
602
|
+
<span className="font-medium text-destructive">
|
|
603
|
+
<Money value={item.bucket90plus} />
|
|
604
|
+
</span>
|
|
605
|
+
) : (
|
|
606
|
+
'-'
|
|
607
|
+
)}
|
|
608
|
+
</TableCell>
|
|
609
|
+
<TableCell className="text-right font-semibold">
|
|
610
|
+
<Money value={item.total} />
|
|
611
|
+
</TableCell>
|
|
612
|
+
<TableCell>
|
|
613
|
+
<div className="flex justify-end gap-2">
|
|
614
|
+
<HistoricoContatosSheet
|
|
615
|
+
cliente={item.cliente}
|
|
616
|
+
historicoContatos={historicoContatos.filter(
|
|
617
|
+
(contato) => contato.clienteId === item.clienteId
|
|
618
|
+
)}
|
|
619
|
+
t={t}
|
|
620
|
+
/>
|
|
621
|
+
<EnviarCobrancaDialog
|
|
622
|
+
cliente={item.cliente}
|
|
623
|
+
clienteId={item.clienteId}
|
|
624
|
+
onSuccess={refetch}
|
|
625
|
+
t={t}
|
|
626
|
+
/>
|
|
627
|
+
<RegistrarAcordoDialog
|
|
628
|
+
cliente={item.cliente}
|
|
629
|
+
clienteId={item.clienteId}
|
|
630
|
+
onSuccess={refetch}
|
|
631
|
+
t={t}
|
|
632
|
+
/>
|
|
633
|
+
</div>
|
|
634
|
+
</TableCell>
|
|
635
|
+
</TableRow>
|
|
636
|
+
))}
|
|
637
|
+
</TableBody>
|
|
638
|
+
</Table>
|
|
639
|
+
</CardContent>
|
|
640
|
+
</Card>
|
|
641
|
+
</Page>
|
|
642
|
+
);
|
|
643
|
+
}
|