Merge branch 'dev' into 8030-newPriceComponent
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
f7e13e8ac9
|
@ -38,7 +38,7 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'hasFile',
|
arg: 'hasFile',
|
||||||
type: 'Boolean',
|
type: 'Boolean',
|
||||||
description: 'True if has an attached file'
|
description: 'True if has the original in paper'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'hasFileAttached',
|
arg: 'hasFileAttached',
|
||||||
|
|
|
@ -2523,14 +2523,15 @@ INSERT INTO `vn`.`thermograph`(`id`, `model`)
|
||||||
('138350-0', 'DISPOSABLE');
|
('138350-0', 'DISPOSABLE');
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `result`, `dmsFk`)
|
INSERT INTO `vn`.`travelThermograph`
|
||||||
|
(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperatureFk`, `minTemperature`, `maxTemperature`, `result`, `dmsFk`)
|
||||||
VALUES
|
VALUES
|
||||||
('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', 'Ok', NULL),
|
('TMM190901395', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Ok', NULL),
|
||||||
('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL),
|
('TL.BBA85422', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', NULL, NULL, 'Ok', NULL),
|
||||||
('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL),
|
('TL.BBA85422', util.VN_CURDATE(), 2, 1, 'COOL', NULL, NULL, 'can not read the temperature', NULL),
|
||||||
('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5),
|
('TZ1905012010', util.VN_CURDATE(), 1, 1, 'WARM', NULL, NULL, 'Temperature in range', 5),
|
||||||
('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5),
|
('138350-0', DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', 2, 12, NULL, 5),
|
||||||
('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL);
|
('138350-0', util.VN_CURDATE(), 1, NULL, 'COOL', NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
REPLACE INTO `vn`.`incoterms`(`code`, `name`)
|
REPLACE INTO `vn`.`incoterms`(`code`, `name`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`clearShelvingList`(vShelvingFk VARCHAR(8))
|
|
||||||
BEGIN
|
|
||||||
UPDATE vn.itemShelving
|
|
||||||
SET visible = 0
|
|
||||||
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk COLLATE utf8_unicode_ci;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,5 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_new`(vUserFk INT, OUT vCollectionFk INT)
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`collection_new`(
|
||||||
|
vUserFk INT,
|
||||||
|
OUT vCollectionFk INT
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Genera colecciones de tickets sin asignar trabajador.
|
* Genera colecciones de tickets sin asignar trabajador.
|
||||||
|
@ -12,30 +15,29 @@ BEGIN
|
||||||
DECLARE vLinesLimit INT;
|
DECLARE vLinesLimit INT;
|
||||||
DECLARE vTicketLines INT;
|
DECLARE vTicketLines INT;
|
||||||
DECLARE vVolumeLimit DECIMAL;
|
DECLARE vVolumeLimit DECIMAL;
|
||||||
DECLARE vTicketVolume DECIMAL;
|
|
||||||
DECLARE vSizeLimit INT;
|
DECLARE vSizeLimit INT;
|
||||||
|
DECLARE vTicketVolume DECIMAL;
|
||||||
DECLARE vMaxTickets INT;
|
DECLARE vMaxTickets INT;
|
||||||
DECLARE vStateFk VARCHAR(45);
|
DECLARE vStateCode VARCHAR(45);
|
||||||
DECLARE vFirstTicketFk INT;
|
DECLARE vFirstTicketFk INT;
|
||||||
DECLARE vHour INT;
|
|
||||||
DECLARE vMinute INT;
|
|
||||||
DECLARE vWorkerCode VARCHAR(3);
|
DECLARE vWorkerCode VARCHAR(3);
|
||||||
DECLARE vWagonCounter INT DEFAULT 0;
|
DECLARE vWagonCounter INT DEFAULT 1;
|
||||||
DECLARE vTicketFk INT;
|
DECLARE vTicketFk INT;
|
||||||
DECLARE vItemPackingTypeFk VARCHAR(1);
|
DECLARE vItemPackingTypeFk VARCHAR(1);
|
||||||
DECLARE vHasAssignedTickets BOOLEAN;
|
DECLARE vHasAssignedTickets BOOL;
|
||||||
DECLARE vHasUniqueCollectionTime BOOL;
|
DECLARE vHasUniqueCollectionTime BOOL;
|
||||||
DECLARE vDone INT DEFAULT FALSE;
|
DECLARE vHeight INT;
|
||||||
DECLARE vLockName VARCHAR(215);
|
DECLARE vVolume INT;
|
||||||
DECLARE vLockTime INT DEFAULT 30;
|
DECLARE vLiters INT;
|
||||||
|
DECLARE vLines INT;
|
||||||
|
DECLARE vTotalLines INT DEFAULT 0;
|
||||||
|
DECLARE vTotalVolume INT DEFAULT 0;
|
||||||
DECLARE vFreeWagonFk INT;
|
DECLARE vFreeWagonFk INT;
|
||||||
DECLARE vErrorNumber INT;
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
DECLARE vErrorMsg TEXT;
|
|
||||||
|
|
||||||
DECLARE c1 CURSOR FOR
|
DECLARE vTickets CURSOR FOR
|
||||||
SELECT ticketFk, `lines`, m3
|
SELECT ticketFk, `lines`, m3
|
||||||
FROM tmp.productionBuffer
|
FROM tmp.productionBuffer
|
||||||
WHERE ticketFk <> vFirstTicketFk
|
|
||||||
ORDER BY HH,
|
ORDER BY HH,
|
||||||
mm,
|
mm,
|
||||||
productionOrder DESC,
|
productionOrder DESC,
|
||||||
|
@ -48,26 +50,6 @@ BEGIN
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
|
||||||
BEGIN
|
|
||||||
GET DIAGNOSTICS CONDITION 1
|
|
||||||
vErrorNumber = MYSQL_ERRNO,
|
|
||||||
vErrorMsg = MESSAGE_TEXT;
|
|
||||||
|
|
||||||
CALL util.debugAdd('collection_new', JSON_OBJECT(
|
|
||||||
'errorNumber', vErrorNumber,
|
|
||||||
'errorMsg', vErrorMsg,
|
|
||||||
'lockName', vLockName,
|
|
||||||
'userFk', vUserFk,
|
|
||||||
'ticketFk', vTicketFk
|
|
||||||
)); -- Tmp
|
|
||||||
|
|
||||||
IF vLockName IS NOT NULL THEN
|
|
||||||
DO RELEASE_LOCK(vLockName);
|
|
||||||
END IF;
|
|
||||||
RESIGNAL;
|
|
||||||
END;
|
|
||||||
|
|
||||||
SELECT pc.ticketTrolleyMax * o.numberOfWagons,
|
SELECT pc.ticketTrolleyMax * o.numberOfWagons,
|
||||||
pc.hasUniqueCollectionTime,
|
pc.hasUniqueCollectionTime,
|
||||||
w.code,
|
w.code,
|
||||||
|
@ -78,36 +60,26 @@ BEGIN
|
||||||
o.trainFk,
|
o.trainFk,
|
||||||
o.linesLimit,
|
o.linesLimit,
|
||||||
o.volumeLimit,
|
o.volumeLimit,
|
||||||
o.sizeLimit,
|
o.sizeLimit
|
||||||
pc.collection_new_lockname
|
|
||||||
INTO vMaxTickets,
|
INTO vMaxTickets,
|
||||||
vHasUniqueCollectionTime,
|
vHasUniqueCollectionTime,
|
||||||
vWorkerCode,
|
vWorkerCode,
|
||||||
vWarehouseFk,
|
vWarehouseFk,
|
||||||
vItemPackingTypeFk,
|
vItemPackingTypeFk,
|
||||||
vStateFk,
|
vStateCode,
|
||||||
vWagons,
|
vWagons,
|
||||||
vTrainFk,
|
vTrainFk,
|
||||||
vLinesLimit,
|
vLinesLimit,
|
||||||
vVolumeLimit,
|
vVolumeLimit,
|
||||||
vSizeLimit,
|
vSizeLimit
|
||||||
vLockName
|
FROM worker w
|
||||||
FROM productionConfig pc
|
JOIN operator o ON o.workerFk = w.id
|
||||||
JOIN worker w ON w.id = vUserFk
|
|
||||||
JOIN state st ON st.`code` = 'ON_PREPARATION'
|
JOIN state st ON st.`code` = 'ON_PREPARATION'
|
||||||
JOIN operator o ON o.workerFk = vUserFk;
|
JOIN productionConfig pc
|
||||||
|
WHERE w.id = vUserFk;
|
||||||
SET vLockName = CONCAT_WS('/',
|
|
||||||
vLockName,
|
|
||||||
vWarehouseFk,
|
|
||||||
vItemPackingTypeFk
|
|
||||||
);
|
|
||||||
|
|
||||||
IF NOT GET_LOCK(vLockName, vLockTime) THEN
|
|
||||||
CALL util.throw(CONCAT('Cannot get lock: ', vLockName));
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
-- Se prepara el tren, con tantos vagones como sea necesario.
|
-- Se prepara el tren, con tantos vagones como sea necesario.
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tTrain
|
CREATE OR REPLACE TEMPORARY TABLE tTrain
|
||||||
(wagon INT,
|
(wagon INT,
|
||||||
shelve INT,
|
shelve INT,
|
||||||
|
@ -118,59 +90,58 @@ BEGIN
|
||||||
PRIMARY KEY(wagon, shelve))
|
PRIMARY KEY(wagon, shelve))
|
||||||
ENGINE = MEMORY;
|
ENGINE = MEMORY;
|
||||||
|
|
||||||
WHILE vWagons > vWagonCounter DO
|
|
||||||
SET vWagonCounter = vWagonCounter + 1;
|
|
||||||
|
|
||||||
INSERT INTO tTrain (wagon, shelve, liters, `lines`, height)
|
INSERT INTO tTrain (wagon, shelve, liters, `lines`, height)
|
||||||
SELECT vWagonCounter, cv.`level` , cv.liters , cv.`lines` , cv.height
|
WITH RECURSIVE wagonSequence AS (
|
||||||
FROM collectionVolumetry cv
|
SELECT vWagonCounter wagon
|
||||||
WHERE cv.trainFk = vTrainFk
|
UNION ALL
|
||||||
|
SELECT wagon + 1 wagon
|
||||||
|
FROM wagonSequence
|
||||||
|
WHERE wagon < vWagonCounter + vWagons -1
|
||||||
|
)
|
||||||
|
SELECT ws.wagon, cv.`level`, cv.liters, cv.`lines`, cv.height
|
||||||
|
FROM wagonSequence ws
|
||||||
|
JOIN vn.collectionVolumetry cv ON cv.trainFk = vTrainFk
|
||||||
AND cv.itemPackingTypeFk = vItemPackingTypeFk;
|
AND cv.itemPackingTypeFk = vItemPackingTypeFk;
|
||||||
END WHILE;
|
|
||||||
|
|
||||||
-- Esto desaparecerá cuando tengamos la table cache.ticket
|
-- Esto desaparecerá cuando tengamos la table cache.ticket
|
||||||
|
|
||||||
CALL productionControl(vWarehouseFk, 0);
|
CALL productionControl(vWarehouseFk, 0);
|
||||||
|
|
||||||
ALTER TABLE tmp.productionBuffer
|
ALTER TABLE tmp.productionBuffer
|
||||||
ADD COLUMN liters INT,
|
ADD COLUMN liters INT,
|
||||||
ADD COLUMN height INT;
|
ADD COLUMN height INT;
|
||||||
|
|
||||||
-- Se obtiene nº de colección.
|
|
||||||
INSERT INTO collection
|
|
||||||
SET itemPackingTypeFk = vItemPackingTypeFk,
|
|
||||||
trainFk = vTrainFk,
|
|
||||||
wagons = vWagons,
|
|
||||||
warehouseFk = vWarehouseFk;
|
|
||||||
|
|
||||||
SELECT LAST_INSERT_ID() INTO vCollectionFk;
|
|
||||||
|
|
||||||
-- Los tickets de recogida en Algemesí sólo se sacan si están asignados.
|
-- Los tickets de recogida en Algemesí sólo se sacan si están asignados.
|
||||||
-- Los pedidos con riesgo no se sacan aunque se asignen.
|
-- Los pedidos con riesgo no se sacan aunque se asignen.
|
||||||
DELETE pb.*
|
|
||||||
|
DELETE pb
|
||||||
FROM tmp.productionBuffer pb
|
FROM tmp.productionBuffer pb
|
||||||
JOIN state s ON s.id = pb.state
|
JOIN state s ON s.id = pb.state
|
||||||
WHERE (pb.agency = 'REC_ALGEMESI'
|
WHERE (pb.agency = 'REC_ALGEMESI'
|
||||||
AND s.code <> 'PICKER_DESIGNED')
|
AND s.code <> 'PICKER_DESIGNED')
|
||||||
OR pb.problem LIKE '%RIESGO%';
|
OR pb.problem LIKE '%RIESGO%';
|
||||||
|
|
||||||
-- Comprobamos si hay tickets asignados. En ese caso, nos centramos
|
-- Si hay tickets asignados, nos centramos exclusivamente en esos tickets
|
||||||
-- exclusivamente en esos tickets y los sacamos independientemente
|
-- y los sacamos independientemente de problemas o tamaños
|
||||||
-- de problemas o tamaños
|
|
||||||
SELECT COUNT(*) INTO vHasAssignedTickets
|
SELECT EXISTS (
|
||||||
|
SELECT TRUE
|
||||||
FROM tmp.productionBuffer pb
|
FROM tmp.productionBuffer pb
|
||||||
JOIN state s ON s.id = pb.state
|
JOIN state s ON s.id = pb.state
|
||||||
WHERE s.code = 'PICKER_DESIGNED'
|
WHERE s.code = 'PICKER_DESIGNED'
|
||||||
AND pb.workerCode = vWorkerCode;
|
AND pb.workerCode = vWorkerCode
|
||||||
|
) INTO vHasAssignedTickets;
|
||||||
|
|
||||||
-- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados
|
-- Se dejan en la tabla tmp.productionBuffer sólo aquellos tickets adecuados
|
||||||
|
|
||||||
IF vHasAssignedTickets THEN
|
IF vHasAssignedTickets THEN
|
||||||
DELETE pb.*
|
DELETE pb
|
||||||
FROM tmp.productionBuffer pb
|
FROM tmp.productionBuffer pb
|
||||||
JOIN state s ON s.id = pb.state
|
JOIN state s ON s.id = pb.state
|
||||||
WHERE s.code <> 'PICKER_DESIGNED'
|
WHERE s.code <> 'PICKER_DESIGNED'
|
||||||
OR pb.workerCode <> vWorkerCode;
|
OR pb.workerCode <> vWorkerCode;
|
||||||
ELSE
|
ELSE
|
||||||
DELETE pb.*
|
DELETE pb
|
||||||
FROM tmp.productionBuffer pb
|
FROM tmp.productionBuffer pb
|
||||||
JOIN state s ON s.id = pb.state
|
JOIN state s ON s.id = pb.state
|
||||||
JOIN agencyMode am ON am.id = pb.agencyModeFk
|
JOIN agencyMode am ON am.id = pb.agencyModeFk
|
||||||
|
@ -193,24 +164,23 @@ BEGIN
|
||||||
OR (NOT pb.H AND pb.V > 0 AND vItemPackingTypeFk = 'H')
|
OR (NOT pb.H AND pb.V > 0 AND vItemPackingTypeFk = 'H')
|
||||||
OR (NOT pb.V AND vItemPackingTypeFk = 'V')
|
OR (NOT pb.V AND vItemPackingTypeFk = 'V')
|
||||||
OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking)
|
OR (pc.isPreviousPreparationRequired AND pb.previousWithoutParking)
|
||||||
OR LENGTH(pb.problem) > 0
|
OR LENGTH(pb.problem)
|
||||||
OR pb.lines > vLinesLimit
|
OR pb.lines > vLinesLimit
|
||||||
OR pb.m3 > vVolumeLimit
|
OR pb.m3 > vVolumeLimit
|
||||||
OR sub.maxSize > vSizeLimit
|
OR sub.maxSize > vSizeLimit
|
||||||
OR pb.hasPlantTray;
|
OR pb.hasPlantTray;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Es importante que el primer ticket se coja en todos los casos
|
-- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede
|
||||||
SELECT ticketFk,
|
|
||||||
HH,
|
IF vHasUniqueCollectionTime THEN
|
||||||
mm,
|
DELETE pb
|
||||||
`lines`,
|
FROM tmp.productionBuffer pb
|
||||||
m3
|
JOIN tmp.productionBuffer pb2 ON pb2.ticketFk = vFirstTicketFk
|
||||||
INTO vFirstTicketFk,
|
AND (pb.HH <> pb2.HH OR pb.mm <> pb2.mm);
|
||||||
vHour,
|
END IF;
|
||||||
vMinute,
|
|
||||||
vTicketLines,
|
SELECT ticketFk INTO vFirstTicketFk
|
||||||
vTicketVolume
|
|
||||||
FROM tmp.productionBuffer
|
FROM tmp.productionBuffer
|
||||||
ORDER BY HH,
|
ORDER BY HH,
|
||||||
mm,
|
mm,
|
||||||
|
@ -222,44 +192,37 @@ BEGIN
|
||||||
ticketFk
|
ticketFk
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
-- Hay que excluir aquellos que no tengan la misma hora de preparacion, si procede
|
OPEN vTickets;
|
||||||
IF vHasUniqueCollectionTime THEN
|
l: LOOP
|
||||||
DELETE FROM tmp.productionBuffer
|
SET vDone = FALSE;
|
||||||
WHERE HH <> vHour
|
FETCH vTickets INTO vTicketFk, vTicketLines, vTicketVolume;
|
||||||
OR mm <> vMinute;
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SET vTicketFk = vFirstTicketFk;
|
|
||||||
SET @lines = 0;
|
|
||||||
SET @volume = 0;
|
|
||||||
|
|
||||||
OPEN c1;
|
|
||||||
read_loop: LOOP
|
|
||||||
SET vDone = FALSE;
|
|
||||||
|
|
||||||
-- Buscamos un ticket que cumpla con los requisitos en el listado
|
-- Buscamos un ticket que cumpla con los requisitos en el listado
|
||||||
IF ((vTicketLines + @lines) <= vLinesLimit OR vLinesLimit IS NULL)
|
|
||||||
AND ((vTicketVolume + @volume) <= vVolumeLimit OR vVolumeLimit IS NULL) THEN
|
IF (vLinesLimit IS NULL OR (vTotalLines + vTicketLines) <= vLinesLimit)
|
||||||
|
AND (vVolumeLimit IS NULL OR (vTotalVolume + vTicketVolume) <= vVolumeLimit) THEN
|
||||||
|
|
||||||
CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk);
|
CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk);
|
||||||
DROP TEMPORARY TABLE tmp.ticketIPT;
|
DROP TEMPORARY TABLE tmp.ticketIPT;
|
||||||
|
|
||||||
UPDATE tmp.productionBuffer pb
|
SELECT COUNT(*), SUM(litros), MAX(i.`size`), SUM(sv.volume)
|
||||||
JOIN (
|
INTO vLines, vLiters, vHeight, vVolume
|
||||||
SELECT SUM(litros) liters,
|
|
||||||
@lines:= COUNT(*) + @lines,
|
|
||||||
COUNT(*) `lines`,
|
|
||||||
MAX(i.`size`) height,
|
|
||||||
@volume := SUM(sv.volume) + @volume,
|
|
||||||
SUM(sv.volume) volume
|
|
||||||
FROM saleVolume sv
|
FROM saleVolume sv
|
||||||
JOIN sale s ON s.id = sv.saleFk
|
JOIN sale s ON s.id = sv.saleFk
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
WHERE sv.ticketFk = vTicketFk
|
WHERE sv.ticketFk = vTicketFk;
|
||||||
) sub
|
|
||||||
SET pb.liters = sub.liters,
|
SET vTotalVolume = vTotalVolume + vVolume,
|
||||||
pb.`lines` = sub.`lines`,
|
vTotalLines = vTotalLines + vLines;
|
||||||
pb.height = sub.height
|
|
||||||
|
UPDATE tmp.productionBuffer pb
|
||||||
|
SET pb.liters = vLiters,
|
||||||
|
pb.`lines` = vLines,
|
||||||
|
pb.height = vHeight
|
||||||
WHERE pb.ticketFk = vTicketFk;
|
WHERE pb.ticketFk = vTicketFk;
|
||||||
|
|
||||||
UPDATE tTrain tt
|
UPDATE tTrain tt
|
||||||
|
@ -276,17 +239,13 @@ BEGIN
|
||||||
tt.height
|
tt.height
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
-- Si no le encuentra una balda adecuada, intentamos darle un carro entero si queda alguno libre
|
-- Si no le encuentra una balda, intentamos darle un carro entero libre
|
||||||
|
|
||||||
IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
IF NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
||||||
SELECT tt.wagon
|
SELECT wagon INTO vFreeWagonFk
|
||||||
INTO vFreeWagonFk
|
|
||||||
FROM tTrain tt
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT DISTINCT wagon
|
|
||||||
FROM tTrain
|
FROM tTrain
|
||||||
WHERE ticketFk IS NOT NULL
|
GROUP BY wagon
|
||||||
) nn ON nn.wagon = tt.wagon
|
HAVING COUNT(ticketFk) = 0
|
||||||
WHERE nn.wagon IS NULL
|
|
||||||
ORDER BY wagon
|
ORDER BY wagon
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
|
@ -295,38 +254,35 @@ BEGIN
|
||||||
SET ticketFk = vFirstTicketFk
|
SET ticketFk = vFirstTicketFk
|
||||||
WHERE wagon = vFreeWagonFk;
|
WHERE wagon = vFreeWagonFk;
|
||||||
|
|
||||||
-- Se anulan el resto de carros libres para que sólo uno lleve un pedido excesivo
|
-- Se anulan el resto de carros libres,
|
||||||
DELETE tt.*
|
-- máximo un carro con pedido excesivo
|
||||||
FROM tTrain tt
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT DISTINCT wagon
|
|
||||||
FROM tTrain
|
|
||||||
WHERE ticketFk IS NOT NULL
|
|
||||||
) nn ON nn.wagon = tt.wagon
|
|
||||||
WHERE nn.wagon IS NULL;
|
|
||||||
END IF;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume;
|
DELETE tt
|
||||||
IF vDone OR NOT (SELECT COUNT(*) FROM tTrain WHERE ticketFk IS NULL) THEN
|
FROM tTrain tt
|
||||||
LEAVE read_loop;
|
JOIN (SELECT wagon
|
||||||
|
FROM tTrain
|
||||||
|
GROUP BY wagon
|
||||||
|
HAVING COUNT(ticketFk) = 0
|
||||||
|
) sub ON sub.wagon = tt.wagon;
|
||||||
END IF;
|
END IF;
|
||||||
ELSE
|
|
||||||
FETCH c1 INTO vTicketFk, vTicketLines, vTicketVolume;
|
|
||||||
IF vDone THEN
|
|
||||||
LEAVE read_loop;
|
|
||||||
END IF;
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
CLOSE c1;
|
CLOSE vTickets;
|
||||||
|
|
||||||
IF (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
IF (SELECT COUNT(*) FROM tTrain WHERE ticketFk) THEN
|
||||||
UPDATE collection c
|
-- Se obtiene nº de colección
|
||||||
JOIN state st ON st.code = 'ON_PREPARATION'
|
|
||||||
SET c.stateFk = st.id
|
INSERT INTO collection
|
||||||
WHERE c.id = vCollectionFk;
|
SET itemPackingTypeFk = vItemPackingTypeFk,
|
||||||
|
trainFk = vTrainFk,
|
||||||
|
wagons = vWagons,
|
||||||
|
warehouseFk = vWarehouseFk;
|
||||||
|
|
||||||
|
SELECT LAST_INSERT_ID() INTO vCollectionFk;
|
||||||
|
|
||||||
-- Asigna las bandejas
|
-- Asigna las bandejas
|
||||||
|
|
||||||
INSERT IGNORE INTO ticketCollection(ticketFk, collectionFk, `level`, wagon, liters)
|
INSERT IGNORE INTO ticketCollection(ticketFk, collectionFk, `level`, wagon, liters)
|
||||||
SELECT tt.ticketFk, vCollectionFk, tt.shelve, tt.wagon, tt.liters
|
SELECT tt.ticketFk, vCollectionFk, tt.shelve, tt.wagon, tt.liters
|
||||||
FROM tTrain tt
|
FROM tTrain tt
|
||||||
|
@ -334,15 +290,17 @@ BEGIN
|
||||||
ORDER BY tt.wagon, tt.shelve;
|
ORDER BY tt.wagon, tt.shelve;
|
||||||
|
|
||||||
-- Actualiza el estado de los tickets
|
-- Actualiza el estado de los tickets
|
||||||
CALL collection_setState(vCollectionFk, vStateFk);
|
|
||||||
|
CALL collection_setState(vCollectionFk, vStateCode);
|
||||||
|
|
||||||
-- Aviso para la preparacion previa
|
-- Aviso para la preparacion previa
|
||||||
|
|
||||||
INSERT INTO ticketDown(ticketFk, collectionFk)
|
INSERT INTO ticketDown(ticketFk, collectionFk)
|
||||||
SELECT tc.ticketFk, tc.collectionFk
|
SELECT tc.ticketFk, tc.collectionFk
|
||||||
FROM ticketCollection tc
|
FROM ticketCollection tc
|
||||||
WHERE tc.collectionFk = vCollectionFk;
|
WHERE tc.collectionFk = vCollectionFk;
|
||||||
|
|
||||||
CALL sales_mergeByCollection(vCollectionFk);
|
CALL collection_mergeSales(vCollectionFk);
|
||||||
|
|
||||||
UPDATE `collection` c
|
UPDATE `collection` c
|
||||||
JOIN(
|
JOIN(
|
||||||
|
@ -356,15 +314,10 @@ BEGIN
|
||||||
SET c.saleTotalCount = sub.saleTotalCount,
|
SET c.saleTotalCount = sub.saleTotalCount,
|
||||||
c.salePickedCount = sub.salePickedCount
|
c.salePickedCount = sub.salePickedCount
|
||||||
WHERE c.id = vCollectionFk;
|
WHERE c.id = vCollectionFk;
|
||||||
|
|
||||||
ELSE
|
ELSE
|
||||||
DELETE FROM `collection`
|
|
||||||
WHERE id = vCollectionFk;
|
|
||||||
SET vCollectionFk = NULL;
|
SET vCollectionFk = NULL;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
DO RELEASE_LOCK(vLockName);
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tTrain,
|
tTrain,
|
||||||
tmp.productionBuffer;
|
tmp.productionBuffer;
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22))
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
DECLARE vItemFk INT;
|
|
||||||
|
|
||||||
SELECT vn.barcodeToItem(vBarcode) INTO vItemFk;
|
|
||||||
|
|
||||||
SELECT itemFk INTO vItemFk
|
|
||||||
FROM vn.buy b
|
|
||||||
WHERE b.id = vItemFk;
|
|
||||||
|
|
||||||
IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN
|
|
||||||
|
|
||||||
INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk);
|
|
||||||
INSERT INTO vn.shelving(`code`, parkingFk)
|
|
||||||
SELECT vShelvingFk, id
|
|
||||||
FROM vn.parking
|
|
||||||
WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
|
|
||||||
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
IF (SELECT COUNT(*) FROM vn.itemShelving
|
|
||||||
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
||||||
AND itemFk = vItemFk
|
|
||||||
AND packing = vPacking) = 1 THEN
|
|
||||||
|
|
||||||
UPDATE vn.itemShelving
|
|
||||||
SET visible = visible+vQuantity,
|
|
||||||
created = vCreated
|
|
||||||
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
|
||||||
AND itemFk = vItemFk
|
|
||||||
AND packing = vPacking;
|
|
||||||
|
|
||||||
ELSE
|
|
||||||
CALL cache.last_buy_refresh(FALSE);
|
|
||||||
INSERT INTO itemShelving( itemFk,
|
|
||||||
shelvingFk,
|
|
||||||
visible,
|
|
||||||
created,
|
|
||||||
`grouping`,
|
|
||||||
packing,
|
|
||||||
packagingFk)
|
|
||||||
SELECT vItemFk,
|
|
||||||
vShelvingFk,
|
|
||||||
vQuantity,
|
|
||||||
vCreated,
|
|
||||||
IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) `grouping`,
|
|
||||||
IF(vPacking = 0, b.packing, vPacking) packing,
|
|
||||||
IF(vPackagingFk = '', b.packagingFk, vPackagingFk) packaging
|
|
||||||
FROM vn.item i
|
|
||||||
LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
|
|
||||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
|
||||||
WHERE i.id = vItemFk;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -1,20 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT)
|
|
||||||
BEGIN
|
|
||||||
|
|
||||||
INSERT INTO vn.itemShelvingPlacementSupply( itemShelvingFk,
|
|
||||||
itemPlacementSupplyFk,
|
|
||||||
quantity,
|
|
||||||
userFk)
|
|
||||||
VALUES (vItemShelvingFk,
|
|
||||||
vItemPlacementSupplyFk,
|
|
||||||
vQuantity,
|
|
||||||
getUser());
|
|
||||||
|
|
||||||
UPDATE vn.itemShelving
|
|
||||||
SET visible = visible - vQuantity
|
|
||||||
WHERE id = vItemShelvingFk;
|
|
||||||
|
|
||||||
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -18,7 +18,8 @@ BEGIN
|
||||||
getUser());
|
getUser());
|
||||||
|
|
||||||
UPDATE itemShelving
|
UPDATE itemShelving
|
||||||
SET visible = visible - vQuantity
|
SET visible = visible - vQuantity,
|
||||||
|
available = available - vQuantity
|
||||||
WHERE id = vItemShelvingFk;
|
WHERE id = vItemShelvingFk;
|
||||||
|
|
||||||
UPDATE vn.saleTracking
|
UPDATE vn.saleTracking
|
||||||
|
|
|
@ -6,12 +6,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`itemShelving_selfCons
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Leave the indicated amount on the shelf
|
* Leave the indicated amount on the shelve
|
||||||
* and create a ticket with the difference.
|
* and create a ticket with the difference.
|
||||||
*
|
*
|
||||||
* @param vShelvingFk id of the shelf where the item is located.
|
* @param vShelvingFk id of the shelve where the item is located.
|
||||||
* @param vItemFk article of which the self-consumption ticket is to be created.
|
* @param vItemFk article of which the self-consumption ticket is to be created.
|
||||||
* @param vQuantity amount that will stay on the shelf
|
* @param vQuantity amount that will stay on the shelve
|
||||||
*/
|
*/
|
||||||
DECLARE vVisible INT;
|
DECLARE vVisible INT;
|
||||||
DECLARE vClientFk INT;
|
DECLARE vClientFk INT;
|
||||||
|
@ -80,7 +80,8 @@ BEGIN
|
||||||
WHERE id = vItemFk;
|
WHERE id = vItemFk;
|
||||||
|
|
||||||
UPDATE itemShelving
|
UPDATE itemShelving
|
||||||
SET visible = IF(id = vItemShelvingFk, vQuantity, 0)
|
SET visible = IF(id = vItemShelvingFk, vQuantity, 0),
|
||||||
|
available = IF(id = vItemShelvingFk, vQuantity, 0)
|
||||||
WHERE shelvingFk = vShelvingFk
|
WHERE shelvingFk = vShelvingFk
|
||||||
AND itemFk = vItemFk;
|
AND itemFk = vItemFk;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@ BEGIN
|
||||||
IF vNewItemShelvingFk THEN
|
IF vNewItemShelvingFk THEN
|
||||||
UPDATE itemShelving ish
|
UPDATE itemShelving ish
|
||||||
JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk
|
JOIN itemShelving ish2 ON ish2.id = vItemShelvingFk
|
||||||
SET ish.visible = ish.visible + ish2.visible
|
SET ish.visible = ish.visible + ish2.visible,
|
||||||
|
ish.available = ish.available + ish2.available
|
||||||
WHERE ish.id = vNewItemShelvingFk;
|
WHERE ish.id = vNewItemShelvingFk;
|
||||||
|
|
||||||
DELETE FROM itemShelving
|
DELETE FROM itemShelving
|
||||||
|
|
|
@ -303,7 +303,8 @@ BEGIN
|
||||||
WHERE id = vTargetItemShelvingFk;
|
WHERE id = vTargetItemShelvingFk;
|
||||||
ELSE
|
ELSE
|
||||||
UPDATE itemShelving
|
UPDATE itemShelving
|
||||||
SET visible = vCurrentVisible - vQuantity
|
SET visible = vCurrentVisible - vQuantity,
|
||||||
|
available = GREATEST(0, available - vQuantity)
|
||||||
WHERE id = vTargetItemShelvingFk;
|
WHERE id = vTargetItemShelvingFk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,11 @@ proc: BEGIN
|
||||||
DECLARE vEndingDate DATETIME;
|
DECLARE vEndingDate DATETIME;
|
||||||
DECLARE vIsTodayRelative BOOLEAN;
|
DECLARE vIsTodayRelative BOOLEAN;
|
||||||
|
|
||||||
SELECT util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, maxProductionScopeDays) DAY
|
SELECT w.isTodayRelative, util.dayEnd(util.VN_CURDATE()) + INTERVAL LEAST(vScopeDays, pc.maxProductionScopeDays) DAY
|
||||||
INTO vEndingDate
|
INTO vIsTodayRelative,vEndingDate
|
||||||
FROM productionConfig;
|
FROM worker w
|
||||||
|
JOIN productionConfig pc
|
||||||
SELECT isTodayRelative INTO vIsTodayRelative
|
WHERE w.id = account.myUser_getId();
|
||||||
FROM worker
|
|
||||||
WHERE id = getUser(); -- Cambiar por account.myUser_getId(), falta dar permisos
|
|
||||||
|
|
||||||
CALL prepareTicketList(util.yesterday(), vEndingDate);
|
CALL prepareTicketList(util.yesterday(), vEndingDate);
|
||||||
|
|
||||||
|
@ -272,7 +270,6 @@ proc: BEGIN
|
||||||
AND lb.item_id = s.itemFk
|
AND lb.item_id = s.itemFk
|
||||||
JOIN buy b ON b.id = lb.buy_id
|
JOIN buy b ON b.id = lb.buy_id
|
||||||
JOIN packaging p ON p.id = b.packagingFk
|
JOIN packaging p ON p.id = b.packagingFk
|
||||||
JOIN productionConfig pc
|
|
||||||
SET pb.hasPlantTray = TRUE
|
SET pb.hasPlantTray = TRUE
|
||||||
WHERE p.isPlantTray
|
WHERE p.isPlantTray
|
||||||
AND s.quantity >= b.packing
|
AND s.quantity >= b.packing
|
||||||
|
|
|
@ -3,12 +3,25 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_mergeSales`(
|
||||||
vSelf INT
|
vSelf INT
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Para un ticket se agrupa las diferentes líneas de venta de un mismo artículo en una sola
|
||||||
|
* siempre y cuando tengan el mismo precio y dto.
|
||||||
|
*
|
||||||
|
* @param vSelf Id de ticket
|
||||||
|
*/
|
||||||
|
DECLARE vHasSalesToMerge BOOL;
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
|
SELECT id INTO vSelf
|
||||||
|
FROM ticket
|
||||||
|
WHERE id = vSelf FOR UPDATE;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve
|
CREATE OR REPLACE TEMPORARY TABLE tSalesToPreserve
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -18,26 +31,24 @@ BEGIN
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
WHERE s.ticketFk = vSelf
|
WHERE s.ticketFk = vSelf
|
||||||
AND it.isMergeable
|
AND it.isMergeable
|
||||||
GROUP BY s.itemFk, s.price, s.discount;
|
GROUP BY s.itemFk, s.price, s.discount
|
||||||
|
HAVING COUNT(*) > 1;
|
||||||
|
|
||||||
START TRANSACTION;
|
SELECT COUNT(*) INTO vHasSalesToMerge FROM tSalesToPreserve;
|
||||||
|
|
||||||
|
IF vHasSalesToMerge THEN
|
||||||
UPDATE sale s
|
UPDATE sale s
|
||||||
JOIN tSalesToPreserve stp ON stp.id = s.id
|
JOIN tSalesToPreserve stp ON stp.id = s.id
|
||||||
SET s.quantity = newQuantity
|
SET s.quantity = newQuantity;
|
||||||
WHERE s.ticketFk = vSelf;
|
|
||||||
|
|
||||||
DELETE s.*
|
DELETE s
|
||||||
FROM sale s
|
FROM sale s
|
||||||
LEFT JOIN tSalesToPreserve stp ON stp.id = s.id
|
JOIN tSalesToPreserve stp ON stp.itemFk = s.itemFk
|
||||||
JOIN item i ON i.id = s.itemFk
|
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
|
||||||
WHERE s.ticketFk = vSelf
|
WHERE s.ticketFk = vSelf
|
||||||
AND stp.id IS NULL
|
AND s.id <> stp.id;
|
||||||
AND it.isMergeable;
|
END IF;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tSalesToPreserve;
|
DROP TEMPORARY TABLE tSalesToPreserve;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,83 +3,62 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_splitItemPacki
|
||||||
vSelf INT,
|
vSelf INT,
|
||||||
vOriginalItemPackingTypeFk VARCHAR(1)
|
vOriginalItemPackingTypeFk VARCHAR(1)
|
||||||
)
|
)
|
||||||
BEGIN
|
proc:BEGIN
|
||||||
/**
|
/**
|
||||||
* Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado.
|
* Clona y reparte las líneas de ventas de un ticket en funcion del tipo de empaquetado.
|
||||||
* Respeta el id inicial para el tipo propuesto.
|
* Respeta el id de ticket original para el tipo de empaquetado propuesto.
|
||||||
*
|
*
|
||||||
* @param vSelf Id ticket
|
* @param vSelf Id ticket
|
||||||
* @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original
|
* @param vOriginalItemPackingTypeFk Tipo empaquetado que se mantiene el ticket original
|
||||||
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
* @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
||||||
*/
|
*/
|
||||||
DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H';
|
|
||||||
DECLARE vNewTicketFk INT;
|
|
||||||
DECLARE vPackingTypesToSplit INT;
|
|
||||||
DECLARE vDone INT DEFAULT FALSE;
|
DECLARE vDone INT DEFAULT FALSE;
|
||||||
|
DECLARE vHasItemPackingType BOOL;
|
||||||
|
DECLARE vItemPackingTypeFk INT;
|
||||||
|
DECLARE vNewTicketFk INT;
|
||||||
|
|
||||||
DECLARE vSaleGroup CURSOR FOR
|
DECLARE vItemPackingTypes CURSOR FOR
|
||||||
SELECT itemPackingTypeFk
|
SELECT DISTINCT itemPackingTypeFk
|
||||||
FROM tSaleGroup
|
FROM tSalesToMove;
|
||||||
WHERE itemPackingTypeFk IS NOT NULL
|
|
||||||
ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC;
|
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
START TRANSACTION;
|
SELECT COUNT(*) INTO vHasItemPackingType
|
||||||
|
FROM ticket t
|
||||||
SELECT id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
FROM sale
|
|
||||||
WHERE ticketFk = vSelf
|
|
||||||
AND NOT quantity
|
|
||||||
FOR UPDATE;
|
|
||||||
|
|
||||||
DELETE FROM sale
|
|
||||||
WHERE NOT quantity
|
|
||||||
AND ticketFk = vSelf;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSale
|
|
||||||
(PRIMARY KEY (id))
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT s.id, i.itemPackingTypeFk, IFNULL(sv.litros, 0) litros
|
|
||||||
FROM sale s
|
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
LEFT JOIN saleVolume sv ON sv.saleFk = s.id
|
WHERE t.id = vSelf
|
||||||
WHERE s.ticketFk = vSelf;
|
AND i.itemPackingTypeFk = vOriginalItemPackingTypeFk;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSaleGroup
|
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT itemPackingTypeFk, SUM(litros) totalLitros
|
|
||||||
FROM tSale
|
|
||||||
GROUP BY itemPackingTypeFk;
|
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vPackingTypesToSplit
|
|
||||||
FROM tSaleGroup
|
|
||||||
WHERE itemPackingTypeFk IS NOT NULL;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT(
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT(
|
||||||
ticketFk INT,
|
ticketFk INT,
|
||||||
itemPackingTypeFk VARCHAR(1)
|
itemPackingTypeFk VARCHAR(1)
|
||||||
|
) ENGINE=MEMORY
|
||||||
|
SELECT vSelf ticketFk, vOriginalItemPackingTypeFk itemPackingTypeFk;
|
||||||
|
|
||||||
|
IF NOT vHasItemPackingType THEN
|
||||||
|
LEAVE proc;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tSalesToMove (
|
||||||
|
ticketFk INT,
|
||||||
|
saleFk INT,
|
||||||
|
itemPackingTypeFk INT
|
||||||
) ENGINE=MEMORY;
|
) ENGINE=MEMORY;
|
||||||
|
|
||||||
CASE vPackingTypesToSplit
|
INSERT INTO tSalesToMove (saleFk, itemPackingTypeFk)
|
||||||
WHEN 0 THEN
|
SELECT s.id, i.itemPackingTypeFk
|
||||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
FROM ticket t
|
||||||
VALUES(vSelf, vItemPackingTypeFk);
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
WHEN 1 THEN
|
JOIN item i ON i.id = s.itemFk
|
||||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
WHERE t.id = vSelf
|
||||||
SELECT vSelf, itemPackingTypeFk
|
AND i.itemPackingTypeFk <> vOriginalItemPackingTypeFk;
|
||||||
FROM tSaleGroup
|
|
||||||
WHERE itemPackingTypeFk IS NOT NULL;
|
|
||||||
ELSE
|
|
||||||
OPEN vSaleGroup;
|
|
||||||
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
|
||||||
|
|
||||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
OPEN vItemPackingTypes;
|
||||||
VALUES(vSelf, vItemPackingTypeFk);
|
|
||||||
|
|
||||||
l: LOOP
|
l: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
FETCH vSaleGroup INTO vItemPackingTypeFk;
|
FETCH vItemPackingTypes INTO vItemPackingTypeFk;
|
||||||
|
|
||||||
IF vDone THEN
|
IF vDone THEN
|
||||||
LEAVE l;
|
LEAVE l;
|
||||||
|
@ -87,40 +66,24 @@ BEGIN
|
||||||
|
|
||||||
CALL ticket_Clone(vSelf, vNewTicketFk);
|
CALL ticket_Clone(vSelf, vNewTicketFk);
|
||||||
|
|
||||||
INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk)
|
UPDATE tSalesToMove
|
||||||
VALUES(vNewTicketFk, vItemPackingTypeFk);
|
SET ticketFk = vNewTicketFk
|
||||||
|
WHERE itemPackingTypeFk = vItemPackingTypeFk;
|
||||||
|
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
CLOSE vSaleGroup;
|
CLOSE vItemPackingTypes;
|
||||||
|
|
||||||
SELECT s.id
|
|
||||||
FROM sale s
|
|
||||||
JOIN tSale ts ON ts.id = s.id
|
|
||||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
|
||||||
FOR UPDATE;
|
|
||||||
|
|
||||||
UPDATE sale s
|
UPDATE sale s
|
||||||
JOIN tSale ts ON ts.id = s.id
|
JOIN tSalesToMove stm ON stm.saleFk = s.id
|
||||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk
|
SET s.ticketFk = stm.ticketFk
|
||||||
SET s.ticketFk = t.ticketFk;
|
WHERE stm.ticketFk;
|
||||||
|
|
||||||
SELECT itemPackingTypeFk INTO vItemPackingTypeFk
|
INSERT INTO tmp.ticketIPT (ticketFk, itemPackingTypeFk)
|
||||||
FROM tSaleGroup sg
|
SELECT ticketFk, itemPackingTypeFk
|
||||||
WHERE sg.itemPackingTypeFk IS NOT NULL
|
FROM tSalesToMove
|
||||||
ORDER BY sg.itemPackingTypeFk
|
GROUP BY ticketFk;
|
||||||
LIMIT 1;
|
|
||||||
|
|
||||||
UPDATE sale s
|
DROP TEMPORARY TABLE tSalesToMove;
|
||||||
JOIN tSale ts ON ts.id = s.id
|
|
||||||
JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk
|
|
||||||
SET s.ticketFk = t.ticketFk
|
|
||||||
WHERE ts.itemPackingTypeFk IS NULL;
|
|
||||||
END CASE;
|
|
||||||
|
|
||||||
COMMIT;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
|
||||||
tSale,
|
|
||||||
tSaleGroup;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `vn`.`travelThermograph`
|
||||||
|
ADD COLUMN `maxTemperature` DECIMAL(5,2) NULL AFTER `temperatureFk`,
|
||||||
|
ADD COLUMN `minTemperature` DECIMAL(5,2) NULL AFTER `maxTemperature`;
|
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE `vn`.`travelThermograph` DROP FOREIGN KEY travelThermographDmsFgn;
|
||||||
|
ALTER TABLE `vn`.`travelThermograph` ADD CONSTRAINT travelThermographDmsFgn FOREIGN KEY (dmsFk) REFERENCES vn.dms(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE dipole.expedition_PrintOut DROP COLUMN IF EXISTS isChecked;
|
|
@ -1,64 +0,0 @@
|
||||||
import selectors from '../../helpers/selectors.js';
|
|
||||||
import getBrowser from '../../helpers/puppeteer';
|
|
||||||
|
|
||||||
describe('Travel thermograph path', () => {
|
|
||||||
const thermographName = '7H3-37H3RN4L-FL4M3';
|
|
||||||
let browser;
|
|
||||||
let page;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
|
||||||
browser = await getBrowser();
|
|
||||||
page = browser.page;
|
|
||||||
await page.loginAndModule('buyer', 'travel');
|
|
||||||
await page.write(selectors.travelIndex.generalSearchFilter, '3');
|
|
||||||
await page.keyboard.press('Enter');
|
|
||||||
await page.accessToSection('travel.card.thermograph.index');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(async() => {
|
|
||||||
await browser.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should reach the thermograph section', async() => {
|
|
||||||
await page.waitForState('travel.card.thermograph.index');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should click the add thermograph floating button', async() => {
|
|
||||||
await page.waitToClick(selectors.travelThermograph.add);
|
|
||||||
await page.waitForState('travel.card.thermograph.create');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should click on the add thermograph icon of the thermograph autocomplete', async() => {
|
|
||||||
await page.waitToClick(selectors.travelThermograph.addThermographIcon);
|
|
||||||
await page.write(selectors.travelThermograph.newThermographId, thermographName);
|
|
||||||
await page.autocompleteSearch(selectors.travelThermograph.newThermographModel, 'TEMPMATE');
|
|
||||||
await page.autocompleteSearch(selectors.travelThermograph.newThermographWarehouse, 'Warehouse Two');
|
|
||||||
await page.autocompleteSearch(selectors.travelThermograph.newThermographTemperature, 'Warm');
|
|
||||||
await page.waitToClick(selectors.travelThermograph.createThermographButton);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should select the file to upload', async() => {
|
|
||||||
let currentDir = process.cwd();
|
|
||||||
let filePath = `${currentDir}/e2e/assets/thermograph.jpeg`;
|
|
||||||
|
|
||||||
const [fileChooser] = await Promise.all([
|
|
||||||
page.waitForFileChooser(),
|
|
||||||
page.waitToClick(selectors.travelThermograph.uploadIcon)
|
|
||||||
]);
|
|
||||||
await fileChooser.accept([filePath]);
|
|
||||||
|
|
||||||
await page.waitToClick(selectors.travelThermograph.upload);
|
|
||||||
|
|
||||||
const message = await page.waitForSnackbar();
|
|
||||||
const state = await page.getState();
|
|
||||||
|
|
||||||
expect(message.text).toContain('Data saved!');
|
|
||||||
expect(state).toBe('travel.card.thermograph.index');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should check everything was saved correctly', async() => {
|
|
||||||
const result = await page.waitToGetProperty(selectors.travelThermograph.createdThermograph, 'innerText');
|
|
||||||
|
|
||||||
expect(result).toContain(thermographName);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -378,5 +378,6 @@
|
||||||
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
"The maximum height of the wagon is 200cm": "La altura máxima es 200cm",
|
||||||
"The entry does not have stickers": "La entrada no tiene etiquetas",
|
"The entry does not have stickers": "La entrada no tiene etiquetas",
|
||||||
"Too many records": "Demasiados registros",
|
"Too many records": "Demasiados registros",
|
||||||
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha"
|
"This buyer has already made a reservation for this date": "Este comprador ya ha hecho una reserva para esta fecha",
|
||||||
|
"No valid travel thermograph found": "No se encontró un termógrafo válido"
|
||||||
}
|
}
|
|
@ -360,6 +360,6 @@
|
||||||
"It was not able to create the invoice": "Não foi possível criar a fatura",
|
"It was not able to create the invoice": "Não foi possível criar a fatura",
|
||||||
"The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
|
"The invoices have been created but the PDFs could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
|
||||||
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso",
|
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso",
|
||||||
"Original invoice not found": "Fatura original não encontrada"
|
"Original invoice not found": "Fatura original não encontrada",
|
||||||
|
"Cannot send mail": "Não é possível enviar o email"
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ module.exports = Self => {
|
||||||
FROM ticketWeekly tw
|
FROM ticketWeekly tw
|
||||||
JOIN ticket t ON t.id = tw.ticketFk
|
JOIN ticket t ON t.id = tw.ticketFk
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
JOIN account.user u ON u.id = c.salesPersonFk
|
LEFT JOIN account.user u ON u.id = c.salesPersonFk
|
||||||
JOIN warehouse wh ON wh.id = t.warehouseFk
|
JOIN warehouse wh ON wh.id = t.warehouseFk
|
||||||
LEFT JOIN agencyMode am ON am.id = tw.agencyModeFk`
|
LEFT JOIN agencyMode am ON am.id = tw.agencyModeFk`
|
||||||
);
|
);
|
||||||
|
|
|
@ -76,7 +76,8 @@ module.exports = Self => {
|
||||||
{
|
{
|
||||||
arg: 'myTeam',
|
arg: 'myTeam',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: `Whether to show only tickets for the current logged user team (For now it shows only the current user tickets)`
|
description: `Whether to show only tickets for the current logged user team
|
||||||
|
(For now it shows only the current user tickets)`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'problems',
|
arg: 'problems',
|
||||||
|
@ -258,7 +259,8 @@ module.exports = Self => {
|
||||||
MINUTE(z.hour) zoneMinute,
|
MINUTE(z.hour) zoneMinute,
|
||||||
z.name zoneName,
|
z.name zoneName,
|
||||||
z.id zoneFk,
|
z.id zoneFk,
|
||||||
CAST(z.hour AS CHAR) hour
|
CAST(z.hour AS CHAR) hour,
|
||||||
|
a.nickname addressNickname
|
||||||
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
|
||||||
|
|
|
@ -56,14 +56,16 @@ module.exports = Self => {
|
||||||
model: model
|
model: model
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`
|
const travelThermograph = await models.TravelThermograph.create({
|
||||||
INSERT INTO travelThermograph(thermographFk, warehouseFk, temperatureFk, created)
|
thermographFk: thermograph.id,
|
||||||
VALUES (?, ?, ?, ?)
|
warehouseFk: warehouseId,
|
||||||
`, [thermograph.id, warehouseId, temperatureFk, date], myOptions);
|
temperatureFk: temperatureFk,
|
||||||
|
created: date
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return thermograph;
|
return travelThermograph;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -6,47 +6,42 @@ describe('Termograph createThermograph()', () => {
|
||||||
const temperatureFk = 'COOL';
|
const temperatureFk = 'COOL';
|
||||||
const warehouseId = 1;
|
const warehouseId = 1;
|
||||||
const ctx = beforeAll.getCtx();
|
const ctx = beforeAll.getCtx();
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
tx = await models.Thermograph.beginTransaction({});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
|
it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => {
|
||||||
const tx = await models.Thermograph.beginTransaction({});
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const createdThermograph = await models.Thermograph.createThermograph(
|
||||||
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
|
|
||||||
|
expect(createdThermograph.thermographFk).toEqual(thermographId);
|
||||||
|
|
||||||
|
const createdTravelThermograph =
|
||||||
|
await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
|
||||||
|
|
||||||
|
expect(createdTravelThermograph.warehouseFk).toEqual(warehouseId);
|
||||||
|
expect(createdTravelThermograph.temperatureFk).toEqual(temperatureFk);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should throw an error when trying to create a repeated thermograph`, async() => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const createdThermograph = await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
await models.Thermograph.createThermograph(
|
||||||
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
expect(createdThermograph.id).toEqual(thermographId);
|
await models.Thermograph.createThermograph(
|
||||||
expect(createdThermograph.model).toEqual(model);
|
ctx, thermographId, model, temperatureFk, warehouseId, options);
|
||||||
|
fail('Expected an error to be thrown when trying to create a repeated thermograph');
|
||||||
const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
|
|
||||||
|
|
||||||
expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId);
|
|
||||||
expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
expect(e.message).toBe('This thermograph id already exists');
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should throw an error when trying to created repeated thermograph`, async() => {
|
|
||||||
const tx = await models.Thermograph.beginTransaction({});
|
|
||||||
|
|
||||||
let error;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
|
||||||
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error.message).toBe('This thermograph id already exists');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,103 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('createThermograph', {
|
|
||||||
description: 'Creates a new travel thermograph',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The travel id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'thermographId',
|
|
||||||
type: 'string',
|
|
||||||
description: 'The thermograph id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'state',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'warehouseId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The warehouse id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'companyId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The company id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'dmsTypeId',
|
|
||||||
type: 'number',
|
|
||||||
description: 'The dms type id',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'reference',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'description',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'object',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/:id/createThermograph`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.createThermograph = async(ctx, id, thermographId, state, options) => {
|
|
||||||
const models = Self.app.models;
|
|
||||||
let tx;
|
|
||||||
const myOptions = {};
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const travelThermograph = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: null
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (!travelThermograph)
|
|
||||||
throw new UserError('No valid travel thermograph found');
|
|
||||||
|
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
|
||||||
const firstDms = uploadedFiles[0];
|
|
||||||
|
|
||||||
await travelThermograph.updateAttributes({
|
|
||||||
dmsFk: firstDms.id,
|
|
||||||
travelFk: id,
|
|
||||||
result: state
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
|
|
||||||
return travelThermograph;
|
|
||||||
} catch (err) {
|
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('saveThermograph', {
|
||||||
|
description: 'Creates or updates a travel thermograph',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The travel id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'travelThermographFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The travel thermograph id',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'state',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'maxTemperature',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The maximum temperature'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'minTemperature',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The minimum temperature'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'temperatureFk',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Range of temperature'
|
||||||
|
}, {
|
||||||
|
arg: 'warehouseId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The warehouse id'
|
||||||
|
}, {
|
||||||
|
arg: 'companyId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The company id'
|
||||||
|
}, {
|
||||||
|
arg: 'dmsTypeId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The dms type id'
|
||||||
|
}, {
|
||||||
|
arg: 'reference',
|
||||||
|
type: 'String'
|
||||||
|
}, {
|
||||||
|
arg: 'description',
|
||||||
|
type: 'String'
|
||||||
|
}, {
|
||||||
|
arg: 'hasFileAttached',
|
||||||
|
type: 'Boolean',
|
||||||
|
description: 'True if has an attached file'
|
||||||
|
}],
|
||||||
|
returns: {type: 'object', root: true},
|
||||||
|
http: {path: `/:id/saveThermograph`, verb: 'POST'}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.saveThermograph = async(
|
||||||
|
ctx,
|
||||||
|
id,
|
||||||
|
travelThermographFk,
|
||||||
|
state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk,
|
||||||
|
warehouseId,
|
||||||
|
companyId,
|
||||||
|
dmsTypeId,
|
||||||
|
reference,
|
||||||
|
description,
|
||||||
|
hasFileAttached,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
let tx;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
let dmsFk;
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const travelThermograph = await models.TravelThermograph.findById(
|
||||||
|
travelThermographFk,
|
||||||
|
{fields: ['id', 'dmsFk', 'warehouseFk']},
|
||||||
|
myOptions
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!travelThermograph)
|
||||||
|
throw new UserError('No valid travel thermograph found');
|
||||||
|
|
||||||
|
if (travelThermograph.dmsFk) {
|
||||||
|
await models.Dms.updateFile(ctx, travelThermograph.dmsFk, myOptions);
|
||||||
|
dmsFk = travelThermograph.dmsFk;
|
||||||
|
} else {
|
||||||
|
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
||||||
|
const firstDms = uploadedFiles[0];
|
||||||
|
dmsFk = firstDms.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
await travelThermograph.updateAttributes({
|
||||||
|
dmsFk,
|
||||||
|
travelFk: id,
|
||||||
|
result: state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return travelThermograph;
|
||||||
|
} catch (err) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,51 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('Travel createThermograph()', () => {
|
|
||||||
beforeAll.mockLoopBackContext();
|
|
||||||
const travelId = 3;
|
|
||||||
const currentUserId = 1102;
|
|
||||||
const thermographId = '138350-0';
|
|
||||||
const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}};
|
|
||||||
|
|
||||||
it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => {
|
|
||||||
const tx = await models.Travel.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
|
|
||||||
|
|
||||||
travelThermographBefore = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: null
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
await models.Travel.createThermograph(ctx, travelId, thermographId, options);
|
|
||||||
|
|
||||||
const travelThermographAfter = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: travelId
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
|
|
||||||
|
|
||||||
expect(travelThermographBefore).toBeDefined();
|
|
||||||
expect(travelThermographBefore.thermographFk).toEqual(thermographId);
|
|
||||||
expect(travelThermographBefore.travelFk).toBeNull();
|
|
||||||
expect(travelThermographAfter).toBeDefined();
|
|
||||||
|
|
||||||
expect(travelThermographAfter.thermographFk).toEqual(thermographId);
|
|
||||||
expect(travelThermographAfter.travelFk).toEqual(travelId);
|
|
||||||
expect(travelThermographAfter.dmsFk).toEqual(5);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('Thermograph saveThermograph()', () => {
|
||||||
|
const ctx = beforeAll.getCtx();
|
||||||
|
const travelFk = 1;
|
||||||
|
const thermographId = '138350-0';
|
||||||
|
const warehouseFk = '1';
|
||||||
|
const state = 'COMPLETED';
|
||||||
|
const maxTemperature = 30;
|
||||||
|
const minTemperature = 10;
|
||||||
|
const temperatureFk = 'COOL';
|
||||||
|
let tx;
|
||||||
|
let options;
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
options = {transaction: tx};
|
||||||
|
tx = await models.Sale.beginTransaction({});
|
||||||
|
options.transaction = tx;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update an existing travel thermograph', async() => {
|
||||||
|
const dmsFk = 5;
|
||||||
|
spyOn(models.Dms, 'uploadFile').and.returnValue([{id: dmsFk}]);
|
||||||
|
|
||||||
|
const travelThermograph = await models.TravelThermograph.create({
|
||||||
|
travelFk,
|
||||||
|
thermographFk: thermographId,
|
||||||
|
temperatureFk,
|
||||||
|
warehouseFk,
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
const updatedThermograph = await models.Travel.saveThermograph(
|
||||||
|
ctx,
|
||||||
|
travelFk,
|
||||||
|
travelThermograph.id,
|
||||||
|
state,
|
||||||
|
maxTemperature,
|
||||||
|
minTemperature,
|
||||||
|
temperatureFk,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null, options
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(updatedThermograph.result).toEqual(state);
|
||||||
|
expect(updatedThermograph.maxTemperature).toEqual(maxTemperature);
|
||||||
|
expect(updatedThermograph.minTemperature).toEqual(minTemperature);
|
||||||
|
expect(updatedThermograph.temperatureFk).toEqual(temperatureFk);
|
||||||
|
expect(updatedThermograph.dmsFk).toEqual(dmsFk);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if no valid travel thermograph is found', async() => {
|
||||||
|
try {
|
||||||
|
await models.Travel.saveThermograph(
|
||||||
|
ctx, null, 'notExists', state, maxTemperature, minTemperature, temperatureFk, options
|
||||||
|
);
|
||||||
|
fail('Expected an error to be thrown when no valid travel thermograph is found');
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toBe('No valid travel thermograph found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,83 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethodCtx('updateThermograph', {
|
|
||||||
description: 'Updates a travel thermograph',
|
|
||||||
accessType: 'WRITE',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'id',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The travel id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}, {
|
|
||||||
arg: 'thermographId',
|
|
||||||
type: 'String',
|
|
||||||
description: 'The thermograph id',
|
|
||||||
required: true
|
|
||||||
}, {
|
|
||||||
arg: 'state',
|
|
||||||
type: 'String',
|
|
||||||
required: true
|
|
||||||
}, {
|
|
||||||
arg: 'warehouseId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The warehouse id'
|
|
||||||
}, {
|
|
||||||
arg: 'companyId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The company id'
|
|
||||||
}, {
|
|
||||||
arg: 'dmsTypeId',
|
|
||||||
type: 'Number',
|
|
||||||
description: 'The dms type id'
|
|
||||||
}, {
|
|
||||||
arg: 'reference',
|
|
||||||
type: 'String'
|
|
||||||
}, {
|
|
||||||
arg: 'description',
|
|
||||||
type: 'String'
|
|
||||||
}, {
|
|
||||||
arg: 'hasFileAttached',
|
|
||||||
type: 'Boolean',
|
|
||||||
description: 'True if has an attached file'
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'Object',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/:id/updateThermograph`,
|
|
||||||
verb: 'POST'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.updateThermograph = async(ctx, id, thermographId, state) => {
|
|
||||||
const models = Self.app.models;
|
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const travelThermograph = await models.TravelThermograph.findOne({
|
|
||||||
where: {
|
|
||||||
thermographFk: thermographId,
|
|
||||||
travelFk: id
|
|
||||||
}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
if (!travelThermograph)
|
|
||||||
throw new UserError('No valid travel thermograph found');
|
|
||||||
|
|
||||||
const dmsFk = travelThermograph.dmsFk;
|
|
||||||
await models.Dms.updateFile(ctx, dmsFk, options);
|
|
||||||
await travelThermograph.updateAttributes({
|
|
||||||
result: state
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
await tx.commit();
|
|
||||||
return travelThermograph;
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -28,6 +28,14 @@
|
||||||
"warehouseFk": {
|
"warehouseFk": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
"maxTemperature": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Maximum temperature"
|
||||||
|
},
|
||||||
|
"minTemperature": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Minimum temperature"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -4,9 +4,8 @@ module.exports = Self => {
|
||||||
require('../methods/travel/getTravel')(Self);
|
require('../methods/travel/getTravel')(Self);
|
||||||
require('../methods/travel/getEntries')(Self);
|
require('../methods/travel/getEntries')(Self);
|
||||||
require('../methods/travel/filter')(Self);
|
require('../methods/travel/filter')(Self);
|
||||||
require('../methods/travel/createThermograph')(Self);
|
|
||||||
require('../methods/travel/deleteThermograph')(Self);
|
require('../methods/travel/deleteThermograph')(Self);
|
||||||
require('../methods/travel/updateThermograph')(Self);
|
require('../methods/travel/saveThermograph')(Self);
|
||||||
require('../methods/travel/extraCommunityFilter')(Self);
|
require('../methods/travel/extraCommunityFilter')(Self);
|
||||||
require('../methods/travel/getAverageDays')(Self);
|
require('../methods/travel/getAverageDays')(Self);
|
||||||
require('../methods/travel/cloneWithEntries')(Self);
|
require('../methods/travel/cloneWithEntries')(Self);
|
||||||
|
|
|
@ -87,7 +87,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `Travels/${this.travel.id}/createThermograph`;
|
const query = `Travels/${this.travel.id}/saveThermograph`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Controller extends Section {
|
||||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||||
const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`;
|
const path = `TravelThermographs/${this.$params.thermographId}?filter=${filter}`;
|
||||||
this.$http.get(path).then(res => {
|
this.$http.get(path).then(res => {
|
||||||
const thermograph = res.data && res.data;
|
const thermograph = res.data;
|
||||||
this.thermograph = {
|
this.thermograph = {
|
||||||
thermographId: thermograph.thermographFk,
|
thermographId: thermograph.thermographFk,
|
||||||
state: thermograph.result,
|
state: thermograph.result,
|
||||||
|
@ -51,7 +51,7 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `travels/${this.$params.id}/updateThermograph`;
|
const query = `travels/${this.$params.id}/saveThermograph`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
@ -62,8 +62,8 @@ class Controller extends Section {
|
||||||
transformRequest: files => {
|
transformRequest: files => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
for (let i = 0; i < files.length; i++)
|
for (const element of files)
|
||||||
formData.append(files[i].name, files[i]);
|
formData.append(element.name, element);
|
||||||
|
|
||||||
return formData;
|
return formData;
|
||||||
},
|
},
|
||||||
|
|
|
@ -109,7 +109,7 @@ describe('Worker', () => {
|
||||||
const files = [{id: 1, name: 'MyFile'}];
|
const files = [{id: 1, name: 'MyFile'}];
|
||||||
controller.thermograph = {files};
|
controller.thermograph = {files};
|
||||||
const serializedParams = $httpParamSerializer(controller.thermograph);
|
const serializedParams = $httpParamSerializer(controller.thermograph);
|
||||||
const query = `travels/${controller.$params.id}/updateThermograph?${serializedParams}`;
|
const query = `travels/${controller.$params.id}/saveThermograph?${serializedParams}`;
|
||||||
|
|
||||||
$httpBackend.expect('POST', query).respond({});
|
$httpBackend.expect('POST', query).respond({});
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
Loading…
Reference in New Issue