Merge pull request '6456-refactor-ticketState' (!1911) from 6456-refactor-ticketState into test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1911 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
37a13414d1
|
@ -0,0 +1,81 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticketPositionInPath`(vTicketId INT)
|
||||
RETURNS varchar(10) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
|
||||
DECLARE vRestTicketsMaxOrder INT;
|
||||
DECLARE vRestTicketsMinOrder INT;
|
||||
DECLARE vRestTicketsPacking INT;
|
||||
DECLARE vMyProductionOrder INT;
|
||||
DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
|
||||
DECLARE vMyPath INT;
|
||||
DECLARE vMyWarehouse INT;
|
||||
DECLARE PACKING_ORDER INT;
|
||||
DECLARE vExpeditionsCount INT;
|
||||
DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
|
||||
|
||||
|
||||
|
||||
SELECT `order`
|
||||
INTO PACKING_ORDER
|
||||
FROM state
|
||||
WHERE code = 'PACKING';
|
||||
|
||||
SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
|
||||
INTO vMyPath, vMyWarehouse, vMyProductionOrder
|
||||
FROM ticket t
|
||||
LEFT JOIN ticketState ts on ts.ticketFk = t.id
|
||||
WHERE t.id = vTicketId;
|
||||
|
||||
SELECT (ag.`name` = 'VN_VALENCIA')
|
||||
INTO vIsValenciaPath
|
||||
FROM vn2008.Rutas r
|
||||
JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
|
||||
JOIN vn2008.agency ag on ag.agency_id = a.agency_id
|
||||
WHERE r.Id_Ruta = vMyPath;
|
||||
|
||||
IF vIsValenciaPath THEN -- Rutas Valencia
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO vExpeditionsCount
|
||||
FROM expedition e
|
||||
JOIN ticket t ON t.id = e.ticketFk
|
||||
WHERE t.routeFk = vMyPath;
|
||||
|
||||
SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
|
||||
INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
|
||||
FROM ticket t
|
||||
LEFT JOIN ticketState ts on t.id = ts.ticketFk
|
||||
WHERE t.routeFk = vMyPath
|
||||
AND t.warehouseFk = vMyWarehouse
|
||||
AND t.id != vTicketid;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO vRestTicketsPacking
|
||||
FROM ticket t
|
||||
LEFT JOIN ticketState ts on t.id = ts.ticketFk
|
||||
WHERE ts.productionOrder = PACKING_ORDER
|
||||
AND t.routeFk = vMyPath
|
||||
AND t.warehouseFk = vMyWarehouse
|
||||
AND t.id != vTicketid;
|
||||
|
||||
IF vExpeditionsCount = 1 THEN
|
||||
SET vPosition = 'FIRST';
|
||||
ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
|
||||
SET vPosition = 'LAST';
|
||||
ELSEIF vRestTicketsPacking THEN
|
||||
SET vPosition = 'SHARED';
|
||||
ELSE
|
||||
SET vPosition = 'MID';
|
||||
END IF;
|
||||
|
||||
ELSE
|
||||
SET vPosition = 'MID';
|
||||
|
||||
END IF;
|
||||
|
||||
RETURN vPosition;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`expedition_beforeInsert`
|
||||
BEFORE INSERT ON `expedition`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE intcounter INT;
|
||||
DECLARE vShipFk INT;
|
||||
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
|
||||
IF NEW.freightItemFk IS NOT NULL THEN
|
||||
|
||||
UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk;
|
||||
|
||||
SELECT IFNULL(MAX(counter),0) +1 INTO intcounter
|
||||
FROM expedition e
|
||||
INNER JOIN ticket t1 ON e.ticketFk = t1.id
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t1.id
|
||||
INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped)
|
||||
AND t1.warehouseFk = t2.warehouseFk
|
||||
WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk
|
||||
AND t1.agencyModeFk = t2.agencyModeFk;
|
||||
|
||||
SET NEW.`counter` = intcounter;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,58 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`expeditionRoute_freeTickets` AS
|
||||
SELECT
|
||||
`t`.`routeFk` AS `routeFk`,
|
||||
`tss`.`ticketFk` AS `ticket`,
|
||||
`s`.`name` AS `code`,
|
||||
`w`.`name` AS `almacen`,
|
||||
`tss`.`updated` AS `updated`,
|
||||
`p`.`code` AS `parkingCode`
|
||||
FROM `vn`.`ticketState` `tss`
|
||||
JOIN `vn`.`ticket` `t` ON `t`.`id` = `tss`.`ticketFk`
|
||||
JOIN `vn`.`warehouse` `w` ON `w`.`id` = `t`.`warehouseFk`
|
||||
JOIN `vn`.`state` `s` ON `s`.`id` = `tss`.`state`
|
||||
LEFT JOIN `vn`.`ticketParking` `tp` ON `tp`.`ticketFk` = `t`.`id`
|
||||
LEFT JOIN `vn`.`parking` `p` ON `p`.`id` = `tp`.`parkingFk`
|
||||
WHERE IFNULL(`t`.`packages`, 0) = 0;
|
||||
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`ticketState`
|
||||
AS SELECT `tt`.`created` AS `updated`,
|
||||
`tt`.`stateFk` AS `stateFk`,
|
||||
`tt`.`userFk` AS `userFk`,
|
||||
`tls`.`ticketFk` AS `ticketFk`,
|
||||
`s`.`id` AS `state`,
|
||||
`s`.`order` AS `productionOrder`,
|
||||
`s`.`alertLevel` AS `alertLevel`,
|
||||
`s`.`code` AS `code`,
|
||||
`s`.`isPreviousPreparable` AS `isPreviousPreparable`,
|
||||
`s`.`isPicked` AS `isPicked`
|
||||
FROM (
|
||||
(
|
||||
`vn`.`ticketLastState` `tls`
|
||||
JOIN `vn`.`ticketTracking` `tt` ON(`tt`.`id` = `tls`.`ticketTrackingFk`)
|
||||
)
|
||||
JOIN `vn`.`state` `s` ON(`s`.`id` = `tt`.`stateFk`)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`ticketStateToday`
|
||||
AS
|
||||
SELECT
|
||||
`ts`.`ticketFk` AS `ticket`,
|
||||
`ts`.`state` AS `state`,
|
||||
`ts`.`productionOrder` AS `productionOrder`,
|
||||
`ts`.`alertLevel` AS `alertLevel`,
|
||||
`ts`.`userFk` AS `worker`,
|
||||
`ts`.`code` AS `code`,
|
||||
`ts`.`updated` AS `updated`,
|
||||
`ts`.`isPicked` AS `isPicked`
|
||||
FROM
|
||||
`vn`.`ticketState` `ts`
|
||||
JOIN `vn`.`ticket` `t` ON `t`.`id` = `ts`.`ticketFk`
|
||||
WHERE
|
||||
`t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `util`.`VN_CURDATE`() + INTERVAL 1 DAY;
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
"user": {
|
||||
"type": "belongsTo",
|
||||
"model": "VnUser",
|
||||
"foreignKey": "workerFk"
|
||||
"foreignKey": "userFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue