refs #7486 Fix collection_new
This commit is contained in:
parent
e202bea92f
commit
a7b653c42a
|
@ -47,9 +47,9 @@ BEGIN
|
||||||
INTO vHasTooMuchCollections,
|
INTO vHasTooMuchCollections,
|
||||||
vLockName
|
vLockName
|
||||||
FROM productionConfig pc
|
FROM productionConfig pc
|
||||||
LEFT JOIN tCollection ON TRUE;
|
LEFT JOIN tmp.collection ON TRUE;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tCollection;
|
DROP TEMPORARY TABLE tmp.collection;
|
||||||
|
|
||||||
IF vHasTooMuchCollections THEN
|
IF vHasTooMuchCollections THEN
|
||||||
CALL util.throw('Hay colecciones pendientes');
|
CALL util.throw('Hay colecciones pendientes');
|
||||||
|
|
|
@ -7,27 +7,32 @@ BEGIN
|
||||||
* @param vWorkerFk id del worker.
|
* @param vWorkerFk id del worker.
|
||||||
* @table Devuelve tabla temporal con las colecciones pendientes
|
* @table Devuelve tabla temporal con las colecciones pendientes
|
||||||
*/
|
*/
|
||||||
DROP TEMPORARY TABLE IF EXISTS tCollection;
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
CREATE TEMPORARY TABLE tCollection
|
CREATE OR REPLACE TEMPORARY TABLE tmp.collection
|
||||||
SELECT c.id collectionFk,
|
ENGINE = MEMORY
|
||||||
date(c.created) created,
|
SELECT c.id collectionFk,
|
||||||
COUNT(DISTINCT tc.ticketFk) ticketTotalCount
|
DATE(c.created) created,
|
||||||
FROM collection c
|
COUNT(DISTINCT tc.ticketFk) ticketTotalCount
|
||||||
JOIN ticketCollection tc ON tc.collectionFk = c.id
|
FROM collection c
|
||||||
JOIN sale s ON s.ticketFk = tc.ticketFk
|
JOIN ticketCollection tc ON tc.collectionFk = c.id
|
||||||
JOIN ticketState ts ON ts.ticketFk = tc.ticketFk
|
JOIN sale s ON s.ticketFk = tc.ticketFk
|
||||||
JOIN state s2 ON s2.id = ts.stateFk
|
JOIN ticketState ts ON ts.ticketFk = tc.ticketFk
|
||||||
JOIN productionConfig pc
|
JOIN state s2 ON s2.id = ts.stateFk
|
||||||
JOIN vn.state ss on ss.code = 'PREPARED'
|
JOIN productionConfig pc
|
||||||
LEFT JOIN vn.saleTracking st on st.saleFk = s.id AND st.stateFk = ss.id
|
JOIN vn.state ss ON ss.code = 'PREPARED'
|
||||||
WHERE c.workerFk = vWorkerFk
|
LEFT JOIN vn.saleTracking st ON st.saleFk = s.id
|
||||||
AND TIMESTAMPDIFF(HOUR, c.created , util.VN_NOW()) < pc.pendingCollectionsAge
|
AND st.stateFk = ss.id
|
||||||
AND s.quantity != 0
|
WHERE c.workerFk = vWorkerFk
|
||||||
AND s2.order < pc.pendingCollectionsOrder
|
AND TIMESTAMPDIFF(HOUR, c.created , util.VN_NOW()) < pc.pendingCollectionsAge
|
||||||
GROUP BY c.id
|
AND s.quantity
|
||||||
HAVING COUNT(*) > COUNT(DISTINCT st.id);
|
AND s2.order < pc.pendingCollectionsOrder
|
||||||
|
GROUP BY c.id
|
||||||
|
HAVING COUNT(*) > COUNT(DISTINCT st.id);
|
||||||
|
|
||||||
SELECT * FROM tCollection;
|
SELECT * FROM tmp.collection;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -15,6 +15,11 @@ proc: BEGIN
|
||||||
DECLARE vEndingDate DATETIME;
|
DECLARE vEndingDate DATETIME;
|
||||||
DECLARE vIsTodayRelative BOOLEAN;
|
DECLARE vIsTodayRelative BOOLEAN;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY
|
SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY
|
||||||
INTO vEndingDate
|
INTO vEndingDate
|
||||||
FROM productionConfig;
|
FROM productionConfig;
|
||||||
|
@ -31,7 +36,8 @@ proc: BEGIN
|
||||||
CALL prepareClientList();
|
CALL prepareClientList();
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||||
(INDEX (ticketFk)) ENGINE = MEMORY
|
(INDEX (ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped
|
SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped
|
||||||
FROM tmp.productionTicket tt
|
FROM tmp.productionTicket tt
|
||||||
JOIN ticket t ON t.id = tt.ticketFk;
|
JOIN ticket t ON t.id = tt.ticketFk;
|
||||||
|
|
|
@ -9,6 +9,11 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
DECLARE vStateFk INT;
|
DECLARE vStateFk INT;
|
||||||
|
|
||||||
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
|
BEGIN
|
||||||
|
RESIGNAL;
|
||||||
|
END;
|
||||||
|
|
||||||
INSERT INTO ticket (
|
INSERT INTO ticket (
|
||||||
clientFk,
|
clientFk,
|
||||||
shipped,
|
shipped,
|
||||||
|
|
Loading…
Reference in New Issue