Compare commits
14 Commits
8077-sumDe
...
dev
Author | SHA1 | Date |
---|---|---|
Guillermo Bonet | 3453aa0f8c | |
Guillermo Bonet | 3b73ffbd8a | |
Sergio De la torre | 76b12e73b9 | |
Sergio De la torre | 009b4ab7b9 | |
Alex Moreno | 20b68b4b41 | |
Alex Moreno | b48beaf4b3 | |
Alex Moreno | d6a849727e | |
Alex Moreno | 838296e744 | |
Alex Moreno | 6785779fe5 | |
Alex Moreno | e730b5d4a1 | |
Alex Moreno | 5923916cda | |
Pablo Natek | c8b0874e95 | |
Alex Moreno | 8ef78818db | |
Pablo Natek | 00e5f86020 |
|
@ -24,12 +24,13 @@ module.exports = Self => {
|
|||
|
||||
Self.cancelShipment = async expeditionFk => {
|
||||
const models = Self.app.models;
|
||||
|
||||
const mrw = await models.MrwConfig.findOne();
|
||||
const {externalId} = await models.Expedition.findById(expeditionFk);
|
||||
const clientType = await models.MrwConfig.getClientType(expeditionFk);
|
||||
const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8');
|
||||
const renderedXml = ejs.render(template, {mrw, externalId, clientType});
|
||||
|
||||
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', renderedXml]);
|
||||
const response = await axios.post(mrw.url, renderedXml, {
|
||||
headers: {
|
||||
'Content-Type': 'application/soap+xml; charset=utf-8'
|
||||
|
@ -37,12 +38,11 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
const xmlString = response.data;
|
||||
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipmentResponse', xmlString]);
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||
|
||||
await Self.rawSql('CALL util.debugAdd(?,?);', ['cancelShipment', xmlDoc]);
|
||||
|
||||
const result = xmlDoc.getElementsByTagName('Mensaje')[0].textContent;
|
||||
return result.toLowerCase().includes('se ha cancelado correctamente');
|
||||
return ['no se ha encontrado', 'se ha cancelado correctamente'].some(res => result.toLowerCase().includes(res));
|
||||
};
|
||||
};
|
||||
|
|
|
@ -18,11 +18,6 @@ module.exports = Self => {
|
|||
arg: 'search',
|
||||
type: 'string',
|
||||
description: `If it's and integer searchs by id, otherwise it searchs by name`
|
||||
},
|
||||
{
|
||||
arg: 'sumAmount',
|
||||
type: 'boolean',
|
||||
description: `Indicates whether to calculate the total sum of amounts or to return detailed records`
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -33,7 +28,6 @@ module.exports = Self => {
|
|||
path: `/filter`,
|
||||
verb: 'GET'
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Self.filter = async(ctx, filter, options) => {
|
||||
|
@ -56,7 +50,14 @@ module.exports = Self => {
|
|||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
|
||||
const stmts = [];
|
||||
const fields = ctx.args.sumAmount ? 'sum(d.amount) sumAmount' : ` DISTINCT c.id clientFk,
|
||||
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
DISTINCT c.id clientFk,
|
||||
c.name clientName,
|
||||
c.salesPersonFk,
|
||||
c.businessTypeFk = 'worker' isWorker,
|
||||
|
@ -74,14 +75,7 @@ module.exports = Self => {
|
|||
r.finished IS NULL hasRecovery,
|
||||
dp.id departmentFk,
|
||||
dp.name departmentName,
|
||||
dp.notificationEmail departmentEmail`;
|
||||
const date = Date.vnNew();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
const stmt = new ParameterizedSQL(
|
||||
`SELECT *
|
||||
FROM (
|
||||
SELECT
|
||||
${fields}
|
||||
dp.notificationEmail departmentEmail
|
||||
FROM defaulter d
|
||||
JOIN client c ON c.id = d.clientFk
|
||||
JOIN country cn ON cn.id = c.countryFk
|
||||
|
@ -108,7 +102,7 @@ module.exports = Self => {
|
|||
, [date]);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
!ctx.args.sumAmount && stmt.merge(`GROUP BY d.clientFk`);
|
||||
stmt.merge(`GROUP BY d.clientFk`);
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ module.exports = Self => {
|
|||
JOIN vn.productionConfig pc
|
||||
WHERE sh.code = ? AND s.code = pc.sectorFromCode
|
||||
), tItemInSector AS (
|
||||
SELECT is2.itemFk, is2.created, is2.shelvingFk
|
||||
SELECT is2.itemFk, is2.created, sh.code
|
||||
FROM vn.itemShelving is2
|
||||
JOIN vn.shelving sh ON sh.id = is2.shelvingFk
|
||||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
|
@ -59,7 +59,7 @@ module.exports = Self => {
|
|||
JOIN vn.productionConfig pc
|
||||
WHERE sh.code <> ?
|
||||
AND s.code = pc.sectorFromCode)
|
||||
SELECT ti.itemFK, tis.shelvingFk
|
||||
SELECT ti.itemFK, tis.code shelvingFk
|
||||
FROM tItemShelving ti
|
||||
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
|
||||
JOIN vn.productionConfig pc
|
||||
|
|
|
@ -52,7 +52,8 @@ module.exports = Self => {
|
|||
|
||||
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
|
||||
deletedExpeditions.push(deletedExpedition);
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
console.error('error: ', error);
|
||||
notDeletedExpeditions.push(expeditionId);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue