refs #7844 Change in problems calc
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
fc102eff7b
commit
ea75446982
|
@ -15,11 +15,6 @@ 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;
|
||||||
|
@ -273,7 +268,6 @@ proc: BEGIN
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tmp.productionTicket,
|
tmp.productionTicket,
|
||||||
tmp.ticket,
|
tmp.ticket,
|
||||||
tmp.risk,
|
|
||||||
tmp.ticket_problems,
|
tmp.ticket_problems,
|
||||||
tmp.ticketWithPrevia,
|
tmp.ticketWithPrevia,
|
||||||
tItemShelvingStock,
|
tItemShelvingStock,
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getProblems`(IN vIsTodayRelative tinyint(1))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getProblems`(
|
||||||
|
vIsTodayRelative tinyint(1)
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula los problemas de cada venta para un conjunto de tickets.
|
* Calcula los problemas de cada venta para un conjunto de tickets.
|
||||||
*
|
*
|
||||||
* @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
|
* @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
|
||||||
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
|
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Tickets a calcular
|
||||||
* @return tmp.sale_problems
|
* @return tmp.sale_problems
|
||||||
*/
|
*/
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
|
@ -13,13 +15,11 @@ BEGIN
|
||||||
DECLARE vAvailableCache INT;
|
DECLARE vAvailableCache INT;
|
||||||
DECLARE vVisibleCache INT;
|
DECLARE vVisibleCache INT;
|
||||||
DECLARE vDone BOOL;
|
DECLARE vDone BOOL;
|
||||||
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 warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(shipped))
|
||||||
FROM tmp.sale_getProblems tt
|
FROM tmp.sale_getProblems
|
||||||
WHERE DATE(tt.shipped) BETWEEN util.VN_CURDATE()
|
WHERE shipped BETWEEN util.VN_CURDATE()
|
||||||
AND util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY;
|
AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY);
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
@ -48,105 +48,40 @@ BEGIN
|
||||||
PRIMARY KEY (ticketFk, saleFk)
|
PRIMARY KEY (ticketFk, saleFk)
|
||||||
) ENGINE = MEMORY;
|
) ENGINE = MEMORY;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_list
|
INSERT INTO tmp.sale_problems (ticketFk,
|
||||||
(PRIMARY KEY (ticketFk))
|
saleFk,
|
||||||
ENGINE = MEMORY
|
isFreezed,
|
||||||
SELECT ticketFk, clientFk
|
hasHighRisk,
|
||||||
FROM tmp.sale_getProblems;
|
hasTicketRequest,
|
||||||
|
isTaxDataChecked,
|
||||||
SELECT COUNT(*) INTO vRequiredComponent
|
hasComponentLack,
|
||||||
FROM component
|
hasRounding,
|
||||||
WHERE isRequired;
|
isTooLittle,
|
||||||
|
isVip)
|
||||||
-- Too Little
|
SELECT sgp.ticketFk,
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, isTooLittle)
|
s.id,
|
||||||
SELECT tp.ticketFk, TRUE
|
IF(FIND_IN_SET('isFreezed', s.problem), TRUE, FALSE) isFreezed,
|
||||||
FROM tmp.sale_getProblems tp
|
IF(FIND_IN_SET('hasHighRisk', s.problem), TRUE, FALSE) hasHighRisk,
|
||||||
JOIN ticket t ON t.id = tp.ticketFk
|
IF(FIND_IN_SET('hasTicketRequest', s.problem), TRUE, FALSE) hasTicketRequest,
|
||||||
JOIN (
|
IF(FIND_IN_SET('isTaxDataChecked', s.problem), FALSE, TRUE) isTaxDataChecked,
|
||||||
SELECT t.addressFk,
|
IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack,
|
||||||
SUM(ROUND(`ic`.`cm3delivery` * `s`.`quantity` / 1000, 0)) litros,
|
IF(FIND_IN_SET('hasRounding', s.problem),
|
||||||
t.totalWithoutVat
|
LEFT(GROUP_CONCAT('RE: ', i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250),
|
||||||
FROM tmp.ticket_list tl
|
NULL
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
) hasRounding,
|
||||||
|
IF(FIND_IN_SET('isTooLittle', s.problem), TRUE, FALSE) isTooLittle,
|
||||||
|
IF(FIND_IN_SET('isVip', s.problem), TRUE, FALSE) isVip
|
||||||
|
FROM tmp.sale_getProblems sgp
|
||||||
|
JOIN ticket t ON t.id = sgp.ticketFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
AND s.quantity > 0
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN itemCost ic ON ic.itemFk = s.itemFk
|
WHERE s.problem <> ''
|
||||||
AND ic.warehouseFk = t.warehouseFk
|
GROUP BY s.id;
|
||||||
JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
|
||||||
AND zc.dated = util.VN_CURDATE()
|
|
||||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
|
||||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
|
||||||
WHERE util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE
|
|
||||||
AND dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
|
||||||
AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight()
|
|
||||||
GROUP BY t.addressFk
|
|
||||||
) sub ON sub.addressFk = t.addressFk
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
WHERE sub.litros < vc.minTicketVolume
|
|
||||||
AND sub.totalWithoutVat < vc.minTicketValue;
|
|
||||||
|
|
||||||
-- VIP
|
INSERT INTO tmp.sale_problems (ticketFk, risk)
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, isVip)
|
SELECT t.id, t.risk
|
||||||
SELECT DISTINCT tl.ticketFk, TRUE
|
FROM tmp.sale_getProblems sgp
|
||||||
FROM tmp.ticket_list tl
|
JOIN ticket t ON t.id = sgp.ticketFk;
|
||||||
JOIN client c ON c.id = tl.clientFk
|
|
||||||
WHERE c.businessTypeFk = 'VIP'
|
|
||||||
ON DUPLICATE KEY UPDATE isVip = TRUE;
|
|
||||||
|
|
||||||
-- Faltan componentes
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk)
|
|
||||||
SELECT t.id, COUNT(c.id) < vRequiredComponent hasComponentLack, s.id
|
|
||||||
FROM tmp.ticket_list tl
|
|
||||||
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 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')
|
|
||||||
AND s.quantity > 0
|
|
||||||
GROUP BY s.id
|
|
||||||
HAVING hasComponentLack;
|
|
||||||
|
|
||||||
-- Cliente congelado
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, isFreezed)
|
|
||||||
SELECT DISTINCT tl.ticketFk, TRUE
|
|
||||||
FROM tmp.ticket_list tl
|
|
||||||
JOIN client c ON c.id = tl.clientFk
|
|
||||||
WHERE c.isFreezed
|
|
||||||
ON DUPLICATE KEY UPDATE isFreezed = c.isFreezed;
|
|
||||||
|
|
||||||
-- Credit exceeded
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.clientGetDebt
|
|
||||||
(PRIMARY KEY (clientFk))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT DISTINCT clientFk
|
|
||||||
FROM tmp.ticket_list;
|
|
||||||
|
|
||||||
CALL client_getDebt(util.VN_CURDATE());
|
|
||||||
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, risk, hasHighRisk)
|
|
||||||
SELECT DISTINCT tl.ticketFk, r.risk, ((r.risk - cc.riskTolerance) > c.credit + 10)
|
|
||||||
FROM tmp.ticket_list tl
|
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
|
||||||
JOIN agencyMode a ON t.agencyModeFk = a.id
|
|
||||||
JOIN tmp.risk r ON r.clientFk = t.clientFk
|
|
||||||
JOIN client c ON c.id = t.clientFk
|
|
||||||
JOIN clientConfig cc
|
|
||||||
WHERE r.risk > c.credit + 10
|
|
||||||
AND NOT a.isRiskFree
|
|
||||||
ON DUPLICATE KEY UPDATE
|
|
||||||
risk = r.risk, hasHighRisk = ((r.risk - cc.riskTolerance) > c.credit + 10);
|
|
||||||
|
|
||||||
-- Antiguo COD 100, son peticiones de compra sin terminar
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, hasTicketRequest)
|
|
||||||
SELECT DISTINCT tl.ticketFk, TRUE
|
|
||||||
FROM tmp.ticket_list tl
|
|
||||||
JOIN ticketRequest tr ON tr.ticketFk = tl.ticketFk
|
|
||||||
WHERE tr.isOK IS NULL
|
|
||||||
ON DUPLICATE KEY UPDATE hasTicketRequest = TRUE;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse
|
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse
|
||||||
(INDEX (itemFk, warehouseFk))
|
(INDEX (itemFk, warehouseFk))
|
||||||
|
@ -158,10 +93,9 @@ BEGIN
|
||||||
JOIN shelving sh ON sh.code = ish.shelvingFk
|
JOIN shelving sh ON sh.code = ish.shelvingFk
|
||||||
JOIN parking p ON p.id = sh.parkingFk
|
JOIN parking p ON p.id = sh.parkingFk
|
||||||
JOIN sector s ON s.id = p.sectorFk
|
JOIN sector s ON s.id = p.sectorFk
|
||||||
GROUP BY ish.itemFk,
|
GROUP BY ish.itemFk, s.warehouseFk;
|
||||||
s.warehouseFk;
|
|
||||||
|
|
||||||
-- Disponible, Faltas, Inventario y Retrasos
|
-- Disponible, faltas, inventario y retrasos
|
||||||
OPEN vCursor;
|
OPEN vCursor;
|
||||||
l: LOOP
|
l: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
|
@ -180,14 +114,14 @@ BEGIN
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk)
|
INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk)
|
||||||
SELECT ticketFk, problem, saleFk
|
SELECT ticketFk, problem, saleFk
|
||||||
FROM (
|
FROM (
|
||||||
SELECT tl.ticketFk,
|
SELECT sgp.ticketFk,
|
||||||
LEFT(CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')),250) problem,
|
LEFT(CONCAT('F: ', GROUP_CONCAT(i.id, ' ', i.longName, ' ')), 250) problem,
|
||||||
s.id AS saleFk
|
s.id saleFk
|
||||||
FROM tmp.ticket_list tl
|
FROM tmp.sale_getProblems sgp
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
JOIN ticket t ON t.id = sgp.ticketFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN itemType it on it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||||
LEFT JOIN cache.visible v ON v.item_id = i.id
|
LEFT JOIN cache.visible v ON v.item_id = i.id
|
||||||
AND v.calc_id = vVisibleCache
|
AND v.calc_id = vVisibleCache
|
||||||
|
@ -195,8 +129,8 @@ BEGIN
|
||||||
AND av.calc_id = vAvailableCache
|
AND av.calc_id = vAvailableCache
|
||||||
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
||||||
AND issw.warehouseFk = t.warehouseFk
|
AND issw.warehouseFk = t.warehouseFk
|
||||||
WHERE IFNULL(v.visible,0) < s.quantity
|
WHERE IFNULL(v.visible, 0) < s.quantity
|
||||||
AND IFNULL(av.available ,0) < s.quantity
|
AND IFNULL(av.available, 0) < s.quantity
|
||||||
AND IFNULL(issw.visible, 0) < s.quantity
|
AND IFNULL(issw.visible, 0) < s.quantity
|
||||||
AND NOT s.isPicked
|
AND NOT s.isPicked
|
||||||
AND NOT s.reserved
|
AND NOT s.reserved
|
||||||
|
@ -205,27 +139,27 @@ BEGIN
|
||||||
AND NOT i.generic
|
AND NOT i.generic
|
||||||
AND util.VN_CURDATE() = vDate
|
AND util.VN_CURDATE() = vDate
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
GROUP BY tl.ticketFk) sub
|
GROUP BY sgp.ticketFk) sub
|
||||||
ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk;
|
ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk;
|
||||||
|
|
||||||
-- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida
|
-- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk)
|
INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk)
|
||||||
SELECT ticketFk, problem, saleFk
|
SELECT ticketFk, problem, saleFk
|
||||||
FROM (
|
FROM (
|
||||||
SELECT tl.ticketFk,
|
SELECT sgp.ticketFk,
|
||||||
LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem,
|
LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem,
|
||||||
s.id saleFk
|
s.id saleFk
|
||||||
FROM tmp.ticket_list tl
|
FROM tmp.sale_getProblems sgp
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
JOIN ticket t ON t.id = sgp.ticketFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN itemType it on it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||||
AND v.calc_id = vVisibleCache
|
AND v.calc_id = vVisibleCache
|
||||||
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
||||||
AND issw.warehouseFk = t.warehouseFk
|
AND issw.warehouseFk = t.warehouseFk
|
||||||
WHERE IFNULL(v.visible,0) >= s.quantity
|
WHERE IFNULL(v.visible, 0) >= s.quantity
|
||||||
AND IFNULL(issw.visible, 0) < s.quantity
|
AND IFNULL(issw.visible, 0) < s.quantity
|
||||||
AND s.quantity > 0
|
AND s.quantity > 0
|
||||||
AND NOT s.isPicked
|
AND NOT s.isPicked
|
||||||
|
@ -235,22 +169,22 @@ BEGIN
|
||||||
AND NOT i.generic
|
AND NOT i.generic
|
||||||
AND util.VN_CURDATE() = vDate
|
AND util.VN_CURDATE() = vDate
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
GROUP BY tl.ticketFk
|
GROUP BY sgp.ticketFk
|
||||||
) sub
|
) sub
|
||||||
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
ON DUPLICATE KEY UPDATE itemLost = sub.problem, saleFk = sub.saleFk;
|
||||||
|
|
||||||
-- Retraso: Disponible suficiente, pero no visible ni ubicado
|
-- Retraso: Disponible suficiente, pero no visible ni ubicado
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk)
|
INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk)
|
||||||
SELECT ticketFk, problem, saleFk
|
SELECT ticketFk, problem, saleFk
|
||||||
FROM (
|
FROM (
|
||||||
SELECT tl.ticketFk,
|
SELECT sgp.ticketFk,
|
||||||
LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem,
|
LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem,
|
||||||
s.id saleFk
|
s.id saleFk
|
||||||
FROM tmp.ticket_list tl
|
FROM tmp.sale_getProblems sgp
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
JOIN ticket t ON t.id = sgp.ticketFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN itemType it on it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||||
AND v.calc_id = vVisibleCache
|
AND v.calc_id = vVisibleCache
|
||||||
|
@ -269,42 +203,29 @@ BEGIN
|
||||||
AND NOT i.generic
|
AND NOT i.generic
|
||||||
AND util.VN_CURDATE() = vDate
|
AND util.VN_CURDATE() = vDate
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
GROUP BY tl.ticketFk
|
GROUP BY sgp.ticketFk
|
||||||
) sub
|
) sub
|
||||||
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
||||||
|
|
||||||
-- Redondeo: Cantidad pedida incorrecta en al grouping de la última compra
|
|
||||||
CALL buy_getUltimate(NULL, vWarehouseFk, vDate);
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
|
||||||
SELECT ticketFk, problem ,saleFk
|
|
||||||
FROM (
|
|
||||||
SELECT tl.ticketFk,
|
|
||||||
s.id saleFk,
|
|
||||||
LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250) problem
|
|
||||||
FROM tmp.ticket_list tl
|
|
||||||
JOIN ticket t ON t.id = tl.ticketFk
|
|
||||||
AND t.warehouseFk = vWarehouseFk
|
|
||||||
JOIN sale s ON s.ticketFk = tl.ticketFk
|
|
||||||
JOIN item i ON i.id = s.itemFk
|
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
|
||||||
WHERE MOD(s.quantity, b.`grouping`)
|
|
||||||
GROUP BY tl.ticketFk
|
|
||||||
)sub
|
|
||||||
ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk;
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE vCursor;
|
CLOSE vCursor;
|
||||||
|
|
||||||
INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked)
|
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
||||||
SELECT DISTINCT tl.ticketFk, FALSE
|
SELECT ticketFk, problem, saleFk
|
||||||
FROM tmp.ticket_list tl
|
FROM (
|
||||||
JOIN client c ON c.id = tl.clientFk
|
SELECT sgp.ticketFk,
|
||||||
WHERE NOT c.isTaxDataChecked
|
s.id saleFk,
|
||||||
ON DUPLICATE KEY UPDATE isTaxDataChecked = FALSE;
|
LEFT(GROUP_CONCAT('RE: ', i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250) problem
|
||||||
|
FROM tmp.sale_getProblems sgp
|
||||||
|
JOIN ticket t ON t.id = sgp.ticketFk
|
||||||
|
JOIN sale s ON s.ticketFk = sgp.ticketFk
|
||||||
|
JOIN item i ON i.id = s.itemFk
|
||||||
|
WHERE FIND_IN_SET('hasRounding', s.problem)
|
||||||
|
GROUP BY sgp.ticketFk
|
||||||
|
) sub
|
||||||
|
ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tmp.clientGetDebt,
|
tmp.sale_getProblems,
|
||||||
tmp.ticket_list,
|
|
||||||
tItemShelvingStock_byWarehouse;
|
tItemShelvingStock_byWarehouse;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -7,8 +7,7 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @return Problems result
|
* @return Problems result
|
||||||
*/
|
*/
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems;
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||||
CREATE TEMPORARY TABLE tmp.sale_getProblems
|
|
||||||
(INDEX (ticketFk))
|
(INDEX (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped
|
SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getProblems`(IN vIsTodayRelative tinyint(1))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getProblems`(
|
||||||
|
vIsTodayRelative tinyint(1)
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula los problemas para un conjunto de tickets.
|
* Calcula los problemas para un conjunto de tickets.
|
||||||
|
|
Loading…
Reference in New Issue