feat(createShipment): refs #7765 add dynamic weight by box
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Pablo Natek 2024-07-22 07:20:21 +02:00
parent 5567359d73
commit 40583020d0
4 changed files with 52 additions and 35 deletions

View File

@ -41,7 +41,7 @@
<mrw:Alto><%= mrw.defaultHeight %></mrw:Alto> <mrw:Alto><%= mrw.defaultHeight %></mrw:Alto>
<mrw:Largo><%= mrw.defaultLength %></mrw:Largo> <mrw:Largo><%= mrw.defaultLength %></mrw:Largo>
<mrw:Ancho><%= mrw.defaultWidth %></mrw:Ancho> <mrw:Ancho><%= mrw.defaultWidth %></mrw:Ancho>
<mrw:Peso><%= mrw.defaultWeight %></mrw:Peso> <mrw:Peso><%= expeditionData.defaultWeight ?? mrw.defaultWeight %></mrw:Peso>
</mrw:BultoRequest> </mrw:BultoRequest>
</mrw:Bultos> </mrw:Bultos>
</mrw:DatosServicio> </mrw:DatosServicio>

View File

@ -36,39 +36,44 @@ module.exports = Self => {
} }
const query = const query =
`SELECT `SELECT CASE co.code
CASE co.code WHEN 'ES' THEN a.postalCode
WHEN 'ES' THEN a.postalCode WHEN 'PT' THEN LEFT(a.postalCode, mc.portugalPostCodeTrim)
WHEN 'PT' THEN LEFT(a.postalCode, mc.portugalPostCodeTrim) WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00')
WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00') END postalCode,
END postalCode, a.city,
a.city, a.street,
a.street, co.code countryCode,
co.code countryCode, c.fi,
c.fi, c.name clientName,
c.name clientName, c.phone,
c.phone, DATE_FORMAT(t.shipped, '%d/%m/%Y') created,
DATE_FORMAT(t.shipped, '%d/%m/%Y') created, t.shipped,
t.shipped, CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference,
CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, LPAD(
LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType),
IF(mw.weekdays, 'S', 'N') weekDays, mc.serviceTypeWidth,
oa.description deliveryObservation '0'
FROM expedition e ) serviceType,
JOIN ticket t ON e.ticketFk = t.id IF(mw.weekdays, 'S', 'N') weekDays,
JOIN agencyMode am ON am.id = t.agencyModeFk oa.description deliveryObservation,
JOIN mrwService ms ON ms.agencyModeCodeFk = am.code pa.defaultWeight
LEFT JOIN mrwServiceWeekday mw ON mw.agencyModeCodeFk = am.code FROM expedition e
AND mw.weekDays & (1 << WEEKDAY(t.landed)) LEFT JOIN packaging pa ON e.packagingFk = pa.id
JOIN client c ON t.clientFk = c.id JOIN ticket t ON e.ticketFk = t.id
JOIN address a ON t.addressFk = a.id JOIN agencyMode am ON am.id = t.agencyModeFk
LEFT JOIN addressObservation oa ON oa.addressFk = a.id JOIN mrwService ms ON ms.agencyModeCodeFk = am.code
AND oa.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery') LEFT JOIN mrwServiceWeekday mw ON mw.agencyModeCodeFk = am.code
JOIN province p ON a.provinceFk = p.id AND mw.weekDays & (1 << WEEKDAY(t.landed))
JOIN country co ON co.id = p.countryFk JOIN client c ON t.clientFk = c.id
JOIN mrwConfig mc JOIN address a ON t.addressFk = a.id
WHERE e.id = ? LEFT JOIN addressObservation oa ON oa.addressFk = a.id
LIMIT 1`; 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]); const [expeditionData] = await Self.rawSql(query, [expeditionFk]);

View File

@ -21,7 +21,6 @@ module.exports = Self => {
Self.sendXmlDoc = async function(path, params, contentType) { Self.sendXmlDoc = async function(path, params, contentType) {
const parser = new DOMParser(); const parser = new DOMParser();
const xmlTemplate = fs.readFileSync(path, 'utf-8'); const xmlTemplate = fs.readFileSync(path, 'utf-8');
const renderedTemplate = ejs.render(xmlTemplate, params); const renderedTemplate = ejs.render(xmlTemplate, params);
const data = await axios.post(params.mrw.url, renderedTemplate, { const data = await axios.post(params.mrw.url, renderedTemplate, {

View File

@ -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);