2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
|
|
|
|
vProblemCode VARCHAR(25)
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* Update column sale.problem with a problem code
|
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-06-27 11:01:42 +00:00
|
|
|
UPDATE tmp.sale ts
|
|
|
|
JOIN sale s ON s.id = ts.saleFk
|
|
|
|
SET s.problem = NULL
|
|
|
|
WHERE NOT ts.isProblemCalcNeeded;
|
|
|
|
|
|
|
|
DELETE FROM tmp.sale WHERE NOT isProblemCalcNeeded;
|
|
|
|
|
2024-04-16 15:01:14 +00:00
|
|
|
UPDATE sale s
|
|
|
|
JOIN tmp.sale ts ON ts.saleFk = s.id
|
|
|
|
SET s.problem = CONCAT(
|
|
|
|
IF(ts.hasProblem,
|
|
|
|
CONCAT(s.problem, ',', vProblemCode),
|
|
|
|
REPLACE(s.problem, vProblemCode , '')));
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|