refs #4734 feat: se utiliza la libreria ejs y xmldom
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
13e95bcd35
commit
4444b45b08
|
@ -1,4 +1,5 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const {DOMParser} = require('xmldom');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('internationalExpedition', {
|
Self.remoteMethod('internationalExpedition', {
|
||||||
|
@ -27,69 +28,17 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk);
|
||||||
// const renderedXml = `<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
// <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
|
||||||
// <soap12:Body>
|
|
||||||
// <PutExpedicionInternacional xmlns="http://82.223.6.71:82">
|
|
||||||
// <ObjetoEnvio>
|
|
||||||
// <Peso>10</Peso>
|
|
||||||
// <Bultos>1</Bultos>
|
|
||||||
// <Reembolso>0</Reembolso>
|
|
||||||
// <Fecha>2023-06-12</Fecha>
|
|
||||||
// <ConRetorno>0</ConRetorno>
|
|
||||||
// <Tipo>E</Tipo>
|
|
||||||
// <Debidos>0</Debidos>
|
|
||||||
// <Asegurado>0</Asegurado>
|
|
||||||
// <Imprimir>0</Imprimir>
|
|
||||||
// <ConDevolucionAlbaran>0</ConDevolucionAlbaran>
|
|
||||||
// <Intradia>0</Intradia>
|
|
||||||
// <Observaciones></Observaciones>
|
|
||||||
// <AlbaranRemitente></AlbaranRemitente>
|
|
||||||
// <Modo>0</Modo>
|
|
||||||
// <TextoAgencia></TextoAgencia>
|
|
||||||
// <Terminal></Terminal>
|
|
||||||
// <ObjetoRemitente>
|
|
||||||
// <RazonSocial>VERDNATURA LEVANTE SL</RazonSocial>
|
|
||||||
// <Domicilio>FENOLLARS, 2</Domicilio>
|
|
||||||
// <Cpostal>46680</Cpostal>
|
|
||||||
// <Poblacion>Algemesi</Poblacion>
|
|
||||||
// <Provincia>Valencia</Provincia>
|
|
||||||
// <Contacto></Contacto>
|
|
||||||
// <Telefono>963677177</Telefono>
|
|
||||||
// <Email>pako.natek@gmail.com</Email>
|
|
||||||
// </ObjetoRemitente>
|
|
||||||
// <ObjetoDestinatario>
|
|
||||||
// <RazonSocial>ROSAMARY FLORISTERIA</RazonSocial>
|
|
||||||
// <Domicilio>C SANTA ROSA,25</Domicilio>
|
|
||||||
// <Cpostal>03802</Cpostal>
|
|
||||||
// <Poblacion>ALCOY</Poblacion>
|
|
||||||
// <Municipio>ALCOY</Municipio>
|
|
||||||
// <Provincia>Alicante</Provincia>
|
|
||||||
// <Contacto></Contacto>
|
|
||||||
// <Telefono>653967489</Telefono>
|
|
||||||
// <Email>correo@floristeriarosamary.com</Email>
|
|
||||||
// <Pais>ES</Pais>
|
|
||||||
// </ObjetoDestinatario>
|
|
||||||
// <ObjetoLogin>
|
|
||||||
// <IdCliente>16092</IdCliente>
|
|
||||||
// <Usuario>B97367486</Usuario>
|
|
||||||
// <Password>VERDNA22</Password>
|
|
||||||
// </ObjetoLogin>
|
|
||||||
// </ObjetoEnvio>
|
|
||||||
// </PutExpedicionInternacional>
|
|
||||||
// </soap12:Body>
|
|
||||||
// </soap12:Envelope>`;
|
|
||||||
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(response);
|
|
||||||
const startTag = '<ReferenciaVx>';
|
const xmlString = response.data;
|
||||||
const endTag = '</ReferenciaVx>';
|
const parser = new DOMParser();
|
||||||
const startIndex = response.data.indexOf(startTag) + startTag.length;
|
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||||
const endIndex = response.data.indexOf(endTag);
|
const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0];
|
||||||
const referenciaVx = response.data.substring(startIndex, endIndex);
|
const referenciaVx = referenciaVxElement.textContent;
|
||||||
|
|
||||||
return referenciaVx;
|
return referenciaVx;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const handlebars = require('handlebars');
|
const ejs = require('ejs');
|
||||||
// const Vue = require('vue');
|
|
||||||
// const renderer = require('vue-server-renderer').createRenderer();
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('renderer', {
|
Self.remoteMethod('renderer', {
|
||||||
|
@ -110,14 +108,10 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const shipped = expedition.ticket().shipped;
|
const shipped = expedition.ticket().shipped;
|
||||||
const year = shipped.getFullYear();
|
|
||||||
const month = shipped.getMonth() + 1;
|
|
||||||
const day = shipped.getDate();
|
|
||||||
const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
defaultWeight: viaexpressConfig.defaultWeight,
|
defaultWeight: viaexpressConfig.defaultWeight,
|
||||||
date: date, // const date = new Date().toISOString();
|
date: shipped.toISOString(), // const date = new Date().toISOString();
|
||||||
deliveryType: viaexpressConfig.deliveryType,
|
deliveryType: viaexpressConfig.deliveryType,
|
||||||
senderName: expedition.ticket().company().client().socialName,
|
senderName: expedition.ticket().company().client().socialName,
|
||||||
senderStreet: expedition.ticket().company().client().defaultAddress().street,
|
senderStreet: expedition.ticket().company().client().defaultAddress().street,
|
||||||
|
@ -145,20 +139,8 @@ module.exports = Self => {
|
||||||
passwordViaexpress: viaexpressConfig.passwordViaexpress
|
passwordViaexpress: viaexpressConfig.passwordViaexpress
|
||||||
};
|
};
|
||||||
|
|
||||||
const templateXml = fs.readFileSync(__dirname + '/template.xml', 'utf-8');
|
const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8');
|
||||||
|
const renderedXml = ejs.render(template, data);
|
||||||
// // Crea una instancia de Vue con los datos
|
return renderedXml;
|
||||||
// const vueInstance = new Vue({
|
|
||||||
// data: data,
|
|
||||||
// template: templateXml,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // Renderiza la plantilla con los datos utilizando vue-server-renderer
|
|
||||||
// const renderer = createRenderer();
|
|
||||||
// return renderer.renderToString(vueInstance);
|
|
||||||
|
|
||||||
const compiledTemplate = handlebars.compile(templateXml);
|
|
||||||
const renderedHtml = compiledTemplate(data);
|
|
||||||
return renderedHtml;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
||||||
|
<soap12:Body>
|
||||||
|
<PutExpedicionInternacional xmlns="http://82.223.6.71:82">
|
||||||
|
<ObjetoEnvio>
|
||||||
|
<Peso><%= defaultWeight %></Peso>
|
||||||
|
<Bultos>1</Bultos>
|
||||||
|
<Reembolso>0</Reembolso>
|
||||||
|
<Fecha><%= date %></Fecha>
|
||||||
|
<ConRetorno>0</ConRetorno>
|
||||||
|
<Tipo><%= deliveryType %></Tipo>
|
||||||
|
<Debidos>0</Debidos>
|
||||||
|
<Asegurado>0</Asegurado>
|
||||||
|
<Imprimir>0</Imprimir>
|
||||||
|
<ConDevolucionAlbaran>0</ConDevolucionAlbaran>
|
||||||
|
<Intradia>0</Intradia>
|
||||||
|
<Observaciones></Observaciones>
|
||||||
|
<AlbaranRemitente></AlbaranRemitente>
|
||||||
|
<Modo>0</Modo>
|
||||||
|
<TextoAgencia></TextoAgencia>
|
||||||
|
<Terminal></Terminal>
|
||||||
|
<ObjetoRemitente>
|
||||||
|
<RazonSocial><%= senderName %></RazonSocial>
|
||||||
|
<Domicilio><%= senderStreet %></Domicilio>
|
||||||
|
<Cpostal><%= senderPostalCode %></Cpostal>
|
||||||
|
<Poblacion><%= senderCity %></Poblacion>
|
||||||
|
<Provincia><%= senderProvince %></Provincia>
|
||||||
|
<Contacto></Contacto>
|
||||||
|
<Telefono><%= senderPhone %></Telefono>
|
||||||
|
<Email><%= senderEmail %></Email>
|
||||||
|
</ObjetoRemitente>
|
||||||
|
<ObjetoDestinatario>
|
||||||
|
<RazonSocial><%= receiverName %></RazonSocial>
|
||||||
|
<Domicilio><%= receiverStreet %></Domicilio>
|
||||||
|
<Cpostal><%= receiverPostalCode %></Cpostal>
|
||||||
|
<Poblacion><%= receiverCity %></Poblacion>
|
||||||
|
<Municipio></Municipio>
|
||||||
|
<Provincia><%= receiverProvince %></Provincia>
|
||||||
|
<Contacto></Contacto>
|
||||||
|
<Telefono><%= receiverPhone %></Telefono>
|
||||||
|
<Email><%= receiverEmail %></Email>
|
||||||
|
<Pais><%= receiverCountry %></Pais>
|
||||||
|
</ObjetoDestinatario>
|
||||||
|
<ObjetoLogin>
|
||||||
|
<IdCliente><%= clientViaexpress %></IdCliente>
|
||||||
|
<Usuario><%= userViaexpress %></Usuario>
|
||||||
|
<Password><%= passwordViaexpress %></Password>
|
||||||
|
</ObjetoLogin>
|
||||||
|
</ObjetoEnvio>
|
||||||
|
</PutExpedicionInternacional>
|
||||||
|
</soap12:Body>
|
||||||
|
</soap12:Envelope>
|
|
@ -1,52 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
|
|
||||||
<soap12:Body>
|
|
||||||
<PutExpedicionInternacional xmlns="http://82.223.6.71:82">
|
|
||||||
<ObjetoEnvio>
|
|
||||||
<Peso>{{ defaultWeight }}</Peso>
|
|
||||||
<Bultos>1</Bultos>
|
|
||||||
<Reembolso>0</Reembolso>
|
|
||||||
<Fecha>{{ date }}</Fecha>
|
|
||||||
<ConRetorno>0</ConRetorno>
|
|
||||||
<Tipo>{{ deliveryType }}</Tipo>
|
|
||||||
<Debidos>0</Debidos>
|
|
||||||
<Asegurado>0</Asegurado>
|
|
||||||
<Imprimir>0</Imprimir>
|
|
||||||
<ConDevolucionAlbaran>0</ConDevolucionAlbaran>
|
|
||||||
<Intradia>0</Intradia>
|
|
||||||
<Observaciones></Observaciones>
|
|
||||||
<AlbaranRemitente></AlbaranRemitente>
|
|
||||||
<Modo>0</Modo>
|
|
||||||
<TextoAgencia></TextoAgencia>
|
|
||||||
<Terminal></Terminal>
|
|
||||||
<ObjetoRemitente>
|
|
||||||
<RazonSocial>{{ senderName }}</RazonSocial>
|
|
||||||
<Domicilio>{{ senderStreet }}</Domicilio>
|
|
||||||
<Cpostal>{{ senderPostalCode }}</Cpostal>
|
|
||||||
<Poblacion>{{ senderCity }}</Poblacion>
|
|
||||||
<Provincia>{{ senderProvince }}</Provincia>
|
|
||||||
<Contacto></Contacto>
|
|
||||||
<Telefono>{{ senderPhone }}</Telefono>
|
|
||||||
<Email>{{ senderEmail }}</Email>
|
|
||||||
</ObjetoRemitente>
|
|
||||||
<ObjetoDestinatario>
|
|
||||||
<RazonSocial>{{ receiverName }}</RazonSocial>
|
|
||||||
<Domicilio>{{ receiverStreet }}</Domicilio>
|
|
||||||
<Cpostal>{{ receiverPostalCode }}</Cpostal>
|
|
||||||
<Poblacion>{{ receiverCity }}</Poblacion>
|
|
||||||
<Municipio></Municipio>
|
|
||||||
<Provincia>{{ receiverProvince }}</Provincia>
|
|
||||||
<Contacto></Contacto>
|
|
||||||
<Telefono>{{ receiverPhone }}</Telefono>
|
|
||||||
<Email>{{ receiverEmail }}</Email>
|
|
||||||
<Pais>{{ receiverCountry }}</Pais>
|
|
||||||
</ObjetoDestinatario>
|
|
||||||
<ObjetoLogin>
|
|
||||||
<IdCliente>{{ clientViaexpress }}</IdCliente>
|
|
||||||
<Usuario>{{ userViaexpress }}</Usuario>
|
|
||||||
<Password>{{ passwordViaexpress }}</Password>
|
|
||||||
</ObjetoLogin>
|
|
||||||
</ObjetoEnvio>
|
|
||||||
</PutExpedicionInternacional>
|
|
||||||
</soap12:Body>
|
|
||||||
</soap12:Envelope>
|
|
Loading…
Reference in New Issue