delete vendedores_updatePortfolio.sql
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ca40eee5ad
commit
5ea8c5b06c
|
@ -1,30 +0,0 @@
|
|||
DROP PROCEDURE IF EXISTS bs.vendedores_updatePortfolio;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `bs`.`vendedores_updatePortfolio`()
|
||||
BEGIN
|
||||
/**
|
||||
* Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial
|
||||
*
|
||||
*/
|
||||
DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01');
|
||||
|
||||
DELETE v
|
||||
FROM vendedores v
|
||||
JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes
|
||||
WHERE t.dated BETWEEN vStarted AND CURDATE();
|
||||
|
||||
INSERT INTO vendedores(Id_Trabajador, año, mes, portfolioWeight)
|
||||
SELECT c.lastSalesPersonFk
|
||||
, t.`year`
|
||||
, t.`month`
|
||||
, SUM(v.importe)
|
||||
FROM vn.`time` t
|
||||
STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha
|
||||
JOIN vn.`client` c ON c.id = v.Id_Cliente
|
||||
WHERE c.lastSalesPersonFk IS NOT NULL
|
||||
AND v.fecha BETWEEN vStarted AND CURDATE()
|
||||
GROUP BY c.lastSalesPersonFk, t.`month`, t.`year`;
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue