2024-01-31 11:14:24 +00:00
|
|
|
DELIMITER $$
|
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`analisis_ventas_update`()
|
2024-01-15 11:31:03 +00:00
|
|
|
BEGIN
|
|
|
|
DECLARE vLastMonth DATE;
|
|
|
|
|
|
|
|
SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, util.VN_CURDATE()));
|
|
|
|
|
|
|
|
DELETE FROM analisis_ventas
|
|
|
|
WHERE Año > YEAR(vLastMonth)
|
|
|
|
OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth));
|
|
|
|
|
|
|
|
INSERT INTO analisis_ventas (
|
2024-02-05 12:52:28 +00:00
|
|
|
Familia,
|
|
|
|
Reino,
|
|
|
|
Comercial,
|
|
|
|
Comprador,
|
|
|
|
Provincia,
|
|
|
|
almacen,
|
|
|
|
Año,
|
|
|
|
Mes,
|
|
|
|
Semana,
|
|
|
|
Vista,
|
|
|
|
Importe
|
|
|
|
)
|
2024-01-15 11:31:03 +00:00
|
|
|
SELECT
|
2024-04-24 07:53:31 +00:00
|
|
|
it.name,
|
|
|
|
ic.name,
|
|
|
|
w.code,
|
|
|
|
w2.code,
|
|
|
|
p.name,
|
|
|
|
wa.name,
|
|
|
|
tm.year,
|
|
|
|
tm.month,
|
|
|
|
tm.week,
|
|
|
|
dm.description,
|
|
|
|
bt.importe
|
2024-01-15 11:31:03 +00:00
|
|
|
FROM bs.ventas bt
|
2024-04-24 07:53:31 +00:00
|
|
|
LEFT JOIN vn.itemType it ON it.id = bt.tipo_id
|
|
|
|
LEFT JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
|
|
|
LEFT JOIN vn.client c on c.id = bt.Id_Cliente
|
|
|
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
|
|
|
LEFT JOIN vn.worker w2 ON w2.id = it.workerFk
|
|
|
|
JOIN vn.time tm ON tm.dated = bt.fecha
|
|
|
|
JOIN vn.sale s ON s.id = bt.Id_Movimiento
|
|
|
|
LEFT JOIN vn.ticket t ON t.id = s.ticketFk
|
|
|
|
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
|
|
|
LEFT JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
|
|
|
LEFT JOIN vn.address a ON a.id = t.addressFk
|
|
|
|
LEFT JOIN vn.province p ON p.id = a.provinceFk
|
|
|
|
LEFT JOIN vn.warehouse wa ON wa.id = t.warehouseFk
|
|
|
|
WHERE bt.fecha >= vLastMonth AND ic.merchandise;
|
2024-01-31 11:14:24 +00:00
|
|
|
END$$
|
|
|
|
DELIMITER ;
|