Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 7323-fineTunningWorker
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-09-26 09:17:14 +02:00
commit f62d11dab2
52 changed files with 566 additions and 511 deletions

View File

@ -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',

View File

@ -1506,7 +1506,8 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO
(7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7),
(8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10),
(10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10), (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10),
(11, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); (11, util.VN_CURDATE() - INTERVAL 1 DAY , util.VN_CURDATE(), 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4),
(12, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4);
INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`)
VALUES VALUES
@ -1520,7 +1521,7 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed
(8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''),
(9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''),
(10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''), (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''),
(99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 1, 1, ''); (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 0, 0, '');
INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`) INSERT INTO `vn`.`entryConfig` (`defaultEntry`, `inventorySupplierFk`, `defaultSupplierFk`)
VALUES (2, 4, 1); VALUES (2, 4, 1);
@ -2522,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

View File

@ -126,7 +126,10 @@ BEGIN
AND a.available > 0 AND a.available > 0
AND (sub.itemAllowed OR NOT it.isFloramondo OR anr.available > 0) AND (sub.itemAllowed OR NOT it.isFloramondo OR anr.available > 0)
AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize) AND (ag.isAnyVolumeAllowed OR NOT itt.isUnconventionalSize)
AND (itc.isReclining OR it.`size` IS NULL OR it.`size` < z.itemMaxSize OR z.itemMaxSize IS NULL) AND (it.`size` IS NULL
OR IF(itc.isReclining,
it.size <= z.itemMaxLength OR z.itemMaxLength IS NULL,
it.size <= z.itemMaxSize OR z.itemMaxSize IS NULL))
AND cit.id IS NULL AND cit.id IS NULL
AND zit.id IS NULL AND zit.id IS NULL
AND ait.id IS NULL; AND ait.id IS NULL;

View File

