From c4e82022611fecada029cfa8614e4c4eceb0f8bf Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Aug 2024 08:53:24 +0200 Subject: [PATCH] feat: refs #7774 #7774 Changes ticket_cloneWeekly --- .../vn/procedures/ticket_cloneWeekly.sql | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/db/routines/vn/procedures/ticket_cloneWeekly.sql b/db/routines/vn/procedures/ticket_cloneWeekly.sql index f689f2600..be19a40bf 100644 --- a/db/routines/vn/procedures/ticket_cloneWeekly.sql +++ b/db/routines/vn/procedures/ticket_cloneWeekly.sql @@ -17,35 +17,33 @@ BEGIN DECLARE vYear INT; DECLARE vSalesPersonFK INT; DECLARE vItemPicker INT; - DECLARE vTicketfailed INT; + DECLARE vEmail VARCHAR(150); + DECLARE vIsDuplicateMail BOOL; + DECLARE vSubject VARCHAR(150); + DECLARE vMessage TEXT; - DECLARE rsTicket CURSOR FOR - SELECT tt.ticketFk, - t.clientFk, - t.warehouseFk, - t.companyFk, - t.addressFk, - tt.agencyModeFk, - ti.dated - FROM ticketWeekly tt - JOIN ticket t ON tt.ticketFk = t.id - JOIN tmp.time ti - WHERE WEEKDAY(ti.dated) = tt.weekDay; + DECLARE vTickets CURSOR FOR + SELECT tt.ticketFk, + t.clientFk, + t.warehouseFk, + t.companyFk, + t.addressFk, + tt.agencyModeFk, + ti.dated + FROM ticketWeekly tt + JOIN ticket t ON tt.ticketFk = t.id + JOIN tmp.time ti + WHERE WEEKDAY(ti.dated) = tt.weekDay; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; - - CALL `util`.`time_generate`(vDateFrom,vDateTo); - - OPEN rsTicket; - myLoop: LOOP - BEGIN - DECLARE vSalesPersonEmail VARCHAR(150); - DECLARE vIsDuplicateMail BOOL; - DECLARE vSubject VARCHAR(150); - DECLARE vMessage TEXT; + + CALL `util`.`time_generate`(vDateFrom, vDateTo); + + OPEN vTickets; + l: LOOP SET vIsDone = FALSE; - FETCH rsTicket INTO + FETCH vTickets INTO vTicketFk, vClientFk, vWarehouseFk, @@ -55,10 +53,10 @@ BEGIN vShipment; IF vIsDone THEN - LEAVE myLoop; + LEAVE l; END IF; - -- busca si el ticket ya ha sido clonado + -- Busca si el ticket ya ha sido clonado IF EXISTS (SELECT TRUE FROM ticket tOrig JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id @@ -68,7 +66,7 @@ BEGIN AND tClon.isDeleted = FALSE AND DATE(tClon.shipped) = vShipment) THEN - ITERATE myLoop; + ITERATE l; END IF; IF vAgencyModeFk IS NULL THEN @@ -184,9 +182,9 @@ BEGIN ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); - IF (vLanding IS NULL) THEN + IF vLanding IS NULL THEN - SELECT IFNULL(d.notificationEmail,e.email) INTO vSalesPersonEmail + SELECT IFNULL(d.notificationEmail, e.email) INTO vEmail FROM client c JOIN worker w ON w.id = c.salesPersonFk JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk @@ -203,21 +201,21 @@ BEGIN SELECT COUNT(*) INTO vIsDuplicateMail FROM mail - WHERE receiver = vSalesPersonEmail + WHERE receiver = vEmail AND subject = vSubject; IF NOT vIsDuplicateMail THEN - CALL mail_insert(vSalesPersonEmail, NULL, vSubject, vMessage); + CALL mail_insert(vEmail, NULL, vSubject, vMessage); END IF; CALL ticket_setState(vNewTicket, 'FIXING'); ELSE CALL ticketCalculateClon(vNewTicket, vTicketFk); END IF; - - END; END LOOP; - CLOSE rsTicket; + CLOSE vTickets; - DROP TEMPORARY TABLE IF EXISTS tmp.time, tmp.zoneGetLanded; + DROP TEMPORARY TABLE IF EXISTS + tmp.time, + tmp.zoneGetLanded; END$$ DELIMITER ;