feat(mrwXml): refs #6403 render and transmEnvio integrated
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-01-15 15:00:36 +01:00
parent f73a447391
commit 73c0ca5382
7 changed files with 215 additions and 0 deletions

View File

@ -0,0 +1,59 @@
const fs = require('fs');
const ejs = require('ejs');
module.exports = Self => {
Self.remoteMethod('renderer', {
description: 'Renders the data from an XML',
accessType: 'READ',
accepts: [{
arg: 'expeditionFk',
type: 'number',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/renderer`,
verb: 'GET'
}
});
Self.renderer = async expeditionFk => {
const mrw = await Self.app.models.MrwConfig.findOne();
const [expedition] = await Self.rawSql(
`SELECT CASE co.code
WHEN 'ES' THEN a.postalCode
WHEN 'PT' THEN LEFT(a.postalCode, 4)
WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00')
END postalCode,
a.city,
a.street,
co.code countryCode,
c.fi,
c.name clientName,
c.phone,
e.created,
e.id expeditionId,
LPAD(ms.serviceType, 4 ,'0') serviceType,
pa.height,
pa.depth,
pa.width
FROM expedition e
JOIN packaging pa ON pa.id = e.packagingFk
JOIN ticket t ON e.ticketFk = t.id
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN mrwService ms ON ms.agencyModeCodeFk = am.code
JOIN client c ON t.clientFk = c.id
JOIN address a ON t.addressFk = a.id
JOIN province p ON a.provinceFk = p.id
JOIN country co ON co.id = p.countryFk
WHERE e.id = ?`, [expeditionFk]
);
const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8');
return ejs.render(template, {mrw, expedition});
};
};

View File

@ -0,0 +1,46 @@
const axios = require('axios');
const {DOMParser} = require('xmldom');
module.exports = Self => {
Self.remoteMethod('shipmentCreation', {
description: 'Create an expedition and return a label',
accessType: 'WRITE',
accepts: [{
arg: 'expeditionFk',
type: 'number',
required: true
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/shipmentCreation`,
verb: 'POST'
}
});
Self.shipmentCreation = async expeditionFk => {
const models = Self.app.models;
const MrwConfig = await models.MrwConfig.findOne({
fields: ['url']
});
const renderedXml = await models.MrwConfig.renderer(expeditionFk);
const response = await axios.post(MrwConfig.url, renderedXml, {
headers: {
'Content-Type': 'application/soap+xml; charset=utf-8'
}
});
const xmlString = response.data;
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
const transmEnvioResponse = xmlDoc.getElementsByTagName('TransmEnvioResponse')[0];
console.log(xmlDoc.getElementsByTagName('TransmEnvioResponse'));
console.log('transmEnvioResponse: ', transmEnvioResponse);
return transmEnvioResponse.textContent;
};
};

View File

@ -0,0 +1,40 @@
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mrw="http://www.mrw.es/">
<soap:Header>
<mrw:AuthInfo>
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado>
<mrw:UserName><%= mrw.user %></mrw:UserName>
<mrw:Password><%= mrw.password %></mrw:Password>
</mrw:AuthInfo>
</soap:Header>
<soap:Body>
<mrw:TransmEnvio>
<mrw:request>
<mrw:DatosEntrega>
<mrw:Direccion>
<mrw:Via><%= expedition.street %></mrw:Via>
<mrw:CodigoPostal><%= expedition.postalCode %></mrw:CodigoPostal>
<mrw:Poblacion><%= expedition.city %></mrw:Poblacion>
<mrw:CodigoPais><%= expedition.countryCode %></mrw:CodigoPais>
</mrw:Direccion>
<mrw:Nif><%= expedition.fi %></mrw:Nif>
<mrw:Nombre><%= expedition.clientName %></mrw:Nombre>
<mrw:Telefono><%= expedition.phone %></mrw:Telefono>
</mrw:DatosEntrega>
<mrw:DatosServicio>
<mrw:Fecha><%= expedition.created %></mrw:Fecha>
<mrw:Referencia><%= expedition.expeditionId %></mrw:Referencia>
<mrw:CodigoServicio><%= expedition.serviceType %></mrw:CodigoServicio>
<mrw:Bultos>
<mrw:BultoRequest>
<mrw:Alto><%= expedition.height %></mrw:Alto>
<mrw:Largo><%= expedition.depth %></mrw:Largo>
<mrw:Ancho><%= expedition.width %></mrw:Ancho>
</mrw:BultoRequest>
</mrw:Bultos>
<mrw:Peso><%= expedition.kg %></mrw:Peso>
</mrw:DatosServicio>
</mrw:request>
</mrw:TransmEnvio>
</soap:Body>
</soap:Envelope>

View File

@ -156,6 +156,9 @@
}, },
"ViaexpressConfig": { "ViaexpressConfig": {
"dataSource": "vn" "dataSource": "vn"
},
"MrwConfig": {
"dataSource": "vn"
} }
} }

