2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
2024-05-02 16:13:12 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`sale_hasComponentLack`(
|
|
|
|
vSelf INT
|
|
|
|
)RETURNS tinyint(1)
|
2024-04-16 15:01:14 +00:00
|
|
|
READS SQL DATA
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* Check if a sales line has all the required components.
|
2024-04-16 15:01:14 +00:00
|
|
|
*
|
2024-05-02 16:13:12 +00:00
|
|
|
* @param vSelf Id de sale
|
2024-04-16 15:01:14 +00:00
|
|
|
* @return BOOL
|
|
|
|
*/
|
|
|
|
DECLARE vHasComponentLack TINYINT(1);
|
|
|
|
|
|
|
|
WITH componentRequired AS(
|
2024-05-02 16:13:12 +00:00
|
|
|
SELECT COUNT(*) total
|
|
|
|
FROM vn.component
|
2024-04-16 15:01:14 +00:00
|
|
|
WHERE isRequired
|
|
|
|
)SELECT SUM(IF(c.isRequired, TRUE, FALSE)) <> cr.total INTO vHasComponentLack
|
|
|
|
FROM vn.sale s
|
|
|
|
JOIN componentRequired cr
|
|
|
|
LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
|
|
|
|
LEFT JOIN vn.component c ON c.id = sc.componentFk
|
|
|
|
WHERE s.id = vSelf;
|
|
|
|
|
|
|
|
RETURN vHasComponentLack;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|