From 82259eee162d942d0b2fbed9940fda26b34b98db Mon Sep 17 00:00:00 2001 From: carlosjr Date: Wed, 4 Aug 2021 11:48:21 +0200 Subject: [PATCH 1/2] added catalog calculate join to show only available item types --- .../methods/order/getItemTypeAvailable.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/order/back/methods/order/getItemTypeAvailable.js b/modules/order/back/methods/order/getItemTypeAvailable.js index 56f6a8c0e..52a2db5f5 100644 --- a/modules/order/back/methods/order/getItemTypeAvailable.js +++ b/modules/order/back/methods/order/getItemTypeAvailable.js @@ -31,13 +31,36 @@ module.exports = Self => { let stmts = []; let stmt; + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item'); + + stmt = new ParameterizedSQL( + `CREATE TEMPORARY TABLE tmp.item + (PRIMARY KEY (itemFk)) ENGINE = MEMORY + SELECT DISTINCT + i.id AS itemFk, + i.typeFk, + it.categoryFk + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk`); + stmts.push(stmt); + let order = await app.models.Order.findById(orderId); stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [ order.landed, order.addressFk, order.agencyModeFk ]); + + stmts.push(new ParameterizedSQL( + 'CALL vn.catalog_calculate(?, ?, ?)', [ + order.landed, + order.addressFk, + order.agencyModeFk, + ] + )); stmts.push(stmt); + stmt = new ParameterizedSQL(` SELECT it.id, it.name, ic.name categoryName FROM tmp.availableCalc ac @@ -45,6 +68,7 @@ module.exports = Self => { JOIN item i ON i.id = a.item_id JOIN itemType it ON it.id = i.typeFk JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.id WHERE it.categoryFk = ? GROUP BY it.id`, [itemCategoryId] ); From 3432fab6af11079901509c1b52963f6823aea073 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Fri, 6 Aug 2021 11:53:38 +0200 Subject: [PATCH 2/2] now shows only the itemType of available items --- .../methods/order/getItemTypeAvailable.js | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/modules/order/back/methods/order/getItemTypeAvailable.js b/modules/order/back/methods/order/getItemTypeAvailable.js index 52a2db5f5..906095f41 100644 --- a/modules/order/back/methods/order/getItemTypeAvailable.js +++ b/modules/order/back/methods/order/getItemTypeAvailable.js @@ -28,9 +28,17 @@ module.exports = Self => { }); Self.getItemTypeAvailable = async(orderId, itemCategoryId) => { - let stmts = []; + const stmts = []; let stmt; + const order = await app.models.Order.findById(orderId); + stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [ + order.landed, + order.addressFk, + order.agencyModeFk + ]); + stmts.push(stmt); + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item'); stmt = new ParameterizedSQL( @@ -38,44 +46,39 @@ module.exports = Self => { (PRIMARY KEY (itemFk)) ENGINE = MEMORY SELECT DISTINCT i.id AS itemFk, - i.typeFk, - it.categoryFk - FROM vn.item i + it.id AS typeFk, + it.name, + ic.name AS categoryName + FROM tmp.availableCalc ac + JOIN cache.available a ON a.calc_id = ac.calcFk + JOIN vn.item i ON i.id = a.item_id JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk`); + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE it.categoryFk = ?`, [itemCategoryId] + ); stmts.push(stmt); - let order = await app.models.Order.findById(orderId); - stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [ - order.landed, - order.addressFk, - order.agencyModeFk - ]); - - stmts.push(new ParameterizedSQL( + stmt = new ParameterizedSQL( 'CALL vn.catalog_calculate(?, ?, ?)', [ order.landed, order.addressFk, order.agencyModeFk, ] - )); + ); stmts.push(stmt); stmt = new ParameterizedSQL(` - SELECT it.id, it.name, ic.name categoryName - FROM tmp.availableCalc ac - JOIN cache.available a ON a.calc_id = ac.calcFk - JOIN item i ON i.id = a.item_id - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.id - WHERE it.categoryFk = ? - GROUP BY it.id`, [itemCategoryId] + SELECT i.typeFk AS id, i.name, i.categoryName + FROM tmp.item i + JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.itemFk + GROUP BY i.typeFk` ); - let categoriesIndex = stmts.push(stmt) - 1; + const categoriesIndex = stmts.push(stmt) - 1; - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await Self.rawStmt(sql); + stmts.push('DROP TEMPORARY TABLE tmp.item'); + + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await Self.rawStmt(sql); return result[categoriesIndex]; };