commit inicial
This commit is contained in:
13
.dockerignore
Normal file
13
.dockerignore
Normal file
@@ -0,0 +1,13 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
yarn-debug.log
|
||||
yarn-error.log
|
||||
.git
|
||||
.gitignore
|
||||
.dockerignore
|
||||
Dockerfile
|
||||
.env
|
||||
.env.*
|
||||
.vscode
|
||||
.idea
|
||||
README.md
|
||||
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# Logs
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# IDEs and OS files
|
||||
.idea/
|
||||
.vscode/
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
# Use the official Node.js 20 lightweight Alpine image as the base
|
||||
FROM node:20-alpine
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy dependency manifests
|
||||
COPY package.json yarn.lock ./
|
||||
|
||||
# Install dependencies (using --frozen-lockfile to guarantee exact versions from yarn.lock)
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# Copy the rest of the application code
|
||||
COPY . .
|
||||
|
||||
# Expose the port that the API server listens on (default is 3150)
|
||||
EXPOSE 3150
|
||||
|
||||
# Set environment variables
|
||||
ENV NODE_ENV=production
|
||||
|
||||
# By default, run the API server.
|
||||
# To run the cron process, you can override the CMD at runtime: docker run <image> node src/cronIndex.js
|
||||
CMD [ "node", "src/apiIndex.js" ]
|
||||
BIN
otros/codigos_ubigeo.xlsx
Normal file
BIN
otros/codigos_ubigeo.xlsx
Normal file
Binary file not shown.
33
package.json
Normal file
33
package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "uc",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "nodemon ./src/apiIndex.js",
|
||||
"cron": "nodemon ./src/cronIndex.js"
|
||||
},
|
||||
"type": "module",
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"date-fns": "^3.3.1",
|
||||
"date-fns-tz": "^2.0.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"moment": "^2.30.1",
|
||||
"moment-timezone": "^0.5.44",
|
||||
"morgan": "^1.10.0",
|
||||
"mysql2": "^3.6.5",
|
||||
"node-cron": "^3.0.3",
|
||||
"node-fetch": "^3.3.2",
|
||||
"nodemon": "^3.0.2",
|
||||
"sequelize": "^6.35.2",
|
||||
"swagger-jsdoc": "^6.2.8",
|
||||
"swagger-ui-express": "^5.0.0",
|
||||
"winston": "^3.11.0"
|
||||
}
|
||||
}
|
||||
73
src/apiIndex.js
Normal file
73
src/apiIndex.js
Normal file
@@ -0,0 +1,73 @@
|
||||
import dotenv from 'dotenv';
|
||||
import express, { json } from 'express';
|
||||
import cors from 'cors';
|
||||
import morgan from 'morgan';
|
||||
import winston from 'winston';
|
||||
import { swaggerSpec, swaggerUI } from '../swagger.js'; // Importa la configuración de Swagger
|
||||
import https from 'https';
|
||||
import v1Router from './v1/routes/index.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3150;
|
||||
|
||||
// Configuración de Winston para el logging
|
||||
const logger = winston.createLogger({
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.File({ filename: 'api.log' })
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
// Middlewares
|
||||
app.use(morgan('combined', { stream: { write: message => logger.info(message.trim()) } }));
|
||||
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerSpec));
|
||||
|
||||
app.use(json());
|
||||
app.use(cors({
|
||||
origin: ['*'],
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
|
||||
allowedHeaders: ['Content-Type', 'Authorization', 'x-access-token'],
|
||||
}));
|
||||
|
||||
// Rutas
|
||||
app.use("/api/v1/guias", v1Router);
|
||||
|
||||
// Manejador de errores
|
||||
app.use((error, req, res, next) => {
|
||||
logger.error(error.message);
|
||||
res.status(500).json({ mensaje: error.message || 'Error interno del servidor' });
|
||||
});
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const privateKeyPath = path.join(__dirname, 'certificados', 'privateKey.key');
|
||||
const certPath = path.join(__dirname, 'certificados', 'certificado.crt');
|
||||
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync(privateKeyPath),
|
||||
cert: fs.readFileSync(certPath)
|
||||
};
|
||||
|
||||
|
||||
const server = https.createServer(httpsOptions, app);
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Excecuting on port ${port}`)
|
||||
})
|
||||
|
||||
|
||||
// Iniciar el servidor
|
||||
// app.listen(port, () => {
|
||||
// console.log(`Excecuting Server on port ${port}`);
|
||||
// });
|
||||
60
src/certificados/certificado.crt
Normal file
60
src/certificados/certificado.crt
Normal file
@@ -0,0 +1,60 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIE/DCCA+SgAwIBAgISBHsV0eMgVVb6w9yJeUIsAHWzMA0GCSqGSIb3DQEBCwUA
|
||||
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
|
||||
EwJSMzAeFw0yNDAzMDYxNzE3MTNaFw0yNDA2MDQxNzE3MTJaMCIxIDAeBgNVBAMT
|
||||
F3dzLWFwaS5jYXRvbGljYS5zaWFsLmNsMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
|
||||
MIIBCgKCAQEAhpblspKKXYj5pkJt1fq2KLAgVsojq06fpzUXLBofdQvIZXimXuQI
|
||||
CpyzEQNupxmBvaIa6+u2mIU+X4N4F0IMZbbIZkhb2tzLRDgPlKms01ChCG1e8P+V
|
||||
9/88+CNBChLODrpdjFZhWr8iuyRpfnc8Z1sGGJpqfy3QlykiAPHRyWX/C7scLykg
|
||||
Sbvm5FB2NA2fka2E2MugRTFuL58v2POQ4VfC5ilDNdUbS5SjNcp0ZQIDcERQiaR7
|
||||
ZmdtWZ9KRjDfdhTXeY+gkAHGC2qblJyCz1TYIvme0zkyoXWiQxCeCFgTq4//UBtA
|
||||
1NrV2KweP8ztFQOVePzhvQg8QVReCDZoUwIDAQABo4ICGjCCAhYwDgYDVR0PAQH/
|
||||
BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8E
|
||||
AjAAMB0GA1UdDgQWBBSL8BMaV5muVX11/Zt2x9lZxZvZ1TAfBgNVHSMEGDAWgBQU
|
||||
LrMXt1hWy65QCUDmH6+dixTCxjBVBggrBgEFBQcBAQRJMEcwIQYIKwYBBQUHMAGG
|
||||
FWh0dHA6Ly9yMy5vLmxlbmNyLm9yZzAiBggrBgEFBQcwAoYWaHR0cDovL3IzLmku
|
||||
bGVuY3Iub3JnLzAiBgNVHREEGzAZghd3cy1hcGkuY2F0b2xpY2Euc2lhbC5jbDAT
|
||||
BgNVHSAEDDAKMAgGBmeBDAECATCCAQUGCisGAQQB1nkCBAIEgfYEgfMA8QB3AEiw
|
||||
42vapkc0D+VqAvqdMOscUgHLVt0sgdm7v6s52IRzAAABjhT72ugAAAQDAEgwRgIh
|
||||
ALgZcElG+WObTY4PtnshKirY85359FzxtX7oOEutXbXrAiEA+7Pe2hNWWjOVVy9G
|
||||
O41co802R+DHCbvRL3iGdU9yezoAdgCi4r/WHt4vLweg1k5tN6fcZUOwxrUuotq3
|
||||
iviabfUX2AAAAY4U+9sLAAAEAwBHMEUCIHVyWgfvBa7/G1w7kCuL90sBC0U7IQb+
|
||||
2DWWGam9MaMVAiEA+4uonnOGe0YmhBOXI+xFUvYooDHh3bBtqjRZmrCa8jYwDQYJ
|
||||
KoZIhvcNAQELBQADggEBAKI0cK+PPO/oYi8PGcY54CaWE+ajVcdhUzsJJxDQgtFe
|
||||
JGcA39qXAwtto7TzPNOfP2ah/NThLw1Zx+83H2os4gbQQbP1LCx2r0B9vUlHRfrt
|
||||
NYyFMCpqcH5imdTo3/fD4N0CGMM5/6JwwQbNFm+dLu/pArlawpuL5f+RsTeXW2sV
|
||||
WumNXHkvz1x4mgUOvuWGgQNDnkpY371RfKNJDxn2/WjkIrl5YRIaT26lzT3WSROq
|
||||
RiSeaHwThkqtvf8nRByo/IasuJns0JzrW4DnX4p+U1aQXkyQ0JSB/fVWpLeNHtsA
|
||||
XSaHunMNKWTch4fAuP8dRp/yZ7XMKmNCPg3/3d7gHpc=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw
|
||||
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
||||
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMjAwOTA0MDAwMDAw
|
||||
WhcNMjUwOTE1MTYwMDAwWjAyMQswCQYDVQQGEwJVUzEWMBQGA1UEChMNTGV0J3Mg
|
||||
RW5jcnlwdDELMAkGA1UEAxMCUjMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||
AoIBAQC7AhUozPaglNMPEuyNVZLD+ILxmaZ6QoinXSaqtSu5xUyxr45r+XXIo9cP
|
||||
R5QUVTVXjJ6oojkZ9YI8QqlObvU7wy7bjcCwXPNZOOftz2nwWgsbvsCUJCWH+jdx
|
||||
sxPnHKzhm+/b5DtFUkWWqcFTzjTIUu61ru2P3mBw4qVUq7ZtDpelQDRrK9O8Zutm
|
||||
NHz6a4uPVymZ+DAXXbpyb/uBxa3Shlg9F8fnCbvxK/eG3MHacV3URuPMrSXBiLxg
|
||||
Z3Vms/EY96Jc5lP/Ooi2R6X/ExjqmAl3P51T+c8B5fWmcBcUr2Ok/5mzk53cU6cG
|
||||
/kiFHaFpriV1uxPMUgP17VGhi9sVAgMBAAGjggEIMIIBBDAOBgNVHQ8BAf8EBAMC
|
||||
AYYwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMBMBIGA1UdEwEB/wQIMAYB
|
||||
Af8CAQAwHQYDVR0OBBYEFBQusxe3WFbLrlAJQOYfr52LFMLGMB8GA1UdIwQYMBaA
|
||||
FHm0WeZ7tuXkAXOACIjIGlj26ZtuMDIGCCsGAQUFBwEBBCYwJDAiBggrBgEFBQcw
|
||||
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
|
||||
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
|
||||
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
|
||||
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
|
||||
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
|
||||
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
|
||||
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
|
||||
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
|
||||
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
|
||||
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
|
||||
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
|
||||
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
|
||||
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
|
||||
nLRbwHOoq7hHwg==
|
||||
-----END CERTIFICATE-----
|
||||
28
src/certificados/privateKey.key
Normal file
28
src/certificados/privateKey.key
Normal file
@@ -0,0 +1,28 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCGluWykopdiPmm
|
||||
Qm3V+rYosCBWyiOrTp+nNRcsGh91C8hleKZe5AgKnLMRA26nGYG9ohrr67aYhT5f
|
||||
g3gXQgxltshmSFva3MtEOA+UqazTUKEIbV7w/5X3/zz4I0EKEs4Oul2MVmFavyK7
|
||||
JGl+dzxnWwYYmmp/LdCXKSIA8dHJZf8LuxwvKSBJu+bkUHY0DZ+RrYTYy6BFMW4v
|
||||
ny/Y85DhV8LmKUM11RtLlKM1ynRlAgNwRFCJpHtmZ21Zn0pGMN92FNd5j6CQAcYL
|
||||
apuUnILPVNgi+Z7TOTKhdaJDEJ4IWBOrj/9QG0DU2tXYrB4/zO0VA5V4/OG9CDxB
|
||||
VF4INmhTAgMBAAECggEACGbFAeep4Xracql058WVt2Z/LkvB/ECVML/cqXEcA5dv
|
||||
s/3bDNNZOShc+TPopV+vPKIw4gc9x7mRki7HwVPrKDJHwjLEIR5lReXl+xa4ZhyD
|
||||
YN5K7epWdzukl6zDs5hG6p5xloAR5bNGvL3iI/XXfHAvKjwBZ9z5R2ZW7A4sVVEE
|
||||
dNzXzrD6Rlme7UQmZcKoL5qGzWSAPYSvlP00n63d7Z2gtSnX5k8dKaeP49GN0sFw
|
||||
fbh0KzPmdCfz7X7kmevcsLmEdSYCoBrJ2PW+8cUu/yGpLUMvF9WrmyPKLxHX8G4K
|
||||
WDZWuQSQtx1GU+Y5C7WPkiJwh7H9twIvj9PW1kdCkQKBgQC7aLHcKHdP2taU95bh
|
||||
LrTRFAAYx1ZBtuspZRTcOUHB9ZYUq5KbuDc9pPV0cPym6Zg1VOxA8zmZJbL3V4GZ
|
||||
mDYJsfZQjqK+QzFWhhn8RhPohoa614fC+wscpsbozKyMXKa3Mf7+QxAWo376L/DS
|
||||
7ZhpyKuo5VXsVaRrIfV/YZHP+QKBgQC32UVoGqt/ADRmNN7mEBtMIMT88AYRpe7X
|
||||
3bO2wIQ29IuIIgYpU8CQ8ltA1FuPgxgAmJAS3O/RSoEEl389nP4dAP456DSMUBrX
|
||||
idiLUAcFhUZ9+uLpfCUcH6Pw6fe/rbJQYb6gWR5Uc7C/HQbTzfF53kVcJFvXXgJ5
|
||||
k8zWYi2lqwKBgDzAgq/I2myjl14xKNMUrf79Cc7+h6LD5lXD89A0K3Hx59YJjHw4
|
||||
aofsOrmlivGc1f+r6O5hKnHP+8Ucs+GTqyjXbO7OXklpRMw0qqXSHdAKFBDrn5IA
|
||||
iaifE+oRt3nE6zKF3ZCVMtjz5Uy7T8lAxmC8cZFNzt3PIX6tQoUpnvgZAoGAZYim
|
||||
3kGsaO1SAwg7+c73ZGnMoOxmTaTYbXtRXyKfYkJYNQylXnmUpfhTEVC2aGG8Bcg7
|
||||
+U7vWyTMcB7C9OIZLSd5P73QF5W93T+Ryg6echwSvEysuMoJLKkEv25XlxJ0ohP5
|
||||
VVEigP2LpWCAfsUEEYwBvkuONTkEIOTRgayjDRUCgYA+2OUrH7AuhIKEfR+ckXqQ
|
||||
/kBDNhz0ZS73BAAdRQiYiNO350m6m6C5kUEexeH4A8HzWQh4zvr28goMnYE6qrJA
|
||||
CYeHRObfWjfVAs0gEJy8e9z5ohAOFog8Yh/y/WWN8UW72+1SvxUw5gOPo5DCwuL/
|
||||
lExkIN6WrdGmTu6SzCzKug==
|
||||
-----END PRIVATE KEY-----
|
||||
31
src/controllers/guiasController.js
Normal file
31
src/controllers/guiasController.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { unlinkSync } from 'fs';
|
||||
import { enviarGuias } from '../services/envioGuia.js';
|
||||
|
||||
const enviarGuiasController = async (req, res, next) => {
|
||||
try {
|
||||
let idGuia = req.params.idGuia;
|
||||
const resGuia = await enviarGuias(idGuia);
|
||||
|
||||
if (!resGuia) {
|
||||
res.status(404).send("Guía no encontrada.");
|
||||
}
|
||||
|
||||
// Por ejemplo:
|
||||
// if (body.estados) {
|
||||
// let estados = body.estados;
|
||||
// encabezados = await obtenerEncabezadosPorEstado(estados);
|
||||
// } else {
|
||||
// encabezados = await obtenerEncabezados();
|
||||
// }
|
||||
|
||||
res.status(200).send("Guia enviada exitosamente.");
|
||||
} catch (error) {
|
||||
// Pasar el error al middleware de errores
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
enviarGuiasController
|
||||
|
||||
}
|
||||
52
src/cronIndex.js
Normal file
52
src/cronIndex.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import dotenv from 'dotenv';
|
||||
import winston from 'winston';
|
||||
import cron from 'node-cron';
|
||||
import { envioDte } from './services/envioDte.js';
|
||||
import { envioEstados } from './services/envioEstado.js';
|
||||
|
||||
import Logger from './utils/logger.js';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Configuración de Winston para logging
|
||||
// const Logger = winston.createLogger({
|
||||
// level: 'info',
|
||||
// format: winston.format.combine(
|
||||
// winston.format.timestamp(),
|
||||
// winston.format.json()
|
||||
// ),
|
||||
// transports: [
|
||||
// new winston.transports.File({ filename: 'cron.log' }),
|
||||
|
||||
// new winston.transports.Console({
|
||||
// format: winston.format.simple(),
|
||||
// }),
|
||||
// ],
|
||||
// });
|
||||
|
||||
cron.schedule('*/10 * * * *', async () => {
|
||||
Logger.info({ message: 'Iniciando el proceso de envío de Dte...', proceso: 'cron' });
|
||||
|
||||
try {
|
||||
await envioDte();
|
||||
Logger.info({ message: 'Proceso de envío de Dte finalizado.', proceso: 'cron' });
|
||||
|
||||
|
||||
} catch (error) {
|
||||
Logger.error('Error al enviar Dte: ', error);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
cron.schedule('*/10 * * * *', async () => {
|
||||
Logger.info({ message: 'Iniciando el proceso de actualización de estados...', proceso: 'cron' });
|
||||
|
||||
try {
|
||||
await envioEstados();
|
||||
Logger.info({ message: 'Proceso de actualización de estados finalizado.', proceso: 'cron' });
|
||||
|
||||
} catch (error) {
|
||||
Logger.error('Error al enviar estados: ', error);
|
||||
|
||||
}
|
||||
});
|
||||
10
src/database/UC/config/config.json
Normal file
10
src/database/UC/config/config.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"dbCentral": {
|
||||
"username": "sialuc",
|
||||
"password": "Sialuc2930.,",
|
||||
"database": "centraluc",
|
||||
"host": "cloudoracle.sial.cl",
|
||||
"dialect": "mysql",
|
||||
"port": "3306"
|
||||
}
|
||||
}
|
||||
34
src/database/UC/config/db.models.js
Normal file
34
src/database/UC/config/db.models.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import Sequelize from 'sequelize';
|
||||
import dbs from './config.json' assert {type: 'json'};
|
||||
// import { crm as dbCrmConfig } from './config.json';
|
||||
// import { store as dbStoreConfig } from './config.json';
|
||||
|
||||
const dbCentralConfig = dbs.dbCentral;
|
||||
// const dbEcommerceConfig = dbs.dbEcommerce;
|
||||
|
||||
const dbCentral = new Sequelize(dbCentralConfig.database, dbCentralConfig.username, dbCentralConfig.password, {
|
||||
host: dbCentralConfig.host,
|
||||
dialect: dbCentralConfig.dialect,
|
||||
port: dbCentralConfig.port,
|
||||
define: {
|
||||
freezeTableName: true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// const dbEcommerce = new Sequelize(dbEcommerceConfig.database, dbEcommerceConfig.username, dbEcommerceConfig.password, {
|
||||
// host: dbEcommerceConfig.host,
|
||||
// dialect: dbEcommerceConfig.dialect,
|
||||
// port: dbEcommerceConfig.port,
|
||||
// define: {
|
||||
// freezeTableName: true
|
||||
// }
|
||||
|
||||
// });
|
||||
|
||||
|
||||
|
||||
export {
|
||||
dbCentral,
|
||||
|
||||
};
|
||||
146
src/database/UC/models/central/arti.js
Normal file
146
src/database/UC/models/central/arti.js
Normal file
@@ -0,0 +1,146 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const Arti = dbCentral.define('arti', {
|
||||
CODINT_MA: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
CLASE_MA: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
CODMOD_MA: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
MODELO_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
CODCOL_MA: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
COLOR_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TALNUM_MA: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
MARCA_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
GENERO_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
MATERIAL_MA: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
LINEA_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TEMPORADA_MA: {
|
||||
type: DataTypes.STRING(10),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
SELECCION_MA: {
|
||||
type: DataTypes.CHAR(1),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
ESTADO_MA: {
|
||||
type: DataTypes.CHAR(1),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
ESTILO_MA: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
KANBAN_MA: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
CLASIFICACION_MA: {
|
||||
type: DataTypes.CHAR(1),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
PRECIO_MA: {
|
||||
type: DataTypes.DOUBLE(10, 2),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
NUMERO_PROMOCION: {
|
||||
type: DataTypes.DECIMAL(8, 0),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
PRECIO_PROMOCION: {
|
||||
type: DataTypes.DECIMAL(8, 0),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TIPOPRO_MA: {
|
||||
type: DataTypes.STRING(1),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
CODIVA_MA: {
|
||||
type: DataTypes.INTEGER(11),
|
||||
allowNull: true,
|
||||
defaultValue: '1',
|
||||
},
|
||||
PRENDA_MA: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TEMPORADA_COMERCIAL: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
GRUPO_MA: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
empaque_ma: {
|
||||
type: DataTypes.INTEGER(11),
|
||||
allowNull: true,
|
||||
defaultValue: '1',
|
||||
},
|
||||
}, {
|
||||
timestamps: false, // No se incluyen timestamps
|
||||
collate: 'latin1_swedish_ci', // No se incluye collate
|
||||
indexes: [], // No se incluyen índices en este ejemplo
|
||||
sync: { force: false }, // No se sincroniza automáticamente
|
||||
primaryKey: true, // Se especifica que `CODINT_MA` es la llave primaria
|
||||
});
|
||||
|
||||
export default Arti;
|
||||
|
||||
58
src/database/UC/models/central/cadenas.js
Normal file
58
src/database/UC/models/central/cadenas.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const Cadenas = dbCentral.define('cadenas', {
|
||||
codigo_cad: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
nombre_cad: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: '',
|
||||
},
|
||||
division_cad: {
|
||||
type: DataTypes.INTEGER(11),
|
||||
defaultValue: 0,
|
||||
},
|
||||
empresa_cad: {
|
||||
type: DataTypes.INTEGER(10),
|
||||
defaultValue: 1,
|
||||
},
|
||||
mensajeurl_cad: {
|
||||
type: DataTypes.STRING(70),
|
||||
defaultValue: null,
|
||||
},
|
||||
rutaimagen_cad: {
|
||||
type: DataTypes.STRING(70),
|
||||
defaultValue: null,
|
||||
},
|
||||
mensajemail1_cad: {
|
||||
type: DataTypes.STRING(80),
|
||||
defaultValue: null,
|
||||
},
|
||||
cuentamail_cad: {
|
||||
type: DataTypes.STRING(30),
|
||||
defaultValue: null,
|
||||
},
|
||||
clavemail_cad: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
servidormail_cad: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
puertomail_cad: {
|
||||
type: DataTypes.INTEGER(5),
|
||||
defaultValue: null,
|
||||
},
|
||||
}, {
|
||||
timestamps: false, // No se incluyen timestamps
|
||||
collate: 'latin1_swedish_ci', // No se incluye collate
|
||||
sync: { force: false }, // No se sincroniza automáticamente
|
||||
primaryKey: true, // Se especifica que `codigo_cad` es la llave primaria
|
||||
});
|
||||
|
||||
export default Cadenas;
|
||||
136
src/database/UC/models/central/clie.js
Normal file
136
src/database/UC/models/central/clie.js
Normal file
@@ -0,0 +1,136 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const Clie = dbCentral.define('clie', {
|
||||
RUTCLI_CL: {
|
||||
type: DataTypes.STRING(11),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
CORREL_CL: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
nombre_cl: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
direcc_cl: {
|
||||
type: DataTypes.STRING(500),
|
||||
allowNull: true,
|
||||
},
|
||||
comuna_cl: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
},
|
||||
ciudad_cl: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
},
|
||||
ESTADO_CL: {
|
||||
type: DataTypes.CHAR(1),
|
||||
allowNull: true,
|
||||
},
|
||||
FULCOM_CL: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
GIRO_CL: {
|
||||
type: DataTypes.STRING(40),
|
||||
allowNull: true,
|
||||
},
|
||||
DESCTO_CL: {
|
||||
type: DataTypes.FLOAT,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
FONO_CL: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
},
|
||||
FAX_CL: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
email_cl: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
FECCRE_CL: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
ESTADOENV: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
AGENTERETE_CL: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
AGENTEPERC_CL: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
dnireplegal_cl: {
|
||||
type: DataTypes.STRING(11),
|
||||
allowNull: true,
|
||||
},
|
||||
nombrereplegal_cl: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
formapago_cl: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
lineacred_cl: {
|
||||
type: DataTypes.DOUBLE(14, 2),
|
||||
allowNull: true,
|
||||
},
|
||||
datosalbaran_cl: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
origen_cl: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: true,
|
||||
defaultValue: 1,
|
||||
},
|
||||
apellido_cl: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
},
|
||||
ubigeo_cl: {
|
||||
type: DataTypes.CHAR(10),
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
provincia_cl: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: '',
|
||||
},
|
||||
cuotas_cl: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 99,
|
||||
},
|
||||
}, {
|
||||
timestamps: false,
|
||||
}, {
|
||||
indexes: [],
|
||||
});
|
||||
|
||||
export default Clie;
|
||||
25
src/database/UC/models/central/ctrlSalesforce.js
Normal file
25
src/database/UC/models/central/ctrlSalesforce.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { Sequelize, DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const CtrlSalesforce = dbCentral.define('ctrl_salesforce', {
|
||||
tabla: {
|
||||
type: DataTypes.CHAR(30),
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
fecha_mutt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
fecha_ingenia: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
},{
|
||||
timestamps: false,
|
||||
});
|
||||
|
||||
|
||||
export default CtrlSalesforce;
|
||||
106
src/database/UC/models/central/dtfa.js
Normal file
106
src/database/UC/models/central/dtfa.js
Normal file
@@ -0,0 +1,106 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
|
||||
const Dtfa = dbCentral.define('Dtfa', {
|
||||
NLOCAL_DF: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
FECDOC_DF: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TIPDOC_DF: {
|
||||
type: DataTypes.CHAR(2),
|
||||
primaryKey: true
|
||||
},
|
||||
NUMFAC_DF: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TERMINAL_DF: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TRANSACCION_DF: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
CODPRO_DF: {
|
||||
type: DataTypes.STRING(30),
|
||||
primaryKey: true
|
||||
},
|
||||
CODEAN_DF: {
|
||||
type: DataTypes.STRING(30)
|
||||
},
|
||||
CANPED_DF: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
PREVEN_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
DSCPOR_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2),
|
||||
primaryKey: true
|
||||
},
|
||||
DSCPES_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
PREFIN_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
COSUNI_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
NUMERO_REGISTRO: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
COSPRO_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
COSULT_DF: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
prenet_df: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
adicional1_df: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional2_df: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional3_df: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional4_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional5_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional6_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional7_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional8_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional9_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional10_df: {
|
||||
type: DataTypes.STRING(50)
|
||||
}
|
||||
}, {
|
||||
tableName: 'dtfa',
|
||||
timestamps: false
|
||||
});
|
||||
|
||||
|
||||
|
||||
export default Dtfa;
|
||||
171
src/database/UC/models/central/dtpg.js
Normal file
171
src/database/UC/models/central/dtpg.js
Normal file
@@ -0,0 +1,171 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
import MaestroCi from './maestroCi.js';
|
||||
|
||||
const Dtpg = dbCentral.define('dtpg', {
|
||||
NLOCAL_PG: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
FECVTA_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
TIPDOC_PG: {
|
||||
type: DataTypes.CHAR(2),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
NUMDOC_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
TERMINAL_PG: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
TRANSACCION_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
TIPOPAGO_PG: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
NUMCHQ_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
NUMERO_REGISTRO: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
primaryKey: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
MONTO_PG: {
|
||||
type: DataTypes.DOUBLE(10, 4),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
MONTOADI_PG: {
|
||||
type: DataTypes.DOUBLE(10, 4),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TARJETA_PG: {
|
||||
type: DataTypes.STRING(20),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
CODAUT_PG: {
|
||||
type: DataTypes.STRING(12),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
CUOTAS_PG: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
RUTPAGA_PG: {
|
||||
type: DataTypes.STRING(13),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
RUTCOMP_PG: {
|
||||
type: DataTypes.STRING(13),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
OCVAL_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
FECOCVAL_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
TIPOCAMBIO_PG: {
|
||||
type: DataTypes.DOUBLE(10, 3),
|
||||
allowNull: true,
|
||||
defaultValue: '0.000',
|
||||
},
|
||||
FONO_PG: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
BANCO_PG: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
CTACTE_PG: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
FECVEN_PG: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
allowNull: true,
|
||||
defaultValue: '0',
|
||||
},
|
||||
user1_pg: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: ' ',
|
||||
},
|
||||
user2_pg: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: ' ',
|
||||
},
|
||||
user3_pg: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: ' ',
|
||||
},
|
||||
user4_pg: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: ' ',
|
||||
},
|
||||
user5_pg: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: ' ',
|
||||
},
|
||||
}, {
|
||||
timestamps: false, // No se incluyen timestamps
|
||||
indexes: [], // No se incluyen índices en este ejemplo
|
||||
});
|
||||
|
||||
MaestroCi.hasMany(Dtpg, {
|
||||
foreignKey: 'TIPOPAGO_PG',
|
||||
sourceKey: 'CODIGO_CI'
|
||||
});
|
||||
|
||||
Dtpg.belongsTo(MaestroCi, {
|
||||
foreignKey: 'TIPOPAGO_PG',
|
||||
targetId: 'CODIGO_CI'
|
||||
});
|
||||
|
||||
export default Dtpg;
|
||||
46
src/database/UC/models/central/estadosOrdenes.js
Normal file
46
src/database/UC/models/central/estadosOrdenes.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const EstadoOrdenes = dbCentral.define('EstadoOrdenes', {
|
||||
pedido: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true
|
||||
},
|
||||
ordenecommerce: {
|
||||
type: DataTypes.CHAR(22)
|
||||
},
|
||||
idecommerce: {
|
||||
type: DataTypes.INTEGER,
|
||||
unique: true
|
||||
},
|
||||
operador: {
|
||||
type: DataTypes.INTEGER,
|
||||
unique: true
|
||||
},
|
||||
estado: {
|
||||
type: DataTypes.TINYINT,
|
||||
unique: true
|
||||
},
|
||||
empresa: {
|
||||
type: DataTypes.INTEGER,
|
||||
unique: true
|
||||
},
|
||||
observacion: {
|
||||
type: DataTypes.STRING(500)
|
||||
},
|
||||
fechahora: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
EstadoEnvio: {
|
||||
type: DataTypes.CHAR(1)
|
||||
},
|
||||
FechaProceso: {
|
||||
type: DataTypes.DATE
|
||||
}
|
||||
}, {
|
||||
tableName: 'estado_ordenes',
|
||||
timestamps: false // Suponiendo que no quieres que Sequelize maneje automáticamente campos como createdAt y updatedAt
|
||||
});
|
||||
|
||||
export default EstadoOrdenes;
|
||||
51
src/database/UC/models/central/labelOperador.js
Normal file
51
src/database/UC/models/central/labelOperador.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
import EstadoOrdenes from './estadosOrdenes.js';
|
||||
|
||||
const LabelOperador = dbCentral.define('LabelOperador', {
|
||||
bodega: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
pedido: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
fecha: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false
|
||||
},
|
||||
operador: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
label: {
|
||||
type: DataTypes.CHAR(50),
|
||||
allowNull: false
|
||||
},
|
||||
numeroorden: {
|
||||
type: DataTypes.CHAR(25),
|
||||
allowNull: false
|
||||
},
|
||||
sitio: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
estado: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'label_operador',
|
||||
timestamps: false
|
||||
});
|
||||
|
||||
LabelOperador.hasMany(EstadoOrdenes, { foreignKey: 'pedido', sourceKey: 'pedido' });
|
||||
EstadoOrdenes.belongsTo(LabelOperador, { foreignKey: 'pedido', targetKey: 'pedido' });
|
||||
|
||||
export default LabelOperador;
|
||||
199
src/database/UC/models/central/locales.js
Normal file
199
src/database/UC/models/central/locales.js
Normal file
@@ -0,0 +1,199 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const Loca = dbCentral.define('loca', {
|
||||
CODEMP_LOC: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
cadena_loc: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
NLOCAL_LOC: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
REGION_LOC: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
NOMBRE_LOC: {
|
||||
type: DataTypes.STRING(25),
|
||||
defaultValue: null,
|
||||
},
|
||||
DIRECC_LOC: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
comuna_loc: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
ciudad_loc: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
NUMCAJ_LOC: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
TIPCAJ_LOC: {
|
||||
type: DataTypes.STRING(25),
|
||||
defaultValue: null,
|
||||
},
|
||||
ADMINI_LOC: {
|
||||
type: DataTypes.STRING(25),
|
||||
defaultValue: null,
|
||||
},
|
||||
SUBADM_LOC: {
|
||||
type: DataTypes.STRING(25),
|
||||
defaultValue: null,
|
||||
},
|
||||
FONO_LOC: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
ESTADO_LOC: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
MAX_CUOTAS: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
MAX_MES_APLICACION: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
REGALIA: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
defaultValue: null,
|
||||
},
|
||||
ANEXO: {
|
||||
type: DataTypes.STRING(15),
|
||||
defaultValue: null,
|
||||
},
|
||||
ANEXO_IP: {
|
||||
type: DataTypes.STRING(15),
|
||||
defaultValue: null,
|
||||
},
|
||||
FAX_IP: {
|
||||
type: DataTypes.STRING(15),
|
||||
defaultValue: null,
|
||||
},
|
||||
CAMPO1: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
CAMPO2: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
CAMPO3: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
CAMPO4: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
RUTLOC_LOC: {
|
||||
type: DataTypes.STRING(11),
|
||||
defaultValue: null,
|
||||
},
|
||||
GIRO_LOC: {
|
||||
type: DataTypes.STRING(30),
|
||||
defaultValue: null,
|
||||
},
|
||||
FANTAS_LOC: {
|
||||
type: DataTypes.STRING(35),
|
||||
defaultValue: null,
|
||||
},
|
||||
ccosto_loc: {
|
||||
type: DataTypes.STRING(10),
|
||||
defaultValue: null,
|
||||
},
|
||||
NOMBRE_CORTO: {
|
||||
type: DataTypes.STRING(6),
|
||||
defaultValue: null,
|
||||
},
|
||||
GRUPO1: {
|
||||
type: DataTypes.DECIMAL(1),
|
||||
defaultValue: null,
|
||||
},
|
||||
PRIORI_LOC: {
|
||||
type: DataTypes.DECIMAL(11),
|
||||
defaultValue: null,
|
||||
},
|
||||
email_loc: {
|
||||
type: DataTypes.STRING(30),
|
||||
defaultValue: null,
|
||||
},
|
||||
rpm_loc: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
conteo_loc: {
|
||||
type: DataTypes.STRING(1),
|
||||
defaultValue: null,
|
||||
},
|
||||
comision_loc: {
|
||||
type: DataTypes.DOUBLE(6, 3),
|
||||
defaultValue: 0.000,
|
||||
},
|
||||
zona_loc: {
|
||||
type: DataTypes.STRING(30),
|
||||
defaultValue: ' ',
|
||||
},
|
||||
tipotienda_loc: {
|
||||
type: DataTypes.STRING(2),
|
||||
defaultValue: ' ',
|
||||
},
|
||||
factor_loc: {
|
||||
type: DataTypes.DOUBLE(10, 2),
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
tiempo_loc: {
|
||||
type: DataTypes.DECIMAL(11),
|
||||
defaultValue: 0,
|
||||
},
|
||||
maximoseg_loc: {
|
||||
type: DataTypes.DECIMAL(10, 0),
|
||||
defaultValue: 0,
|
||||
},
|
||||
bloqueo_loc: {
|
||||
type: DataTypes.TINYINT(3),
|
||||
defaultValue: 0,
|
||||
},
|
||||
codsunat_loc: {
|
||||
type: DataTypes.STRING(8),
|
||||
defaultValue: '0',
|
||||
},
|
||||
ubigeo_loc: {
|
||||
type: DataTypes.CHAR(10),
|
||||
defaultValue: null,
|
||||
},
|
||||
provincia_loc: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
comisiondigital_loc: {
|
||||
type: DataTypes.DOUBLE(6, 3),
|
||||
defaultValue: 0.000,
|
||||
},
|
||||
codigosunat: {
|
||||
type: DataTypes.CHAR(5),
|
||||
defaultValue: '',
|
||||
},
|
||||
}, {
|
||||
timestamps: false, // No se incluyen timestamps
|
||||
collate: 'latin1_swedish_ci', // No se incluye collate
|
||||
sync: { force: false }, // No se sincroniza automáticamente
|
||||
primaryKey: true, // Se especifica que la combinación de `CODEMP_LOC` y `NLOCAL_LOC` es la llave primaria
|
||||
});
|
||||
|
||||
export default Loca;
|
||||
89
src/database/UC/models/central/logSalesforce.js
Normal file
89
src/database/UC/models/central/logSalesforce.js
Normal file
@@ -0,0 +1,89 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { Sequelize, DataTypes, STRING } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
import CtrlSalesforce from './ctrlSalesforce.js';
|
||||
|
||||
// Definir el modelo para la tabla log_salesforce
|
||||
const LogSalesforce = dbCentral.define('log_salesforce', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
allowNull: false,
|
||||
},
|
||||
tabla: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: false,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user1: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: false,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user2: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user3: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user4: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user5: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
user6: {
|
||||
type: DataTypes.CHAR(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
collate: 'latin1_swedish_ci',
|
||||
},
|
||||
insercion: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
id_ingenia: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
id_interno: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
fecha_ingenia: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
},
|
||||
request_json: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
}
|
||||
},{
|
||||
// Opciones adicionales del modelo
|
||||
timestamps: false, // Si no necesitas createdAt y updatedAt
|
||||
});
|
||||
|
||||
CtrlSalesforce.hasMany(LogSalesforce, {
|
||||
foreignKey: 'tabla',
|
||||
sourceKey: 'tabla'
|
||||
});
|
||||
|
||||
LogSalesforce.belongsTo(CtrlSalesforce, {
|
||||
foreignKey: 'tabla',
|
||||
targetId: 'tabla'
|
||||
});
|
||||
|
||||
export default LogSalesforce;
|
||||
139
src/database/UC/models/central/lvta.js
Normal file
139
src/database/UC/models/central/lvta.js
Normal file
@@ -0,0 +1,139 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
import Dtfa from './dtfa.js';
|
||||
|
||||
const Lvta = dbCentral.define('Lvta', {
|
||||
NLOCAL_LV: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
FECMOV_LV: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TIPDOC_LV: {
|
||||
type: DataTypes.CHAR(2),
|
||||
primaryKey: true
|
||||
},
|
||||
NRODOC_LV: {
|
||||
type: DataTypes.DECIMAL(11, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TERMINAL_LV: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
TRANSAC_LV: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
NROASO_LV: {
|
||||
type: DataTypes.DECIMAL(5, 0)
|
||||
},
|
||||
NROPED_LV: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
RUTCLI_LV: {
|
||||
type: DataTypes.STRING(13)
|
||||
},
|
||||
CORREL_LV: {
|
||||
type: DataTypes.DECIMAL(5, 0)
|
||||
},
|
||||
DCTPOR_LV: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
DCTPES_LV: {
|
||||
type: DataTypes.STRING(15)
|
||||
},
|
||||
TOTNET_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTIVA_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTEXE_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTILA1_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTILA2_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
totila3_lv: {
|
||||
type: DataTypes.CHAR(30)
|
||||
},
|
||||
TOTILA4_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTILA5_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTILA6_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTILA7_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
TOTBRT_LV: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
ESTADO_LV: {
|
||||
type: DataTypes.CHAR(1)
|
||||
},
|
||||
CLASI_LV: {
|
||||
type: DataTypes.CHAR(2)
|
||||
},
|
||||
NUMERO_REGISTRO: {
|
||||
type: DataTypes.DECIMAL(11, 0)
|
||||
},
|
||||
impuesto_lv: {
|
||||
type: DataTypes.DOUBLE(5, 2)
|
||||
},
|
||||
adicional1_lv: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional2_lv: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional3_lv: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
adicional4_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional5_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional6_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
//numero documento
|
||||
adicional7_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional8_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional9_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
adicional10_lv: {
|
||||
type: DataTypes.STRING(50)
|
||||
}
|
||||
}, {
|
||||
tableName: 'lvta',
|
||||
timestamps: false
|
||||
});
|
||||
|
||||
Lvta.hasMany(Dtfa, {
|
||||
foreignKey: 'NUMFAC_DF',
|
||||
sourceKey: 'NRODOC_LV'
|
||||
});
|
||||
|
||||
Dtfa.belongsTo(Lvta, {
|
||||
foreignKey: 'NUMFAC_DF',
|
||||
targetKey: 'NRODOC_LV'
|
||||
});
|
||||
|
||||
export default Lvta;
|
||||
45
src/database/UC/models/central/maestroCi.js
Normal file
45
src/database/UC/models/central/maestroCi.js
Normal file
@@ -0,0 +1,45 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const MaestroCi = dbCentral.define('maestro_ci', {
|
||||
CODIGO_CI: {
|
||||
type: DataTypes.INTEGER(2),
|
||||
allowNull: false,
|
||||
primaryKey: true
|
||||
},
|
||||
DESCRIPCION_CI: {
|
||||
type: DataTypes.STRING(30),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
ANALISIS_CI: {
|
||||
type: DataTypes.CHAR(2),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
BANCO_CI: {
|
||||
type: DataTypes.CHAR(2),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
TIPO_CI: {
|
||||
type: DataTypes.INTEGER(1).UNSIGNED,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
posintegrado_ci: {
|
||||
type: DataTypes.TINYINT(2),
|
||||
allowNull: false,
|
||||
defaultValue: '0',
|
||||
},
|
||||
marcatarjeta_ci: {
|
||||
type: DataTypes.CHAR(20),
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
}, {
|
||||
timestamps: false, // No se incluyen timestamps
|
||||
});
|
||||
|
||||
export default MaestroCi;
|
||||
233
src/database/UC/models/central/parametrosNuevaGuiaEntrega.js
Normal file
233
src/database/UC/models/central/parametrosNuevaGuiaEntrega.js
Normal file
@@ -0,0 +1,233 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const ParametrosNuevaGuiaEntrega = dbCentral.define(
|
||||
'ParametrosNuevaGuiaEntrega',
|
||||
{
|
||||
estado: {
|
||||
type: DataTypes.TINYINT.UNSIGNED,
|
||||
defaultValue: 0,
|
||||
},
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
primaryKey: true,
|
||||
},
|
||||
operador: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
codcliente: {
|
||||
type: DataTypes.CHAR(30),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
nombredestinatario: {
|
||||
type: DataTypes.STRING(100),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
telefonodestinatario: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
direcciondestinatario: {
|
||||
type: DataTypes.STRING(100),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
direcciondestinatario2: {
|
||||
type: DataTypes.STRING(100),
|
||||
defaultValue: null,
|
||||
},
|
||||
informacionadicional: {
|
||||
type: DataTypes.STRING(100),
|
||||
defaultValue: null,
|
||||
},
|
||||
numeropaquetes: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
defaultValue: 1,
|
||||
},
|
||||
pesopaquetes: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
numeropedido: {
|
||||
type: DataTypes.CHAR(30),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
defaultValue: null,
|
||||
},
|
||||
ubigeoorigen: {
|
||||
type: DataTypes.CHAR(10),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
ubigeodestino: {
|
||||
type: DataTypes.CHAR(10),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
descripcion: {
|
||||
type: DataTypes.STRING(400),
|
||||
defaultValue: null,
|
||||
},
|
||||
sucursal: {
|
||||
type: DataTypes.CHAR(30),
|
||||
defaultValue: null,
|
||||
},
|
||||
codigoproducto: {
|
||||
type: DataTypes.CHAR(30),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
descripcionproducto: {
|
||||
type: DataTypes.STRING(1000),
|
||||
allowNull: false,
|
||||
defaultValue: '',
|
||||
},
|
||||
modeloproducto: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
marcaproducto: {
|
||||
type: DataTypes.STRING(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
pesoproducto: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
allowNull: false,
|
||||
defaultValue: 0.00,
|
||||
},
|
||||
valorreferencial: {
|
||||
type: DataTypes.DOUBLE(10, 2),
|
||||
defaultValue: null,
|
||||
},
|
||||
anchoproducto: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
defaultValue: null,
|
||||
},
|
||||
altoproducto: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
defaultValue: null,
|
||||
},
|
||||
largoproducto: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
defaultValue: null,
|
||||
},
|
||||
pesovolumetrico: {
|
||||
type: DataTypes.DOUBLE(5, 2),
|
||||
defaultValue: null,
|
||||
},
|
||||
latitud_desde: {
|
||||
type: DataTypes.DOUBLE(13, 10),
|
||||
defaultValue: null,
|
||||
},
|
||||
longitud_desde: {
|
||||
type: DataTypes.DOUBLE(13, 10),
|
||||
defaultValue: null,
|
||||
},
|
||||
latitud_hasta: {
|
||||
type: DataTypes.DOUBLE(13, 10),
|
||||
defaultValue: null,
|
||||
},
|
||||
longitud_hasta: {
|
||||
type: DataTypes.DOUBLE(13, 10),
|
||||
defaultValue: null,
|
||||
},
|
||||
direccion_origen: {
|
||||
type: DataTypes.STRING(100),
|
||||
defaultValue: null,
|
||||
},
|
||||
documentodestinatario: {
|
||||
type: DataTypes.CHAR(13),
|
||||
defaultValue: null,
|
||||
},
|
||||
centrocosto: {
|
||||
type: DataTypes.TINYINT,
|
||||
defaultValue: null,
|
||||
},
|
||||
occliente: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
cantidad: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: null,
|
||||
},
|
||||
turnorecojo: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
fecharegistro: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: null,
|
||||
},
|
||||
paymentMethodID: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
paymentProofID: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
serviceID: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
packageEnvelope: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
packageWeight: {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: null,
|
||||
},
|
||||
packageSizeID: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
crossdocking: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
dropPrimaryReference: {
|
||||
type: DataTypes.CHAR(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
dropSecondaryReference: {
|
||||
type: DataTypes.CHAR(50),
|
||||
defaultValue: null,
|
||||
},
|
||||
dropContactName: {
|
||||
type: DataTypes.CHAR(80),
|
||||
defaultValue: null,
|
||||
},
|
||||
dropContactEmail: {
|
||||
type: DataTypes.CHAR(80),
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'parametros_nuevaguiaentrega',
|
||||
timestamps: false, // Desactivar timestamps
|
||||
}
|
||||
);
|
||||
|
||||
export default ParametrosNuevaGuiaEntrega;
|
||||
50
src/database/UC/models/central/pedidosDetail.js
Normal file
50
src/database/UC/models/central/pedidosDetail.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const PedidosDetail = dbCentral.define('PedidosDetail', {
|
||||
NROPED_PD: {
|
||||
type: DataTypes.DECIMAL(10, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
IDDETA_PD: {
|
||||
type: DataTypes.INTEGER,
|
||||
unique: true
|
||||
},
|
||||
CODINT_PD: {
|
||||
type: DataTypes.STRING(30)
|
||||
},
|
||||
PRECIO_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
CANPED_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
CANDES_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
ESTADO_PD: {
|
||||
type: DataTypes.DECIMAL(2, 0)
|
||||
},
|
||||
DSCTOIT_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
DSCTOTO_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
PREORI_PD: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
},
|
||||
CODLOC_PD: {
|
||||
type: DataTypes.INTEGER,
|
||||
unique: true
|
||||
},
|
||||
canori_pd: {
|
||||
type: DataTypes.DOUBLE(10, 2)
|
||||
}
|
||||
}, {
|
||||
tableName: 'pedidos_detail',
|
||||
timestamps: false // Si no deseas que Sequelize maneje los campos createdAt y updatedAt
|
||||
});
|
||||
|
||||
export default PedidosDetail;
|
||||
178
src/database/UC/models/central/pedidosHeader.js
Normal file
178
src/database/UC/models/central/pedidosHeader.js
Normal file
@@ -0,0 +1,178 @@
|
||||
// Importar Sequelize y la conexión a la base de datos
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
import PedidosDetail from './pedidosDetail.js';
|
||||
import EstadoOrdenes from './estadosOrdenes.js';
|
||||
import LabelOperador from './labelOperador.js';
|
||||
|
||||
const PedidosHeader = dbCentral.define('pedidos_header', {
|
||||
NROPED_PH: {
|
||||
type: DataTypes.DECIMAL(10, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
IDCLIE_PH: {
|
||||
type: DataTypes.STRING(13)
|
||||
},
|
||||
FECPED_PH: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
FECENT_PH: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
CODPAG_PH: {
|
||||
type: DataTypes.DECIMAL(5, 0)
|
||||
},
|
||||
APRO01_PH: {
|
||||
type: DataTypes.DECIMAL(10, 0)
|
||||
},
|
||||
FECAP1_PH: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
APRO02_PH: {
|
||||
type: DataTypes.STRING(30)
|
||||
},
|
||||
FECAP2_PH: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
ESTADO_PH: {
|
||||
type: DataTypes.DECIMAL(2, 1)
|
||||
},
|
||||
CODLOC_PH: {
|
||||
type: DataTypes.DECIMAL(5, 0),
|
||||
primaryKey: true
|
||||
},
|
||||
CODVEN_PH: {
|
||||
type: DataTypes.DECIMAL(6, 0)
|
||||
},
|
||||
NROORC_PH: {
|
||||
type: DataTypes.STRING(15)
|
||||
},
|
||||
DIRDES_PH: {
|
||||
type: DataTypes.STRING(50)
|
||||
},
|
||||
COMDES_PH: {
|
||||
type: DataTypes.STRING(30)
|
||||
},
|
||||
CIUDES_PH: {
|
||||
type: DataTypes.STRING(30)
|
||||
},
|
||||
FECEXP_PH: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
PRIORI_PH: {
|
||||
type: DataTypes.DECIMAL(2, 0)
|
||||
},
|
||||
FECREG_PH: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
FECMLS_PH: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
FECDOC_PH: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
FECREC_PH: {
|
||||
type: DataTypes.DATE
|
||||
},
|
||||
TIPUBI_PH: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
ORIGEN_PH: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
condicion_ph: {
|
||||
type: DataTypes.STRING(40)
|
||||
},
|
||||
bodega_ph: {
|
||||
type: DataTypes.DECIMAL(5, 0)
|
||||
},
|
||||
empresa_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
ordcli_ph: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
fecord_ph: {
|
||||
type: DataTypes.DATEONLY
|
||||
},
|
||||
succli_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
conceptoped_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
GLOSA_PH: {
|
||||
type: DataTypes.STRING(100)
|
||||
},
|
||||
tipopago_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
ntarjeta_ph: {
|
||||
type: DataTypes.CHAR(20)
|
||||
},
|
||||
cuota_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
nroautorizacion_ph: {
|
||||
type: DataTypes.CHAR(20)
|
||||
},
|
||||
marcatarjeta_ph: {
|
||||
type: DataTypes.CHAR(40)
|
||||
},
|
||||
depto_ph: {
|
||||
type: DataTypes.CHAR(20)
|
||||
},
|
||||
referencia_ph: {
|
||||
type: DataTypes.STRING(10)
|
||||
},
|
||||
nombrerecibe_ph: {
|
||||
type: DataTypes.STRING(60)
|
||||
},
|
||||
vigilancia_ph: {
|
||||
type: DataTypes.TINYINT
|
||||
},
|
||||
IdOrdenOMS_ph: {
|
||||
type: DataTypes.STRING(20)
|
||||
},
|
||||
bodegadespacho_ph: {
|
||||
type: DataTypes.INTEGER
|
||||
},
|
||||
UrlDoc_ph: {
|
||||
type: DataTypes.STRING(300)
|
||||
}
|
||||
}, {
|
||||
tableName: 'pedidos_header',
|
||||
timestamps: false
|
||||
});
|
||||
|
||||
PedidosHeader.hasMany(PedidosDetail, {
|
||||
foreignKey: 'NROPED_PD',
|
||||
sourceKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
PedidosDetail.belongsTo(PedidosHeader, {
|
||||
foreignKey: 'NROPED_PD',
|
||||
targetKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
PedidosHeader.hasMany(EstadoOrdenes, {
|
||||
foreignKey: 'pedido',
|
||||
sourceKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
EstadoOrdenes.belongsTo(PedidosHeader, {
|
||||
foreignKey: 'pedido',
|
||||
targetKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
PedidosHeader.hasMany(LabelOperador, {
|
||||
foreignKey: 'pedido',
|
||||
sourceKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
LabelOperador.belongsTo(PedidosHeader, {
|
||||
foreignKey: 'pedido',
|
||||
targetKey: 'NROPED_PH'
|
||||
});
|
||||
|
||||
export default PedidosHeader;
|
||||
49
src/database/UC/models/central/respuestaNuevaGuiaEntrega.js
Normal file
49
src/database/UC/models/central/respuestaNuevaGuiaEntrega.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import { DataTypes } from 'sequelize';
|
||||
import { dbCentral } from '../../config/db.models.js';
|
||||
|
||||
const RespuestaNuevaGuiaEntrega = dbCentral.define(
|
||||
'RespuestaNuevaGuiaEntrega',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER.UNSIGNED,
|
||||
allowNull: false,
|
||||
primaryKey: true,
|
||||
},
|
||||
estado: {
|
||||
type: DataTypes.CHAR(10),
|
||||
defaultValue: null,
|
||||
},
|
||||
descripcion: {
|
||||
type: DataTypes.STRING(300),
|
||||
charset: 'latin1',
|
||||
collate: 'latin1_swedish_ci',
|
||||
defaultValue: null,
|
||||
},
|
||||
numeroguia: {
|
||||
type: DataTypes.CHAR(30),
|
||||
defaultValue: null,
|
||||
},
|
||||
mensajeerror: {
|
||||
type: DataTypes.STRING(1000),
|
||||
defaultValue: null,
|
||||
},
|
||||
ordenservicio: {
|
||||
type: DataTypes.CHAR(20),
|
||||
defaultValue: null,
|
||||
},
|
||||
fecha: {
|
||||
type: DataTypes.DATE,
|
||||
defaultValue: null,
|
||||
},
|
||||
json_guia: {
|
||||
type: DataTypes.JSON,
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: 'respuesta_nuevaguiaentrega',
|
||||
timestamps: false, // Desactivar timestamps
|
||||
}
|
||||
);
|
||||
|
||||
export default RespuestaNuevaGuiaEntrega;
|
||||
21
src/services/config.json
Normal file
21
src/services/config.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"dataUrbano": {
|
||||
"url": "https://app.urbanoexpress.cl/ws/ue/ge/",
|
||||
"id_contrato": 2292,
|
||||
"linea": 3,
|
||||
"userHeader": "WS_PUC",
|
||||
"passHeader": "d4e434db64fd3567a94b098d381a575e535142b2"
|
||||
},
|
||||
"dataInfracommerce": {
|
||||
"urlDte": "https://oms.brandlive.net/api/v2/document/:oms_id/create",
|
||||
"urlEstados": "https://oms.brandlive.net/api/v2/shipment/:oms_id",
|
||||
"AppKey": "9285785147",
|
||||
"AppToken": "0bd1741dabf2ba558bd92ec045d65d08",
|
||||
"skuShipping": "1032426"
|
||||
},
|
||||
"dataEnvioEstados": {
|
||||
"url": "https://oms.brandlive.net/api/v2/shipment/:oms_id",
|
||||
"AppKey": "9285785147",
|
||||
"AppToken": "0bd1741dabf2ba558bd92ec045d65d08"
|
||||
}
|
||||
}
|
||||
212
src/services/envioDte.js
Normal file
212
src/services/envioDte.js
Normal file
@@ -0,0 +1,212 @@
|
||||
import { Op } from 'sequelize';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import PedidosHeader from '../database/UC/models/central/pedidosHeader.js';
|
||||
import PedidosDetail from '../database/UC/models/central/pedidosDetail.js';
|
||||
import EstadoOrdenes from '../database/UC/models/central/estadosOrdenes.js';
|
||||
import Lvta from '../database/UC/models/central/lvta.js';
|
||||
import Dtfa from '../database/UC/models/central/dtfa.js';
|
||||
|
||||
import Logger from '../utils/logger.js'
|
||||
import { sendRequestInfracommerce } from '../utils/utils.js';
|
||||
import config from './config.json' assert {type: 'json'};
|
||||
|
||||
const dataInfracommerce = config.dataInfracommerce;
|
||||
|
||||
// {
|
||||
// "document": {
|
||||
// "type": "invoice",
|
||||
// "id": "001-01",
|
||||
// "parent_document": "",
|
||||
// "total_amount": 4871,
|
||||
// "date": "2023-04-11 15:00:00",
|
||||
// "url": "WWW.facturaenPDFViru.com.ar/001",
|
||||
// "shipping": {
|
||||
// "sku": 1,
|
||||
// "price": 371,
|
||||
// "vat": 21
|
||||
// },
|
||||
// "items": [
|
||||
// {
|
||||
// "sku": "2182118.992",
|
||||
// "price": 1500,
|
||||
// "vat": 21
|
||||
// },
|
||||
// {
|
||||
// "sku": "2182118.992",
|
||||
// "price": 1500,
|
||||
// "vat": 21
|
||||
// },
|
||||
// {
|
||||
// "sku": "2182118.992",
|
||||
// "price": 1500,
|
||||
// "vat": 21
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
|
||||
const envioDte = async () => {
|
||||
try {
|
||||
const dataEstados = await EstadoOrdenes.findAll({
|
||||
where: {
|
||||
estado: 1, //Documentado
|
||||
EstadoEnvio: 'R',
|
||||
// pedido: 127821
|
||||
},
|
||||
include: [PedidosHeader]
|
||||
});
|
||||
|
||||
// console.log(JSON.stringify(dataEstados, null, 2))
|
||||
|
||||
const skuShipping = dataInfracommerce.skuShipping;
|
||||
for (const element of dataEstados) {
|
||||
const omsId = `${element.pedidos_header.IdOrdenOMS_ph}`;
|
||||
const url = dataInfracommerce.urlDte.replace(':oms_id', omsId);
|
||||
// console.log(url);
|
||||
|
||||
const urlDoc = element.pedidos_header.UrlDoc_ph;
|
||||
const pedido = element.pedido;
|
||||
let fechaRegistro = element.pedidos_header.FECREG_PH;
|
||||
fechaRegistro = moment(fechaRegistro).format("YYYY-MM-DD HH:mm:ss");
|
||||
|
||||
console.log(pedido)
|
||||
const dataLvta = await Lvta.findOne({
|
||||
where: {
|
||||
// NROPED_LV: { [Op.gt]: 0 },
|
||||
adicional7_lv: pedido,
|
||||
|
||||
// NRODOC_LV: 51
|
||||
},
|
||||
include: [{
|
||||
model: Dtfa,
|
||||
attributes: ['CODPRO_DF', 'PREFIN_DF'],
|
||||
|
||||
}]
|
||||
});
|
||||
|
||||
// console.log(JSON.stringify(dataLvta, null, 2))
|
||||
// return;
|
||||
|
||||
let res;
|
||||
// for (const elementLvta of dataLvta) {
|
||||
// await dataLvta.forEach(async element => {
|
||||
if (!dataLvta) {
|
||||
continue;
|
||||
}
|
||||
const { NLOCAL_LV, TIPDOC_LV, NRODOC_LV, TERMINAL_LV, TRANSAC_LV, TOTBRT_LV } = dataLvta;
|
||||
|
||||
let items = [];
|
||||
let shipping = {};
|
||||
// let valorTotal = 0;
|
||||
let valorTotal = TOTBRT_LV;
|
||||
for (const elementDtfa of dataLvta.Dtfas) {
|
||||
let { CODPRO_DF, PREFIN_DF } = elementDtfa;
|
||||
|
||||
if (CODPRO_DF == skuShipping) {
|
||||
if (Number(PREFIN_DF) > 0) {
|
||||
shipping = {
|
||||
sku: CODPRO_DF,
|
||||
price: PREFIN_DF,
|
||||
vat: 21
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
items.push({
|
||||
sku: CODPRO_DF,
|
||||
price: PREFIN_DF,
|
||||
|
||||
vat: 21
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let payload
|
||||
if (Object.keys(shipping).length > 0) {
|
||||
payload = {
|
||||
document: {
|
||||
"type": "invoice",
|
||||
"id": NRODOC_LV,
|
||||
"parent_document": "",
|
||||
"total_amount": valorTotal,
|
||||
"date": fechaRegistro,
|
||||
"url": urlDoc,
|
||||
items: items,
|
||||
shipping: shipping
|
||||
},
|
||||
|
||||
};
|
||||
} else {
|
||||
payload = {
|
||||
document: {
|
||||
"type": "invoice",
|
||||
"id": NRODOC_LV,
|
||||
"parent_document": "",
|
||||
"total_amount": valorTotal,
|
||||
"date": fechaRegistro,
|
||||
"url": urlDoc,
|
||||
items: items,
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// console.log(JSON.stringify(payload, null, 2))
|
||||
// return
|
||||
res = await sendRequestInfracommerce(payload, url);
|
||||
console.log(payload)
|
||||
console.log(res)
|
||||
|
||||
|
||||
Logger.info({ message: `Payload enviado: ${JSON.stringify(payload, null, 2)}`, proceso: 'cron' });
|
||||
Logger.info({ message: `Respuesta del documento ${NRODOC_LV}: ${JSON.stringify(res, null, 2)}`, proceso: 'cron' });
|
||||
// console.log(JSON.stringify(res, null, 2))
|
||||
|
||||
|
||||
// if (res) {
|
||||
// if (res.status) {
|
||||
// if (res.status == "error") {
|
||||
// element.set({
|
||||
// EstadoEnvio: 'P'
|
||||
// });
|
||||
|
||||
// await element.save();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (res) {
|
||||
if (res.status) {
|
||||
if (res.status == "error") {
|
||||
if (res.data == "Ya se encuentra un documento para la orden") {
|
||||
element.set({
|
||||
EstadoEnvio: 'P'
|
||||
});
|
||||
|
||||
await element.save();
|
||||
}
|
||||
|
||||
} else {
|
||||
element.set({
|
||||
EstadoEnvio: 'P'
|
||||
});
|
||||
|
||||
await element.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error en Proceso de envío de Dte:', error);
|
||||
Logger.error(`Error en envío de Dte: ${error}`)
|
||||
}
|
||||
};
|
||||
|
||||
// await envioDte();
|
||||
|
||||
export {
|
||||
envioDte
|
||||
}
|
||||
201
src/services/envioEstado.js
Normal file
201
src/services/envioEstado.js
Normal file
@@ -0,0 +1,201 @@
|
||||
import { Sequelize, Op } from 'sequelize';
|
||||
import moment from 'moment';
|
||||
|
||||
import PedidosHeader from '../database/UC/models/central/pedidosHeader.js';
|
||||
import PedidosDetail from '../database/UC/models/central/pedidosDetail.js';
|
||||
import EstadoOrdenes from '../database/UC/models/central/estadosOrdenes.js';
|
||||
import LabelOperador from '../database/UC/models/central/labelOperador.js';
|
||||
import Lvta from '../database/UC/models/central/lvta.js';
|
||||
import Dtfa from '../database/UC/models/central/dtfa.js';
|
||||
import Logger from '../utils/logger.js';
|
||||
|
||||
import { sendRequestInfracommerce } from '../utils/utils.js';
|
||||
import config from './config.json' assert {type: 'json'};
|
||||
|
||||
const dataInfracommerce = config.dataInfracommerce;
|
||||
const dataUrbano = config.dataUrbano;
|
||||
|
||||
|
||||
const envioEstados = async () => {
|
||||
try {
|
||||
|
||||
const dataOperador = await LabelOperador.findAll({
|
||||
where: {
|
||||
estado: 'A', // Activo
|
||||
// EstadoEnvio: 'P',
|
||||
|
||||
},
|
||||
include: [{
|
||||
model: PedidosHeader,
|
||||
attributes: ['IdOrdenOMS_ph']
|
||||
}]
|
||||
|
||||
});
|
||||
|
||||
for (const element of dataOperador) {
|
||||
const omsId = element.pedidos_header.IdOrdenOMS_ph;
|
||||
const url = dataInfracommerce.urlEstados.replace(':oms_id', omsId);
|
||||
const trackingCode = element.label;
|
||||
const dataTracking = await fetchTrackingInfo(trackingCode);
|
||||
const estadoEnvioUrbano = dataTracking[0].chk;
|
||||
|
||||
// SS : Solicitud de Servicio
|
||||
// AO : Admitido en Origen
|
||||
// DD : Despachadas a su Destino
|
||||
// AD : Arribado en Destino
|
||||
// ER : Salió a Ruta
|
||||
// NT : No hubo tiempo (incidencia en ruta)
|
||||
// EN : Entregado
|
||||
// CV : Visitado
|
||||
|
||||
let estadoSial;
|
||||
//1 => documentado, 2 => pendiente, 3 => despachado, 4 => entregado, 5 => no entregado
|
||||
|
||||
let payload;
|
||||
if (estadoEnvioUrbano == 'SS' || estadoEnvioUrbano == 'AO') {
|
||||
/**
|
||||
* Estado 2 => Pendiente
|
||||
*/
|
||||
estadoSial = 2;
|
||||
|
||||
} else if (estadoEnvioUrbano == 'DD' || estadoEnvioUrbano == 'AD' || estadoEnvioUrbano == 'ER' || estadoEnvioUrbano == 'NT') {
|
||||
/**
|
||||
* Estado 3 => Despachado
|
||||
*/
|
||||
|
||||
estadoSial = 3;
|
||||
let urlSeguimiento = `https://portal.urbanoexpress.cl/rastrear-shipper/${trackingCode}`;
|
||||
payload = {
|
||||
"status": "shipped",
|
||||
"tracking_number": trackingCode,
|
||||
"tracking_url": urlSeguimiento
|
||||
|
||||
}
|
||||
} else if (estadoEnvioUrbano == 'EN') {
|
||||
|
||||
/**
|
||||
* Estado 4 => Entregado
|
||||
*/
|
||||
|
||||
estadoSial = 4;
|
||||
|
||||
payload = {
|
||||
"status": "delivered",
|
||||
|
||||
}
|
||||
|
||||
} else if (estadoEnvioUrbano == 'CV') {
|
||||
/**
|
||||
* Estado 5 => No Entregado
|
||||
*/
|
||||
|
||||
estadoSial = 5;
|
||||
|
||||
payload = {
|
||||
"status": "not_delivered",
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let date = new Date();
|
||||
|
||||
let dataRegistroEstado = {
|
||||
"pedido": element.pedido,
|
||||
"ordenecommerce": element.numeroorden,
|
||||
// "idecommerce": element.idecommerce,
|
||||
"idecommerce": 1,
|
||||
// "operador": element.operador,
|
||||
"estado": estadoSial,
|
||||
// "empresa": element.empresa,
|
||||
// "observacion": element.observacion,
|
||||
"fechahora": date,
|
||||
"EstadoEnvio": "P",
|
||||
"FechaProceso": element.FechaProceso
|
||||
|
||||
}
|
||||
|
||||
if (estadoSial == 4) {
|
||||
element.set({
|
||||
estado: 'C' //cerrado
|
||||
});
|
||||
|
||||
await element.save();
|
||||
}
|
||||
|
||||
dataRegistroEstado.estado = estadoSial;
|
||||
|
||||
const dataEstado = await EstadoOrdenes.findOne({
|
||||
attributes: ['pedido', [Sequelize.fn('MAX', Sequelize.col('estado')), 'estado']],
|
||||
where: {
|
||||
pedido: element.pedido
|
||||
},
|
||||
});
|
||||
|
||||
console.log(element.pedido, JSON.stringify(dataEstado, null, 2))
|
||||
|
||||
if (dataEstado.pedido) {
|
||||
if ((dataEstado.estado < estadoSial)) {
|
||||
if (estadoSial == 3 || estadoSial == 4 || estadoSial == 5) {
|
||||
const res = await sendRequestInfracommerce(payload, url);
|
||||
|
||||
console.log(res)
|
||||
Logger.info({ message: `Estado de la orden ${omsId}: ${estadoEnvioUrbano}, resInfracommerce: ${JSON.stringify(res, null, 2)}`, proceso: 'cron' });
|
||||
|
||||
}
|
||||
|
||||
|
||||
// console.log(dataEstado.estado, estadoSial)
|
||||
await EstadoOrdenes.create(dataRegistroEstado)
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("No existe Guía")
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
} catch (error) {
|
||||
// Logger.error(`Error en la actualización de estados: ${error.message}`);
|
||||
console.error('Error al enviar estado:', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const fetchTrackingInfo = async (guia) => {
|
||||
|
||||
const user = dataUrbano.userHeader;
|
||||
const pass = dataUrbano.passHeader;
|
||||
|
||||
const url = `https://app.urbanoexpress.cl/ws/ue/tracking/?json={"guia":"${guia}","docref":"","vp_linea":"3"}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'user': user,
|
||||
'pass': pass
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
await envioEstados();
|
||||
|
||||
|
||||
export {
|
||||
envioEstados
|
||||
}
|
||||
|
||||
200
src/services/envioEstadoOld.js
Normal file
200
src/services/envioEstadoOld.js
Normal file
@@ -0,0 +1,200 @@
|
||||
import { Op } from 'sequelize';
|
||||
import moment from 'moment';
|
||||
|
||||
import PedidosHeader from '../database/UC/models/central/pedidosHeader.js';
|
||||
import PedidosDetail from '../database/UC/models/central/pedidosDetail.js';
|
||||
import EstadoOrdenes from '../database/UC/models/central/estadosOrdenes.js';
|
||||
import LabelOperador from '../database/UC/models/central/labelOperador.js';
|
||||
import Lvta from '../database/UC/models/central/lvta.js';
|
||||
import Dtfa from '../database/UC/models/central/dtfa.js';
|
||||
import Logger from '../utils/logger.js';
|
||||
|
||||
import { sendRequestInfracommerce } from '../utils/utils.js';
|
||||
import config from './config.json' assert {type: 'json'};
|
||||
|
||||
const dataInfracommerce = config.dataInfracommerce;
|
||||
const dataUrbano = config.dataUrbano;
|
||||
|
||||
|
||||
const envioEstados = async () => {
|
||||
try {
|
||||
|
||||
const dataEstados = await EstadoOrdenes.findAll({
|
||||
where: {
|
||||
estado: [1, 2, 3], //1 => documentado, 2 => pendiente, 3 => despachado, 4 => entregado, 5 => no entregado
|
||||
EstadoEnvio: 'P',
|
||||
pedido: [1426, 1427]
|
||||
},
|
||||
include: [LabelOperador, PedidosHeader]
|
||||
// include: [PedidosHeader]
|
||||
|
||||
});
|
||||
console.log(JSON.stringify(dataEstados, null, 2))
|
||||
// const trackingCode = 'WB178651579';
|
||||
|
||||
// return;
|
||||
for (const element of dataEstados) {
|
||||
// dataEstados.forEach(async element => {
|
||||
// console.log(JSON.stringify(element, null, 2))
|
||||
|
||||
let trackingCode;
|
||||
let urlSeguimiento;
|
||||
if (element.LabelOperador) {
|
||||
trackingCode = element.LabelOperador.label;
|
||||
urlSeguimiento = `https://portal.urbanoexpress.cl/rastrear-shipper/${trackingCode}`;
|
||||
} else {
|
||||
// trackingCode = "";
|
||||
// urlSeguimiento = "";
|
||||
trackingCode = "WB179882541";
|
||||
urlSeguimiento = `https://portal.urbanoexpress.cl/rastrear-shipper/${trackingCode}`;
|
||||
}
|
||||
|
||||
// 'WB178649450'
|
||||
const omsId = element.pedidos_header.IdOrdenOMS_ph;
|
||||
// const omsId = 6252;
|
||||
|
||||
// Logger.info(`Actualización de estado de envío de la orden ${omsId}`)
|
||||
|
||||
|
||||
const url = dataInfracommerce.urlEstados.replace(':oms_id', omsId);
|
||||
// const dataTracking = await fetchTrackingInfo(trackingCode);
|
||||
// console.log(JSON.stringify(dataTracking, null, 2))
|
||||
|
||||
// const estadoEnvioUrbano = dataTracking[0].chk;
|
||||
const estadoEnvioUrbano = "EN";
|
||||
|
||||
// SS : Solicitud de Servicio
|
||||
// AO : Admitido en Origen
|
||||
// DD : Despachadas a su Destino
|
||||
// AD : Arribado en Destino
|
||||
// ER : Salió a Ruta
|
||||
// NT : No hubo tiempo (incidencia en ruta)
|
||||
// EN : Entregado
|
||||
// CV : Visitado
|
||||
let payload;
|
||||
let date = new Date();
|
||||
let dataRegistroEstado = {
|
||||
"pedido": element.pedido,
|
||||
"ordenecommerce": element.ordenecommerce,
|
||||
"idecommerce": element.idecommerce,
|
||||
"operador": element.operador,
|
||||
"estado": element.estado,
|
||||
"empresa": element.empresa,
|
||||
"observacion": element.observacion,
|
||||
"fechahora": date,
|
||||
"EstadoEnvio": "P",
|
||||
"FechaProceso": element.FechaProceso
|
||||
|
||||
|
||||
}
|
||||
|
||||
let estadoSial;
|
||||
if (estadoEnvioUrbano == 'SS' || estadoEnvioUrbano == 'AO' || estadoEnvioUrbano == 'DD' || estadoEnvioUrbano == 'AD') {
|
||||
/**
|
||||
* Estado 2 => Pendiente
|
||||
*/
|
||||
estadoSial = 2;
|
||||
|
||||
// payload = {
|
||||
// "status": "shipped",
|
||||
// "tracking_number": trackingCode,
|
||||
// "tracking_url": urlSeguimiento
|
||||
|
||||
// }
|
||||
} else {
|
||||
if (estadoEnvioUrbano == 'ER') {
|
||||
/**
|
||||
* Estado 3 => Despachado
|
||||
*/
|
||||
|
||||
estadoSial = 3;
|
||||
|
||||
payload = {
|
||||
"status": "shipped",
|
||||
"tracking_number": trackingCode,
|
||||
"tracking_url": urlSeguimiento
|
||||
|
||||
}
|
||||
|
||||
} else if (estadoEnvioUrbano == 'EN') {
|
||||
/**
|
||||
* Estado 4 => Entregado
|
||||
*/
|
||||
|
||||
estadoSial = 4;
|
||||
|
||||
payload = {
|
||||
"status": "delivered",
|
||||
|
||||
}
|
||||
|
||||
} else if (estadoEnvioUrbano == 'CV') {
|
||||
/**
|
||||
* Estado 5 => No Entregado
|
||||
*/
|
||||
|
||||
estadoSial = 5;
|
||||
|
||||
payload = {
|
||||
"status": "not_delivered",
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
console.log(payload, url)
|
||||
|
||||
const res = await sendRequestInfracommerce(payload, url)
|
||||
console.log(res)
|
||||
}
|
||||
Logger.info({ message: `Estado de la orden ${omsId}: ${estadoEnvioUrbano}`, proceso: 'cron' });
|
||||
|
||||
dataRegistroEstado.estado = estadoSial;
|
||||
await EstadoOrdenes.create(dataRegistroEstado)
|
||||
// console.log(dataRegistroEstado)
|
||||
};
|
||||
|
||||
|
||||
} catch (error) {
|
||||
// Logger.error(`Error en la actualización de estados: ${error.message}`);
|
||||
console.error('Error al enviar estado:', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const fetchTrackingInfo = async (guia) => {
|
||||
|
||||
const user = dataUrbano.userHeader;
|
||||
const pass = dataUrbano.passHeader;
|
||||
|
||||
const url = `https://app.urbanoexpress.cl/ws/ue/tracking/?json={"guia":"${guia}","docref":"","vp_linea":"3"}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'user': user,
|
||||
'pass': pass
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Error: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
// console.log(data);
|
||||
return data;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching data: ', error);
|
||||
}
|
||||
}
|
||||
|
||||
// const actualizarEstadoEnvioSial = async (estado)
|
||||
await envioEstados();
|
||||
|
||||
|
||||
export {
|
||||
envioEstados
|
||||
}
|
||||
|
||||
// fetchTrackingInfo('WB178651579', 'WS_PUC', 'd4e434db64fd3567a94b098d381a575e535142b2');
|
||||
188
src/services/envioGuia.js
Normal file
188
src/services/envioGuia.js
Normal file
@@ -0,0 +1,188 @@
|
||||
import ParametrosGuia from '../database/UC/models/central/parametrosNuevaGuiaEntrega.js';
|
||||
import RespuestaGuia from '../database/UC/models/central/respuestaNuevaGuiaEntrega.js';
|
||||
import PedidosHeader from '../database/UC/models/central/pedidosHeader.js';
|
||||
import { sendData } from '../utils/utils.js';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
|
||||
import config from './config.json' assert {type: 'json'};
|
||||
|
||||
const dataUrbano = config.dataUrbano;
|
||||
|
||||
|
||||
const enviarGuias = async (idGuia) => {
|
||||
|
||||
const url = dataUrbano.url;
|
||||
const idContrato = dataUrbano.id_contrato;
|
||||
const linea = dataUrbano.linea;
|
||||
// console.log(url, idContrato);
|
||||
|
||||
const guias = await ParametrosGuia.findAll({
|
||||
where: {
|
||||
id: idGuia,
|
||||
// estado: 0
|
||||
}
|
||||
});
|
||||
|
||||
if (!guias) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (guias && guias.length > 0) {
|
||||
let date = new Date(guias[0].fecharegistro)
|
||||
let mes = `${date.getMonth() + 1}`.padStart(2, "0")
|
||||
let fecha = `${date.getDate().toString().padStart(2, "0")}/${mes}/${date.getFullYear()}`;
|
||||
|
||||
// let dataDireccion = guias[0].direcciondestinatario.split(':');
|
||||
|
||||
// let direccionEntrega = dataDireccion[0];
|
||||
let direccionEntrega = guias[0].direcciondestinatario;
|
||||
let numeroPedido = guias[0].numeropedido;
|
||||
let cantidad = guias.length;
|
||||
let telefonoMovil = guias[0].telefonodestinatario.slice(-9);
|
||||
let emailDestinatario = guias[0].informacionadicional;
|
||||
|
||||
const dataPedidosHeader = await PedidosHeader.findOne({
|
||||
where: {
|
||||
NROPED_PH: numeroPedido
|
||||
}
|
||||
})
|
||||
|
||||
let referenciaDireccion = '';
|
||||
|
||||
if (dataPedidosHeader) {
|
||||
referenciaDireccion = dataPedidosHeader.referencia_ph;
|
||||
|
||||
}
|
||||
|
||||
let dataGuia = {
|
||||
// Identificador del Servicio
|
||||
linea: linea,
|
||||
id_contrato: idContrato,
|
||||
|
||||
// Identificador del Envío
|
||||
cod_rastreo: `URB${numeroPedido}`,
|
||||
cod_barra: '',//no requerido
|
||||
fech_emi_vent: fecha,//no requerido
|
||||
nro_o_compra: '',//no requerido
|
||||
nro_guia_trans: idGuia,//no requerido
|
||||
|
||||
// Datos del Seller / Vendedor
|
||||
venta_seller: '', //no requerido
|
||||
sell_codigo: '', //no requerido
|
||||
sell_nombre: '', //no requerido
|
||||
sell_direcc: '', //no requerido
|
||||
sell_ubigeo: '', //no requerido
|
||||
|
||||
// Datos del receptor (Cliente)
|
||||
cod_cliente: guias[0].codcliente,
|
||||
nom_cliente: guias[0].nombredestinatario,
|
||||
nom_empresa: '', //no requerido
|
||||
nro_telf: '', //no requerido
|
||||
nro_telf_mobil: telefonoMovil,//no requerido
|
||||
correo_elec: emailDestinatario,//no requerido
|
||||
|
||||
// Dirección de entrega
|
||||
dir_entrega: direccionEntrega,
|
||||
nro_via: '',
|
||||
nro_int: '',
|
||||
nro_urb: '',//no requerido
|
||||
ubi_direc: guias[0].ubigeodestino,
|
||||
ref_direc: referenciaDireccion,//no requerido
|
||||
id_direc: '',//no requerido
|
||||
|
||||
// Datos para despachos
|
||||
peso_total: guias[0].pesopaquetes,
|
||||
// pieza_total: cantidad,
|
||||
pieza_total: 1,
|
||||
urgente: '',//no requerido
|
||||
picking: '',//no requerido
|
||||
asegurado: '',//no requerido
|
||||
monto_asegurado: '',//no requerido
|
||||
via_aereo: '',//no requerido
|
||||
|
||||
// Datos para la entrega
|
||||
// de aqui en adelante no son requeridos
|
||||
fech_pro: '',
|
||||
arco_hor: '',
|
||||
fech_venc: '',
|
||||
|
||||
// Datos autorizados para entrega
|
||||
nom_autorizado: '',
|
||||
nro_doc_autorizado: '',
|
||||
nom_autorizado_2: '',
|
||||
nro_doc_autorizado_2: '',
|
||||
|
||||
// Datos para Cobranza
|
||||
med_pago: '',
|
||||
descripcion: '',
|
||||
anotacion: '',
|
||||
moneda: '',
|
||||
importe: '',
|
||||
tipo_empaque: '',
|
||||
};
|
||||
|
||||
|
||||
guias.forEach(async entry => {
|
||||
entry.set({
|
||||
estado: 1
|
||||
});
|
||||
await entry.save();
|
||||
})
|
||||
|
||||
const payload = dataGuia;
|
||||
|
||||
console.log(JSON.stringify(payload, null, 2))
|
||||
|
||||
try {
|
||||
const res = await sendData(url, null, payload);
|
||||
await guardarRespuesta(idGuia, 1, res, payload);
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error en el envío de guía:", error);
|
||||
await guardarRespuesta(idGuia, 0, { error: -1, mensaje: "Error en el envío de guía" }, payload);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
const guardarRespuesta = async (idGuia, estado = 1, respuesta, payloadRequest) => {
|
||||
|
||||
const date = moment().tz("America/Santiago").utc().format();
|
||||
|
||||
let dataRespuesta;
|
||||
if (respuesta.error >= 0) {
|
||||
console.log("aca")
|
||||
console.log(respuesta)
|
||||
dataRespuesta = {
|
||||
numeroguia: respuesta.guia,
|
||||
id: idGuia,
|
||||
fecha: date,
|
||||
descripcion: respuesta.etiqueta,
|
||||
mensajeerror: JSON.stringify(respuesta),
|
||||
json_guia: JSON.stringify(payloadRequest),
|
||||
estado: estado
|
||||
|
||||
}
|
||||
} else {
|
||||
dataRespuesta = {
|
||||
numeroguia: respuesta.numeroguia,
|
||||
id: idGuia,
|
||||
fecha: date,
|
||||
mensajeerror: JSON.stringify(respuesta),
|
||||
estado: estado,
|
||||
json_guia: JSON.stringify(payloadRequest),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
await RespuestaGuia.create(dataRespuesta);
|
||||
|
||||
}
|
||||
|
||||
export {
|
||||
enviarGuias
|
||||
}
|
||||
75
src/services/parche.js
Normal file
75
src/services/parche.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import { Sequelize } from "sequelize";
|
||||
import dbs from '../database/UC/config/config.json' assert {type: 'json'};
|
||||
|
||||
const dbCentralConfig = dbs.dbParche;
|
||||
const dbEcommerceConfig = dbs.dbParcheEcommerce;
|
||||
|
||||
const dbCentral = new Sequelize(dbCentralConfig.database, dbCentralConfig.username, dbCentralConfig.password, {
|
||||
host: dbCentralConfig.host,
|
||||
dialect: dbCentralConfig.dialect,
|
||||
port: dbCentralConfig.port,
|
||||
define: {
|
||||
freezeTableName: true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const dbEcommerce = new Sequelize(dbEcommerceConfig.database, dbEcommerceConfig.username, dbEcommerceConfig.password, {
|
||||
host: dbEcommerceConfig.host,
|
||||
dialect: dbEcommerceConfig.dialect,
|
||||
port: dbEcommerceConfig.port,
|
||||
define: {
|
||||
freezeTableName: true
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
const data = await dbCentral.query(`select shgroup_ph from pedidos_header where ecommerceorigen_ph='forusapp' and fecped_ph >= '2024-01-22'
|
||||
and length(trim(direccion2_ph))=0 and estado_ph=1`);
|
||||
|
||||
for (const element of data[0]) {
|
||||
const campoSh = element.shgroup_ph
|
||||
console.log(campoSh)
|
||||
|
||||
|
||||
const dataLog = await dbEcommerce.query(`select * from log_ordenes_fapp where shGroup = ${campoSh}`);
|
||||
|
||||
const jsonData = dataLog[0][0].json;
|
||||
|
||||
console.log(dataLog)
|
||||
const neighborhood = jsonData.shippingData.neighborhood
|
||||
console.log(jsonData.shippingData.neighborhood)
|
||||
|
||||
await dbCentral.query(`update pedidos_header set direccion2_ph='${neighborhood}' where shgroup_ph='${campoSh}'`);
|
||||
await dbEcommerce.query(`update pedidos_header set direccion2_ph='${neighborhood}' where shgroup_ph='${campoSh}'`);
|
||||
}
|
||||
// data[0].forEach(async element => {
|
||||
|
||||
|
||||
// });
|
||||
// console.log(JSON.stringify(data, null, 2))
|
||||
// let campoSh = data[0][0].shgroup_ph
|
||||
// let campoSh = data[0][0].shgroup_ph
|
||||
|
||||
// const dataLog = await dbEcommerce.query(`select * from log_ordenes_fapp where shGroup = ${campoSh}`);
|
||||
|
||||
// const jsonData = dataLog[0][0].json;
|
||||
|
||||
// console.log(dataLog)
|
||||
// const neighborhood = jsonData.shippingData.neighborhood
|
||||
// console.log(jsonData.shippingData.neighborhood)
|
||||
|
||||
// await dbCentral.query(`update pedidos_header set direccion2_ph='${neighborhood}' where shgroup_ph='${campoSh}'`);
|
||||
// await dbEcommerce.query(`update pedidos_header set direccion2_ph='${neighborhood}' where shgroup_ph='${campoSh}'`);
|
||||
|
||||
|
||||
|
||||
// // "username": "sialuc",
|
||||
// // "password": "Sialuc2930.,",
|
||||
// // "database": "centraluc",
|
||||
// // "host": "201.236.140.150",
|
||||
// // "dialect": "mysql",
|
||||
// // "port": "3397"
|
||||
46
src/utils/logger.js
Normal file
46
src/utils/logger.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import winston from 'winston';
|
||||
|
||||
const cronLogFilter = winston.format((info, opts) => {
|
||||
return info.proceso === 'cron' ? info : false;
|
||||
});
|
||||
|
||||
const apiLogFilter = winston.format((info, opts) => {
|
||||
return info.proceso === 'api' ? info : false;
|
||||
});
|
||||
|
||||
const borrarCampoProceso = winston.format((info) => {
|
||||
//Evita que aparezca el campo proceso en el log.
|
||||
|
||||
delete info.proceso;
|
||||
return info;
|
||||
});
|
||||
|
||||
const logger = winston.createLogger({
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
filename: 'cron.log',
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
cronLogFilter(),
|
||||
borrarCampoProceso(),
|
||||
winston.format.json()
|
||||
)
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: 'api.log',
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
apiLogFilter(),
|
||||
borrarCampoProceso(),
|
||||
winston.format.json()
|
||||
)
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
export default logger;
|
||||
78
src/utils/utils.js
Normal file
78
src/utils/utils.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import fetch from 'node-fetch';
|
||||
import { Op } from 'sequelize';
|
||||
|
||||
import config from '../services/config.json' assert {type: 'json'};
|
||||
import { interval } from 'date-fns';
|
||||
|
||||
const dataUrbano = config.dataUrbano;
|
||||
const dataInfracommerce = config.dataInfracommerce;
|
||||
|
||||
const sendData = async (url, token = null, payload) => {
|
||||
|
||||
try {
|
||||
const headers = {
|
||||
// 'Authorization': `Bearer ${token}`,
|
||||
'user': dataUrbano.userHeader,
|
||||
'pass': dataUrbano.passHeader,
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: `json=${JSON.stringify(payload)}`
|
||||
};
|
||||
|
||||
const response = await fetch(url, options);
|
||||
|
||||
const result = await response.json();
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return error;
|
||||
}
|
||||
};
|
||||
|
||||
const sendRequestInfracommerce = async (payload, url) => {
|
||||
// if (!omsId) {
|
||||
// throw new Error('omsId no proporcionado');
|
||||
// }
|
||||
|
||||
// const url = dataEnvioEstados.url.replace(':oms_id', omsId);
|
||||
const { AppKey, AppToken } = dataInfracommerce;
|
||||
|
||||
console.log(AppKey, AppToken)
|
||||
|
||||
try {
|
||||
const headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'OMS-AppKey': AppKey,
|
||||
'OMS-AppTok': AppToken
|
||||
};
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const res = await response.json();
|
||||
const data = JSON.stringify(res, null, 2);
|
||||
throw new Error(`Error en la solicitud: ${response.status} ${data}`);
|
||||
}
|
||||
const result = await response.json();
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
sendData,
|
||||
sendRequestInfracommerce
|
||||
}
|
||||
36
src/v1/routes/index.js
Normal file
36
src/v1/routes/index.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Router } from 'express';
|
||||
const router = Router();
|
||||
|
||||
import { enviarGuiasController } from '../../controllers/guiasController.js';
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
|
||||
* /api/v1/guias/{idGuia}/nueva:
|
||||
* get:
|
||||
*
|
||||
* summary: Obtener información de una guía específica.
|
||||
* description: Retorna detalles de una guía según su ID.
|
||||
* parameters:
|
||||
* - in: path
|
||||
* tittle: Test api
|
||||
* name: idGuia
|
||||
* schema:
|
||||
* type: string
|
||||
* required: true
|
||||
* description: ID único de la guía.
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Guía enviada exitosamente.
|
||||
* 404:
|
||||
* description: La guía no fue encontrada.
|
||||
* 500:
|
||||
* description: Error interno del servidor.
|
||||
* operationId: obtenerGuiaPorId
|
||||
|
||||
*/
|
||||
|
||||
router
|
||||
.get('/:idGuia/nueva', enviarGuiasController)
|
||||
|
||||
export default router;
|
||||
30
swagger.js
Normal file
30
swagger.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// swagger.js
|
||||
|
||||
import swaggerJSDoc from 'swagger-jsdoc';
|
||||
import swaggerUI from 'swagger-ui-express';
|
||||
|
||||
const options = {
|
||||
definition: {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'API envío de Guías',
|
||||
// version: '1.0.0',
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
apis: ['./src/v1/routes/*.js', './src/v1/controllers/*.js'], // Rutas donde se encuentran tus archivos de especificación Swagger
|
||||
swaggerOptions: {
|
||||
// Cambia el nombre del grupo de rutas
|
||||
tags: [
|
||||
{
|
||||
name: 'GrupoDeRutas', // Cambia este nombre
|
||||
description: 'Descripción del grupo de rutas',
|
||||
},
|
||||
],
|
||||
defaultTag: 'OtraEtiqueta',
|
||||
},
|
||||
};
|
||||
|
||||
const swaggerSpec = swaggerJSDoc(options);
|
||||
|
||||
export { swaggerSpec, swaggerUI };
|
||||
Reference in New Issue
Block a user