2024-04-16 15:01:14 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
2024-05-02 16:13:12 +00:00
|
|
|
vSelf INT
|
|
|
|
)
|
2024-08-28 09:59:46 +00:00
|
|
|
RETURNS BOOL
|
2024-04-16 15:01:14 +00:00
|
|
|
READS SQL DATA
|
|
|
|
BEGIN
|
|
|
|
/**
|
2024-05-02 16:13:12 +00:00
|
|
|
* Check if the ticket is small based on the volume and amount parameters.
|
2024-04-16 15:01:14 +00:00
|
|
|
*
|
2024-05-13 11:31:58 +00:00
|
|
|
* @param vSelf Id ticket
|
2024-04-16 15:01:14 +00:00
|
|
|
* @return BOOL
|
|
|
|
*/
|
2024-08-28 09:59:46 +00:00
|
|
|
DECLARE vIsTooLittle BOOL;
|
2024-08-27 15:12:41 +00:00
|
|
|
|
2024-08-28 09:59:46 +00:00
|
|
|
WITH ticketData AS (
|
2024-08-27 15:12:41 +00:00
|
|
|
SELECT addressFk, DATE(shipped) dated
|
|
|
|
FROM vn.ticket
|
|
|
|
WHERE id = vSelf
|
|
|
|
)
|
2024-04-16 15:01:14 +00:00
|
|
|
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
2024-08-27 15:12:41 +00:00
|
|
|
AND SUM(IFNULL(t.totalWithoutVat, 0)) < vc.minTicketValue) INTO vIsTooLittle
|
2024-08-28 09:59:46 +00:00
|
|
|
FROM ticketData td
|
|
|
|
JOIN vn.ticket t ON t.addressFk = td.addressFk
|
2024-08-27 15:12:41 +00:00
|
|
|
LEFT JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
2024-08-27 15:39:54 +00:00
|
|
|
JOIN vn.volumeConfig vc
|
2024-08-28 09:59:46 +00:00
|
|
|
WHERE t.shipped BETWEEN td.dated AND util.dayEnd(td.dated)
|
2024-08-27 15:39:54 +00:00
|
|
|
AND ticket_isProblemCalcNeeded(t.id);
|
2024-04-16 15:01:14 +00:00
|
|
|
|
|
|
|
RETURN vIsTooLittle;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|