Merge pull request 'fix: ticket #216260 buy_recalcPrices' (!2916) from ticket216260-buy_recalcPrices into master
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2916 Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es> Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
commit
44adb9cde0
|
@ -2,51 +2,58 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPrices`()
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_recalcPrices`()
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Recalcula los precios para las compras insertadas en tmp.buyRecalc
|
* Recalcula los precios para las compras insertadas en tmp.buyRecalc.
|
||||||
*
|
*
|
||||||
* @param tmp.buyRecalc (id)
|
* @param tmp.buyRecalc (id)
|
||||||
*/
|
*/
|
||||||
DECLARE vLanded DATE;
|
DECLARE vLanded DATE;
|
||||||
DECLARE vWarehouseFk INT;
|
DECLARE vWarehouseFk INT;
|
||||||
DECLARE vHasNotPrice BOOL;
|
|
||||||
DECLARE vBuyingValue DECIMAL(10,4);
|
|
||||||
DECLARE vPackagingFk VARCHAR(10);
|
|
||||||
DECLARE vIsWarehouseFloramondo BOOL;
|
DECLARE vIsWarehouseFloramondo BOOL;
|
||||||
|
DECLARE vDone BOOL;
|
||||||
|
DECLARE vTravels CURSOR FOR
|
||||||
|
SELECT t.landed, t.warehouseInFk, (w.code = 'flm')
|
||||||
|
FROM tmp.buyRecalc br
|
||||||
|
JOIN buy b ON b.id = br.id
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN travel t ON t.id = e.travelFk
|
||||||
|
JOIN warehouse w ON w.id = t.warehouseInFk
|
||||||
|
GROUP BY t.landed, t.warehouseInFk;
|
||||||
|
|
||||||
SELECT t.landed, t.warehouseInFk, (w.`name` = 'Floramondo')
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo
|
|
||||||
FROM tmp.buyRecalc br
|
|
||||||
JOIN buy b ON b.id = br.id
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN travel t ON t.id = e.travelFk
|
|
||||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
|
||||||
LIMIT 1;
|
|
||||||
|
|
||||||
CALL rate_getPrices(vLanded, vWarehouseFk);
|
OPEN vTravels;
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH vTravels INTO vLanded, vWarehouseFk, vIsWarehouseFloramondo;
|
||||||
|
|
||||||
UPDATE buy b
|
IF vDone THEN
|
||||||
JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id)
|
LEAVE l;
|
||||||
LEFT JOIN packaging p ON p.id = b.packagingFk
|
END IF;
|
||||||
JOIN item i ON i.id = b.itemFk
|
|
||||||
JOIN entry e ON e.id = b.entryFk
|
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
|
||||||
JOIN agencyMode am ON am.id = tr.agencyModeFk
|
|
||||||
JOIN tmp.rate r
|
|
||||||
JOIN volumeConfig vc
|
|
||||||
SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000)
|
|
||||||
/ b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0),
|
|
||||||
b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3),
|
|
||||||
b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)),
|
|
||||||
b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0
|
|
||||||
b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2),
|
|
||||||
b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2);
|
|
||||||
|
|
||||||
SELECT (b.buyingValue = b.price2), b.buyingValue, b.packagingFk
|
CALL rate_getPrices(vLanded, vWarehouseFk);
|
||||||
INTO vHasNotPrice, vBuyingValue, vPackagingFk
|
|
||||||
FROM vn.buy b
|
|
||||||
WHERE b.id = @buyId AND b.buyingValue <> 0.01;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.rate;
|
UPDATE buy b
|
||||||
|
JOIN tmp.buyRecalc br ON br.id = b.id AND (@buyId := b.id)
|
||||||
|
LEFT JOIN packaging p ON p.id = b.packagingFk
|
||||||
|
JOIN item i ON i.id = b.itemFk
|
||||||
|
JOIN entry e ON e.id = b.entryFk
|
||||||
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
|
JOIN agencyMode am ON am.id = tr.agencyModeFk
|
||||||
|
JOIN tmp.rate r
|
||||||
|
JOIN volumeConfig vc
|
||||||
|
SET b.freightValue = @PF:= IFNULL(((am.m3 * @m3:= item_getVolume(b.itemFk, b.packagingFk) / 1000000)
|
||||||
|
/ b.packing) * IF(am.hasWeightVolumetric, GREATEST(b.weight / @m3 / vc.aerealVolumetricDensity, 1), 1), 0),
|
||||||
|
b.comissionValue = @CF:= ROUND(IFNULL(e.commission * b.buyingValue / 100, 0), 3),
|
||||||
|
b.packageValue = @EF:= IF(vIsWarehouseFloramondo, 0, IFNULL(ROUND(IF(p.isPackageReturnable, p.returnCost / b.packing , p.`value` / b.packing), 3),0)),
|
||||||
|
b.price3 = @t3:= IF(r.rate3 = 0, b.buyingValue,ROUND((b.buyingValue + @CF + @EF + @PF) / ((100 - r.rate3 - it.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0
|
||||||
|
b.price2 = @t2:= round(@t3 * (1 + ((r.rate2 - r.rate3)/100)),2),
|
||||||
|
b.price2 = @t2:= IF(@t2 <= @t3,@t3 , @t2)
|
||||||
|
WHERE tr.landed = vLanded
|
||||||
|
AND tr.warehouseInFk = vWarehouseFk;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.rate;
|
||||||
|
END LOOP;
|
||||||
|
CLOSE vTravels;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue