vnZoneEvents refactor
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
parent
f12b1b8595
commit
4d4e4f31f4
|
@ -26,6 +26,12 @@ CREATE TABLE `vn`.`zoneEvent` (
|
||||||
CONSTRAINT `zoneEvent_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT `zoneEvent_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`zoneEvent`
|
||||||
|
ADD COLUMN `type` ENUM('day', 'indefinitely', 'range') NOT NULL AFTER `zoneFk`,
|
||||||
|
ADD COLUMN `dated` DATE NULL DEFAULT NULL AFTER `type`,
|
||||||
|
CHANGE COLUMN `from` `started` DATE NULL DEFAULT NULL ,
|
||||||
|
CHANGE COLUMN `to` `ended` DATE NULL DEFAULT NULL ;
|
||||||
|
|
||||||
CREATE TABLE `vn`.`zoneExclusion` (
|
CREATE TABLE `vn`.`zoneExclusion` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`zoneFk` int(11) NOT NULL,
|
`zoneFk` int(11) NOT NULL,
|
||||||
|
@ -45,3 +51,6 @@ ADD CONSTRAINT `fk_zone_1`
|
||||||
REFERENCES `vn`.`warehouse` (`id`)
|
REFERENCES `vn`.`warehouse` (`id`)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE CASCADE;
|
ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE `vn`.`zoneExclusion`
|
||||||
|
CHANGE COLUMN `day` `dated` DATE NOT NULL ;
|
|
@ -37,11 +37,11 @@ BEGIN
|
||||||
WHERE z.agencyModeFk != vAgencyModeFk;
|
WHERE z.agencyModeFk != vAgencyModeFk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT e.`from`, e.`to`, e.weekDays
|
SELECT e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays
|
||||||
FROM tmp.zone t
|
FROM tmp.zone t
|
||||||
JOIN zoneEvent e ON e.zoneFk = t.id;
|
JOIN zoneEvent e ON e.zoneFk = t.id;
|
||||||
|
|
||||||
SELECT DISTINCT e.`day`
|
SELECT DISTINCT e.dated
|
||||||
FROM tmp.zone t
|
FROM tmp.zone t
|
||||||
JOIN zoneExclusion e ON e.zoneFk = t.id;
|
JOIN zoneExclusion e ON e.zoneFk = t.id;
|
||||||
|
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
|
|
||||||
DROP PROCEDURE IF EXISTS `vn`.`zone_getOptionsForLanding`;
|
|
||||||
DELIMITER $$
|
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zone_getOptionsForLanding`(vLanded DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Gets computed options for the passed zones and delivery date.
|
|
||||||
*
|
|
||||||
* @table tmp.zones(id) The zones ids
|
|
||||||
* @param vLanded The delivery date
|
|
||||||
* @return tmp.zoneOption The computed options
|
|
||||||
*/
|
|
||||||
DECLARE vHour TIME DEFAULT TIME(NOW());
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
|
||||||
CREATE TEMPORARY TABLE tTemp
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT t.id zoneFk,
|
|
||||||
TIME(e.`hour`) `hour`,
|
|
||||||
e.travelingDays,
|
|
||||||
e.price,
|
|
||||||
e.bonus,
|
|
||||||
CASE
|
|
||||||
WHEN e.`from` IS NULL AND e.`to` IS NULL
|
|
||||||
THEN 3
|
|
||||||
WHEN e.`to` IS NULL
|
|
||||||
THEN 2
|
|
||||||
ELSE 1
|
|
||||||
END specificity
|
|
||||||
FROM tmp.zone t
|
|
||||||
JOIN zoneEvent e ON e.zoneFk = t.id
|
|
||||||
WHERE (e.`from` = vLanded AND e.`to` IS NULL)
|
|
||||||
OR (
|
|
||||||
(e.`from` IS NULL OR vLanded BETWEEN e.`from` AND e.`to`)
|
|
||||||
AND e.weekDays & (1 << WEEKDAY(vLanded))
|
|
||||||
);
|
|
||||||
|
|
||||||
-- XXX: Compatibility with the deprecated #zoneCalendar table
|
|
||||||
|
|
||||||
INSERT INTO tTemp
|
|
||||||
SELECT t.id zoneFk,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
c.price,
|
|
||||||
c.bonus,
|
|
||||||
4
|
|
||||||
FROM tmp.zone t
|
|
||||||
JOIN zoneCalendar c ON c.zoneFk = t.id
|
|
||||||
WHERE c.delivered = vLanded;
|
|
||||||
|
|
||||||
DELETE t FROM tTemp t
|
|
||||||
JOIN zoneExclusion e
|
|
||||||
ON e.zoneFk = t.zoneFk AND e.`day` = vLanded;
|
|
||||||
|
|
||||||
UPDATE tTemp t
|
|
||||||
JOIN zone z ON z.id = t.zoneFk
|
|
||||||
SET t.`hour` = IFNULL(t.`hour`, TIME(z.`hour`)),
|
|
||||||
t.travelingDays = IFNULL(t.travelingDays, z.travelingDays),
|
|
||||||
t.price = IFNULL(t.price, z.price),
|
|
||||||
t.bonus = IFNULL(t.bonus, z.bonus);
|
|
||||||
|
|
||||||
DELETE FROM tTemp
|
|
||||||
WHERE (@shipped := TIMESTAMPADD(DAY, -travelingDays, vLanded)) < CURDATE()
|
|
||||||
OR @shipped = CURDATE() AND vHour > `hour`;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
|
||||||
CREATE TEMPORARY TABLE tmp.zoneOption
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT *
|
|
||||||
FROM (
|
|
||||||
SELECT * FROM tTemp
|
|
||||||
ORDER BY zoneFk, specificity
|
|
||||||
) t
|
|
||||||
GROUP BY zoneFk;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTemp;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
USE `vn`;
|
||||||
|
DROP procedure IF EXISTS `zone_getOptionsForLanding`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
USE `vn`$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForLanding`(vLanded DATE)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Gets computed options for the passed zones and delivery date.
|
||||||
|
*
|
||||||
|
* @table tmp.zones(id) The zones ids
|
||||||
|
* @param vLanded The delivery date
|
||||||
|
* @return tmp.zoneOption The computed options
|
||||||
|
*/
|
||||||
|
DECLARE vHour TIME DEFAULT TIME(NOW());
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
||||||
|
CREATE TEMPORARY TABLE tTemp
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id zoneFk,
|
||||||
|
IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`,
|
||||||
|
IFNULL(e.travelingDays, z.travelingDays) travelingDays,
|
||||||
|
IFNULL(e.price, z.price) price,
|
||||||
|
IFNULL(e.bonus, z.bonus) bonus,
|
||||||
|
CASE
|
||||||
|
WHEN e.`type` = 'day'
|
||||||
|
THEN 1
|
||||||
|
WHEN e.`type` = 'range'
|
||||||
|
THEN 2
|
||||||
|
ELSE 3
|
||||||
|
END specificity
|
||||||
|
FROM tmp.zone t
|
||||||
|
JOIN zone z ON z.id = t.id
|
||||||
|
JOIN zoneEvent e ON e.zoneFk = t.id
|
||||||
|
WHERE (
|
||||||
|
e.`type` = 'day'
|
||||||
|
AND e.dated = vLanded
|
||||||
|
) OR (
|
||||||
|
e.`type` != 'day'
|
||||||
|
AND e.weekDays & (1 << WEEKDAY(vLanded))
|
||||||
|
AND (e.`started` IS NULL OR vLanded >= e.`started`)
|
||||||
|
AND (e.`ended` IS NULL OR vLanded <= e.`ended`)
|
||||||
|
);
|
||||||
|
|
||||||
|
DELETE t FROM tTemp t
|
||||||
|
JOIN zoneExclusion e
|
||||||
|
ON e.zoneFk = t.zoneFk AND e.`dated` = vLanded;
|
||||||
|
|
||||||
|
DELETE FROM tTemp
|
||||||
|
WHERE (@shipped := TIMESTAMPADD(DAY, -travelingDays, vLanded)) < CURDATE()
|
||||||
|
OR @shipped = CURDATE() AND vHour > `hour`;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
||||||
|
CREATE TEMPORARY TABLE tmp.zoneOption
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT * FROM tTemp
|
||||||
|
ORDER BY zoneFk, specificity
|
||||||
|
) t
|
||||||
|
GROUP BY zoneFk;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tTemp;
|
||||||
|
END$$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
USE `vn`;
|
||||||
|
DROP procedure IF EXISTS `zone_getOptionsForShipment`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
USE `vn`$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForShipment`(vShipped DATE)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Gets computed options for the passed zones and shipping date.
|
||||||
|
*
|
||||||
|
* @table tmp.zones(id) The zones ids
|
||||||
|
* @param vShipped The shipping date
|
||||||
|
* @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options
|
||||||
|
*/
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tLandings;
|
||||||
|
CREATE TEMPORARY TABLE tLandings
|
||||||
|
(INDEX (eventFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT e.id eventFk,
|
||||||
|
@travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays,
|
||||||
|
TIMESTAMPADD(DAY, @travelingDays, vShipped) landed
|
||||||
|
FROM tmp.zone t
|
||||||
|
JOIN zone z ON z.id = t.id
|
||||||
|
JOIN zoneEvent e ON e.zoneFk = t.id;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
||||||
|
CREATE TEMPORARY TABLE tTemp
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id zoneFk,
|
||||||
|
IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`,
|
||||||
|
IFNULL(e.price, z.price) price,
|
||||||
|
IFNULL(e.bonus, z.bonus) bonus,
|
||||||
|
CASE
|
||||||
|
WHEN e.`type` = 'day'
|
||||||
|
THEN 1
|
||||||
|
WHEN e.`type` = 'range'
|
||||||
|
THEN 2
|
||||||
|
ELSE 3
|
||||||
|
END specificity,
|
||||||
|
l.travelingDays,
|
||||||
|
l.landed
|
||||||
|
FROM tmp.zone t
|
||||||
|
JOIN zone z ON z.id = t.id
|
||||||
|
JOIN zoneEvent e ON e.zoneFk = t.id
|
||||||
|
JOIN tLandings l ON l.eventFk = e.id
|
||||||
|
HAVING (
|
||||||
|
e.`type` = 'day'
|
||||||
|
AND e.`dated` = l.landed
|
||||||
|
) OR (
|
||||||
|
e.`type` != 'day'
|
||||||
|
AND e.weekDays & (1 << WEEKDAY(l.landed))
|
||||||
|
AND (e.`started` IS NULL OR l.landed >= e.`started`)
|
||||||
|
AND (e.`ended` IS NULL OR l.landed <= e.`ended`)
|
||||||
|
);
|
||||||
|
|
||||||
|
DELETE t FROM tTemp t
|
||||||
|
JOIN zoneExclusion e
|
||||||
|
ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
||||||
|
CREATE TEMPORARY TABLE tmp.zoneOption
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT *
|
||||||
|
FROM (
|
||||||
|
SELECT * FROM tTemp
|
||||||
|
ORDER BY zoneFk, specificity
|
||||||
|
) t
|
||||||
|
GROUP BY zoneFk;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE
|
||||||
|
tTemp,
|
||||||
|
tLandings;
|
||||||
|
END$$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -1,88 +0,0 @@
|
||||||
USE `vn`;
|
|
||||||
DROP procedure IF EXISTS `ticketCreateWithUser`;
|
|
||||||
|
|
||||||
DELIMITER $$
|
|
||||||
USE `vn`$$
|
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`(
|
|
||||||
vClientId INT
|
|
||||||
,vShipped DATE
|
|
||||||
,vWarehouseFk INT
|
|
||||||
,vCompanyFk INT
|
|
||||||
,vAddressFk INT
|
|
||||||
,vAgencyModeFk INT
|
|
||||||
,vRouteFk INT
|
|
||||||
,vlanded DATE
|
|
||||||
,vUserId INT
|
|
||||||
,OUT vNewTicket INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
DECLARE vZoneFk INT;
|
|
||||||
|
|
||||||
IF vClientId IS NULL THEN
|
|
||||||
CALL util.throw ('CLIENT_NOT_ESPECIFIED');
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF NOT vAddressFk OR vAddressFk IS NULL THEN
|
|
||||||
SELECT id INTO vAddressFk
|
|
||||||
FROM address
|
|
||||||
WHERE clientFk = vClientId AND isDefaultAddress;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF vAgencyModeFk IS NOT NULL THEN
|
|
||||||
|
|
||||||
CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk);
|
|
||||||
|
|
||||||
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetShipped
|
|
||||||
WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1;
|
|
||||||
|
|
||||||
IF vZoneFk IS NULL OR vZoneFk = 0 THEN
|
|
||||||
CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS');
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
INSERT INTO vn2008.Tickets (
|
|
||||||
Id_Cliente,
|
|
||||||
Fecha,
|
|
||||||
Id_Consigna,
|
|
||||||
Id_Agencia,
|
|
||||||
Alias,
|
|
||||||
warehouse_id,
|
|
||||||
Id_Ruta,
|
|
||||||
empresa_id,
|
|
||||||
landing,
|
|
||||||
zoneFk
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
vClientId,
|
|
||||||
vShipped,
|
|
||||||
a.id,
|
|
||||||
vAgencyModeFk,
|
|
||||||
a.nickname,
|
|
||||||
vWarehouseFk,
|
|
||||||
IF(vRouteFk,vRouteFk,NULL),
|
|
||||||
vCompanyFk,
|
|
||||||
vlanded,
|
|
||||||
vZoneFk
|
|
||||||
FROM address a
|
|
||||||
JOIN agencyMode am ON am.id = a.agencyModeFk
|
|
||||||
WHERE a.id = vAddressFk;
|
|
||||||
|
|
||||||
SET vNewTicket = LAST_INSERT_ID();
|
|
||||||
|
|
||||||
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
|
|
||||||
SELECT vNewTicket, ao.observationTypeFk, ao.description
|
|
||||||
FROM addressObservation ao
|
|
||||||
JOIN address a ON a.id = ao.addressFk
|
|
||||||
WHERE a.id = vAddressFk;
|
|
||||||
|
|
||||||
INSERT INTO vn.ticketLog
|
|
||||||
SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket);
|
|
||||||
|
|
||||||
IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN
|
|
||||||
INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
|
|
||||||
SELECT id, vNewTicket, getWorker()
|
|
||||||
FROM state
|
|
||||||
WHERE `code` = 'DELIVERED';
|
|
||||||
END IF;
|
|
||||||
END$$
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
|
@ -1,83 +0,0 @@
|
||||||
|
|
||||||
USE `vn`;
|
|
||||||
DROP procedure IF EXISTS `vn`.`zone_getOptionsForLanding`;
|
|
||||||
|
|
||||||
DELIMITER $$
|
|
||||||
USE `vn`$$
|
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForLanding`(vLanded DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Gets computed options for the passed zones and delivery date.
|
|
||||||
*
|
|
||||||
* @table tmp.zones(id) The zones ids
|
|
||||||
* @param vLanded The delivery date
|
|
||||||
* @return tmp.zoneOption The computed options
|
|
||||||
*/
|
|
||||||
DECLARE vHour TIME DEFAULT TIME(NOW());
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
|
||||||
CREATE TEMPORARY TABLE tTemp
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT t.id zoneFk,
|
|
||||||
TIME(e.`hour`) `hour`,
|
|
||||||
e.travelingDays,
|
|
||||||
e.price,
|
|
||||||
e.bonus,
|
|
||||||
CASE
|
|
||||||
WHEN e.`from` IS NULL AND e.`to` IS NULL
|
|
||||||
THEN 3
|
|
||||||
WHEN e.`to` IS NULL
|
|
||||||
THEN 2
|
|
||||||
ELSE 1
|
|
||||||
END specificity
|
|
||||||
FROM tmp.zone t
|
|
||||||
JOIN zoneEvent e ON e.zoneFk = t.id
|
|
||||||
WHERE (e.`from` = vLanded AND e.`to` IS NULL)
|
|
||||||
OR (
|
|
||||||
(e.`from` IS NULL OR vLanded BETWEEN e.`from` AND e.`to`)
|
|
||||||
AND e.weekDays & (1 << WEEKDAY(vLanded))
|
|
||||||
);
|
|
||||||
|
|
||||||
-- XXX: Compatibility with the deprecated #zoneCalendar table
|
|
||||||
|
|
||||||
INSERT INTO tTemp
|
|
||||||
SELECT t.id zoneFk,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
c.price,
|
|
||||||
c.bonus,
|
|
||||||
4
|
|
||||||
FROM tmp.zone t
|
|
||||||
JOIN zoneCalendar c ON c.zoneFk = t.id
|
|
||||||
WHERE c.delivered = vLanded;
|
|
||||||
|
|
||||||
DELETE t FROM tTemp t
|
|
||||||
JOIN zoneExclusion e
|
|
||||||
ON e.zoneFk = t.zoneFk AND e.`day` = vLanded;
|
|
||||||
|
|
||||||
UPDATE tTemp t
|
|
||||||
JOIN zone z ON z.id = t.zoneFk
|
|
||||||
SET t.`hour` = IFNULL(t.`hour`, TIME(z.`hour`)),
|
|
||||||
t.travelingDays = IFNULL(t.travelingDays, z.travelingDays),
|
|
||||||
t.price = IFNULL(t.price, z.price),
|
|
||||||
t.bonus = IFNULL(t.bonus, z.bonus);
|
|
||||||
|
|
||||||
DELETE FROM tTemp
|
|
||||||
WHERE (@shipped := TIMESTAMPADD(DAY, -travelingDays, vLanded)) < CURDATE()
|
|
||||||
OR @shipped = CURDATE() AND vHour > `hour`;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
|
||||||
CREATE TEMPORARY TABLE tmp.zoneOption
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT *
|
|
||||||
FROM (
|
|
||||||
SELECT * FROM tTemp
|
|
||||||
ORDER BY zoneFk, specificity
|
|
||||||
) t
|
|
||||||
GROUP BY zoneFk;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTemp;
|
|
||||||
END$$
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
||||||
;
|
|
|
@ -1,65 +0,0 @@
|
||||||
USE `vn`;
|
|
||||||
DROP procedure IF EXISTS `zone_getOptionsForShipment`;
|
|
||||||
|
|
||||||
DELIMITER $$
|
|
||||||
USE `vn`$$
|
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getOptionsForShipment`(vShipped DATE)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Gets computed options for the passed zones and shipping date.
|
|
||||||
*
|
|
||||||
* @table tmp.zones(id) The zones ids
|
|
||||||
* @param vShipped The shipping date
|
|
||||||
* @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options
|
|
||||||
*/
|
|
||||||
DECLARE vHour TIME DEFAULT TIME(NOW());
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tTemp;
|
|
||||||
CREATE TEMPORARY TABLE tTemp
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT t.id zoneFk,
|
|
||||||
TIME(e.`hour`) `hour`,
|
|
||||||
e.travelingDays,
|
|
||||||
e.price,
|
|
||||||
e.bonus,
|
|
||||||
CASE
|
|
||||||
WHEN e.`from` IS NULL AND e.`to` IS NULL
|
|
||||||
THEN 3
|
|
||||||
WHEN e.`to` IS NULL
|
|
||||||
THEN 2
|
|
||||||
ELSE 1
|
|
||||||
END specificity
|
|
||||||
FROM tmp.zone t
|
|
||||||
JOIN zoneEvent e ON e.zoneFk = t.id
|
|
||||||
WHERE (e.`from` = TIMESTAMPADD(DAY, e.travelingDays, vShipped) AND e.`to` IS NULL)
|
|
||||||
OR (
|
|
||||||
(e.`from` IS NULL OR TIMESTAMPADD(DAY, e.travelingDays, vShipped) BETWEEN e.`from` AND e.`to`)
|
|
||||||
AND e.weekDays & (1 << WEEKDAY(TIMESTAMPADD(DAY, e.travelingDays, vShipped)))
|
|
||||||
);
|
|
||||||
|
|
||||||
DELETE t FROM tTemp t
|
|
||||||
JOIN zoneExclusion e
|
|
||||||
ON e.zoneFk = t.zoneFk AND TIMESTAMPADD(DAY,-t.travelingDays, e.`day`) = vShipped;
|
|
||||||
|
|
||||||
UPDATE tTemp t
|
|
||||||
JOIN zone z ON z.id = t.zoneFk
|
|
||||||
SET t.`hour` = IFNULL(t.`hour`, TIME(z.`hour`)),
|
|
||||||
t.travelingDays = IFNULL(t.travelingDays, z.travelingDays),
|
|
||||||
t.price = IFNULL(t.price, z.price),
|
|
||||||
t.bonus = IFNULL(t.bonus, z.bonus);
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption;
|
|
||||||
CREATE TEMPORARY TABLE tmp.zoneOption
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT *
|
|
||||||
FROM (
|
|
||||||
SELECT * FROM tTemp
|
|
||||||
ORDER BY zoneFk, specificity
|
|
||||||
) t
|
|
||||||
GROUP BY zoneFk;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTemp;
|
|
||||||
END$$
|
|
||||||
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
|
@ -1619,220 +1619,220 @@ INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`)
|
||||||
(8, 5, 0),
|
(8, 5, 0),
|
||||||
(8, 1, 1);
|
(8, 1, 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `from`)
|
INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=2, 2, 9 ) - DAYOFWEEK(CURDATE())) DAY)),
|
(1, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=2, 2, 9 ) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=3, 3, 10) - DAYOFWEEK(CURDATE())) DAY)),
|
(1, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=3, 3, 10) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=4, 4, 11) - DAYOFWEEK(CURDATE())) DAY)),
|
(1, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=4, 4, 11) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=5, 5, 12) - DAYOFWEEK(CURDATE())) DAY)),
|
(1, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=5, 5, 12) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(1, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=6, 6, 13) - DAYOFWEEK(CURDATE())) DAY)),
|
(1, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=6, 6, 13) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(2, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=2, 2, 9 ) - DAYOFWEEK(CURDATE())) DAY)),
|
(2, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=2, 2, 9 ) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(2, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=3, 3, 10) - DAYOFWEEK(CURDATE())) DAY)),
|
(2, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=3, 3, 10) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(2, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=4, 4, 11) - DAYOFWEEK(CURDATE())) DAY)),
|
(2, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=4, 4, 11) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(2, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=5, 5, 12) - DAYOFWEEK(CURDATE())) DAY)),
|
(2, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=5, 5, 12) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(2, DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=6, 6, 13) - DAYOFWEEK(CURDATE())) DAY)),
|
(2, 'day', DATE_ADD(CURDATE(), INTERVAL (IF(DAYOFWEEK(CURDATE())<=6, 6, 13) - DAYOFWEEK(CURDATE())) DAY)),
|
||||||
(3, CURDATE()),
|
(3, 'day', CURDATE()),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
||||||
(3, DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
(3, 'day', DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
||||||
(4, CURDATE()),
|
(4, 'day', CURDATE()),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
||||||
(4, DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
(4, 'day', DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
||||||
(5, CURDATE()),
|
(5, 'day', CURDATE()),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
||||||
(5, DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
(5, 'day', DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
||||||
(6, CURDATE()),
|
(6, 'day', CURDATE()),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +7 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +8 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +9 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +10 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +11 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +12 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +13 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +14 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +15 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +16 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +17 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +18 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +19 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +20 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +21 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +22 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +23 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +24 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +25 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +26 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +27 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +28 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +29 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +30 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +31 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +32 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +33 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +34 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +35 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +36 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +37 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +38 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +39 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +40 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +41 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +42 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +43 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +44 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +45 DAY)),
|
||||||
(6, DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
(6, 'day', DATE_ADD(CURDATE(), INTERVAL +46 DAY)),
|
||||||
(7, CURDATE()),
|
(7, 'day', CURDATE()),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(7, DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
(7, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)),
|
||||||
(8, CURDATE()),
|
(8, 'day', CURDATE()),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +1 DAY)),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +2 DAY)),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +3 DAY)),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +4 DAY)),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)),
|
||||||
(8, DATE_ADD(CURDATE(), INTERVAL +6 DAY));
|
(8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY));
|
||||||
|
|
||||||
INSERT INTO `vn`.`workerTimeControl`(`userFk`,`timed`,`manual`)
|
INSERT INTO `vn`.`workerTimeControl`(`userFk`,`timed`,`manual`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<span
|
<span
|
||||||
ng-repeat="day in $ctrl.days"
|
ng-repeat="day in $ctrl.days"
|
||||||
translate-attr="::{title: day.name}"
|
translate-attr="::{title: day.name}"
|
||||||
ng-class="{marked: $ctrl.field[day.code]}"
|
ng-class="{marked: $ctrl.field[day.index]}"
|
||||||
ng-click="$ctrl.field[day.code] = !$ctrl.field[day.code]">
|
ng-click="$ctrl.toggleDay(day.index)">
|
||||||
{{day.localeChar}}
|
{{day.localeChar}}
|
||||||
</span>
|
</span>
|
|
@ -8,6 +8,13 @@ export default class WdayPicker extends FormInput {
|
||||||
this.days = vnWeekDays.locales;
|
this.days = vnWeekDays.locales;
|
||||||
this.initTabIndex();
|
this.initTabIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleDay(index) {
|
||||||
|
let field = this.field;
|
||||||
|
if (!field) field = [];
|
||||||
|
field[index] = !field[index];
|
||||||
|
this.change(field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WdayPicker.$inject = ['$element', '$scope', 'vnWeekDays'];
|
WdayPicker.$inject = ['$element', '$scope', 'vnWeekDays'];
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {Array} days Weekdays data array with the same indexes as Date.getDay()
|
||||||
|
* @property {Object} map Weekdays data map using weekday codes as key
|
||||||
|
* @property {Array} localeCodes Locale weekday codes indexes depend on current locale
|
||||||
|
* @property {Array} locale Weekday data array with indexes depending on current locale
|
||||||
|
*
|
||||||
|
* Weekday properties:
|
||||||
|
*
|
||||||
|
* @property {Number} index The weekday index acording to Date.getDay()
|
||||||
|
* @property {String} code The weekday code
|
||||||
|
* @property {String} name The weekday name
|
||||||
|
* @property {String} char The first weekday letter
|
||||||
|
* @property {String} abr The abreviated 3 letters weekday name
|
||||||
|
* @property {String} locale The weekday name in current locale
|
||||||
|
* @property {String} localeChar The first weekday letter in current locale
|
||||||
|
* @property {String} localeAbr The abreviated 3 letters weekday name in current locale
|
||||||
|
*/
|
||||||
class WeekDays {
|
class WeekDays {
|
||||||
constructor($translate) {
|
constructor($translate) {
|
||||||
this.$translate = $translate;
|
this.$translate = $translate;
|
||||||
|
@ -65,6 +82,34 @@ class WeekDays {
|
||||||
for (let code of this.localeCodes)
|
for (let code of this.localeCodes)
|
||||||
this.locales.push(this.map[code]);
|
this.locales.push(this.map[code]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fromSet(weekDays) {
|
||||||
|
let wdays = [];
|
||||||
|
|
||||||
|
if (weekDays) {
|
||||||
|
let codes = weekDays.split(',');
|
||||||
|
for (let code of codes) {
|
||||||
|
let data = this.map[code];
|
||||||
|
if (data) wdays[data.index] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wdays;
|
||||||
|
}
|
||||||
|
|
||||||
|
toSet(wdays) {
|
||||||
|
let weekDays = [];
|
||||||
|
|
||||||
|
if (wdays) {
|
||||||
|
for (let i = 0; i < wdays.length; i++) {
|
||||||
|
if (!wdays[i]) continue;
|
||||||
|
let data = this.days[i];
|
||||||
|
if (data) weekDays.push(data.code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return weekDays.join(',');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
WeekDays.$inject = ['$translate'];
|
WeekDays.$inject = ['$translate'];
|
||||||
|
|
||||||
|
|
|
@ -113,5 +113,9 @@
|
||||||
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
|
"You can't create a claim for a removed ticket": "No puedes crear una reclamación para un ticket eliminado",
|
||||||
"You cannot delete a ticket that part of it is being prepared": "No puedes eliminar un ticket en el que una parte que está siendo preparada",
|
"You cannot delete a ticket that part of it is being prepared": "No puedes eliminar un ticket en el que una parte que está siendo preparada",
|
||||||
"You must delete all the buy requests first": "Debes eliminar todas las peticiones de compra primero",
|
"You must delete all the buy requests first": "Debes eliminar todas las peticiones de compra primero",
|
||||||
"Has deleted the ticket id": "Ha eliminado el ticket id [#{{id}}]({{{url}}})"
|
"Has deleted the ticket id": "Ha eliminado el ticket id [#{{id}}]({{{url}}})",
|
||||||
|
"You should specify a date": "Debes especificar una fecha",
|
||||||
|
"You should specify at least a start or end date": "Debes especificar al menos una fecha de inicio o de fín",
|
||||||
|
"Start date should be lower than end date": "La fecha de inicio debe ser menor que la fecha de fín",
|
||||||
|
"You should mark at least one week day": "Debes marcar al menos un día de la semana"
|
||||||
}
|
}
|
|
@ -1,9 +1,35 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
function rangeValid(err) {
|
Self.validate('range', function(err) {
|
||||||
if (this.from && this.to && this.from >= this.to)
|
if (this.type == 'range'
|
||||||
|
&& !this.started
|
||||||
|
&& !this.ended)
|
||||||
err();
|
err();
|
||||||
}
|
}, {
|
||||||
Self.validate('rangeValid', rangeValid, {
|
message: `You should specify at least a start or end date`
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.validate('validRange', function(err) {
|
||||||
|
if (this.type == 'range'
|
||||||
|
&& this.started
|
||||||
|
&& this.ended
|
||||||
|
&& this.started >= this.ended)
|
||||||
|
err();
|
||||||
|
}, {
|
||||||
message: `Start date should be lower than end date`
|
message: `Start date should be lower than end date`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Self.validate('dated', function(err) {
|
||||||
|
if (this.type == 'day' && !this.dated)
|
||||||
|
err();
|
||||||
|
}, {
|
||||||
|
message: `You should specify a date`
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.validate('weekDays', function(err) {
|
||||||
|
if (['range', 'indefinitely'].indexOf(this.type) !== -1
|
||||||
|
&& !this.weekDays)
|
||||||
|
err();
|
||||||
|
}, {
|
||||||
|
message: `You should mark at least one week day`
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,10 +15,16 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"from": {
|
"type": {
|
||||||
|
"type": "String"
|
||||||
|
},
|
||||||
|
"dated": {
|
||||||
"type": "Date"
|
"type": "Date"
|
||||||
},
|
},
|
||||||
"to": {
|
"started": {
|
||||||
|
"type": "Date"
|
||||||
|
},
|
||||||
|
"ended": {
|
||||||
"type": "Date"
|
"type": "Date"
|
||||||
},
|
},
|
||||||
"weekDays": {
|
"weekDays": {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "Number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
"day": {
|
"dated": {
|
||||||
"type": "Date",
|
"type": "Date",
|
||||||
"required": true
|
"required": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Component {
|
class Controller extends Component {
|
||||||
constructor($element, $) {
|
constructor($element, $, vnWeekDays) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
|
this.vnWeekDays = vnWeekDays;
|
||||||
this.nMonths = 4;
|
this.nMonths = 4;
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
|
@ -54,19 +55,29 @@ class Controller extends Component {
|
||||||
this._data = value;
|
this._data = value;
|
||||||
|
|
||||||
value = value || {};
|
value = value || {};
|
||||||
this.events = value.events;
|
|
||||||
this.exclusions = value.exclusions;
|
|
||||||
|
|
||||||
if (this.events) {
|
this.events = value.events;
|
||||||
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
||||||
for (event of this.events) {
|
function toStamp(date) {
|
||||||
event.wdays = [];
|
return date && new Date(date).setHours(0, 0, 0, 0);
|
||||||
if (!event.weekDays) continue;
|
|
||||||
let weekDays = event.weekDays.split(',');
|
|
||||||
for (let wday of weekDays) {
|
|
||||||
let index = codes.indexOf(wday);
|
|
||||||
if (index !== -1) event.wdays[index] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.exclusionsMap = {};
|
||||||
|
let exclusions = value.exclusions;
|
||||||
|
|
||||||
|
if (exclusions) {
|
||||||
|
for (let exclusion of exclusions)
|
||||||
|
this.exclusionsMap[toStamp(exclusion.dated)] = exclusion;
|
||||||
|
}
|
||||||
|
|
||||||
|
let events = value.events;
|
||||||
|
|
||||||
|
if (events) {
|
||||||
|
for (event of events) {
|
||||||
|
event.dated = toStamp(event.dated);
|
||||||
|
event.ended = toStamp(event.ended);
|
||||||
|
event.started = toStamp(event.started);
|
||||||
|
event.wdays = this.vnWeekDays.fromSet(event.weekDays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,17 +89,9 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshEvents() {
|
refreshEvents() {
|
||||||
function getDate(date) {
|
|
||||||
return date && new Date(date).setHours(0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
let exclusionsMap = {};
|
|
||||||
if (this.exclusions) {
|
|
||||||
for (let exclusion of this.exclusions)
|
|
||||||
exclusionsMap[getDate(exclusion.day)] = exclusion;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.days = {};
|
this.days = {};
|
||||||
|
if (!this.data) return;
|
||||||
|
|
||||||
let day = new Date(this.firstDay.getTime());
|
let day = new Date(this.firstDay.getTime());
|
||||||
|
|
||||||
while (day <= this.lastDay) {
|
while (day <= this.lastDay) {
|
||||||
|
@ -99,23 +102,24 @@ class Controller extends Component {
|
||||||
if (this.events) {
|
if (this.events) {
|
||||||
for (let event of this.events) {
|
for (let event of this.events) {
|
||||||
let match;
|
let match;
|
||||||
let from = getDate(event.from);
|
|
||||||
let to = getDate(event.to);
|
|
||||||
|
|
||||||
if (event.from && event.to) {
|
switch (event.type) {
|
||||||
match = stamp >= from && stamp <= to
|
case 'day':
|
||||||
&& event.wdays[wday];
|
match = event.dated == stamp;
|
||||||
} else if (event.from)
|
break;
|
||||||
match = from == stamp;
|
default:
|
||||||
else
|
match = event.wdays[wday]
|
||||||
match = event.wdays[wday];
|
&& (!event.started || stamp >= event.started)
|
||||||
|
&& (!event.ended || stamp <= event.ended);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (match)
|
if (match)
|
||||||
dayEvents.push(event);
|
dayEvents.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let exclusion = exclusionsMap[stamp];
|
let exclusion = this.exclusionsMap[stamp];
|
||||||
|
|
||||||
if (dayEvents.length || exclusion) {
|
if (dayEvents.length || exclusion) {
|
||||||
let dayData = {};
|
let dayData = {};
|
||||||
|
@ -152,6 +156,7 @@ class Controller extends Component {
|
||||||
return dayData && dayData.exclusion ? 'excluded' : '';
|
return dayData && dayData.exclusion ? 'excluded' : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
|
||||||
|
|
||||||
ngModule.component('vnZoneCalendar', {
|
ngModule.component('vnZoneCalendar', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -42,17 +42,17 @@
|
||||||
class="vn-item">
|
class="vn-item">
|
||||||
<vn-item-section>
|
<vn-item-section>
|
||||||
<div
|
<div
|
||||||
ng-if="::row.from && !row.to"
|
ng-if="::row.type == 'day'"
|
||||||
class="vn-mb-sm">
|
class="vn-mb-sm">
|
||||||
{{::row.from | date:'dd/MM/yy'}}
|
{{::row.dated | date:'dd/MM/yy'}}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
ng-if="::!row.from || row.to"
|
ng-if="::row.type != 'day'"
|
||||||
class="vn-mb-sm ellipsize">
|
class="vn-mb-sm ellipsize">
|
||||||
<span ng-if="row.to">
|
<span ng-if="row.type == 'range'">
|
||||||
{{::row.from | date:'dd/MM/yy'}} - {{::row.to | date:'dd/MM/yy'}}
|
{{::row.started | date:'dd/MM/yy'}} - {{::row.ended | date:'dd/MM/yy'}}
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="!row.to" translate>
|
<span ng-if="row.type == 'indefinitely'" translate>
|
||||||
Indefinitely
|
Indefinitely
|
||||||
</span>
|
</span>
|
||||||
<span ng-if="row.weekDays">
|
<span ng-if="row.weekDays">
|
||||||
|
@ -94,40 +94,40 @@
|
||||||
<vn-vertical>
|
<vn-vertical>
|
||||||
<vn-vertical class="vn-pb-md">
|
<vn-vertical class="vn-pb-md">
|
||||||
<vn-radio
|
<vn-radio
|
||||||
ng-model="$ctrl.eventType"
|
ng-model="$ctrl.selected.type"
|
||||||
label="One day"
|
label="One day"
|
||||||
val="day">
|
val="day">
|
||||||
</vn-radio>
|
</vn-radio>
|
||||||
<vn-radio
|
<vn-radio
|
||||||
ng-model="$ctrl.eventType"
|
ng-model="$ctrl.selected.type"
|
||||||
label="Indefinitely"
|
label="Indefinitely"
|
||||||
val="indefinitely">
|
val="indefinitely">
|
||||||
</vn-radio>
|
</vn-radio>
|
||||||
<vn-radio
|
<vn-radio
|
||||||
ng-model="$ctrl.eventType"
|
ng-model="$ctrl.selected.type"
|
||||||
label="Range of dates"
|
label="Range of dates"
|
||||||
val="range">
|
val="range">
|
||||||
</vn-radio>
|
</vn-radio>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
<vn-wday-picker
|
<vn-wday-picker
|
||||||
ng-if="$ctrl.eventType != 'day'"
|
ng-if="$ctrl.selected.type != 'day'"
|
||||||
ng-model="$ctrl.selected.wdays"
|
ng-model="$ctrl.selected.wdays"
|
||||||
class="vn-mt-sm vn-mb-md">
|
class="vn-mt-sm vn-mb-md">
|
||||||
</vn-wday-picker>
|
</vn-wday-picker>
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
ng-if="$ctrl.eventType == 'day'"
|
ng-if="$ctrl.selected.type == 'day'"
|
||||||
label="Day"
|
label="Day"
|
||||||
ng-model="$ctrl.selected.from">
|
ng-model="$ctrl.selected.dated">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
<vn-horizontal
|
<vn-horizontal
|
||||||
ng-if="$ctrl.eventType == 'range'">
|
ng-if="$ctrl.selected.type == 'range'">
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
label="From"
|
label="From"
|
||||||
ng-model="$ctrl.selected.from">
|
ng-model="$ctrl.selected.started">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
<vn-date-picker
|
<vn-date-picker
|
||||||
label="To"
|
label="To"
|
||||||
ng-model="$ctrl.selected.to">
|
ng-model="$ctrl.selected.ended">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-input-time
|
<vn-input-time
|
||||||
|
@ -162,7 +162,7 @@
|
||||||
</input>
|
</input>
|
||||||
<button
|
<button
|
||||||
ng-if="!$ctrl.isNew"
|
ng-if="!$ctrl.isNew"
|
||||||
response="DELETE"
|
response="delete"
|
||||||
translate>
|
translate>
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import Component from 'core/lib/component';
|
import Section from 'salix/components/section';
|
||||||
|
|
||||||
class Controller extends Component {
|
class Controller extends Section {
|
||||||
constructor($element, $, vnWeekDays) {
|
constructor($element, $, vnWeekDays) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.vnWeekDays = vnWeekDays;
|
this.vnWeekDays = vnWeekDays;
|
||||||
|
@ -27,13 +27,13 @@ class Controller extends Component {
|
||||||
formatWdays(weekDays) {
|
formatWdays(weekDays) {
|
||||||
if (!weekDays) return;
|
if (!weekDays) return;
|
||||||
|
|
||||||
let abrWdays = [];
|
let abrWdays = weekDays
|
||||||
for (let wday of weekDays.split(','))
|
.split(',')
|
||||||
abrWdays.push(this.vnWeekDays.map[wday].localeAbr);
|
.map(wday => this.vnWeekDays.map[wday].localeAbr);
|
||||||
|
|
||||||
return abrWdays.length < 7
|
return abrWdays.length < 7
|
||||||
? abrWdays.join(', ')
|
? abrWdays.join(', ')
|
||||||
: this._('Everyday');
|
: this.$t('Everyday');
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelection(days, type, weekday, data) {
|
onSelection(days, type, weekday, data) {
|
||||||
|
@ -66,37 +66,28 @@ class Controller extends Component {
|
||||||
|
|
||||||
edit(row) {
|
edit(row) {
|
||||||
this.isNew = false;
|
this.isNew = false;
|
||||||
|
|
||||||
if (row.from && !row.to)
|
|
||||||
this.eventType = 'day';
|
|
||||||
else if (!row.from)
|
|
||||||
this.eventType = 'indefinitely';
|
|
||||||
else
|
|
||||||
this.eventType = 'range';
|
|
||||||
|
|
||||||
this.selected = angular.copy(row);
|
this.selected = angular.copy(row);
|
||||||
this.selected.wdays = {};
|
this.selected.wdays = this.vnWeekDays.fromSet(row.weekDays);
|
||||||
|
|
||||||
if (row.weekDays) {
|
|
||||||
let weekDays = row.weekDays.split(',');
|
|
||||||
for (let day of weekDays)
|
|
||||||
this.selected.wdays[day] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$.dialog.show();
|
this.$.dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
create(days, type, weekday) {
|
create(days, type, weekday) {
|
||||||
this.isNew = true;
|
this.isNew = true;
|
||||||
this.eventType = type == 'day' ? 'day' : 'indefinitely';
|
|
||||||
|
|
||||||
if (type == 'weekday') {
|
if (type == 'weekday') {
|
||||||
let wdays = [];
|
let wdays = [];
|
||||||
let code = this.vnWeekDays.days[weekday].code;
|
wdays[weekday] = true;
|
||||||
wdays[code] = true;
|
|
||||||
this.selected = {wdays};
|
this.selected = {
|
||||||
} else
|
type: 'indefinitely',
|
||||||
this.selected = {from: days[0]};
|
wdays
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.selected = {
|
||||||
|
type: 'day',
|
||||||
|
dated: days[0]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
this.$.dialog.show();
|
this.$.dialog.show();
|
||||||
}
|
}
|
||||||
|
@ -105,24 +96,18 @@ class Controller extends Component {
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 'accept': {
|
case 'accept': {
|
||||||
let selected = this.selected;
|
let selected = this.selected;
|
||||||
|
let type = selected.type;
|
||||||
|
|
||||||
if (this.eventType == 'indefinitely') {
|
selected.weekDays = this.vnWeekDays.toSet(selected.wdays);
|
||||||
selected.from = null;
|
|
||||||
selected.to = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.eventType != 'day') {
|
if (type == 'day')
|
||||||
let weekDays = [];
|
|
||||||
|
|
||||||
for (let wday in selected.wdays) {
|
|
||||||
if (selected.wdays[wday])
|
|
||||||
weekDays.push(wday);
|
|
||||||
}
|
|
||||||
|
|
||||||
selected.weekDays = weekDays.join(',');
|
|
||||||
} else {
|
|
||||||
selected.to = null;
|
|
||||||
selected.weekDays = '';
|
selected.weekDays = '';
|
||||||
|
else
|
||||||
|
selected.dated = null;
|
||||||
|
|
||||||
|
if (type != 'range') {
|
||||||
|
selected.started = null;
|
||||||
|
selected.ended = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let req;
|
let req;
|
||||||
|
@ -138,7 +123,7 @@ class Controller extends Component {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'DELETE':
|
case 'delete':
|
||||||
return this.onDelete(this.selected.id)
|
return this.onDelete(this.selected.id)
|
||||||
.then(response => response == 'accept');
|
.then(response => response == 'accept');
|
||||||
}
|
}
|
||||||
|
@ -162,8 +147,8 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
exclusionCreate(days) {
|
exclusionCreate(days) {
|
||||||
let exclusions = days.map(day => {
|
let exclusions = days.map(dated => {
|
||||||
return {day};
|
return {dated};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$http.post(this.exclusionsPath, exclusions)
|
this.$http.post(this.exclusionsPath, exclusions)
|
||||||
|
|
Loading…
Reference in New Issue