@hed-hog/finance 0.0.350 → 0.0.351
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-financial-title.dto.d.ts +6 -0
- package/dist/dto/create-financial-title.dto.d.ts.map +1 -1
- package/dist/dto/create-financial-title.dto.js +27 -1
- package/dist/dto/create-financial-title.dto.js.map +1 -1
- package/dist/finance-data.controller.d.ts +12 -0
- package/dist/finance-data.controller.d.ts.map +1 -1
- package/dist/finance-installments.controller.d.ts +120 -0
- package/dist/finance-installments.controller.d.ts.map +1 -1
- package/dist/finance-realtime.controller.d.ts +7 -0
- package/dist/finance-realtime.controller.d.ts.map +1 -0
- package/dist/finance-realtime.controller.js +34 -0
- package/dist/finance-realtime.controller.js.map +1 -0
- package/dist/finance-realtime.service.d.ts +36 -0
- package/dist/finance-realtime.service.d.ts.map +1 -0
- package/dist/finance-realtime.service.js +59 -0
- package/dist/finance-realtime.service.js.map +1 -0
- package/dist/finance-statements.controller.d.ts +6 -0
- package/dist/finance-statements.controller.d.ts.map +1 -1
- package/dist/finance.module.d.ts.map +1 -1
- package/dist/finance.module.js +28 -0
- package/dist/finance.module.js.map +1 -1
- package/dist/finance.service.d.ts +142 -1
- package/dist/finance.service.d.ts.map +1 -1
- package/dist/finance.service.js +134 -19
- package/dist/finance.service.js.map +1 -1
- package/dist/mcp-tools/finance-audit-logs.mcp-tools.d.ts +8 -0
- package/dist/mcp-tools/finance-audit-logs.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-audit-logs.mcp-tools.js +60 -0
- package/dist/mcp-tools/finance-audit-logs.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-bank-accounts.mcp-tools.d.ts +16 -0
- package/dist/mcp-tools/finance-bank-accounts.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-bank-accounts.mcp-tools.js +121 -0
- package/dist/mcp-tools/finance-bank-accounts.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-categories.mcp-tools.d.ts +20 -0
- package/dist/mcp-tools/finance-categories.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-categories.mcp-tools.js +135 -0
- package/dist/mcp-tools/finance-categories.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-collections.mcp-tools.d.ts +16 -0
- package/dist/mcp-tools/finance-collections.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-collections.mcp-tools.js +91 -0
- package/dist/mcp-tools/finance-collections.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-cost-centers.mcp-tools.d.ts +16 -0
- package/dist/mcp-tools/finance-cost-centers.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-cost-centers.mcp-tools.js +114 -0
- package/dist/mcp-tools/finance-cost-centers.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-currencies.mcp-tools.d.ts +16 -0
- package/dist/mcp-tools/finance-currencies.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-currencies.mcp-tools.js +120 -0
- package/dist/mcp-tools/finance-currencies.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-data.mcp-tools.d.ts +15 -0
- package/dist/mcp-tools/finance-data.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-data.mcp-tools.js +80 -0
- package/dist/mcp-tools/finance-data.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-installments.mcp-tools.d.ts +93 -0
- package/dist/mcp-tools/finance-installments.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-installments.mcp-tools.js +646 -0
- package/dist/mcp-tools/finance-installments.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-period-close.mcp-tools.d.ts +9 -0
- package/dist/mcp-tools/finance-period-close.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-period-close.mcp-tools.js +79 -0
- package/dist/mcp-tools/finance-period-close.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-reports.mcp-tools.d.ts +10 -0
- package/dist/mcp-tools/finance-reports.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-reports.mcp-tools.js +89 -0
- package/dist/mcp-tools/finance-reports.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-statements.mcp-tools.d.ts +34 -0
- package/dist/mcp-tools/finance-statements.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-statements.mcp-tools.js +253 -0
- package/dist/mcp-tools/finance-statements.mcp-tools.js.map +1 -0
- package/dist/mcp-tools/finance-transfers.mcp-tools.d.ts +9 -0
- package/dist/mcp-tools/finance-transfers.mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools/finance-transfers.mcp-tools.js +79 -0
- package/dist/mcp-tools/finance-transfers.mcp-tools.js.map +1 -0
- package/hedhog/data/route.yaml +659 -1
- package/hedhog/frontend/app/_components/finance-title-actions-menu.tsx.ejs +9 -3
- package/hedhog/frontend/app/_lib/http-error.ts.ejs +105 -0
- package/hedhog/frontend/app/_lib/use-finance-realtime-refresh.ts.ejs +62 -0
- package/hedhog/frontend/app/accounts-payable/approvals/page.tsx.ejs +3 -0
- package/hedhog/frontend/app/accounts-payable/installments/[id]/page.tsx.ejs +5 -5
- package/hedhog/frontend/app/accounts-payable/installments/page.tsx.ejs +776 -344
- package/hedhog/frontend/app/accounts-receivable/collections-default/page.tsx.ejs +7 -13
- package/hedhog/frontend/app/accounts-receivable/installments/[id]/page.tsx.ejs +5 -5
- package/hedhog/frontend/app/accounts-receivable/installments/page.tsx.ejs +802 -355
- package/hedhog/frontend/app/administration/categories/page.tsx.ejs +9 -3
- package/hedhog/frontend/app/administration/cost-centers/page.tsx.ejs +9 -3
- package/hedhog/frontend/app/administration/currencies/page.tsx.ejs +9 -3
- package/hedhog/frontend/app/administration/period-close/page.tsx.ejs +9 -3
- package/hedhog/frontend/app/cash-and-banks/bank-accounts/page.tsx.ejs +7 -3
- package/hedhog/frontend/app/cash-and-banks/bank-reconciliation/page.tsx.ejs +3 -3
- package/hedhog/frontend/app/cash-and-banks/statements/page.tsx.ejs +28 -7
- package/hedhog/frontend/app/cash-and-banks/transfers/page.tsx.ejs +12 -3
- package/hedhog/frontend/messages/en.json +63 -3
- package/hedhog/frontend/messages/pt.json +63 -3
- package/hedhog/table/financial_title.yaml +10 -0
- package/package.json +5 -5
- package/src/dto/create-financial-title.dto.ts +23 -0
- package/src/finance-realtime.controller.ts +12 -0
- package/src/finance-realtime.service.ts +106 -0
- package/src/finance.module.ts +28 -0
- package/src/finance.service.ts +184 -45
- package/src/mcp-tools/finance-audit-logs.mcp-tools.ts +38 -0
- package/src/mcp-tools/finance-bank-accounts.mcp-tools.ts +76 -0
- package/src/mcp-tools/finance-categories.mcp-tools.ts +86 -0
- package/src/mcp-tools/finance-collections.mcp-tools.ts +50 -0
- package/src/mcp-tools/finance-cost-centers.mcp-tools.ts +69 -0
- package/src/mcp-tools/finance-currencies.mcp-tools.ts +75 -0
- package/src/mcp-tools/finance-data.mcp-tools.ts +43 -0
- package/src/mcp-tools/finance-installments.mcp-tools.ts +560 -0
- package/src/mcp-tools/finance-period-close.mcp-tools.ts +53 -0
- package/src/mcp-tools/finance-reports.mcp-tools.ts +59 -0
- package/src/mcp-tools/finance-statements.mcp-tools.ts +202 -0
- package/src/mcp-tools/finance-transfers.mcp-tools.ts +53 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
type ErrorMessageMap = Record<string, string | string[] | null | undefined>;
|
|
2
|
+
|
|
3
|
+
type ApiErrorLike = {
|
|
4
|
+
response?: {
|
|
5
|
+
data?: {
|
|
6
|
+
message?: string | string[] | ErrorMessageMap;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
message?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const appendUniqueMessages = (
|
|
13
|
+
target: string[],
|
|
14
|
+
values: Array<string | null | undefined>
|
|
15
|
+
) => {
|
|
16
|
+
values.forEach((value) => {
|
|
17
|
+
const normalizedValue = String(value || '').trim();
|
|
18
|
+
|
|
19
|
+
if (!normalizedValue || target.includes(normalizedValue)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
target.push(normalizedValue);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function getApiErrorMessage(error: unknown, fallbackMessage: string) {
|
|
28
|
+
const normalizedError = error as ApiErrorLike;
|
|
29
|
+
const message = normalizedError.response?.data?.message;
|
|
30
|
+
|
|
31
|
+
if (typeof message === 'string' && message.trim()) {
|
|
32
|
+
return message;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(message)) {
|
|
36
|
+
const messages = message
|
|
37
|
+
.map((item) => String(item || '').trim())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
|
|
40
|
+
return messages.length > 0 ? messages.join(', ') : fallbackMessage;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (message && typeof message === 'object') {
|
|
44
|
+
const normalizedMessages: string[] = [];
|
|
45
|
+
|
|
46
|
+
Object.values(message as ErrorMessageMap).forEach((value) => {
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
appendUniqueMessages(normalizedMessages, value);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
appendUniqueMessages(normalizedMessages, [value]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (normalizedMessages.length > 0) {
|
|
56
|
+
return normalizedMessages.join(', ');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const genericMessage = normalizedError.message;
|
|
61
|
+
|
|
62
|
+
if (typeof genericMessage === 'string' && genericMessage.trim()) {
|
|
63
|
+
return genericMessage;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return fallbackMessage;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const isErrorContainer = (value: unknown): value is Record<string, unknown> =>
|
|
70
|
+
typeof value === 'object' && value !== null;
|
|
71
|
+
|
|
72
|
+
export function getFirstFormErrorMessage(
|
|
73
|
+
errors: unknown,
|
|
74
|
+
fallbackMessage: string
|
|
75
|
+
) {
|
|
76
|
+
const queue: unknown[] = [errors];
|
|
77
|
+
|
|
78
|
+
while (queue.length > 0) {
|
|
79
|
+
const current = queue.shift();
|
|
80
|
+
|
|
81
|
+
if (!isErrorContainer(current)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const message = current.message;
|
|
86
|
+
if (typeof message === 'string' && message.trim()) {
|
|
87
|
+
return message;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Object.entries(current).forEach(([key, value]) => {
|
|
91
|
+
if (key === 'message' || key === 'type' || key === 'ref') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (Array.isArray(value)) {
|
|
96
|
+
value.forEach((item) => queue.push(item));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
queue.push(value);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return fallbackMessage;
|
|
105
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useQuery } from '@hed-hog/next-app-provider';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
export type RequestFn = (input: {
|
|
5
|
+
url: string;
|
|
6
|
+
method: string;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
}) => Promise<{ data: unknown }>;
|
|
9
|
+
|
|
10
|
+
type FinanceRealtimeCursorResponse = {
|
|
11
|
+
cursor: number;
|
|
12
|
+
updatedAt: string | null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
async function fetchFinance<T>(request: RequestFn, url: string): Promise<T> {
|
|
16
|
+
const response = await request({ url, method: 'GET' });
|
|
17
|
+
return response.data as T;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useFinanceRealtimeRefresh({
|
|
21
|
+
request,
|
|
22
|
+
enabled = true,
|
|
23
|
+
pollIntervalMs = 5000,
|
|
24
|
+
onRefresh,
|
|
25
|
+
}: {
|
|
26
|
+
request: RequestFn;
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
pollIntervalMs?: number;
|
|
29
|
+
onRefresh: () => unknown | Promise<unknown>;
|
|
30
|
+
}) {
|
|
31
|
+
const lastCursorRef = useRef<number | null>(null);
|
|
32
|
+
|
|
33
|
+
const { data } = useQuery<FinanceRealtimeCursorResponse>({
|
|
34
|
+
queryKey: ['finance-realtime-cursor'],
|
|
35
|
+
queryFn: () =>
|
|
36
|
+
fetchFinance<FinanceRealtimeCursorResponse>(
|
|
37
|
+
request,
|
|
38
|
+
'/finance/realtime/cursor',
|
|
39
|
+
),
|
|
40
|
+
enabled,
|
|
41
|
+
refetchInterval: enabled ? pollIntervalMs : false,
|
|
42
|
+
refetchIntervalInBackground: true,
|
|
43
|
+
placeholderData: (previous) => previous,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!enabled) return;
|
|
48
|
+
|
|
49
|
+
const cursor = data?.cursor;
|
|
50
|
+
if (typeof cursor !== 'number') return;
|
|
51
|
+
|
|
52
|
+
if (lastCursorRef.current === null) {
|
|
53
|
+
lastCursorRef.current = cursor;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (cursor !== lastCursorRef.current) {
|
|
58
|
+
lastCursorRef.current = cursor;
|
|
59
|
+
void onRefresh();
|
|
60
|
+
}
|
|
61
|
+
}, [data?.cursor, enabled, onRefresh]);
|
|
62
|
+
}
|
|
@@ -35,6 +35,7 @@ import { AlertTriangle, CheckCircle, Clock, XCircle } from 'lucide-react';
|
|
|
35
35
|
import { useTranslations } from 'next-intl';
|
|
36
36
|
import { useState } from 'react';
|
|
37
37
|
import { formatarData } from '../../_lib/formatters';
|
|
38
|
+
import { useFinanceRealtimeRefresh } from '../../_lib/use-finance-realtime-refresh';
|
|
38
39
|
|
|
39
40
|
type ApprovalTitle = {
|
|
40
41
|
id: string;
|
|
@@ -159,6 +160,8 @@ export default function AprovacoesPage() {
|
|
|
159
160
|
placeholderData: (old) => old,
|
|
160
161
|
});
|
|
161
162
|
|
|
163
|
+
useFinanceRealtimeRefresh({ request, onRefresh: refetch });
|
|
164
|
+
|
|
162
165
|
const aprovacoes = approvalsResponse?.data ?? [];
|
|
163
166
|
const totalAprovacoes = approvalsResponse?.total ?? 0;
|
|
164
167
|
|
|
@@ -32,11 +32,11 @@ import {
|
|
|
32
32
|
} from '@/components/ui/select';
|
|
33
33
|
import {
|
|
34
34
|
Sheet,
|
|
35
|
-
SheetContent,
|
|
36
35
|
SheetDescription,
|
|
37
36
|
SheetHeader,
|
|
38
37
|
SheetTitle,
|
|
39
38
|
} from '@/components/ui/sheet';
|
|
39
|
+
import { ResizableSheetContent } from '@/components/ui/resizable-sheet-content';
|
|
40
40
|
import { StatusBadge } from '@/components/ui/status-badge';
|
|
41
41
|
import {
|
|
42
42
|
Table,
|
|
@@ -653,7 +653,7 @@ export default function TituloDetalhePage() {
|
|
|
653
653
|
}
|
|
654
654
|
}}
|
|
655
655
|
>
|
|
656
|
-
<
|
|
656
|
+
<ResizableSheetContent sheetId="finance-payable-reverse-settlement" defaultWidth={512} className="overflow-y-auto">
|
|
657
657
|
<SheetHeader>
|
|
658
658
|
<SheetTitle>{t('dialogs.reverse.title')}</SheetTitle>
|
|
659
659
|
<SheetDescription>
|
|
@@ -708,14 +708,14 @@ export default function TituloDetalhePage() {
|
|
|
708
708
|
</Button>
|
|
709
709
|
</div>
|
|
710
710
|
</div>
|
|
711
|
-
</
|
|
711
|
+
</ResizableSheetContent>
|
|
712
712
|
</Sheet>
|
|
713
713
|
|
|
714
714
|
<Sheet
|
|
715
715
|
open={isSettleDialogOpen}
|
|
716
716
|
onOpenChange={setIsSettleDialogOpen}
|
|
717
717
|
>
|
|
718
|
-
<
|
|
718
|
+
<ResizableSheetContent sheetId="finance-payable-settle-installment" defaultWidth={512} className="overflow-y-auto">
|
|
719
719
|
<SheetHeader>
|
|
720
720
|
<SheetTitle>{t('settleSheet.title')}</SheetTitle>
|
|
721
721
|
<SheetDescription>
|
|
@@ -828,7 +828,7 @@ export default function TituloDetalhePage() {
|
|
|
828
828
|
</div>
|
|
829
829
|
</form>
|
|
830
830
|
</Form>
|
|
831
|
-
</
|
|
831
|
+
</ResizableSheetContent>
|
|
832
832
|
</Sheet>
|
|
833
833
|
</div>
|
|
834
834
|
}
|