fix: descuentos en bs.ventas refs #6974
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
08ca1a302b
commit
27d59f4a8f
|
@ -1,32 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add`()
|
||||
BEGIN
|
||||
DECLARE lastCOMP INT; # Se trata de una variable para almacenar el ultimo valor del Periodo
|
||||
DECLARE vMaxPeriod INT;
|
||||
DECLARE vMaxWeek INT;
|
||||
|
||||
SELECT t.period, t.`week` INTO vMaxPeriod, vMaxWeek
|
||||
FROM vn.`time` t
|
||||
WHERE t.dated = util.VN_CURDATE();
|
||||
|
||||
SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa;
|
||||
-- Fijaremos las ventas con más de un mes de antiguedad en la tabla Comparativa
|
||||
|
||||
IF lastCOMP < vMaxPeriod - 3 AND vMaxWeek > 3 THEN
|
||||
|
||||
REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
|
||||
SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe)
|
||||
FROM bs.ventas v
|
||||
JOIN vn2008.time tm ON tm.date = v.fecha
|
||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id
|
||||
JOIN vn2008.reinos r ON r.id = tp.reino_id
|
||||
JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
|
||||
WHERE tm.period BETWEEN lastCOMP AND vMaxPeriod - 3
|
||||
AND t.Id_Cliente NOT IN(400,200)
|
||||
AND t.warehouse_id NOT IN (0,13)
|
||||
GROUP BY m.Id_Article, Periodo, t.warehouse_id;
|
||||
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,40 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`comparativa_add_manual`(IN vStarted DATE, IN vEnded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Recalcula la tabla Comparativa para dos valores dados
|
||||
*
|
||||
* @param vStarted fecha desde
|
||||
* @param vEnded fecha hasta
|
||||
*/
|
||||
|
||||
DECLARE periodStart INT;
|
||||
DECLARE periodEnd INT;
|
||||
|
||||
-- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar
|
||||
|
||||
SELECT t.period INTO periodStart
|
||||
FROM vn.`time` t
|
||||
WHERE t.dated = vStarted;
|
||||
|
||||
SELECT t.period INTO periodEnd
|
||||
FROM vn.`time` t
|
||||
WHERE t.dated = vEnded;
|
||||
|
||||
DELETE FROM vn2008.Comparativa
|
||||
WHERE Periodo BETWEEN periodStart AND periodEnd;
|
||||
|
||||
INSERT INTO vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
|
||||
SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe)
|
||||
FROM bs.ventas v
|
||||
JOIN vn2008.time tm ON tm.date = v.fecha
|
||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento
|
||||
JOIN vn2008.Tipos tp ON tp.tipo_id = v.tipo_id
|
||||
JOIN vn2008.reinos r ON r.id = tp.reino_id
|
||||
JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
|
||||
WHERE tm.period BETWEEN periodStart AND periodEnd
|
||||
AND t.Id_Cliente NOT IN(400,200)
|
||||
AND t.warehouse_id NOT IN (0,13)
|
||||
GROUP BY m.Id_Article, Periodo, t.warehouse_id;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -29,30 +29,34 @@ BEGIN
|
|||
|
||||
WHILE vEndingDate <= vEnded DO
|
||||
|
||||
REPLACE ventas(Id_Movimiento, importe, recargo, fecha, tipo_id, Id_Cliente, empresa_id)
|
||||
SELECT saleFk,
|
||||
SUM(IF(ct.isBase, s.quantity * sc.value, 0)) importe,
|
||||
SUM(IF(ct.isBase, 0, s.quantity * sc.value)) recargo,
|
||||
vStartingDate,
|
||||
i.typeFk,
|
||||
a.clientFk,
|
||||
t.companyFk
|
||||
FROM vn.saleComponent sc
|
||||
JOIN vn.component c ON c.id = sc.componentFk
|
||||
JOIN vn.componentType ct ON ct.id = c.typeFk
|
||||
JOIN vn.sale s ON s.id = sc.saleFk
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
JOIN vn.address a ON a.id = t.addressFk
|
||||
JOIN vn.client cl ON cl.id = a.clientFk
|
||||
WHERE t.shipped BETWEEN vStartingDate AND vEndingDate
|
||||
AND s.quantity <> 0
|
||||
AND s.discount <> 100
|
||||
AND ic.merchandise
|
||||
GROUP BY sc.saleFk
|
||||
HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0;
|
||||
REPLACE ventas(Id_Movimiento,
|
||||
importe,
|
||||
recargo,
|
||||
fecha,
|
||||
tipo_id,
|
||||
Id_Cliente,
|
||||
empresa_id
|
||||
)SELECT saleFk,
|
||||
IFNULL(SUM(IF(ct.isBase, s.quantity * sc.value, 0)), 0) importe,
|
||||
IFNULL(SUM(IF(ct.isBase, 0, s.quantity * sc.value)), 0) recargo,
|
||||
vStartingDate,
|
||||
i.typeFk,
|
||||
a.clientFk,
|
||||
t.companyFk
|
||||
FROM vn.saleComponent sc
|
||||
JOIN vn.component c ON c.id = sc.componentFk
|
||||
JOIN vn.componentType ct ON ct.id = c.typeFk
|
||||
JOIN vn.sale s ON s.id = sc.saleFk
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
JOIN vn.address a ON a.id = t.addressFk
|
||||
JOIN vn.client cl ON cl.id = a.clientFk
|
||||
WHERE t.shipped BETWEEN vStartingDate AND vEndingDate
|
||||
AND s.quantity <> 0
|
||||
AND ic.merchandise
|
||||
GROUP BY sc.saleFk;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN (
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
UPDATE vn.componentType
|
||||
SET isBase = 1
|
||||
WHERE code = 'MANA';
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.discountSale
|
||||
(PRIMARY KEY (saleFk))
|
||||
SELECT bs.saleFk,
|
||||
bs.amount,
|
||||
s.discount,
|
||||
SUM(IF(ct.isBase, s.quantity * sc.value, 0)) importe,
|
||||
SUM(IF(ct.isBase, 0, s.quantity * sc.value)) recargo
|
||||
FROM bs.sale bs
|
||||
JOIN vn.sale s ON s.id = bs.saleFk
|
||||
JOIN vn.saleComponent sc ON sc.saleFk = s.id
|
||||
JOIN vn.component c ON c.id = sc.componentFk
|
||||
JOIN vn.componentType ct ON ct.id = c.typeFk
|
||||
WHERE s.discount
|
||||
GROUP BY bs.saleFk;
|
||||
UPDATE bs.sale bs
|
||||
JOIN tmp.discountSale ts ON ts.saleFk = bs.saleFk
|
||||
SET bs.amount = ts.importe
|
||||
bs.surcharge = ts.recargo;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.discountSale;
|
||||
|
||||
DELETE FROM comparative
|
||||
WHERE timePeriod BETWEEN '202101' AND '202409';
|
||||
|
||||
INSERT INTO comparative(
|
||||
timePeriod,
|
||||
itemFk,
|
||||
warehouseFk,
|
||||
quantity,
|
||||
price,
|
||||
countryFk
|
||||
)
|
||||
SELECT tm.period,
|
||||
s.itemFk,
|
||||
t.warehouseFk,
|
||||
sum(s.quantity),
|
||||
sum(v.importe),
|
||||
p.countryFk
|
||||
FROM bs.ventas v
|
||||
JOIN time tm ON tm.dated = v.fecha
|
||||
JOIN sale s ON s.id = v.Id_Movimiento
|
||||
JOIN itemType tp ON tp.id = v.tipo_id
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk
|
||||
JOIN address ad ON ad.id = t.addressFk
|
||||
LEFT JOIN province p ON p.id = ad.provinceFk
|
||||
WHERE tm.period BETWEEN '202101' AND '202409'
|
||||
AND c.typeFk <> 'loses'
|
||||
AND NOT w.code = 'inv'
|
||||
GROUP BY p.countryFk, s.itemFk, tm.period, t.warehouseFk;
|
Loading…
Reference in New Issue