7199-devToTest_2316 #2287
|
@ -1,8 +1,14 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`greuge_dif_porte_add`()
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`greuge_dif_porte_add`()
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-60,util.VN_CURDATE()); -- '2019-07-01'
|
DECLARE vDateStarted DATETIME;
|
||||||
DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,util.VN_CURDATE());
|
DECLARE vDateEnded DATETIME DEFAULT TIMESTAMPADD(DAY,-1,util.VN_CURDATE());
|
||||||
|
DECLARE vDaysSinceLastRecalculation INT;
|
||||||
|
|
||||||
|
SELECT daysSinceLastRecalculation INTO vDaysSinceLastRecalculation
|
||||||
|
FROM vn.greugeConfig;
|
||||||
|
|
||||||
|
SET vDateStarted = TIMESTAMPADD(DAY, -vDaysSinceLastRecalculation, util.VN_CURDATE());
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.dp;
|
DROP TEMPORARY TABLE IF EXISTS tmp.dp;
|
||||||
|
|
||||||
|
@ -14,19 +20,17 @@ BEGIN
|
||||||
SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) AS teorico,
|
SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) AS teorico,
|
||||||
00000.00 as practico,
|
00000.00 as practico,
|
||||||
00000.00 as greuge,
|
00000.00 as greuge,
|
||||||
t.clientFk,
|
t.clientFk,
|
||||||
t.shipped
|
t.shipped
|
||||||
FROM
|
FROM vn.ticket t
|
||||||
vn.ticket t
|
|
||||||
JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk
|
JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk
|
||||||
LEFT JOIN vn.expedition e ON e.ticketFk = t.id
|
LEFT JOIN vn.expedition e ON e.ticketFk = t.id
|
||||||
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk
|
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk
|
||||||
JOIN vn.zone z ON t.zoneFk = z.id
|
JOIN vn.zone z ON t.zoneFk = z.id
|
||||||
WHERE
|
WHERE t.shipped between vDateStarted AND vDateEnded
|
||||||
t.shipped between datSTART AND datEND
|
AND cli.`real`
|
||||||
AND cli.`real`
|
AND t.companyFk IN (442 , 567)
|
||||||
AND t.companyFk IN (442 , 567)
|
AND z.isVolumetric = FALSE
|
||||||
AND z.isVolumetric = FALSE
|
|
||||||
GROUP BY t.id;
|
GROUP BY t.id;
|
||||||
|
|
||||||
-- Agencias que cobran por volumen
|
-- Agencias que cobran por volumen
|
||||||
|
@ -35,11 +39,11 @@ BEGIN
|
||||||
SUM(IFNULL(sv.freight,0)) AS teorico,
|
SUM(IFNULL(sv.freight,0)) AS teorico,
|
||||||
00000.00 as practico,
|
00000.00 as practico,
|
||||||
00000.00 as greuge,
|
00000.00 as greuge,
|
||||||
sv.clientFk,
|
sv.clientFk,
|
||||||
sv.shipped
|
sv.shipped
|
||||||
FROM vn.saleVolume sv
|
FROM vn.saleVolume sv
|
||||||
JOIN vn.zone z ON z.id = sv.zoneFk
|
JOIN vn.zone z ON z.id = sv.zoneFk
|
||||||
AND sv.shipped BETWEEN datSTART AND datEND
|
AND sv.shipped BETWEEN vDateStarted AND vDateEnded
|
||||||
AND z.isVolumetric != FALSE
|
AND z.isVolumetric != FALSE
|
||||||
GROUP BY sv.ticketFk;
|
GROUP BY sv.ticketFk;
|
||||||
|
|
||||||
|
@ -49,11 +53,11 @@ BEGIN
|
||||||
(PRIMARY KEY (ticketFk))
|
(PRIMARY KEY (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT dp.ticketFk, sum(Cantidad * Valor) as valor
|
SELECT dp.ticketFk, sum(Cantidad * Valor) as valor
|
||||||
FROM tmp.dp
|
FROM tmp.dp
|
||||||
JOIN vn2008.Movimientos m ON m.Id_Ticket = dp.ticketFk
|
JOIN vn2008.Movimientos m ON m.Id_Ticket = dp.ticketFk
|
||||||
JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
|
JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
|
||||||
WHERE mc.Id_Componente = 15
|
WHERE mc.Id_Componente = 15
|
||||||
GROUP BY dp.ticketFk;
|
GROUP BY dp.ticketFk;
|
||||||
|
|
||||||
UPDATE tmp.dp
|
UPDATE tmp.dp
|
||||||
JOIN tmp.dp_aux USING(ticketFk)
|
JOIN tmp.dp_aux USING(ticketFk)
|
||||||
|
@ -75,14 +79,14 @@ BEGIN
|
||||||
SET greuge = IFNULL(Importe,0);
|
SET greuge = IFNULL(Importe,0);
|
||||||
|
|
||||||
INSERT INTO vn.greuge (clientFk,description,amount,shipped,greugeTypeFk,ticketFk)
|
INSERT INTO vn.greuge (clientFk,description,amount,shipped,greugeTypeFk,ticketFk)
|
||||||
SELECT dp.clientFk
|
SELECT dp.clientFk,
|
||||||
, concat('dif_porte ', dp.ticketFk)
|
concat('dif_porte ', dp.ticketFk),
|
||||||
, round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe
|
round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe,
|
||||||
, date(dp.shipped)
|
date(dp.shipped),
|
||||||
, 1
|
1,
|
||||||
,dp.ticketFk
|
dp.ticketFk
|
||||||
FROM tmp.dp
|
FROM tmp.dp
|
||||||
JOIN vn.client c ON c.id = dp.clientFk
|
JOIN vn.client c ON c.id = dp.clientFk
|
||||||
WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1
|
WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1
|
||||||
AND c.isRelevant;
|
AND c.isRelevant;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE IF EXISTS `vn`.`greugeConfig`
|
||||||
|
ADD COLUMN IF NOT EXISTS `daysSinceLastRecalculation` int(11) NOT NULL;
|
||||||
|
|
||||||
|
INSERT INTO vn.greugeConfig (daysSinceLastRecalculation)
|
||||||
|
VALUES (15);
|
Loading…
Reference in New Issue