@grafosoft/excel-validator 1.1.8 → 1.1.9
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ExcelFileProps } from "../types/excelTypes";
|
|
2
|
-
export declare const ExcelFile: ({ initData, fileContent, matrix, error, onFileSelected, onReset, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference, onApplyStringEmptyFilter, onDownloadFilteredExcel, isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors, }: ExcelFileProps) => import("react").JSX.Element;
|
|
2
|
+
export declare const ExcelFile: ({ initData, fileContent, matrix, error, onFileSelected, onReset, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference, isBalances, onApplyStringEmptyFilter, onDownloadFilteredExcel, isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors, }: ExcelFileProps) => import("react").JSX.Element;
|
|
@@ -6,7 +6,8 @@ const react_1 = require("@heroui/react");
|
|
|
6
6
|
const react_2 = require("react");
|
|
7
7
|
const tb_1 = require("react-icons/tb");
|
|
8
8
|
const ExcelValidator_1 = require("./ExcelValidator");
|
|
9
|
-
const
|
|
9
|
+
const ThemeSwitcher_1 = require("./ThemeSwitcher");
|
|
10
|
+
const ExcelFile = ({ initData, fileContent, matrix, error, onFileSelected, onReset, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference = false, isBalances = false, onApplyStringEmptyFilter, onDownloadFilteredExcel, isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors, }) => {
|
|
10
11
|
var _a;
|
|
11
12
|
const [isVisible, setIsVisible] = (0, react_2.useState)(false);
|
|
12
13
|
const inputRef = (0, react_2.useRef)(null);
|
|
@@ -28,12 +29,12 @@ const ExcelFile = ({ initData, fileContent, matrix, error, onFileSelected, onRes
|
|
|
28
29
|
}
|
|
29
30
|
return (bytes / KB).toFixed(2) + " KB";
|
|
30
31
|
};
|
|
31
|
-
return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full bg-content1 p-4 border-none md:border-l border-default-200", children: [(0, jsx_runtime_1.jsxs)("h2", { className: "text-xl font-semibold text-default-700", children: ["Importa ", initData.title] }), error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: error, className: "mt-3", radius: "sm", hideIconWrapper: true })) : isVisible ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { radius: "sm", hideIconWrapper: true, hideIcon: true, isVisible: isVisible, className: "mt-4 max-w-full overflow-hidden", classNames: {
|
|
32
|
+
return ((0, jsx_runtime_1.jsxs)("section", { className: "h-full bg-content1 p-4 border-none md:border-l border-default-200", children: [(0, jsx_runtime_1.jsx)(ThemeSwitcher_1.ThemeSwitcher, {}), (0, jsx_runtime_1.jsxs)("h2", { className: "text-xl font-semibold text-default-700", children: ["Importa ", initData.title] }), error ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: error, className: "mt-3", radius: "sm", hideIconWrapper: true })) : isVisible ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { radius: "sm", hideIconWrapper: true, hideIcon: true, isVisible: isVisible, className: "mt-4 max-w-full overflow-hidden", classNames: {
|
|
32
33
|
mainWrapper: "min-w-0 flex-1 overflow-hidden",
|
|
33
34
|
closeButton: "shrink-0",
|
|
34
35
|
}, variant: "bordered", onClose: handleReset, children: (0, jsx_runtime_1.jsxs)("div", { className: "flex min-w-0 max-w-full items-center gap-2 overflow-hidden text-default-700", children: [(0, jsx_runtime_1.jsx)(tb_1.TbFile, { className: "shrink-0", size: 28 }), " ", (0, jsx_runtime_1.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col overflow-hidden", children: [(0, jsx_runtime_1.jsx)("p", { className: "max-w-full truncate text-sm", title: fileContent === null || fileContent === void 0 ? void 0 : fileContent.name, children: fileContent === null || fileContent === void 0 ? void 0 : fileContent.name }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: bytesFormat((_a = fileContent === null || fileContent === void 0 ? void 0 : fileContent.size) !== null && _a !== void 0 ? _a : 0) })] })] }) }), initData.type === "accounts" && ((0, jsx_runtime_1.jsxs)("div", { className: "mt-4 space-y-2 flex md:flex-col gap-5 md:gap-0", children: [(0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "warning", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbFilter, { size: 18 }), onPress: onApplyStringEmptyFilter, isDisabled: !hasStringEmptyDuplicateErrors || isStringEmptyFilterApplied, children: isStringEmptyFilterApplied
|
|
35
36
|
? "Filtro aplicado"
|
|
36
|
-
: "Quitar cuentas ya registradas" }), (0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "success", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbDownload, { size: 18 }), onPress: onDownloadFilteredExcel, isDisabled: !isStringEmptyFilterApplied || !hasStringEmptyDuplicateErrors, children: "Descargar Nuevo Excel" })] })), (0, jsx_runtime_1.jsx)(ExcelValidator_1.ExcelValidator, { initData: initData, fileContent: fileContent, matrix: matrix, validationErrors: validationErrors, onSelectError: onSelectError, onClearSelectedError: onClearSelectedError, hasBalanceDifference: hasBalanceDifference })] })) : ((0, jsx_runtime_1.jsx)("label", { className: "mt-4 flex cursor-pointer items-center justify-center rounded-lg border border-dashed border-default-300 px-4 py-8 text-sm font-medium text-default-600 transition hover:border-primary hover:text-primary", htmlFor: "excel-upload", children: (0, jsx_runtime_1.jsxs)("div", { className: "text-center flex flex-col items-center gap-2", children: [(0, jsx_runtime_1.jsx)(tb_1.TbUpload, { size: 28 }), (0, jsx_runtime_1.jsx)("p", { className: "font-semibold text-lg", children: "Seleccionar plantilla" }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: "Adjunta un archivo .xlsx o .xls para validar y previsualizar." })] }) })), (0, jsx_runtime_1.jsx)("input", { id: "excel-upload", ref: inputRef, className: "hidden", type: "file", accept: ".xlsx,.xls", onChange: (event) => {
|
|
37
|
+
: "Quitar cuentas ya registradas" }), (0, jsx_runtime_1.jsx)(react_1.Button, { className: "w-full border-1", color: "success", variant: "bordered", radius: "sm", startContent: (0, jsx_runtime_1.jsx)(tb_1.TbDownload, { size: 18 }), onPress: onDownloadFilteredExcel, isDisabled: !isStringEmptyFilterApplied || !hasStringEmptyDuplicateErrors, children: "Descargar Nuevo Excel" })] })), (0, jsx_runtime_1.jsx)(ExcelValidator_1.ExcelValidator, { initData: initData, fileContent: fileContent, matrix: matrix, validationErrors: validationErrors, onSelectError: onSelectError, onClearSelectedError: onClearSelectedError, hasBalanceDifference: hasBalanceDifference, isBalances: isBalances })] })) : ((0, jsx_runtime_1.jsx)("label", { className: "mt-4 flex cursor-pointer items-center justify-center rounded-lg border border-dashed border-default-300 px-4 py-8 text-sm font-medium text-default-600 transition hover:border-primary hover:text-primary", htmlFor: "excel-upload", children: (0, jsx_runtime_1.jsxs)("div", { className: "text-center flex flex-col items-center gap-2", children: [(0, jsx_runtime_1.jsx)(tb_1.TbUpload, { size: 28 }), (0, jsx_runtime_1.jsx)("p", { className: "font-semibold text-lg", children: "Seleccionar plantilla" }), (0, jsx_runtime_1.jsx)("small", { className: "text-default-500", children: "Adjunta un archivo .xlsx o .xls para validar y previsualizar." })] }) })), (0, jsx_runtime_1.jsx)("input", { id: "excel-upload", ref: inputRef, className: "hidden", type: "file", accept: ".xlsx,.xls", onChange: (event) => {
|
|
37
38
|
void onFileSelected(event);
|
|
38
39
|
setIsVisible(true);
|
|
39
40
|
} })] }));
|
|
@@ -387,14 +387,17 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
|
|
|
387
387
|
const isOptional = rule.type.trim().startsWith("$");
|
|
388
388
|
if (normalizedType === "fetch") {
|
|
389
389
|
const trimmedValue = value.trim();
|
|
390
|
+
const normalizedProp = rule.prop.trim();
|
|
391
|
+
const fetchProp = normalizedProp.replace(/^\$/, "");
|
|
392
|
+
const isFetchOptional = isOptional || normalizedProp.startsWith("$");
|
|
390
393
|
if (trimmedValue === "") {
|
|
391
|
-
return
|
|
394
|
+
return isFetchOptional
|
|
392
395
|
? { valid: true, message: "" }
|
|
393
396
|
: { valid: false, message: "Valor vacío" };
|
|
394
397
|
}
|
|
395
398
|
const catalog = (_a = fetchCatalogsByUrl[rule.url]) !== null && _a !== void 0 ? _a : [];
|
|
396
399
|
const hasMatch = catalog.some((catalogItem) => {
|
|
397
|
-
const propValue = catalogItem[
|
|
400
|
+
const propValue = catalogItem[fetchProp];
|
|
398
401
|
return String(propValue !== null && propValue !== void 0 ? propValue : "").trim() === trimmedValue;
|
|
399
402
|
});
|
|
400
403
|
return {
|
|
@@ -586,5 +589,5 @@ function ExcelLayout({ initData, jsonValidator, isBalances = false, }) {
|
|
|
586
589
|
setFocusTarget(null);
|
|
587
590
|
setIsStringEmptyFilterApplied(false);
|
|
588
591
|
};
|
|
589
|
-
return ((0, jsx_runtime_1.jsxs)("main", { ref: mainRef, className: "grid grid-cols-1 h-full grid-rows-2 md:grid-rows-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-hidden", children: [(0, jsx_runtime_1.jsx)("div", { className: "space-y-4 col-span-1 order-2 ", children: (0, jsx_runtime_1.jsx)(ExcelFile_1.ExcelFile, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, onFileSelected: handleFileSelected, onReset: handleReset, validationErrors: validationErrorsForPanel, onSelectError: handleSelectError, onClearSelectedError: handleClearSelectedError, hasBalanceDifference: hasBalanceDifference, onApplyStringEmptyFilter: handleApplyStringEmptyFilter, onDownloadFilteredExcel: handleDownloadFilteredExcel, isStringEmptyFilterApplied: isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors: hasStringEmptyDuplicateErrors }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-span-1 lg:col-span-2 xl:col-span-3", children: (0, jsx_runtime_1.jsx)(ExcelPreview_1.ExcelPreview, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, validationErrors: validationErrors, focusTarget: focusTarget, currentPage: currentPage, onPageChange: setCurrentPage, isBalances: isBalances, hiddenFilteredRowIndexes: isStringEmptyFilterApplied ? stringEmptyDuplicateRowIndexes : [] }) })] }));
|
|
592
|
+
return ((0, jsx_runtime_1.jsxs)("main", { ref: mainRef, className: "grid grid-cols-1 h-full grid-rows-2 md:grid-rows-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 overflow-hidden", children: [(0, jsx_runtime_1.jsx)("div", { className: "space-y-4 col-span-1 order-2 ", children: (0, jsx_runtime_1.jsx)(ExcelFile_1.ExcelFile, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, onFileSelected: handleFileSelected, onReset: handleReset, validationErrors: validationErrorsForPanel, onSelectError: handleSelectError, onClearSelectedError: handleClearSelectedError, hasBalanceDifference: hasBalanceDifference, isBalances: isBalances, onApplyStringEmptyFilter: handleApplyStringEmptyFilter, onDownloadFilteredExcel: handleDownloadFilteredExcel, isStringEmptyFilterApplied: isStringEmptyFilterApplied, hasStringEmptyDuplicateErrors: hasStringEmptyDuplicateErrors }) }), (0, jsx_runtime_1.jsx)("div", { className: "col-span-1 lg:col-span-2 xl:col-span-3", children: (0, jsx_runtime_1.jsx)(ExcelPreview_1.ExcelPreview, { initData: initData, fileContent: fileContent, matrix: matrix, error: error, validationErrors: validationErrors, focusTarget: focusTarget, currentPage: currentPage, onPageChange: setCurrentPage, isBalances: isBalances, hiddenFilteredRowIndexes: isStringEmptyFilterApplied ? stringEmptyDuplicateRowIndexes : [] }) })] }));
|
|
590
593
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ExcelValidatorProps } from "../types/excelTypes";
|
|
2
|
-
export declare const ExcelValidator: ({ initData, fileContent, matrix, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference, }: ExcelValidatorProps) => import("react").JSX.Element | null;
|
|
2
|
+
export declare const ExcelValidator: ({ initData, fileContent, matrix, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference, isBalances, }: ExcelValidatorProps) => import("react").JSX.Element | null;
|
|
@@ -3,17 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExcelValidator = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("@heroui/react");
|
|
6
|
+
const date_1 = require("@internationalized/date");
|
|
6
7
|
const navigation_1 = require("next/navigation");
|
|
7
8
|
const react_2 = require("react");
|
|
8
9
|
const tb_1 = require("react-icons/tb");
|
|
9
|
-
const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference = false, }) => {
|
|
10
|
+
const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSelectError, onClearSelectedError, hasBalanceDifference = false, isBalances = false, }) => {
|
|
10
11
|
const { replace } = (0, navigation_1.useRouter)();
|
|
11
12
|
const [selectedErrorId, setSelectedErrorId] = (0, react_2.useState)(null);
|
|
12
13
|
const [isUploadingTemplate, setIsUploadingTemplate] = (0, react_2.useState)(false);
|
|
13
14
|
const [uploadMessage, setUploadMessage] = (0, react_2.useState)(null);
|
|
15
|
+
const [balanceDate, setBalanceDate] = (0, react_2.useState)(() => isBalances ? (0, date_1.today)((0, date_1.getLocalTimeZone)()) : null);
|
|
14
16
|
if (!fileContent) {
|
|
15
17
|
return null;
|
|
16
18
|
}
|
|
19
|
+
const hasDataRows = matrix
|
|
20
|
+
.slice(1)
|
|
21
|
+
.some((row) => { var _a, _b; return ((_b = (_a = row[0]) === null || _a === void 0 ? void 0 : _a.toString().trim()) !== null && _b !== void 0 ? _b : "") !== ""; });
|
|
17
22
|
const handleTXTFormat = async () => {
|
|
18
23
|
var _a;
|
|
19
24
|
setIsUploadingTemplate(true);
|
|
@@ -27,6 +32,11 @@ const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSel
|
|
|
27
32
|
return padded.join("|");
|
|
28
33
|
});
|
|
29
34
|
const content = lines.join("\n");
|
|
35
|
+
const dateBalances = balanceDate
|
|
36
|
+
? `${balanceDate.year.toString().padStart(4, "0")}-${balanceDate.month
|
|
37
|
+
.toString()
|
|
38
|
+
.padStart(2, "0")}-${balanceDate.day.toString().padStart(2, "0")}`
|
|
39
|
+
: "";
|
|
30
40
|
const utf8Content = `\uFEFF${content}`;
|
|
31
41
|
const base64Content = (() => {
|
|
32
42
|
const bytes = new TextEncoder().encode(utf8Content);
|
|
@@ -48,6 +58,7 @@ const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSel
|
|
|
48
58
|
content: base64Content,
|
|
49
59
|
extension: "txt",
|
|
50
60
|
encoding: "utf-8",
|
|
61
|
+
date: dateBalances,
|
|
51
62
|
name: `Plantilla ${initData.title}`,
|
|
52
63
|
type: initData.type,
|
|
53
64
|
}),
|
|
@@ -81,7 +92,7 @@ const ExcelValidator = ({ initData, fileContent, matrix, validationErrors, onSel
|
|
|
81
92
|
};
|
|
82
93
|
return ((0, jsx_runtime_1.jsxs)("section", { className: "mt-5 bg-content1 max-h-[calc(100vh-11.5rem)] overflow-y-auto pr-1", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex xl:flex-row lg:flex-col mb-3 justify-between items-center", children: [(0, jsx_runtime_1.jsx)("h2", { className: "text-xl font-semibold text-default-700", children: "Validaciones" }), (0, jsx_runtime_1.jsx)(react_1.Chip, { color: validationErrors.length > 0 ? "danger" : "success", variant: "solid", className: "text-white", startContent: validationErrors.length > 0 ? ((0, jsx_runtime_1.jsx)(tb_1.TbAlertCircle, { size: 20 })) : ((0, jsx_runtime_1.jsx)(tb_1.TbCheck, { size: 20 })), children: (0, jsx_runtime_1.jsxs)("p", { className: "pl-1", children: [validationErrors.length, " ", validationErrors.length === 1
|
|
83
94
|
? "error encontrado"
|
|
84
|
-
: "errores encontrados"] }) })] }), hasBalanceDifference ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: "Hay diferencias en los saldos iniciales", variant: "faded", hideIcon: true, startContent: (0, jsx_runtime_1.jsx)(tb_1.TbAlertCircle, { size: 30 }), className: "mb-3" })) : null, validationErrors.length === 0 && !hasBalanceDifference ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { color: "success", title: "Sin errores de validaci\u00F3n.", variant: "faded", hideIcon: true, startContent: (0, jsx_runtime_1.jsx)(tb_1.TbCircleCheck, { size: 30 }) }), (0, jsx_runtime_1.jsx)(react_1.Button, { color: "success", className: "mt-4 w-full", variant: "flat", endContent: (0, jsx_runtime_1.jsx)(tb_1.TbUpload, { size: 20 }), radius: "sm", isLoading: isUploadingTemplate, onPress: handleTXTFormat, children: "Enviar Plantilla" }), uploadMessage ? ((0, jsx_runtime_1.jsx)("p", { className: `mt-2 text-sm ${uploadMessage.type === "success"
|
|
95
|
+
: "errores encontrados"] }) })] }), hasBalanceDifference ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: "Hay diferencias en los saldos iniciales", variant: "faded", hideIcon: true, startContent: (0, jsx_runtime_1.jsx)(tb_1.TbAlertCircle, { size: 30 }), className: "mb-3" })) : null, !hasDataRows ? ((0, jsx_runtime_1.jsx)(react_1.Alert, { color: "danger", title: "No hay filas insertadas en la plantilla.", variant: "faded", hideIcon: true, startContent: (0, jsx_runtime_1.jsx)(tb_1.TbAlertCircle, { size: 30 }) })) : validationErrors.length === 0 && !hasBalanceDifference ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_1.Alert, { color: "success", title: "Sin errores de validaci\u00F3n.", variant: "faded", hideIcon: true, startContent: (0, jsx_runtime_1.jsx)(tb_1.TbCircleCheck, { size: 30 }) }), isBalances ? ((0, jsx_runtime_1.jsx)(react_1.DatePicker, { className: "mt-4 w-full", label: "Fecha de Corte", value: balanceDate, onChange: setBalanceDate, isRequired: true })) : null, (0, jsx_runtime_1.jsx)(react_1.Button, { color: "success", className: "mt-4 w-full", variant: "flat", endContent: (0, jsx_runtime_1.jsx)(tb_1.TbUpload, { size: 20 }), radius: "sm", isLoading: isUploadingTemplate, isDisabled: isBalances && balanceDate === null, onPress: handleTXTFormat, children: "Enviar Plantilla" }), uploadMessage ? ((0, jsx_runtime_1.jsx)("p", { className: `mt-2 text-sm ${uploadMessage.type === "success"
|
|
85
96
|
? "text-success-600"
|
|
86
97
|
: "text-danger-600"}`, children: uploadMessage.text })) : null] })) : ((0, jsx_runtime_1.jsx)(react_1.Accordion, { selectionMode: "multiple", showDivider: false, children: Object.entries(validationErrors.reduce((groups, error) => {
|
|
87
98
|
const key = error.columnName;
|
|
@@ -27,6 +27,7 @@ export type ExcelFileProps = {
|
|
|
27
27
|
onSelectError: (error: ValidationError) => void;
|
|
28
28
|
onClearSelectedError: () => void;
|
|
29
29
|
hasBalanceDifference?: boolean;
|
|
30
|
+
isBalances?: boolean;
|
|
30
31
|
onApplyStringEmptyFilter: () => void;
|
|
31
32
|
onDownloadFilteredExcel: () => void;
|
|
32
33
|
isStringEmptyFilterApplied: boolean;
|
|
@@ -40,6 +41,7 @@ export type ExcelValidatorProps = {
|
|
|
40
41
|
onSelectError: (error: ValidationError) => void;
|
|
41
42
|
onClearSelectedError: () => void;
|
|
42
43
|
hasBalanceDifference?: boolean;
|
|
44
|
+
isBalances?: boolean;
|
|
43
45
|
};
|
|
44
46
|
export type ExcelPreviewProps = {
|
|
45
47
|
initData: SettingsProps;
|