fix: refs #7213 problem rounding #2903
|
@ -0,0 +1,71 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRoundingByBuy`(
|
||||||
|
vBuyFk INT
|
||||||
|
)
|
||||||
|
/**
|
||||||
|
* Update rounding problem for all sales related to a buy
|
||||||
|
* @param vBuyFk Id buy
|
||||||
carlosap marked this conversation as resolved
Outdated
guillermo
commented
Outdated
Review
```
/**
* 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 vn.buy b
|
||||||
|
JOIN vn.entry e ON e.id = b.entryFk
|
||||||
carlosap marked this conversation as resolved
guillermo
commented
No utilizar No utilizar `vn.`
|
|||||||
|
JOIN vn.travel t ON t.id = e.travelFk
|
||||||
|
WHERE b.id = vBuyFk;
|
||||||
|
|
||||||
|
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 >= CURDATE()
|
||||||
|
AND s.itemFk = vItemFk
|
||||||
carlosap marked this conversation as resolved
guillermo
commented
util.VN_CURDATE() util.VN_CURDATE()
|
|||||||
|
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))
|
||||||
|
SELECT s.id saleFk ,
|
||||||
carlosap marked this conversation as resolved
guillermo
commented
ENGINE = MEMORY ENGINE = MEMORY
|
|||||||
|
MOD(s.quantity, vGrouping) hasProblem,
|
||||||
carlosap marked this conversation as resolved
Outdated
guillermo
commented
espacio entre el alias y la , espacio entre el alias y la ,
|
|||||||
|
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);
|
||||||
carlosap marked this conversation as resolved
guillermo
commented
Per que no fiques aço en una linea? No he vist ningún lloc aon no se fique el BETWEEN seguit Per que no fiques aço en una linea? No he vist ningún lloc aon no se fique el BETWEEN seguit
|
|||||||
|
|
||||||
|
CALL sale_setProblem('hasRounding');
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
Loading…
Reference in New Issue