fix(sinpe): optimizar botones y ficha bancaria compacta para evitar corte en pantallas móviles

This commit is contained in:
unknown
2026-10-07 00:35:36 -06:00
parent 451d27d7df
commit bbbee76cfe
7 changed files with 988 additions and 92 deletions
+465
View File
@@ -12,7 +12,9 @@
"better-sqlite3": "^13.0.3", "better-sqlite3": "^13.0.3",
"cors": "^2.8.6", "cors": "^2.8.6",
"express": "^5.2.1", "express": "^5.2.1",
"imap-simple": "^5.1.0",
"jsqr": "^1.4.0", "jsqr": "^1.4.0",
"mailparser": "^3.9.36",
"pg": "^8.23.1", "pg": "^8.23.1",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",
"synckit": "^0.11.13", "synckit": "^0.11.13",
@@ -31,6 +33,33 @@
"url": "https://opencollective.com/pkgr" "url": "https://opencollective.com/pkgr"
} }
}, },
"node_modules/@selderee/plugin-htmlparser2": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@selderee/plugin-htmlparser2/-/plugin-htmlparser2-0.12.0.tgz",
"integrity": "sha512-oELmoyA6ML9jDRMV3kgcMQFKxUfBU0yFVn6yTctVaLT5ygXnxH52I3TZEgV9EhXJC68/uFvE5Daj1/25c0Xa/A==",
"license": "MIT",
"dependencies": {
"domelementtype": "~2.3.0",
"domhandler": "~5.0.3"
},
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
},
"peerDependencies": {
"selderee": "~0.12.0"
}
},
"node_modules/@zone-eu/mailsplit": {
"version": "5.4.20",
"resolved": "https://registry.npmjs.org/@zone-eu/mailsplit/-/mailsplit-5.4.20.tgz",
"integrity": "sha512-6B2w0zRBWOwbO5h7SL5N/2z1AuNchTP3OT33MObUr4/cz9bWPrZ6KadLKxnSrOZG0AGu7Q03p4X7eQhZHc1u/A==",
"license": "(MIT OR EUPL-1.1+)",
"dependencies": {
"libbase64": "1.3.2",
"libmime": "5.4.7",
"libqp": "2.1.2"
}
},
"node_modules/accepts": { "node_modules/accepts": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",
@@ -266,6 +295,12 @@
"node": ">=6.6.0" "node": ">=6.6.0"
} }
}, },
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
"license": "MIT"
},
"node_modules/cors": { "node_modules/cors": {
"version": "2.8.6", "version": "2.8.6",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
@@ -309,6 +344,25 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/deepmerge-ts": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/deepmerge-ts/-/deepmerge-ts-8.0.2.tgz",
"integrity": "sha512-uqbvqLUMrc6p0MO+WBRtTxY55hmyh94WRwI5a++PZe54X+bfVh59FSN7uWCBCW1CCVjzjnrwzfI8zidE2obMMw==",
"funding": [
{
"type": "ko-fi",
"url": "https://ko-fi.com/rebeccastevens"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/deepmerge-ts"
}
],
"license": "BSD-3-Clause",
"engines": {
"node": ">=16.9.0"
}
},
"node_modules/depd": { "node_modules/depd": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -324,6 +378,61 @@
"integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==", "integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/dom-serializer": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
"integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",
"license": "MIT",
"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.2",
"entities": "^4.2.0"
},
"funding": {
"url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"
}
},
"node_modules/domelementtype": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",
"integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fb55"
}
],
"license": "BSD-2-Clause"
},
"node_modules/domhandler": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
"integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
"license": "BSD-2-Clause",
"dependencies": {
"domelementtype": "^2.3.0"
},
"engines": {
"node": ">= 4"
},
"funding": {
"url": "https://github.com/fb55/domhandler?sponsor=1"
}
},
"node_modules/domutils": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz",
"integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==",
"license": "BSD-2-Clause",
"dependencies": {
"dom-serializer": "^2.0.0",
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3"
},
"funding": {
"url": "https://github.com/fb55/domutils?sponsor=1"
}
},
"node_modules/dunder-proto": { "node_modules/dunder-proto": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
@@ -368,6 +477,27 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/encoding-japanese": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/encoding-japanese/-/encoding-japanese-2.4.0.tgz",
"integrity": "sha512-PE0KjlsDy9JSsoU4C2Q8NXb1kC4c+bZRac9ZvHXUE4q1Ht63gScKMdEy9jst9+Fi3M4eDkqzkEhBZvix4blP2A==",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/entities": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
"integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/es-define-property": { "node_modules/es-define-property": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
@@ -599,6 +729,65 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"license": "MIT",
"bin": {
"he": "bin/he"
}
},
"node_modules/html-to-text": {
"version": "10.0.1",
"resolved": "https://registry.npmjs.org/html-to-text/-/html-to-text-10.0.1.tgz",
"integrity": "sha512-GiVhRI1BatGARSCmlXWNCjDT0cWrwBWoeduLoV0WSKAgaV/wa+hUWy5LiQLUs4UwiUrE52ZCMfBGiKD87TDPrg==",
"license": "MIT",
"dependencies": {
"@selderee/plugin-htmlparser2": "~0.12.0",
"deepmerge-ts": "^8.0.1",
"dom-serializer": "^2.0.0",
"htmlparser2": "^10.1.0",
"selderee": "~0.12.0"
},
"engines": {
"node": ">=20.19.0"
},
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
}
},
"node_modules/htmlparser2": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-10.1.0.tgz",
"integrity": "sha512-VTZkM9GWRAtEpveh7MSF6SjjrpNVNNVJfFup7xTY3UpFtm67foy9HDVXneLtFVt4pMz5kZtgNcvCniNFb1hlEQ==",
"funding": [
"https://github.com/fb55/htmlparser2?sponsor=1",
{
"type": "github",
"url": "https://github.com/sponsors/fb55"
}
],
"license": "MIT",
"dependencies": {
"domelementtype": "^2.3.0",
"domhandler": "^5.0.3",
"domutils": "^3.2.2",
"entities": "^7.0.1"
}
},
"node_modules/htmlparser2/node_modules/entities": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz",
"integrity": "sha512-TWrgLOFUQTH994YUyl1yT4uyavY5nNB5muff+RtWaqNVCAK408b5ZnnbNAUEWLTCpum9w6arT70i1XdQ4UeOPA==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/http_ece": { "node_modules/http_ece": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/http_ece/-/http_ece-1.2.0.tgz", "resolved": "https://registry.npmjs.org/http_ece/-/http_ece-1.2.0.tgz",
@@ -657,6 +846,47 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/imap": {
"version": "0.8.19",
"resolved": "https://registry.npmjs.org/imap/-/imap-0.8.19.tgz",
"integrity": "sha512-z5DxEA1uRnZG73UcPA4ES5NSCGnPuuouUx43OPX7KZx1yzq3N8/vx2mtXEShT5inxB3pRgnfG1hijfu7XN2YMw==",
"dependencies": {
"readable-stream": "1.1.x",
"utf7": ">=1.0.2"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/imap-simple": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/imap-simple/-/imap-simple-5.1.0.tgz",
"integrity": "sha512-FLZm1v38C5ekN46l/9X5gBRNMQNVc5TSLYQ3Hsq3xBLvKwt1i5fcuShyth8MYMPuvId1R46oaPNrH92hFGHr/g==",
"license": "MIT",
"dependencies": {
"iconv-lite": "~0.4.13",
"imap": "^0.8.18",
"nodeify": "^1.0.0",
"quoted-printable": "^1.0.0",
"utf8": "^2.1.1",
"uuencode": "0.0.4"
},
"engines": {
"node": ">=6"
}
},
"node_modules/imap-simple/node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": { "node_modules/inherits": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
@@ -687,6 +917,12 @@
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==",
"license": "MIT"
},
"node_modules/jsqr": { "node_modules/jsqr": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.4.0.tgz", "resolved": "https://registry.npmjs.org/jsqr/-/jsqr-1.4.0.tgz",
@@ -714,6 +950,58 @@
"safe-buffer": "^5.0.1" "safe-buffer": "^5.0.1"
} }
}, },
"node_modules/leac": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/leac/-/leac-0.7.0.tgz",
"integrity": "sha512-qMrZeyEekgdRQ9o6a4NAB2EQZrv827GJdn1vnapwSJ90hWRB4TzUSunvacPkxQ2TnNqHNI1/zSt0hlo0crG8Jw==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
}
},
"node_modules/libbase64": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/libbase64/-/libbase64-1.3.2.tgz",
"integrity": "sha512-fFCoI0ceXhTu/0QiJ6Uf6BV9k7X/8QW2/D4BR1vw3BPrHcIjLbGLH+U7inQ4SeWrfNCOmpGE09Qt4XjSFfus0g==",
"license": "MIT"
},
"node_modules/libmime": {
"version": "5.4.7",
"resolved": "https://registry.npmjs.org/libmime/-/libmime-5.4.7.tgz",
"integrity": "sha512-r1ENu4wMVSB52AAORwaW4L/MeQJr9rryzHLRpcjud3zcUPWXh1Xkgn+tAqL8oTnRO/LW7y5xxPBE20ta5amtMA==",
"license": "MIT",
"dependencies": {
"encoding-japanese": "2.4.0",
"iconv-lite": "0.7.3",
"libbase64": "1.3.2",
"libqp": "2.1.2"
}
},
"node_modules/libqp": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/libqp/-/libqp-2.1.2.tgz",
"integrity": "sha512-rp+U80tl9Os4K7GnVbPzPRmghPu6eqB8rcF+ontvNAnoga0JhMFG/bkTD/reC8yoznKMgOc5/ttZHJasiWeFPw==",
"license": "MIT"
},
"node_modules/linkify-it": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.2.tgz",
"integrity": "sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/puzrin"
},
{
"type": "github",
"url": "https://github.com/sponsors/markdown-it"
}
],
"license": "MIT",
"dependencies": {
"uc.micro": "^2.0.0"
}
},
"node_modules/locate-path": { "node_modules/locate-path": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@@ -726,6 +1014,27 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/mailparser": {
"version": "3.9.36",
"resolved": "https://registry.npmjs.org/mailparser/-/mailparser-3.9.36.tgz",
"integrity": "sha512-Fng3OmPN7khG0oVHDwwBIOYxjGu7kFxEuN6NnVV1H2tQYCIWjqvjK6cKvhj2r3XQVToVabP0b4HF+N7YgNdXFQ==",
"license": "MIT",
"dependencies": {
"@zone-eu/mailsplit": "5.4.20",
"encoding-japanese": "2.4.0",
"he": "1.2.0",
"html-to-text": "10.0.1",
"iconv-lite": "0.7.3",
"libmime": "5.4.7",
"linkify-it": "5.0.2",
"nodemailer": "10.0.14",
"punycode.js": "2.3.1",
"tlds": "1.261.0"
},
"engines": {
"node": ">=20.0.0"
}
},
"node_modules/math-intrinsics": { "node_modules/math-intrinsics": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
@@ -844,6 +1153,31 @@
"node": "^18 || ^20 || >= 21" "node": "^18 || ^20 || >= 21"
} }
}, },
"node_modules/nodeify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/nodeify/-/nodeify-1.0.1.tgz",
"integrity": "sha512-n7C2NyEze8GCo/z73KdbjRsBiLbv6eBn1FxwYKQ23IqGo7pQY3mhQan61Sv7eEDJCiyUjTVrVkXTzJCo1dW7Aw==",
"license": "MIT",
"dependencies": {
"is-promise": "~1.0.0",
"promise": "~1.3.0"
}
},
"node_modules/nodeify/node_modules/is-promise": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-1.0.1.tgz",
"integrity": "sha512-mjWH5XxnhMA8cFnDchr6qRP9S/kLntKuEfIYku+PaN1CnS8v+OG9O/BKpRCVRJvpIkgAZm0Pf5Is3iSSOILlcg==",
"license": "MIT"
},
"node_modules/nodemailer": {
"version": "10.0.14",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-10.0.14.tgz",
"integrity": "sha512-eJoLFKg55fesSlzUekmfOv/SBXh4KUYT8oiQc2RLP0tfG0rbNMJBK7wgHJwXTJwqyKlSJMz9UzDZ4v+aHEvo8g==",
"license": "MIT-0",
"engines": {
"node": ">=20.0.0"
}
},
"node_modules/object-assign": { "node_modules/object-assign": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -922,6 +1256,19 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/parseley": {
"version": "0.13.1",
"resolved": "https://registry.npmjs.org/parseley/-/parseley-0.13.1.tgz",
"integrity": "sha512-uNBJZzmb60l6p6VWLTmevizNAGnE0xoSf1n0B4q3ntegDNzcS68NRCcBDZTcyXHxt2XhBChsCuqj4M+nChvE/A==",
"license": "MIT",
"dependencies": {
"leac": "^0.7.0",
"peberminta": "^0.10.0"
},
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
}
},
"node_modules/parseurl": { "node_modules/parseurl": {
"version": "1.3.3", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
@@ -950,6 +1297,15 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/peberminta": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/peberminta/-/peberminta-0.10.0.tgz",
"integrity": "sha512-80B2AsU+I4Qdb0ZAPSfe9UwvGzwkM37IKIFEvdS3D/3Ndgv2bsuJ0bfG1+iEYO+l7Gfd4EUJmuRyq7efLgRMzQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
}
},
"node_modules/pg": { "node_modules/pg": {
"version": "8.23.1", "version": "8.23.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.23.1.tgz", "resolved": "https://registry.npmjs.org/pg/-/pg-8.23.1.tgz",
@@ -1087,6 +1443,21 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/promise": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/promise/-/promise-1.3.0.tgz",
"integrity": "sha512-R9WrbTF3EPkVtWjp7B7umQGVndpsi+rsDAfrR4xAALQpFLa/+2OriecLhawxzvii2gd9+DZFwROWDuUUaqS5yA==",
"license": "MIT",
"dependencies": {
"is-promise": "~1"
}
},
"node_modules/promise/node_modules/is-promise": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-1.0.1.tgz",
"integrity": "sha512-mjWH5XxnhMA8cFnDchr6qRP9S/kLntKuEfIYku+PaN1CnS8v+OG9O/BKpRCVRJvpIkgAZm0Pf5Is3iSSOILlcg==",
"license": "MIT"
},
"node_modules/proxy-addr": { "node_modules/proxy-addr": {
"version": "2.0.8", "version": "2.0.8",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz",
@@ -1104,6 +1475,15 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/punycode.js": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
"integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/qrcode": { "node_modules/qrcode": {
"version": "1.5.4", "version": "1.5.4",
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz", "resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
@@ -1137,6 +1517,18 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/quoted-printable": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/quoted-printable/-/quoted-printable-1.0.1.tgz",
"integrity": "sha512-cihC68OcGiQOjGiXuo5Jk6XHANTHl1K4JLk/xlEJRTIXfy19Sg6XzB95XonYgr+1rB88bCpr7WZE7D7AlZow4g==",
"license": "MIT",
"dependencies": {
"utf8": "^2.1.0"
},
"bin": {
"quoted-printable": "bin/quoted-printable"
}
},
"node_modules/range-parser": { "node_modules/range-parser": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz",
@@ -1165,6 +1557,18 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==",
"license": "MIT",
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/require-directory": { "node_modules/require-directory": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@@ -1222,6 +1626,27 @@
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/selderee": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/selderee/-/selderee-0.12.0.tgz",
"integrity": "sha512-b1YMh3+DHZp59DLna3qVwQ5iOla/nrI6mLBNW02XxU77M3046Df6VLkoaJyFz20VsGIG5kkp+FK0kg4K4HnUFw==",
"license": "MIT",
"dependencies": {
"parseley": "~0.13.1"
},
"funding": {
"url": "https://github.com/sponsors/KillyMXI"
}
},
"node_modules/semver": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz",
"integrity": "sha512-mfmm3/H9+67MCVix1h+IXTpDwL6710LyHuk7+cWC9T1mE0qz4iHhh6r4hU2wrIT9iTsAAC2XQRvfblL028cpLw==",
"license": "ISC",
"bin": {
"semver": "bin/semver"
}
},
"node_modules/send": { "node_modules/send": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz",
@@ -1369,6 +1794,12 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==",
"license": "MIT"
},
"node_modules/string-width": { "node_modules/string-width": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@@ -1410,6 +1841,15 @@
"url": "https://opencollective.com/synckit" "url": "https://opencollective.com/synckit"
} }
}, },
"node_modules/tlds": {
"version": "1.261.0",
"resolved": "https://registry.npmjs.org/tlds/-/tlds-1.261.0.tgz",
"integrity": "sha512-QXqwfEl9ddlGBaRFXIvNKK6OhipSiLXuRuLJX5DErz0o0Q0rYxulWLdFryTkV5PkdZct5iMInwYEGe/eR++1AA==",
"license": "MIT",
"bin": {
"tlds": "bin.js"
}
},
"node_modules/toidentifier": { "node_modules/toidentifier": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
@@ -1450,6 +1890,12 @@
"url": "https://opencollective.com/express" "url": "https://opencollective.com/express"
} }
}, },
"node_modules/uc.micro": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
"integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
"license": "MIT"
},
"node_modules/unpipe": { "node_modules/unpipe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
@@ -1459,6 +1905,25 @@
"node": ">= 0.8" "node": ">= 0.8"
} }
}, },
"node_modules/utf7": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utf7/-/utf7-1.0.2.tgz",
"integrity": "sha512-qQrPtYLLLl12NF4DrM9CvfkxkYI97xOb5dsnGZHE3teFr0tWiEZ9UdgMPczv24vl708cYMpe6mGXGHrotIp3Bw==",
"dependencies": {
"semver": "~5.3.0"
}
},
"node_modules/utf8": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
"integrity": "sha512-QXo+O/QkLP/x1nyi54uQiG0XrODxdysuQvE5dtVqv7F5K2Qb6FsN+qbr6KhF5wQ20tfcV3VQp0/2x1e1MRSPWg==",
"license": "MIT"
},
"node_modules/uuencode": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/uuencode/-/uuencode-0.0.4.tgz",
"integrity": "sha512-yEEhCuCi5wRV7Z5ZVf9iV2gWMvUZqKJhAs1ecFdKJ0qzbyaVelmsE3QjYAamehfp9FKLiZbKldd+jklG3O0LfA=="
},
"node_modules/vary": { "node_modules/vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+2
View File
@@ -24,7 +24,9 @@
"better-sqlite3": "^13.0.3", "better-sqlite3": "^13.0.3",
"cors": "^2.8.6", "cors": "^2.8.6",
"express": "^5.2.1", "express": "^5.2.1",
"imap-simple": "^5.1.0",
"jsqr": "^1.4.0", "jsqr": "^1.4.0",
"mailparser": "^3.9.36",
"pg": "^8.23.1", "pg": "^8.23.1",
"qrcode": "^1.5.4", "qrcode": "^1.5.4",
"synckit": "^0.11.13", "synckit": "^0.11.13",
+1 -1
View File
@@ -600,7 +600,7 @@
<div id="adminTabContentRecarga" class="admin-card" style="display: none; max-width: 820px; margin: 0 auto;"> <div id="adminTabContentRecarga" class="admin-card" style="display: none; max-width: 820px; margin: 0 auto;">
<!-- SECCIÓN 1: SOLICITUDES SINPE PENDIENTES DE APROBACIÓN --> <!-- SECCIÓN 1: SOLICITUDES SINPE PENDIENTES DE APROBACIÓN -->
<div id="adminSinpeRequestsBox" style="margin-bottom: 24px; background: #ffffff; border: 1.5px solid #86efac; border-radius: 16px; padding: 18px 20px; box-shadow: 0 2px 10px rgba(16, 185, 129, 0.08);"> <div id="adminSinpeRequestsBox" style="margin-bottom: 24px; background: #ffffff; border: 1.5px solid #86efac; border-radius: 16px; padding: 14px 14px; box-sizing: border-box; overflow: hidden; box-shadow: 0 2px 10px rgba(16, 185, 129, 0.08);">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;"> <div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 40px; height: 40px; border-radius: 12px; background: #ecfdf5; color: #10b981; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; border: 1.5px solid #a7f3d0; flex-shrink: 0;"> <div style="width: 40px; height: 40px; border-radius: 12px; background: #ecfdf5; color: #10b981; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; border: 1.5px solid #a7f3d0; flex-shrink: 0;">
+41 -40
View File
@@ -4802,77 +4802,78 @@ async function loadAdminSinpeRequests() {
}); });
return ` return `
<div class="sinpe-admin-card" style="background: #ffffff; border: 1.5px solid #86efac; border-radius: 16px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(16, 185, 129, 0.08); display: flex; flex-direction: column; gap: 12px; width: 100%; box-sizing: border-box;"> <div class="sinpe-admin-card" style="background: #ffffff; border: 1.5px solid #86efac; border-radius: 14px; padding: 14px 14px; box-shadow: 0 2px 8px rgba(16, 185, 129, 0.08); display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 100%; box-sizing: border-box; overflow: hidden;">
<!-- FILA 1: ESTUDIANTE Y MONTO --> <!-- FILA 1: ESTUDIANTE Y MONTO -->
<div style="display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; box-sizing: border-box; flex-wrap: wrap;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; box-sizing: border-box;">
<div style="display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1;"> <div style="display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;">
<div style="width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1rem; border: 1.5px solid #bae6fd; flex-shrink: 0; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15);"> <div style="width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 0.95rem; border: 1.5px solid #bae6fd; flex-shrink: 0; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15);">
${getStudentInitials(s.estudiante_nombre)} ${getStudentInitials(s.estudiante_nombre)}
</div> </div>
<div style="min-width: 0; flex: 1;"> <div style="min-width: 0; flex: 1;">
<div style="font-weight: 900; font-size: 1.05rem; color: #0f172a; line-height: 1.25; word-break: normal;"> <div style="font-weight: 900; font-size: 1rem; color: #0f172a; line-height: 1.2; word-break: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
${escapeHtml(s.estudiante_nombre)} ${escapeHtml(s.estudiante_nombre)}
</div> </div>
<div style="font-size: 0.78rem; color: #64748b; margin-top: 2px; font-weight: 600;"> <div style="font-size: 0.75rem; color: #64748b; margin-top: 1px; font-weight: 600;">
${escapeHtml(s.estudiante_grado || 'Estudiante')} ${s.estudiante_seccion ? '• Sección ' + escapeHtml(s.estudiante_seccion) : ''} ${escapeHtml(s.estudiante_grado || 'Estudiante')} ${s.estudiante_seccion ? '• Sec. ' + escapeHtml(s.estudiante_seccion) : ''}
</div> </div>
</div> </div>
</div> </div>
<div style="text-align: right; flex-shrink: 0;"> <div style="text-align: right; flex-shrink: 0;">
<div style="font-size: 1.35rem; font-weight: 900; color: #16a34a; letter-spacing: -0.5px; line-height: 1;"> <div style="font-size: 1.25rem; font-weight: 900; color: #16a34a; letter-spacing: -0.5px; line-height: 1;">
+₡${s.monto_colones.toLocaleString('es-CR')} +₡${s.monto_colones.toLocaleString('es-CR')}
</div> </div>
<div style="display: inline-block; font-size: 0.70rem; font-weight: 800; color: #b45309; background: #fef3c7; border: 1px solid #fde68a; padding: 2px 8px; border-radius: 6px; margin-top: 4px;"> <div style="display: inline-block; font-size: 0.68rem; font-weight: 800; color: #b45309; background: #fef3c7; border: 1px solid #fde68a; padding: 2px 6px; border-radius: 6px; margin-top: 3px;">
⏳ Por Verificar ⏳ Por Verificar
</div> </div>
</div> </div>
</div> </div>
<!-- FILA 2: DATOS DEL COMPROBANTE Y DETALLE EN CAJA HORIZONTAL --> <!-- FILA 2: DATOS DEL COMPROBANTE Y DETALLE -->
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem;"> <div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 0.80rem; box-sizing: border-box;">
<div style="display: flex; align-items: center; gap: 6px;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Código:</span> <div style="display: flex; align-items: center; gap: 5px;">
<span style="font-family: monospace; font-size: 0.95rem; font-weight: 900; color: #16a34a; background: #dcfce7; padding: 2px 8px; border-radius: 6px; border: 1px solid #bbf7d0;"> <span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase;">Código:</span>
${escapeHtml(s.codigo_detalle || '-')} <span style="font-family: monospace; font-size: 0.88rem; font-weight: 900; color: #16a34a; background: #dcfce7; padding: 2px 7px; border-radius: 6px; border: 1px solid #bbf7d0;">
</span> ${escapeHtml(s.codigo_detalle || '-')}
</span>
</div>
<div style="display: flex; align-items: center; gap: 5px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase;">Saldo:</span>
<span style="color: #334155; font-weight: 800; font-size: 0.82rem;">₡${(s.estudiante_saldo || 0).toLocaleString('es-CR')}</span>
</div>
</div> </div>
<div style="display: flex; align-items: center; gap: 6px;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px dashed #e2e8f0; padding-top: 5px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Comprobante:</span> <div style="display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1;">
<span style="font-family: monospace; font-size: 0.88rem; font-weight: 800; color: #0369a1; background: #e0f2fe; padding: 2px 8px; border-radius: 6px; border: 1px solid #bae6fd;"> <span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; flex-shrink: 0;">Comp:</span>
#${escapeHtml(s.comprobante_sinpe || '-')} <span style="font-family: monospace; font-size: 0.80rem; font-weight: 800; color: #0369a1; background: #e0f2fe; padding: 2px 6px; border-radius: 6px; border: 1px solid #bae6fd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
</span> #${escapeHtml(s.comprobante_sinpe || '-')}
</div> </span>
</div>
<div style="display: flex; align-items: center; gap: 6px;"> <div style="font-size: 0.73rem; color: #64748b; font-weight: 600; flex-shrink: 0;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Reportado:</span> ${fecha}
<span style="color: #334155; font-weight: 700;">${fecha}</span> </div>
</div>
<div style="display: flex; align-items: center; gap: 6px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Saldo Actual:</span>
<span style="color: #334155; font-weight: 800;">₡${(s.estudiante_saldo || 0).toLocaleString('es-CR')}</span>
</div> </div>
</div> </div>
${s.notas ? ` ${s.notas ? `
<div style="font-size: 0.75rem; color: #475569; background: #ffffff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 6px 12px; display: flex; align-items: center; gap: 6px;"> <div style="font-size: 0.75rem; color: #475569; background: #ffffff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 5px 10px; display: flex; align-items: center; gap: 6px; box-sizing: border-box; overflow: hidden;">
<span>💬</span> <span style="flex-shrink: 0;">💬</span>
<span><strong>Detalle:</strong> ${escapeHtml(s.notas)}</span> <span style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><strong>Detalle:</strong> ${escapeHtml(s.notas)}</span>
</div> </div>
` : ''} ` : ''}
<!-- FILA 3: BOTONES DE ACCIÓN (RECHAZAR / APROBAR) --> <!-- FILA 3: BOTONES DE ACCIÓN (RECHAZAR / APROBAR) -->
<div style="display: flex; gap: 10px; align-items: center; width: 100%; border-top: 1px solid #f1f5f9; padding-top: 10px; box-sizing: border-box;"> <div style="display: flex; gap: 8px; align-items: center; width: 100%; border-top: 1px solid #f1f5f9; padding-top: 8px; box-sizing: border-box;">
<button type="button" onclick="procesarSinpeAdmin(${s.id}, 'rechazar')" style="padding: 10px 16px; background: #fff1f2; color: #e11d48; border: 1.5px solid #fecdd3; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: all 0.15s;"> <button type="button" onclick="procesarSinpeAdmin(${s.id}, 'rechazar')" style="flex: 0 0 auto; width: 95px; padding: 10px 8px; background: #fff1f2; color: #e11d48; border: 1.5px solid #fecdd3; border-radius: 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; box-sizing: border-box; transition: all 0.15s;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
<span>Rechazar</span> <span>Rechazar</span>
</button> </button>
<button type="button" onclick="procesarSinpeAdmin(${s.id}, 'aprobar')" style="flex: 1; padding: 11px 18px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.90rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25); white-space: nowrap; transition: all 0.15s;"> <button type="button" onclick="procesarSinpeAdmin(${s.id}, 'aprobar')" style="flex: 1 1 0; min-width: 0; padding: 10px 8px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.86rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25); box-sizing: border-box; transition: all 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg> <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" style="flex-shrink: 0;"><polyline points="20 6 9 17 4 12"/></svg>
<span>Aprobar y Acreditar (+₡${s.monto_colones.toLocaleString('es-CR')})</span> <span>Aprobar (+₡${s.monto_colones.toLocaleString('es-CR')})</span>
</button> </button>
</div> </div>
</div> </div>
+41 -40
View File
@@ -1738,77 +1738,78 @@ async function loadSinpeRequests() {
}); });
return ` return `
<div class="sinpe-admin-card" style="background: #ffffff; border: 1.5px solid #86efac; border-radius: 16px; padding: 16px 18px; box-shadow: 0 2px 8px rgba(16, 185, 129, 0.08); display: flex; flex-direction: column; gap: 12px; width: 100%; box-sizing: border-box;"> <div class="sinpe-admin-card" style="background: #ffffff; border: 1.5px solid #86efac; border-radius: 14px; padding: 14px 14px; box-shadow: 0 2px 8px rgba(16, 185, 129, 0.08); display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 100%; box-sizing: border-box; overflow: hidden;">
<!-- FILA 1: ESTUDIANTE Y MONTO --> <!-- FILA 1: ESTUDIANTE Y MONTO -->
<div style="display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; box-sizing: border-box; flex-wrap: wrap;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; box-sizing: border-box;">
<div style="display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1;"> <div style="display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1;">
<div style="width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1rem; border: 1.5px solid #bae6fd; flex-shrink: 0; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15);"> <div style="width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 0.95rem; border: 1.5px solid #bae6fd; flex-shrink: 0; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.15);">
${getStudentInitials(s.estudiante_nombre)} ${getStudentInitials(s.estudiante_nombre)}
</div> </div>
<div style="min-width: 0; flex: 1;"> <div style="min-width: 0; flex: 1;">
<div style="font-weight: 900; font-size: 1.05rem; color: #0f172a; line-height: 1.25; word-break: normal;"> <div style="font-weight: 900; font-size: 1rem; color: #0f172a; line-height: 1.2; word-break: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
${s.estudiante_nombre} ${s.estudiante_nombre}
</div> </div>
<div style="font-size: 0.78rem; color: #64748b; margin-top: 2px; font-weight: 600;"> <div style="font-size: 0.75rem; color: #64748b; margin-top: 1px; font-weight: 600;">
${s.estudiante_grado || 'Estudiante'} ${s.estudiante_seccion ? '• Sección ' + s.estudiante_seccion : ''} ${s.estudiante_grado || 'Estudiante'} ${s.estudiante_seccion ? '• Sec. ' + s.estudiante_seccion : ''}
</div> </div>
</div> </div>
</div> </div>
<div style="text-align: right; flex-shrink: 0;"> <div style="text-align: right; flex-shrink: 0;">
<div style="font-size: 1.35rem; font-weight: 900; color: #16a34a; letter-spacing: -0.5px; line-height: 1;"> <div style="font-size: 1.25rem; font-weight: 900; color: #16a34a; letter-spacing: -0.5px; line-height: 1;">
+₡${s.monto_colones.toLocaleString('es-CR')} +₡${s.monto_colones.toLocaleString('es-CR')}
</div> </div>
<div style="display: inline-block; font-size: 0.70rem; font-weight: 800; color: #b45309; background: #fef3c7; border: 1px solid #fde68a; padding: 2px 8px; border-radius: 6px; margin-top: 4px;"> <div style="display: inline-block; font-size: 0.68rem; font-weight: 800; color: #b45309; background: #fef3c7; border: 1px solid #fde68a; padding: 2px 6px; border-radius: 6px; margin-top: 3px;">
⏳ Por Verificar ⏳ Por Verificar
</div> </div>
</div> </div>
</div> </div>
<!-- FILA 2: DATOS DEL COMPROBANTE Y DETALLE EN CAJA HORIZONTAL --> <!-- FILA 2: DATOS DEL COMPROBANTE Y DETALLE -->
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 10px 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.82rem;"> <div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 0.80rem; box-sizing: border-box;">
<div style="display: flex; align-items: center; gap: 6px;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Código:</span> <div style="display: flex; align-items: center; gap: 5px;">
<span style="font-family: monospace; font-size: 0.95rem; font-weight: 900; color: #16a34a; background: #dcfce7; padding: 2px 8px; border-radius: 6px; border: 1px solid #bbf7d0;"> <span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase;">Código:</span>
${s.codigo_detalle || '-'} <span style="font-family: monospace; font-size: 0.88rem; font-weight: 900; color: #16a34a; background: #dcfce7; padding: 2px 7px; border-radius: 6px; border: 1px solid #bbf7d0;">
</span> ${s.codigo_detalle || '-'}
</span>
</div>
<div style="display: flex; align-items: center; gap: 5px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase;">Saldo:</span>
<span style="color: #334155; font-weight: 800; font-size: 0.82rem;">₡${(s.estudiante_saldo || 0).toLocaleString('es-CR')}</span>
</div>
</div> </div>
<div style="display: flex; align-items: center; gap: 6px;"> <div style="display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px dashed #e2e8f0; padding-top: 5px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Comprobante:</span> <div style="display: flex; align-items: center; gap: 5px; min-width: 0; flex: 1;">
<span style="font-family: monospace; font-size: 0.88rem; font-weight: 800; color: #0369a1; background: #e0f2fe; padding: 2px 8px; border-radius: 6px; border: 1px solid #bae6fd;"> <span style="color: #64748b; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; flex-shrink: 0;">Comp:</span>
#${s.comprobante_sinpe || '-'} <span style="font-family: monospace; font-size: 0.80rem; font-weight: 800; color: #0369a1; background: #e0f2fe; padding: 2px 6px; border-radius: 6px; border: 1px solid #bae6fd; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
</span> #${s.comprobante_sinpe || '-'}
</div> </span>
</div>
<div style="display: flex; align-items: center; gap: 6px;"> <div style="font-size: 0.73rem; color: #64748b; font-weight: 600; flex-shrink: 0;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Reportado:</span> ${fecha}
<span style="color: #334155; font-weight: 700;">${fecha}</span> </div>
</div>
<div style="display: flex; align-items: center; gap: 6px;">
<span style="color: #64748b; font-weight: 700; font-size: 0.75rem; text-transform: uppercase;">Saldo Actual:</span>
<span style="color: #334155; font-weight: 800;">₡${(s.estudiante_saldo || 0).toLocaleString('es-CR')}</span>
</div> </div>
</div> </div>
${s.notas ? ` ${s.notas ? `
<div style="font-size: 0.75rem; color: #475569; background: #ffffff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 6px 12px; display: flex; align-items: center; gap: 6px;"> <div style="font-size: 0.75rem; color: #475569; background: #ffffff; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 5px 10px; display: flex; align-items: center; gap: 6px; box-sizing: border-box; overflow: hidden;">
<span>💬</span> <span style="flex-shrink: 0;">💬</span>
<span><strong>Detalle:</strong> ${s.notas}</span> <span style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"><strong>Detalle:</strong> ${s.notas}</span>
</div> </div>
` : ''} ` : ''}
<!-- FILA 3: BOTONES DE ACCIÓN (RECHAZAR / APROBAR) --> <!-- FILA 3: BOTONES DE ACCIÓN (RECHAZAR / APROBAR) -->
<div style="display: flex; gap: 10px; align-items: center; width: 100%; border-top: 1px solid #f1f5f9; padding-top: 10px; box-sizing: border-box;"> <div style="display: flex; gap: 8px; align-items: center; width: 100%; border-top: 1px solid #f1f5f9; padding-top: 8px; box-sizing: border-box;">
<button type="button" onclick="procesarSinpePos(${s.id}, 'rechazar')" style="padding: 10px 16px; background: #fff1f2; color: #e11d48; border: 1.5px solid #fecdd3; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: all 0.15s;"> <button type="button" onclick="procesarSinpePos(${s.id}, 'rechazar')" style="flex: 0 0 auto; width: 95px; padding: 10px 8px; background: #fff1f2; color: #e11d48; border: 1.5px solid #fecdd3; border-radius: 10px; font-weight: 800; font-size: 0.82rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; box-sizing: border-box; transition: all 0.15s;">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
<span>Rechazar</span> <span>Rechazar</span>
</button> </button>
<button type="button" onclick="procesarSinpePos(${s.id}, 'aprobar')" style="flex: 1; padding: 11px 18px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.90rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25); white-space: nowrap; transition: all 0.15s;"> <button type="button" onclick="procesarSinpePos(${s.id}, 'aprobar')" style="flex: 1 1 0; min-width: 0; padding: 10px 8px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.86rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25); box-sizing: border-box; transition: all 0.15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg> <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" style="flex-shrink: 0;"><polyline points="20 6 9 17 4 12"/></svg>
<span>Aprobar y Acreditar (+₡${s.monto_colones.toLocaleString('es-CR')})</span> <span>Aprobar (+₡${s.monto_colones.toLocaleString('es-CR')})</span>
</button> </button>
</div> </div>
</div> </div>
+148 -5
View File
@@ -1,5 +1,6 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const { normalizarCodigoDetalle } = require('./sinpeParser');
try { try {
const envPath = path.join(__dirname, '../.env'); const envPath = path.join(__dirname, '../.env');
@@ -145,6 +146,27 @@ function initDatabase() {
`); `);
} catch (e) {} } catch (e) {}
try {
db.exec(`
CREATE TABLE IF NOT EXISTS sinpe_transacciones_banco (
id VARCHAR(100) PRIMARY KEY,
reference_number VARCHAR(100),
codigo_detalle VARCHAR(100),
codigo_detalle_norm VARCHAR(100),
amount_crc NUMERIC NOT NULL,
sender_phone VARCHAR(50),
sender_name VARCHAR(100),
origin_bank VARCHAR(100),
status VARCHAR(20) DEFAULT 'unclaimed',
claimed_by_estudiante_id INTEGER,
raw_data TEXT,
received_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
verified_at TIMESTAMP
);
`);
try { db.exec('ALTER TABLE solicitudes_recarga_sinpe ADD COLUMN IF NOT EXISTS codigo_detalle VARCHAR(100);'); } catch (_) {}
} catch (e) {}
try { try {
db.exec(` db.exec(`
CREATE TABLE IF NOT EXISTS push_subscriptions ( CREATE TABLE IF NOT EXISTS push_subscriptions (
@@ -345,6 +367,28 @@ function initDatabase() {
procesado_en DATETIME procesado_en DATETIME
); );
`); `);
try { db.exec('ALTER TABLE solicitudes_recarga_sinpe ADD COLUMN codigo_detalle TEXT;'); } catch (_) {}
} catch (e) {}
// 11b. Transacciones Bancarias SINPE Detectadas por Correo / IMAP
try {
db.exec(`
CREATE TABLE IF NOT EXISTS sinpe_transacciones_banco (
id TEXT PRIMARY KEY,
reference_number TEXT,
codigo_detalle TEXT,
codigo_detalle_norm TEXT,
amount_crc NUMERIC NOT NULL,
sender_phone TEXT,
sender_name TEXT,
origin_bank TEXT,
status TEXT DEFAULT 'unclaimed',
claimed_by_estudiante_id INTEGER,
raw_data TEXT,
received_at DATETIME DEFAULT CURRENT_TIMESTAMP,
verified_at DATETIME
);
`);
} catch (e) {} } catch (e) {}
// 12. Suscripciones Web Push (VAPID) para Alertas en Segundo Plano (App Cerrada) // 12. Suscripciones Web Push (VAPID) para Alertas en Segundo Plano (App Cerrada)
@@ -1100,31 +1144,127 @@ function revertirTransaccionSaldoTransaction({ transaccionId, usuarioId, usuario
return transaction(); return transaction();
} }
/**
* Genera un código de detalle amigable y tolerante: "SIBO-" + 4 caracteres anti-confusión
*/
function generarCodigoDetalleSinpe() {
const chars = '23456789ACDEFGHJKMNPQRSTUVWXYZ';
let rand = '';
for (let i = 0; i < 4; i++) {
rand += chars.charAt(Math.floor(Math.random() * chars.length));
}
return `SIBO-${rand}`;
}
/** /**
* Crea una nueva solicitud de recarga por SINPE Móvil enviada por un padre * Crea una nueva solicitud de recarga por SINPE Móvil enviada por un padre
*/ */
function crearSolicitudRecargaSinpe({ estudianteId, padreUsuarioId, monto, comprobante, notas }) { function crearSolicitudRecargaSinpe({ estudianteId, padreUsuarioId, monto, comprobante, notas, codigoDetalle }) {
let escuelaId = 1; let escuelaId = 1;
try { try {
const est = db.prepare('SELECT escuela_id FROM estudiantes WHERE id = ?').get(estudianteId); const est = db.prepare('SELECT escuela_id FROM estudiantes WHERE id = ?').get(estudianteId);
if (est && est.escuela_id) escuelaId = est.escuela_id; if (est && est.escuela_id) escuelaId = est.escuela_id;
} catch (e) {} } catch (e) {}
const finalCodigo = codigoDetalle || generarCodigoDetalleSinpe();
const finalComp = comprobante ? String(comprobante).trim() : `SINPE-${finalCodigo.replace(/[^A-Za-z0-9]/g, '')}`;
const insert = db.prepare(` const insert = db.prepare(`
INSERT INTO solicitudes_recarga_sinpe (estudiante_id, padre_usuario_id, monto_colones, comprobante_sinpe, estado, notas, escuela_id) INSERT INTO solicitudes_recarga_sinpe (estudiante_id, padre_usuario_id, monto_colones, comprobante_sinpe, codigo_detalle, estado, notas, escuela_id)
VALUES (?, ?, ?, ?, 'pendiente', ?, ?) VALUES (?, ?, ?, ?, ?, 'pendiente', ?, ?)
`); `);
const res = insert.run(estudianteId, padreUsuarioId || null, parseInt(monto, 10), String(comprobante).trim(), notas || '', escuelaId); const res = insert.run(estudianteId, padreUsuarioId || null, parseInt(monto, 10), finalComp, finalCodigo, notas || '', escuelaId);
return { return {
id: res.lastInsertRowid || res.id, id: res.lastInsertRowid || res.id,
estudiante_id: estudianteId, estudiante_id: estudianteId,
escuela_id: escuelaId, escuela_id: escuelaId,
monto_colones: parseInt(monto, 10), monto_colones: parseInt(monto, 10),
comprobante_sinpe: String(comprobante).trim(), comprobante_sinpe: finalComp,
codigo_detalle: finalCodigo,
estado: 'pendiente' estado: 'pendiente'
}; };
} }
/**
* Busca una transacción bancaria capturada por IMAP/correo para validar la recarga
*/
function buscarTransaccionSinpeBanco({ codigoDetalle, comprobante, monto }) {
const normCod = codigoDetalle ? normalizarCodigoDetalle(codigoDetalle) : null;
const cleanComp = comprobante ? String(comprobante).trim().replace(/^[#:\.\-\s]+/, '') : null;
const numMonto = parseInt(monto, 10);
// 1. Búsqueda por código de detalle normalizado (máxima prioridad)
if (normCod && normCod.length >= 4) {
let tx = db.prepare(`
SELECT * FROM sinpe_transacciones_banco
WHERE (codigo_detalle_norm = ? OR UPPER(REPLACE(REPLACE(codigo_detalle, '-', ''), ' ', '')) = ?)
AND status = 'unclaimed'
ORDER BY received_at DESC
LIMIT 1
`).get(normCod, normCod);
if (tx) {
if (numMonto && Math.abs(Number(tx.amount_crc) - numMonto) > 0.01) {
return { error: 'MONTO_DISCREPANCIA', tx, mensaje: `El comprobante bancario corresponde a ₡${Number(tx.amount_crc).toLocaleString('es-CR')}, pero la recarga solicitada es por ₡${numMonto.toLocaleString('es-CR')}.` };
}
return { encontrado: true, tx };
}
}
// 2. Búsqueda por número de comprobante emitido por el banco
if (cleanComp && cleanComp.length >= 3) {
let tx = db.prepare(`
SELECT * FROM sinpe_transacciones_banco
WHERE (reference_number = ? OR reference_number LIKE ?)
AND status = 'unclaimed'
ORDER BY received_at DESC
LIMIT 1
`).get(cleanComp, `%${cleanComp}%`);
if (tx) {
if (numMonto && Math.abs(Number(tx.amount_crc) - numMonto) > 0.01) {
return { error: 'MONTO_DISCREPANCIA', tx, mensaje: `El comprobante bancario corresponde a ₡${Number(tx.amount_crc).toLocaleString('es-CR')}, pero la recarga solicitada es por ₡${numMonto.toLocaleString('es-CR')}.` };
}
return { encontrado: true, tx };
}
}
// 3. Verificar si el código o comprobante ya fue usado previamente (anti-fraude)
if (normCod) {
const used = db.prepare(`
SELECT * FROM sinpe_transacciones_banco
WHERE codigo_detalle_norm = ? AND status = 'used'
LIMIT 1
`).get(normCod);
if (used) {
return { error: 'COMPROBANTE_YA_UTILIZADO', mensaje: `Este código de detalle ya fue utilizado anteriormente y no es válido para otra recarga.` };
}
} else if (cleanComp) {
const used = db.prepare(`
SELECT * FROM sinpe_transacciones_banco
WHERE reference_number = ? AND status = 'used'
LIMIT 1
`).get(cleanComp);
if (used) {
return { error: 'COMPROBANTE_YA_UTILIZADO', mensaje: `Este comprobante bancario ya fue utilizado anteriormente y no es válido para otra recarga.` };
}
}
return { encontrado: false };
}
function marcarTransaccionSinpeUsada(txId, estudianteId) {
return db.prepare(`
UPDATE sinpe_transacciones_banco
SET status = 'used',
claimed_by_estudiante_id = ?,
verified_at = CURRENT_TIMESTAMP
WHERE id = ?
`).run(estudianteId || null, txId);
}
/** /**
* Obtiene las solicitudes de recarga SINPE (con datos del estudiante y escuela) * Obtiene las solicitudes de recarga SINPE (con datos del estudiante y escuela)
*/ */
@@ -1271,7 +1411,10 @@ module.exports = {
crearOrdenCompleta, crearOrdenCompleta,
transferenciaP2PTransaction, transferenciaP2PTransaction,
revertirTransaccionSaldoTransaction, revertirTransaccionSaldoTransaction,
generarCodigoDetalleSinpe,
crearSolicitudRecargaSinpe, crearSolicitudRecargaSinpe,
buscarTransaccionSinpeBanco,
marcarTransaccionSinpeUsada,
obtenerSolicitudesRecargaSinpe, obtenerSolicitudesRecargaSinpe,
obtenerSolicitudesRecargaPorEstudiante, obtenerSolicitudesRecargaPorEstudiante,
procesarSolicitudRecargaSinpe, procesarSolicitudRecargaSinpe,
+290 -6
View File
@@ -18,7 +18,10 @@ const {
crearOrdenCompleta, crearOrdenCompleta,
transferenciaP2PTransaction, transferenciaP2PTransaction,
revertirTransaccionSaldoTransaction, revertirTransaccionSaldoTransaction,
generarCodigoDetalleSinpe,
crearSolicitudRecargaSinpe, crearSolicitudRecargaSinpe,
buscarTransaccionSinpeBanco,
marcarTransaccionSinpeUsada,
obtenerSolicitudesRecargaSinpe, obtenerSolicitudesRecargaSinpe,
obtenerSolicitudesRecargaPorEstudiante, obtenerSolicitudesRecargaPorEstudiante,
procesarSolicitudRecargaSinpe, procesarSolicitudRecargaSinpe,
@@ -26,6 +29,9 @@ const {
obtenerSuscripcionesPush, obtenerSuscripcionesPush,
eliminarSuscripcionPush eliminarSuscripcionPush
} = require('./db'); } = require('./db');
const { checkSinpeEmailsOnce, simularSinpeEmail } = require('./sinpeImapService');
const { normalizarCodigoDetalle, parseSinpeEmail } = require('./sinpeParser');
const { simpleParser } = require('mailparser');
const webpush = require('web-push'); const webpush = require('web-push');
@@ -1712,25 +1718,62 @@ app.post('/api/estudiantes/:id/recarga', (req, res) => {
// SOLICITUDES DE RECARGA SINPE MÓVIL (PORTAL PADRES & SODA) // SOLICITUDES DE RECARGA SINPE MÓVIL (PORTAL PADRES & SODA)
// ========================================== // ==========================================
// 0. Generar código de detalle único para recarga SINPE
app.post('/api/sinpe/generar-codigo', (req, res) => {
try {
const { estudiante_id, monto } = req.body;
const codigo = generarCodigoDetalleSinpe();
let telefono_sinpe = '8888-8888';
let titular_sinpe = 'Soda Escolar';
let escuela_nombre = 'Soda Escolar';
if (estudiante_id) {
const est = db.prepare(`
SELECT e.id, esc.telefono_sinpe, esc.nombre_sinpe, esc.nombre as escuela_nombre
FROM estudiantes e
LEFT JOIN escuelas esc ON esc.id = e.escuela_id
WHERE e.id = ?
`).get(estudiante_id);
if (est) {
if (est.telefono_sinpe) telefono_sinpe = est.telefono_sinpe;
if (est.nombre_sinpe) titular_sinpe = est.nombre_sinpe;
if (est.escuela_nombre) escuela_nombre = est.escuela_nombre;
}
}
res.json({
success: true,
codigo,
telefono_sinpe,
titular_sinpe,
escuela_nombre
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// 1. Crear solicitud de recarga (enviada por el padre) // 1. Crear solicitud de recarga (enviada por el padre)
app.post('/api/sinpe/solicitar', (req, res) => { app.post('/api/sinpe/solicitar', (req, res) => {
try { try {
const { estudiante_id, padre_usuario_id, monto, comprobante, notas } = req.body; const { estudiante_id, padre_usuario_id, monto, comprobante, codigo_detalle, notas } = req.body;
if (!estudiante_id) return res.status(400).json({ error: 'Estudiante no especificado' }); if (!estudiante_id) return res.status(400).json({ error: 'Estudiante no especificado' });
const montoNum = parseInt(monto, 10); const montoNum = parseInt(monto, 10);
if (isNaN(montoNum) || montoNum <= 0) { if (isNaN(montoNum) || montoNum <= 0) {
return res.status(400).json({ error: 'Ingresa un monto válido mayor a ₡0' }); return res.status(400).json({ error: 'Ingresa un monto válido mayor a ₡0' });
} }
const cleanComp = String(comprobante || '').trim(); const cleanComp = String(comprobante || '').trim();
if (!cleanComp) { const cleanCod = codigo_detalle ? String(codigo_detalle).trim() : null;
return res.status(400).json({ error: 'Debes ingresar el número de comprobante SINPE' }); if (!cleanComp && !cleanCod) {
return res.status(400).json({ error: 'Debes ingresar el comprobante o código de detalle SINPE' });
} }
const nuevaSol = crearSolicitudRecargaSinpe({ const nuevaSol = crearSolicitudRecargaSinpe({
estudianteId: parseInt(estudiante_id, 10), estudianteId: parseInt(estudiante_id, 10),
padreUsuarioId: padre_usuario_id ? parseInt(padre_usuario_id, 10) : null, padreUsuarioId: padre_usuario_id ? parseInt(padre_usuario_id, 10) : null,
monto: montoNum, monto: montoNum,
comprobante: cleanComp, comprobante: cleanComp || (cleanCod ? `SINPE-${cleanCod}` : ''),
codigoDetalle: cleanCod,
notas notas
}); });
@@ -1752,7 +1795,7 @@ app.post('/api/sinpe/solicitar', (req, res) => {
escuelaId: nuevaSol.escuela_id || 1, escuelaId: nuevaSol.escuela_id || 1,
payload: { payload: {
title: '🔔 Nueva Recarga SINPE - SiboPay', title: '🔔 Nueva Recarga SINPE - SiboPay',
body: `Recarga de ₡${montoFmt} para ${payloadNotificacion.estudiante_nombre}. Comprobante: #${payloadNotificacion.comprobante_sinpe}`, body: `Recarga de ₡${montoFmt} para ${payloadNotificacion.estudiante_nombre}. Detalle: ${payloadNotificacion.codigo_detalle || payloadNotificacion.comprobante_sinpe}`,
icon: '/icons/icon-192.png', icon: '/icons/icon-192.png',
badge: '/icons/icon-192.png', badge: '/icons/icon-192.png',
tag: `sinpe-${payloadNotificacion.id || Date.now()}`, tag: `sinpe-${payloadNotificacion.id || Date.now()}`,
@@ -1762,7 +1805,7 @@ app.post('/api/sinpe/solicitar', (req, res) => {
res.json({ res.json({
success: true, success: true,
mensaje: 'Solicitud de recarga enviada. La soda verificará el comprobante en breve.', mensaje: 'Solicitud de recarga enviada.',
solicitud: payloadNotificacion solicitud: payloadNotificacion
}); });
} catch (error) { } catch (error) {
@@ -1770,6 +1813,247 @@ app.post('/api/sinpe/solicitar', (req, res) => {
} }
}); });
// 1b. Validar SINPE en tiempo real por correo bancario
app.post('/api/sinpe/validar', async (req, res) => {
try {
const { estudiante_id, monto, codigo, comprobante, solicitud_id, padre_usuario_id } = req.body;
if (!estudiante_id) return res.status(400).json({ error: 'Estudiante no especificado' });
const montoNum = parseInt(monto, 10);
if (isNaN(montoNum) || montoNum <= 0) {
return res.status(400).json({ error: 'Ingresa un monto válido mayor a ₡0' });
}
const cleanCod = codigo ? String(codigo).trim() : null;
const cleanComp = comprobante ? String(comprobante).trim() : null;
if (!cleanCod && !cleanComp) {
return res.status(400).json({ error: 'Se requiere el código de detalle (ej. SIBO-XXXX) o el número de comprobante para validar.' });
}
// 1. Escaneo en caliente del buzón IMAP (si está configurado)
try {
await checkSinpeEmailsOnce(db);
} catch (scanErr) {
console.warn('⚠️ [SINPE Validar] Error en escaneo IMAP caliente:', scanErr.message);
}
// 2. Buscar en las transacciones registradas
const busqueda = buscarTransaccionSinpeBanco({
codigoDetalle: cleanCod,
comprobante: cleanComp,
monto: montoNum
});
if (busqueda.error) {
return res.status(400).json({
success: false,
verificado: false,
error: busqueda.error,
message: busqueda.mensaje
});
}
if (busqueda.encontrado && busqueda.tx) {
const tx = busqueda.tx;
marcarTransaccionSinpeUsada(tx.id, estudiante_id);
let resultadoAprobacion = null;
if (solicitud_id) {
try {
resultadoAprobacion = procesarSolicitudRecargaSinpe({
solicitudId: parseInt(solicitud_id, 10),
accion: 'aprobar',
usuarioId: null,
motivo: `Validación automática por correo (${tx.origin_bank} - Ref #${tx.reference_number || tx.codigo_detalle})`
});
} catch (_) {}
}
if (!resultadoAprobacion) {
resultadoAprobacion = recargaSaldoTransaction({
estudianteId: parseInt(estudiante_id, 10),
monto: montoNum,
comprobanteSinpe: tx.reference_number || cleanComp || tx.codigo_detalle,
descripcion: `Recarga SINPE verificada automáticamente por correo (${tx.origin_bank} Ref #${tx.reference_number || tx.codigo_detalle})`
});
}
const est = db.prepare('SELECT nombre_completo, saldo_colones FROM estudiantes WHERE id = ?').get(estudiante_id);
const nuevoSaldo = est ? est.saldo_colones : (resultadoAprobacion.saldo_nuevo || montoNum);
broadcastEvent('recarga_exitosa', {
estudiante_id,
monto: montoNum,
saldo_nuevo: nuevoSaldo,
origen_banco: tx.origin_bank,
referencia: tx.reference_number
});
broadcastEvent('saldo_actualizado', { id: estudiante_id, saldo_colones: nuevoSaldo });
broadcastEvent('estudiante_actualizado', { id: estudiante_id, saldo_colones: nuevoSaldo });
console.log(`🎉 [SINPE Validado] ₡${montoNum} acreditados a estudiante #${estudiante_id} vía ${tx.origin_bank} (Ref #${tx.reference_number})`);
return res.json({
success: true,
verificado: true,
monto: montoNum,
banco: tx.origin_bank,
comprobante: tx.reference_number,
codigo: tx.codigo_detalle,
saldo_nuevo: nuevoSaldo,
mensaje: `🎉 ¡Pago verificado con éxito! Se acreditaron ₡${montoNum.toLocaleString('es-CR')} de ${tx.origin_bank}.`
});
}
// Si aún no se detectó el correo
return res.json({
success: false,
verificado: false,
retry: true,
mensaje: `⏳ Aún no detectamos la notificación del banco en el correo. Si acabas de realizar la transferencia, espera unos 10-15 segundos a que el banco emita el comprobante y presiona "Validar SINPE" nuevamente.`
});
} catch (error) {
console.error('Error en /api/sinpe/validar:', error);
res.status(500).json({ error: error.message });
}
});
// 1c. Simular correo bancario entrante (para pruebas y demos)
app.post('/api/sinpe/simular-correo', (req, res) => {
try {
const { codigo, monto, banco, remitente, telefono, comprobante } = req.body;
if (!monto) return res.status(400).json({ error: 'Monto es requerido' });
const tx = simularSinpeEmail(db, { codigo, monto, banco, remitente, telefono, comprobante });
res.json({ success: true, mensaje: 'Transacción simulada registrada exitosamente', tx });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// 1d. Webhook receptor en el aire para Cloudflare Email Routing / Worker
app.post('/api/sinpe/webhook-email', express.text({ type: ['text/*', 'application/json', '*/*'], limit: '25mb' }), async (req, res) => {
try {
const rawData = req.body;
let subject = '';
let bodyText = '';
let bodyHtml = '';
let from = '';
if (typeof rawData === 'string') {
try {
const parsed = await simpleParser(rawData);
subject = parsed.subject || '';
bodyText = parsed.text || '';
bodyHtml = parsed.html || '';
from = parsed.from ? parsed.from.text : '';
} catch (e) {
bodyText = rawData;
}
if (!bodyText && !bodyHtml) {
bodyText = rawData;
} else {
bodyText = `${bodyText}\n${rawData}`;
}
} else if (typeof rawData === 'object' && rawData !== null) {
subject = rawData.subject || '';
bodyText = rawData.text || rawData.body || '';
from = rawData.from || '';
}
const parsedSinpe = parseSinpeEmail(subject, bodyText, bodyHtml, from);
if (parsedSinpe.isSinpe && parsedSinpe.amountCrc > 0) {
const txId = `sinpe_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
const normCod = parsedSinpe.codigoDetalleNormalizado || '';
const refNum = parsedSinpe.referenceNumber || (normCod ? `REF-${normCod}` : `TX-${Date.now()}`);
// Evitar duplicados exactos: solo si el código ya fue recibido previamente
const existing = db.prepare(`
SELECT id FROM sinpe_transacciones_banco
WHERE (codigo_detalle_norm = ? AND codigo_detalle_norm IS NOT NULL AND codigo_detalle_norm != '')
OR (reference_number = ? AND reference_number IS NOT NULL AND codigo_detalle_norm = ?)
LIMIT 1
`).get(normCod || '__none__', refNum, normCod || '__none__');
if (!existing) {
db.prepare(`
INSERT INTO sinpe_transacciones_banco
(id, reference_number, codigo_detalle, codigo_detalle_norm, amount_crc, sender_phone, sender_name, origin_bank, status, raw_data)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, 'unclaimed', ?)
`).run(
txId,
refNum,
parsedSinpe.codigoDetalle || null,
normCod || null,
parsedSinpe.amountCrc,
parsedSinpe.senderPhone || null,
parsedSinpe.senderName || 'Cliente SINPE',
parsedSinpe.originBank || 'SINPE Móvil',
JSON.stringify({ from, subject, summary: parsedSinpe.rawSummary, source: 'cloudflare_webhook' })
);
console.log(`⚡ [SINPE Webhook Cloudflare] Correo atrapado en el aire: ₡${parsedSinpe.amountCrc} | Cód: ${parsedSinpe.codigoDetalle || 'N/A'} | Ref: #${refNum} | Banco: ${parsedSinpe.originBank}`);
// AUTO-CONCILIACIÓN INMEDIATA:
// Si hay una solicitud pendiente con este código y monto, aprobarla al instante
if (normCod || refNum) {
try {
const solPendiente = db.prepare(`
SELECT id, estudiante_id, monto_colones, codigo_detalle, comprobante_sinpe
FROM solicitudes_recarga_sinpe
WHERE estado = 'pendiente'
AND (
(codigo_detalle IS NOT NULL AND (codigo_detalle = ? OR UPPER(REPLACE(REPLACE(codigo_detalle, '-', ''), ' ', '')) = ?))
OR (comprobante_sinpe IS NOT NULL AND (comprobante_sinpe = ? OR comprobante_sinpe = ? OR comprobante_sinpe LIKE ?))
)
ORDER BY creado_en DESC LIMIT 1
`).get(
parsedSinpe.codigoDetalle || '__none__',
normCod || '__none__',
refNum,
`SINPE-${parsedSinpe.codigoDetalle}`,
`%${refNum}%`
);
if (solPendiente && Math.abs(Number(solPendiente.monto_colones) - parsedSinpe.amountCrc) < 0.01) {
marcarTransaccionSinpeUsada(txId, solPendiente.estudiante_id);
procesarSolicitudRecargaSinpe({
solicitudId: solPendiente.id,
accion: 'aprobar',
usuarioId: null,
motivo: `Validación automática por correo (${parsedSinpe.originBank} Ref #${refNum})`
});
const est = db.prepare('SELECT saldo_colones FROM estudiantes WHERE id = ?').get(solPendiente.estudiante_id);
const nuevoSaldo = est ? est.saldo_colones : parsedSinpe.amountCrc;
broadcastEvent('recarga_exitosa', {
estudiante_id: solPendiente.estudiante_id,
monto: parsedSinpe.amountCrc,
saldo_nuevo: nuevoSaldo,
origen_banco: parsedSinpe.originBank,
referencia: refNum
});
broadcastEvent('saldo_actualizado', { id: solPendiente.estudiante_id, saldo_colones: nuevoSaldo });
broadcastEvent('estudiante_actualizado', { id: solPendiente.estudiante_id, saldo_colones: nuevoSaldo });
broadcastEvent('solicitud_sinpe_procesada', { id: solPendiente.id, estado: 'aprobada' });
console.log(`🎉 [SINPE Auto-Conciliado] Solicitud #${solPendiente.id} aprobada automáticamente al llegar el correo bancario (+₡${parsedSinpe.amountCrc} a estudiante #${solPendiente.estudiante_id})`);
}
} catch (autoErr) {
console.warn('⚠️ Error en auto-conciliación de webhook:', autoErr.message);
}
}
}
}
res.json({ success: true, parsed: parsedSinpe });
} catch (error) {
console.error('Error en /api/sinpe/webhook-email:', error);
res.status(500).json({ error: error.message });
}
});
// 2. Listar solicitudes (para la soda/admin) // 2. Listar solicitudes (para la soda/admin)
app.get('/api/sinpe/solicitudes', (req, res) => { app.get('/api/sinpe/solicitudes', (req, res) => {
try { try {