From 80b338228ebc85d65719d726ac208a25320c55a9 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 23 Jul 2024 12:29:08 +0200 Subject: [PATCH 1/6] fix: refs #6403 take observation from ticket --- back/methods/mrw-config/createShipment.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 4db0d0c7d..8a0eb58b3 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -53,7 +53,7 @@ module.exports = Self => { 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 + ta.description deliveryObservation FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk @@ -62,8 +62,8 @@ module.exports = Self => { 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') + LEFT JOIN ticketObservation ta ON ta.ticketFk = t.id + AND ta.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 From 88724d6d8c4810ea9b798b030466e53df3984ad5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 23 Jul 2024 13:08:49 +0200 Subject: [PATCH 2/6] fix: refs #7505 visible_refresh support warehouse null --- db/routines/cache/procedures/visible_refresh.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 78d23dbfb..e1b40ec10 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -22,7 +22,7 @@ proc:BEGIN ENGINE = MEMORY SELECT item_id, amount stock, amount visible FROM cache.stock - WHERE warehouse_id = v_warehouse; + WHERE (warehouse_id IS NULL OR warehouse_id = v_warehouse); -- Calculamos los movimientos confirmados de hoy CALL vn.item_calcVisible(NULL, v_warehouse); From bdfaf02c959bfaa95ee4d31994e8f08fc729bf13 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 23 Jul 2024 13:36:52 +0200 Subject: [PATCH 3/6] fix: refs #6403 fix delivery observation --- back/methods/mrw-config/createShipment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 8a0eb58b3..3b91f4486 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -63,7 +63,7 @@ module.exports = Self => { JOIN client c ON t.clientFk = c.id JOIN address a ON t.addressFk = a.id LEFT JOIN ticketObservation ta ON ta.ticketFk = t.id - AND ta.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'delivery') + AND ta.observationTypeFk IN (SELECT id FROM observationType ot WHERE ot.code = 'agency') JOIN province p ON a.provinceFk = p.id JOIN country co ON co.id = p.countryFk JOIN mrwConfig mc From 5d2e9c6210bf511990848b98637e7272ffaf2d7b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 23 Jul 2024 13:59:36 +0200 Subject: [PATCH 4/6] fix: refs #7505 visible_refresh support warehouse null and added isComparative --- .../cache/procedures/visible_refresh.sql | 5 +-- .../vn/procedures/item_calcVisible.sql | 36 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index e1b40ec10..053da1d14 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,9 +20,10 @@ proc:BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible + SELECT item_id, SUM(amount) stock, SUM(amount) visible FROM cache.stock - WHERE (warehouse_id IS NULL OR warehouse_id = v_warehouse); + WHERE (v_warehouse IS NULL OR warehouse_id = v_warehouse) + GROUP BY item_id; -- Calculamos los movimientos confirmados de hoy CALL vn.item_calcVisible(NULL, v_warehouse); diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 820e73a7e..2ce663d80 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -21,6 +21,8 @@ BEGIN FROM itemTicketOut i LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk JOIN `state` s ON s.id = ts.stateFk + JOIN warehouse w ON w.id = i.warehouseFk + AND w.isComparative LEFT JOIN ( SELECT DISTINCT st.saleFk FROM saleTracking st @@ -28,26 +30,30 @@ BEGIN WHERE st.created > vDated AND (s.isPicked OR st.isChecked) ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk - WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk + WHERE (vWarehouseFk IS NULL OR i.warehouseFk = vWarehouseFk) AND (vSelf IS NULL OR i.itemFk = vSelf) AND (s.isPicked OR i.reserved OR stPrevious.saleFk) AND i.shipped >= vDated AND i.shipped < vTomorrow UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE isReceived - AND landed >= vDated AND landed < vTomorrow - AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk - AND (vSelf IS NULL OR itemFk = vSelf) - AND NOT isVirtualStock + SELECT iei.itemFk, iei.quantity + FROM itemEntryIn iei + JOIN warehouse w ON w.id = iei.warehouseInFk + AND w.isComparative + WHERE iei.isReceived + AND iei.landed >= vDated AND iei.landed < vTomorrow + AND (vWarehouseFk IS NULL OR iei.warehouseInFk = vWarehouseFk) + AND (vSelf IS NULL OR iei.itemFk = vSelf) + AND NOT iei.isVirtualStock UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE isDelivered - AND shipped >= vDated - AND shipped < vTomorrow - AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk - AND (vSelf IS NULL OR itemFk = vSelf) + SELECT ieo.itemFk, ieo.quantity + FROM itemEntryOut ieo + JOIN warehouse w ON w.id = ieo.warehouseOutFk + AND w.isComparative + WHERE ieo.isDelivered + AND ieo.shipped >= vDated + AND ieo.shipped < vTomorrow + AND (vWarehouseFk IS NULL OR ieo.warehouseOutFk = vWarehouseFk) + AND (vSelf IS NULL OR ieo.itemFk = vSelf) ) t GROUP BY itemFk ON DUPLICATE KEY UPDATE From a9aa47fef1aa194145cbe93260a2618ec365702b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 23 Jul 2024 14:17:01 +0200 Subject: [PATCH 5/6] fix: refs #7505 visible_refresh support warehouse null and added isComparative --- db/routines/cache/procedures/visible_refresh.sql | 10 ++++++---- db/routines/vn/procedures/item_calcVisible.sql | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 053da1d14..d7c5c3738 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,10 +20,12 @@ proc:BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, SUM(amount) stock, SUM(amount) visible - FROM cache.stock - WHERE (v_warehouse IS NULL OR warehouse_id = v_warehouse) - GROUP BY item_id; + SELECT s.item_id, SUM(s.amount) stock, SUM(s.amount) visible + FROM cache.stock s + JOIN warehouse w ON w.id = s.warehouse_id + WHERE (v_warehouse IS NULL OR s.warehouse_id = v_warehouse) + AND w.isComparative + GROUP BY s.item_id; -- Calculamos los movimientos confirmados de hoy CALL vn.item_calcVisible(NULL, v_warehouse); diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 2ce663d80..32adfdfa3 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -22,7 +22,6 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk JOIN `state` s ON s.id = ts.stateFk JOIN warehouse w ON w.id = i.warehouseFk - AND w.isComparative LEFT JOIN ( SELECT DISTINCT st.saleFk FROM saleTracking st @@ -34,26 +33,27 @@ BEGIN AND (vSelf IS NULL OR i.itemFk = vSelf) AND (s.isPicked OR i.reserved OR stPrevious.saleFk) AND i.shipped >= vDated AND i.shipped < vTomorrow + AND w.isComparative UNION ALL SELECT iei.itemFk, iei.quantity FROM itemEntryIn iei JOIN warehouse w ON w.id = iei.warehouseInFk - AND w.isComparative WHERE iei.isReceived AND iei.landed >= vDated AND iei.landed < vTomorrow AND (vWarehouseFk IS NULL OR iei.warehouseInFk = vWarehouseFk) AND (vSelf IS NULL OR iei.itemFk = vSelf) AND NOT iei.isVirtualStock + AND w.isComparative UNION ALL SELECT ieo.itemFk, ieo.quantity FROM itemEntryOut ieo JOIN warehouse w ON w.id = ieo.warehouseOutFk - AND w.isComparative WHERE ieo.isDelivered AND ieo.shipped >= vDated AND ieo.shipped < vTomorrow AND (vWarehouseFk IS NULL OR ieo.warehouseOutFk = vWarehouseFk) AND (vSelf IS NULL OR ieo.itemFk = vSelf) + AND w.isComparative ) t GROUP BY itemFk ON DUPLICATE KEY UPDATE From abfbf13440deec47bfb63e6e3eec84454099cf2a Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 23 Jul 2024 14:18:52 +0200 Subject: [PATCH 6/6] fix: refs #7505 fix --- db/routines/cache/procedures/visible_refresh.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index d7c5c3738..a673969d2 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -21,8 +21,8 @@ proc:BEGIN (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT s.item_id, SUM(s.amount) stock, SUM(s.amount) visible - FROM cache.stock s - JOIN warehouse w ON w.id = s.warehouse_id + FROM stock s + JOIN vn.warehouse w ON w.id = s.warehouse_id WHERE (v_warehouse IS NULL OR s.warehouse_id = v_warehouse) AND w.isComparative GROUP BY s.item_id;