Merge pull request 'fix: refs #7829 Error al calcular problemas de componentes' (!2828) from 7829-Error-calcular-problemas-componentes into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2828 Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
This commit is contained in:
commit
69d4c8bd6e
|
@ -13,7 +13,7 @@ BEGIN
|
||||||
DECLARE vAvailableCache INT;
|
DECLARE vAvailableCache INT;
|
||||||
DECLARE vVisibleCache INT;
|
DECLARE vVisibleCache INT;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
DECLARE vComponentCount INT;
|
DECLARE vRequiredComponent INT;
|
||||||
|
|
||||||
DECLARE vCursor CURSOR FOR
|
DECLARE vCursor CURSOR FOR
|
||||||
SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(tt.shipped))
|
SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(tt.shipped))
|
||||||
|
@ -54,7 +54,7 @@ BEGIN
|
||||||
SELECT ticketFk, clientFk
|
SELECT ticketFk, clientFk
|
||||||
FROM tmp.sale_getProblems;
|
FROM tmp.sale_getProblems;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vComponentCount
|
SELECT COUNT(*) INTO vRequiredComponent
|
||||||
FROM component
|
FROM component
|
||||||
WHERE isRequired;
|
WHERE isRequired;
|
||||||
|
|
||||||
|
@ -96,20 +96,18 @@ BEGIN
|
||||||
|
|
||||||
-- Faltan componentes
|
-- Faltan componentes
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk)
|
INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk)
|
||||||
SELECT ticketFk, (vComponentCount > nComp) hasComponentLack, saleFk
|
SELECT t.id, COUNT(c.id) < vRequiredComponent hasComponentLack, s.id
|
||||||
FROM (
|
|
||||||
SELECT COUNT(s.id) nComp, tl.ticketFk, s.id saleFk
|
|
||||||
FROM tmp.ticket_list tl
|
FROM tmp.ticket_list tl
|
||||||
JOIN sale s ON s.ticketFk = tl.ticketFk
|
|
||||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
|
||||||
LEFT JOIN component c ON c.id = sc.componentFk AND c.isRequired
|
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
JOIN ticket t ON t.id = tl.ticketFk
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
|
LEFT JOIN component c ON c.id = sc.componentFk
|
||||||
|
AND c.isRequired
|
||||||
WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
||||||
AND s.quantity > 0
|
AND s.quantity > 0
|
||||||
GROUP BY s.id
|
GROUP BY s.id
|
||||||
) sub
|
|
||||||
HAVING hasComponentLack;
|
HAVING hasComponentLack;
|
||||||
|
|
||||||
-- Cliente congelado
|
-- Cliente congelado
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRiskByClient`(
|
||||||
|
vClientFk INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Updates future ticket risk for a client.
|
||||||
|
*
|
||||||
|
* @param vClientFk Id client
|
||||||
|
*/
|
||||||
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
|
DECLARE vTicketFk INT;
|
||||||
|
DECLARE vTickets CURSOR FOR
|
||||||
|
SELECT id
|
||||||
|
FROM ticket
|
||||||
|
WHERE clientFk = vClientFk
|
||||||
|
AND shipped >= util.VN_CURDATE()
|
||||||
|
AND refFk IS NULL;
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
OPEN vTickets;
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH vTickets INTO vTicketFk;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CALL vn.ticket_setProblemRisk(vTicketFk);
|
||||||
|
END LOOP;
|
||||||
|
CLOSE vTickets;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
Loading…
Reference in New Issue