diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 23b62e845..70a68acd6 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -26,42 +26,6 @@ module.exports = Self => { if (typeof options == 'object') 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({ fields: ['id', 'ticketFk'], where: {id: expeditionFk}, @@ -141,20 +105,28 @@ module.exports = Self => { } ] }, 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 = ` - ${data.defaultWeight} + ${viaexpressConfig.defaultWeight} 1 0 - ${data.shipped} + ${date} 0 - ${data.deliveryType} + ${viaexpressConfig.deliveryType} 0 0 0 @@ -166,31 +138,31 @@ module.exports = Self => { - ${data.senderName} - ${data.senderStreet} - ${data.senderPostalCode} - ${data.senderCity} - ${data.senderProvince} + ${expedition.ticket().company().client().socialName} + ${expedition.ticket().company().client().defaultAddress().street} + ${expedition.ticket().company().client().defaultAddress().postalCode} + ${expedition.ticket().company().client().defaultAddress().city} + ${expedition.ticket().company().client().defaultAddress().province().name} - ${data.senderPhone} - ${data.senderEmail} + ${expedition.ticket().company().client().defaultAddress().mobile || expedition.ticket().company().client().defaultAddress().phone || expedition.ticket().company().client().mobile || expedition.ticket().company().client().phone} + ${expedition.ticket().company().client().email} - ${data.receiverName} - ${data.receiverStreet} - ${data.receiverPostalCode} - ${data.receiverCity} + ${expedition.ticket().address().nickname} + ${expedition.ticket().address().street} + ${expedition.ticket().address().postalCode} + ${expedition.ticket().address().city} - ${data.receiverProvince} + ${expedition.ticket().address().province().name} - ${data.receiverPhone} - ${data.receiverEmail} - ${data.receiverCountry} + ${expedition.ticket().address().mobile || expedition.ticket().address().phone || expedition.ticket().client().mobile || expedition.ticket().client().phone} + ${expedition.ticket().client().email} + ${expedition.ticket().address().province().country().code} - ${data.clientViaexpress} - ${data.userViaexpress} - ${data.passwordViaexpress} + ${viaexpressConfig.clientViaexpress} + ${viaexpressConfig.userViaexpress} + ${viaexpressConfig.passwordViaexpress} @@ -198,7 +170,7 @@ module.exports = Self => { `; try { - const response = await axios.post(`${data.url}ServicioVxClientes.asmx`, xmlData, { + const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, xmlData, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' } diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 5927cee3f..26d6c8e37 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -16,19 +16,19 @@ "required": true }, "clientViaexpress": { - "type": "date" + "type": "string" }, "userViaexpress": { - "type": "number" + "type": "string" }, "passwordViaexpress": { - "type": "number" + "type": "string" }, "defaultWeight": { "type": "number" }, "deliveryType": { - "type": "number" + "type": "string" } } }