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