fix: refs #7844 salesFilter and tmp.ticket_problems.totalProblems
gitea/salix/pipeline/pr-test This commit looks good Details
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2024-09-03 15:03:09 +02:00
parent bd06bed570
commit 3cc19549e4
6 changed files with 52 additions and 47 deletions

View File

@ -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 ;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -69,6 +69,9 @@
},
"cmrFk": {
"type": "number"
},
"problem": {
"type": "string"
}
},
"relations": {

View File

@ -58,7 +58,7 @@
<vn-icon
vn-tooltip="Client has debt"
icon="icon-risk"
ng-if="$ctrl.ticket.client.debt > $ctrl.ticket.client.credit">
ng-if="$ctrl.ticket.problem.includes('hasRisk')">
</vn-icon>
<vn-icon
vn-tooltip="Client not checked"