fix: refs #7213 change rounding problems #2943
|
@ -51,7 +51,6 @@ BEGIN
|
|||
hasTicketRequest,
|
||||
isTaxDataChecked,
|
||||
hasComponentLack,
|
||||
hasRounding,
|
||||
isTooLittle)
|
||||
SELECT sgp.ticketFk,
|
||||
s.id,
|
||||
|
@ -62,10 +61,6 @@ BEGIN
|
|||
IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest,
|
||||
IF(FIND_IN_SET('isTaxDataChecked', t.problem), FALSE, TRUE) isTaxDataChecked,
|
||||
IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack,
|
||||
IF(FIND_IN_SET('hasRounding', s.problem),
|
||||
LEFT(GROUP_CONCAT('RE: ', i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250),
|
||||
NULL
|
||||
) hasRounding,
|
||||
IF(FIND_IN_SET('isTooLittle', t.problem)
|
||||
AND util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE,
|
||||
TRUE, FALSE) isTooLittle
|
||||
|
@ -208,6 +203,25 @@ BEGIN
|
|||
GROUP BY sgp.ticketFk
|
||||
) sub
|
||||
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
||||
|
||||
CALL buyUltimate(vWarehouseFk, vDate);
|
||||
guillermo marked this conversation as resolved
Outdated
|
||||
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
||||
SELECT ticketFk, problem ,saleFk
|
||||
guillermo marked this conversation as resolved
guillermo
commented
SELECT ticketFk, problem, 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;
|
||||
CLOSE vCursor;
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRounding`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the rounding problem for a sales line
|
||||
* @param vSelf Id sale
|
||||
*/
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vQuantity INT;
|
||||
DECLARE vIsProblemCalcNeeded BOOL;
|
||||
|
||||
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id)
|
||||
INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
WHERE s.id = vSelf;
|
||||
|
||||
CALL buy_getUltimate(vItemFk, vWarehouseFk, vShipped);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
SELECT vSelf saleFk,
|
||||
MOD(vQuantity, b.`grouping`) hasProblem,
|
||||
vIsProblemCalcNeeded isProblemCalcNeeded
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE bu.itemFk = vItemFk;
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,75 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRoundingByBuy`(
|
||||
vBuyFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update rounding problem for all sales related to a buy.
|
||||
*
|
||||
* @param vBuyFk Buy id
|
||||
*/
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vMaxDated DATE;
|
||||
DECLARE vMinDated DATE;
|
||||
DECLARE vLanding DATE;
|
||||
DECLARE vLastBuy INT;
|
||||
DECLARE vCurrentBuy INT;
|
||||
DECLARE vGrouping INT;
|
||||
|
||||
SELECT b.itemFk, t.warehouseInFk
|
||||
INTO vItemFk, vWarehouseFk
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE b.id = vBuyFk;
|
||||
|
||||
IF vItemFk AND vWarehouseFk THEN
|
||||
SELECT DATE(MAX(t.shipped)) + INTERVAL 1 DAY, DATE(MIN(t.shipped))
|
||||
INTO vMaxDated, vMinDated
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
WHERE t.shipped >= util.VN_CURDATE()
|
||||
AND s.itemFk = vItemFk
|
||||
AND s.quantity > 0;
|
||||
|
||||
CALL buy_getUltimate(vItemFk, vWarehouseFk, vMinDated);
|
||||
|
||||
SELECT bu.buyFk, b.grouping INTO vLastBuy, vGrouping
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN buy b ON b.id = bu.buyFk;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
|
||||
SET vLanding = vMaxDated;
|
||||
|
||||
WHILE vCurrentBuy <> vLastBuy OR vLanding > vMinDated DO
|
||||
SET vMaxDated = vLanding - INTERVAL 1 DAY;
|
||||
|
||||
CALL buy_getUltimate(vItemFk, vWarehouseFk, vMaxDated);
|
||||
|
||||
SELECT buyFk, landing
|
||||
INTO vCurrentBuy, vLanding
|
||||
FROM tmp.buyUltimate;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END WHILE;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(INDEX(saleFk, isProblemCalcNeeded))
|
||||
ENGINE = MEMORY
|
||||
SELECT s.id saleFk,
|
||||
MOD(s.quantity, vGrouping) hasProblem,
|
||||
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
WHERE s.itemFk = vItemFk
|
||||
AND s.quantity > 0
|
||||
AND t.shipped BETWEEN vMinDated AND util.dayEnd(vMaxDated);
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,37 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRounding`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the rounding problem for the sales lines of a ticket
|
||||
*
|
||||
* @param vSelf Id de ticket
|
||||
*/
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vDated DATE;
|
||||
|
||||
SELECT warehouseFk, shipped
|
||||
INTO vWarehouseFk, vDated
|
||||
FROM ticket
|
||||
WHERE id = vSelf;
|
||||
|
||||
CALL buy_getUltimate(NULL, vWarehouseFk, vDated);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(INDEX(saleFk, isProblemCalcNeeded))
|
||||
SELECT s.id saleFk ,
|
||||
MOD(s.quantity, b.`grouping`) hasProblem,
|
||||
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE t.id = vSelf;
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue
No falta el drop de la tabla generada?