fix: refs #7844 salesFilter and tmp.ticket_problems.totalProblems
This commit is contained in:
parent
bd06bed570
commit
3cc19549e4
|
@ -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 ;
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -69,6 +69,9 @@
|
|||
},
|
||||
"cmrFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"problem": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue