feat: Turn issues into calculated columns refs#7213
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
b47637610b
commit
cbd46330b3
|
@ -0,0 +1,27 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
|
RETURNS BOOL
|
||||||
|
DETERMINISTIC
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Check if the ticket requires to update column vn.ticket.problem
|
||||||
|
*
|
||||||
|
* @param vSelf Id ticket
|
||||||
|
* @return BOOL
|
||||||
|
*/
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
|
SELECT COUNT(*) INTO vIsProblemCalcNeeded
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
|
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||||
|
WHERE t.id = vSelf
|
||||||
|
AND dm.code IN ('AGENCY','DELIVERY','PICKUP')
|
||||||
|
AND c.typeFk = 'normal';
|
||||||
|
|
||||||
|
RETURN vIsProblemCalcNeeded;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,5 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vDated DATE
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula las últimas compras realizadas hasta una fecha
|
* Calcula las últimas compras realizadas hasta una fecha
|
||||||
|
@ -19,21 +22,22 @@ BEGIN
|
||||||
FROM cache.last_buy
|
FROM cache.last_buy
|
||||||
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
||||||
|
|
||||||
CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated);
|
IF vDated >= util.VN_CURDATE() THEN
|
||||||
|
CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated);
|
||||||
|
|
||||||
REPLACE INTO tmp.buyUltimate
|
REPLACE INTO tmp.buyUltimate
|
||||||
SELECT itemFk, buyFk, warehouseFk, landed landing
|
SELECT itemFk, buyFk, warehouseFk, landed landing
|
||||||
FROM tmp.buyUltimateFromInterval
|
FROM tmp.buyUltimateFromInterval
|
||||||
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
AND landed <= vDated
|
AND landed <= vDated
|
||||||
AND NOT isIgnored;
|
AND NOT isIgnored;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimate
|
|
||||||
SELECT itemFk, buyFk, warehouseFk, landed landing
|
|
||||||
FROM tmp.buyUltimateFromInterval
|
|
||||||
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
|
||||||
AND landed > vDated
|
|
||||||
ORDER BY isIgnored = FALSE DESC;
|
|
||||||
|
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimate
|
||||||
|
SELECT itemFk, buyFk, warehouseFk, landed landing
|
||||||
|
FROM tmp.buyUltimateFromInterval
|
||||||
|
WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL)
|
||||||
|
AND landed > vDated
|
||||||
|
ORDER BY isIgnored = FALSE DESC;
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(
|
||||||
|
vWarehouseFk SMALLINT,
|
||||||
|
vStarted DATE,
|
||||||
|
vEnded DATE
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula las últimas compras realizadas
|
* Calcula las últimas compras realizadas
|
||||||
|
@ -21,12 +25,13 @@ BEGIN
|
||||||
-- Item
|
-- Item
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
||||||
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
||||||
(PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
(PRIMARY KEY (itemFk, warehouseFk),
|
||||||
|
INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT itemFk,
|
SELECT itemFk,
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
buyFk,
|
buyFk,
|
||||||
MAX(landed) landed,
|
landed,
|
||||||
isIgnored
|
isIgnored
|
||||||
FROM (SELECT b.itemFk,
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
|
@ -45,93 +50,117 @@ BEGIN
|
||||||
|
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
t.warehouseInFk warehouseFk,
|
buyFk,
|
||||||
b.id buyFk,
|
landed,
|
||||||
t.landed,
|
isIgnored
|
||||||
b.isIgnored
|
FROM (SELECT b.itemFk,
|
||||||
FROM buy b
|
t.warehouseInFk warehouseFk,
|
||||||
JOIN entry e ON e.id = b.entryFk
|
b.id buyFk,
|
||||||
JOIN travel t ON t.id = e.travelFk
|
t.landed,
|
||||||
WHERE t.landed > vEnded
|
b.isIgnored
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
FROM buy b
|
||||||
AND b.price2 > 0
|
JOIN entry e ON e.id = b.entryFk
|
||||||
AND NOT b.isIgnored
|
JOIN travel t ON t.id = e.travelFk
|
||||||
GROUP BY itemFk, warehouseInFk;
|
WHERE t.landed > vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND b.price2 > 0
|
||||||
|
AND NOT b.isIgnored
|
||||||
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
t.warehouseInFk warehouseFk,
|
buyFk,
|
||||||
b.id buyFk,
|
landed,
|
||||||
t.landed,
|
isIgnored
|
||||||
b.isIgnored
|
FROM (SELECT b.itemFk,
|
||||||
FROM buy b
|
t.warehouseInFk warehouseFk,
|
||||||
JOIN entry e ON e.id = b.entryFk
|
b.id buyFk,
|
||||||
JOIN travel t ON t.id = e.travelFk
|
t.landed,
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
b.isIgnored
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
FROM buy b
|
||||||
AND b.quantity = 0
|
JOIN entry e ON e.id = b.entryFk
|
||||||
GROUP BY itemFk, warehouseInFk;
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND b.quantity = 0
|
||||||
|
ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
-- ItemOriginal
|
-- ItemOriginal
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT itemFk,
|
SELECT itemFk,
|
||||||
warehouseFk,
|
warehouseFk,
|
||||||
buyFk,
|
buyFk,
|
||||||
MAX(landed) landed,
|
landed,
|
||||||
isIgnored
|
isIgnored
|
||||||
FROM (SELECT b.itemFk,
|
FROM (SELECT b.itemFk,
|
||||||
t.warehouseInFk warehouseFk,
|
t.warehouseInFk warehouseFk,
|
||||||
b.id buyFk,
|
b.id buyFk,
|
||||||
t.landed,
|
t.landed,
|
||||||
itemOriginalFk,
|
itemOriginalFk,
|
||||||
b.isIgnored
|
b.isIgnored
|
||||||
FROM buy b
|
FROM buy b
|
||||||
JOIN entry e ON e.id = b.entryFk
|
JOIN entry e ON e.id = b.entryFk
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
AND b.price2 > 0
|
AND b.price2 > 0
|
||||||
AND NOT b.isIgnored
|
AND NOT b.isIgnored
|
||||||
AND b.quantity > 0
|
AND b.quantity > 0
|
||||||
AND itemOriginalFk
|
AND itemOriginalFk
|
||||||
ORDER BY t.landed DESC, b.id DESC
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
LIMIT 10000000000000000000) sub
|
LIMIT 10000000000000000000) sub
|
||||||
GROUP BY itemOriginalFk, warehouseFk;
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
|
SELECT itemFk,
|
||||||
|
warehouseFk,
|
||||||
|
buyFk,
|
||||||
|
landed,
|
||||||
|
isIgnored
|
||||||
|
FROM (SELECT b.itemFk,
|
||||||
|
t.warehouseInFk warehouseFk,
|
||||||
|
b.id buyFk,
|
||||||
|
t.landed,
|
||||||
|
b.isIgnored
|
||||||
|
FROM buy b
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
WHERE t.landed > vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
|
AND b.price2 > 0
|
||||||
|
AND NOT b.isIgnored
|
||||||
|
AND itemOriginalFk
|
||||||
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
|
LIMIT 10000000000000000000) sub
|
||||||
|
GROUP BY itemFk, warehouseFk;
|
||||||
|
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
||||||
SELECT
|
SELECT itemFk,
|
||||||
b.itemFk,
|
warehouseFk,
|
||||||
t.warehouseInFk warehouseFk,
|
buyFk,
|
||||||
b.id buyFk,
|
landed,
|
||||||
t.landed,
|
isIgnored
|
||||||
b.isIgnored
|
FROM
|
||||||
FROM buy b
|
(SELECT b.itemFk,
|
||||||
JOIN entry e ON e.id = b.entryFk
|
t.warehouseInFk warehouseFk,
|
||||||
JOIN travel t ON t.id = e.travelFk
|
b.id buyFk,
|
||||||
WHERE t.landed > vEnded
|
t.landed,
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
b.isIgnored
|
||||||
AND b.price2 > 0
|
FROM buy b
|
||||||
AND NOT b.isIgnored
|
JOIN entry e ON e.id = b.entryFk
|
||||||
AND itemOriginalFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
GROUP BY itemOriginalFk, warehouseInFk;
|
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||||
|
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||||
INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored)
|
AND b.quantity = 0
|
||||||
SELECT
|
AND itemOriginalFk
|
||||||
b.itemFk,
|
ORDER BY t.landed DESC, b.id DESC
|
||||||
t.warehouseInFk warehouseFk,
|
LIMIT 10000000000000000000) sub
|
||||||
b.id buyFk,
|
GROUP BY itemFk, warehouseFk;
|
||||||
t.landed,
|
|
||||||
b.isIgnored
|
|
||||||
FROM buy b
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
|
||||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
|
||||||
AND b.quantity = 0
|
|
||||||
AND itemOriginalFk
|
|
||||||
GROUP BY itemOriginalFk, warehouseInFk;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -6,8 +6,15 @@ BEGIN
|
||||||
/**
|
/**
|
||||||
* Update column sale.problem with a problem code
|
* Update column sale.problem with a problem code
|
||||||
* @param vProblemCode Code to set or unset
|
* @param vProblemCode Code to set or unset
|
||||||
* @table tmp.sale(saleFk, hasProblem)
|
* @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded)
|
||||||
*/
|
*/
|
||||||
|
UPDATE tmp.sale ts
|
||||||
|
JOIN sale s ON s.id = ts.saleFk
|
||||||
|
SET s.problem = NULL
|
||||||
|
WHERE NOT ts.isProblemCalcNeeded;
|
||||||
|
|
||||||
|
DELETE FROM tmp.sale WHERE NOT isProblemCalcNeeded;
|
||||||
|
|
||||||
UPDATE sale s
|
UPDATE sale s
|
||||||
JOIN tmp.sale ts ON ts.saleFk = s.id
|
JOIN tmp.sale ts ON ts.saleFk = s.id
|
||||||
SET s.problem = CONCAT(
|
SET s.problem = CONCAT(
|
||||||
|
|
|
@ -10,9 +10,13 @@ BEGIN
|
||||||
* @param vSelf Id del sale
|
* @param vSelf Id del sale
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(INDEX(saleFk))
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem;
|
SELECT vSelf saleFk,
|
||||||
|
sale_hasComponentLack(vSelf) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
||||||
|
FROM sale
|
||||||
|
WHERE id = vSelf;
|
||||||
|
|
||||||
CALL sale_setProblem('hasComponentLack');
|
CALL sale_setProblem('hasComponentLack');
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ BEGIN
|
||||||
* @param vComponentFk Id component
|
* @param vComponentFk Id component
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
(INDEX(saleFk))
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem
|
SELECT saleFk,
|
||||||
|
sale_hasComponentLack(saleFk) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded
|
||||||
FROM (
|
FROM (
|
||||||
SELECT s.id saleFk
|
SELECT s.id saleFk, s.ticketFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
|
|
|
@ -11,9 +11,10 @@ BEGIN
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vShipped DATE;
|
DECLARE vShipped DATE;
|
||||||
DECLARE vQuantity INT;
|
DECLARE vQuantity INT;
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity
|
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id)
|
||||||
INTO vItemFk, vWarehouseFk, vShipped, vQuantity
|
INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
WHERE s.id = vSelf;
|
WHERE s.id = vSelf;
|
||||||
|
@ -21,7 +22,9 @@ BEGIN
|
||||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
CALL buyUltimate(vWarehouseFk, vShipped);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
SELECT vSelf saleFk, MOD(vQuantity, b.`grouping`) hasProblem
|
SELECT vSelf saleFk,
|
||||||
|
MOD(vQuantity, b.`grouping`) hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded
|
||||||
FROM tmp.buyUltimate bu
|
FROM tmp.buyUltimate bu
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
JOIN buy b ON b.id = bu.buyFk
|
||||||
WHERE bu.itemFk = vItemFk;
|
WHERE bu.itemFk = vItemFk;
|
||||||
|
|
|
@ -4,11 +4,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Update column ticket.problem with a problem code
|
* Update column ticket.problem with a problem code and SET NULL when
|
||||||
|
* the problem is not requiered
|
||||||
*
|
*
|
||||||
* @param vProblemCode Code to set or unset
|
* @param vProblemCode Code to set or unset
|
||||||
* @table tmp.ticket(ticketFk, hasProblem)
|
* @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded)
|
||||||
*/
|
*/
|
||||||
|
UPDATE ticket t
|
||||||
|
JOIN tmp.ticket tt ON tt.ticketFk = t.id
|
||||||
|
SET t.problem = NULL
|
||||||
|
WHERE NOT tt.isProblemCalcNeeded;
|
||||||
|
|
||||||
|
DELETE FROM tmp.ticket WHERE NOT isProblemCalcNeeded;
|
||||||
|
|
||||||
UPDATE ticket t
|
UPDATE ticket t
|
||||||
JOIN tmp.ticket tt ON tt.ticketFk = t.id
|
JOIN tmp.ticket tt ON tt.ticketFk = t.id
|
||||||
SET t.problem = CONCAT(
|
SET t.problem = CONCAT(
|
||||||
|
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vClientFk Id Cliente, if NULL all clients
|
* @param vClientFk Id Cliente, if NULL all clients
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
FALSE hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
||||||
|
@ -21,7 +23,7 @@ BEGIN
|
||||||
JOIN client c ON c.id = ti.clientFk
|
JOIN client c ON c.id = ti.clientFk
|
||||||
SET t.hasProblem = TRUE
|
SET t.hasProblem = TRUE
|
||||||
WHERE c.isFreezed;
|
WHERE c.isFreezed;
|
||||||
|
|
||||||
CALL ticket_setProblem('isFreezed');
|
CALL ticket_setProblem('isFreezed');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vSelf Id ticket, if NULL ALL tickets
|
* @param vSelf Id ticket, if NULL ALL tickets
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
FALSE hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vSelf IS NULL OR t.id = vSelf);
|
AND (vSelf IS NULL OR t.id = vSelf);
|
||||||
|
|
|
@ -10,21 +10,30 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
DECLARE vHasRisk BOOL;
|
DECLARE vHasRisk BOOL;
|
||||||
DECLARE vHasHighRisk BOOL;
|
DECLARE vHasHighRisk BOOL;
|
||||||
|
DECLARE vIsProblemCalcNeeded BOOL;
|
||||||
|
|
||||||
SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10))
|
SELECT t.risk > (c.credit + 10),
|
||||||
INTO vHasRisk, vHasHighRisk
|
(t.risk - cc.riskTolerance) > (c.credit + 10),
|
||||||
|
ticket_isProblemCalcNeeded(t.id)
|
||||||
|
INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded
|
||||||
FROM client c
|
FROM client c
|
||||||
JOIN ticket t ON t.clientFk = c.id
|
JOIN ticket t ON t.clientFk = c.id
|
||||||
JOIN clientConfig cc
|
JOIN clientConfig cc
|
||||||
WHERE t.id = vSelf;
|
WHERE t.id = vSelf;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
SELECT vSelf ticketFk, vHasRisk hasProblem;
|
ENGINE = MEMORY
|
||||||
|
SELECT vSelf ticketFk,
|
||||||
|
vHasRisk hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('hasRisk');
|
CALL ticket_setProblem('hasRisk');
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
SELECT vSelf ticketFk, vHasHighRisk hasProblem;
|
ENGINE = MEMORY
|
||||||
|
SELECT vSelf ticketFk,
|
||||||
|
vHasHighRisk hasProblem,
|
||||||
|
vIsProblemCalcNeeded isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('hasHighRisk');
|
CALL ticket_setProblem('hasHighRisk');
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,11 @@ BEGIN
|
||||||
|
|
||||||
CALL buyUltimate(vWarehouseFk, vDated);
|
CALL buyUltimate(vWarehouseFk, vDated);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem
|
(INDEX(saleFk, isProblemCalcNeeded))
|
||||||
|
SELECT s.id saleFk ,
|
||||||
|
MOD(s.quantity, b.`grouping`) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||||
|
|
|
@ -9,9 +9,11 @@ BEGIN
|
||||||
* @param vClientFk Id cliente, if NULL all clients
|
* @param vClientFk Id cliente, if NULL all clients
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
|
SELECT t.id ticketFk,
|
||||||
|
IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
|
|
|
@ -8,13 +8,17 @@ BEGIN
|
||||||
*
|
*
|
||||||
* @param vSelf Id del ticket
|
* @param vSelf Id del ticket
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
|
SELECT vSelf ticketFk,
|
||||||
|
ticket_isTooLittle(vSelf) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -10,7 +10,7 @@ BEGIN
|
||||||
* @param vItemFk Id del item, NULL ALL items
|
* @param vItemFk Id del item, NULL ALL items
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk, isProblemCalcNeeded))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH tickets AS(
|
WITH tickets AS(
|
||||||
SELECT t.id ticketFk
|
SELECT t.id ticketFk
|
||||||
|
@ -19,7 +19,9 @@ BEGIN
|
||||||
WHERE t.shipped >= util.VN_CURDATE()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
)SELECT ticketFk,
|
||||||
|
ticket_isTooLittle(ticketFk) hasProblem,
|
||||||
|
ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded
|
||||||
FROM tickets;
|
FROM tickets;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
Loading…
Reference in New Issue