Hotfix: refs #7213 ticket_isTooLittle group by addressFk

This commit is contained in:
Carlos Andrés 2024-08-27 17:12:41 +02:00
parent 4a3f884173
commit 9a2351b958
2 changed files with 24 additions and 9 deletions

View File

@ -13,12 +13,20 @@ BEGIN
*/
DECLARE vIsTooLittle TINYINT(1);
WITH tickets 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 vn.ticket t
JOIN tickets ts ON ts.addressFk = t.addressFk
JOIN vn.volumeConfig vc
LEFT JOIN vn.saleVolume sv ON sv.ticketFk = t.id
WHERE t.shipped BETWEEN ts.dated AND util.dayEnd(ts.dated)
AND sv.litros > 0
AND t.totalWithoutVat > 0;
RETURN vIsTooLittle;
END$$

View File

@ -12,13 +12,20 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk, isProblemCalcNeeded))
ENGINE = MEMORY
WITH tickets AS (
SELECT addressFk, DATE(shipped) dated
FROM vn.ticket
WHERE id = vSelf
)
SELECT vSelf ticketFk,
ticket_isTooLittle(vSelf) hasProblem,
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded;
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded
FROM vn.ticket t
JOIN tickets ts ON ts.addressFk = t.addressFk
WHERE t.shipped BETWEEN ts.dated AND util.dayEnd(ts.dated);
CALL ticket_setProblem('isTooLittle');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;