feat: refs #8119 itemCampaignQuantity #3117
|
@ -72,9 +72,9 @@ describe('Renew Token', () => {
|
|||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
const query = 'SELECT * FROM util.debug';
|
||||
|
||||
const debugLog = await models.Application.rawSql(query, null);
|
||||
const query = 'SELECT * FROM util.debug WHERE variable = "renewToken"';
|
||||
const debugLog = await models.Application.rawSql(query);
|
||||
|
||||
expect(debugLog.length).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`itemCampaig_add`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-10-18 03:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL itemCampaign_add()$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,54 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemCampaign_add`()
|
||||
proc: BEGIN
|
||||
/**
|
||||
* Añade registros a tabla itemCampaign.
|
||||
*
|
||||
* @param vDateFrom Fecha desde
|
||||
* @param vDateTo Fecha hasta
|
||||
* @param vCampaign Código de la campaña
|
||||
*/
|
||||
DECLARE vYesterday DATE;
|
||||
DECLARE vCampaign VARCHAR(100);
|
||||
DECLARE vScopeDays INT;
|
||||
DECLARE vPreviousDays INT;
|
||||
DECLARE vDateSumFrom DATE;
|
||||
DECLARE vDateSumTo DATE;
|
||||
|
||||
SET vYesterday = util.yesterday();
|
||||
|
||||
SELECT dated, code, scopeDays, previousDays
|
||||
INTO vDateSumTo, vCampaign, vScopeDays, vPreviousDays
|
||||
FROM campaign
|
||||
WHERE dated >= vYesterday
|
||||
ORDER BY dated
|
||||
LIMIT 1;
|
||||
|
||||
IF vCampaign IS NULL THEN
|
||||
CALL util.throw('Missing data in campaign table');
|
||||
END IF;
|
||||
|
||||
IF NOT vYesterday BETWEEN vDateSumTo - INTERVAL vPreviousDays DAY
|
||||
AND vDateSumTo THEN
|
||||
LEAVE proc;
|
||||
END IF;
|
||||
|
||||
SET vDateSumFrom = vDateSumTo - INTERVAL vScopeDays DAY;
|
||||
SET vDateSumTo = vDateSumTo - INTERVAL 1 DAY;
|
||||
|
||||
INSERT INTO itemCampaign(dated, itemFk, quantity, total, campaign)
|
||||
SELECT vYesterday,
|
||||
s.itemFk,
|
||||
SUM(s.quantity) quantity,
|
||||
SUM((s.quantity * s.price) * (100 - s.discount) / 100) total,
|
||||
guillermo marked this conversation as resolved
Outdated
|
||||
vCampaign
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.shipped BETWEEN vDateSumFrom AND util.dayEnd(vDateSumTo)
|
||||
AND c.typeFk = 'normal'
|
||||
AND NOT t.isDeleted
|
||||
GROUP BY s.itemFk
|
||||
HAVING quantity;
|
||||
END$$
|
||||
guillermo marked this conversation as resolved
jgallego
commented
el rango que ha d'agafar es del 15 d'octubre al 31 d'octubre (aprox) el rango que ha d'agafar es del 15 d'octubre al 31 d'octubre (aprox)
|
||||
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
|||
CREATE TABLE IF NOT EXISTS `vn`.`itemCampaign` (
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
posali una definicio de que es guarda en esta taula posali una definicio de que es guarda en esta taula
|
||||
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
dated date NOT NULL,
|
||||
itemFk int(11) NOT NULL,
|
||||
quantity decimal(10,2) NOT NULL,
|
||||
total decimal(10,2) NOT NULL,
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
posali un camp id, que a salix les claus primaries dobles no les gestiona be, despues ja poses una clau unique en item,quantity posali un camp id, que a salix les claus primaries dobles no les gestiona be, despues ja poses una clau unique en item,quantity
|
||||
campaign varchar(100) NOT NULL,
|
||||
UNIQUE KEY `itemCampaign_UNIQUE` (`dated`,`itemFk`),
|
||||
CONSTRAINT itemCampaign_item_FK FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb3
|
||||
COLLATE=utf8mb3_unicode_ci
|
||||
COMMENT='Tallos confirmados por día en los días de más producción de una campaña. La tabla está pensada para que sea una foto.';
|
||||
|
||||
guillermo marked this conversation as resolved
Outdated
jgallego
commented
açò deuria tindre una Fk a la taula campaing? açò deuria tindre una Fk a la taula campaing?
guillermo
commented
No se puede, ya que en la tabla campaign hay más de 1 registro con ese dato, y además es de tipo ENUM. No se puede, ya que en la tabla campaign hay más de 1 registro con ese dato, y además es de tipo ENUM.
|
||||
ALTER TABLE vn.campaign
|
||||
ADD previousDays int(10) unsigned DEFAULT 30 NOT NULL COMMENT 'Días previos para calcular e insertar en la tabla itemCampaign';
|
||||
|
||||
UPDATE vn.campaign
|
||||
SET previousDays = 90
|
||||
WHERE code = 'allSaints';
|
||||
|
||||
UPDATE vn.campaign
|
||||
SET previousDays = 60
|
||||
WHERE code IN ('valentinesDay', 'mothersDay');
|
Loading…
Reference in New Issue
aci es on et comentaba que el from y el tu van en el where i despues agrupem tot junt per item