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