This commit is contained in:
parent
075259dee9
commit
9667d31441
|
@ -1,8 +1,14 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`greuge_dif_porte_add`()
|
||||
BEGIN
|
||||
DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-60,util.VN_CURDATE()); -- '2019-07-01'
|
||||
DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,util.VN_CURDATE());
|
||||
DECLARE vDateStarted DATETIME;
|
||||
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;
|
||||
|
||||
|
@ -16,14 +22,12 @@ BEGIN
|
|||
00000.00 as greuge,
|
||||
t.clientFk,
|
||||
t.shipped
|
||||
FROM
|
||||
vn.ticket t
|
||||
FROM vn.ticket t
|
||||
JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk
|
||||
LEFT JOIN vn.expedition e ON e.ticketFk = t.id
|
||||
JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.freightItemFk
|
||||
JOIN vn.zone z ON t.zoneFk = z.id
|
||||
WHERE
|
||||
t.shipped between datSTART AND datEND
|
||||
WHERE t.shipped between vDateStarted AND vDateEnded
|
||||
AND cli.`real`
|
||||
AND t.companyFk IN (442 , 567)
|
||||
AND z.isVolumetric = FALSE
|
||||
|
@ -39,7 +43,7 @@ BEGIN
|
|||
sv.shipped
|
||||
FROM vn.saleVolume sv
|
||||
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
|
||||
GROUP BY sv.ticketFk;
|
||||
|
||||
|
@ -75,12 +79,12 @@ BEGIN
|
|||
SET greuge = IFNULL(Importe,0);
|
||||
|
||||
INSERT INTO vn.greuge (clientFk,description,amount,shipped,greugeTypeFk,ticketFk)
|
||||
SELECT dp.clientFk
|
||||
, concat('dif_porte ', dp.ticketFk)
|
||||
, round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe
|
||||
, date(dp.shipped)
|
||||
, 1
|
||||
,dp.ticketFk
|
||||
SELECT dp.clientFk,
|
||||
concat('dif_porte ', dp.ticketFk),
|
||||
round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe,
|
||||
date(dp.shipped),
|
||||
1,
|
||||
dp.ticketFk
|
||||
FROM tmp.dp
|
||||
JOIN vn.client c ON c.id = dp.clientFk
|
||||
WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1
|
||||
|
|
|
@ -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