Merge branch 'dev' into 3411-route_ticket_fixtures
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
872f5b488b
|
@ -130,8 +130,7 @@ BEGIN
|
||||||
END
|
END
|
||||||
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
|
||||||
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id
|
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id
|
||||||
LEFT JOIN claim cl ON cl.ticketFk = t.id
|
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
|
||||||
LEFT JOIN claimBeginning cb ON cl.id = cb.claimFk AND s.id = cb.saleFk
|
|
||||||
WHERE t.shipped >= vDateInventory
|
WHERE t.shipped >= vDateInventory
|
||||||
AND s.itemFk = vItemId
|
AND s.itemFk = vItemId
|
||||||
AND vWarehouse =t.warehouseFk
|
AND vWarehouse =t.warehouseFk
|
||||||
|
|
|
@ -0,0 +1,120 @@
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`sale_recalcComponent`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_recalcComponent`(vOption INT)
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los componentes
|
||||||
|
*
|
||||||
|
* @table tmp.recalculateSales
|
||||||
|
*/
|
||||||
|
DECLARE vShipped DATE;
|
||||||
|
DECLARE vWarehouseFk SMALLINT;
|
||||||
|
DECLARE vAgencyModeFk INT;
|
||||||
|
DECLARE vAddressFk INT;
|
||||||
|
DECLARE vTicketFk BIGINT;
|
||||||
|
DECLARE vItemFk BIGINT;
|
||||||
|
DECLARE vLanded DATE;
|
||||||
|
DECLARE vIsEditable BOOLEAN;
|
||||||
|
DECLARE vZoneFk INTEGER;
|
||||||
|
DECLARE vOption INTEGER;
|
||||||
|
|
||||||
|
DECLARE vSale INTEGER;
|
||||||
|
DECLARE vDone BOOL DEFAULT FALSE;
|
||||||
|
|
||||||
|
DECLARE vCur CURSOR FOR
|
||||||
|
SELECT id from tmp.recalculateSales;
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||||
|
|
||||||
|
OPEN vCur;
|
||||||
|
|
||||||
|
l: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH vCur INTO vSale;
|
||||||
|
|
||||||
|
IF vDone THEN
|
||||||
|
LEAVE l;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
SELECT t.refFk IS NULL AND (IFNULL(ts.alertLevel, 0) = 0 OR s.price = 0),
|
||||||
|
s.ticketFk,
|
||||||
|
s.itemFk ,
|
||||||
|
t.zoneFk,
|
||||||
|
t.warehouseFk,
|
||||||
|
t.shipped,
|
||||||
|
t.addressFk,
|
||||||
|
t.agencyModeFk,
|
||||||
|
t.landed
|
||||||
|
INTO vIsEditable,
|
||||||
|
vTicketFk,
|
||||||
|
vItemFk,
|
||||||
|
vZoneFk,
|
||||||
|
vWarehouseFk,
|
||||||
|
vShipped,
|
||||||
|
vAddressFk,
|
||||||
|
vAgencyModeFk,
|
||||||
|
vLanded
|
||||||
|
FROM ticket t
|
||||||
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
|
WHERE s.id = vSale;
|
||||||
|
|
||||||
|
CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
|
||||||
|
|
||||||
|
IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN
|
||||||
|
CALL util.throw('There is no zone for these parameters');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF vLanded IS NULL OR vZoneFk IS NULL THEN
|
||||||
|
|
||||||
|
UPDATE ticket t
|
||||||
|
SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
|
||||||
|
WHERE t.id = vTicketFk AND t.landed IS NULL;
|
||||||
|
|
||||||
|
IF vZoneFk IS NULL THEN
|
||||||
|
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
|
||||||
|
UPDATE ticket t
|
||||||
|
SET t.zoneFk = vZoneFk
|
||||||
|
WHERE t.id = vTicketFk AND t.zoneFk IS NULL;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.zoneGetLanded;
|
||||||
|
|
||||||
|
-- rellena la tabla buyUltimate con la ultima compra
|
||||||
|
CALL buyUltimate (vWarehouseFk, vShipped);
|
||||||
|
|
||||||
|
DELETE FROM tmp.buyUltimate WHERE itemFk != vItemFk;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||||
|
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||||
|
SELECT vWarehouseFk warehouseFk, NULL available, vItemFk itemFk, buyFk, vZoneFk zoneFk
|
||||||
|
FROM tmp.buyUltimate
|
||||||
|
WHERE itemFk = vItemFk;
|
||||||
|
|
||||||
|
CALL catalog_componentPrepare();
|
||||||
|
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||||
|
CREATE TEMPORARY TABLE tmp.sale
|
||||||
|
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||||
|
SELECT vSale saleFk,vWarehouseFk warehouseFk;
|
||||||
|
|
||||||
|
IF vOption IS NULL THEN
|
||||||
|
SET vOption = IF(vIsEditable, 1, 6);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CALL ticketComponentUpdateSale(vOption);
|
||||||
|
CALL catalog_componentPurge();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||||
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
CLOSE vCur;
|
||||||
|
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,23 @@
|
||||||
|
DROP PROCEDURE IF EXISTS `vn`.`sale_calculateComponent`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_calculateComponent`(vSale INT, vOption INT)
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Crea tabla temporal para vn.sale_recalcComponent() para recalcular los componentes
|
||||||
|
*
|
||||||
|
* @param vSale Id de la venta
|
||||||
|
* @param vOption indica en que componente pone el descuadre, NULL en casos habituales
|
||||||
|
*/
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
||||||
|
CREATE TEMPORARY TABLE tmp.recalculateSales
|
||||||
|
SELECT s.id
|
||||||
|
FROM sale s
|
||||||
|
WHERE s.id = vSale;
|
||||||
|
|
||||||
|
CALL vn.sale_recalcComponent(vOption);
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.recalculateSales;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1 @@
|
||||||
|
Delete me!
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
USE `util`;
|
USE `util`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: util
|
-- Host: db.verdnatura.es Database: util
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -34,9 +34,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:34
|
-- Dump completed on 2021-12-01 7:59:57
|
||||||
USE `account`;
|
USE `account`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: account
|
-- Host: db.verdnatura.es Database: account
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -120,9 +120,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:35
|
-- Dump completed on 2021-12-01 7:59:59
|
||||||
USE `salix`;
|
USE `salix`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: salix
|
-- Host: db.verdnatura.es Database: salix
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -186,9 +186,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:36
|
-- Dump completed on 2021-12-01 8:00:00
|
||||||
USE `vn`;
|
USE `vn`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: vn
|
-- Host: db.verdnatura.es Database: vn
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -452,9 +452,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:41
|
-- Dump completed on 2021-12-01 8:00:05
|
||||||
USE `cache`;
|
USE `cache`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: cache
|
-- Host: db.verdnatura.es Database: cache
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -488,9 +488,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:42
|
-- Dump completed on 2021-12-01 8:00:06
|
||||||
USE `hedera`;
|
USE `hedera`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: hedera
|
-- Host: db.verdnatura.es Database: hedera
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -554,9 +554,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:43
|
-- Dump completed on 2021-12-01 8:00:07
|
||||||
USE `postgresql`;
|
USE `postgresql`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: postgresql
|
-- Host: db.verdnatura.es Database: postgresql
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -640,9 +640,9 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:44
|
-- Dump completed on 2021-12-01 8:00:08
|
||||||
USE `sage`;
|
USE `sage`;
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: sage
|
-- Host: db.verdnatura.es Database: sage
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -696,4 +696,4 @@ UNLOCK TABLES;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-24 12:27:44
|
-- Dump completed on 2021-12-01 8:00:09
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64)
|
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64)
|
||||||
--
|
--
|
||||||
-- Host: db.verdnatura.es Database: account
|
-- Host: db.verdnatura.es Database: account
|
||||||
-- ------------------------------------------------------
|
-- ------------------------------------------------------
|
||||||
|
@ -14652,9 +14652,9 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
/*!50003 SET character_set_client = utf8 */ ;
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
/*!50003 SET character_set_results = utf8 */ ;
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
|
@ -14703,8 +14703,8 @@ BEGIN
|
||||||
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate
|
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate
|
||||||
FROM order_row r
|
FROM order_row r
|
||||||
JOIN vn.item i ON i.id = r.item_id
|
JOIN vn.item i ON i.id = r.item_id
|
||||||
WHERE /*r.amount != 0 JGF 2021-11-15
|
WHERE r.amount != 0
|
||||||
AND*/ r.warehouse_id = vWarehouse
|
AND r.warehouse_id = vWarehouse
|
||||||
AND r.order_id = vOrder
|
AND r.order_id = vOrder
|
||||||
ORDER BY r.rate DESC;
|
ORDER BY r.rate DESC;
|
||||||
|
|
||||||
|
@ -25233,11 +25233,11 @@ CREATE TABLE `buy` (
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
/*!50003 SET character_set_client = utf8 */ ;
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
/*!50003 SET character_set_results = utf8 */ ;
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeInsert`
|
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeInsert`
|
||||||
BEFORE INSERT ON `buy`
|
BEFORE INSERT ON `buy`
|
||||||
|
@ -25327,11 +25327,11 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
/*!50003 SET character_set_client = utf8 */ ;
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
/*!50003 SET character_set_results = utf8 */ ;
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeUpdate`
|
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeUpdate`
|
||||||
BEFORE UPDATE ON `buy`
|
BEFORE UPDATE ON `buy`
|
||||||
|
@ -29855,9 +29855,17 @@ CREATE TABLE `genericAllocation` (
|
||||||
`color` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
|
`color` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
`quality` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
|
`quality` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
`numFlores` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
|
`numFlores` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
|
`category` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
|
`productor` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `genericAllocation_FK` (`itemFk`),
|
KEY `genericAllocation_FK` (`itemFk`),
|
||||||
KEY `genericAllocation_FK_1` (`typeFk`),
|
KEY `genericAllocation_FK_1` (`typeFk`),
|
||||||
|
KEY `genericAllocation_origin_IDX` (`origin`) USING BTREE,
|
||||||
|
KEY `genericAllocation_color_IDX` (`color`) USING BTREE,
|
||||||
|
KEY `genericAllocation_quality_IDX` (`quality`) USING BTREE,
|
||||||
|
KEY `genericAllocation_numFlores_IDX` (`numFlores`) USING BTREE,
|
||||||
|
KEY `genericAllocation_category_IDX` (`category`) USING BTREE,
|
||||||
|
KEY `genericAllocation_productor_IDX` (`productor`) USING BTREE,
|
||||||
CONSTRAINT `genericAllocation_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT `genericAllocation_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items';
|
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items';
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
@ -35838,11 +35846,12 @@ DELIMITER ;;
|
||||||
AFTER INSERT
|
AFTER INSERT
|
||||||
ON saleBuy FOR EACH ROW
|
ON saleBuy FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
/* Activar de nuevo cuando volvamos a vender fruta y verdura
|
||||||
|
*
|
||||||
UPDATE vn.sale s
|
UPDATE vn.sale s
|
||||||
SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk)
|
SET s.concept = CONCAT(s.concept, ' Lote: ', NEW.buyFk)
|
||||||
WHERE s.id = NEW.saleFk;
|
WHERE s.id = NEW.saleFk;
|
||||||
|
*/
|
||||||
END */;;
|
END */;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -36590,6 +36599,33 @@ DELIMITER ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Table structure for table `shelvingLog`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `shelvingLog`;
|
||||||
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
|
CREATE TABLE `shelvingLog` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`originFk` varchar(10) CHARACTER SET utf8 NOT NULL,
|
||||||
|
`userFk` int(10) unsigned DEFAULT NULL,
|
||||||
|
`action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`description` text CHARACTER SET utf8,
|
||||||
|
`changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
|
`oldInstance` text COLLATE utf8_unicode_ci,
|
||||||
|
`newInstance` text COLLATE utf8_unicode_ci,
|
||||||
|
`changedModelId` int(11) DEFAULT NULL,
|
||||||
|
`changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `userFk` (`userFk`),
|
||||||
|
KEY `originFk` (`originFk`),
|
||||||
|
CONSTRAINT `shelvingLog_FK_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `shelvingLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||||
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `silexACL`
|
-- Table structure for table `silexACL`
|
||||||
--
|
--
|
||||||
|
@ -48640,7 +48676,7 @@ BEGIN
|
||||||
DELETE g FROM glsExpedition g
|
DELETE g FROM glsExpedition g
|
||||||
JOIN expedition e ON e.id = g.expeditionFk
|
JOIN expedition e ON e.id = g.expeditionFk
|
||||||
WHERE e.created < v26Month;
|
WHERE e.created < v26Month;
|
||||||
DELETE FROM expedition WHERE created < v26Month;
|
DELETE IGNORE FROM expedition WHERE created < v26Month;
|
||||||
DELETE FROM sms WHERE created < v18Month;
|
DELETE FROM sms WHERE created < v18Month;
|
||||||
DELETE FROM saleTracking WHERE created < vDateShort;
|
DELETE FROM saleTracking WHERE created < vDateShort;
|
||||||
DELETE tobs FROM ticketObservation tobs
|
DELETE tobs FROM ticketObservation tobs
|
||||||
|
@ -50260,6 +50296,50 @@ BEGIN
|
||||||
AND MONTH(c.created) = MONTH(CURDATE() - INTERVAL 1 MONTH)
|
AND MONTH(c.created) = MONTH(CURDATE() - INTERVAL 1 MONTH)
|
||||||
AND YEAR(c.created) = YEAR(CURDATE() - INTERVAL 1 MONTH);
|
AND YEAR(c.created) = YEAR(CURDATE() - INTERVAL 1 MONTH);
|
||||||
-- END IF;
|
-- END IF;
|
||||||
|
END ;;
|
||||||
|
DELIMITER ;
|
||||||
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
/*!50003 DROP PROCEDURE IF EXISTS `collectionOrTicket_printSticker` */;
|
||||||
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `collectionOrTicket_printSticker`(vParam INT, vSectorFk INT)
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
/*Imprime una etiqueta amarilla a partir de una colección o ticket
|
||||||
|
*
|
||||||
|
* @param vParam colección o ticket a imprimir
|
||||||
|
* @param vSectorFk id del sector
|
||||||
|
*/
|
||||||
|
|
||||||
|
DECLARE vLabelReport INT;
|
||||||
|
|
||||||
|
SELECT labelReportFk INTO vLabelReport
|
||||||
|
FROM sector
|
||||||
|
WHERE id = vSectorFk;
|
||||||
|
|
||||||
|
IF vLabelReport THEN
|
||||||
|
|
||||||
|
INSERT INTO ticketTrolley(ticket, labelCount)
|
||||||
|
SELECT ticketFk, 1
|
||||||
|
FROM ticketCollection
|
||||||
|
WHERE collectionFk = vParam OR ticketFK = vParam
|
||||||
|
ON DUPLICATE KEY UPDATE labelCount = labelCount + 1;
|
||||||
|
|
||||||
|
INSERT INTO printServerQueue(labelReportFk, param1, workerFk)
|
||||||
|
SELECT vLabelReport, vParam, getUser();
|
||||||
|
|
||||||
|
END IF;
|
||||||
|
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -50603,6 +50683,9 @@ DELIMITER ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `collectionSticker_print`(vCollectionFk INT, vSectorFk INT)
|
CREATE DEFINER=`root`@`%` PROCEDURE `collectionSticker_print`(vCollectionFk INT, vSectorFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
/*@deprecated :utilizar collectionOrTicket_printSticker*/
|
||||||
|
|
||||||
DECLARE vLabelReport INT;
|
DECLARE vLabelReport INT;
|
||||||
|
|
||||||
SELECT labelReportFk INTO vLabelReport
|
SELECT labelReportFk INTO vLabelReport
|
||||||
|
@ -54382,7 +54465,7 @@ BEGIN
|
||||||
SELECT COUNT(*) INTO vIsDepartment
|
SELECT COUNT(*) INTO vIsDepartment
|
||||||
FROM vn.workerDepartment dp
|
FROM vn.workerDepartment dp
|
||||||
JOIN department d ON d.id = dp.departmentFk
|
JOIN department d ON d.id = dp.departmentFk
|
||||||
WHERE dp.workerFk = vUserFk AND d.name = "PRODUCCION";
|
WHERE dp.workerFk = vUserFk AND (d.name = "PRODUCCION" OR d.name = "CAMARA" OR d.name = "PALETIZADO" OR d.name = "ARTIFICIAL" OR d.name="NATURAL" OR d.name="TALLER ARTIFICIAL" OR d.name="TALLER NATURAL") ;
|
||||||
|
|
||||||
IF vIsDepartment THEN
|
IF vIsDepartment THEN
|
||||||
SELECT COUNT(*) INTO vIsAuthorized
|
SELECT COUNT(*) INTO vIsAuthorized
|
||||||
|
@ -56147,9 +56230,7 @@ BEGIN
|
||||||
DECLARE vEntryFk INTEGER;
|
DECLARE vEntryFk INTEGER;
|
||||||
|
|
||||||
DECLARE vCur CURSOR FOR
|
DECLARE vCur CURSOR FOR
|
||||||
SELECT e.id FROM vn.entry e
|
SELECT id FROM tmp.recalcEntryCommision;
|
||||||
JOIN vn.travel t ON t.id = e.travelFk
|
|
||||||
WHERE t.shipped >= '2021-10-08' AND t.warehouseInFk= 60;
|
|
||||||
|
|
||||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||||
SET v_done = TRUE;
|
SET v_done = TRUE;
|
||||||
|
@ -62140,6 +62221,67 @@ BEGIN
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.item;
|
DROP TEMPORARY TABLE tmp.item;
|
||||||
|
|
||||||
|
END ;;
|
||||||
|
DELIMITER ;
|
||||||
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
/*!50003 DROP PROCEDURE IF EXISTS `itemSale_byWeek` */;
|
||||||
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
/*!50003 SET character_set_client = utf8 */ ;
|
||||||
|
/*!50003 SET character_set_results = utf8 */ ;
|
||||||
|
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
||||||
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `itemSale_byWeek`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT)
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
DECLARE datSTART DATE;
|
||||||
|
DECLARE datEND DATETIME;
|
||||||
|
|
||||||
|
SELECT MIN(dated), TIMESTAMP(MAX(dated),'23:59:59') INTO datSTART, datEND
|
||||||
|
FROM vn.`time` t
|
||||||
|
WHERE t.`week` = vWeek
|
||||||
|
AND t.`year` = vYear;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
t.shipped,
|
||||||
|
w.name warehouse,
|
||||||
|
s.ticketFk,
|
||||||
|
c.quality,
|
||||||
|
t.nickname AS client,
|
||||||
|
am.name AS agencyName,
|
||||||
|
wk.code AS salesPerson,
|
||||||
|
s.itemFk,
|
||||||
|
IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept,
|
||||||
|
s.quantity,
|
||||||
|
s.price,
|
||||||
|
s.priceFixed,
|
||||||
|
s.discount,
|
||||||
|
tls.name stateName,
|
||||||
|
sb.buyFk,
|
||||||
|
s.id saleFk,
|
||||||
|
wk.id salesPersonFk
|
||||||
|
FROM vn.sale s
|
||||||
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
|
JOIN vn.warehouse w ON w.id = t.warehouseFk
|
||||||
|
JOIN vn.address a ON a.id = t.addressFk
|
||||||
|
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
||||||
|
JOIN vn.client c ON c.id = a.clientFk
|
||||||
|
JOIN vn.worker wk ON wk.id = c.salesPersonFk
|
||||||
|
LEFT JOIN vn.ticketLastState tls ON tls.ticketFk = t.id
|
||||||
|
LEFT JOIN vn.saleBuy sb ON sb.saleFk = s.id
|
||||||
|
LEFT JOIN vn.buy b ON b.id = sb.buyFk
|
||||||
|
LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk
|
||||||
|
WHERE s.itemFk = vItemFk
|
||||||
|
AND t.shipped BETWEEN datSTART and datEND
|
||||||
|
AND IF(vWarehouseFk = 0, w.hasComission , t.warehouseFk= vWarehouseFk)
|
||||||
|
ORDER BY t.shipped, t.id;
|
||||||
|
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -64353,7 +64495,7 @@ DELIMITER ;
|
||||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
/*!50003 DROP PROCEDURE IF EXISTS `itemTagReplace` */;
|
/*!50003 DROP PROCEDURE IF EXISTS `itemTagReplace__` */;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
@ -64363,10 +64505,12 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `itemTagReplace`(fromItemFk INT, toItemFk INT)
|
CREATE DEFINER=`root`@`%` PROCEDURE `itemTagReplace__`(fromItemFk INT, toItemFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
/*
|
||||||
|
* deprecated use itemTag_replace
|
||||||
|
*/
|
||||||
DELETE FROM itemTag
|
DELETE FROM itemTag
|
||||||
WHERE itemFk = toItemFk;
|
WHERE itemFk = toItemFk;
|
||||||
|
|
||||||
|
@ -64375,6 +64519,54 @@ BEGIN
|
||||||
FROM itemTag
|
FROM itemTag
|
||||||
WHERE itemFk = fromItemFk;
|
WHERE itemFk = fromItemFk;
|
||||||
|
|
||||||
|
END ;;
|
||||||
|
DELIMITER ;
|
||||||
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
/*!50003 DROP PROCEDURE IF EXISTS `itemTag_replace` */;
|
||||||
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
/*!50003 SET character_set_client = utf8 */ ;
|
||||||
|
/*!50003 SET character_set_results = utf8 */ ;
|
||||||
|
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
||||||
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100))
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
/* Reemplaza los tags de un artículo por los de otro, así como su imagen
|
||||||
|
*
|
||||||
|
* @param vItemFromFk id de vn.item con el artículo del que se toman los tags
|
||||||
|
* @param vItemToFk id de vn.item con el artículo del que se toman los tags
|
||||||
|
* @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk
|
||||||
|
*/
|
||||||
|
|
||||||
|
DELETE FROM vn.itemTag
|
||||||
|
WHERE itemFk = vItemToFk;
|
||||||
|
|
||||||
|
INSERT INTO vn.itemTag(itemFk, tagFk, value, priority)
|
||||||
|
SELECT vItemToFk, tagFk, value, priority
|
||||||
|
FROM vn.itemTag
|
||||||
|
WHERE itemFk = vItemFromFk;
|
||||||
|
|
||||||
|
IF ISNULL(vPicture) THEN
|
||||||
|
|
||||||
|
SELECT image INTO vPicture
|
||||||
|
FROM vn.item
|
||||||
|
WHERE id = vItemFromFk;
|
||||||
|
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
UPDATE vn.item i
|
||||||
|
SET i.image = vPicture
|
||||||
|
WHERE i.id = vItemToFk;
|
||||||
|
|
||||||
|
CALL vn.itemRefreshTags(vItemToFk);
|
||||||
|
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -65072,7 +65264,7 @@ BEGIN
|
||||||
LEFT JOIN itemTag it1 ON it1.priority = 1 AND it1.itemFk = i.id
|
LEFT JOIN itemTag it1 ON it1.priority = 1 AND it1.itemFk = i.id
|
||||||
LEFT JOIN tagAbbreviation ta1 ON ta1.`value` = it1.`value`
|
LEFT JOIN tagAbbreviation ta1 ON ta1.`value` = it1.`value`
|
||||||
LEFT JOIN itemTag it2 ON it2.priority = 2 AND it2.itemFk = i.id
|
LEFT JOIN itemTag it2 ON it2.priority = 2 AND it2.itemFk = i.id
|
||||||
LEFT JOIN tagAbbreviation ta2 ON ta2.`value` = it2.`value`
|
LEFT JOIN tagAbbreviation ta2 ON ta2.`value` = it2.`value` AND ta2.`value` != 'Rosa'
|
||||||
LEFT JOIN itemTag it3 ON it3.priority = 3 AND it3.itemFk = i.id
|
LEFT JOIN itemTag it3 ON it3.priority = 3 AND it3.itemFk = i.id
|
||||||
LEFT JOIN tagAbbreviation ta3 ON ta3.`value` = it3.`value`
|
LEFT JOIN tagAbbreviation ta3 ON ta3.`value` = it3.`value`
|
||||||
SET i.`name` = CONCAT_WS(' ',
|
SET i.`name` = CONCAT_WS(' ',
|
||||||
|
@ -65563,13 +65755,17 @@ BEGIN
|
||||||
|
|
||||||
SELECT ga.itemFk INTO vGenericFk
|
SELECT ga.itemFk INTO vGenericFk
|
||||||
FROM vn.genericAllocation ga
|
FROM vn.genericAllocation ga
|
||||||
JOIN vn.item i ON i.typeFk = ga.typeFk OR ISNULL(ga.typeFk)
|
JOIN vn.item i ON (i.typeFk = ga.typeFk OR ISNULL(ga.typeFk))
|
||||||
JOIN vn.itemTag it1 ON it1.itemFk = i.id AND (it1.value = ga.origin OR ISNULL(ga.origin))
|
JOIN vn.itemTag it1 ON it1.itemFk = i.id AND (it1.value = ga.origin OR ISNULL(ga.origin))
|
||||||
JOIN vn.itemTag it2 ON it2.itemFk = i.id AND (it2.value = ga.color OR ISNULL(ga.color))
|
JOIN vn.itemTag it2 ON it2.itemFk = i.id AND (it2.value = ga.color OR ISNULL(ga.color))
|
||||||
JOIN vn.itemTag it3 ON it3.itemFk = i.id AND (it3.value = ga.quality OR ISNULL(ga.quality))
|
JOIN vn.itemTag it3 ON it3.itemFk = i.id AND (it3.value = ga.quality OR ISNULL(ga.quality))
|
||||||
JOIN vn.itemTag it4 ON it4.itemFk = i.id AND (it4.value = ga.numFlores OR ISNULL(ga.numFlores))
|
JOIN vn.itemTag it4 ON it4.itemFk = i.id AND (it4.value = ga.numFlores OR ISNULL(ga.numFlores))
|
||||||
|
JOIN vn.itemTag it5 ON it5.itemFk = i.id AND (it5.value = ga.category OR ISNULL(ga.category))
|
||||||
|
JOIN vn.itemTag it6 ON it6.itemFk = i.id AND (it6.value = ga.productor OR ISNULL(ga.productor))
|
||||||
WHERE i.id = vSelf
|
WHERE i.id = vSelf
|
||||||
AND NOT i.isFloramondo;
|
AND ga.itemFk != vSelf
|
||||||
|
AND NOT i.isFloramondo
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
UPDATE vn.item
|
UPDATE vn.item
|
||||||
SET genericFk = vGenericFk
|
SET genericFk = vGenericFk
|
||||||
|
@ -70469,15 +70665,20 @@ DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT)
|
CREATE DEFINER=`root`@`%` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
DECLARE isFood BOOLEAN;
|
/* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad
|
||||||
|
*
|
||||||
IF (SELECT COUNT(*)
|
* @param vSaleFk clave primaria de vn.sale
|
||||||
|
* @param vBuyFk clave primaria de vn.buy
|
||||||
|
*/
|
||||||
|
/*IF (SELECT COUNT(*)
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
JOIN vn.item i ON i.id = s.itemFk
|
JOIN vn.item i ON i.id = s.itemFk
|
||||||
JOIN vn.itemType it ON it.id = i.typeFk
|
JOIN vn.itemType it ON it.id = i.typeFk
|
||||||
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
JOIN vn.itemCategory ic ON ic.id = it.categoryFk
|
||||||
WHERE s.id = vSaleFk
|
WHERE s.id = vSaleFk
|
||||||
AND ic.code = 'fruit') THEN
|
AND ic.code = 'fruit') THEN */
|
||||||
|
|
||||||
|
IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN
|
||||||
|
|
||||||
INSERT INTO vn.saleBuy (saleFk, buyFk)
|
INSERT INTO vn.saleBuy (saleFk, buyFk)
|
||||||
VALUES(vSaleFk, vBuyFk);
|
VALUES(vSaleFk, vBuyFk);
|
||||||
|
@ -72322,6 +72523,36 @@ BEGIN
|
||||||
SELECT * FROM tmp.result
|
SELECT * FROM tmp.result
|
||||||
ORDER BY created, visible;
|
ORDER BY created, visible;
|
||||||
|
|
||||||
|
END ;;
|
||||||
|
DELIMITER ;
|
||||||
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
/*!50003 DROP PROCEDURE IF EXISTS `shelvingLog_get` */;
|
||||||
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `shelvingLog_get`(shelvingFk VARCHAR(10))
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
/* Lista el log de un carro
|
||||||
|
*
|
||||||
|
* @param shelvingFk matrícula del carro
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
SELECT originFk, name, creationDate, description
|
||||||
|
FROM shelvingLog sl
|
||||||
|
JOIN user u ON u.id = sl.userFk
|
||||||
|
WHERE sl.originFk = shelvingFk COLLATE utf8_general_ci;
|
||||||
|
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -72382,6 +72613,12 @@ proc: BEGIN
|
||||||
|
|
||||||
ELSE
|
ELSE
|
||||||
|
|
||||||
|
INSERT INTO vn.shelvingLog (originFk, userFk, action , description)
|
||||||
|
SELECT vShelvingFk, getUser(), 'update', CONCAT("Cambio parking ",vShelvingFk," de ", p.code," a ", vParkingCode)
|
||||||
|
FROM parking p
|
||||||
|
JOIN shelving s ON s.parkingFk = p.id
|
||||||
|
WHERE s.code = vShelvingFk COLLATE utf8_unicode_ci;
|
||||||
|
|
||||||
UPDATE vn.shelving
|
UPDATE vn.shelving
|
||||||
SET parkingFk = vParkingFk, parked = NOW(), isPrinted = 1
|
SET parkingFk = vParkingFk, parked = NOW(), isPrinted = 1
|
||||||
WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
|
WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci;
|
||||||
|
@ -74541,7 +74778,7 @@ BEGIN
|
||||||
AND sc.componentFk = tc.componentFk
|
AND sc.componentFk = tc.componentFk
|
||||||
LEFT JOIN `component` c ON c.id = tc.componentFk
|
LEFT JOIN `component` c ON c.id = tc.componentFk
|
||||||
WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE);
|
WHERE IF(sc.componentFk IS NULL AND NOT c.isRenewable, FALSE, TRUE);
|
||||||
/*
|
|
||||||
-- Añadir componente venta por paquete
|
-- Añadir componente venta por paquete
|
||||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale2;
|
DROP TEMPORARY TABLE IF EXISTS tmp.sale2;
|
||||||
CREATE TEMPORARY TABLE tmp.sale2
|
CREATE TEMPORARY TABLE tmp.sale2
|
||||||
|
@ -74576,7 +74813,7 @@ BEGIN
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS
|
DROP TEMPORARY TABLE IF EXISTS
|
||||||
tmp.sale2,
|
tmp.sale2,
|
||||||
tmp.ticketComponent2;*/
|
tmp.ticketComponent2;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
IF vKeepPrices THEN
|
IF vKeepPrices THEN
|
||||||
|
@ -76133,6 +76370,45 @@ BEGIN
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
END ;;
|
||||||
|
DELIMITER ;
|
||||||
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
|
/*!50003 DROP PROCEDURE IF EXISTS `ticketStateToday_setOnPreviousChecking` */;
|
||||||
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
/*!50003 SET character_set_client = utf8mb4 */ ;
|
||||||
|
/*!50003 SET character_set_results = utf8mb4 */ ;
|
||||||
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
DELIMITER ;;
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `ticketStateToday_setOnPreviousChecking`(vParamFk INT)
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cambia el estado del ticket al estado de "control previa"
|
||||||
|
*
|
||||||
|
* @param vParamFk ticket a cambiar el estado
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
DECLARE vAlertLevel INT;
|
||||||
|
|
||||||
|
SELECT s.alertLevel INTO vAlertLevel
|
||||||
|
FROM state s
|
||||||
|
JOIN ticketStateToday tst ON tst.state = s.id
|
||||||
|
WHERE tst.ticket = vParamFk
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
IF vAlertLevel < 2 THEN
|
||||||
|
|
||||||
|
CALL ticketStateUpdate(vParamFk, 'PREVIOUS_CONTROL');
|
||||||
|
|
||||||
|
END IF;
|
||||||
|
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -77131,9 +77407,9 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
/*!50003 SET character_set_client = utf8mb4 */ ;
|
/*!50003 SET character_set_client = utf8 */ ;
|
||||||
/*!50003 SET character_set_results = utf8mb4 */ ;
|
/*!50003 SET character_set_results = utf8 */ ;
|
||||||
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
|
@ -82229,7 +82505,7 @@ DELIMITER ;
|
||||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlNonDays` */;
|
/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlNonDays__` */;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
@ -82239,7 +82515,7 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlNonDays`()
|
CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlNonDays__`()
|
||||||
BEGIN
|
BEGIN
|
||||||
SET @cont := 0;
|
SET @cont := 0;
|
||||||
SELECT sub2.userFk, sub2.dated Fecha, CONCAT (w.firstName," ", w.lastName) worker, au.name Boss, d.name
|
SELECT sub2.userFk, sub2.dated Fecha, CONCAT (w.firstName," ", w.lastName) worker, au.name Boss, d.name
|
||||||
|
@ -84080,7 +84356,7 @@ BEGIN
|
||||||
GROUP BY tm.userFk,t.dated
|
GROUP BY tm.userFk,t.dated
|
||||||
ORDER BY tm.userFk,t.dated;
|
ORDER BY tm.userFk,t.dated;
|
||||||
|
|
||||||
-- INSERT INTO vn.mail (receiver, replyTo, subject, body)
|
INSERT INTO vn.mail (receiver, replyTo, subject, body)
|
||||||
SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(CURDATE())-1, ' año ', YEAR(CURDATE())) ,
|
SELECT eu.email, 'laboral@verdnatura.es', CONCAT('Registro de horas semana ', WEEK(CURDATE())-1, ' año ', YEAR(CURDATE())) ,
|
||||||
CONCAT('
|
CONCAT('
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -87525,9 +87801,9 @@ DELIMITER ;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
/*!50003 SET character_set_client = utf8mb4 */ ;
|
/*!50003 SET character_set_client = utf8 */ ;
|
||||||
/*!50003 SET character_set_results = utf8mb4 */ ;
|
/*!50003 SET character_set_results = utf8 */ ;
|
||||||
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
/*!50003 SET collation_connection = utf8_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
|
@ -87536,11 +87812,31 @@ DELIMITER ;;
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
DECLARE vNumTicketsPrepared INT;
|
||||||
|
|
||||||
REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
|
REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name)
|
||||||
SELECT NEW.Id_Ticket, NEW.inter_id, `name`
|
SELECT NEW.Id_Ticket, NEW.inter_id, `name`
|
||||||
FROM vn.state
|
FROM vn.state
|
||||||
WHERE id = NEW.state_id;
|
WHERE id = NEW.state_id;
|
||||||
|
/*
|
||||||
|
SELECT count(*) INTO vNumTicketsPrepared
|
||||||
|
FROM vn.ticketCollection tc2
|
||||||
|
JOIN vn.ticketState ts2 ON ts2.ticketFk = tc2.ticketFk
|
||||||
|
WHERE tc2.collectionFk IN
|
||||||
|
(SELECT tc.collectionFk
|
||||||
|
FROM vn.ticketCollection tc
|
||||||
|
WHERE tc.ticketFk IN
|
||||||
|
(SELECT ts.ticketFk
|
||||||
|
FROM vn.ticketState ts
|
||||||
|
WHERE code = 'ON_PREPARATION'
|
||||||
|
)
|
||||||
|
AND tc.collectionFk IN (SELECT collectionFk FROM vn.ticketCollection WHERE ticketFk = NEW.Id_Ticket));
|
||||||
|
|
||||||
|
IF vNumTicketsPrepared = 0 THEN
|
||||||
|
UPDATE vn.collection SET stateFk = (SELECT id FROM vn.state WHERE code = 'ON_CHECKING')
|
||||||
|
WHERE id = (SELECT tc.collectionFk FROM vn.ticketCollection tc WHERE tc.ticketFk = NEW.Id_Ticket);
|
||||||
|
END IF;
|
||||||
|
*/
|
||||||
END */;;
|
END */;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
|
@ -91030,7 +91326,7 @@ USE `vn`;
|
||||||
/*!50001 SET collation_connection = utf8_general_ci */;
|
/*!50001 SET collation_connection = utf8_general_ci */;
|
||||||
/*!50001 CREATE ALGORITHM=UNDEFINED */
|
/*!50001 CREATE ALGORITHM=UNDEFINED */
|
||||||
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
|
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
|
||||||
/*!50001 VIEW `traceabilityBuy` AS select `b`.`id` AS `buyFk`,`b`.`quantity` AS `quantity`,`tr`.`landed` AS `landed`,`w`.`name` AS `warehouseName`,`b`.`entryFk` AS `entryFk`,`s`.`name` AS `supplierName`,`b`.`itemFk` AS `itemFk` from ((((`buy` `b` join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) */;
|
/*!50001 VIEW `traceabilityBuy` AS select `b`.`id` AS `buyFk`,`b`.`quantity` AS `quantity`,`tr`.`landed` AS `landed`,`w`.`name` AS `warehouseName`,`b`.`entryFk` AS `entryFk`,`s`.`name` AS `supplierName`,ifnull(`b`.`itemOriginalFk`,`b`.`itemFk`) AS `itemFk` from ((((`buy` `b` join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) */;
|
||||||
/*!50001 SET character_set_client = @saved_cs_client */;
|
/*!50001 SET character_set_client = @saved_cs_client */;
|
||||||
/*!50001 SET character_set_results = @saved_cs_results */;
|
/*!50001 SET character_set_results = @saved_cs_results */;
|
||||||
/*!50001 SET collation_connection = @saved_col_connection */;
|
/*!50001 SET collation_connection = @saved_col_connection */;
|
||||||
|
@ -91430,4 +91726,4 @@ USE `vncontrol`;
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2021-11-23 14:44:10
|
-- Dump completed on 2021-12-01 7:52:52
|
||||||
|
|
|
@ -557,6 +557,7 @@ export default {
|
||||||
moreMenuReserve: 'vn-item[name="reserve"]',
|
moreMenuReserve: 'vn-item[name="reserve"]',
|
||||||
moreMenuUnmarkReseved: 'vn-item[name="unreserve"]',
|
moreMenuUnmarkReseved: 'vn-item[name="unreserve"]',
|
||||||
moreMenuUpdateDiscount: 'vn-item[name="discount"]',
|
moreMenuUpdateDiscount: 'vn-item[name="discount"]',
|
||||||
|
moreMenuRecalculatePrice: 'vn-item[name="calculatePrice"]',
|
||||||
moreMenuUpdateDiscountInput: 'vn-input-number[ng-model="$ctrl.edit.discount"] input',
|
moreMenuUpdateDiscountInput: 'vn-input-number[ng-model="$ctrl.edit.discount"] input',
|
||||||
transferQuantityInput: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable > span > text',
|
transferQuantityInput: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable > span > text',
|
||||||
transferQuantityCell: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable',
|
transferQuantityCell: '.vn-popover.shown vn-table > div > vn-tbody > vn-tr > vn-td-editable',
|
||||||
|
|
|
@ -195,6 +195,17 @@ describe('Ticket Edit sale path', () => {
|
||||||
expect(result).toContain('22.50');
|
expect(result).toContain('22.50');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should recalculate price of sales', async() => {
|
||||||
|
await page.waitToClick(selectors.ticketSales.firstSaleCheckbox);
|
||||||
|
await page.waitToClick(selectors.ticketSales.secondSaleCheckbox);
|
||||||
|
|
||||||
|
await page.waitToClick(selectors.ticketSales.moreMenu);
|
||||||
|
await page.waitToClick(selectors.ticketSales.moreMenuRecalculatePrice);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toContain('Data saved!');
|
||||||
|
});
|
||||||
|
|
||||||
it('should select the third sale and create a claim of it', async() => {
|
it('should select the third sale and create a claim of it', async() => {
|
||||||
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
await page.waitToClick(selectors.ticketSales.thirdSaleCheckbox);
|
||||||
await page.waitToClick(selectors.ticketSales.moreMenu);
|
await page.waitToClick(selectors.ticketSales.moreMenu);
|
||||||
|
|
|
@ -55,8 +55,8 @@ vn-chip {
|
||||||
&.message,
|
&.message,
|
||||||
&.message.clickable:hover,
|
&.message.clickable:hover,
|
||||||
&.message.clickable:focus {
|
&.message.clickable:focus {
|
||||||
color: $color-font-dark;
|
background-color: $color-font-bg-dark;
|
||||||
background-color: $color-bg-dark;
|
color: $color-font-bg;
|
||||||
}
|
}
|
||||||
&.clickable {
|
&.clickable {
|
||||||
@extend %clickable;
|
@extend %clickable;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@import "variables";
|
@import "variables";
|
||||||
|
|
||||||
vn-label {
|
vn-label {
|
||||||
color: $color-font-secondary;
|
color: $color-font-light;
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
content: ':';
|
content: ':';
|
||||||
|
|
|
@ -94,8 +94,8 @@ smart-table table {
|
||||||
color: $color-font-bg;
|
color: $color-font-bg;
|
||||||
}
|
}
|
||||||
&.message {
|
&.message {
|
||||||
background-color: $color-bg-dark;
|
background-color: $color-font-bg-dark;
|
||||||
color: $color-font-dark;
|
color: $color-font-bg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,8 +150,8 @@ vn-table {
|
||||||
color: $color-font-bg;
|
color: $color-font-bg;
|
||||||
}
|
}
|
||||||
&.message {
|
&.message {
|
||||||
background-color: $color-bg-dark;
|
background-color: $color-font-bg-dark;
|
||||||
color: $color-font-dark;
|
color: $color-font-bg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vn-icon-menu {
|
vn-icon-menu {
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
}
|
}
|
||||||
.icon-account:before {
|
.icon-account:before {
|
||||||
content: "\e900";
|
content: "\e900";
|
||||||
color: #000;
|
|
||||||
}
|
}
|
||||||
.icon-actions:before {
|
.icon-actions:before {
|
||||||
content: "\e901";
|
content: "\e901";
|
||||||
|
@ -71,7 +70,6 @@
|
||||||
}
|
}
|
||||||
.icon-bucket:before {
|
.icon-bucket:before {
|
||||||
content: "\e90e";
|
content: "\e90e";
|
||||||
color: #000;
|
|
||||||
}
|
}
|
||||||
.icon-buscaman:before {
|
.icon-buscaman:before {
|
||||||
content: "\e90f";
|
content: "\e90f";
|
||||||
|
|
|
@ -52,8 +52,6 @@
|
||||||
"Agency cannot be blank": "La agencia no puede quedar en blanco",
|
"Agency cannot be blank": "La agencia no puede quedar en blanco",
|
||||||
"You can't make changes on a client with verified data": "No puedes hacer cambios en un cliente con datos comprobados",
|
"You can't make changes on a client with verified data": "No puedes hacer cambios en un cliente con datos comprobados",
|
||||||
"This address doesn't exist": "Este consignatario no existe",
|
"This address doesn't exist": "Este consignatario no existe",
|
||||||
"You can't create an order for a inactive client": "You can't create an order for a inactive client",
|
|
||||||
"You can't create an order for a client that doesn't has tax data verified": "You can't create an order for a client that doesn't has tax data verified",
|
|
||||||
"You must delete the claim id %d first": "Antes debes borrar la reclamación %d",
|
"You must delete the claim id %d first": "Antes debes borrar la reclamación %d",
|
||||||
"You don't have enough privileges": "No tienes suficientes permisos",
|
"You don't have enough privileges": "No tienes suficientes permisos",
|
||||||
"Cannot check Equalization Tax in this NIF/CIF": "No se puede marcar RE en este NIF/CIF",
|
"Cannot check Equalization Tax in this NIF/CIF": "No se puede marcar RE en este NIF/CIF",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('entry addBuy()', () => {
|
describe('entry addBuy()', () => {
|
||||||
|
@ -25,11 +25,11 @@ describe('entry addBuy()', () => {
|
||||||
packageFk: 3
|
packageFk: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
const tx = await app.models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newBuy = await app.models.Entry.addBuy(ctx, options);
|
const newBuy = await models.Entry.addBuy(ctx, options);
|
||||||
|
|
||||||
expect(newBuy.itemFk).toEqual(itemId);
|
expect(newBuy.itemFk).toEqual(itemId);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('sale deleteBuys()', () => {
|
describe('sale deleteBuys()', () => {
|
||||||
|
@ -15,13 +15,13 @@ describe('sale deleteBuys()', () => {
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
|
|
||||||
const tx = await app.models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
ctx.args = {buys: [{id: 1}]};
|
ctx.args = {buys: [{id: 1}]};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await app.models.Buy.deleteBuys(ctx, options);
|
const result = await models.Buy.deleteBuys(ctx, options);
|
||||||
|
|
||||||
expect(result).toEqual([{count: 1}]);
|
expect(result).toEqual([{count: 1}]);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const model = app.models.Buy;
|
|
||||||
|
|
||||||
describe('Buy editLatestsBuys()', () => {
|
describe('Buy editLatestsBuys()', () => {
|
||||||
it('should change the value of a given column for the selected buys', async() => {
|
it('should change the value of a given column for the selected buys', async() => {
|
||||||
const tx = await app.models.Entry.beginTransaction({});
|
const tx = await models.Buy.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -13,15 +12,15 @@ describe('Buy editLatestsBuys()', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [original] = await model.latestBuysFilter(ctx, null, options);
|
const [original] = await models.Buy.latestBuysFilter(ctx, null, options);
|
||||||
|
|
||||||
const field = 'size';
|
const field = 'size';
|
||||||
const newValue = 99;
|
const newValue = 99;
|
||||||
const lines = [{itemFk: original.itemFk, id: original.id}];
|
const lines = [{itemFk: original.itemFk, id: original.id}];
|
||||||
|
|
||||||
await model.editLatestBuys(field, newValue, lines, options);
|
await models.Buy.editLatestBuys(field, newValue, lines, options);
|
||||||
|
|
||||||
const [result] = await model.latestBuysFilter(ctx, null, options);
|
const [result] = await models.Buy.latestBuysFilter(ctx, null, options);
|
||||||
|
|
||||||
expect(result[field]).toEqual(newValue);
|
expect(result[field]).toEqual(newValue);
|
||||||
|
|
||||||
|
|
|
@ -1,77 +1,137 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Entry filter()', () => {
|
describe('Entry filter()', () => {
|
||||||
it('should return the entry matching "search"', async() => {
|
it('should return the entry matching "search"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
search: 1
|
search: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
expect(result[0].id).toEqual(1);
|
expect(result[0].id).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entry matching the currency', async() => {
|
it('should return the entry matching the currency', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
currencyFk: 1
|
currencyFk: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(8);
|
expect(result.length).toEqual(8);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entry matching the supplier', async() => {
|
it('should return the entry matching the supplier', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
supplierFk: 2
|
supplierFk: 2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(6);
|
expect(result.length).toEqual(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entry matching the company', async() => {
|
it('should return the entry matching the company', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
companyFk: 442
|
companyFk: 442
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(7);
|
expect(result.length).toEqual(7);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entries matching isBooked', async() => {
|
it('should return the entries matching isBooked', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
isBooked: true,
|
isBooked: true,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the routes matching the reference and travel', async() => {
|
it('should return the routes matching the reference and travel', async() => {
|
||||||
let ctx = {
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
reference: 'movement',
|
reference: 'movement',
|
||||||
travelFk: '2'
|
travelFk: '2'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = await app.models.Entry.filter(ctx);
|
const result = await models.Entry.filter(ctx, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('entry getBuys()', () => {
|
describe('entry getBuys()', () => {
|
||||||
const entryId = 4;
|
const entryId = 4;
|
||||||
it('should get the buys and items of an entry', async() => {
|
it('should get the buys and items of an entry', async() => {
|
||||||
const result = await app.models.Entry.getBuys(entryId);
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await models.Entry.getBuys(entryId, options);
|
||||||
|
|
||||||
const length = result.length;
|
const length = result.length;
|
||||||
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
const anyResult = result[Math.floor(Math.random() * Math.floor(length))];
|
||||||
|
|
||||||
expect(result.length).toEqual(4);
|
expect(result.length).toEqual(4);
|
||||||
expect(anyResult.item).toBeDefined();
|
expect(anyResult.item).toBeDefined();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,31 +1,71 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('travel getEntry()', () => {
|
describe('travel getEntry()', () => {
|
||||||
const entryId = 1;
|
const entryId = 1;
|
||||||
it('should check the entry contains the id', async() => {
|
it('should check the entry contains the id', async() => {
|
||||||
const entry = await app.models.Entry.getEntry(entryId);
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.getEntry(entryId, options);
|
||||||
|
|
||||||
expect(entry.id).toEqual(entryId);
|
expect(entry.id).toEqual(entryId);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the entry contains the supplier name', async() => {
|
it('should check the entry contains the supplier name', async() => {
|
||||||
const entry = await app.models.Entry.getEntry(entryId);
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.getEntry(entryId, options);
|
||||||
const supplierName = entry.supplier().nickname;
|
const supplierName = entry.supplier().nickname;
|
||||||
|
|
||||||
expect(supplierName).toEqual('Plants nick');
|
expect(supplierName).toEqual('Plants nick');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the entry contains the receiver warehouse name', async() => {
|
it('should check the entry contains the receiver warehouse name', async() => {
|
||||||
const entry = await app.models.Entry.getEntry(entryId);
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.getEntry(entryId, options);
|
||||||
const receiverWarehouseName = entry.travel().warehouseIn().name;
|
const receiverWarehouseName = entry.travel().warehouseIn().name;
|
||||||
|
|
||||||
expect(receiverWarehouseName).toEqual('Warehouse One');
|
expect(receiverWarehouseName).toEqual('Warehouse One');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the entry contains the company code', async() => {
|
it('should check the entry contains the company code', async() => {
|
||||||
const entry = await app.models.Entry.getEntry(entryId);
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entry = await models.Entry.getEntry(entryId, options);
|
||||||
const companyCode = entry.company().code;
|
const companyCode = entry.company().code;
|
||||||
|
|
||||||
expect(companyCode).toEqual('VNL');
|
expect(companyCode).toEqual('VNL');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('entry import()', () => {
|
describe('entry import()', () => {
|
||||||
|
@ -48,10 +48,10 @@ describe('entry import()', () => {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const tx = await app.models.Entry.beginTransaction({});
|
const tx = await models.Entry.beginTransaction({});
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const newEntry = await app.models.Entry.create({
|
const newEntry = await models.Entry.create({
|
||||||
dated: new Date(),
|
dated: new Date(),
|
||||||
supplierFk: supplierId,
|
supplierFk: supplierId,
|
||||||
travelFk: travelId,
|
travelFk: travelId,
|
||||||
|
@ -60,10 +60,10 @@ describe('entry import()', () => {
|
||||||
ref: 'Entry ref'
|
ref: 'Entry ref'
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
await app.models.Entry.importBuys(ctx, newEntry.id, options);
|
await models.Entry.importBuys(ctx, newEntry.id, options);
|
||||||
|
|
||||||
const updatedEntry = await app.models.Entry.findById(newEntry.id, null, options);
|
const updatedEntry = await models.Entry.findById(newEntry.id, null, options);
|
||||||
const entryBuys = await app.models.Buy.find({
|
const entryBuys = await models.Buy.find({
|
||||||
where: {entryFk: newEntry.id}
|
where: {entryFk: newEntry.id}
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('entry importBuysPreview()', () => {
|
describe('entry importBuysPreview()', () => {
|
||||||
|
@ -10,6 +10,10 @@ describe('entry importBuysPreview()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the buys with the calculated packageFk', async() => {
|
it('should return the buys with the calculated packageFk', async() => {
|
||||||
|
const tx = await models.Entry.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
const expectedPackageFk = '3';
|
const expectedPackageFk = '3';
|
||||||
const buys = [
|
const buys = [
|
||||||
{
|
{
|
||||||
|
@ -30,10 +34,16 @@ describe('entry importBuysPreview()', () => {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const result = await app.models.Entry.importBuysPreview(entryId, buys);
|
const result = await models.Entry.importBuysPreview(entryId, buys, options);
|
||||||
const randomIndex = Math.floor(Math.random() * result.length);
|
const randomIndex = Math.floor(Math.random() * result.length);
|
||||||
const buy = result[randomIndex];
|
const buy = result[randomIndex];
|
||||||
|
|
||||||
expect(buy.packageFk).toEqual(expectedPackageFk);
|
expect(buy.packageFk).toEqual(expectedPackageFk);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,34 +1,58 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Buy latests buys filter()', () => {
|
describe('Buy latests buys filter()', () => {
|
||||||
it('should return the entry matching "search"', async() => {
|
it('should return the entry matching "search"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
search: 'Ranged weapon longbow 2m'
|
search: 'Ranged weapon longbow 2m'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx);
|
||||||
let firstBuy = results[0];
|
const firstBuy = results[0];
|
||||||
|
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
expect(firstBuy.size).toEqual(70);
|
expect(firstBuy.size).toEqual(70);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the entry matching "id"', async() => {
|
it('should return the entry matching "id"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
id: 1
|
id: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toEqual(1);
|
expect(results.length).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "tags"', async() => {
|
it('should return results matching "tags"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
tags: [
|
tags: [
|
||||||
{tagFk: 27, value: '2m'}
|
{tagFk: 27, value: '2m'}
|
||||||
|
@ -36,160 +60,286 @@ describe('Buy latests buys filter()', () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(2);
|
expect(results.length).toBe(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "categoryFk"', async() => {
|
it('should return results matching "categoryFk"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
categoryFk: 1
|
categoryFk: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(4);
|
expect(results.length).toBe(4);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "typeFk"', async() => {
|
it('should return results matching "typeFk"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
typeFk: 2
|
typeFk: 2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(4);
|
expect(results.length).toBe(4);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "active"', async() => {
|
it('should return results matching "active"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
active: true
|
active: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(6);
|
expect(results.length).toBe(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "not active"', async() => {
|
it('should return results matching "not active"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
active: false
|
active: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(0);
|
expect(results.length).toBe(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "visible"', async() => {
|
it('should return results matching "visible"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
visible: true
|
visible: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(5);
|
expect(results.length).toBe(5);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "not visible"', async() => {
|
it('should return results matching "not visible"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
visible: false
|
visible: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(0);
|
expect(results.length).toBe(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "floramondo"', async() => {
|
it('should return results matching "floramondo"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
floramondo: true
|
floramondo: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(1);
|
expect(results.length).toBe(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "not floramondo"', async() => {
|
it('should return results matching "not floramondo"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
floramondo: false
|
floramondo: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(5);
|
expect(results.length).toBe(5);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "salesPersonFk"', async() => {
|
it('should return results matching "salesPersonFk"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
salesPersonFk: 35
|
salesPersonFk: 35
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(6);
|
expect(results.length).toBe(6);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "description"', async() => {
|
it('should return results matching "description"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
description: 'Increases block'
|
description: 'Increases block'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(1);
|
expect(results.length).toBe(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "supplierFk"', async() => {
|
it('should return results matching "supplierFk"', async() => {
|
||||||
let ctx = {
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
supplierFk: 1
|
supplierFk: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(2);
|
expect(results.length).toBe(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return results matching "from" and "to"', async() => {
|
it('should return results matching "from" and "to"', async() => {
|
||||||
|
const tx = await models.Buy.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
const from = new Date();
|
const from = new Date();
|
||||||
from.setHours(0, 0, 0, 0);
|
from.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
const to = new Date();
|
const to = new Date();
|
||||||
to.setHours(23, 59, 59, 999);
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
let ctx = {
|
const ctx = {
|
||||||
args: {
|
args: {
|
||||||
from: from,
|
from: from,
|
||||||
to: to
|
to: to
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let results = await app.models.Buy.latestBuysFilter(ctx);
|
const results = await models.Buy.latestBuysFilter(ctx, options);
|
||||||
|
|
||||||
expect(results.length).toBe(2);
|
expect(results.length).toBe(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ module.exports = Self => {
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.filter');
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`CREATE TEMPORARY TABLE tmp.filter
|
`CREATE TEMPORARY TABLE tmp.filter
|
||||||
(INDEX (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT
|
SELECT
|
||||||
t.id,
|
t.id,
|
||||||
|
@ -221,7 +221,7 @@ module.exports = Self => {
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt');
|
||||||
stmts.push(`
|
stmts.push(`
|
||||||
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
||||||
(INDEX (clientFk))
|
(PRIMARY KEY (clientFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT DISTINCT clientFk FROM tmp.filter`);
|
SELECT DISTINCT clientFk FROM tmp.filter`);
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ module.exports = Self => {
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.tickets');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.tickets');
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
CREATE TEMPORARY TABLE tmp.tickets
|
CREATE TEMPORARY TABLE tmp.tickets
|
||||||
(INDEX (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT f.*, r.risk AS debt
|
SELECT f.*, r.risk AS debt
|
||||||
FROM tmp.filter f
|
FROM tmp.filter f
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="SalesMonitors/salesFilter"
|
url="SalesMonitors/salesFilter"
|
||||||
limit="20"
|
limit="20"
|
||||||
order="shippedDate DESC, preparationHour ASC, zoneLanding ASC, id">
|
order="shippedDate DESC, theoreticalhour, id">
|
||||||
</vn-crud-model>
|
</vn-crud-model>
|
||||||
<vn-portal slot="topbar">
|
<vn-portal slot="topbar">
|
||||||
<vn-searchbar
|
<vn-searchbar
|
||||||
|
@ -167,7 +167,7 @@
|
||||||
{{::ticket.state}}
|
{{::ticket.state}}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td name="zone">
|
||||||
<span
|
<span
|
||||||
title="{{::ticket.zoneName}}"
|
title="{{::ticket.zoneName}}"
|
||||||
vn-click-stop="zoneDescriptor.show($event, ticket.zoneFk)"
|
vn-click-stop="zoneDescriptor.show($event, ticket.zoneFk)"
|
||||||
|
|
|
@ -36,4 +36,12 @@ vn-monitor-sales-tickets {
|
||||||
.highRisk i {
|
.highRisk i {
|
||||||
color: $color-alert
|
color: $color-alert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td[name="nickname"] {
|
||||||
|
max-width: 200px
|
||||||
|
}
|
||||||
|
|
||||||
|
td[name="zone"] {
|
||||||
|
max-width: 150px
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,22 +21,42 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.addToOrder = async params => {
|
Self.addToOrder = async(params, options) => {
|
||||||
let isEditable = await Self.app.models.Order.isEditable(params.orderFk);
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const isEditable = await Self.app.models.Order.isEditable(params.orderFk, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
throw new UserError('This order is not editable');
|
throw new UserError('This order is not editable');
|
||||||
|
|
||||||
let promises = [];
|
const promises = [];
|
||||||
params.items.forEach(item => {
|
for (const item of params.items) {
|
||||||
promises.push(
|
promises.push(
|
||||||
Self.rawSql(
|
Self.rawSql(
|
||||||
`CALL hedera.order_addItem(?, ?, ?, ?)`,
|
`CALL hedera.order_addItem(?, ?, ?, ?)`,
|
||||||
[params.orderFk, item.warehouseFk, item.itemFk, item.quantity]
|
[params.orderFk, item.warehouseFk, item.itemFk, item.quantity],
|
||||||
|
myOptions
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,19 +21,39 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removes = async params => {
|
Self.removes = async(params, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
if (!params.rows || !params.rows.length)
|
if (!params.rows || !params.rows.length)
|
||||||
throw new UserError('There is nothing to delete');
|
throw new UserError('There is nothing to delete');
|
||||||
|
|
||||||
let isEditable = await Self.app.models.Order.isEditable(params.actualOrderId);
|
const isEditable = await Self.app.models.Order.isEditable(params.actualOrderId, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
throw new UserError('This order is not editable');
|
throw new UserError('This order is not editable');
|
||||||
|
|
||||||
let promises = [];
|
const promises = [];
|
||||||
for (let i = 0; i < params.rows.length; i++)
|
for (let i = 0; i < params.rows.length; i++)
|
||||||
promises.push(Self.app.models.OrderRow.destroyById(params.rows[i]));
|
promises.push(Self.app.models.OrderRow.destroyById(params.rows[i], myOptions));
|
||||||
|
|
||||||
return await Promise.all(promises);
|
const deletions = await Promise.all(promises);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return deletions;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order addToOrder()', () => {
|
describe('order addToOrder()', () => {
|
||||||
const orderId = 8;
|
const orderId = 8;
|
||||||
let rowToDelete;
|
|
||||||
afterAll(async() => {
|
|
||||||
await app.models.OrderRow.removes({rows: [rowToDelete], actualOrderId: orderId});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should add a row to a given order', async() => {
|
it('should add a row to a given order', async() => {
|
||||||
let unmodifiedRows = await app.models.OrderRow.find({where: {orderFk: orderId}});
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const unmodifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
|
||||||
|
|
||||||
expect(unmodifiedRows.length).toBe(2);
|
expect(unmodifiedRows.length).toBe(2);
|
||||||
|
|
||||||
let params = {
|
const params = {
|
||||||
orderFk: orderId,
|
orderFk: orderId,
|
||||||
items: [{
|
items: [{
|
||||||
itemFk: 1,
|
itemFk: 1,
|
||||||
|
@ -21,12 +21,16 @@ describe('order addToOrder()', () => {
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
await app.models.OrderRow.addToOrder(params);
|
await models.OrderRow.addToOrder(params, options);
|
||||||
|
|
||||||
let modifiedRows = await app.models.OrderRow.find({where: {orderFk: orderId}});
|
const modifiedRows = await models.OrderRow.find({where: {orderFk: orderId}}, options);
|
||||||
|
|
||||||
rowToDelete = modifiedRows[modifiedRows.length - 1].id;
|
|
||||||
|
|
||||||
expect(modifiedRows.length).toBe(3);
|
expect(modifiedRows.length).toBe(3);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order removes()', () => {
|
describe('order removes()', () => {
|
||||||
let row;
|
|
||||||
let newRow;
|
|
||||||
|
|
||||||
beforeAll(async() => {
|
|
||||||
row = await app.models.OrderRow.findOne({where: {id: 12}});
|
|
||||||
row.id = null;
|
|
||||||
newRow = await app.models.OrderRow.create(row);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if rows property is empty', async() => {
|
it('should throw an error if rows property is empty', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
await app.models.OrderRow.removes({rows: []});
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
await models.OrderRow.removes({rows: []}, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +20,17 @@ describe('order removes()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if the row selected is not editable', async() => {
|
it('should throw an error if the row selected is not editable', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
try {
|
try {
|
||||||
await app.models.OrderRow.removes({rows: [2]});
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
await models.OrderRow.removes({rows: [2]}, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,13 +38,24 @@ describe('order removes()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete the row', async() => {
|
it('should delete the row', async() => {
|
||||||
let params = {
|
const tx = await models.Order.beginTransaction({});
|
||||||
rows: [newRow.id],
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
rows: [12],
|
||||||
actualOrderId: 16
|
actualOrderId: 16
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = await app.models.OrderRow.removes(params);
|
const res = await models.OrderRow.removes(params, options);
|
||||||
|
|
||||||
expect(res).toEqual([{count: 1}]);
|
expect(res).toEqual([{count: 1}]);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,28 +7,28 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'orderFk',
|
arg: 'orderFk',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'orderBy',
|
arg: 'orderBy',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
description: 'Items order',
|
description: 'Items order',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'tagGroups',
|
arg: 'tagGroups',
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
description: 'Filter by tag'
|
description: 'Filter by tag'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
root: true,
|
root: true,
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -37,8 +37,13 @@ module.exports = Self => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.catalogFilter = async(orderFk, orderBy, filter, tagGroups) => {
|
Self.catalogFilter = async(orderFk, orderBy, filter, tagGroups, options) => {
|
||||||
let conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
|
@ -85,7 +90,7 @@ module.exports = Self => {
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
// Calculate items
|
// Calculate items
|
||||||
const order = await Self.findById(orderFk);
|
const order = await Self.findById(orderFk, null, myOptions);
|
||||||
stmts.push(new ParameterizedSQL(
|
stmts.push(new ParameterizedSQL(
|
||||||
'CALL vn.catalog_calculate(?, ?, ?)', [
|
'CALL vn.catalog_calculate(?, ?, ?)', [
|
||||||
order.landed,
|
order.landed,
|
||||||
|
@ -131,9 +136,9 @@ module.exports = Self => {
|
||||||
params: [orderBy.field],
|
params: [orderBy.field],
|
||||||
});
|
});
|
||||||
|
|
||||||
let way = orderBy.way == 'DESC' ? 'DESC' : 'ASC';
|
const way = orderBy.way == 'DESC' ? 'DESC' : 'ASC';
|
||||||
let tag = await Self.app.models.Tag.findById(orderBy.field);
|
const tag = await Self.app.models.Tag.findById(orderBy.field, null, myOptions);
|
||||||
let orderSql = `
|
const orderSql = `
|
||||||
ORDER BY
|
ORDER BY
|
||||||
itg.value IS NULL,
|
itg.value IS NULL,
|
||||||
${tag.isQuantitative ? 'CAST(itg.value AS SIGNED)' : 'itg.value'}
|
${tag.isQuantitative ? 'CAST(itg.value AS SIGNED)' : 'itg.value'}
|
||||||
|
@ -181,7 +186,7 @@ module.exports = Self => {
|
||||||
stmts.push('CALL vn.ticketCalculatePurge()');
|
stmts.push('CALL vn.ticketCalculatePurge()');
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await conn.executeStmt(sql);
|
const result = await conn.executeStmt(sql, myOptions);
|
||||||
|
|
||||||
// Add prices to items
|
// Add prices to items
|
||||||
result[itemsIndex].forEach(item => {
|
result[itemsIndex].forEach(item => {
|
||||||
|
|
|
@ -21,7 +21,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.confirm = async(ctx, orderFk) => {
|
Self.confirm = async(ctx, orderFk) => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
let query = `CALL hedera.order_confirmWithUser(?, ?)`;
|
|
||||||
return await Self.rawSql(query, [orderFk, userId]);
|
const query = `CALL hedera.order_confirmWithUser(?, ?)`;
|
||||||
|
const response = await Self.rawSql(query, [orderFk, userId]);
|
||||||
|
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,60 +9,60 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'ctx',
|
arg: 'ctx',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
http: {source: 'context'}
|
http: {source: 'context'}
|
||||||
}, {
|
}, {
|
||||||
arg: 'filter',
|
arg: 'filter',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
|
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string'
|
||||||
}, {
|
}, {
|
||||||
arg: 'search',
|
arg: 'search',
|
||||||
type: 'String',
|
type: 'string',
|
||||||
description: `If it's and integer searchs by id, otherwise it searchs by nickname`
|
description: `If it's and integer searchs by id, otherwise it searchs by nickname`
|
||||||
}, {
|
}, {
|
||||||
arg: 'from',
|
arg: 'from',
|
||||||
type: 'Date',
|
type: 'date',
|
||||||
description: `The from date`
|
description: 'The from date'
|
||||||
}, {
|
}, {
|
||||||
arg: 'to',
|
arg: 'to',
|
||||||
type: 'Date',
|
type: 'date',
|
||||||
description: `The to date`
|
description: 'The to date'
|
||||||
}, {
|
}, {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Integer',
|
type: 'integer',
|
||||||
description: `The ticket id`
|
description: 'The ticket id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'clientFk',
|
arg: 'clientFk',
|
||||||
type: 'Integer',
|
type: 'integer',
|
||||||
description: `The client id`
|
description: 'The client id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'ticketFk',
|
arg: 'ticketFk',
|
||||||
type: 'Integer',
|
type: 'integer',
|
||||||
description: `The ticket id`
|
description: 'The ticket id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'agencyModeFk',
|
arg: 'agencyModeFk',
|
||||||
type: 'Integer',
|
type: 'integer',
|
||||||
description: `The agency mode id`
|
description: 'The agency mode id'
|
||||||
}, {
|
}, {
|
||||||
arg: 'workerFk',
|
arg: 'workerFk',
|
||||||
type: 'Integer',
|
type: 'integer',
|
||||||
description: `The salesperson id`
|
description: 'The salesperson id'
|
||||||
}, {
|
}, {
|
||||||
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 (currently user tickets)'
|
||||||
}, {
|
}, {
|
||||||
arg: 'isConfirmed',
|
arg: 'isConfirmed',
|
||||||
type: 'Boolean',
|
type: 'boolean',
|
||||||
description: `Order is confirmed`
|
description: 'Order is confirmed'
|
||||||
}, {
|
}, {
|
||||||
arg: 'showEmpty',
|
arg: 'showEmpty',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
description: `Show empty orders`
|
description: 'Show empty orders'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -71,34 +71,35 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter) => {
|
Self.filter = async(ctx, filter, options) => {
|
||||||
let conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
let worker = await Self.app.models.Worker.findOne({
|
const myOptions = {};
|
||||||
where: {userFk: ctx.req.accessToken.userId},
|
|
||||||
include: [
|
if (typeof options == 'object')
|
||||||
{relation: 'collegues'}
|
Object.assign(myOptions, options);
|
||||||
]
|
|
||||||
});
|
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
let teamIds = [];
|
|
||||||
|
|
||||||
if (worker.collegues().length && args.myTeam) {
|
// Apply filter by team
|
||||||
worker.collegues().forEach(collegue => {
|
const teamMembersId = [];
|
||||||
teamIds.push(collegue.collegueFk);
|
if (args.myTeam != null) {
|
||||||
});
|
const worker = await models.Worker.findById(userId, {
|
||||||
|
include: {
|
||||||
|
relation: 'collegues'
|
||||||
}
|
}
|
||||||
|
}, myOptions);
|
||||||
|
const collegues = worker.collegues() || [];
|
||||||
|
for (let collegue of collegues)
|
||||||
|
teamMembersId.push(collegue.collegueFk);
|
||||||
|
|
||||||
if (worker.collegues().length === 0 && args.myTeam) {
|
if (teamMembersId.length == 0)
|
||||||
worker = await Self.app.models.Worker.findOne({
|
teamMembersId.push(userId);
|
||||||
fields: ['id'],
|
|
||||||
where: {userFk: ctx.req.accessToken.userId}
|
|
||||||
});
|
|
||||||
teamIds = [worker && worker.id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args && args.myTeam)
|
if (args && args.myTeam)
|
||||||
args.teamIds = teamIds;
|
args.teamIds = teamIds;
|
||||||
let where = buildFilter(args, (param, value) => {
|
|
||||||
|
const where = buildFilter(args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'search':
|
case 'search':
|
||||||
return /^\d+$/.test(value)
|
return /^\d+$/.test(value)
|
||||||
|
@ -123,7 +124,10 @@ module.exports = Self => {
|
||||||
case 'isConfirmed':
|
case 'isConfirmed':
|
||||||
return {'o.confirmed': value ? 1 : 0};
|
return {'o.confirmed': value ? 1 : 0};
|
||||||
case 'myTeam':
|
case 'myTeam':
|
||||||
return {'c.salesPersonFk': {inq: teamIds}};
|
if (value)
|
||||||
|
return {'c.salesPersonFk': {inq: teamMembersId}};
|
||||||
|
else
|
||||||
|
return {'c.salesPersonFk': {nin: teamMembersId}};
|
||||||
case 'showEmpty':
|
case 'showEmpty':
|
||||||
return {'o.total': {neq: value}};
|
return {'o.total': {neq: value}};
|
||||||
case 'id':
|
case 'id':
|
||||||
|
@ -133,7 +137,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
filter = mergeFilters(filter, {where});
|
filter = mergeFilters(filter, {where});
|
||||||
let stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
|
@ -183,7 +187,7 @@ module.exports = Self => {
|
||||||
stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
|
stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await conn.executeStmt(sql);
|
const result = await conn.executeStmt(sql, myOptions);
|
||||||
|
|
||||||
return result[ordersIndex];
|
return result[ordersIndex];
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('getItemTypeAvailable', {
|
Self.remoteMethod('getItemTypeAvailable', {
|
||||||
description: 'Gets the item types available for an rder and item category ',
|
description: 'Gets the item types available for an order and item category',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
|
@ -27,11 +27,16 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getItemTypeAvailable = async(orderId, itemCategoryId) => {
|
Self.getItemTypeAvailable = async(orderId, itemCategoryId, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
const order = await app.models.Order.findById(orderId);
|
const order = await app.models.Order.findById(orderId, null, myOptions);
|
||||||
stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [
|
stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [
|
||||||
order.landed,
|
order.landed,
|
||||||
order.addressFk,
|
order.addressFk,
|
||||||
|
@ -78,7 +83,7 @@ module.exports = Self => {
|
||||||
stmts.push('DROP TEMPORARY TABLE tmp.item');
|
stmts.push('DROP TEMPORARY TABLE tmp.item');
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await Self.rawStmt(sql);
|
const result = await Self.rawStmt(sql, myOptions);
|
||||||
|
|
||||||
return result[categoriesIndex];
|
return result[categoriesIndex];
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ module.exports = Self => {
|
||||||
description: 'Gets the sourceApp type set',
|
description: 'Gets the sourceApp type set',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
returns: {
|
returns: {
|
||||||
type: ['String'],
|
type: ['string'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
|
|
@ -21,10 +21,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getTaxes = async orderFk => {
|
Self.getTaxes = async(orderFk, options) => {
|
||||||
let conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
let stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order');
|
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order');
|
||||||
|
|
||||||
|
@ -37,15 +41,15 @@ module.exports = Self => {
|
||||||
|
|
||||||
stmts.push('CALL hedera.order_getTax()');
|
stmts.push('CALL hedera.order_getTax()');
|
||||||
|
|
||||||
let orderTaxIndex = stmts.push('SELECT * FROM tmp.orderAmount') - 1;
|
const orderTaxIndex = stmts.push('SELECT * FROM tmp.orderAmount') - 1;
|
||||||
|
|
||||||
stmts.push(`
|
stmts.push(`
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tmp.order,
|
tmp.order,
|
||||||
tmp.orderTax`);
|
tmp.orderTax`);
|
||||||
|
|
||||||
let sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
let result = await conn.executeStmt(sql);
|
const result = await conn.executeStmt(sql, myOptions);
|
||||||
|
|
||||||
return result[orderTaxIndex];
|
return result[orderTaxIndex];
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,9 +19,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getTotal = async orderFk => {
|
Self.getTotal = async(orderFk, options) => {
|
||||||
let query = `SELECT hedera.order_getTotal(?) total;`;
|
const myOptions = {};
|
||||||
let [total] = await Self.rawSql(query, [orderFk]);
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const query = `SELECT hedera.order_getTotal(?) total;`;
|
||||||
|
const [total] = await Self.rawSql(query, [orderFk], myOptions);
|
||||||
|
|
||||||
return total.total;
|
return total.total;
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,9 +19,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getTotalVolume = async orderFk => {
|
Self.getTotalVolume = async(orderFk, options) => {
|
||||||
let query = `SELECT vn.orderTotalVolume(?) totalVolume, vn.orderTotalVolumeBoxes(?) totalBoxes`;
|
const myOptions = {};
|
||||||
let [res] = await Self.rawSql(query, [orderFk, orderFk]);
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const query = `SELECT vn.orderTotalVolume(?) totalVolume, vn.orderTotalVolumeBoxes(?) totalBoxes`;
|
||||||
|
const [res] = await Self.rawSql(query, [orderFk, orderFk], myOptions);
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,9 +19,14 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getVAT = async orderId => {
|
Self.getVAT = async(orderId, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
let totalTax = 0.00;
|
let totalTax = 0.00;
|
||||||
let taxes = await Self.app.models.Order.getTaxes(orderId);
|
const taxes = await Self.app.models.Order.getTaxes(orderId, myOptions);
|
||||||
taxes.forEach(tax => {
|
taxes.forEach(tax => {
|
||||||
totalTax += tax.tax;
|
totalTax += tax.tax;
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,8 +18,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getVolumes = async orderFk => {
|
Self.getVolumes = async(orderFk, options) => {
|
||||||
let [volume] = await Self.rawSql(`CALL vn.orderListVolume(?)`, [orderFk]);
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const [volume] = await Self.rawSql(`CALL vn.orderListVolume(?)`, [orderFk], myOptions);
|
||||||
return volume;
|
return volume;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,8 +19,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.isEditable = async orderId => {
|
Self.isEditable = async(orderId, options) => {
|
||||||
let exists = await Self.app.models.Order.findOne({
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const exists = await Self.app.models.Order.findOne({
|
||||||
where: {id: orderId},
|
where: {id: orderId},
|
||||||
fields: ['isConfirmed', 'clientFk'],
|
fields: ['isConfirmed', 'clientFk'],
|
||||||
include: [
|
include: [
|
||||||
|
@ -32,7 +37,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
if (exists && exists.client().type().code !== 'normal')
|
if (exists && exists.client().type().code !== 'normal')
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -32,8 +32,20 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.new = async(landed, addressId, agencyModeId) => {
|
Self.new = async(landed, addressId, agencyModeId, options) => {
|
||||||
let address = await Self.app.models.Address.findOne({
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const address = await Self.app.models.Address.findOne({
|
||||||
where: {id: addressId},
|
where: {id: addressId},
|
||||||
fields: ['clientFk'],
|
fields: ['clientFk'],
|
||||||
include: [
|
include: [
|
||||||
|
@ -45,11 +57,11 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
if (address.client().type().code === 'normal') {
|
if (address.client().type().code === 'normal') {
|
||||||
if (!address.client().isActive)
|
if (!address.client().isActive)
|
||||||
throw new UserError(`You can't create an order for a inactive client`);
|
throw new UserError(`You can't create an order for an inactive client`);
|
||||||
}
|
}
|
||||||
|
|
||||||
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
|
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
|
||||||
|
@ -58,8 +70,14 @@ module.exports = Self => {
|
||||||
agencyModeId,
|
agencyModeId,
|
||||||
addressId,
|
addressId,
|
||||||
'SALIX'
|
'SALIX'
|
||||||
]);
|
], myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return result[0].vOrderId;
|
return result[0].vOrderId;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,17 +18,35 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.newFromTicket = async ticketFk => {
|
Self.newFromTicket = async(ticketFk, options) => {
|
||||||
let ticket = await Self.app.models.Ticket.findOne({
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const ticket = await Self.app.models.Ticket.findOne({
|
||||||
where: {id: ticketFk}
|
where: {id: ticketFk}
|
||||||
});
|
}, myOptions);
|
||||||
|
|
||||||
let landed = ticket.landed;
|
const landed = ticket.landed;
|
||||||
let addressFk = ticket.addressFk;
|
const addressFk = ticket.addressFk;
|
||||||
let agencyModeFk = ticket.agencyModeFk;
|
const agencyModeFk = ticket.agencyModeFk;
|
||||||
|
|
||||||
let orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk);
|
const orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return orderID;
|
return orderID;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,27 +1,43 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order catalogFilter()', () => {
|
describe('order catalogFilter()', () => {
|
||||||
const colorTagId = 1;
|
const colorTagId = 1;
|
||||||
const categoryTagId = 67;
|
const categoryTagId = 67;
|
||||||
|
|
||||||
it('should return an array of items', async() => {
|
it('should return an array of items', async() => {
|
||||||
let filter = {
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
categoryFk: 1,
|
categoryFk: 1,
|
||||||
typeFk: 2
|
typeFk: 2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let tags = [];
|
const tags = [];
|
||||||
let orderFk = 11;
|
const orderFk = 11;
|
||||||
let orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
const orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
||||||
let result = await app.models.Order.catalogFilter(orderFk, orderBy, filter, tags);
|
const result = await models.Order.catalogFilter(orderFk, orderBy, filter, tags, options);
|
||||||
let firstItemId = result[0].id;
|
const firstItemId = result[0].id;
|
||||||
|
|
||||||
expect(result.length).toEqual(4);
|
expect(result.length).toEqual(4);
|
||||||
expect(firstItemId).toEqual(1);
|
expect(firstItemId).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should now return an array of items based on tag filter', async() => {
|
it('should now return an array of items based on tag filter', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
categoryFk: 1,
|
categoryFk: 1,
|
||||||
|
@ -35,7 +51,7 @@ describe('order catalogFilter()', () => {
|
||||||
];
|
];
|
||||||
const orderFk = 11;
|
const orderFk = 11;
|
||||||
const orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
const orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
||||||
const result = await app.models.Order.catalogFilter(orderFk, orderBy, filter, tagGroups);
|
const result = await models.Order.catalogFilter(orderFk, orderBy, filter, tagGroups, options);
|
||||||
|
|
||||||
const randomIndex = Math.round(Math.random());
|
const randomIndex = Math.round(Math.random());
|
||||||
const item = result[randomIndex];
|
const item = result[randomIndex];
|
||||||
|
@ -47,5 +63,11 @@ describe('order catalogFilter()', () => {
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(2);
|
||||||
expect(colorTag.value).toEqual('Silver');
|
expect(colorTag.value).toEqual('Silver');
|
||||||
expect(categoryTag.value).toEqual('Concussion');
|
expect(categoryTag.value).toEqual('Concussion');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order filter()', () => {
|
describe('order filter()', () => {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
|
@ -8,51 +8,107 @@ describe('order filter()', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should call the filter method with a basic search', async() => {
|
it('should call the filter method with a basic search', async() => {
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {where: {'o.id': 2}};
|
const filter = {where: {'o.id': 2}};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
const orderId = result[0].id;
|
const orderId = result[0].id;
|
||||||
|
|
||||||
expect(orderId).toEqual(2);
|
expect(orderId).toEqual(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the filter method with a single advanced search', async() => {
|
it('should call the filter method with a single advanced search', async() => {
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {where: {'o.confirmed': false}};
|
const filter = {where: {'o.confirmed': false}};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(16);
|
expect(result.length).toEqual(16);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the filter method with a complex advanced search', async() => {
|
it('should call the filter method with a complex advanced search', async() => {
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}};
|
const filter = {where: {'o.confirmed': false, 'c.salesPersonFk': 18}};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(9);
|
expect(result.length).toEqual(9);
|
||||||
expect(result[0].id).toEqual(7);
|
expect(result[0].id).toEqual(7);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the orders matching the showEmpty on false', async() => {
|
it('should return the orders matching the showEmpty on false', async() => {
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {};
|
const filter = {};
|
||||||
ctx.args = {showEmpty: false};
|
myCtx.args = {showEmpty: false};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
const hasEmptyLines = result.some(order => {
|
const hasEmptyLines = result.some(order => {
|
||||||
return order.total === 0;
|
return order.total === 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(hasEmptyLines).toBeFalsy();
|
expect(hasEmptyLines).toBeFalsy();
|
||||||
|
|
||||||
ctx.args = {showEmpty: null};
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the orders matching the showEmpty on true', async() => {
|
it('should return the orders matching the showEmpty on true', async() => {
|
||||||
|
const myCtx = Object.assign({}, ctx);
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const filter = {};
|
const filter = {};
|
||||||
ctx.args = {showEmpty: true};
|
myCtx.args = {showEmpty: true};
|
||||||
const result = await app.models.Order.filter(ctx, filter);
|
const result = await models.Order.filter(myCtx, filter, options);
|
||||||
const hasEmptyLines = result.some(order => {
|
const hasEmptyLines = result.some(order => {
|
||||||
return order.total === 0;
|
return order.total === 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(hasEmptyLines).toBeTruthy();
|
expect(hasEmptyLines).toBeTruthy();
|
||||||
|
|
||||||
ctx.args = {showEmpty: null};
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,19 +1,41 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getItemTypeAvailable()', () => {
|
describe('order getItemTypeAvailable()', () => {
|
||||||
it('should call the getItemTypeAvailable method with a valid order and item category', async() => {
|
it('should call the getItemTypeAvailable method with a valid order and item category', async() => {
|
||||||
let orderId = 11;
|
const tx = await models.Order.beginTransaction({});
|
||||||
let itemCategoryId = 1;
|
|
||||||
let result = await app.models.Order.getItemTypeAvailable(orderId, itemCategoryId);
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const orderId = 11;
|
||||||
|
const itemCategoryId = 1;
|
||||||
|
const result = await models.Order.getItemTypeAvailable(orderId, itemCategoryId, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the getItemTypeAvailable method with the same order and different item category', async() => {
|
it('should call the getItemTypeAvailable method with the same order and different item category', async() => {
|
||||||
let orderId = 11;
|
const tx = await models.Order.beginTransaction({});
|
||||||
let itemCategoryId = 4;//
|
|
||||||
let result = await app.models.Order.getItemTypeAvailable(orderId, itemCategoryId);
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const orderId = 11;
|
||||||
|
const itemCategoryId = 4;
|
||||||
|
const result = await models.Order.getItemTypeAvailable(orderId, itemCategoryId, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,31 +1,75 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getTaxes()', () => {
|
describe('order getTaxes()', () => {
|
||||||
it('should call the getTaxes method and return undefined if its called with a string', async() => {
|
it('should call the getTaxes method and return undefined if its called with a string', async() => {
|
||||||
let result = await app.models.Order.getTaxes('string');
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getTaxes('string', options);
|
||||||
|
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the getTaxes method and return undefined if its called with unknown id', async() => {
|
it('should call the getTaxes method and return undefined if its called with unknown id', async() => {
|
||||||
let result = await app.models.Order.getTaxes(99999999999999999999999);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getTaxes(9999, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(0);
|
expect(result.length).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the getTaxes method and return the taxes splited if different type of taxes', async() => {
|
it('should call the getTaxes method and return the taxes splited if different type of taxes', async() => {
|
||||||
let result = await app.models.Order.getTaxes(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getTaxes(1, options);
|
||||||
|
|
||||||
const expectedResult = result[0].tax + result[1].tax;
|
const expectedResult = result[0].tax + result[1].tax;
|
||||||
|
|
||||||
expect(expectedResult).toEqual(20.29);
|
expect(expectedResult).toEqual(20.29);
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the getTaxes method and return the taxes for them same type', async() => {
|
it('should call the getTaxes method and return the taxes for them same type', async() => {
|
||||||
let result = await app.models.Order.getTaxes(2);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getTaxes(2, options);
|
||||||
|
|
||||||
expect(result[0].tax).toEqual(9.1);
|
expect(result[0].tax).toEqual(9.1);
|
||||||
expect(result.length).toEqual(1);
|
expect(result.length).toEqual(1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getTotal()', () => {
|
describe('order getTotal()', () => {
|
||||||
it('should return the order total', async() => {
|
it('should return the order total', async() => {
|
||||||
let result = await app.models.Order.getTotal(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const result = await models.Order.getTotal(1, options);
|
||||||
|
|
||||||
expect(result).toEqual(155.89);
|
expect(result).toEqual(155.89);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,21 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getTotalVolume()', () => {
|
describe('order getTotalVolume()', () => {
|
||||||
it('should return the total', async() => {
|
it('should return the total', async() => {
|
||||||
let result = await app.models.Order.getTotalVolume(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getTotalVolume(1, options);
|
||||||
|
|
||||||
expect(result.totalVolume).toEqual(1.568);
|
expect(result.totalVolume).toEqual(1.568);
|
||||||
expect(result.totalBoxes).toEqual(11.1);
|
expect(result.totalBoxes).toEqual(11.1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getVAT()', () => {
|
describe('order getVAT()', () => {
|
||||||
it('should return the order VAT', async() => {
|
it('should return the order VAT', async() => {
|
||||||
const result = await app.models.Order.getVAT(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.getVAT(1, options);
|
||||||
|
|
||||||
expect(result).toEqual(20.29);
|
expect(result).toEqual(20.29);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order getVolumes()', () => {
|
describe('order getVolumes()', () => {
|
||||||
it('should return the volumes of a given order id', async() => {
|
it('should return the volumes of a given order id', async() => {
|
||||||
let [result] = await app.models.Order.getVolumes(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const [result] = await models.Order.getVolumes(1, options);
|
||||||
|
|
||||||
expect(result.volume).toEqual(1.09);
|
expect(result.volume).toEqual(1.09);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,21 +1,54 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order isEditable()', () => {
|
describe('order isEditable()', () => {
|
||||||
it('should return false when the given order is not editable', async() => {
|
it('should return false when the given order is not editable', async() => {
|
||||||
let isEditable = await app.models.Order.isEditable(2);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const isEditable = await models.Order.isEditable(2, options);
|
||||||
|
|
||||||
expect(isEditable).toBeFalsy();
|
expect(isEditable).toBeFalsy();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false when the given order doesnt exists', async() => {
|
it('should return false when the given order doesnt exists', async() => {
|
||||||
let isEditable = await app.models.Order.isEditable(99999);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const isEditable = await models.Order.isEditable(999, options);
|
||||||
|
|
||||||
expect(isEditable).toBeFalsy();
|
expect(isEditable).toBeFalsy();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true when the given order is editable', async() => {
|
it('should return true when the given order is editable', async() => {
|
||||||
let isEditable = await app.models.Order.isEditable(16);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const isEditable = await models.Order.isEditable(16, options);
|
||||||
|
|
||||||
expect(isEditable).toBeTruthy();
|
expect(isEditable).toBeTruthy();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,36 +1,49 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
let UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
describe('order new()', () => {
|
describe('order new()', () => {
|
||||||
let orderId;
|
|
||||||
|
|
||||||
afterAll(async() => {
|
|
||||||
await app.models.Order.destroyById(orderId);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if the client isnt active', async() => {
|
it('should throw an error if the client isnt active', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
let landed = new Date();
|
try {
|
||||||
let addressFk = 6;
|
const options = {transaction: tx};
|
||||||
let agencyModeFk = 1;
|
|
||||||
|
|
||||||
await app.models.Order.new(landed, addressFk, agencyModeFk)
|
const landed = new Date();
|
||||||
.catch(e => {
|
const addressFk = 6;
|
||||||
|
const agencyModeFk = 1;
|
||||||
|
|
||||||
|
await models.Order.new(landed, addressFk, agencyModeFk, options);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
});
|
}
|
||||||
|
|
||||||
expect(error).toEqual(new UserError(`You can't create an order for a inactive client`));
|
expect(error).toEqual(new UserError(`You can't create an order for an inactive client`));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should now create a new order when all conditions are met', async() => {
|
it('should now create a new order when all conditions are met', async() => {
|
||||||
let landed = new Date();
|
const tx = await models.Order.beginTransaction({});
|
||||||
let addressFk = 121;
|
|
||||||
let agencyModeFk = 1;
|
|
||||||
|
|
||||||
orderId = await app.models.Order.new(landed, addressFk, agencyModeFk);
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
let highestOrderIdInFixtures = 3;
|
const landed = new Date();
|
||||||
|
const addressFk = 121;
|
||||||
|
const agencyModeFk = 1;
|
||||||
|
|
||||||
|
orderId = await models.Order.new(landed, addressFk, agencyModeFk, options);
|
||||||
|
|
||||||
|
const highestOrderIdInFixtures = 3;
|
||||||
|
|
||||||
expect(orderId).toBeGreaterThan(highestOrderIdInFixtures);
|
expect(orderId).toBeGreaterThan(highestOrderIdInFixtures);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('order newFromTicket()', () => {
|
||||||
|
it('should create a new order from an existing ticket', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ticketId = 11;
|
||||||
|
|
||||||
|
const orderId = await models.Order.newFromTicket(ticketId, options);
|
||||||
|
|
||||||
|
const highestOrderIdInFixtures = 3;
|
||||||
|
|
||||||
|
expect(orderId).toBeGreaterThan(highestOrderIdInFixtures);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,36 +1,91 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('order summary()', () => {
|
describe('order summary()', () => {
|
||||||
it('should return a summary object containing data from 1 order', async() => {
|
it('should return a summary object containing data from 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.summary(1, options);
|
||||||
|
|
||||||
expect(result.id).toEqual(1);
|
expect(result.id).toEqual(1);
|
||||||
expect(result.clientFk).toEqual(1101);
|
expect(result.clientFk).toEqual(1101);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a summary object containing sales from 1 order', async() => {
|
it('should return a summary object containing sales from 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.summary(1, options);
|
||||||
|
|
||||||
expect(result.rows.length).toEqual(3);
|
expect(result.rows.length).toEqual(3);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a summary object containing subTotal for 1 order', async() => {
|
it('should return a summary object containing subTotal for 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.summary(1, options);
|
||||||
|
|
||||||
expect(Math.round(result.subTotal * 100) / 100).toEqual(135.60);
|
expect(Math.round(result.subTotal * 100) / 100).toEqual(135.60);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a summary object containing VAT for 1 order', async() => {
|
it('should return a summary object containing VAT for 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.summary(1, options);
|
||||||
|
|
||||||
expect(Math.round(result.VAT * 100) / 100).toEqual(20.29);
|
expect(Math.round(result.VAT * 100) / 100).toEqual(20.29);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a summary object containing total for 1 order', async() => {
|
it('should return a summary object containing total for 1 order', async() => {
|
||||||
let result = await app.models.Order.summary(1);
|
const tx = await models.Order.beginTransaction({});
|
||||||
let total = result.subTotal + result.VAT;
|
|
||||||
let expectedTotal = Math.round(total * 100) / 100;
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const result = await models.Order.summary(1, options);
|
||||||
|
const total = result.subTotal + result.VAT;
|
||||||
|
const expectedTotal = Math.round(total * 100) / 100;
|
||||||
|
|
||||||
expect(result.total).toEqual(expectedTotal);
|
expect(result.total).toEqual(expectedTotal);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,61 +1,93 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
describe('Order updateBasicData', () => {
|
describe('Order updateBasicData', () => {
|
||||||
const orderId = 21;
|
const orderId = 21;
|
||||||
afterAll(async() => {
|
|
||||||
let validparams = {note: null};
|
|
||||||
|
|
||||||
await app.models.Order.updateBasicData(orderId, validparams);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return an error if the order is confirmed', async() => {
|
it('should return an error if the order is confirmed', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const params = [];
|
||||||
|
const orderConfirmed = 1;
|
||||||
|
|
||||||
let params = [];
|
await models.Order.updateBasicData(orderConfirmed, params, options);
|
||||||
let orderConfirmed = 1;
|
|
||||||
|
|
||||||
await app.models.Order.updateBasicData(orderConfirmed, params)
|
await tx.rollback();
|
||||||
.catch(e => {
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
});
|
}
|
||||||
|
const expectedError = `You can't make changes on the basic data of an confirmed order or with rows`;
|
||||||
|
|
||||||
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
|
expect(error).toEqual(new UserError(expectedError));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an error if the order has rows', async() => {
|
it('should return an error if the order has rows', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let error;
|
let error;
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
let params = [];
|
const params = [];
|
||||||
let orderWithRows = 16;
|
const orderWithRows = 16;
|
||||||
|
|
||||||
await app.models.Order.updateBasicData(orderWithRows, params)
|
await models.Order.updateBasicData(orderWithRows, params, options);
|
||||||
.catch(e => {
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
error = e;
|
error = e;
|
||||||
});
|
}
|
||||||
|
|
||||||
expect(error.toString()).toContain(`You can't make changes on the basic data of an confirmed order or with rows`);
|
const expectedError = `You can't make changes on the basic data of an confirmed order or with rows`;
|
||||||
|
|
||||||
|
expect(error).toEqual(new UserError(expectedError));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip invalid params', async() => {
|
it('should skip invalid params', async() => {
|
||||||
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
let success;
|
let success;
|
||||||
|
|
||||||
let invalidparams = {invalid: 'param for update'};
|
const invalidparams = {invalid: 'param for update'};
|
||||||
|
|
||||||
await app.models.Order.updateBasicData(orderId, invalidparams)
|
await models.Order.updateBasicData(orderId, invalidparams, options)
|
||||||
.then(() => success = true);
|
.then(() => success = true);
|
||||||
|
|
||||||
expect(success).toBeTruthy();
|
expect(success).toBeTruthy();
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the client fiscal data and return the count if changes made', async() => {
|
it('should update the client fiscal data and return the count if changes made', async() => {
|
||||||
let validparams = {note: 'test note'};
|
const tx = await models.Order.beginTransaction({});
|
||||||
|
|
||||||
let order = await app.models.Order.findById(orderId);
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const validparams = {note: 'test note'};
|
||||||
|
|
||||||
|
const order = await models.Order.findById(orderId, null, options);
|
||||||
|
|
||||||
expect(order.note).toEqual(null);
|
expect(order.note).toEqual(null);
|
||||||
|
|
||||||
let result = await app.models.Order.updateBasicData(orderId, validparams);
|
const result = await models.Order.updateBasicData(orderId, validparams, options);
|
||||||
|
|
||||||
expect(result.note).toEqual('test note');
|
expect(result.note).toEqual('test note');
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,17 +19,22 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.summary = async orderId => {
|
Self.summary = async(orderId, options) => {
|
||||||
let models = Self.app.models;
|
const models = Self.app.models;
|
||||||
let summary = await getOrderData(Self, orderId);
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const summary = await getOrderData(Self, orderId, myOptions);
|
||||||
summary.subTotal = getSubTotal(summary.rows);
|
summary.subTotal = getSubTotal(summary.rows);
|
||||||
summary.VAT = await models.Order.getVAT(orderId);
|
summary.VAT = await models.Order.getVAT(orderId, myOptions);
|
||||||
summary.total = await models.Order.getTotal(orderId);
|
summary.total = await models.Order.getTotal(orderId, myOptions);
|
||||||
return summary;
|
return summary;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getOrderData(Self, orderId) {
|
async function getOrderData(Self, orderId, options) {
|
||||||
let filter = {
|
const filter = {
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
relation: 'agencyMode', scope: {fields: ['name']}},
|
relation: 'agencyMode', scope: {fields: ['name']}},
|
||||||
|
@ -69,7 +74,7 @@ module.exports = Self => {
|
||||||
where: {id: orderId}
|
where: {id: orderId}
|
||||||
};
|
};
|
||||||
|
|
||||||
return await Self.findOne(filter);
|
return Self.findOne(filter, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubTotal(rows) {
|
function getSubTotal(rows) {
|
||||||
|
|
|
@ -31,16 +31,27 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.updateBasicData = async(id, params) => {
|
Self.updateBasicData = async(id, params, options) => {
|
||||||
let models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
let tx;
|
||||||
|
|
||||||
let order = await models.Order.findById(id);
|
if (typeof options == 'object')
|
||||||
let orderRows = await models.OrderRow.find({where: {orderFk: id}});
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const order = await models.Order.findById(id, null, myOptions);
|
||||||
|
const orderRows = await models.OrderRow.find({where: {orderFk: id}}, myOptions);
|
||||||
|
|
||||||
if (order.isConfirmed || orderRows.length != 0)
|
if (order.isConfirmed || orderRows.length != 0)
|
||||||
throw new UserError(`You can't make changes on the basic data of an confirmed order or with rows`);
|
throw new UserError(`You can't make changes on the basic data of an confirmed order or with rows`);
|
||||||
|
|
||||||
let updateParams = pick(params, [
|
const updateParams = pick(params, [
|
||||||
'clientFk',
|
'clientFk',
|
||||||
'addressFk',
|
'addressFk',
|
||||||
'landed',
|
'landed',
|
||||||
|
@ -48,8 +59,14 @@ module.exports = Self => {
|
||||||
'note',
|
'note',
|
||||||
]);
|
]);
|
||||||
if (Object.keys(updateParams).length)
|
if (Object.keys(updateParams).length)
|
||||||
await order.updateAttributes(updateParams);
|
await order.updateAttributes(updateParams, myOptions);
|
||||||
|
|
||||||
return await order;
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return order;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
You can't create an order for a frozen client: No puedes crear una orden a un cliente congelado
|
You can't create an order for a frozen client: No puedes crear una orden a un cliente congelado
|
||||||
You can't create an order for a inactive client: No puedes crear una orden a un cliente inactivo
|
You can't create an order for an inactive client: No puedes crear una orden a un cliente inactivo
|
||||||
You can't create an order for a client that doesn't has tax data verified:
|
You can't create an order for a client that doesn't has tax data verified:
|
||||||
No puedes crear una orden a un cliente cuyos datos fiscales no han sido verificados
|
No puedes crear una orden a un cliente cuyos datos fiscales no han sido verificados
|
||||||
You can't create an order for a client that has a debt: No puedes crear una orden a un cliente que tiene deuda
|
You can't create an order for a client that has a debt: No puedes crear una orden a un cliente que tiene deuda
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
this.$http.get(query).then(response => {
|
this.$http.get(query).then(response => {
|
||||||
if (!response.data)
|
if (!response.data)
|
||||||
throw new UserError(`The route's vehicle doesn't have a departing warehouse`);
|
throw new UserError(`The route's vehicle doesn't have a delivery point`);
|
||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}).then(address => {
|
}).then(address => {
|
||||||
|
|
|
@ -9,6 +9,6 @@ Tickets to add: Tickets a añadir
|
||||||
Ticket not found: No se ha encontrado el ticket
|
Ticket not found: No se ha encontrado el ticket
|
||||||
The selected ticket is not suitable for this route: El ticket seleccionado no es apto para esta ruta
|
The selected ticket is not suitable for this route: El ticket seleccionado no es apto para esta ruta
|
||||||
PC: CP
|
PC: CP
|
||||||
The route's vehicle doesn't have a departing warehouse: El vehículo de la ruta no tiene un almacén de salida
|
The route's vehicle doesn't have a delivery point: El vehículo de la ruta no tiene un punto de entrega
|
||||||
The route doesn't have a vehicle: La ruta no tiene un vehículo
|
The route doesn't have a vehicle: La ruta no tiene un vehículo
|
||||||
Population: Población
|
Population: Población
|
|
@ -1,26 +1,26 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('recalculatePrice', {
|
Self.remoteMethodCtx('recalculatePrice', {
|
||||||
description: 'Calculates the price of a sale and its components',
|
description: 'Calculates the price of sales and its components',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'sales',
|
||||||
description: 'The sale id',
|
description: 'The sales',
|
||||||
type: 'number',
|
type: ['object'],
|
||||||
required: true,
|
required: true,
|
||||||
http: {source: 'path'}
|
http: {source: 'body'}
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/recalculatePrice`,
|
path: `/recalculatePrice`,
|
||||||
verb: 'post'
|
verb: 'post'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.recalculatePrice = async(ctx, id, options) => {
|
Self.recalculatePrice = async(ctx, sales, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -34,18 +34,33 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sale = await Self.findById(id, null, myOptions);
|
const salesIds = [];
|
||||||
const isEditable = await models.Ticket.isEditable(ctx, sale.ticketFk, myOptions);
|
const params = [];
|
||||||
|
sales.forEach(sale => {
|
||||||
|
salesIds.push(sale.id);
|
||||||
|
params.push('?');
|
||||||
|
});
|
||||||
|
|
||||||
|
const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions);
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
|
|
||||||
const canEditSale = await models.Sale.canEdit(ctx, [id], myOptions);
|
const canEditSale = await models.Sale.canEdit(ctx, sales, myOptions);
|
||||||
|
|
||||||
if (!canEditSale)
|
if (!canEditSale)
|
||||||
throw new UserError(`Sale(s) blocked, please contact production`);
|
throw new UserError(`Sale(s) blocked, please contact production`);
|
||||||
|
|
||||||
const recalculation = await Self.rawSql('CALL vn.sale_calculateComponent(?, null)', [id], myOptions);
|
const paramsString = params.join();
|
||||||
|
|
||||||
|
const query = `
|
||||||
|
DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales;
|
||||||
|
CREATE TEMPORARY TABLE tmp.recalculateSales
|
||||||
|
SELECT s.id
|
||||||
|
FROM sale s
|
||||||
|
WHERE s.id IN (${paramsString});
|
||||||
|
CALL vn.sale_recalcComponent(null);
|
||||||
|
DROP TEMPORARY TABLE tmp.recalculateSales;`;
|
||||||
|
|
||||||
|
const recalculation = await Self.rawSql(query, salesIds, myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('sale recalculatePrice()', () => {
|
describe('sale recalculatePrice()', () => {
|
||||||
const saleId = 7;
|
|
||||||
|
|
||||||
it('should update the sale price', async() => {
|
it('should update the sale price', async() => {
|
||||||
const tx = await models.Sale.beginTransaction({});
|
const tx = await models.Sale.beginTransaction({});
|
||||||
|
const sales = [
|
||||||
|
{id: 7, ticketFk: 11},
|
||||||
|
{id: 8, ticketFk: 11}
|
||||||
|
];
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
const ctx = {req: {accessToken: {userId: 9}}};
|
||||||
const response = await models.Sale.recalculatePrice(ctx, saleId, options);
|
const response = await models.Sale.recalculatePrice(ctx, sales, options);
|
||||||
|
|
||||||
expect(response.affectedRows).toBeDefined();
|
expect(response[0].affectedRows).toBeDefined();
|
||||||
|
expect(response[1].affectedRows).toBeDefined();
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -29,8 +31,8 @@ describe('sale recalculatePrice()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const ctx = {req: {accessToken: {userId: 9}}};
|
const ctx = {req: {accessToken: {userId: 9}}};
|
||||||
const immutableSaleId = 1;
|
const immutableSale = [{id: 1, ticketFk: 1}];
|
||||||
await models.Sale.recalculatePrice(ctx, immutableSaleId, options);
|
await models.Sale.recalculatePrice(ctx, immutableSale, options);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -177,6 +177,8 @@ module.exports = Self => {
|
||||||
return {'a.provinceFk': value};
|
return {'a.provinceFk': value};
|
||||||
case 'stateFk':
|
case 'stateFk':
|
||||||
return {'ts.stateFk': value};
|
return {'ts.stateFk': value};
|
||||||
|
case 'collectionFk':
|
||||||
|
return {'cll.id': value};
|
||||||
case 'mine':
|
case 'mine':
|
||||||
case 'myTeam':
|
case 'myTeam':
|
||||||
if (value)
|
if (value)
|
||||||
|
@ -276,9 +278,8 @@ module.exports = Self => {
|
||||||
if (args.collectionFk) {
|
if (args.collectionFk) {
|
||||||
stmt.merge({
|
stmt.merge({
|
||||||
sql: `
|
sql: `
|
||||||
JOIN collection cll ON cll.id = ?
|
JOIN collection cll
|
||||||
JOIN ticketCollection tc ON tc.collectionFk = cll.id AND tc.ticketFk = t.id`,
|
JOIN ticketCollection tc ON tc.collectionFk = cll.id AND tc.ticketFk = t.id`
|
||||||
params: [args.collectionFk]
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ export default class Ticket extends ModuleMain {
|
||||||
'to',
|
'to',
|
||||||
'search',
|
'search',
|
||||||
'clientFk',
|
'clientFk',
|
||||||
|
'collectionFk',
|
||||||
'orderFk',
|
'orderFk',
|
||||||
'refFk',
|
'refFk',
|
||||||
'scopeDays'
|
'scopeDays'
|
||||||
|
|
|
@ -464,7 +464,7 @@
|
||||||
<vn-item translate
|
<vn-item translate
|
||||||
name="calculatePrice"
|
name="calculatePrice"
|
||||||
ng-click="$ctrl.calculateSalePrice()"
|
ng-click="$ctrl.calculateSalePrice()"
|
||||||
ng-if="$ctrl.isEditable && $ctrl.hasOneSaleSelected()">
|
ng-if="$ctrl.isEditable">
|
||||||
Recalculate price
|
Recalculate price
|
||||||
</vn-item>
|
</vn-item>
|
||||||
<vn-item translate
|
<vn-item translate
|
||||||
|
|
|
@ -450,10 +450,11 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateSalePrice() {
|
calculateSalePrice() {
|
||||||
const sale = this.selectedValidSales()[0];
|
const sales = this.selectedValidSales();
|
||||||
if (!sale) return;
|
if (!sales) return;
|
||||||
const query = `Sales/${sale.id}/recalculatePrice`;
|
|
||||||
this.$http.post(query).then(() => {
|
const query = `Sales/recalculatePrice`;
|
||||||
|
this.$http.post(query, sales).then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
this.$.model.refresh();
|
this.$.model.refresh();
|
||||||
});
|
});
|
||||||
|
|
|
@ -688,10 +688,11 @@ describe('Ticket', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
|
||||||
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
|
jest.spyOn(controller.$.model, 'refresh').mockReturnThis();
|
||||||
|
|
||||||
const selectedSale = controller.sales[0];
|
controller.sales.forEach(sale => {
|
||||||
selectedSale.checked = true;
|
sale.checked = true;
|
||||||
|
});
|
||||||
|
|
||||||
$httpBackend.expect('POST', `Sales/1/recalculatePrice`).respond(200);
|
$httpBackend.expect('POST', `Sales/recalculatePrice`).respond(200);
|
||||||
controller.calculateSalePrice();
|
controller.calculateSalePrice();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue