7120-specialPrice #2213
|
@ -14,7 +14,10 @@ BEGIN
|
||||||
SELECT `value` INTO price
|
SELECT `value` INTO price
|
||||||
FROM vn.specialPrice
|
FROM vn.specialPrice
|
||||||
WHERE itemFk = vItemFk
|
WHERE itemFk = vItemFk
|
||||||
AND clientFk = vClientFk ;
|
AND (clientFk = vClientFk OR clientFk IS NULL)
|
||||||
|
AND started <= util.VN_CURDATE()
|
||||||
jgallego marked this conversation as resolved
|
|||||||
|
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
|
||||||
jgallego marked this conversation as resolved
carlosap
commented
La columna aunque está declarada NOTNULL, la mayoría de los valores es NULL La columna aunque está declarada NOTNULL, la mayoría de los valores es NULL
jgallego
commented
si ho mires en php no eren null eren 0000-00-00 pero dbeaver ho mostra com a null. De totes formes he creat un valor per defecte. si ho mires en php no eren null eren 0000-00-00 pero dbeaver ho mostra com a null. De totes formes he creat un valor per defecte.
|
|||||||
|
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,8 +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
|
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT * FROM (
|
SELECT * FROM (
|
||||||
SELECT pf.itemFk,
|
SELECT pf.itemFk,
|
||||||
|
@ -146,7 +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.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
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;
|
||||||
|
@ -169,7 +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.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
LEFT JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
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))
|
||||||
|
@ -208,7 +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.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
|
JOIN tSpecialPrice sp ON sp.itemFk = tcc.itemFk
|
||||||
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
|
||||||
|
@ -289,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,10 @@
|
||||||
|
ALTER TABLE vn.specialPrice MODIFY COLUMN clientFk int(11) NULL;
|
||||||
|
ALTER TABLE vn.specialPrice ADD started date NOT NULL DEFAULT '2024-01-01';
|
||||||
jgallego marked this conversation as resolved
Outdated
carlosap
commented
Hay que actualizar los valores antes de hacer este cambio para que no falle? Hay que actualizar los valores antes de hacer este cambio para que no falle?
|
|||||||
|
ALTER TABLE vn.specialPrice ADD ended date NULL;
|
||||||
|
ALTER TABLE vn.specialPrice MODIFY COLUMN itemFk int(11) NOT NULL;
|
||||||
|
ALTER TABLE vn.specialPrice MODIFY COLUMN value DECIMAL(10,2) NOT NULL;
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE vn.`specialPrice`
|
||||||
|
ADD CONSTRAINT `check_date_range`
|
||||||
|
CHECK (`ended` IS NULL OR `ended` >= `started`);
|
Loading…
Reference in New Issue
La columna aunque está declarada NOTNULL, la mayoría de los valores es NULL