2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
|
2024-04-16 15:01:14 +00:00
|
|
|
vProblemCode VARCHAR(25)
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* Update column sale.problem with a problem code
|
2024-07-12 06:15:09 +00:00
|
|
|
*
|
2024-05-13 11:31:58 +00:00
|
|
|
* @param vProblemCode Code to set or unset
|
2024-06-27 11:01:42 +00:00
|
|
|
* @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded)
|
2024-04-16 15:01:14 +00:00
|
|
|
*/
|
2024-07-12 06:15:09 +00:00
|
|
|
DECLARE vSaleFk INT;
|
|
|
|
DECLARE vHasProblem INT;
|
2024-08-02 11:45:58 +00:00
|
|
|
DECLARE vIsProblemCalcNeeded BOOL;
|
2024-07-12 06:15:09 +00:00
|
|
|
DECLARE vDone BOOL;
|
2024-08-02 11:45:58 +00:00
|
|
|
DECLARE vSaleList CURSOR FOR
|
|
|
|
SELECT saleFk, hasProblem, isProblemCalcNeeded
|
|
|
|
FROM tmp.sale;
|
2024-07-12 06:15:09 +00:00
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
2024-06-27 11:01:42 +00:00
|
|
|
|
2024-07-12 06:15:09 +00:00
|
|
|
OPEN vSaleList;
|
|
|
|
l: LOOP
|
|
|
|
SET vDone = FALSE;
|
2024-08-02 11:45:58 +00:00
|
|
|
FETCH vSaleList INTO vSaleFk, vHasProblem, vIsProblemCalcNeeded;
|
2024-06-27 11:01:42 +00:00
|
|
|
|
2024-07-12 06:15:09 +00:00
|
|
|
IF vDone THEN
|
|
|
|
LEAVE l;
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
UPDATE sale
|
2024-08-02 11:45:58 +00:00
|
|
|
SET problem = IF (vIsProblemCalcNeeded,
|
|
|
|
CONCAT(
|
|
|
|
IF(vHasProblem,
|
|
|
|
CONCAT(problem, ',', vProblemCode),
|
|
|
|
REPLACE(problem, vProblemCode , ''))),
|
|
|
|
NULL)
|
2024-07-12 06:15:09 +00:00
|
|
|
WHERE id = vSaleFk;
|
|
|
|
END LOOP;
|
|
|
|
CLOSE vSaleList;
|
2024-04-16 15:01:14 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|