24 lines
666 B
MySQL
24 lines
666 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(vSelf INT)
|
||
|
RETURNS tinyint(1)
|
||
|
READS SQL DATA
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Comprueba si el ticket es pequeño en función de los parámtros de configuración
|
||
|
* teniendo en cuenta el volumen y el importe
|
||
|
*
|
||
|
* @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 sale s ON s.ticketFk = t.id
|
||
|
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
||
|
JOIN volumeConfig vc
|
||
|
WHERE t.id = vSelf;
|
||
|
|
||
|
RETURN vIsTooLittle;
|
||
|
END$$
|
||
|
DELIMITER ;
|