2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `stock`.`log_refreshSale`(
|
2024-04-08 07:11:40 +00:00
|
|
|
`vTableName` VARCHAR(255),
|
|
|
|
`vTableId` INT)
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
DROP TEMPORARY TABLE IF EXISTS tValues;
|
2024-04-08 07:11:40 +00:00
|
|
|
CREATE TEMPORARY TABLE tValues
|
2024-01-15 11:31:03 +00:00
|
|
|
ENGINE = MEMORY
|
|
|
|
SELECT
|
|
|
|
m.id saleFk,
|
|
|
|
m.ticketFk,
|
|
|
|
m.itemFk,
|
|
|
|
t.warehouseFk,
|
|
|
|
t.shipped,
|
|
|
|
ABS(m.quantity) quantity,
|
|
|
|
m.created,
|
2024-04-08 07:11:40 +00:00
|
|
|
TIMESTAMPADD(DAY, tp.life, t.shipped) expired,
|
2024-01-15 11:31:03 +00:00
|
|
|
m.quantity < 0 isIn,
|
2024-06-05 06:05:46 +00:00
|
|
|
m.isPicked OR s.alertLevel > al.id isPicked
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM vn.sale m
|
|
|
|
JOIN vn.ticket t ON t.id = m.ticketFk
|
|
|
|
JOIN vn.ticketState s ON s.ticketFk = t.id
|
|
|
|
JOIN vn.item i ON i.id = m.itemFk
|
|
|
|
JOIN vn.itemType tp ON tp.id = i.typeFk
|
2024-06-05 06:05:46 +00:00
|
|
|
JOIN vn.alertLevel al ON al.code = 'ON_PREPARATION'
|
2024-01-15 11:31:03 +00:00
|
|
|
WHERE (
|
|
|
|
vTableId IS NULL
|
|
|
|
OR (vTableName = 'ticket' AND t.id = vTableId)
|
|
|
|
OR (vTableName = 'sale' AND m.id = vTableId)
|
|
|
|
)
|
|
|
|
AND t.shipped >= vn.getInventoryDate()
|
|
|
|
AND m.quantity != 0;
|
|
|
|
|
|
|
|
REPLACE INTO inbound (
|
|
|
|
tableName, tableId, warehouseFk, dated,
|
2024-04-08 07:11:40 +00:00
|
|
|
itemFk, expired, quantity, isPicked
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
2024-04-08 07:11:40 +00:00
|
|
|
SELECT 'sale',
|
2024-01-15 11:31:03 +00:00
|
|
|
saleFk,
|
|
|
|
warehouseFk,
|
|
|
|
shipped,
|
|
|
|
itemFk,
|
2024-04-08 07:11:40 +00:00
|
|
|
expired,
|
2024-01-15 11:31:03 +00:00
|
|
|
quantity,
|
2024-04-08 07:11:40 +00:00
|
|
|
isPicked
|
|
|
|
FROM tValues
|
|
|
|
WHERE isIn;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
REPLACE INTO outbound (
|
|
|
|
tableName, tableId, warehouseFk, dated,
|
2024-04-08 07:11:40 +00:00
|
|
|
itemFk, created, quantity, isPicked
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
2024-04-08 07:11:40 +00:00
|
|
|
SELECT 'sale',
|
2024-01-15 11:31:03 +00:00
|
|
|
saleFk,
|
|
|
|
warehouseFk,
|
|
|
|
shipped,
|
|
|
|
itemFk,
|
|
|
|
created,
|
|
|
|
quantity,
|
2024-04-08 07:11:40 +00:00
|
|
|
isPicked
|
|
|
|
FROM tValues
|
|
|
|
WHERE !isIn;
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tValues;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|