This commit is contained in:
parent
6227ef0821
commit
baec188ff5
|
@ -8,20 +8,19 @@ proc: BEGIN
|
||||||
* @param vDateTo Fecha hasta
|
* @param vDateTo Fecha hasta
|
||||||
* @param vCampaign Código de la campaña
|
* @param vCampaign Código de la campaña
|
||||||
*/
|
*/
|
||||||
DECLARE vCurdate DATE;
|
|
||||||
DECLARE vYesterday DATE;
|
DECLARE vYesterday DATE;
|
||||||
DECLARE vCampaign VARCHAR(100);
|
DECLARE vCampaign VARCHAR(100);
|
||||||
|
DECLARE vScopeDays INT;
|
||||||
DECLARE vPreviousDays INT;
|
DECLARE vPreviousDays INT;
|
||||||
DECLARE vDateSumFrom DATE;
|
DECLARE vDateSumFrom DATE;
|
||||||
DECLARE vDateSumTo DATE;
|
DECLARE vDateSumTo DATE;
|
||||||
DECLARE vScopeDays INT;
|
|
||||||
|
|
||||||
SET vCurdate = util.VN_CURDATE();
|
SET vYesterday = util.yesterday();
|
||||||
|
|
||||||
SELECT dated, code, scopeDays, previousDays
|
SELECT dated, code, scopeDays, previousDays
|
||||||
INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays
|
INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays
|
||||||
FROM campaign
|
FROM campaign
|
||||||
WHERE dated > vCurdate
|
WHERE dated >= vYesterday
|
||||||
ORDER BY dated
|
ORDER BY dated
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
|
@ -29,30 +28,26 @@ proc: BEGIN
|
||||||
CALL util.throw('Missing data in campaign table');
|
CALL util.throw('Missing data in campaign table');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF NOT vCurdate BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY
|
IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY
|
||||||
AND vDateSumTo THEN
|
AND vDateSumTo THEN
|
||||||
LEAVE proc;
|
LEAVE proc;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY;
|
SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY;
|
||||||
SET vYesterday = util.yesterday();
|
|
||||||
|
|
||||||
REPLACE itemCampaign(dated, itemFk, quantity, total, campaign)
|
INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign)
|
||||||
SELECT DATE(s.created),
|
SELECT vYesterday,
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo
|
SUM(s.quantity) quantity,
|
||||||
THEN s.quantity
|
SUM((s.quantity * s.price) * (100 - s.discount) / 100) total,
|
||||||
END) quantity,
|
|
||||||
SUM(CASE WHEN t.shipped BETWEEN vDateSumFrom AND vDateSumTo
|
|
||||||
THEN (s.quantity * s.price) * (100 - s.discount) / 100
|
|
||||||
END) total,
|
|
||||||
vCampaign
|
vCampaign
|
||||||
FROM sale s
|
FROM sale s
|
||||||
JOIN ticket t ON t.id = s.ticketFk
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
WHERE s.created BETWEEN vYesterday AND util.dayEnd(vYesterday)
|
WHERE t.shipped BETWEEN vDateSumFrom AND vDateSumTo
|
||||||
AND c.typeFk = 'normal'
|
AND c.typeFk = 'normal'
|
||||||
GROUP BY DATE(s.created), s.itemFk
|
AND NOT t.isDeleted
|
||||||
|
GROUP BY s.itemFk
|
||||||
HAVING quantity;
|
HAVING quantity;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue