2024-06-27 11:01:42 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`(
|
2024-06-27 11:01:42 +00:00
|
|
|
vSelf INT
|
|
|
|
)
|
|
|
|
RETURNS BOOL
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Check if the ticket requires to update column vn.ticket.problem
|
|
|
|
*
|
|
|
|
* @param vSelf Id ticket
|
|
|
|
* @return BOOL
|
|
|
|
*/
|
|
|
|
DECLARE vIsProblemCalcNeeded BOOL;
|
|
|
|
|
|
|
|
SELECT COUNT(*) INTO vIsProblemCalcNeeded
|
|
|
|
FROM ticket t
|
|
|
|
JOIN client c ON c.id = t.clientFk
|
|
|
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
|
|
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
|
|
|
WHERE t.id = vSelf
|
|
|
|
AND dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
|
|
|
AND c.typeFk = 'normal';
|
|
|
|
|
|
|
|
RETURN vIsProblemCalcNeeded;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|