8062-testToMaster_2 #3059

Merged
alexm merged 293 commits from 8062-testToMaster_2 into master 2024-10-03 05:43:41 +00:00
1 changed files with 102 additions and 84 deletions
Showing only changes of commit 56e6a7e6aa - Show all commits

View File

@ -1,99 +1,117 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getSimilar`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(
vSelf INT, vSelf INT,
vWarehouseFk INT, vWarehouseFk INT,
vDated DATE, vDated DATE,
vShowType BOOL vShowType BOOL,
vDaysInForward INT
) )
BEGIN BEGIN
/** /**
* Propone articulos disponibles ordenados, con la cantidad * Propone articulos ordenados, con la cantidad
* de veces usado y segun sus caracteristicas. * de veces usado y segun sus caracteristicas.
* *
* @param vSelf Id de artículo * @param vSelf Id de artículo
* @param vWarehouseFk Id de almacen * @param vWarehouseFk Id de almacen
* @param vDated Fecha * @param vDated Fecha
* @param vShowType Mostrar tipos * @param vShowType Mostrar tipos
* @param vDaysInForward Días de alcance para las ventas
*/ */
DECLARE vAvailableCalcFk INT; DECLARE vAvailableCalcFk INT;
DECLARE vVisibleCalcFk INT; DECLARE vPriority INT DEFAULT 1;
DECLARE vTypeFk INT;
DECLARE vPriority INT DEFAULT 1;
CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated);
CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk);
WITH itemTags AS ( WITH itemTags AS (
SELECT i.id, SELECT i.id,
typeFk, typeFk,
tag5, tag5,
value5, value5,
tag6, tag6,
value6, value6,
tag7, tag7,
value7, value7,
tag8, tag8,
value8, value8,
t.name, t.name,
it.value it.value
FROM vn.item i FROM vn.item i
LEFT JOIN vn.itemTag it ON it.itemFk = i.id LEFT JOIN vn.itemTag it ON it.itemFk = i.id
AND it.priority = vPriority AND it.priority = vPriority
LEFT JOIN vn.tag t ON t.id = it.tagFk LEFT JOIN vn.tag t ON t.id = it.tagFk
WHERE i.id = vSelf WHERE i.id = vSelf
) ),
SELECT i.id itemFk, stock AS (
i.longName, SELECT itemFk, SUM(visible) stock
i.subName, FROM vn.itemShelvingStock
i.tag5, WHERE warehouseFk = vWarehouseFk
i.value5, GROUP BY itemFk
(i.value5 <=> its.value5) match5, ),
i.tag6, sold AS (
i.value6, SELECT SUM(s.quantity) AS quantity,
(i.value6 <=> its.value6) match6, s.itemFk
i.tag7, FROM vn.sale s
i.value7, JOIN vn.ticket t ON t.id = s.ticketFk
(i.value7 <=> its.value7) match7, LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id
i.tag8, WHERE t.shipped BETWEEN CURDATE() AND CURDATE() + INTERVAL vDaysInForward DAY
i.value8, AND iss.saleFk IS NULL
(i.value8 <=> its.value8) match8, AND t.warehouseFk = vWarehouseFk
a.available, GROUP BY s.itemFk
IFNULL(ip.counter, 0) `counter`, )
CASE SELECT i.id itemFk,
WHEN b.groupingMode = 'grouping' THEN b.grouping CAST(sd.quantity AS INT) advanceable,
WHEN b.groupingMode = 'packing' THEN b.packing i.longName,
ELSE 1 i.subName,
END minQuantity, i.tag5,
v.visible located, i.value5,
b.price2 (i.value5 <=> its.value5) match5,
FROM vn.item i i.tag6,
JOIN cache.available a ON a.item_id = i.id i.value6,
AND a.calc_id = vAvailableCalcFk (i.value6 <=> its.value6) match6,
LEFT JOIN cache.visible v ON v.item_id = i.id i.tag7,
AND v.calc_id = vVisibleCalcFk i.value7,
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id (i.value7 <=> its.value7) match7,
AND lb.warehouse_id = vWarehouseFk i.tag8,
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id i.value8,
AND ip.itemFk = vSelf (i.value8 <=> its.value8) match8,
LEFT JOIN vn.itemTag it ON it.itemFk = i.id a.available,
AND it.priority = vPriority IFNULL(ip.counter, 0) `counter`,
LEFT JOIN vn.tag t ON t.id = it.tagFk CASE
LEFT JOIN vn.buy b ON b.id = lb.buy_id WHEN b.groupingMode = 'grouping' THEN b.grouping
JOIN itemTags its WHEN b.groupingMode = 'packing' THEN b.packing
WHERE a.available > 0 ELSE 1
AND (i.typeFk = its.typeFk OR NOT vShowType) END minQuantity,
AND i.id <> vSelf sk.stock located,
ORDER BY `counter` DESC, b.price2
(t.name = its.name) DESC, FROM vn.item i
(it.value = its.value) DESC, LEFT JOIN sold sd ON sd.itemFk = i.id
(i.tag5 = its.tag5) DESC, JOIN cache.available a ON a.item_id = i.id
match5 DESC, AND a.calc_id = vAvailableCalcFk
(i.tag6 = its.tag6) DESC, LEFT JOIN stock sk ON sk.itemFk = i.id
match6 DESC, LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
(i.tag7 = its.tag7) DESC, AND lb.warehouse_id = vWarehouseFk
match7 DESC, LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id
(i.tag8 = its.tag8) DESC, AND ip.itemFk = vSelf
match8 DESC LEFT JOIN vn.itemTag it ON it.itemFk = i.id
LIMIT 100; AND it.priority = vPriority
LEFT JOIN vn.tag t ON t.id = it.tagFk
LEFT JOIN vn.buy b ON b.id = lb.buy_id
JOIN itemTags its
WHERE (a.available > 0 OR sd.quantity < sk.stock)
AND (i.typeFk = its.typeFk OR NOT vShowType)
AND i.id <> vSelf
ORDER BY (a.available > 0) DESC,
`counter` DESC,
(t.name = its.name) DESC,
(it.value = its.value) DESC,
(i.tag5 = its.tag5) DESC,
match5 DESC,
(i.tag6 = its.tag6) DESC,
match6 DESC,
(i.tag7 = its.tag7) DESC,
match7 DESC,
(i.tag8 = its.tag8) DESC,
match8 DESC
LIMIT 100;
END$$ END$$
DELIMITER ; DELIMITER ;