salix/db/routines/vn/procedures/sale_getRoundingProblem.sql

34 lines
859 B
SQL

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getRoundingProblem`(
vSelf INT
)
BEGIN
/**
* Update the rounding problem for a sales line
* @param vSelf Id sale
*/
DECLARE vItemFk INT;
DECLARE vWarehouseFk INT;
DECLARE vDated DATE;
DECLARE vQuantity INT;
SELECT s.itemFk, t.warehouseFk, DATE(t.shipped), s.quantity
INTO vItemFk, vWarehouseFk, vDated, vQuantity
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
WHERE s.id = vSelf;
CALL buyUltimate(vWarehouseFk, vDated);
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem
FROM tmp.buyUltimate bu
JOIN buy b ON b.id = bu.buyFk
WHERE bu.itemFk = vItemFk;
CALL sale_setProblem('hasRounding');
DROP TEMPORARY TABLE tmp.ticket;
DROP TEMPORARY TABLE tmp.buyUltimate;
END$$
DELIMITER ;