From 5bb7f7f14aafa1ddcd1354fe7b843c71e0f00e60 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 20 Nov 2019 11:14:11 +0100 Subject: [PATCH] deprecated getItemVisibleAvailable() #1887 --- .../00-getItemVisibleAvailable.sql | 17 +++++ .../00-itemGetVisibleAvailable.sql | 17 +++++ .../00-item_getVisibleAvailable.sql | 71 +++++++++++++++++++ modules/item/back/methods/item/getSummary.js | 2 +- .../back/methods/item/getVisibleAvailable.js | 2 +- modules/item/back/methods/item/regularize.js | 2 +- .../methods/item/specs/regularize.spec.js | 2 +- .../back/methods/ticket-request/confirm.js | 2 +- modules/ticket/back/methods/ticket/addSale.js | 2 +- 9 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 db/changes/10110-postCampaign/00-getItemVisibleAvailable.sql create mode 100644 db/changes/10110-postCampaign/00-itemGetVisibleAvailable.sql create mode 100644 db/changes/10110-postCampaign/00-item_getVisibleAvailable.sql diff --git a/db/changes/10110-postCampaign/00-getItemVisibleAvailable.sql b/db/changes/10110-postCampaign/00-getItemVisibleAvailable.sql new file mode 100644 index 000000000..21b827a75 --- /dev/null +++ b/db/changes/10110-postCampaign/00-getItemVisibleAvailable.sql @@ -0,0 +1,17 @@ +USE `vn`; +DROP procedure IF EXISTS `getItemVisibleAvailable`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `getItemVisibleAvailable`( + vItem INT, + vDate DATE, + vWarehouse TINYINT, + vRefresh BOOL) +BEGIN + -- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20 + CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh); +END$$ + +DELIMITER ; + diff --git a/db/changes/10110-postCampaign/00-itemGetVisibleAvailable.sql b/db/changes/10110-postCampaign/00-itemGetVisibleAvailable.sql new file mode 100644 index 000000000..4701e7124 --- /dev/null +++ b/db/changes/10110-postCampaign/00-itemGetVisibleAvailable.sql @@ -0,0 +1,17 @@ +USE `vn`; +DROP procedure IF EXISTS `itemGetVisibleAvailable`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `itemGetVisibleAvailable`( + vItem INT, + vDate DATE, + vWarehouse TINYINT, + vRefresh BOOL) +BEGIN + -- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20 + CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh); +END$$ + +DELIMITER ; + diff --git a/db/changes/10110-postCampaign/00-item_getVisibleAvailable.sql b/db/changes/10110-postCampaign/00-item_getVisibleAvailable.sql new file mode 100644 index 000000000..e6b6df2f9 --- /dev/null +++ b/db/changes/10110-postCampaign/00-item_getVisibleAvailable.sql @@ -0,0 +1,71 @@ + +USE `vn`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `item_getVisibleAvailable`( + vItem INT, + vDate DATE, + vWarehouse TINYINT, + vRefresh BOOL) +BEGIN + DECLARE vVisibleCalc INT; + DECLARE vAvailableCalc INT; + DECLARE vVisibleAltillo INT; + + CALL cache.available_refresh(vAvailableCalc, FALSE /*vRefresh*/ , vWarehouse, vDate); + CALL cache.visible_refresh(vVisibleCalc, FALSE,vWarehouse); + + SELECT visible INTO vVisibleAltillo + FROM vn.itemShelvingStock + WHERE itemFk = vItem + AND warehouseFk = vWarehouse; + + IF vRefresh THEN + + DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item; + CREATE TEMPORARY TABLE vn2008.tmp_item + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT vItem item_id, 0 stock, 0 visible; + + SELECT i.id, i.longName, i.box, i.typeFk, + i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8, + ip.code, ip.reserve, + vi.visible - IFNULL(vVisibleAltillo,0) AS visible, + av.available + FROM vn.item i + LEFT JOIN vn.itemPlacement ip + ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse + LEFT JOIN vn2008.tmp_item v + ON v.item_id = i.id + LEFT JOIN cache.available av + ON av.calc_id = vAvailableCalc AND av.item_id = i.id + LEFT JOIN cache.visible vi + ON vi.calc_id = vVisibleCalc AND vi.item_id = i.id + LEFT JOIN cache.stock st + ON st.warehouse_id = vWarehouse AND st.item_id = i.id + WHERE (vItem IS NULL OR i.id = vItem); + + ELSE + + SELECT i.id, i.longName, i.box, i.typeFk, + i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8, + ip.code, ip.reserve, + v.visible - IFNULL(vVisibleAltillo,0) AS visible, + av.available + FROM vn.item i + LEFT JOIN vn.itemPlacement ip + ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse + LEFT JOIN cache.visible v + ON v.item_id = i.id AND v.calc_id = vVisibleCalc + LEFT JOIN cache.available av + ON av.item_id = i.id AND av.calc_id = vAvailableCalc + WHERE (vItem IS NULL OR i.id = vItem); + + END IF; + +END$$ + +DELIMITER ; +; diff --git a/modules/item/back/methods/item/getSummary.js b/modules/item/back/methods/item/getSummary.js index 51fed3753..749e1212f 100644 --- a/modules/item/back/methods/item/getSummary.js +++ b/modules/item/back/methods/item/getSummary.js @@ -103,7 +103,7 @@ module.exports = Self => { // Visible Avaible let query = ` - CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; + CALL vn.item_getVisibleAvailable(?,curdate(),?,?)`; let options = [summary.item.id, summary.item.itemType().warehouseFk, false]; [res] = await Self.rawSql(query, options); diff --git a/modules/item/back/methods/item/getVisibleAvailable.js b/modules/item/back/methods/item/getVisibleAvailable.js index b35ca5fb7..7f0855740 100644 --- a/modules/item/back/methods/item/getVisibleAvailable.js +++ b/modules/item/back/methods/item/getVisibleAvailable.js @@ -24,7 +24,7 @@ module.exports = Self => { Self.getVisibleAvailable = async(id, warehouseFk) => { let query = ` - CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; + CALL vn.item_getVisibleAvailable(?,curdate(),?,?)`; let options = [id, warehouseFk, false]; [res] = await Self.rawSql(query, options); diff --git a/modules/item/back/methods/item/regularize.js b/modules/item/back/methods/item/regularize.js index b9aa0d85f..b9c646086 100644 --- a/modules/item/back/methods/item/regularize.js +++ b/modules/item/back/methods/item/regularize.js @@ -65,7 +65,7 @@ module.exports = Self => { let query = ` - CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; + CALL vn.item_getVisibleAvailable(?,curdate(),?,?)`; let params = [itemFk, warehouseFk, true]; let [res] = await Self.rawSql(query, params, options); diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index e0ea4d874..a5d7c1c95 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -16,7 +16,7 @@ describe('regularize()', () => { let ctx = {req: {accessToken: {userId: 18}}}; - let query = `CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`; + let query = `CALL vn.item_getVisibleAvailable(?,curdate(),?,?)`; let options = [itemFk, warehouseFk, true]; diff --git a/modules/ticket/back/methods/ticket-request/confirm.js b/modules/ticket/back/methods/ticket-request/confirm.js index 53fb2527c..72c41737a 100644 --- a/modules/ticket/back/methods/ticket-request/confirm.js +++ b/modules/ticket/back/methods/ticket-request/confirm.js @@ -46,7 +46,7 @@ module.exports = Self => { include: {relation: 'ticket'} }, options); - let [[stock]] = await Self.rawSql(`CALL vn.getItemVisibleAvailable(?,?,?,?)`, [ + let [[stock]] = await Self.rawSql(`CALL vn.item_getVisibleAvailable(?,?,?,?)`, [ ctx.args.itemFk, request.ticket().shipped, request.ticket().warehouseFk, diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 5eb06cf78..bb833709e 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -43,7 +43,7 @@ module.exports = Self => { const ticket = await models.Ticket.findById(id); const shouldRefresh = false; - const [[stock]] = await Self.rawSql(`CALL vn.itemGetVisibleAvailable(?, ?, ?, ?)`, [ + const [[stock]] = await Self.rawSql(`CALL vn.item_getVisibleAvailable(?, ?, ?, ?)`, [ itemId, ticket.shipped, ticket.warehouseFk,