View File

@ -0,0 +1,4 @@
module.exports = Self => {
require('../methods/mrw-config/shipmentCreation')(Self);
require('../methods/mrw-config/renderer')(Self);
};

View File

@ -0,0 +1,28 @@
{
"name": "MrwConfig",
"base": "VnModel",
"options": {
"mysql": {
"table": "mrwConfig"
}
},
"properties": {
"id": {
"type": "number",
"required": true
},
"url": {
"type": "string",
"required": true
},
"user": {
"type": "string"
},
"franchiseCode": {
"type": "string"
},
"subscriberCode": {
"type": "string"
}
}
}

View File

@ -0,0 +1,35 @@
CREATE TABLE IF NOT EXISTS vn.mrwConfig (
id INT auto_increment NULL,
url varchar(100) NULL,
`user` varchar(100) NULL,
password varchar(100) NULL,
franchiseCode varchar(100) NULL,
subscriberCode varchar(100) NULL,
CONSTRAINT mrwConfig_pk PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
INSERT INTO vn.mrwConfig (url, `user`,password,franchiseCode,subscriberCode)
VALUES ('https://sagec-test.mrw.es/MRWEnvio.asmx', '04301SGVERDNATURA', 'Verdnatura@4301V', '009731', '04301');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('MrwConfig','renderer','READ','ALLOW','ROLE','employee');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('MrwConfig','shipmentCreation','WRITE','ALLOW','ROLE','employee');
INSERT INTO vn.agency (name,warehouseFk,warehouseAliasFk,isOwn,isAnyVolumeAllowed)
VALUES ('MRW',1,1,0,0);
INSERT INTO vn.agencyMode (id, name, description, deliveryMethodFk, m3, web, agencyFk, inflation, isVolumetric, reportMail, showAgencyName, isActive, isExternalAgency, flag, code, isRiskFree, hasWeightVolumetric)
VALUES(25, 'MRW', NULL, NULL, 0.0, 0, 11, 0.00, 0, NULL, 1, 1, 0, NULL, 'MRW', 0, 0);
INSERT INTO vn.ticket (id, clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight, clonedFrom, cmrFk, editorFk)
VALUES(33, 1101, 1, '2001-01-01 00:00:00.000', 'MRW', NULL, 1, NULL, NULL, 0, 0, 0, 1, NULL, 0, '2001-01-01 00:00:00.000', 1, NULL, 6, NULL, 1, 442, 25, '2001-01-02', 0, 0, 3, 5.00, 1.00, 8.88, 8.07, NULL, NULL, NULL, 100);
INSERT INTO vn.expedition (agencyModeFk,ticketFk,freightItemFk,created,counter,workerFk,packagingFk,hostFk,stateTypeFk,hasNewRoute,isBox,editorFk)
VALUES (25,33,71,'2001-01-01 01:00:00.000',1,18,'94','',3,0,71,100);