2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
2024-05-13 08:06:00 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLackByComponent`(
|
2024-04-16 15:01:14 +00:00
|
|
|
vComponentFk INT
|
|
|
|
)
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* 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
|
2024-04-16 15:01:14 +00:00
|
|
|
*
|
2024-05-03 08:19:05 +00:00
|
|
|
* @param vComponentFk Id component
|
2024-04-16 15:01:14 +00:00
|
|
|
*/
|
|
|
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
2024-06-27 11:01:42 +00:00
|
|
|
(INDEX(saleFk, isProblemCalcNeeded))
|
2024-04-16 15:01:14 +00:00
|
|
|
ENGINE = MEMORY
|
2024-06-27 11:01:42 +00:00
|
|
|
SELECT saleFk,
|
|
|
|
sale_hasComponentLack(saleFk) hasProblem,
|
|
|
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
2024-05-22 12:50:45 +00:00
|
|
|
FROM (
|
2024-06-27 11:01:42 +00:00
|
|
|
SELECT s.id saleFk, s.ticketFk
|
2024-05-22 12:50:45 +00:00
|
|
|
FROM ticket t
|
|
|
|
JOIN sale s ON s.ticketFk = t.id
|
|
|
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
2024-06-05 08:11:04 +00:00
|
|
|
WHERE t.shipped >= util.VN_CURDATE()
|
2024-05-22 12:50:45 +00:00
|
|
|
AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk)
|
|
|
|
GROUP BY s.id) sub;
|
2024-05-02 16:13:12 +00:00
|
|
|
|
2024-04-16 15:01:14 +00:00
|
|
|
CALL sale_setProblem('hasComponentLack');
|
|
|
|
|
|
|
|
DROP TEMPORARY TABLE tmp.sale;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|