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
|
@ -15,7 +15,9 @@ BEGIN
|
|||
FROM vn.specialPrice
|
||||
WHERE itemFk = vItemFk
|
||||
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;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -25,6 +25,19 @@ BEGIN
|
|||
FROM address
|
||||
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
|
||||
(PRIMARY KEY (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
|
@ -44,9 +57,7 @@ BEGIN
|
|||
JOIN item i ON i.id = tl.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN specialPrice 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 tSpecialPrice sp ON sp.itemFk = i.id
|
||||
LEFT JOIN (
|
||||
SELECT * FROM (
|
||||
SELECT pf.itemFk,
|
||||
|
@ -147,9 +158,7 @@ BEGIN
|
|||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN vn.component c2 ON c2.code = 'lastUnitsDiscount'
|
||||
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
|
||||
LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
||||
AND vShipped BETWEEN sp.started AND sp.ended
|
||||
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
JOIN vn.item i ON i.id = tcb.itemFk
|
||||
WHERE sp.value IS NULL
|
||||
AND i.supplyResponseFk IS NULL;
|
||||
|
@ -172,9 +181,7 @@ BEGIN
|
|||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN vn.component c2 ON c2.code = 'salePerPackage'
|
||||
JOIN buy b ON b.id = tcc.buyFk
|
||||
LEFT JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
||||
AND vShipped BETWEEN sp.started AND sp.ended
|
||||
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
WHERE sp.value IS NULL;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id))
|
||||
|
@ -213,9 +220,7 @@ BEGIN
|
|||
sp.value - SUM(tcc.cost) sumCost
|
||||
FROM tmp.ticketComponentCopy tcc
|
||||
JOIN component c ON c.id = tcc.componentFk
|
||||
JOIN specialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
AND (sp.clientFk = vClientFk OR sp.clientFk IS NULL)
|
||||
AND vShipped BETWEEN sp.started AND sp.ended
|
||||
JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||
JOIN vn.component c2 ON c2.code = 'specialPrices'
|
||||
WHERE c.classRate IS NULL
|
||||
AND tcc.warehouseFk = vWarehouseFk
|
||||
|
@ -296,6 +301,7 @@ BEGIN
|
|||
tmp.ticketComponentSum,
|
||||
tmp.ticketComponentBase,
|
||||
tmp.ticketComponentRate,
|
||||
tmp.ticketComponentCopy;
|
||||
tmp.ticketComponentCopy,
|
||||
tSpecialPrice;
|
||||
END$$
|
||||
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