24 lines
570 B
SQL
24 lines
570 B
SQL
DELIMITER $$
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
|
vSelf INT
|
|
)
|
|
RETURNS tinyint(1)
|
|
READS SQL DATA
|
|
BEGIN
|
|
/**
|
|
* Check if the ticket is small based on the volume and amount parameters.
|
|
*
|
|
* @return BOOL
|
|
*/
|
|
DECLARE vIsTooLittle TINYINT(1);
|
|
|
|
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
|
OR IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle
|
|
FROM ticket t
|
|
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
|
JOIN volumeConfig vc
|
|
WHERE t.id = vSelf;
|
|
|
|
RETURN vIsTooLittle;
|
|
END$$
|
|
DELIMITER ; |