fix: refs #7213 Hotfix-ticket_isTooLittle-group-by-addressFk #2895
|
@ -2,7 +2,7 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
||||||
vSelf INT
|
vSelf INT
|
||||||
)
|
)
|
||||||
RETURNS tinyint(1)
|
RETURNS BOOL
|
||||||
READS SQL DATA
|
READS SQL DATA
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
@ -11,14 +11,21 @@ BEGIN
|
||||||
* @param vSelf Id ticket
|
* @param vSelf Id ticket
|
||||||
* @return BOOL
|
* @return BOOL
|
||||||
*/
|
*/
|
||||||
DECLARE vIsTooLittle TINYINT(1);
|
DECLARE vIsTooLittle BOOL;
|
||||||
carlosap marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
|
WITH ticketData AS (
|
||||||
carlosap marked this conversation as resolved
Outdated
guillermo
commented
Aço es soles una observació, crec que no te sentit dir-li tickets si soles es 1 ticket, jo li diría ticketAddress o algo per l'estil Aço es soles una observació, crec que no te sentit dir-li tickets si soles es 1 ticket, jo li diría ticketAddress o algo per l'estil
|
|||||||
|
SELECT addressFk, DATE(shipped) dated
|
||||||
|
FROM vn.ticket
|
||||||
|
WHERE id = vSelf
|
||||||
|
)
|
||||||
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
||||||
AND IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle
|
AND SUM(IFNULL(t.totalWithoutVat, 0)) < vc.minTicketValue) INTO vIsTooLittle
|
||||||
FROM ticket t
|
FROM ticketData td
|
||||||
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
JOIN vn.ticket t ON t.addressFk = td.addressFk
|
||||||
JOIN volumeConfig vc
|
LEFT JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
||||||
WHERE t.id = vSelf;
|
JOIN vn.volumeConfig vc
|
||||||
|
WHERE t.shipped BETWEEN td.dated AND util.dayEnd(td.dated)
|
||||||
|
AND ticket_isProblemCalcNeeded(t.id);
|
||||||
|
|
||||||
RETURN vIsTooLittle;
|
RETURN vIsTooLittle;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -8,17 +8,27 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @param vSelf Id del ticket
|
* @param vSelf Id del ticket
|
||||||
*/
|
*/
|
||||||
|
DECLARE vTicketIsTooLittle BOOL;
|
||||||
|
|
||||||
|
SELECT ticket_isTooLittle(vSelf) INTO vTicketIsTooLittle;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
carlosap marked this conversation as resolved
Outdated
guillermo
commented
Lo mateix que ací #2895 (comment) Lo mateix que ací https://gitea.verdnatura.es/verdnatura/salix/pulls/2895#issuecomment-61020
|
|||||||
(INDEX(ticketFk, isProblemCalcNeeded))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf ticketFk,
|
WITH ticketData AS (
|
||||||
ticket_isTooLittle(vSelf) hasProblem,
|
SELECT addressFk, DATE(shipped) dated
|
||||||
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded;
|
FROM vn.ticket
|
||||||
carlosap marked this conversation as resolved
Outdated
guillermo
commented
Ací estás pasant per cada ticket per la funció Entenc tot lo demes, ja que si que te interesa cridar a la funció Ací estás pasant per cada ticket per la funció `vn.ticket_isTooLittle()`, no et fa falta, jo ficaria el SELECT amb el ticket vSelf dalt en una variable, ja que tots els tickets te van a donar lo mateix.
Entenc tot lo demes, ja que si que te interesa cridar a la funció `ticket_isProblemCalcNeeded` per cada 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');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
Loading…
Reference in New Issue
BOOL, i dalt en el RETURNS tame BOOL