refs #4734 refactor: use loopback instead of
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-06-19 11:55:07 +02:00
parent 219ad75172
commit 303be74382
2 changed files with 36 additions and 64 deletions

View File

@ -26,42 +26,6 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const [data] = await Self.rawSql(`
SELECT
url,
clientViaexpress,
userViaexpress,
passwordViaexpress,
defaultWeight,
deliveryType,
DATE_FORMAT(t.shipped, '%Y-%m-%d') shipped,
cv.socialName senderName,
av.street senderStreet,
av.postalCode senderPostalCode,
av.city senderCity,
pv.name senderProvince,
IFNULL(av.mobile, IFNULL(av.phone, IFNULL(cv.mobile, cv.phone))) senderPhone,
SUBSTRING_INDEX(cv.email, ',', 1) senderEmail,
a.nickname receiverName,
a.street receiverStreet,
a.postalCode receiverPostalCode,
a.city receiverCity,
p.name receiverProvince,
IFNULL(a.mobile, IFNULL(a.phone, IFNULL(c.mobile, c.phone))) receiverPhone,
SUBSTRING_INDEX(c.email, ',', 1) receiverEmail,
c2.code receiverCountry
FROM vn.viaexpressConfig
JOIN vn.expedition e ON e.id = ?
JOIN vn.ticket t ON t.id = e.ticketFk
JOIN vn.address a ON a.id = t.addressFk
JOIN vn.province p ON p.id = a.provinceFk
JOIN vn.client c ON c.id = t.clientFk
JOIN vn.company co ON co.id = t.companyFk
JOIN vn.client cv ON cv.id = co.clientFk
JOIN vn.address av ON av.id = cv.defaultAddressFk
JOIN vn.province pv ON pv.id = av.provinceFk
JOIN vn.country c2 ON c2.id = p.countryFk`, [expeditionFk], myOptions);
const expedition = await models.Expedition.findOne({ const expedition = await models.Expedition.findOne({
fields: ['id', 'ticketFk'], fields: ['id', 'ticketFk'],
where: {id: expeditionFk}, where: {id: expeditionFk},
@ -141,20 +105,28 @@ module.exports = Self => {
} }
] ]
}, myOptions); }, myOptions);
console.log(data);
console.log(expedition); const viaexpressConfig = await models.ViaexpressConfig.findOne({
fields: ['url', 'clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType']
}, myOptions);
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 xmlData = `<?xml version="1.0" encoding="utf-8"?> const xmlData = `<?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: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> <soap12:Body>
<PutExpedicionInternacional xmlns="http://82.223.6.71:82"> <PutExpedicionInternacional xmlns="http://82.223.6.71:82">
<ObjetoEnvio> <ObjetoEnvio>
<Peso>${data.defaultWeight}</Peso> <Peso>${viaexpressConfig.defaultWeight}</Peso>
<Bultos>1</Bultos> <Bultos>1</Bultos>
<Reembolso>0</Reembolso> <Reembolso>0</Reembolso>
<Fecha>${data.shipped}</Fecha> <Fecha>${date}</Fecha>
<ConRetorno>0</ConRetorno> <ConRetorno>0</ConRetorno>
<Tipo>${data.deliveryType}</Tipo> <Tipo>${viaexpressConfig.deliveryType}</Tipo>
<Debidos>0</Debidos> <Debidos>0</Debidos>
<Asegurado>0</Asegurado> <Asegurado>0</Asegurado>
<Imprimir>0</Imprimir> <Imprimir>0</Imprimir>
@ -166,31 +138,31 @@ module.exports = Self => {
<TextoAgencia></TextoAgencia> <TextoAgencia></TextoAgencia>
<Terminal></Terminal> <Terminal></Terminal>
<ObjetoRemitente> <ObjetoRemitente>
<RazonSocial>${data.senderName}</RazonSocial> <RazonSocial>${expedition.ticket().company().client().socialName}</RazonSocial>
<Domicilio>${data.senderStreet}</Domicilio> <Domicilio>${expedition.ticket().company().client().defaultAddress().street}</Domicilio>
<Cpostal>${data.senderPostalCode}</Cpostal> <Cpostal>${expedition.ticket().company().client().defaultAddress().postalCode}</Cpostal>
<Poblacion>${data.senderCity}</Poblacion> <Poblacion>${expedition.ticket().company().client().defaultAddress().city}</Poblacion>
<Provincia>${data.senderProvince}</Provincia> <Provincia>${expedition.ticket().company().client().defaultAddress().province().name}</Provincia>
<Contacto></Contacto> <Contacto></Contacto>
<Telefono>${data.senderPhone}</Telefono> <Telefono>${expedition.ticket().company().client().defaultAddress().mobile || expedition.ticket().company().client().defaultAddress().phone || expedition.ticket().company().client().mobile || expedition.ticket().company().client().phone}</Telefono>
<Email>${data.senderEmail}</Email> <Email>${expedition.ticket().company().client().email}</Email>
</ObjetoRemitente> </ObjetoRemitente>
<ObjetoDestinatario> <ObjetoDestinatario>
<RazonSocial>${data.receiverName}</RazonSocial> <RazonSocial>${expedition.ticket().address().nickname}</RazonSocial>
<Domicilio>${data.receiverStreet}</Domicilio> <Domicilio>${expedition.ticket().address().street}</Domicilio>
<Cpostal>${data.receiverPostalCode}</Cpostal> <Cpostal>${expedition.ticket().address().postalCode}</Cpostal>
<Poblacion>${data.receiverCity}</Poblacion> <Poblacion>${expedition.ticket().address().city}</Poblacion>
<Municipio></Municipio> <Municipio></Municipio>
<Provincia>${data.receiverProvince}</Provincia> <Provincia>${expedition.ticket().address().province().name}</Provincia>
<Contacto></Contacto> <Contacto></Contacto>
<Telefono>${data.receiverPhone}</Telefono> <Telefono>${expedition.ticket().address().mobile || expedition.ticket().address().phone || expedition.ticket().client().mobile || expedition.ticket().client().phone}</Telefono>
<Email>${data.receiverEmail}</Email> <Email>${expedition.ticket().client().email}</Email>
<Pais>${data.receiverCountry}</Pais> <Pais>${expedition.ticket().address().province().country().code}</Pais>
</ObjetoDestinatario> </ObjetoDestinatario>
<ObjetoLogin> <ObjetoLogin>
<IdCliente>${data.clientViaexpress}</IdCliente> <IdCliente>${viaexpressConfig.clientViaexpress}</IdCliente>
<Usuario>${data.userViaexpress}</Usuario> <Usuario>${viaexpressConfig.userViaexpress}</Usuario>
<Password>${data.passwordViaexpress}</Password> <Password>${viaexpressConfig.passwordViaexpress}</Password>
</ObjetoLogin> </ObjetoLogin>
</ObjetoEnvio> </ObjetoEnvio>
</PutExpedicionInternacional> </PutExpedicionInternacional>
@ -198,7 +170,7 @@ module.exports = Self => {
</soap12:Envelope>`; </soap12:Envelope>`;
try { try {
const response = await axios.post(`${data.url}ServicioVxClientes.asmx`, xmlData, { const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, xmlData, {
headers: { headers: {
'Content-Type': 'application/soap+xml; charset=utf-8' 'Content-Type': 'application/soap+xml; charset=utf-8'
} }

View File

@ -16,19 +16,19 @@
"required": true "required": true
}, },
"clientViaexpress": { "clientViaexpress": {
"type": "date" "type": "string"
}, },
"userViaexpress": { "userViaexpress": {
"type": "number" "type": "string"
}, },
"passwordViaexpress": { "passwordViaexpress": {
"type": "number" "type": "string"
}, },
"defaultWeight": { "defaultWeight": {
"type": "number" "type": "number"
}, },
"deliveryType": { "deliveryType": {
"type": "number" "type": "string"
} }
} }
} }