From 40583020d012b744530f3851c229ef42fb994548 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 22 Jul 2024 07:20:21 +0200 Subject: [PATCH] feat(createShipment): refs #7765 add dynamic weight by box --- back/methods/mrw-config/createShipment.ejs | 2 +- back/methods/mrw-config/createShipment.js | 71 ++++++++++--------- back/models/mrw-config.js | 1 - .../11162-salmonBirch/00-firstScript.sql | 13 ++++ 4 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 db/versions/11162-salmonBirch/00-firstScript.sql diff --git a/back/methods/mrw-config/createShipment.ejs b/back/methods/mrw-config/createShipment.ejs index 65326112b..d927315ee 100644 --- a/back/methods/mrw-config/createShipment.ejs +++ b/back/methods/mrw-config/createShipment.ejs @@ -41,7 +41,7 @@ <%= mrw.defaultHeight %> <%= mrw.defaultLength %> <%= mrw.defaultWidth %> - <%= mrw.defaultWeight %> + <%= expeditionData.defaultWeight ?? mrw.defaultWeight %> diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 900e1fc0f..4c3c1bc4a 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -36,39 +36,44 @@ module.exports = Self => { } const query = - `SELECT - CASE co.code - WHEN 'ES' THEN a.postalCode - WHEN 'PT' THEN LEFT(a.postalCode, mc.portugalPostCodeTrim) - WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00') - END postalCode, - a.city, - a.street, - co.code countryCode, - c.fi, - c.name clientName, - c.phone, - DATE_FORMAT(t.shipped, '%d/%m/%Y') created, - t.shipped, - CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, - LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, - IF(mw.weekdays, 'S', 'N') weekDays, - oa.description deliveryObservation - FROM expedition e - JOIN ticket t ON e.ticketFk = t.id - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN mrwService ms ON ms.agencyModeCodeFk = am.code - LEFT JOIN mrwServiceWeekday mw ON mw.agencyModeCodeFk = am.code - AND mw.weekDays & (1 << WEEKDAY(t.landed)) - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN addressObservation oa ON oa.addressFk = a.id - AND oa.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery') - JOIN province p ON a.provinceFk = p.id - JOIN country co ON co.id = p.countryFk - JOIN mrwConfig mc - WHERE e.id = ? - LIMIT 1`; + `SELECT CASE co.code + WHEN 'ES' THEN a.postalCode + WHEN 'PT' THEN LEFT(a.postalCode, mc.portugalPostCodeTrim) + WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00') + END postalCode, + a.city, + a.street, + co.code countryCode, + c.fi, + c.name clientName, + c.phone, + DATE_FORMAT(t.shipped, '%d/%m/%Y') created, + t.shipped, + CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, + LPAD( + IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), + mc.serviceTypeWidth, + '0' + ) serviceType, + IF(mw.weekdays, 'S', 'N') weekDays, + oa.description deliveryObservation, + pa.defaultWeight + FROM expedition e + LEFT JOIN packaging pa ON e.packagingFk = pa.id + JOIN ticket t ON e.ticketFk = t.id + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN mrwService ms ON ms.agencyModeCodeFk = am.code + LEFT JOIN mrwServiceWeekday mw ON mw.agencyModeCodeFk = am.code + AND mw.weekDays & (1 << WEEKDAY(t.landed)) + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN addressObservation oa ON oa.addressFk = a.id + AND oa.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery') + JOIN province p ON a.provinceFk = p.id + JOIN country co ON co.id = p.countryFk + JOIN mrwConfig mc + WHERE e.id = ? + LIMIT 1`; const [expeditionData] = await Self.rawSql(query, [expeditionFk]); diff --git a/back/models/mrw-config.js b/back/models/mrw-config.js index 8bb24dbe5..8041bdcd1 100644 --- a/back/models/mrw-config.js +++ b/back/models/mrw-config.js @@ -21,7 +21,6 @@ module.exports = Self => { Self.sendXmlDoc = async function(path, params, contentType) { const parser = new DOMParser(); - const xmlTemplate = fs.readFileSync(path, 'utf-8'); const renderedTemplate = ejs.render(xmlTemplate, params); const data = await axios.post(params.mrw.url, renderedTemplate, { diff --git a/db/versions/11162-salmonBirch/00-firstScript.sql b/db/versions/11162-salmonBirch/00-firstScript.sql new file mode 100644 index 000000000..2d94ccc04 --- /dev/null +++ b/db/versions/11162-salmonBirch/00-firstScript.sql @@ -0,0 +1,13 @@ +-- Place your SQL code here +ALTER TABLE vn.packaging ADD IF NOT EXISTS defaultWeight INT NULL + COMMENT 'default weight used in mrw'; + +INSERT IGNORE INTO vn.packaging (id, defaultWeight) + VALUES ('QB033', 3), + ('HC', 3), + ('kalan400', 4), + ('kalan577', 5), + ('guzma650', 6), + ('b-1', 7), + ('guzma1400', 9), + ('guzma1200', 9); \ No newline at end of file