feat: #7120 con tabla temporal
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
20a338f746
commit
c99de95b33
|
@ -13,9 +13,11 @@ BEGIN
|
||||||
|
|
||||||
SELECT `value` INTO price
|
SELECT `value` INTO price
|
||||||
FROM vn.specialPrice
|
FROM vn.specialPrice
|
||||||
WHERE itemFk = vItemFk
|
WHERE itemFk = vItemFk
|
||||||
AND (clientFk = vClientFk OR clientFk IS NULL)
|
AND (clientFk = vClientFk OR clientFk IS NULL)
|
||||||
AND util.VN_CURDATE() BETWEEN started AND ended;
|
AND started <= util.VN_CURDATE()
|
||||||
|
AND (ended >= util.VN_CURDATE() OR ended IS NULL)
|
||||||
|
ORDER BY id DESC LIMIT 1;
|
||||||
RETURN price;
|
RETURN price;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -25,6 +25,19 @@ BEGIN
|
||||||
FROM address
|
FROM address
|
||||||
WHERE id = vAddressFk;
|
WHERE id = vAddressFk;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice
|
||||||
|
(INDEX (itemFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT *
|
||||||
|
FROM specialPrice
|
||||||
|
WHERE (clientFk = vClientFk OR clientFk IS NULL)
|
||||||
|
AND started <= vShipped
|
||||||
|
AND (ended >= vShipped OR ended IS NULL)
|
||||||
|
ORDER BY (clientFk = vClientFk) DESC, id DESC
|
||||||
|
LIMIT 10000000000000000000) t
|
||||||
|
GROUP BY itemFk;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate
|
||||||
(PRIMARY KEY (itemFk, warehouseFk))
|
(PRIMARY KEY (itemFk, warehouseFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -44,9 +57,7 @@ BEGIN
|
||||||
JOIN item i ON i.id = tl.itemFk
|
JOIN item i ON i.id = tl.itemFk
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||||
LEFT JOIN specialPrice sp ON sp.itemFk = i.id
|
LEFT JOIN tSpecialPrice sp ON sp.itemFk = i.id
|
||||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
|
||||||
AND vShipped BETWEEN sp.started AND sp.ended
|
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT * FROM (
|
SELECT * FROM (
|
||||||
SELECT pf.itemFk,
|
SELECT pf.itemFk,
|
||||||
|
@ -147,9 +158,7 @@ BEGIN
|
||||||
FROM tmp.ticketComponentBase tcb
|
FROM tmp.ticketComponentBase tcb
|
||||||
JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount'
|
JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount'
|
||||||
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
|
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
|
||||||
LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
|
||||||
AND vShipped BETWEEN sp.started AND sp.ended
|
|
||||||
JOIN vn.item i ON i.id = tcb.itemFk
|
JOIN vn.item i ON i.id = tcb.itemFk
|
||||||
WHERE sp.value IS NULL
|
WHERE sp.value IS NULL
|
||||||
AND i.supplyResponseFk IS NULL;
|
AND i.supplyResponseFk IS NULL;
|
||||||
|
@ -172,9 +181,7 @@ BEGIN
|
||||||
FROM tmp.ticketComponentCalculate tcc
|
FROM tmp.ticketComponentCalculate tcc
|
||||||
JOIN vn.component c2 ON c2.code = 'salePerPackage'
|
JOIN vn.component c2 ON c2.code = 'salePerPackage'
|
||||||
JOIN buy b ON b.id = tcc.buyFk
|
JOIN buy b ON b.id = tcc.buyFk
|
||||||
LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
|
||||||
AND vShipped BETWEEN sp.started AND sp.ended
|
|
||||||
WHERE sp.value IS NULL;
|
WHERE sp.value IS NULL;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id))
|
CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id))
|
||||||
|
@ -213,9 +220,7 @@ BEGIN
|
||||||
sp.value - SUM(tcc.cost) sumCost
|
sp.value - SUM(tcc.cost) sumCost
|
||||||
FROM tmp.ticketComponentCopy tcc
|
FROM tmp.ticketComponentCopy tcc
|
||||||
JOIN component c ON c.id = tcc.componentFk
|
JOIN component c ON c.id = tcc.componentFk
|
||||||
JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
|
||||||
AND vShipped BETWEEN sp.started AND sp.ended
|
|
||||||
JOIN vn.component c2 ON c2.code = 'specialPrices'
|
JOIN vn.component c2 ON c2.code = 'specialPrices'
|
||||||
WHERE c.classRate IS NULL
|
WHERE c.classRate IS NULL
|
||||||
AND tcc.warehouseFk = vWarehouseFk
|
AND tcc.warehouseFk = vWarehouseFk
|
||||||
|
@ -296,6 +301,7 @@ BEGIN
|
||||||
tmp.ticketComponentSum,
|
tmp.ticketComponentSum,
|
||||||
tmp.ticketComponentBase,
|
tmp.ticketComponentBase,
|
||||||
tmp.ticketComponentRate,
|
tmp.ticketComponentRate,
|
||||||
tmp.ticketComponentCopy;
|
tmp.ticketComponentCopy,
|
||||||
|
tSpecialPrice;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) DEFAULT 0 NULL;
|
||||||
|
ALTER TABLE vn.specialPrice ADD started date NOT NULL;
|
||||||
|
ALTER TABLE vn.specialPrice ADD ended date NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `specialPrice`
|
||||||
|
ADD CONSTRAINT `check_date_range`
|
||||||
|
CHECK (`ended` IS NULL OR `ended` >= `started`);
|
Loading…
Reference in New Issue