Merge pull request 'fix: refs #7213 Hotfix-ticket_isTooLittle-group-by-addressFk' (!2895) from Hotfix-ticket_isTooLittle-group-by-addressFk into master
Reviewed-on: #2895 Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
This commit is contained in:
commit
88246174dc
|
@ -2,7 +2,7 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
||||
vSelf INT
|
||||
)
|
||||
RETURNS tinyint(1)
|
||||
RETURNS BOOL
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -11,14 +11,21 @@ BEGIN
|
|||
* @param vSelf Id ticket
|
||||
* @return BOOL
|
||||
*/
|
||||
DECLARE vIsTooLittle TINYINT(1);
|
||||
|
||||
DECLARE vIsTooLittle BOOL;
|
||||
|
||||
WITH ticketData AS (
|
||||
SELECT addressFk, DATE(shipped) dated
|
||||
FROM vn.ticket
|
||||
WHERE id = vSelf
|
||||
)
|
||||
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
||||
AND 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;
|
||||
AND SUM(IFNULL(t.totalWithoutVat, 0)) < vc.minTicketValue) INTO vIsTooLittle
|
||||
FROM ticketData td
|
||||
JOIN vn.ticket t ON t.addressFk = td.addressFk
|
||||
LEFT JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
||||
JOIN vn.volumeConfig vc
|
||||
WHERE t.shipped BETWEEN td.dated AND util.dayEnd(td.dated)
|
||||
AND ticket_isProblemCalcNeeded(t.id);
|
||||
|
||||
RETURN vIsTooLittle;
|
||||
END$$
|
||||
|
|
|
@ -8,17 +8,27 @@ BEGIN
|
|||
*
|
||||
* @param vSelf Id del ticket
|
||||
*/
|
||||
|
||||
DECLARE vTicketIsTooLittle BOOL;
|
||||
|
||||
SELECT ticket_isTooLittle(vSelf) INTO vTicketIsTooLittle;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||
ENGINE = MEMORY
|
||||
SELECT vSelf ticketFk,
|
||||
ticket_isTooLittle(vSelf) hasProblem,
|
||||
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded;
|
||||
|
||||
WITH ticketData AS (
|
||||
SELECT addressFk, DATE(shipped) dated
|
||||
FROM vn.ticket
|
||||
WHERE id = vSelf
|
||||
)
|
||||
SELECT t.id ticketFk,
|
||||
vTicketIsTooLittle hasProblem,
|
||||
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||
FROM vn.ticket t
|
||||
JOIN ticketData td ON td.addressFk = t.addressFk
|
||||
WHERE t.shipped BETWEEN td.dated AND util.dayEnd(td.dated);
|
||||
|
||||
CALL ticket_setProblem('isTooLittle');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue