diff --git a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql index a1362c222..b0e286d25 100644 --- a/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql +++ b/db/routines/vn/procedures/sale_setProblemRoundingByBuy.sql @@ -9,7 +9,7 @@ BEGIN * @param vBuyFk Buy id */ DECLARE vItemFk INT; - DECLARE vWareHouseFk INT; + DECLARE vWarehouseFk INT; DECLARE vMaxDated DATE; DECLARE vMinDated DATE; DECLARE vLanding DATE; @@ -18,56 +18,58 @@ BEGIN DECLARE vGrouping INT; SELECT b.itemFk, t.warehouseInFk - INTO vItemFk, vWareHouseFk + 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; - - 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 + 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 s.itemFk = vItemFk - AND s.quantity > 0 - AND t.shipped BETWEEN vMinDated AND util.dayEnd(vMaxDated); + WHERE t.shipped >= util.VN_CURDATE() + AND s.itemFk = vItemFk + AND s.quantity > 0; + + CALL buy_getUltimate(vItemFk, vWarehouseFk, vMinDated); - CALL sale_setProblem('hasRounding'); + 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; - DROP TEMPORARY TABLE tmp.sale; + 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 ; \ No newline at end of file diff --git a/modules/monitor/back/methods/sales-monitor/salesFilter.js b/modules/monitor/back/methods/sales-monitor/salesFilter.js index dbf2ea468..8ef51a0d1 100644 --- a/modules/monitor/back/methods/sales-monitor/salesFilter.js +++ b/modules/monitor/back/methods/sales-monitor/salesFilter.js @@ -264,7 +264,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` UPDATE tmp.ticket_problems - SET risk = IF(hasRisk AND risk > 0, risk, 0) + SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index e29109bde..2209c8df4 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -308,7 +308,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` UPDATE tmp.ticket_problems - SET risk = IF(hasRisk AND risk > 0, risk, 0) + SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); diff --git a/modules/ticket/back/methods/ticket/getTicketsFuture.js b/modules/ticket/back/methods/ticket/getTicketsFuture.js index 24ff37be8..9f455ec03 100644 --- a/modules/ticket/back/methods/ticket/getTicketsFuture.js +++ b/modules/ticket/back/methods/ticket/getTicketsFuture.js @@ -160,7 +160,7 @@ module.exports = Self => { stmt = new ParameterizedSQL(` UPDATE tmp.ticket_problems - SET risk = IF(hasRisk AND risk > 0, risk, 0) + SET risk = IF(hasRisk, risk, 0) `); stmts.push(stmt); diff --git a/modules/ticket/back/models/ticket.json b/modules/ticket/back/models/ticket.json index d8a3206c6..3f073806e 100644 --- a/modules/ticket/back/models/ticket.json +++ b/modules/ticket/back/models/ticket.json @@ -69,6 +69,9 @@ }, "cmrFk": { "type": "number" + }, + "problem": { + "type": "string" } }, "relations": { diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 75bcd2801..32a30833b 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -58,7 +58,7 @@ + ng-if="$ctrl.ticket.problem.includes('hasRisk')">