This commit is contained in:
parent
59fddb5c55
commit
5bb7f7f14a
|
@ -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 ;
|
||||
|
|
@ -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 ;
|
||||
|
|
@ -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 ;
|
||||
;
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue