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`.`ticket_isTooLittle`(
|
|
|
|
vSelf INT
|
|
|
|
)
|
2024-04-16 15:01:14 +00:00
|
|
|
RETURNS tinyint(1)
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
DECLARE vIsTooLittle TINYINT(1);
|
2024-08-27 15:12:41 +00:00
|
|
|
|
|
|
|
WITH tickets AS (
|
|
|
|
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-27 15:39:54 +00:00
|
|
|
FROM tickets ts
|
|
|
|
JOIN vn.ticket t ON t.addressFk = ts.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-27 15:12:41 +00:00
|
|
|
WHERE t.shipped BETWEEN ts.dated AND util.dayEnd(ts.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 ;
|