Merge branch 'test' into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
6acba08a91
|
@ -1,37 +1,40 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`(IN vWarehouseFk TINYINT, IN vDatedFrom DATETIME, IN vRange INT, IN vItemFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getMinacum`(
|
||||||
|
vWarehouseFk TINYINT,
|
||||||
|
vDated DATE,
|
||||||
|
vRange INT,
|
||||||
|
vItemFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Cálculo del mínimo acumulado, para un item/almacén especificado, en caso de
|
* Cálculo del mínimo acumulado, para un item/almacén
|
||||||
* NULL para todo.
|
* especificado, en caso de NULL para todos.
|
||||||
*
|
*
|
||||||
* @param vWarehouseFk -> warehouseFk
|
* @param vWarehouseFk Id warehouse
|
||||||
* @param vDatedFrom -> fecha inicio
|
* @param vDated Fecha inicio
|
||||||
* @param vRange -> número de días a considerar
|
* @param vRange Número de días a considerar
|
||||||
* @param vItemFk -> Identificador de item
|
* @param vItemFk Id de artículo
|
||||||
* @return tmp.itemMinacum
|
* @return tmp.itemMinacum
|
||||||
*/
|
*/
|
||||||
DECLARE vDatedTo DATETIME;
|
DECLARE vDatedTo DATETIME DEFAULT util.dayEnd(vDated + INTERVAL vRange DAY);
|
||||||
|
|
||||||
SET vDatedFrom = TIMESTAMP(DATE(vDatedFrom), '00:00:00');
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
||||||
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, vRange, vDatedFrom), '23:59:59');
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemCalc;
|
|
||||||
CREATE TEMPORARY TABLE tmp.itemCalc
|
|
||||||
(INDEX (itemFk, warehouseFk))
|
(INDEX (itemFk, warehouseFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
SELECT sub.itemFk,
|
SELECT sub.itemFk,
|
||||||
sub.dated,
|
sub.dated,
|
||||||
CAST(SUM(sub.quantity) AS SIGNED) quantity,
|
CAST(SUM(sub.quantity) AS SIGNED) quantity,
|
||||||
sub.warehouseFk
|
sub.warehouseFk
|
||||||
FROM (SELECT s.itemFk,
|
FROM (
|
||||||
|
SELECT s.itemFk,
|
||||||
DATE(t.shipped) dated,
|
DATE(t.shipped) dated,
|
||||||
-s.quantity quantity,
|
-s.quantity quantity,
|
||||||
t.warehouseFk
|
t.warehouseFk
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo
|
WHERE t.shipped BETWEEN vDated AND vDatedTo
|
||||||
AND t.warehouseFk
|
AND t.warehouseFk
|
||||||
AND s.quantity != 0
|
AND s.quantity <> 0
|
||||||
AND (vItemFk IS NULL OR s.itemFk = vItemFk)
|
AND (vItemFk IS NULL OR s.itemFk = vItemFk)
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseFk = vWarehouseFk)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
@ -42,10 +45,10 @@ BEGIN
|
||||||
FROM buy b
|
FROM buy b
|
||||||
JOIN entry e ON e.id = b.entryFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
WHERE t.landed BETWEEN vDatedFrom AND vDatedTo
|
WHERE t.landed BETWEEN vDated AND vDatedTo
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
AND !e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND b.quantity != 0
|
AND b.quantity <> 0
|
||||||
AND (vItemFk IS NULL OR b.itemFk = vItemFk)
|
AND (vItemFk IS NULL OR b.itemFk = vItemFk)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT b.itemFk,
|
SELECT b.itemFk,
|
||||||
|
@ -55,28 +58,45 @@ BEGIN
|
||||||
FROM buy b
|
FROM buy b
|
||||||
JOIN entry e ON e.id = b.entryFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo
|
WHERE t.shipped BETWEEN vDated AND vDatedTo
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseOutFk = vWarehouseFk)
|
||||||
AND !e.isExcludedFromAvailable
|
AND NOT e.isExcludedFromAvailable
|
||||||
AND b.quantity != 0
|
AND b.quantity <> 0
|
||||||
AND (vItemFk IS NULL OR b.itemFk = vItemFk)
|
AND (vItemFk IS NULL OR b.itemFk = vItemFk)
|
||||||
AND !e.isRaid
|
AND NOT e.isRaid
|
||||||
|
UNION ALL
|
||||||
|
SELECT r.itemFk,
|
||||||
|
r.shipment,
|
||||||
|
-r.amount,
|
||||||
|
r.warehouseFk
|
||||||
|
FROM hedera.orderRow r
|
||||||
|
JOIN hedera.`order` o ON o.id = r.orderFk
|
||||||
|
JOIN client c ON c.id = o.customer_id
|
||||||
|
WHERE r.shipment BETWEEN vDated AND vDatedTo
|
||||||
|
AND (vWarehouseFk IS NULL OR r.warehouseFk = vWarehouseFk)
|
||||||
|
AND r.created >= (
|
||||||
|
SELECT util.VN_NOW() - INTERVAL TIME_TO_SEC(reserveTime) SECOND
|
||||||
|
FROM hedera.orderConfig
|
||||||
|
)
|
||||||
|
AND NOT o.confirmed
|
||||||
|
AND (vItemFk IS NULL OR r.itemFk = vItemFk)
|
||||||
|
AND r.amount <> 0
|
||||||
) sub
|
) sub
|
||||||
GROUP BY sub.itemFk, sub.warehouseFk, sub.dated;
|
GROUP BY sub.itemFk, sub.warehouseFk, sub.dated;
|
||||||
|
|
||||||
CALL item_getAtp(vDatedFrom);
|
CALL item_getAtp(vDated);
|
||||||
DROP TEMPORARY TABLE tmp.itemCalc;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemMinacum;
|
CREATE OR REPLACE TEMPORARY TABLE tmp.itemMinacum
|
||||||
CREATE TEMPORARY TABLE tmp.itemMinacum
|
|
||||||
(INDEX(itemFk))
|
(INDEX(itemFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT i.itemFk,
|
SELECT itemFk,
|
||||||
i.warehouseFk,
|
warehouseFk,
|
||||||
i.quantity amount
|
quantity amount
|
||||||
FROM tmp.itemAtp i
|
FROM tmp.itemAtp
|
||||||
HAVING amount != 0;
|
WHERE quantity <> 0;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.itemAtp;
|
DROP TEMPORARY TABLE
|
||||||
|
tmp.itemAtp,
|
||||||
|
tmp.itemCalc;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue