2023-06-13 13:05:37 +00:00
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
module.exports = Self => {
|
2023-06-16 11:49:21 +00:00
|
|
|
Self.remoteMethod('internationalExpedition', {
|
2023-06-20 05:19:32 +00:00
|
|
|
description: 'Create an expedition and return a label',
|
2023-06-13 13:05:37 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'expeditionFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2023-06-16 11:49:21 +00:00
|
|
|
path: `/internationalExpedition`,
|
2023-06-13 13:05:37 +00:00
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-06-19 12:27:24 +00:00
|
|
|
Self.internationalExpedition = async expeditionFk => {
|
2023-06-16 12:24:47 +00:00
|
|
|
const models = Self.app.models;
|
2023-06-19 09:55:07 +00:00
|
|
|
|
|
|
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
2023-06-19 12:27:24 +00:00
|
|
|
fields: ['url']
|
|
|
|
});
|
2023-06-19 09:55:07 +00:00
|
|
|
|
2023-06-19 12:27:24 +00:00
|
|
|
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, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log(response);
|
|
|
|
const startTag = '<ReferenciaVx>';
|
|
|
|
const endTag = '</ReferenciaVx>';
|
|
|
|
const startIndex = response.data.indexOf(startTag) + startTag.length;
|
|
|
|
const endIndex = response.data.indexOf(endTag);
|
|
|
|
const referenciaVx = response.data.substring(startIndex, endIndex);
|
2023-06-16 12:24:47 +00:00
|
|
|
|
2023-06-19 12:27:24 +00:00
|
|
|
return referenciaVx;
|
2023-06-13 13:05:37 +00:00
|
|
|
};
|
|
|
|
};
|