This commit is contained in:
parent
7e3660aece
commit
854447f7c1
|
@ -1,5 +1,6 @@
|
|||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
const ejs = require('ejs');
|
||||
const {DOMParser} = require('xmldom');
|
||||
|
||||
module.exports = Self => {
|
||||
|
@ -21,7 +22,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.deleteExpedition = async expeditionFk => {
|
||||
Self.cancelShipment = async expeditionFk => {
|
||||
const models = Self.app.models;
|
||||
|
||||
const mrw = await models.MrwConfig.findOne();
|
||||
|
@ -39,8 +40,7 @@ module.exports = Self => {
|
|||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||
const resultElement = xmlDoc.getElementsByTagName('Mensaje')[0];
|
||||
const result = resultElement.textContent;
|
||||
|
||||
return result;
|
||||
return resultElement.textContent;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -4,8 +4,8 @@ const fs = require('fs');
|
|||
const ejs = require('ejs');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('shipmentCreation', {
|
||||
description: 'Create an expedition and return a label',
|
||||
Self.remoteMethod('createShipment', {
|
||||
description: 'Create an expedition and return a base64Binary label',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'expeditionFk',
|
||||
|
@ -17,12 +17,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/shipmentCreation`,
|
||||
path: `/createShipment`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.shipmentCreation = async expeditionFk => {
|
||||
Self.createShipment = async expeditionFk => {
|
||||
const models = Self.app.models;
|
||||
const mrw = await models.MrwConfig.findOne();
|
||||
|
||||
|
@ -56,7 +56,7 @@ module.exports = Self => {
|
|||
WHERE e.id = ?`, [expeditionFk]
|
||||
);
|
||||
|
||||
const shipmentTemplate = fs.readFileSync(__dirname + '/shipmentCreation.ejs', 'utf-8');
|
||||
const shipmentTemplate = fs.readFileSync(__dirname + '/createShipment.ejs', 'utf-8');
|
||||
const renderedShipment = ejs.render(shipmentTemplate, {mrw, expeditionData});
|
||||
const shipmentResponse = await axios.post(mrw.url, renderedShipment, {
|
||||
headers: {
|
||||
|
@ -75,7 +75,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
const getLableXmlDoc = parser.parseFromString(getLabelResponse.data, 'text/xml');
|
||||
const base64Binary = getLableXmlDoc.getElementsByTagName('EtiquetaFile')[0].textContent;
|
||||
const base64Binary = getLableXmlDoc.getElementsByTagName('EtiquetaFile')[0]?.textContent;
|
||||
|
||||
const expedition = await models.Expedition.findById(expeditionFk);
|
||||
await expedition.updateAttribute('externalId', shipmentId);
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/mrw-config/shipmentCreation')(Self);
|
||||
require('../methods/mrw-config/createShipment')(Self);
|
||||
require('../methods/mrw-config/cancelShipment')(Self);
|
||||
};
|
||||
|
|
|
@ -1,38 +1,36 @@
|
|||
CREATE TABLE IF NOT EXISTS vn.mrwConfig (
|
||||
id INT auto_increment NULL,
|
||||
url varchar(100) NULL,
|
||||
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,
|
||||
`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;
|
||||
|
||||
ALTER TABLE `vn`.`packingSite` ADD `hasNewLabelMrwMethod` BOOL NULL;
|
||||
|
||||
INSERT INTO vn.mrwConfig (url, `user`,password,franchiseCode,subscriberCode)
|
||||
INSERT INTO `vn`.`mrwConfig` (`url`, `user`, `password`, `franchiseCode`, `subscriberCode`)
|
||||
VALUES ('https://sagec-test.mrw.es/MRWEnvio.asmx', '04301SGVERDNATURA', 'Verdnatura@4301V', '04301', '009731');
|
||||
|
||||
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES('MrwConfig', 'cancelShipment', 'WRITE', 'ALLOW', 'ROLE', 'employee');
|
||||
|
||||
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 `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`)
|
||||
VALUES ('MrwConfig','createShipment','WRITE','ALLOW','ROLE','employee');
|
||||
|
||||
|
||||
INSERT INTO vn.agency (name,warehouseFk,warehouseAliasFk,isOwn,isAnyVolumeAllowed)
|
||||
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)
|
||||
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`.`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
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue