29 lines
902 B
SQL
29 lines
902 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLackByComponent`(
|
|
vComponentFk INT
|
|
)
|
|
BEGIN
|
|
/**
|
|
* Update the issues for sales lines that have or no longer have problems with components, verify
|
|
* whether all mandatory components are present or not resulting from changes in the table vn.component
|
|
*
|
|
* @param vComponentFk Id component
|
|
*/
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
|
(INDEX(saleFk))
|
|
ENGINE = MEMORY
|
|
SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem
|
|
FROM (
|
|
SELECT s.id saleFk
|
|
FROM ticket t
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
|
WHERE t.shipped >= util.VN_CURDATE()
|
|
AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk)
|
|
GROUP BY s.id) sub;
|
|
|
|
CALL sale_setProblem('hasComponentLack');
|
|
|
|
DROP TEMPORARY TABLE tmp.sale;
|
|
END$$
|
|
DELIMITER ; |