Compare commits
16 Commits
b453abdb3a
...
4383ebd7f1
Author | SHA1 | Date |
---|---|---|
Javier Segarra | 4383ebd7f1 | |
Javier Segarra | 5d156e81ca | |
Javier Segarra | a2329e1276 | |
Javier Segarra | 57b8b69ae9 | |
Guillermo Bonet | 31c1add02b | |
Guillermo Bonet | d52c82fb19 | |
Guillermo Bonet | b3d1c72adc | |
Guillermo Bonet | 5fdf18825c | |
Guillermo Bonet | b2b12adb3d | |
Guillermo Bonet | 61b2d4c5fd | |
Guillermo Bonet | badb4d69a2 | |
Guillermo Bonet | 8da36569f7 | |
Guillermo Bonet | 500eb22dc6 | |
Guillermo Bonet | 3d1c69be56 | |
Guillermo Bonet | 2f611391b9 | |
Guillermo Bonet | bfd6e1f398 |
|
@ -0,0 +1,73 @@
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterInsert`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterInsert`
|
||||||
|
AFTER INSERT ON `zoneIncluded`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO zoneLog
|
||||||
|
SET `action` = 'insert',
|
||||||
|
`changedModel` = 'zoneIncluded',
|
||||||
|
`changedModelId` = NEW.zoneFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
INSERT INTO zoneIncludedCheck
|
||||||
|
SET
|
||||||
|
`action`= 'insert',
|
||||||
|
`zoneFk` = NEW.zoneFk,
|
||||||
|
`geoFk` = NEW.geoFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
-- CALL `vn`.`zoneIncluded_checkCollisions`(NEW.zoneFk, NEW.geoFk);
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterUpdate`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterUpdate`
|
||||||
|
AFTER UPDATE ON `zoneIncluded`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO zoneLog
|
||||||
|
SET `action` = 'update',
|
||||||
|
`changedModel` = 'zoneIncluded',
|
||||||
|
`changedModelId` = OLD.zoneFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
INSERT INTO zoneIncludedCheck
|
||||||
|
SET
|
||||||
|
`action`= 'update',
|
||||||
|
`zoneFk` = NEW.zoneFk,
|
||||||
|
`geoFk` = NEW.geoFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
|
||||||
|
-- CALL `vn`.`zoneIncluded_checkCollisions`();
|
||||||
|
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`;
|
||||||
|
USE `vn`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
|
||||||
|
AFTER DELETE ON `zoneIncluded`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO zoneLog
|
||||||
|
SET `action` = 'delete',
|
||||||
|
`changedModel` = 'zoneIncluded',
|
||||||
|
`changedModelId` = OLD.zoneFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
INSERT INTO zoneIncludedCheck
|
||||||
|
SET
|
||||||
|
`action`= 'delete',
|
||||||
|
`zoneFk` = OLD.zoneFk,
|
||||||
|
`geoFk` = OLD.geoFk,
|
||||||
|
`userFk` = account.myUser_getId();
|
||||||
|
|
||||||
|
-- CALL `vn`.`zoneIncluded_checkCollisions`();
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,14 @@
|
||||||
|
CREATE TABLE `vn`.`zoneIncludedCheck` (
|
||||||
|
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`zoneFK` int(11) NOT NULL,
|
||||||
|
`geoFK` int(11) NOT NULL,
|
||||||
|
`userFK` int(10) unsigned NOT NULL,
|
||||||
|
`action`set('insert','update','delete') NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
CONSTRAINT `user_FK` FOREIGN KEY (`userFK`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT `zone_FK` FOREIGN KEY (`zoneFK`) REFERENCES `vn`.`zone` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
CONSTRAINT `geo_FK` FOREIGN KEY (`geoFK`) REFERENCES `vn`.`zoneGeo` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||||
|
UNIQUE INDEX (`zoneFK`, `geoFK`, `userFK`, `action`)
|
||||||
|
)
|
||||||
|
|
||||||
|
comment 'Table to save temporarily zone changes';
|
|
@ -0,0 +1,33 @@
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`;
|
||||||
|
DELIMITER $$
|
||||||
|
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`(IN zi_zone INT, IN zi_geo INT)
|
||||||
|
BEGIN
|
||||||
|
DECLARE done INT DEFAULT 0;
|
||||||
|
DECLARE zic_id, zic_zone, zic_geo, zic_action, zic_userFk INT;
|
||||||
|
DECLARE z_name VARCHAR(255);
|
||||||
|
DECLARE g_name VARCHAR(255);
|
||||||
|
|
||||||
|
DECLARE my_cur CURSOR FOR
|
||||||
|
SELECT zic.id, z.name , zg.name , zic.geoFk ,zic.`action` , zic.userFK FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id ;
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
|
||||||
|
|
||||||
|
OPEN my_cur;
|
||||||
|
my_cur_loop:
|
||||||
|
LOOP FETCH my_cur INTO zic_id, z_name,g_name, zic_geo, zic_action, zic_userFk ;
|
||||||
|
IF done = 1 THEN
|
||||||
|
select concat('NO REDCORDS' ) AS '** DEBUG:';
|
||||||
|
LEAVE my_cur_loop;
|
||||||
|
END IF;
|
||||||
|
SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_geo,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:';
|
||||||
|
DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id;
|
||||||
|
SELECT util.notification_send('zone-included',
|
||||||
|
JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name),
|
||||||
|
account.myUser_getId()
|
||||||
|
);
|
||||||
|
END LOOP my_cur_loop;
|
||||||
|
CLOSE my_cur;
|
||||||
|
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,11 @@
|
||||||
|
-- Auto-generated SQL script #202311241021
|
||||||
|
INSERT INTO util.notification (name,description)
|
||||||
|
VALUES ('zone-included','An email to notify zoneCollisions');
|
||||||
|
|
||||||
|
-- Auto-generated SQL script #202311241051
|
||||||
|
INSERT INTO util.notificationSubscription (notificationFk,userFk)
|
||||||
|
SELECT id, account.myUser_getId() FROM util.notification WHERE name= "zone-included"
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO util.notificationAcl (notificationFk,roleFk)
|
||||||
|
SELECT id, account.role FROM util.notification WHERE name= "zone-included"
|
|
@ -1,47 +0,0 @@
|
||||||
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterInsert`;
|
|
||||||
USE `vn`;
|
|
||||||
|
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterInsert`
|
|
||||||
AFTER INSERT ON `zoneIncluded`
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
INSERT INTO zoneLog
|
|
||||||
SET `action` = 'insert',
|
|
||||||
`changedModel` = 'zoneIncluded',
|
|
||||||
`changedModelId` = OLD.zoneFk,
|
|
||||||
`userFk` = account.myUser_getId();
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterUpdate`;
|
|
||||||
USE `vn`;
|
|
||||||
|
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterUpdate`
|
|
||||||
AFTER UPDATE ON `zoneIncluded`
|
|
||||||
FOR EACH ROW
|
|
||||||
BEGIN
|
|
||||||
INSERT INTO zoneLog
|
|
||||||
SET `action` = 'update',
|
|
||||||
`changedModel` = 'zoneIncluded',
|
|
||||||
`changedModelId` = OLD.zoneFk,
|
|
||||||
`userFk` = account.myUser_getId();
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
||||||
|
|
||||||
-- DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`;
|
|
||||||
-- USE `vn`;
|
|
||||||
|
|
||||||
-- DELIMITER $$
|
|
||||||
-- CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
|
|
||||||
-- AFTER DELETE ON `zoneIncluded`
|
|
||||||
-- FOR EACH ROW
|
|
||||||
-- BEGIN
|
|
||||||
-- INSERT INTO zoneLog
|
|
||||||
-- SET `action` = 'delete',
|
|
||||||
-- `changedModel` = 'zoneIncluded',
|
|
||||||
-- `changedModelId` = OLD.zoneFk,
|
|
||||||
-- `userFk` = account.myUser_getId();
|
|
||||||
-- END$$
|
|
||||||
-- DELIMITER ;
|
|
|
@ -1,7 +0,0 @@
|
||||||
CREATE TABLE `vn`.`zoneIncludedCheck` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`zoneFK` int(11) NOT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY (`inclusion_FK`,`zoneFK`),
|
|
||||||
CONSTRAINT `inclusion_FK` FOREIGN KEY (`zoneFK`) REFERENCES `zoneIncluded` (`id`) ON UPDATE CASCADE,
|
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`()
|
||||||
|
BEGIN
|
||||||
|
-- DROP TEMPORARY TABLE IF EXISTS tmp.toCheck;
|
||||||
|
DECLARE vZonesToCheck INT;
|
||||||
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
|
DECLARE vZoneFk INT;
|
||||||
|
DECLARE vCounter INT;
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -83201,7 +83201,7 @@ USE `vn`;
|
||||||
/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
|
/*!50001 SET collation_connection = utf8mb4_unicode_ci */;
|
||||||
/*!50001 CREATE ALGORITHM=UNDEFINED */
|
/*!50001 CREATE ALGORITHM=UNDEFINED */
|
||||||
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
|
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */
|
||||||
/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,cast(`util`.`VN_CURDATE`() + interval hour(ifnull(`zc`.`hour`,`z`.`hour`)) * 60 + minute(ifnull(`zc`.`hour`,`z`.`hour`)) minute as time) AS `hourTheoretical`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `totalVolume`,cast(sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) as decimal(5,1)) AS `remainingVolume`,greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) AS `speed`,cast(`zc`.`hour` + interval -sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) minute as time) AS `hourEffective`,floor(-sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) AS `minutesLess`,cast(`zc`.`hour` + interval -sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) minute as time) AS `etc` from (((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on(`tst`.`ticket` = `t`.`id`)) join `vn`.`state` `s` on(`s`.`id` = `tst`.`state`)) join `vn`.`saleVolume` `sv` on(`sv`.`ticketFk` = `t`.`id`)) left join `vn`.`lastHourProduction` `lhp` on(`lhp`.`warehouseFk` = `t`.`warehouseFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `vn`.`warehouseAlias` `wa` on(`wa`.`id` = `w`.`aliasFk`)) straight_join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`zoneClosure` `zc` on(`zc`.`zoneFk` = `t`.`zoneFk` and `zc`.`dated` = `util`.`VN_CURDATE`())) left join `cache`.`departure_limit` `dl` on(`dl`.`warehouse_id` = `t`.`warehouseFk` and `dl`.`fecha` = `util`.`VN_CURDATE`())) where `w`.`hasProduction` <> 0 and cast(`t`.`shipped` as date) = `util`.`VN_CURDATE`() group by `t`.`zoneFk` */;
|
/*!50001 VIEW `zoneEstimatedDelivery` AS SELECT `t`.`zoneFk` AS `zoneFk`, `zc`.`hour` AS `zoneClosureHour`, `z`.`hour` AS `zoneHour`, `sv`.`volume` AS `volume`, `al`.`hasToRecalcPrice` AS `hasToRecalcPrice`, `lhp`.`m3` AS `m3`, `dl`.`minSpeed` AS `minSpeed` FROM ((((((((((`vn`.`ticket` `t` JOIN `vn`.`ticketStateToday` `tst` ON (`tst`.`ticket` = `t`.`id`)) JOIN `vn`.`state` `s` ON (`s`.`id` = `tst`.`state`)) JOIN `vn`.`saleVolume` `sv` ON (`sv`.`ticketFk` = `t`.`id`)) LEFT JOIN `vn`.`lastHourProduction` `lhp` ON (`lhp`.`warehouseFk` = `t`.`warehouseFk`)) JOIN `vn`.`warehouse` `w` ON (`w`.`id` = `t`.`warehouseFk`)) JOIN `vn`.`warehouseAlias` `wa` ON (`wa`.`id` = `w`.`aliasFk`)) STRAIGHT_JOIN `vn`.`zone` `z` ON (`z`.`id` = `t`.`zoneFk`)) LEFT JOIN `vn`.`zoneClosure` `zc` ON (`zc`.`zoneFk` = `t`.`zoneFk` AND `zc`.`dated` = `util`.`VN_CURDATE`())) LEFT JOIN `cache`.`departure_limit` `dl` ON (`dl`.`warehouse_id` = `t`.`warehouseFk` AND `dl`.`fecha` = `util`.`VN_CURDATE`())) JOIN `vn`.`alertLevel` `al` ON (`al`.`id` = `s`.`alertLevel`)) WHERE `w`.`hasProduction` <> 0 AND CAST(`t`.`shipped` AS date) = `util`.`VN_CURDATE`() */;
|
||||||
/*!50001 SET character_set_client = @saved_cs_client */;
|
/*!50001 SET character_set_client = @saved_cs_client */;
|
||||||
/*!50001 SET character_set_results = @saved_cs_results */;
|
/*!50001 SET character_set_results = @saved_cs_results */;
|
||||||
/*!50001 SET collation_connection = @saved_col_connection */;
|
/*!50001 SET collation_connection = @saved_col_connection */;
|
||||||
|
|
|
@ -162,61 +162,69 @@ module.exports = Self => {
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
|
||||||
|
|
||||||
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
|
stmts.push(`SET @_optimizer_search_depth = @@optimizer_search_depth`);
|
||||||
stmts.push(`SET SESSION optimizer_search_depth = 0`);
|
stmts.push(`SET SESSION optimizer_search_depth = 0`);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(`
|
||||||
`CREATE TEMPORARY TABLE tmp.filter
|
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT
|
SELECT t.id,
|
||||||
t.id,
|
t.shipped,
|
||||||
t.shipped,
|
CAST(DATE(t.shipped) AS CHAR) shippedDate,
|
||||||
CAST(DATE(t.shipped) AS CHAR) AS shippedDate,
|
t.nickname,
|
||||||
t.nickname,
|
t.refFk,
|
||||||
t.refFk,
|
t.routeFk,
|
||||||
t.routeFk,
|
t.warehouseFk,
|
||||||
t.warehouseFk,
|
t.clientFk,
|
||||||
t.clientFk,
|
t.totalWithoutVat,
|
||||||
t.totalWithoutVat,
|
t.totalWithVat,
|
||||||
t.totalWithVat,
|
io.id invoiceOutId,
|
||||||
io.id AS invoiceOutId,
|
a.provinceFk,
|
||||||
a.provinceFk,
|
p.name province,
|
||||||
p.name AS province,
|
w.name warehouse,
|
||||||
w.name AS warehouse,
|
am.name agencyMode,
|
||||||
am.name AS agencyMode,
|
am.id agencyModeFk,
|
||||||
am.id AS agencyModeFk,
|
st.name state,
|
||||||
st.name AS state,
|
wk.lastName salesPerson,
|
||||||
wk.lastName AS salesPerson,
|
ts.stateFk stateFk,
|
||||||
ts.stateFk AS stateFk,
|
ts.alertLevel alertLevel,
|
||||||
ts.alertLevel AS alertLevel,
|
ts.code alertLevelCode,
|
||||||
ts.code AS alertLevelCode,
|
u.name userName,
|
||||||
u.name AS userName,
|
c.salesPersonFk,
|
||||||
c.salesPersonFk,
|
c.credit,
|
||||||
c.credit,
|
z.hour zoneLanding,
|
||||||
z.hour AS zoneLanding,
|
z.name zoneName,
|
||||||
z.name AS zoneName,
|
z.id zoneFk,
|
||||||
z.id AS zoneFk,
|
st.classColor,
|
||||||
st.classColor,
|
TIME_FORMAT(t.shipped, '%H:%i') preparationHour,
|
||||||
TIME_FORMAT(t.shipped, '%H:%i') AS preparationHour,
|
TIME_FORMAT(z.hour, '%H:%i') theoreticalhour,
|
||||||
TIME_FORMAT(z.hour, '%H:%i') AS theoreticalhour,
|
TIME_FORMAT(zed.etc, '%H:%i') practicalHour
|
||||||
TIME_FORMAT(zed.etc, '%H:%i') AS practicalHour
|
FROM ticket t
|
||||||
FROM ticket t
|
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
||||||
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
LEFT JOIN zone z ON z.id = t.zoneFk
|
LEFT JOIN address a ON a.id = t.addressFk
|
||||||
LEFT JOIN address a ON a.id = t.addressFk
|
LEFT JOIN province p ON p.id = a.provinceFk
|
||||||
LEFT JOIN province p ON p.id = a.provinceFk
|
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
LEFT JOIN state st ON st.id = ts.stateFk
|
||||||
LEFT JOIN state st ON st.id = ts.stateFk
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
LEFT JOIN account.user u ON u.id = wk.id
|
||||||
LEFT JOIN account.user u ON u.id = wk.id
|
LEFT JOIN (
|
||||||
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
|
SELECT zoneFk,
|
||||||
|
CAST(
|
||||||
|
IFNULL(zoneClosureHour, zoneHour) +
|
||||||
|
SUM(IF(hasToRecalcPrice, volume, 0)) * 60 /
|
||||||
|
GREATEST(IFNULL(m3, 0), IFNULL(minSpeed, 0))
|
||||||
|
AS time
|
||||||
|
) etc
|
||||||
|
FROM zoneEstimatedDelivery
|
||||||
|
GROUP BY zoneFk
|
||||||
|
) zed ON zed.zoneFk = t.zoneFk
|
||||||
|
`);
|
||||||
|
|
||||||
if (args.orderFk) {
|
if (args.orderFk) {
|
||||||
stmt.merge({
|
stmt.merge({
|
||||||
|
|
|
@ -140,40 +140,56 @@ module.exports = Self => {
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(`
|
||||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
(INDEX (id))
|
(INDEX (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT
|
SELECT o.id,
|
||||||
o.id,
|
o.total,
|
||||||
o.total,
|
o.date_send landed,
|
||||||
o.date_send landed,
|
o.date_make created,
|
||||||
o.date_make created,
|
o.customer_id clientFk,
|
||||||
o.customer_id clientFk,
|
o.agency_id agencyModeFk,
|
||||||
o.agency_id agencyModeFk,
|
o.address_id addressFk,
|
||||||
o.address_id addressFk,
|
o.company_id companyFk,
|
||||||
o.company_id companyFk,
|
o.source_app sourceApp,
|
||||||
o.source_app sourceApp,
|
o.confirmed isConfirmed,
|
||||||
o.confirmed isConfirmed,
|
c.name clientName,
|
||||||
c.name clientName,
|
c.salesPersonFk,
|
||||||
c.salesPersonFk,
|
u.nickname workerNickname,
|
||||||
u.nickname workerNickname,
|
u.name name,
|
||||||
u.name name,
|
co.code companyCode,
|
||||||
co.code companyCode,
|
zed.zoneFk,
|
||||||
zed.zoneFk,
|
zed.hourTheoretical,
|
||||||
zed.hourTheoretical,
|
zed.hourEffective,
|
||||||
zed.hourEffective,
|
am.name agencyName
|
||||||
am.name AS agencyName
|
FROM hedera.order o
|
||||||
FROM hedera.order o
|
LEFT JOIN address a ON a.id = o.address_id
|
||||||
LEFT JOIN address a ON a.id = o.address_id
|
LEFT JOIN agencyMode am ON am.id = o.agency_id
|
||||||
LEFT JOIN agencyMode am ON am.id = o.agency_id
|
LEFT JOIN client c ON c.id = o.customer_id
|
||||||
LEFT JOIN client c ON c.id = o.customer_id
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
LEFT JOIN account.user u ON u.id = wk.id
|
||||||
LEFT JOIN account.user u ON u.id = wk.id
|
LEFT JOIN company co ON co.id = o.company_id
|
||||||
LEFT JOIN company co ON co.id = o.company_id
|
LEFT JOIN orderTicket ot ON ot.orderFk = o.id
|
||||||
LEFT JOIN orderTicket ot ON ot.orderFk = o.id
|
LEFT JOIN ticket t ON t.id = ot.ticketFk
|
||||||
LEFT JOIN ticket t ON t.id = ot.ticketFk
|
LEFT JOIN (
|
||||||
LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`);
|
SELECT zoneFk,
|
||||||
|
CAST(
|
||||||
|
util.VN_CURDATE() +
|
||||||
|
INTERVAL HOUR(IFNULL(zoneClosureHour, zoneHour)) * 60 +
|
||||||
|
MINUTE(IFNULL(zoneClosureHour, zoneHour)) MINUTE
|
||||||
|
AS time
|
||||||
|
) hourTheoretical,
|
||||||
|
CAST(
|
||||||
|
IFNULL(zoneClosureHour, zoneHour) +
|
||||||
|
SUM(IF(hasToRecalcPrice, volume, 0)) * 60 /
|
||||||
|
GREATEST(IFNULL(m3, 0), IFNULL(minSpeed, 0))
|
||||||
|
AS time
|
||||||
|
) hourEffective
|
||||||
|
FROM zoneEstimatedDelivery
|
||||||
|
GROUP BY zoneFk
|
||||||
|
) zed ON zed.zoneFk = t.zoneFk
|
||||||
|
`);
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
stmt.merge(`GROUP BY id`);
|
stmt.merge(`GROUP BY id`);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
let conn = null;
|
||||||
describe('zone toggleIsIncluded()', () => {
|
describe('zone toggleIsIncluded()', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
|
conn = await models.Item.dataSource.connector;
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: 9},
|
accessToken: {userId: 9},
|
||||||
http: {
|
http: {
|
||||||
|
@ -16,15 +17,23 @@ describe('zone toggleIsIncluded()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the created location with isIncluded true', async() => {
|
fit('should return the created location with isIncluded true', async() => {
|
||||||
const tx = await models.Zone.beginTransaction({});
|
const tx = await models.Zone.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let toCheck = await conn.executeStmt({sql: ' SELECT * FROM zoneIncludedCheck'});
|
||||||
|
|
||||||
|
expect(toCheck.length).toEqual(0);
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
let result = await models.Zone.toggleIsIncluded(1, 20, true, options);
|
let result = await models.Zone.toggleIsIncluded(1, 20, true, options);
|
||||||
|
|
||||||
expect(result.isIncluded).toBeTrue();
|
expect(result.isIncluded).toBeTrue();
|
||||||
|
toCheck = await conn.executeStmt({sql: ' SELECT * FROM zoneIncludedCheck'});
|
||||||
|
|
||||||
|
expect(toCheck.length).not.toEqual(1);
|
||||||
|
|
||||||
|
await conn.executeStmt({sql: 'CALL vn.zoneIncluded_checkCollisions(?, ? )', params: [0, 0]});
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -11,28 +11,24 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"hourTheoretical": {
|
"zoneClosureHour": {
|
||||||
"type": "date"
|
"type": "date"
|
||||||
},
|
},
|
||||||
"totalVolume": {
|
"zoneHour": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"volume": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"remainingVolume": {
|
"hasToRecalcPrice": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"m3": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
"speed": {
|
"minSpeed": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
|
||||||
"hourEffective": {
|
|
||||||
"type": "date"
|
|
||||||
},
|
|
||||||
"minutesLess": {
|
|
||||||
"type": "date"
|
|
||||||
},
|
|
||||||
"etc": {
|
|
||||||
"type": "date"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"zone": {
|
"zone": {
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
subject: Colisión de zona detectada
|
subject: Colisión de zona detectada
|
||||||
title: "La zona {0} ha sido registrada en más de un sitio"
|
title: "La zona {0} y localización {1} ha sido registrada en más de un sitio"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div class="grid-row">
|
<div class="grid-row">
|
||||||
<div class="grid-block vn-pa-ml">
|
<div class="grid-block vn-pa-ml">
|
||||||
<h1>{{ $t('subject') }}</h1>
|
<h1>{{ $t('subject') }}</h1>
|
||||||
<p>{{ $t('title', [this.zoneIncluded.name]) }}</p>
|
<p>{{ $t('title', [zoneSelected,geoSelected]) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</email-body>
|
</email-body>
|
||||||
|
|
|
@ -3,23 +3,15 @@ const emailBody = new Component('email-body');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'zone-included',
|
name: 'zone-included',
|
||||||
async serverPrefetch() {
|
|
||||||
this.zoneIncluded = await this.fetchZoneIncluded(this.id);
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
fetchZoneIncluded(id) {
|
|
||||||
return this.findOneFromDef('zoneIncluded', [id]);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
components: {
|
components: {
|
||||||
'email-body': emailBody.build(),
|
'email-body': emailBody.build(),
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
id: {
|
zoneSelected: {
|
||||||
type: Number,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
url: {
|
geoSelected: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue