This commit is contained in:
parent
a0308d281a
commit
38d863aac6
|
@ -30,7 +30,7 @@ proc: BEGIN
|
||||||
SELECT inventoried INTO started FROM vn.config LIMIT 1;
|
SELECT inventoried INTO started FROM vn.config LIMIT 1;
|
||||||
SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE());
|
SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE());
|
||||||
|
|
||||||
CALL vn.buyUltimateFromInterval(NULL, started, ended);
|
CALL vn.buy_getUltimateFromInterval (NULL, NULL, started, ended);
|
||||||
|
|
||||||
DELETE FROM last_buy;
|
DELETE FROM last_buy;
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ proc: BEGIN
|
||||||
|
|
||||||
-- Tabla con el ultimo dia de last_buy para cada producto
|
-- Tabla con el ultimo dia de last_buy para cada producto
|
||||||
-- que hace un replace de la anterior.
|
-- que hace un replace de la anterior.
|
||||||
CALL buyUltimate(vWarehouseShipment, util.VN_CURDATE());
|
CALL buy_getUltimate (NULL, vWarehouseShipment, util.VN_CURDATE());
|
||||||
|
|
||||||
INSERT INTO tItemRange
|
INSERT INTO tItemRange
|
||||||
SELECT t.itemFk, tr.landed
|
SELECT t.itemFk, tr.landed
|
||||||
|
|
|
@ -5,39 +5,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
* DEPRECATED usar buy_getUltimate
|
||||||
* Calcula las últimas compras realizadas hasta una fecha
|
* Calcula las últimas compras realizadas hasta una fecha
|
||||||
*
|
*
|
||||||
|
* @param vItemFk Id del artículo
|
||||||
* @param vWarehouseFk Id del almacén
|
* @param vWarehouseFk Id del almacén
|
||||||
* @param vDated Compras hasta fecha
|
* @param vDated Compras hasta fecha
|
||||||
* @return tmp.buyUltimate
|
* @return tmp.buyUltimate
|
||||||
*/
|
*/
|
||||||
CALL cache.last_buy_refresh (FALSE);
|
CALL buy_getUltimate(NULL, vWarehouseFk, vDated);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
|
|
||||||
CREATE TEMPORARY TABLE tmp.buyUltimate
|
|
||||||
(PRIMARY KEY (itemFk, warehouseFk),
|
|
||||||
INDEX(itemFk))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing
|
|
||||||
FROM cache.last_buy
|
|
||||||
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
|
||||||
|
|
||||||
IF vDated >= util.VN_CURDATE() THEN
|
|
||||||
CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated);
|
|
||||||
|
|
||||||
REPLACE INTO tmp.buyUltimate
|
|
||||||
SELECT itemFk, buyFk, warehouseFk, landed landing
|
|
||||||
FROM tmp.buyUltimateFromInterval
|
|
||||||
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
|
||||||
AND landed <= vDated
|
|
||||||
AND NOT isIgnored;
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimate
|
|
||||||
SELECT itemFk, buyFk, warehouseFk, landed landing
|
|
||||||
FROM tmp.buyUltimateFromInterval
|
|
||||||
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
|
||||||
AND landed > vDated
|
|
||||||
ORDER BY isIgnored = FALSE DESC;
|
|
||||||
END IF;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -6,6 +6,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInte
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
* DEPRECATED usar buy_getUltimateFromInterval
|
||||||
* Calcula las últimas compras realizadas
|
* Calcula las últimas compras realizadas
|
||||||
* desde un rango de fechas.
|
* desde un rango de fechas.
|
||||||
*
|
*
|
||||||
|
@ -14,153 +15,6 @@ BEGIN
|
||||||
* @param vEnded Fecha fin
|
* @param vEnded Fecha fin
|
||||||
* @return tmp.buyUltimateFromInterval
|
* @return tmp.buyUltimateFromInterval
|
||||||
*/
|
*/
|
||||||
IF vEnded IS NULL THEN
|
CALL vn.buy_getUltimateFromInterval (NULL,vWarehouseFk,vStarted,vEnded);
|
||||||
SET vEnded = vStarted;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF vEnded < vStarted THEN
|
|
||||||
SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded);
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Item
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
|
||||||
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
|
||||||
(PRIMARY KEY (itemFk, warehouseFk),
|
|
||||||
INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM (SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.price2 > 0
|
|
||||||
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM (SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed > vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.price2 > 0
|
|
||||||
AND NOT b.isIgnored
|
|
||||||
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM (SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.quantity = 0
|
|
||||||
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
|
|
||||||
-- ItemOriginal
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM (SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
itemOriginalFk,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.price2 > 0
|
|
||||||
AND NOT b.isIgnored
|
|
||||||
AND b.quantity > 0
|
|
||||||
AND itemOriginalFk
|
|
||||||
ORDER BY t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM (SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed > vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.price2 > 0
|
|
||||||
AND NOT b.isIgnored
|
|
||||||
AND itemOriginalFk
|
|
||||||
ORDER BY t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
|
||||||
SELECT itemFk,
|
|
||||||
warehouseFk,
|
|
||||||
buyFk,
|
|
||||||
landed,
|
|
||||||
isIgnored
|
|
||||||
FROM
|
|
||||||
(SELECT b.itemFk,
|
|
||||||
t.warehouseInFk warehouseFk,
|
|
||||||
b.id buyFk,
|
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.quantity = 0
|
|
||||||
AND itemOriginalFk
|
|
||||||
ORDER BY t.landed DESC, b.id DESC
|
|
||||||
LIMIT 10000000000000000000) sub
|
|
||||||
GROUP BY itemFk, warehouseFk;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimate`(
|
||||||
|
vItemFk INT,
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vDated DATE
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Calcula las últimas compras realizadas hasta una fecha
|
||||||
|
*
|
||||||
|
* @param vItemFk Id del artículo
|
||||||
|
* @param vWarehouseFk Id del almacén
|
||||||
|
* @param vDated Compras hasta fecha
|
||||||
|
* @return tmp.buyUltimate
|
||||||
|
*/
|
||||||
|
CALL cache.last_buy_refresh (FALSE);
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
|
||||||
|
CREATE TEMPORARY TABLE tmp.buyUltimate
|
||||||
|
(PRIMARY KEY (itemFk, warehouseFk),
|
||||||
|
INDEX(itemFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing
|
||||||
|
FROM cache.last_buy
|
||||||
|
WHERE (warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
|
AND (item_id = vItemFk OR vItemFk IS NULL);
|
||||||
|
|
||||||
|
IF vDated >= util.VN_CURDATE() THEN
|
||||||
|
CALL buyUltimateFromInterval(vItemFk, vWarehouseFk, util.VN_CURDATE(), vDated);
|
||||||
|
|
||||||
|
REPLACE INTO tmp.buyUltimate
|
||||||
|
SELECT itemFk, buyFk, warehouseFk, landed landing
|
||||||
|
FROM tmp.buyUltimateFromInterval
|
||||||
|
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
|
AND (itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND landed <= vDated
|
||||||
|
AND NOT isIgnored;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimate
|
||||||
|
SELECT itemFk, buyFk, warehouseFk, landed landing
|
||||||
|
FROM tmp.buyUltimateFromInterval
|
||||||
|
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
|
AND (itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND landed > vDated
|
||||||
|
ORDER BY isIgnored = FALSE DESC;
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,174 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_getUltimateFromInterval `(
|
||||||
|
vItemFk INT,
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vStarted DATE,
|
||||||
|
vEnded DATE
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Calcula las últimas compras realizadas
|
||||||
|
* desde un rango de fechas.
|
||||||
|
*
|
||||||
|
* @param vItemFk Id del artículo
|
||||||
|
* @param vWarehouseFk Id del almacén si es NULL se actualizan todos
|
||||||
|
* @param vStarted Fecha inicial
|
||||||
|
* @param vEnded Fecha fin
|
||||||
|
* @return tmp.buyUltimateFromInterval
|
||||||
|
*/
|
||||||
|
IF vEnded IS NULL THEN
|
||||||
|
SET vEnded = vStarted;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF vEnded < vStarted THEN
|
||||||
|
SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Item
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
||||||
|
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
||||||
|
(PRIMARY KEY (itemFk, warehouseFk),
|
||||||
|
INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.price2 > 0
|
||||||
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
|
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed > vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.price2 > 0
|
||||||
|
AND NOT b.isIgnored
|
||||||
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.quantity = 0
|
||||||
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
|
-- ItemOriginal
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
itemOriginalFk,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.price2 > 0
|
||||||
|
AND NOT b.isIgnored
|
||||||
|
AND b.quantity > 0
|
||||||
|
AND itemOriginalFk
|
||||||
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed > vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.price2 > 0
|
||||||
|
AND NOT b.isIgnored
|
||||||
|
AND itemOriginalFk
|
||||||
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM
|
||||||
|
(SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND (b.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
|
AND b.quantity = 0
|
||||||
|
AND itemOriginalFk
|
||||||
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -8,7 +8,7 @@ BEGIN
|
||||||
* @param vItemFk Id del Artículo
|
* @param vItemFk Id del Artículo
|
||||||
* @param vGrouping Cantidad de grouping
|
* @param vGrouping Cantidad de grouping
|
||||||
*/
|
*/
|
||||||
CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE());
|
CALL vn.buy_getUltimate (vItemFk, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
UPDATE vn.buy b
|
UPDATE vn.buy b
|
||||||
JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
|
JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
|
||||||
|
|
|
@ -8,7 +8,7 @@ BEGIN
|
||||||
* @param vItemFk id del item
|
* @param vItemFk id del item
|
||||||
* @param vPacking packing a actualizar
|
* @param vPacking packing a actualizar
|
||||||
*/
|
*/
|
||||||
CALL buyUltimate(vWarehouseFk, util.VN_CURDATE());
|
CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
UPDATE buy b
|
UPDATE buy b
|
||||||
JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
|
JOIN tmp.buyUltimate bu ON b.id = bu.buyFk
|
||||||
|
|
|
@ -74,7 +74,7 @@ BEGIN
|
||||||
|
|
||||||
CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped);
|
CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipped);
|
||||||
CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped);
|
CALL `cache`.availableNoRaids_refresh (vAvailableNoRaidsCalc, FALSE, vWarehouseFk, vShipped);
|
||||||
CALL vn.buyUltimate(vWarehouseFk, vShipped);
|
CALL vn.buy_getUltimate(NULL, vWarehouseFk, vShipped);
|
||||||
|
|
||||||
INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk)
|
INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk, zoneFk)
|
||||||
SELECT vWarehouseFk,
|
SELECT vWarehouseFk,
|
||||||
|
|
|
@ -97,7 +97,7 @@ BEGIN
|
||||||
FROM tmp.itemList;
|
FROM tmp.itemList;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded);
|
CALL buy_getUltimateFromInterval(NULL, vWarehouseIn,vInventoryDate, vDateLanded);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tTransfer
|
CREATE OR REPLACE TEMPORARY TABLE tTransfer
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
|
|
@ -15,7 +15,7 @@ BEGIN
|
||||||
JOIN ticket t ON t.id = c.ticketFk
|
JOIN ticket t ON t.id = c.ticketFk
|
||||||
WHERE c.id = vClaimFk;
|
WHERE c.id = vClaimFk;
|
||||||
|
|
||||||
CALL buyUltimate (vWarehouseFk, util.VN_CURDATE());
|
CALL buy_getUltimate(NULL, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible)
|
INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible)
|
||||||
SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible
|
SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible
|
||||||
|
|
|
@ -23,7 +23,7 @@ BEGIN
|
||||||
FROM operator
|
FROM operator
|
||||||
WHERE workerFk = account.myUser_getId();
|
WHERE workerFk = account.myUser_getId();
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, util.VN_CURDATE());
|
CALL buy_getUltimate(vBarcodeItem, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
SELECT buyFk INTO vBuyFk
|
SELECT buyFk INTO vBuyFk
|
||||||
FROM tmp.buyUltimate
|
FROM tmp.buyUltimate
|
||||||
|
|
|
@ -93,7 +93,7 @@ BEGIN
|
||||||
ORDER BY created DESC
|
ORDER BY created DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vCurdate);
|
CALL buy_getUltimate(vSelf, vWarehouseFk, vCurdate);
|
||||||
|
|
||||||
SELECT b.entryFk, bu.buyFk,IFNULL(b.buyingValue, 0) INTO vLastEntryFk, vLastBuyFk, vBuyingValueOriginal
|
SELECT b.entryFk, bu.buyFk,IFNULL(b.buyingValue, 0) INTO vLastEntryFk, vLastBuyFk, vBuyingValueOriginal
|
||||||
FROM tmp.buyUltimate bu
|
FROM tmp.buyUltimate bu
|
||||||
|
|
|
@ -14,9 +14,11 @@ BEGIN
|
||||||
|
|
||||||
CALL cache.visible_refresh(vCacheVisibleFk, FALSE, vWarehouseFk);
|
CALL cache.visible_refresh(vCacheVisibleFk, FALSE, vWarehouseFk);
|
||||||
CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
CALL cache.available_refresh(vCacheAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
||||||
CALL buyUltimate(vWarehouseFk, util.VN_CURDATE());
|
|
||||||
|
|
||||||
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
||||||
|
|
||||||
|
CALL buy_getUltimate(vItemFk, vWarehouseFk, util.VN_CURDATE());
|
||||||
|
|
||||||
SELECT SUM(visible) INTO vVisibleItemShelving
|
SELECT SUM(visible) INTO vVisibleItemShelving
|
||||||
FROM itemShelvingStock
|
FROM itemShelvingStock
|
||||||
WHERE itemFk = vItemFk
|
WHERE itemFk = vItemFk
|
||||||
|
|
|
@ -13,7 +13,7 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT;
|
ALTER TABLE tmp.itemInventory ADD IF NOT EXISTS buy_id INT;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vDate);
|
CALL buy_getUltimate (NULL, vWarehouseFk, vDate);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp
|
CREATE OR REPLACE TEMPORARY TABLE tmp
|
||||||
(KEY (itemFk))
|
(KEY (itemFk))
|
||||||
|
|
|
@ -181,7 +181,7 @@ BEGIN
|
||||||
AND e.isConfirmed
|
AND e.isConfirmed
|
||||||
ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity);
|
ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity);
|
||||||
|
|
||||||
CALL buyUltimate(NULL, vDateDayEnd);
|
CALL buy_getUltimate (NULL, NULL, vDateDayEnd);
|
||||||
|
|
||||||
DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity;
|
DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity;
|
||||||
|
|
||||||
|
|
|
@ -276,7 +276,7 @@ BEGIN
|
||||||
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
||||||
|
|
||||||
-- Redondeo: Cantidad pedida incorrecta en al grouping de la última compra
|
-- Redondeo: Cantidad pedida incorrecta en al grouping de la última compra
|
||||||
CALL buyUltimate(vWarehouseFk, vDate);
|
CALL buy_getUltimate(NULL, vWarehouseFk, vDate);
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
||||||
SELECT ticketFk, problem ,saleFk
|
SELECT ticketFk, problem ,saleFk
|
||||||
FROM (
|
FROM (
|
||||||
|
|
|
@ -78,7 +78,7 @@ proc: BEGIN
|
||||||
DROP TEMPORARY TABLE tmp.zoneGetLanded;
|
DROP TEMPORARY TABLE tmp.zoneGetLanded;
|
||||||
|
|
||||||
-- rellena la tabla buyUltimate con la ultima compra
|
-- rellena la tabla buyUltimate con la ultima compra
|
||||||
CALL buyUltimate (vWarehouseFk, vShipped);
|
CALL buy_getUltimate(NULL, vWarehouseFk, vShipped);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||||
|
|
|
@ -53,7 +53,7 @@ BEGIN
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE s.id = vSaleFk;
|
WHERE s.id = vSaleFk;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vDate);
|
CALL buy_getUltimate(vNewItemFk, vWarehouseFk, vDate);
|
||||||
|
|
||||||
SELECT `grouping`, groupingMode, packing
|
SELECT `grouping`, groupingMode, packing
|
||||||
INTO vGrouping,vGroupingMode,vPacking
|
INTO vGrouping,vGroupingMode,vPacking
|
||||||
|
@ -61,6 +61,8 @@ BEGIN
|
||||||
JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk
|
JOIN tmp.buyUltimate tmp ON b.id = tmp.buyFk
|
||||||
WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk;
|
WHERE tmp.itemFk = vNewItemFk AND tmp.WarehouseFk = vWarehouseFk;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||||
|
|
||||||
IF vGroupingMode = 'packing' AND vPacking > 0 THEN
|
IF vGroupingMode = 'packing' AND vPacking > 0 THEN
|
||||||
SET vRoundQuantity = vPacking;
|
SET vRoundQuantity = vPacking;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
|
@ -19,7 +19,7 @@ BEGIN
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE s.id = vSelf;
|
WHERE s.id = vSelf;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
CALL buy_getUltimate(vItemFk, vWarehouseFk, vShipped);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
SELECT vSelf saleFk,
|
SELECT vSelf saleFk,
|
||||||
|
|
|
@ -36,6 +36,6 @@ BEGIN
|
||||||
WHERE warehouse_id = vAuctionWarehouseFk
|
WHERE warehouse_id = vAuctionWarehouseFk
|
||||||
ON DUPLICATE KEY UPDATE quantity = tmp.item.quantity + VALUES(quantity);
|
ON DUPLICATE KEY UPDATE quantity = tmp.item.quantity + VALUES(quantity);
|
||||||
|
|
||||||
CALL buyUltimate(vAuctionWarehouseFk, vDated);
|
CALL buy_getUltimate(NULL, vAuctionWarehouseFk, vDated);
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -56,13 +56,12 @@ BEGIN
|
||||||
FROM zone
|
FROM zone
|
||||||
WHERE id = vZoneFk;
|
WHERE id = vZoneFk;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
CALL buy_getUltimate(NULL, vWarehouseFk, vShipped);
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||||
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
|
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
|
||||||
SELECT
|
SELECT vWarehouseFk warehouseFk,
|
||||||
vWarehouseFk AS warehouseFk,
|
NULL available,
|
||||||
NULL AS available,
|
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
bu.buyFk,
|
bu.buyFk,
|
||||||
vZoneFk zoneFk
|
vZoneFk zoneFk
|
||||||
|
|
|
@ -16,7 +16,7 @@ BEGIN
|
||||||
FROM ticket
|
FROM ticket
|
||||||
WHERE id = vSelf;
|
WHERE id = vSelf;
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vDated);
|
CALL buy_getUltimate(NULL, vWarehouseFk, vDated);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(INDEX(saleFk, isProblemCalcNeeded))
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
|
|
|
@ -52,8 +52,8 @@ module.exports = Self => {
|
||||||
else {
|
else {
|
||||||
const userConfig = await models.UserConfig.findById(userId, {fields: ['warehouseFk']}, myOptions);
|
const userConfig = await models.UserConfig.findById(userId, {fields: ['warehouseFk']}, myOptions);
|
||||||
await Self.rawSql(
|
await Self.rawSql(
|
||||||
'CALL vn.buyUltimate(?,?)',
|
'CALL vn.buy_getUltimate(?,?,?)',
|
||||||
[userConfig.warehouseFk, null],
|
[args.item, userConfig.warehouseFk, null],
|
||||||
myOptions
|
myOptions
|
||||||
);
|
);
|
||||||
let buyUltimate = await Self.rawSql(
|
let buyUltimate = await Self.rawSql(
|
||||||
|
|
|
@ -73,7 +73,8 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const travel = entry.travel();
|
const travel = entry.travel();
|
||||||
await Self.rawSql('CALL buyUltimate(?, ?)', [
|
await Self.rawSql('CALL buy_getUltimate(?, ?, ?)', [
|
||||||
|
null,
|
||||||
travel.warehouseInFk,
|
travel.warehouseInFk,
|
||||||
travel.landed
|
travel.landed
|
||||||
], myOptions);
|
], myOptions);
|
||||||
|
|
|
@ -50,7 +50,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
stmt = new ParameterizedSQL(`CALL buyUltimate(?, ?)`, [
|
stmt = new ParameterizedSQL(`CALL buy_getUltimate(?, ?, ?)`, [
|
||||||
|
null,
|
||||||
travel.warehouseInFk,
|
travel.warehouseInFk,
|
||||||
travel.landed
|
travel.landed
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -44,16 +44,14 @@ module.exports = Self => {
|
||||||
]);
|
]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.item');
|
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`CREATE TEMPORARY TABLE tmp.item
|
`CREATE OR REPLACE TEMPORARY TABLE tmp.item
|
||||||
(PRIMARY KEY (itemFk)) ENGINE = MEMORY
|
(PRIMARY KEY (itemFk)) ENGINE = MEMORY
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
i.id AS itemFk,
|
i.id itemFk,
|
||||||
it.id AS typeFk,
|
it.id typeFk,
|
||||||
it.name,
|
it.name,
|
||||||
ic.name AS categoryName
|
ic.name categoryName
|
||||||
FROM tmp.availableCalc ac
|
FROM tmp.availableCalc ac
|
||||||
JOIN cache.available a ON a.calc_id = ac.calcFk
|
JOIN cache.available a ON a.calc_id = ac.calcFk
|
||||||
JOIN vn.item i ON i.id = a.item_id
|
JOIN vn.item i ON i.id = a.item_id
|
||||||
|
@ -74,7 +72,7 @@ module.exports = Self => {
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
SELECT i.typeFk AS id, i.name, i.categoryName
|
SELECT i.typeFk id, i.name, i.categoryName
|
||||||
FROM tmp.item i
|
FROM tmp.item i
|
||||||
JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.itemFk
|
JOIN tmp.ticketCalculateItem tci ON tci.itemFk = i.itemFk
|
||||||
GROUP BY i.typeFk`
|
GROUP BY i.typeFk`
|
||||||
|
@ -85,7 +83,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await Self.rawStmt(sql, myOptions);
|
const result = await Self.rawStmt(sql, myOptions);
|
||||||
|
|
||||||
return result[categoriesIndex];
|
return result[categoriesIndex];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue