feat: refs #6403 add dynamic clientType #2714
|
@ -2,7 +2,7 @@
|
||||||
<soap:Header>
|
<soap:Header>
|
||||||
<mrw:AuthInfo>
|
<mrw:AuthInfo>
|
||||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||||
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado>
|
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||||
<mrw:CodigoDepartamento/>
|
<mrw:CodigoDepartamento/>
|
||||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||||
|
|
|
@ -27,9 +27,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
const mrw = await models.MrwConfig.findOne();
|
const mrw = await models.MrwConfig.findOne();
|
||||||
const {externalId} = await models.Expedition.findById(expeditionFk);
|
const {externalId} = await models.Expedition.findById(expeditionFk);
|
||||||
|
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||||
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
||||||
const renderedXml = ejs.render(template, {mrw, externalId});
|
const renderedXml = ejs.render(template, {mrw, externalId, clientType});
|
||||||
const response = await axios.post(mrw.url, renderedXml, {
|
const response = await axios.post(mrw.url, renderedXml, {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<soap:Header>
|
<soap:Header>
|
||||||
<mrw:AuthInfo>
|
<mrw:AuthInfo>
|
||||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||||
<mrw:CodigoAbonado><%= expeditionData.clientType %></mrw:CodigoAbonado>
|
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||||
<mrw:CodigoDepartamento/>
|
<mrw:CodigoDepartamento/>
|
||||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||||
|
|
|
@ -22,6 +22,7 @@ module.exports = Self => {
|
||||||
Self.createShipment = async expeditionFk => {
|
Self.createShipment = async expeditionFk => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const mrw = await Self.getConfig();
|
const mrw = await Self.getConfig();
|
||||||
|
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||||
|
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0];
|
const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0];
|
||||||
|
@ -52,8 +53,7 @@ module.exports = Self => {
|
||||||
CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference,
|
CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference,
|
||||||
LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType,
|
LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType,
|
||||||
IF(mw.weekdays, 'S', 'N') weekDays,
|
IF(mw.weekdays, 'S', 'N') weekDays,
|
||||||
oa.description deliveryObservation,
|
oa.description deliveryObservation
|
||||||
LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType
|
|
||||||
FROM expedition e
|
FROM expedition e
|
||||||
JOIN ticket t ON e.ticketFk = t.id
|
JOIN ticket t ON e.ticketFk = t.id
|
||||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
|
@ -73,22 +73,19 @@ module.exports = Self => {
|
||||||
|
|
||||||
const [expeditionData] = await Self.rawSql(query, [expeditionFk]);
|
const [expeditionData] = await Self.rawSql(query, [expeditionFk]);
|
||||||
|
|
||||||
if (!expeditionData)
|
|
||||||
throw new UserError(`This expedition is not a MRW shipment`);
|
|
||||||
|
|
||||||
if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0))
|
if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0))
|
||||||
throw new UserError(`This ticket has a shipped date earlier than today`);
|
throw new UserError(`This ticket has a shipped date earlier than today`);
|
||||||
|
|
||||||
const shipmentResponse = await Self.sendXmlDoc(
|
const shipmentResponse = await Self.sendXmlDoc(
|
||||||
__dirname + `/createShipment.ejs`,
|
__dirname + `/createShipment.ejs`,
|
||||||
{mrw, expeditionData},
|
{mrw, expeditionData, clientType},
|
||||||
'application/soap+xml'
|
'application/soap+xml'
|
||||||
);
|
);
|
||||||
const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio');
|
const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio');
|
||||||
|
|
||||||
if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje'));
|
if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje'));
|
||||||
|
|
||||||
const file = await models.MrwConfig.getLabel(shipmentId);
|
const file = await models.MrwConfig.getLabel(shipmentId, clientType);
|
||||||
|
|
||||||
return {shipmentId, file};
|
return {shipmentId, file};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<soapenv:Header>
|
<soapenv:Header>
|
||||||
<mrw:AuthInfo>
|
<mrw:AuthInfo>
|
||||||
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
<mrw:CodigoFranquicia><%= mrw.franchiseCode %></mrw:CodigoFranquicia>
|
||||||
<mrw:CodigoAbonado><%= mrw.subscriberCode %></mrw:CodigoAbonado>
|
<mrw:CodigoAbonado><%= clientType %></mrw:CodigoAbonado>
|
||||||
<mrw:CodigoDepartamento/>
|
<mrw:CodigoDepartamento/>
|
||||||
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
<mrw:UserName><%= mrw.user %></mrw:UserName>
|
||||||
<mrw:Password><%= mrw.password %></mrw:Password>
|
<mrw:Password><%= mrw.password %></mrw:Password>
|
||||||
|
|
|
@ -6,7 +6,13 @@ module.exports = Self => {
|
||||||
arg: 'shipmentId',
|
arg: 'shipmentId',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
}],
|
},
|
||||||
|
{
|
||||||
|
arg: 'clientType',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
root: true
|
root: true
|
||||||
|
@ -17,10 +23,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getLabel = async shipmentId => {
|
Self.getLabel = async(shipmentId, clientType) => {
|
||||||
const mrw = await Self.getConfig();
|
const mrw = await Self.getConfig();
|
||||||
|
|
||||||
const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml');
|
const getLabelResponse = await Self.sendXmlDoc(
|
||||||
|
__dirname + `/getLabel.ejs`,
|
||||||
|
{mrw, shipmentId, clientType},
|
||||||
|
'text/xml'
|
||||||
|
);
|
||||||
|
|
||||||
return Self.getTextByTag(getLabelResponse, 'EtiquetaFile');
|
return Self.getTextByTag(getLabelResponse, 'EtiquetaFile');
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => {
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await models.MrwService.create(
|
||||||
|
{'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10}
|
||||||
|
);
|
||||||
|
|
||||||
await createMrwConfig();
|
await createMrwConfig();
|
||||||
|
|
||||||
await models.Application.rawSql(
|
|
||||||
`INSERT INTO vn.mrwService
|
|
||||||
SET agencyModeCodeFk = 'mrw',
|
|
||||||
clientType = 1,
|
|
||||||
serviceType = 1,
|
|
||||||
kg = 1`, null
|
|
||||||
);
|
|
||||||
await models.Ticket.create(ticket1);
|
await models.Ticket.create(ticket1);
|
||||||
await models.Expedition.create(expedition1);
|
await models.Expedition.create(expedition1);
|
||||||
});
|
});
|
||||||
|
@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => {
|
||||||
'user': 'user',
|
'user': 'user',
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'franchiseCode': 'franchiseCode',
|
'franchiseCode': 'franchiseCode',
|
||||||
'subscriberCode': 'subscriberCode'
|
'subscriberCode': 'subscriberCode',
|
||||||
|
'clientTypeWidth': 6
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => {
|
||||||
|
|
||||||
it('should fail if expeditionFk is not a MrwExpedition', async() => {
|
it('should fail if expeditionFk is not a MrwExpedition', async() => {
|
||||||
let error;
|
let error;
|
||||||
await models.MrwConfig.createShipment(undefined).catch(e => {
|
await models.MrwConfig.createShipment(15).catch(e => {
|
||||||
error = e;
|
error = e;
|
||||||
}).finally(async() => {
|
}).finally(async() => {
|
||||||
expect(error.message).toEqual(`This expedition is not a MRW shipment`);
|
expect(error.message).toEqual(`ClientType not available`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.renderer = async (expeditionFk) => {
|
Self.renderer = async expeditionFk => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
const viaexpressConfig = await models.ViaexpressConfig.findOne({
|
||||||
|
@ -109,7 +109,7 @@ module.exports = Self => {
|
||||||
const ticket = expedition.ticket();
|
const ticket = expedition.ticket();
|
||||||
const sender = ticket.company().client();
|
const sender = ticket.company().client();
|
||||||
const shipped = ticket.shipped.toISOString();
|
const shipped = ticket.shipped.toISOString();
|
||||||
const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk)
|
const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk);
|
||||||
const data = {
|
const data = {
|
||||||
viaexpressConfig,
|
viaexpressConfig,
|
||||||
sender,
|
sender,
|
||||||
|
|
|
@ -192,5 +192,8 @@
|
||||||
},
|
},
|
||||||
"RouteConfig": {
|
"RouteConfig": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"MrwService": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,5 +31,30 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
return parser.parseFromString(data.data, 'text/xml');
|
return parser.parseFromString(data.data, 'text/xml');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Self.getClientType = async function(expeditionFk) {
|
||||||
|
if (!expeditionFk) throw new UserError(`No expeditionFk defined`);
|
||||||
|
|
||||||
|
const {clientTypeWidth} = await Self.getConfig();
|
||||||
|
const result = await Self.app.models.Expedition.findById(expeditionFk,
|
||||||
|
{include: [{
|
||||||
|
relation: 'ticket',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'agencyMode',
|
||||||
|
scope: {
|
||||||
|
include: {
|
||||||
|
relation: 'mrwService',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}]}
|
||||||
|
);
|
||||||
|
const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType;
|
||||||
|
if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`);
|
||||||
|
|
||||||
|
return clientType.toString().padStart(clientTypeWidth, '0');
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
},
|
},
|
||||||
"notified":{
|
"notified":{
|
||||||
"type": "date"
|
"type": "date"
|
||||||
|
},
|
||||||
|
"clientTypeWidth": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"name": "MrwService",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "mrwService"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"agencyModeCodeFk": {
|
||||||
|
"id": true,
|
||||||
|
"type": "string",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"clientType": {
|
||||||
|
"type": "number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"serviceType": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"kg": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"agency": {
|
||||||
|
"type": "hasOne",
|
||||||
|
"model": "AgencyMode",
|
||||||
|
"foreignKey": "code"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,6 +60,11 @@
|
||||||
"type": "hasMany",
|
"type": "hasMany",
|
||||||
"model": "Zone",
|
"model": "Zone",
|
||||||
"foreignKey": "agencyModeFk"
|
"foreignKey": "agencyModeFk"
|
||||||
|
},
|
||||||
|
"mrwService": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "MrwService",
|
||||||
|
"foreignKey": "code"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
|
|
Loading…
Reference in New Issue