refactor: refs #6874 Proc itemProposal #2123
|
@ -1,87 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal`(vItemFk INT, vTicketFk INT,vShowType BOOL)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Propone articulos disponible ordenado, con la cantidad de veces usado y segun sus caracteristicas
|
|
||||||
*
|
|
||||||
* @param vItemFk item id
|
|
||||||
* @param vTicketFk ticket id
|
|
||||||
* @param vShowType mostrar tipos
|
|
||||||
*/
|
|
||||||
|
|
||||||
DECLARE vWarehouseFk INT;
|
|
||||||
DECLARE vShipped DATE;
|
|
||||||
DECLARE vCalcFk INT;
|
|
||||||
DECLARE vTypeFk INT;
|
|
||||||
|
|
||||||
DECLARE vTag1 VARCHAR(25);
|
|
||||||
DECLARE vTag5 VARCHAR(25);
|
|
||||||
DECLARE vTag6 VARCHAR(25);
|
|
||||||
DECLARE vTag7 VARCHAR(25);
|
|
||||||
DECLARE vTag8 VARCHAR(25);
|
|
||||||
|
|
||||||
DECLARE vValue1 VARCHAR(50);
|
|
||||||
DECLARE vValue5 VARCHAR(50);
|
|
||||||
DECLARE vValue6 VARCHAR(50);
|
|
||||||
DECLARE vValue7 VARCHAR(50);
|
|
||||||
DECLARE vValue8 VARCHAR(50);
|
|
||||||
|
|
||||||
SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped
|
|
||||||
FROM vn.ticket
|
|
||||||
WHERE id = vTicketFk;
|
|
||||||
|
|
||||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
|
||||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
|
||||||
FROM vn.item i
|
|
||||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
|
||||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
|
||||||
WHERE i.id = vItemFk;
|
|
||||||
|
|
||||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
|
||||||
|
|
||||||
SELECT i.id itemFk,
|
|
||||||
i.longName,
|
|
||||||
i.subName,
|
|
||||||
i.tag5,
|
|
||||||
i.value5,
|
|
||||||
(i.value5 <=> vValue5 COLLATE utf8_general_ci) match5,
|
|
||||||
i.tag6,
|
|
||||||
i.value6,
|
|
||||||
(i.value6 <=> vValue6 COLLATE utf8_general_ci) match6,
|
|
||||||
i.tag7,
|
|
||||||
i.value7,
|
|
||||||
(i.value7 <=> vValue7 COLLATE utf8_general_ci) match7,
|
|
||||||
i.tag8,
|
|
||||||
i.value8,
|
|
||||||
(i.value8 <=> vValue8 COLLATE utf8_general_ci) match8,
|
|
||||||
a.available,
|
|
||||||
IFNULL(ip.counter,0) counter,
|
|
||||||
IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity,
|
|
||||||
iss.visible located
|
|
||||||
FROM item i
|
|
||||||
JOIN cache.available a ON a.item_id = i.id
|
|
||||||
LEFT JOIN itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
|
||||||
LEFT JOIN itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
|
||||||
LEFT JOIN tag t1 ON t1.id = it1.tagFk
|
|
||||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk
|
|
||||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
|
||||||
LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id AND iss.warehouseFk = vWarehouseFk
|
|
||||||
WHERE a.calc_id = vCalcFk
|
|
||||||
AND available > 0
|
|
||||||
AND IF(vShowType,i.typeFk = vTypeFk,true)
|
|
||||||
AND i.id != vItemFk
|
|
||||||
ORDER BY counter DESC,
|
|
||||||
(t1.name = vTag1 COLLATE utf8_general_ci) DESC,
|
|
||||||
(it1.value = vValue1 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag5 = vTag5 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value5 = vValue5 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag6 = vTag6 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value6 = vValue6 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag7 = vTag7 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value7 = vValue7 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag8 = vTag8 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value8 = vValue8 COLLATE utf8_general_ci) DESC;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,76 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal_beta`(vItemFk INT, vTicketFk INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
DECLARE vWarehouseFk INT;
|
|
||||||
DECLARE vShipped DATE;
|
|
||||||
DECLARE vCalcFk INT;
|
|
||||||
DECLARE vTypeFk INT;
|
|
||||||
DECLARE vResultsMax INT DEFAULT 10;
|
|
||||||
|
|
||||||
DECLARE vTag1 VARCHAR(25);
|
|
||||||
DECLARE vTag5 VARCHAR(25);
|
|
||||||
DECLARE vTag6 VARCHAR(25);
|
|
||||||
DECLARE vTag7 VARCHAR(25);
|
|
||||||
DECLARE vTag8 VARCHAR(25);
|
|
||||||
|
|
||||||
DECLARE vValue1 VARCHAR(50);
|
|
||||||
DECLARE vValue5 VARCHAR(50);
|
|
||||||
DECLARE vValue6 VARCHAR(50);
|
|
||||||
DECLARE vValue7 VARCHAR(50);
|
|
||||||
DECLARE vValue8 VARCHAR(50);
|
|
||||||
|
|
||||||
SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped
|
|
||||||
FROM vn.ticket
|
|
||||||
WHERE id = vTicketFk;
|
|
||||||
|
|
||||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
|
||||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
|
||||||
FROM vn.item i
|
|
||||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
|
||||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
|
||||||
WHERE i.id = vItemFk;
|
|
||||||
|
|
||||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
|
||||||
|
|
||||||
SELECT i.id itemFk,
|
|
||||||
i.longName,
|
|
||||||
i.subName,
|
|
||||||
i.tag5,
|
|
||||||
i.value5,
|
|
||||||
(i.value5 <=> vValue5 COLLATE utf8_general_ci) match5,
|
|
||||||
i.tag6,
|
|
||||||
i.value6,
|
|
||||||
(i.value6 <=> vValue6 COLLATE utf8_general_ci) match6,
|
|
||||||
i.tag7,
|
|
||||||
i.value7,
|
|
||||||
(i.value7 <=> vValue7 COLLATE utf8_general_ci) match7,
|
|
||||||
i.tag8,
|
|
||||||
i.value8,
|
|
||||||
(i.value8 <=> vValue8 COLLATE utf8_general_ci) match8,
|
|
||||||
a.available,
|
|
||||||
IFNULL(ip.counter,0) counter
|
|
||||||
FROM vn.item i
|
|
||||||
JOIN cache.available a ON a.item_id = i.id
|
|
||||||
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
|
||||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
|
||||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
|
||||||
WHERE a.calc_id = vCalcFk
|
|
||||||
AND available > 0
|
|
||||||
AND i.typeFk = vTypeFk
|
|
||||||
AND i.id != vItemFk
|
|
||||||
ORDER BY counter DESC,
|
|
||||||
(t1.name = vTag1 COLLATE utf8_general_ci) DESC,
|
|
||||||
(it1.value = vValue1 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag5 = vTag5 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value5 = vValue5 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag6 = vTag6 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value6 = vValue6 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag7 = vTag7 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value7 = vValue7 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.tag8 = vTag8 COLLATE utf8_general_ci) DESC,
|
|
||||||
(i.value8 = vValue8 COLLATE utf8_general_ci) DESC
|
|
||||||
LIMIT vResultsMax;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,19 +1,23 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(vItemFk INT, vWarehouseFk INT, vDate DATE, vIsShowedByType BOOL)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getSimilar`(
|
||||||
|
vSelf INT,
|
||||||
|
vTicketFk INT,
|
||||||
|
vShowType BOOL
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Propone articulos similares para posible cambio,
|
* Propone articulos disponibles ordenados, con la cantidad
|
||||||
* ordenado con la cantidad de veces usado y segun sus caracteristicas
|
* de veces usado y segun sus caracteristicas.
|
||||||
*
|
*
|
||||||
* @param vItemFk item id
|
* @param vSelf Id de artículo
|
||||||
* @param vWarehouseFk warehouse id
|
* @param vTicketFk Id de ticket
|
||||||
* @param vDate fecha para revisar disponible
|
* @param vShowType Mostrar tipos
|
||||||
* @param vIsShowedByType para mostrar solo artículos de ese tipo
|
|
||||||
*/
|
*/
|
||||||
|
DECLARE vWarehouseFk INT;
|
||||||
|
DECLARE vShipped DATE;
|
||||||
DECLARE vCalcFk INT;
|
DECLARE vCalcFk INT;
|
||||||
DECLARE vTypeFk INT;
|
DECLARE vTypeFk INT;
|
||||||
|
DECLARE vPriority INT DEFAULT 1;
|
||||||
|
|
||||||
DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||||
DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||||
|
@ -27,15 +31,40 @@ BEGIN
|
||||||
DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
DECLARE vValue7 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||||
DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
DECLARE vValue8 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
||||||
|
|
||||||
|
SELECT warehouseFk, shipped
|
||||||
|
INTO vWarehouseFk, vShipped
|
||||||
|
FROM ticket
|
||||||
|
WHERE id = vTicketFk;
|
||||||
|
|
||||||
SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value
|
SELECT typeFk,
|
||||||
INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1
|
tag5,
|
||||||
FROM vn.item i
|
value5,
|
||||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
tag6,
|
||||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
value6,
|
||||||
WHERE i.id = vItemFk;
|
tag7,
|
||||||
|
value7,
|
||||||
|
tag8,
|
||||||
|
value8,
|
||||||
|
t.name,
|
||||||
|
it.value
|
||||||
|
INTO vTypeFk,
|
||||||
|
vTag5,
|
||||||
|
vValue5,
|
||||||
|
vTag6,
|
||||||
|
vValue6,
|
||||||
|
vTag7,
|
||||||
|
vValue7,
|
||||||
|
vTag8,
|
||||||
|
vValue8,
|
||||||
|
vTag1,
|
||||||
|
vValue1
|
||||||
|
FROM item i
|
||||||
|
LEFT JOIN itemTag it ON it.itemFk = i.id
|
||||||
|
AND it.priority = vPriority
|
||||||
|
LEFT JOIN tag t ON t.id = it.tagFk
|
||||||
|
WHERE i.id = vSelf;
|
||||||
|
|
||||||
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vDate);
|
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
||||||
|
|
||||||
SELECT i.id itemFk,
|
SELECT i.id itemFk,
|
||||||
i.longName,
|
i.longName,
|
||||||
|
@ -53,32 +82,35 @@ BEGIN
|
||||||
i.value8,
|
i.value8,
|
||||||
(i.value8 <=> vValue8) match8,
|
(i.value8 <=> vValue8) match8,
|
||||||
a.available,
|
a.available,
|
||||||
IFNULL(ip.counter,0) counter,
|
IFNULL(ip.counter, 0) `counter`,
|
||||||
IF(b.groupingMode = 1, b.grouping, b.packing) as minQuantity
|
IF(b.groupingMode = 1, b.grouping, b.packing) minQuantity,
|
||||||
FROM vn.item i
|
iss.visible located
|
||||||
|
FROM item i
|
||||||
JOIN cache.available a ON a.item_id = i.id
|
JOIN cache.available a ON a.item_id = i.id
|
||||||
LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk
|
LEFT JOIN itemProposal ip ON ip.mateFk = i.id
|
||||||
LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1
|
AND ip.itemFk = vSelf
|
||||||
LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk
|
LEFT JOIN itemTag it ON it.itemFk = i.id
|
||||||
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk
|
AND it.priority = vPriority
|
||||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
LEFT JOIN tag t ON t.id = it.tagFk
|
||||||
|
LEFT JOIN cache.last_buy lb ON lb.item_id = i.id
|
||||||
|
AND lb.warehouse_id = vWarehouseFk
|
||||||
|
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||||
|
LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id
|
||||||
|
AND iss.warehouseFk = vWarehouseFk
|
||||||
WHERE a.calc_id = vCalcFk
|
WHERE a.calc_id = vCalcFk
|
||||||
AND available > 0
|
AND a.available > 0
|
||||||
AND IF(vIsShowedByType, i.typeFk = vTypeFk, TRUE)
|
AND IF(vShowType, i.typeFk = vTypeFk, TRUE)
|
||||||
AND i.id != vItemFk
|
AND i.id <> vSelf
|
||||||
ORDER BY counter DESC,
|
ORDER BY `counter` DESC,
|
||||||
(t1.name = vTag1) DESC,
|
(t.name = vTag1) DESC,
|
||||||
(it1.value = vValue1) DESC,
|
(it.value = vValue1) DESC,
|
||||||
(i.tag6 = vTag6) DESC,
|
|
||||||
(i.value6 = vValue6) DESC,
|
|
||||||
(i.tag5 = vTag5) DESC,
|
(i.tag5 = vTag5) DESC,
|
||||||
(i.value5 = vValue5) DESC,
|
match5 DESC,
|
||||||
|
(i.tag6 = vTag6) DESC,
|
||||||
|
match6 DESC,
|
||||||
(i.tag7 = vTag7) DESC,
|
(i.tag7 = vTag7) DESC,
|
||||||
(i.value7 = vValue7) DESC,
|
match7 DESC,
|
||||||
(i.tag8 = vTag8) DESC,
|
(i.tag8 = vTag8) DESC,
|
||||||
(i.value8 = vValue8) DESC
|
match8 DESC;
|
||||||
LIMIT 30;
|
|
||||||
|
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue