feat: refs #7774 ticket_cloneWeekly #2781
|
@ -4,7 +4,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_cloneWeekly`
|
||||||
vDateTo DATE
|
vDateTo DATE
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vIsDone BOOL;
|
|
||||||
DECLARE vLanding DATE;
|
DECLARE vLanding DATE;
|
||||||
DECLARE vShipment DATE;
|
DECLARE vShipment DATE;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
|
@ -15,10 +14,17 @@ BEGIN
|
||||||
DECLARE vAgencyModeFk INT;
|
DECLARE vAgencyModeFk INT;
|
||||||
DECLARE vNewTicket INT;
|
DECLARE vNewTicket INT;
|
||||||
DECLARE vYear INT;
|
DECLARE vYear INT;
|
||||||
DECLARE vSalesPersonFK INT;
|
DECLARE vObservationSalesPersonFk INT
|
||||||
DECLARE vItemPicker INT;
|
DEFAULT (SELECT id FROM observationType WHERE code = 'salesPerson');
|
||||||
|
DECLARE vObservationItemPickerFk INT
|
||||||
|
DEFAULT (SELECT id FROM observationType WHERE code = 'itemPicker');
|
||||||
|
DECLARE vEmail VARCHAR(255);
|
||||||
|
DECLARE vIsDuplicateMail BOOL;
|
||||||
|
DECLARE vSubject VARCHAR(100);
|
||||||
|
DECLARE vMessage TEXT;
|
||||||
|
DECLARE vDone BOOL;
|
||||||
|
|
||||||
DECLARE rsTicket CURSOR FOR
|
DECLARE vTickets CURSOR FOR
|
||||||
SELECT tt.ticketFk,
|
SELECT tt.ticketFk,
|
||||||
t.clientFk,
|
t.clientFk,
|
||||||
t.warehouseFk,
|
t.warehouseFk,
|
||||||
|
@ -31,20 +37,14 @@ BEGIN
|
||||||
JOIN tmp.time ti
|
JOIN tmp.time ti
|
||||||
WHERE WEEKDAY(ti.dated) = tt.weekDay;
|
WHERE WEEKDAY(ti.dated) = tt.weekDay;
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
CALL `util`.`time_generate`(vDateFrom, vDateTo);
|
CALL `util`.`time_generate`(vDateFrom, vDateTo);
|
||||||
|
|
||||||
OPEN rsTicket;
|
OPEN vTickets;
|
||||||
myLoop: LOOP
|
l: LOOP
|
||||||
BEGIN
|
SET vDone = FALSE;
|
||||||
DECLARE vSalesPersonEmail VARCHAR(150);
|
FETCH vTickets INTO
|
||||||
DECLARE vIsDuplicateMail BOOL;
|
|
||||||
DECLARE vSubject VARCHAR(150);
|
|
||||||
DECLARE vMessage TEXT;
|
|
||||||
|
|
||||||
SET vIsDone = FALSE;
|
|
||||||
FETCH rsTicket INTO
|
|
||||||
vTicketFk,
|
vTicketFk,
|
||||||
vClientFk,
|
vClientFk,
|
||||||
vWarehouseFk,
|
vWarehouseFk,
|
||||||
|
@ -53,11 +53,11 @@ BEGIN
|
||||||
vAgencyModeFk,
|
vAgencyModeFk,
|
||||||
vShipment;
|
vShipment;
|
||||||
|
|
||||||
IF vIsDone THEN
|
IF vDone THEN
|
||||||
LEAVE myLoop;
|
LEAVE l;
|
||||||
END IF;
|
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
|
IF EXISTS (SELECT TRUE FROM ticket tOrig
|
||||||
JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk
|
JOIN sale saleOrig ON tOrig.id = saleOrig.ticketFk
|
||||||
JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id
|
JOIN saleCloned sc ON sc.saleOriginalFk = saleOrig.id
|
||||||
|
@ -67,7 +67,7 @@ BEGIN
|
||||||
AND tClon.isDeleted = FALSE
|
AND tClon.isDeleted = FALSE
|
||||||
AND DATE(tClon.shipped) = vShipment)
|
AND DATE(tClon.shipped) = vShipment)
|
||||||
THEN
|
THEN
|
||||||
ITERATE myLoop;
|
ITERATE l;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF vAgencyModeFk IS NULL THEN
|
IF vAgencyModeFk IS NULL THEN
|
||||||
|
@ -107,15 +107,15 @@ BEGIN
|
||||||
priceFixed,
|
priceFixed,
|
||||||
isPriceFixed)
|
isPriceFixed)
|
||||||
SELECT vNewTicket,
|
SELECT vNewTicket,
|
||||||
saleOrig.itemFk,
|
itemFk,
|
||||||
saleOrig.concept,
|
concept,
|
||||||
saleOrig.quantity,
|
quantity,
|
||||||
saleOrig.price,
|
price,
|
||||||
saleOrig.discount,
|
discount,
|
||||||
saleOrig.priceFixed,
|
priceFixed,
|
||||||
saleOrig.isPriceFixed
|
isPriceFixed
|
||||||
FROM sale saleOrig
|
FROM sale
|
||||||
WHERE saleOrig.ticketFk = vTicketFk;
|
WHERE ticketFk = vTicketFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO saleCloned(saleOriginalFk, saleClonedFk)
|
INSERT IGNORE INTO saleCloned(saleOriginalFk, saleClonedFk)
|
||||||
SELECT saleOriginal.id, saleClon.id
|
SELECT saleOriginal.id, saleClon.id
|
||||||
|
@ -154,21 +154,13 @@ BEGIN
|
||||||
FROM ticketRequest
|
FROM ticketRequest
|
||||||
WHERE ticketFk = vTicketFk;
|
WHERE ticketFk = vTicketFk;
|
||||||
|
|
||||||
SELECT id INTO vSalesPersonFK
|
|
||||||
FROM observationType
|
|
||||||
WHERE code = 'salesPerson';
|
|
||||||
|
|
||||||
SELECT id INTO vItemPicker
|
|
||||||
FROM observationType
|
|
||||||
WHERE code = 'itemPicker';
|
|
||||||
|
|
||||||
INSERT INTO ticketObservation(
|
INSERT INTO ticketObservation(
|
||||||
ticketFk,
|
ticketFk,
|
||||||
observationTypeFk,
|
observationTypeFk,
|
||||||
description)
|
description)
|
||||||
VALUES(
|
VALUES(
|
||||||
vNewTicket,
|
vNewTicket,
|
||||||
vSalesPersonFK,
|
vObservationSalesPersonFk,
|
||||||
CONCAT('turno desde ticket: ',vTicketFk))
|
CONCAT('turno desde ticket: ',vTicketFk))
|
||||||
ON DUPLICATE KEY UPDATE description =
|
ON DUPLICATE KEY UPDATE description =
|
||||||
CONCAT(ticketObservation.description,VALUES(description),' ');
|
CONCAT(ticketObservation.description,VALUES(description),' ');
|
||||||
|
@ -178,16 +170,17 @@ BEGIN
|
||||||
description)
|
description)
|
||||||
VALUES(
|
VALUES(
|
||||||
vNewTicket,
|
vNewTicket,
|
||||||
vItemPicker,
|
vObservationItemPickerFk,
|
||||||
'ATENCION: Contiene lineas de TURNO')
|
'ATENCION: Contiene lineas de TURNO')
|
||||||
ON DUPLICATE KEY UPDATE description =
|
ON DUPLICATE KEY UPDATE description =
|
||||||
CONCAT(ticketObservation.description,VALUES(description),' ');
|
CONCAT(ticketObservation.description,VALUES(description),' ');
|
||||||
|
|
||||||
IF (vLanding IS NULL) THEN
|
IF vLanding IS NULL THEN
|
||||||
|
SELECT IFNULL(d.notificationEmail, e.email) INTO vEmail
|
||||||
|
|||||||
SELECT e.email INTO vSalesPersonEmail
|
|
||||||
FROM client c
|
FROM client c
|
||||||
JOIN account.emailUser e ON e.userFk = c.salesPersonFk
|
JOIN account.emailUser e ON e.userFk = c.salesPersonFk
|
||||||
|
LEFT JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk
|
||||||
|
LEFT JOIN department d ON d.id = wd.departmentFk
|
||||||
WHERE c.id = vClientFk;
|
WHERE c.id = vClientFk;
|
||||||
|
|
||||||
SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ',
|
SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ',
|
||||||
|
@ -199,20 +192,21 @@ BEGIN
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vIsDuplicateMail
|
SELECT COUNT(*) INTO vIsDuplicateMail
|
||||||
FROM mail
|
FROM mail
|
||||||
WHERE receiver = vSalesPersonEmail
|
WHERE receiver = vEmail
|
||||||
AND subject = vSubject;
|
AND subject = vSubject;
|
||||||
|
|
||||||
IF NOT vIsDuplicateMail THEN
|
IF NOT vIsDuplicateMail THEN
|
||||||
CALL mail_insert(vSalesPersonEmail, NULL, vSubject, vMessage);
|
CALL mail_insert(vEmail, NULL, vSubject, vMessage);
|
||||||
END IF;
|
END IF;
|
||||||
CALL ticket_setState(vNewTicket, 'FIXING');
|
CALL ticket_setState(vNewTicket, 'FIXING');
|
||||||
ELSE
|
ELSE
|
||||||
CALL ticketCalculateClon(vNewTicket, vTicketFk);
|
CALL ticketCalculateClon(vNewTicket, vTicketFk);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
END;
|
|
||||||
END LOOP;
|
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$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue
Realmente el cambio es este, lo demás es refactor.