2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-03-05 11:33:28 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemProposal`(
|
|
|
|
vSelf INT,
|
|
|
|
vTicketFk INT,
|
|
|
|
vShowType BOOL
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
2024-03-05 11:33:28 +00:00
|
|
|
* Propone articulos disponibles ordenados, con la cantidad
|
|
|
|
* de veces usado y segun sus caracteristicas.
|
|
|
|
*
|
|
|
|
* @param vSelf Id de artículo
|
|
|
|
* @param vTicketFk Id de ticket
|
|
|
|
* @param vShowType Mostrar tipos
|
|
|
|
*/
|
2024-01-15 11:31:03 +00:00
|
|
|
DECLARE vWarehouseFk INT;
|
|
|
|
DECLARE vShipped DATE;
|
|
|
|
DECLARE vCalcFk INT;
|
|
|
|
DECLARE vTypeFk INT;
|
2024-03-05 11:33:28 +00:00
|
|
|
DECLARE vPriority INT DEFAULT 1;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-03-05 11:33:28 +00:00
|
|
|
DECLARE vTag1 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vTag5 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vTag6 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vTag7 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vTag8 VARCHAR(25) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
|
|
|
|
DECLARE vValue1 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vValue5 VARCHAR(50) CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';
|
|
|
|
DECLARE vValue6 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';
|
2024-01-15 11:31:03 +00:00
|
|
|
|
2024-03-05 11:33:28 +00:00
|
|
|
SELECT warehouseFk, shipped
|
|
|
|
INTO vWarehouseFk, vShipped
|
|
|
|
FROM ticket
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE id = vTicketFk;
|
|
|
|
|
2024-03-05 11:33:28 +00:00
|
|
|
SELECT typeFk,
|
|
|
|
tag5,
|
|
|
|
value5,
|
|
|
|
tag6,
|
|
|
|
value6,
|
|
|
|
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;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped);
|
|
|
|
|
|
|
|
SELECT i.id itemFk,
|
|
|
|
i.longName,
|
|
|
|
i.subName,
|
|
|
|
i.tag5,
|
|
|
|
i.value5,
|
2024-03-05 11:33:28 +00:00
|
|
|
(i.value5 <=> vValue5) match5,
|
2024-01-15 11:31:03 +00:00
|
|
|
i.tag6,
|
|
|
|
i.value6,
|
2024-03-05 11:33:28 +00:00
|
|
|
(i.value6 <=> vValue6) match6,
|
2024-01-15 11:31:03 +00:00
|
|
|
i.tag7,
|
|
|
|
i.value7,
|
2024-03-05 11:33:28 +00:00
|
|
|
(i.value7 <=> vValue7) match7,
|
2024-01-15 11:31:03 +00:00
|
|
|
i.tag8,
|
|
|
|
i.value8,
|
2024-03-05 11:33:28 +00:00
|
|
|
(i.value8 <=> vValue8) match8,
|
2024-01-15 11:31:03 +00:00
|
|
|
a.available,
|
2024-03-05 11:33:28 +00:00
|
|
|
IFNULL(ip.counter, 0) `counter`,
|
|
|
|
IF(b.groupingMode = 1, b.grouping, b.packing) minQuantity,
|
2024-01-15 11:31:03 +00:00
|
|
|
iss.visible located
|
|
|
|
FROM item i
|
|
|
|
JOIN cache.available a ON a.item_id = i.id
|
2024-03-05 11:33:28 +00:00
|
|
|
LEFT JOIN itemProposal ip ON ip.mateFk = i.id
|
|
|
|
AND ip.itemFk = vSelf
|
|
|
|
LEFT JOIN itemTag it ON it.itemFk = i.id
|
|
|
|
AND it.priority = vPriority
|
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
LEFT JOIN buy b ON b.id = lb.buy_id
|
2024-03-05 11:33:28 +00:00
|
|
|
LEFT JOIN itemShelvingStock iss ON iss.itemFk = i.id
|
|
|
|
AND iss.warehouseFk = vWarehouseFk
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE a.calc_id = vCalcFk
|
2024-03-05 11:33:28 +00:00
|
|
|
AND a.available > 0
|
|
|
|
AND IF(vShowType, i.typeFk = vTypeFk, TRUE)
|
|
|
|
AND i.id <> vSelf
|
|
|
|
ORDER BY `counter` DESC,
|
|
|
|
(t.name = vTag1) DESC,
|
|
|
|
(it.value = vValue1) DESC,
|
|
|
|
(i.tag5 = vTag5) DESC,
|
|
|
|
match5 DESC,
|
|
|
|
(i.tag6 = vTag6) DESC,
|
|
|
|
match6 DESC,
|
|
|
|
(i.tag7 = vTag7) DESC,
|
|
|
|
match7 DESC,
|
|
|
|
(i.tag8 = vTag8) DESC,
|
|
|
|
match8 DESC;
|
2024-01-15 11:31:03 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|