@ -7,7 +7,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`catalog_componentCalc
) )
BEGIN BEGIN
/** /**
* Calcula los componentes de los articulos de tmp.ticketLot * Calcula los componentes de los articulos de la tabla tmp.ticketLot
* *
* @param vZoneFk para calcular el transporte * @param vZoneFk para calcular el transporte
* @param vAddressFk Consignatario * @param vAddressFk Consignatario
@ -25,18 +25,38 @@ BEGIN
FROM address FROM address
WHERE id = vAddressFk; WHERE id = vAddressFk;
CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice CREATE OR REPLACE TEMPORARY TABLE tPriceDelta
(INDEX (itemFk)) (INDEX (itemFk))
ENGINE = MEMORY ENGINE = MEMORY
SELECT * FROM ( SELECT i.id itemFk,
SUM(IFNULL(pd.absIncreasing,0)) absIncreasing,
SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing,
pd.warehouseFk
FROM item i
JOIN priceDelta pd
ON pd.itemTypeFk = i.typeFk
AND (pd.minSize IS NULL OR pd.minSize <= i.`size`)
AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`)
AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk)
AND (pd.originFk IS NULL OR pd.originFk = i.originFk)
AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk)
AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk)
WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped)
AND (pd.toDated IS NULL OR pd.toDated >= vShipped)
GROUP BY i.id;
CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice
(INDEX (itemFk))
ENGINE = MEMORY
SELECT * FROM (
SELECT * SELECT *
FROM specialPrice FROM specialPrice
WHERE (clientFk = vClientFk OR clientFk IS NULL) WHERE (clientFk = vClientFk OR clientFk IS NULL)
AND started <= vShipped AND started <= vShipped
AND (ended >= vShipped OR ended IS NULL) AND (ended >= vShipped OR ended IS NULL)
ORDER BY (clientFk = vClientFk) DESC, id DESC ORDER BY (clientFk = vClientFk) DESC, id DESC
LIMIT 10000000000000000000) t LIMIT 10000000000000000000) t
GROUP BY itemFk; GROUP BY itemFk;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentCalculate
(PRIMARY KEY (itemFk, warehouseFk)) (PRIMARY KEY (itemFk, warehouseFk))
@ -108,6 +128,19 @@ BEGIN
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tc.itemFk AND tcc.warehouseFk = tc.warehouseFk
GROUP BY tc.itemFk, warehouseFk; GROUP BY tc.itemFk, warehouseFk;
-- Bonus del comprador a un rango de productos
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT
tcb.warehouseFk,
tcb.itemFk,
c.id,
IFNULL(tcb.base * tpd.ratIncreasing / 100,0) + IFNULL(tpd.absIncreasing,0)
FROM tmp.ticketComponentBase tcb
JOIN component c ON c.code = 'bonus'
JOIN tPriceDelta tpd
ON tpd.itemFk = tcb.itemFk
AND tpd.warehouseFk = tcb.warehouseFk;
-- RECOBRO -- RECOBRO
INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost)
SELECT tcb.warehouseFk, tcb.itemFk, c2.id, SELECT tcb.warehouseFk, tcb.itemFk, c2.id,
@ -303,6 +336,7 @@ BEGIN
tmp.ticketComponentBase, tmp.ticketComponentBase,
tmp.ticketComponentRate, tmp.ticketComponentRate,
tmp.ticketComponentCopy, tmp.ticketComponentCopy,
tSpecialPrice; tPriceDelta,
tSpecialPrice;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -1,15 +1,13 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`stockTraslation`( CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_calculateStock`(
vDated DATE vDated DATE
) )
BEGIN BEGIN
/** /**
* Calcula el stock del almacén de subasta desde FechaInventario hasta vDated * Calculate the stock of the auction warehouse from the inventory date to vDated
* sin tener en cuenta las salidas del mismo dia vDated
* para ver el transporte a reservar
* *
* @param vDated Fecha hasta la cual calcula el stock * @param vDated Date to calculate the stock.
* @return tmp.item * @return tmp.item, tmp.buyUltimate
*/ */
DECLARE vAuctionWarehouseFk INT; DECLARE vAuctionWarehouseFk INT;

View File

@ -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;

View File

@ -1,58 +1,64 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`previousSticker_get`(vSaleGroupFk INT) CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`previousSticker_get`(
vSaleGroupFk INT
)
BEGIN BEGIN
/** /**
* Devuelve los campos a imprimir en una etiqueta de preparación previa. * Devuelve los campos a imprimir en una etiqueta de preparación previa.
* Actualiza el valor de vn.saleGroup.parkingFk en el caso de que exista un * Actualiza el valor de saleGroup.parkingFk en el caso de que exista un
* saleGroup del mismo ticket con parking, del mismo sector, para que todos se * saleGroup del mismo ticket con parking, del mismo sector, para que todos se
* pongan juntos. * pongan juntos.
* *
* @param vSaleGroupFk Identificador de vn.saleGroup * @param vSaleGroupFk Identificador de saleGroup
*/ */
DECLARE vTicketFk INT; DECLARE vTicketFk INT;
DECLARE vParkingFk INT; DECLARE vParkingFk INT;
DECLARE vSectorFk INT; DECLARE vSectorFk INT;
DECLARE vTicketLines INT;
SELECT s.ticketFk WITH ticketData AS(
INTO vTicketFk SELECT DISTINCT s.ticketFk
FROM vn.saleGroupDetail sgd FROM vn.saleGroupDetail sgd
JOIN vn.sale s ON s.id = sgd.saleFk JOIN vn.sale s ON s.id = sgd.saleFk
WHERE sgd.saleGroupFk = vSaleGroupFk WHERE sgd.saleGroupFk = vSaleGroupFk
LIMIT 1; )
SELECT COUNT(*), s.ticketFk INTO vTicketLines, vTicketFk
FROM vn.sale s
JOIN ticketData td ON td.ticketFk = s.ticketFk;
SELECT sg.parkingFk, sc.sectorFk SELECT sg.parkingFk, sc.sectorFk
INTO vParkingFk, vSectorFk INTO vParkingFk, vSectorFk
FROM vn.saleGroup sg FROM saleGroup sg
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id JOIN sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk JOIN sectorCollection sc ON sc.id = scsg.sectorCollectionFk
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
JOIN vn.sale s ON s.id = sgd.saleFk JOIN sale s ON s.id = sgd.saleFk
WHERE s.ticketFk = vTicketFk WHERE s.ticketFk = vTicketFk
AND sg.parkingFk IS NOT NULL AND sg.parkingFk IS NOT NULL
LIMIT 1; LIMIT 1;
UPDATE vn.saleGroup sg UPDATE saleGroup sg
SET sg.parkingFk = vParkingFk SET sg.parkingFk = vParkingFk
WHERE sg.id = vSaleGroupFk WHERE sg.id = vSaleGroupFk
AND sg.sectorFk = vSectorFk; AND sg.sectorFk = vSectorFk;
SELECT sgd.saleGroupFk, SELECT sgd.saleGroupFk,
t.id ticketFk, t.id ticketFk,
p.code as location, COUNT(*) previousLines,
t.observations,
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour, IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour,
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute , IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute ,
IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk , IFNULL(MAX(i.itemPackingTypeFk),'H') itemPackingTypeFk ,
count(*) items, vTicketLines ticketLines,
p.code `location`,
sc.description sector sc.description sector
FROM vn.sale s FROM sale s
JOIN vn.item i ON i.id = s.itemFk JOIN item i ON i.id = s.itemFk
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN saleGroupDetail sgd ON sgd.saleFk = s.id
JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk JOIN saleGroup sg ON sg.id = sgd.saleGroupFk
JOIN vn.sector sc ON sc.id = sg.sectorFk JOIN sector sc ON sc.id = sg.sectorFk
JOIN vn.ticket t ON t.id = s.ticketFk JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN vn.parking p ON p.id = sg.parkingFk LEFT JOIN parking p ON p.id = sg.parkingFk
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk LEFT JOIN `zone` z ON z.id = t.zoneFk
WHERE sgd.saleGroupFk = vSaleGroupFk; WHERE sgd.saleGroupFk = vSaleGroupFk;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -99,7 +99,7 @@ proc: BEGIN
LEFT JOIN `zone` z ON z.id = t.zoneFk LEFT JOIN `zone` z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
AND DATE(t.shipped) = zc.dated AND DATE(t.shipped) = zc.dated
LEFT JOIN ticketParking tp ON tp.ticketFk = t.id LEFT JOIN ticketParking tp ON tp.ticketFk = t.id
LEFT JOIN parking pk ON pk.id = tp.parkingFk LEFT JOIN parking pk ON pk.id = tp.parkingFk
WHERE t.warehouseFk = vWarehouseFk WHERE t.warehouseFk = vWarehouseFk
AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP'); AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP');
@ -124,8 +124,8 @@ proc: BEGIN
ADD COLUMN `collectionN` INT; ADD COLUMN `collectionN` INT;
UPDATE tmp.productionBuffer pb UPDATE tmp.productionBuffer pb
JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk
SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''), SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''),
IFNULL(tp.itemDelay, ''), IFNULL(tp.itemDelay, ''),
IFNULL(tp.itemLost, ''), IFNULL(tp.itemLost, ''),
IF(tp.isFreezed, ' CONGELADO',''), IF(tp.isFreezed, ' CONGELADO',''),
@ -141,7 +141,7 @@ proc: BEGIN
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk
JOIN productionConfig pc JOIN productionConfig pc
SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255))) SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255)))
WHERE (cnb.clientFk IS NULL OR cnb.isRookie) WHERE (cnb.clientFk IS NULL OR cnb.isRookie)
AND pc.rookieDays; AND pc.rookieDays;
-- Líneas y volumen por ticket -- Líneas y volumen por ticket

View File

@ -25,8 +25,9 @@ UPDATE shelving sh
AND ( AND (
sh.parked IS NULL sh.parked IS NULL
OR OR
sh.parked < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) sh.parked < util.VN_CURDATE() - INTERVAL 2 WEEK
) )
AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN ( AND IF(code REGEXP '^[A-Za-z]{2}[0-9]', LEFT (code, 2) NOT IN (
SELECT DISTINCT LEFT(its.shelvingFk, 2) SELECT DISTINCT LEFT(its.shelvingFk, 2)
FROM itemShelving its FROM itemShelving its

View File

@ -1,12 +1,17 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`() CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`(
BEGIN vDated DATE
)
proc: BEGIN
/** /**
* Inserts the purchase volume per buyer * Calculate the stock of the auction warehouse from the inventory date to vDated
* into stockBought according to the current date. * without taking into account the outputs of the same day vDated
*
* @param vDated Date to calculate the stock.
*/ */
DECLARE vDated DATE; IF vDated < util.VN_CURDATE() THEN
SET vDated = util.VN_CURDATE(); LEAVE proc;
END IF;
CREATE OR REPLACE TEMPORARY TABLE tStockBought CREATE OR REPLACE TEMPORARY TABLE tStockBought
SELECT workerFk, reserve SELECT workerFk, reserve
@ -16,26 +21,27 @@ BEGIN
DELETE FROM stockBought WHERE dated = vDated; DELETE FROM stockBought WHERE dated = vDated;
INSERT INTO stockBought (workerFk, bought, dated) CALL item_calculateStock(vDated);
INSERT INTO stockBought(workerFk, bought, dated)
SELECT it.workerFk, SELECT it.workerFk,
ROUND(SUM( ROUND(SUM(
(ac.conversionCoefficient * (ti.quantity / b.packing) *
(b.quantity / b.packing) *
buy_getVolume(b.id) buy_getVolume(b.id)
) / (vc.trolleyM3 * 1000000) ) / vc.palletM3 / 1000000, 1) bought,
), 1),
vDated vDated
FROM entry e FROM itemType it
JOIN travel t ON t.id = e.travelFk JOIN item i ON i.typeFk = it.id
JOIN warehouse w ON w.id = t.warehouseInFk LEFT JOIN tmp.item ti ON ti.itemFk = i.id
JOIN buy b ON b.entryFk = e.id JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN item i ON i.id = b.itemFk JOIN warehouse wh ON wh.code = 'VNH'
JOIN itemType it ON it.id = i.typeFk JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
JOIN auctionConfig ac AND bu.warehouseFk = wh.id
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc JOIN volumeConfig vc
WHERE t.shipped = vDated WHERE ic.display
AND t.warehouseInFk = ac.warehouseFk GROUP BY it.workerFk
GROUP BY it.workerFk; HAVING bought;
UPDATE stockBought s UPDATE stockBought s
JOIN tStockBought ts ON ts.workerFk = s.workerFk JOIN tStockBought ts ON ts.workerFk = s.workerFk
@ -45,8 +51,12 @@ BEGIN
INSERT INTO stockBought (workerFk, reserve, dated) INSERT INTO stockBought (workerFk, reserve, dated)
SELECT ts.workerFk, ts.reserve, vDated SELECT ts.workerFk, ts.reserve, vDated
FROM tStockBought ts FROM tStockBought ts
WHERE ts.workerFk NOT IN (SELECT workerFk FROM stockBought WHERE dated = vDated); WHERE ts.workerFk NOT IN (
SELECT workerFk
FROM stockBought
WHERE dated = vDated
);
DROP TEMPORARY TABLE tStockBought; DROP TEMPORARY TABLE tStockBought, tmp.item, tmp.buyUltimate;
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -23,7 +23,7 @@ BEGIN
WHERE dated = vDated WHERE dated = vDated
AND userFk = vWorker; AND userFk = vWorker;
CALL stockTraslation(vDated); CALL item_calculateStock(vDated);
INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description) INSERT INTO stockBuyed(userFk, buyed, `dated`, reserved, requested, description)
SELECT it.workerFk, SELECT it.workerFk,

View File

@ -18,7 +18,7 @@ BEGIN
DELETE FROM stockBuyed WHERE dated = vDated; DELETE FROM stockBuyed WHERE dated = vDated;
CALL stockTraslation(vDated); CALL item_calculateStock(vDated);
INSERT INTO stockBuyed(userFk, buyed, `dated`, description) INSERT INTO stockBuyed(userFk, buyed, `dated`, description)
SELECT it.workerFk, SELECT it.workerFk,

View File

@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_splitItemPacki
vSelf INT, vSelf INT,
vOriginalItemPackingTypeFk VARCHAR(1) vOriginalItemPackingTypeFk VARCHAR(1)
) )
proc: BEGIN BEGIN
/** /**
* Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado. * Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado.
* Respeta el id inicial para el tipo propuesto. * Respeta el id inicial para el tipo propuesto.

View File

@ -0,0 +1,3 @@
ALTER TABLE vn.`zone`
ADD COLUMN IF NOT EXISTS itemMaxLength int(11) NULL COMMENT 'Longitud maxima para articulos acostados que esa agencia puede transportar',
MODIFY COLUMN itemMaxSize int(11) DEFAULT NULL NULL COMMENT 'Altura maxima de los articulos que esa agencia puede transportar';

View File

@ -0,0 +1,3 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Postcode','*','WRITE','ALLOW','ROLE','administrative');

View File

@ -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`;

View File

@ -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;

View File

@ -0,0 +1,6 @@
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Province','*','WRITE','ALLOW','ROLE','administrative');
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
VALUES ('Town','*','WRITE','ALLOW','ROLE','administrative');

View File

@ -0,0 +1,31 @@
-- vn.priceDelta definition
CREATE OR REPLACE TABLE vn.priceDelta (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`itemTypeFk` smallint(5) unsigned NOT NULL,
`minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size',
`maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size',
`inkFk` varchar(3) DEFAULT NULL,
`originFk` tinyint(2) unsigned DEFAULT NULL,
`producerFk` mediumint(3) unsigned DEFAULT NULL,
`fromDated` date DEFAULT NULL,
`toDated` date DEFAULT NULL,
`absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price',
`ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price',
`warehouseFk` smallint(6) unsigned NOT NULL,
`created` timestamp NOT NULL DEFAULT current_timestamp(),
`editorFk` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `priceDelta_itemType_FK` (`itemTypeFk`),
KEY `priceDelta_ink_FK` (`inkFk`),
KEY `priceDelta_producer_FK` (`producerFk`),
KEY `priceDelta_warehouse_FK` (`warehouseFk`),
KEY `priceDelta_worker_FK` (`editorFk`),
CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items';
GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer;

View File

@ -0,0 +1,32 @@
-- Place your SQL code here
-- vn.priceDelta definition
CREATE OR REPLACE TABLE vn.priceDelta (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`itemTypeFk` smallint(5) unsigned NOT NULL,
`minSize` int(10) unsigned DEFAULT NULL COMMENT 'Minimum item.size',
`maxSize` int(10) unsigned DEFAULT NULL COMMENT 'Maximum item.size',
`inkFk` varchar(3) DEFAULT NULL,
`originFk` tinyint(2) unsigned DEFAULT NULL,
`producerFk` mediumint(3) unsigned DEFAULT NULL,
`fromDated` date DEFAULT NULL,
`toDated` date DEFAULT NULL,
`absIncreasing` decimal(10,3) DEFAULT NULL COMMENT 'Absolute increasing of final price',
`ratIncreasing` int(11) DEFAULT NULL COMMENT 'Increasing ratio for the cost price',
`warehouseFk` smallint(6) unsigned NOT NULL,
`created` timestamp NOT NULL DEFAULT current_timestamp(),
`editorFk` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `priceDelta_itemType_FK` (`itemTypeFk`),
KEY `priceDelta_ink_FK` (`inkFk`),
KEY `priceDelta_producer_FK` (`producerFk`),
KEY `priceDelta_warehouse_FK` (`warehouseFk`),
KEY `priceDelta_worker_FK` (`editorFk`),
CONSTRAINT `priceDelta_ink_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_itemType_FK` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_producer_FK` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_warehouse_FK` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE,
CONSTRAINT `priceDelta_worker_FK` FOREIGN KEY (`editorFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Defines the increasing o decreasing for ranges of items';
GRANT INSERT, SELECT, UPDATE, DELETE ON TABLE vn.priceDelta TO buyer;

View File

@ -0,0 +1 @@
ALTER TABLE dipole.expedition_PrintOut DROP COLUMN IF EXISTS isChecked;

View File

@ -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"
} }

View File

@ -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"
} }

View File

@ -29,15 +29,13 @@ module.exports = Self => {
dated.setHours(0, 0, 0, 0); dated.setHours(0, 0, 0, 0);
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
if (dated.getTime() === today.getTime()) await models.StockBought.rawSql(`CALL vn.stockBought_calculate(?)`, [dated]);
await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`);
const filter = { const filter = {
where: { where: {dated},
dated: dated
},
include: [ include: [
{ {
fields: ['workerFk', 'reserve', 'bought'],
relation: 'worker', relation: 'worker',
scope: { scope: {
include: [ include: [

View File

@ -11,6 +11,7 @@ module.exports = Self => {
arg: 'dated', arg: 'dated',
type: 'string', type: 'string',
description: 'The date to filter', description: 'The date to filter',
required: true,
} }
], ],
returns: { returns: {
@ -24,35 +25,50 @@ module.exports = Self => {
}); });
Self.getStockBoughtDetail = async(workerFk, dated) => { Self.getStockBoughtDetail = async(workerFk, dated) => {
if (!dated) { const models = Self.app.models;
dated = Date.vnNew(); const myOptions = {};
dated.setHours(0, 0, 0, 0); let tx;
let result;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], myOptions);
result = await Self.rawSql(
`SELECT b.entryFk entryFk,
i.id itemFk,
i.name itemName,
ti.quantity,
(ac.conversionCoefficient * (ti.quantity / b.packing) * buy_getVolume(b.id))
/ (vc.trolleyM3 * 1000000) volume,
b.packagingFk packagingFk,
b.packing
FROM tmp.item ti
JOIN item i ON i.id = ti.itemFk
JOIN itemType it ON i.typeFk = it.id
JOIN itemCategory ic ON ic.id = it.categoryFk
JOIN worker w ON w.id = it.workerFk
JOIN auctionConfig ac
JOIN tmp.buyUltimate bu ON bu.itemFk = i.id
AND bu.warehouseFk = ac.warehouseFk
JOIN buy b ON b.id = bu.buyFk
JOIN volumeConfig vc
WHERE ic.display
AND w.id = ?`,
[workerFk], myOptions
);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], myOptions);
if (tx) await tx.commit();
return result;
} catch (e) {
await tx.rollback();
throw e;
} }
return Self.rawSql(
`SELECT e.id entryFk,
i.id itemFk,
i.longName itemName,
b.quantity,
ROUND((ac.conversionCoefficient *
(b.quantity / b.packing) *
buy_getVolume(b.id)
) / (vc.trolleyM3 * 1000000),
2
) volume,
b.packagingFk,
b.packing
FROM entry e
JOIN travel t ON t.id = e.travelFk
JOIN buy b ON b.entryFk = e.id
JOIN item i ON i.id = b.itemFk
JOIN itemType it ON it.id = i.typeFk
JOIN worker w ON w.id = it.workerFk
JOIN auctionConfig ac
JOIN volumeConfig vc
WHERE t.warehouseInFk = ac.warehouseFk
AND it.workerFk = ?
AND t.shipped = util.VN_CURDATE()`,
[workerFk]
);
}; };
}; };

View File

@ -63,8 +63,7 @@ module.exports = Self => {
FROM tItemShelving ti FROM tItemShelving ti
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
JOIN vn.productionConfig pc JOIN vn.productionConfig pc
WHERE ti.created + INTERVAL pc.itemOlderReviewHours HOUR < tis.created WHERE ti.created + INTERVAL pc.itemOlderReviewHours HOUR < tis.created;`,
LIMIT 10;`,
[shelvingFk, shelvingFk], myOptions); [shelvingFk, shelvingFk], myOptions);
return result; return result;
}; };

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
describe('item lastEntriesFilter()', () => { describe('item lastEntriesFilter()', () => {
it('should return one entry for the given item', async() => { it('should return two entry for the given item', async() => {
const minDate = Date.vnNew(); const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0); minDate.setHours(0, 0, 0, 0);
const maxDate = Date.vnNew(); const maxDate = Date.vnNew();
@ -13,7 +13,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options); const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(2);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
@ -22,7 +22,7 @@ describe('item lastEntriesFilter()', () => {
} }
}); });
it('should return five entries for the given item', async() => { it('should return six entries for the given item', async() => {
const minDate = Date.vnNew(); const minDate = Date.vnNew();
minDate.setHours(0, 0, 0, 0); minDate.setHours(0, 0, 0, 0);
minDate.setMonth(minDate.getMonth() - 2, 1); minDate.setMonth(minDate.getMonth() - 2, 1);
@ -37,7 +37,7 @@ describe('item lastEntriesFilter()', () => {
const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}}; const filter = {where: {itemFk: 1, landed: {between: [minDate, maxDate]}}};
const result = await models.Item.lastEntriesFilter(filter, options); const result = await models.Item.lastEntriesFilter(filter, options);
expect(result.length).toEqual(5); expect(result.length).toEqual(6);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {

View File

@ -92,10 +92,13 @@ module.exports = Self => {
s.payDay, s.payDay,
s.phone, s.phone,
s.city, s.city,
s.countryFk,
c.name country,
pm.name AS payMethod, pm.name AS payMethod,
pd.payDem AS payDem pd.payDem AS payDem
FROM vn.supplier s FROM vn.supplier s
LEFT JOIN vn.payMethod pm ON pm.id = s.payMethodFk LEFT JOIN vn.payMethod pm ON pm.id = s.payMethodFk
LEFT JOIN vn.country c ON c.id = s.countryFk
LEFT JOIN vn.payDem pd ON pd.id = s.payDemFk` LEFT JOIN vn.payDem pd ON pd.id = s.payDemFk`
); );

View File

@ -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`
); );

View File

@ -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

View File

@ -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;

View File

@ -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};
try { const createdThermograph = await models.Thermograph.createThermograph(
const options = {transaction: tx}; ctx, thermographId, model, temperatureFk, warehouseId, options);
const createdThermograph = await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); expect(createdThermograph.thermographFk).toEqual(thermographId);
expect(createdThermograph.id).toEqual(thermographId); const createdTravelThermograph =
expect(createdThermograph.model).toEqual(model); await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options);
const createdTravelThermograpth = await models.TravelThermograph.findOne({where: {thermographFk: thermographId}}, options); expect(createdTravelThermograph.warehouseFk).toEqual(warehouseId);
expect(createdTravelThermograph.temperatureFk).toEqual(temperatureFk);
expect(createdTravelThermograpth.warehouseFk).toEqual(warehouseId);
expect(createdTravelThermograpth.temperatureFk).toEqual(temperatureFk);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
}); });
it(`should throw an error when trying to created repeated thermograph`, async() => { it(`should throw an error when trying to create a repeated thermograph`, async() => {
const tx = await models.Thermograph.beginTransaction({});
let error;
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); await models.Thermograph.createThermograph(
await models.Thermograph.createThermograph(ctx, thermographId, model, temperatureFk, warehouseId, options); ctx, thermographId, model, temperatureFk, warehouseId, options);
await models.Thermograph.createThermograph(
await tx.rollback(); ctx, thermographId, model, temperatureFk, warehouseId, options);
fail('Expected an error to be thrown when trying to create a repeated thermograph');
} catch (e) { } catch (e) {
await tx.rollback(); expect(e.message).toBe('This thermograph id already exists');
error = e;
} }
expect(error.message).toBe('This thermograph id already exists');
}); });
}); });

View File

@ -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;
}
};
};

View File

@ -79,6 +79,10 @@ module.exports = Self => {
arg: 'landingHour', arg: 'landingHour',
type: 'string', type: 'string',
description: 'The landing hour' description: 'The landing hour'
}, {
arg: 'daysOnward',
type: 'number',
description: 'The days onward'
} }
], ],
returns: { returns: {
@ -92,8 +96,11 @@ module.exports = Self => {
}); });
Self.filter = async(ctx, filter) => { Self.filter = async(ctx, filter) => {
let conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => { const today = Date.vnNew();
const future = Date.vnNew();
const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
@ -109,6 +116,12 @@ module.exports = Self => {
return {'t.landed': {gte: value}}; return {'t.landed': {gte: value}};
case 'landedTo': case 'landedTo':
return {'t.landed': {lte: value}}; return {'t.landed': {lte: value}};
case 'daysOnward':
today.setHours(0, 0, 0, 0);
future.setDate(today.getDate() + value);
future.setHours(23, 59, 59, 999);
return {'t.landed': {between: [today, future]}};
case 'id': case 'id':
case 'agencyModeFk': case 'agencyModeFk':
case 'warehouseOutFk': case 'warehouseOutFk':

View File

@ -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;
}
};
};

View File

@ -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;
}
});
});

View File

@ -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');
}
});
});

View File

@ -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;
}
};
};

View File

@ -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": {

View File

@ -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);

View File

@ -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,

View File

@ -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;
}, },

View File

@ -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();

View File

@ -42,6 +42,9 @@
}, },
"itemMaxSize": { "itemMaxSize": {
"type": "number" "type": "number"
},
"itemMaxLength": {
"type": "number"
} }
}, },
"relations": { "relations": {

View File

@ -1,6 +1,6 @@
{ {
"name": "salix-back", "name": "salix-back",
"version": "24.40.0", "version": "24.42.0",
"author": "Verdnatura Levante SL", "author": "Verdnatura Levante SL",
"description": "Salix backend", "description": "Salix backend",
"license": "GPL-3.0", "license": "GPL-3.0",

View File

@ -19,7 +19,7 @@
<div class="packing">{{previa.itemPackingTypeFk}}</div> <div class="packing">{{previa.itemPackingTypeFk}}</div>
<div class="dated">{{previa.shippingHour}}:{{previa.shippingMinute}}</div> <div class="dated">{{previa.shippingHour}}:{{previa.shippingMinute}}</div>
</div> </div>
<div class="size">{{previa.items}}</div> <div class="size">{{previa.previousLines}}</div>
</div> </div>
</div> </div>
</div> </div>