feat: #7120 specialPrice with new fiels
This commit is contained in:
parent
2f87ba03b2
commit
20a338f746
|
@ -8,13 +8,14 @@ BEGIN
|
|||
|
||||
SELECT rate3 INTO price
|
||||
FROM vn.priceFixed
|
||||
WHERE itemFk = vItemFk
|
||||
WHERE itemFk = vItemFk
|
||||
AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1;
|
||||
|
||||
SELECT `value` INTO price
|
||||
SELECT `value` INTO price
|
||||
FROM vn.specialPrice
|
||||
WHERE itemFk = vItemFk
|
||||
AND clientFk = vClientFk ;
|
||||
WHERE itemFk = vItemFk
|
||||
AND (clientFk = vClientFk OR clientFk IS NULL)
|
||||
AND util.VN_CURDATE() BETWEEN started AND ended;
|
||||
RETURN price;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -10,7 +10,7 @@ BEGIN
|
|||
* Calcula los componentes de los articulos de tmp.ticketLot
|
||||
*
|
||||
* @param vZoneFk para calcular el transporte
|
||||
* @param vAddressFk Consignatario
|
||||
* @param vAddressFk Consignatario
|
||||
* @param vShipped dia de salida del pedido
|
||||
* @param vWarehouseFk warehouse de salida del pedido
|
||||
* @table tmp.ticketLot (warehouseFk, available, itemFk, buyFk, zoneFk)
|
||||
|
@ -24,7 +24,7 @@ BEGIN
|
|||
SELECT clientFk INTO vClientFK
|
||||
FROM address
|
||||
WHERE id = vAddressFk;
|
||||
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate
|
||||
(PRIMARY KEY (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
|
@ -36,7 +36,7 @@ BEGIN
|
|||
IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing,
|
||||
IFNULL(pf.`grouping`, b.`grouping`) `grouping`,
|
||||
ABS(IFNULL(pf.box, b.groupingMode)) groupingMode,
|
||||
tl.buyFk,
|
||||
tl.buyFk,
|
||||
i.typeFk,
|
||||
IF(i.hasKgPrice, b.weight / b.packing, NULL) weightGrouping
|
||||
FROM tmp.ticketLot tl
|
||||
|
@ -44,8 +44,9 @@ 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
|
||||
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 (
|
||||
SELECT * FROM (
|
||||
SELECT pf.itemFk,
|
||||
|
@ -63,7 +64,7 @@ BEGIN
|
|||
LIMIT 10000000000000000000
|
||||
) tpf
|
||||
GROUP BY tpf.itemFk, tpf.warehouseFk
|
||||
) pf ON pf.itemFk = tl.itemFk
|
||||
) pf ON pf.itemFk = tl.itemFk
|
||||
AND pf.warehouseFk = tl.warehouseFk
|
||||
WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01
|
||||
AND ic.merchandise
|
||||
|
@ -95,10 +96,10 @@ BEGIN
|
|||
FROM tmp.ticketComponent tc
|
||||
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk
|
||||
GROUP BY tc.itemFk, warehouseFk;
|
||||
|
||||
|
||||
-- RECOBRO
|
||||
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, c2.id,
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, c2.id,
|
||||
ROUND(tcb.base *
|
||||
LEAST(
|
||||
MAX(GREATEST(IFNULL(cr.priceIncreasing,0),
|
||||
|
@ -129,29 +130,31 @@ BEGIN
|
|||
ROUND(base * wm.pricesModifierRate, 3) manaAuto
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN `client` c on c.id = vClientFk
|
||||
JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
|
||||
JOIN workerMana wm ON c.salesPersonFk = wm.workerFk
|
||||
JOIN vn.component c2 ON c2.code = 'autoMana'
|
||||
WHERE wm.isPricesModifierActivated
|
||||
HAVING manaAuto <> 0;
|
||||
|
||||
|
||||
-- Precios especiales
|
||||
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT tcb.warehouseFk,
|
||||
tcb.itemFk,
|
||||
c2.id,
|
||||
GREATEST(
|
||||
IFNULL(ROUND(tcb.base * c2.tax, 4), 0),
|
||||
IFNULL(ROUND(tcb.base * c2.tax, 4), 0),
|
||||
IF(i.hasMinPrice, i.minPrice,0) - tcc.rate3
|
||||
) cost
|
||||
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.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
||||
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
|
||||
JOIN vn.item i ON i.id = tcb.itemFk
|
||||
WHERE sp.value IS NULL
|
||||
AND i.supplyResponseFk IS NULL;
|
||||
|
||||
-- Individual
|
||||
-- Individual
|
||||
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT tcb.warehouseFk,
|
||||
tcb.itemFk,
|
||||
|
@ -162,14 +165,16 @@ BEGIN
|
|||
JOIN vn.client c ON c.id = vClientFk
|
||||
JOIN vn.businessType bt ON bt.code = c.businessTypeFk
|
||||
WHERE bt.code = 'individual';
|
||||
|
||||
|
||||
-- Venta por paquetes
|
||||
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3
|
||||
SELECT tcc.warehouseFk, tcc.itemFk, c2.id, tcc.rate2 - tcc.rate3
|
||||
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.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
||||
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
|
||||
WHERE sp.value IS NULL;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.`zone` (INDEX (id))
|
||||
|
@ -177,7 +182,7 @@ BEGIN
|
|||
SELECT vZoneFk id;
|
||||
|
||||
CALL zone_getOptionsForShipment(vShipped, TRUE);
|
||||
|
||||
|
||||
-- Reparto
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcc.warehouseFK,
|
||||
|
@ -191,7 +196,7 @@ BEGIN
|
|||
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||
JOIN vn.volumeConfig vc
|
||||
JOIN vn.component c2 ON c2.code = 'delivery'
|
||||
LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
|
||||
LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
|
||||
AND ic.itemFk = tcc.itemFk
|
||||
HAVING cost <> 0;
|
||||
|
||||
|
@ -208,7 +213,9 @@ BEGIN
|
|||
sp.value - SUM(tcc.cost) sumCost
|
||||
FROM tmp.ticketComponentCopy tcc
|
||||
JOIN component c ON c.id = tcc.componentFk
|
||||
JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
|
||||
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 vn.component c2 ON c2.code = 'specialPrices'
|
||||
WHERE c.classRate IS NULL
|
||||
AND tcc.warehouseFk = vWarehouseFk
|
||||
|
@ -244,9 +251,9 @@ BEGIN
|
|||
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) price,
|
||||
CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) / weightGrouping priceKg
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
|
||||
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
|
||||
AND tcs.warehouseFk = tcc.warehouseFk
|
||||
WHERE IFNULL(tcs.classRate, 1) = 1
|
||||
WHERE IFNULL(tcs.classRate, 1) = 1
|
||||
AND tcc.groupingMode < 2 AND (tcc.packing > tcc.`grouping` or tcc.groupingMode = 0)
|
||||
GROUP BY tcs.warehouseFk, tcs.itemFk;
|
||||
|
||||
|
@ -283,7 +290,7 @@ BEGIN
|
|||
SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000
|
||||
) t
|
||||
GROUP BY itemFk, warehouseFk, `grouping`;
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketComponentCalculate,
|
||||
tmp.ticketComponentSum,
|
||||
|
|
Loading…
Reference in New Issue