update structure db

This commit is contained in:
Bernat Exposito Domenech 2020-01-23 12:58:38 +01:00
parent de95127199
commit 64bd721287
12 changed files with 509 additions and 183 deletions

View File

@ -109,10 +109,10 @@ proc: BEGIN
GROUP BY tc.itemFk, warehouseFk;
INSERT INTO tmp.ticketComponent
SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3)
SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.priceIncreasing, 0.25), 3)
FROM tmp.ticketComponentBase tcb
JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk
WHERE cr.recobro > 0.009;
JOIN claimRatio cr ON cr.clientFk = vClientFk
WHERE cr.priceIncreasing > 0.009;
INSERT INTO tmp.ticketComponent
SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + wm.pricesModifierRate), 3) as manaAuto
@ -147,7 +147,7 @@ proc: BEGIN
vGeneralInflationCoefficient
* ROUND((
i.compression
* r.cm3
* ic.cm3
* IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1)
* IFNULL((z.price - z.bonus)
* 1/*amz.inflation*/ , 50)) / vBoxVolume, 4
@ -156,8 +156,8 @@ proc: BEGIN
JOIN item i ON i.id = tcc.itemFk
JOIN zone z ON z.id = vZoneFk
JOIN agencyMode am ON am.id = z.agencyModeFk
LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk
AND r.Id_Article = tcc.itemFk
LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
AND ic.itemFk = tcc.itemFk
HAVING cost <> 0;
IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN

View File

@ -0,0 +1,18 @@
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`clientRisk_update`(vClientId INT, vCompanyId INT, vAmount DECIMAL(10,2))
BEGIN
IF vAmount IS NOT NULL
THEN
INSERT INTO clientRisk
SET
clientFk = vClientId,
companyFk = vCompanyId,
amount = vAmount
ON DUPLICATE KEY UPDATE
amount = amount + VALUES(amount);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,12 @@
DROP procedure IF EXISTS `bi`.`customer_risk_update`;
DELIMITER $$
USE `bi`$$
CREATE DEFINER=`root`@`%` PROCEDURE `bi`.`customer_risk_update`(v_customer INT, v_company INT, v_amount DECIMAL(10,2))
BEGIN
CALL vn.clientRisk_update(v_customer, v_company, v_amount);
END$$
DELIMITER ;

View File

@ -0,0 +1,7 @@
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`invoiceOut_afterInsert` AFTER INSERT ON `vn`.`invoiceOut` FOR EACH ROW BEGIN
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;

File diff suppressed because one or more lines are too long

View File

@ -124,6 +124,13 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`,
(1, 'Pay on receipt', '0000000000', 4, 0, 1, 1),
(2, 'Cash', '1111111111', 1, 0, 1, 1);
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES
(1, 'AGENCY', 'Agencia'),
(2, 'DELIVERY', 'Reparto'),
(3, 'PICKUP', 'Recogida'),
(4, 'OTHER', 'Otros');
INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`)
VALUES
(1, 'inhouse pickup' , 1, 0, 1, 1),
@ -1165,13 +1172,6 @@ INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`package
(14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 7.30, 7.00, 0.00, NULL, 0, 1, 0, CURDATE()),
(15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 1, NULL, 0.00, 1.75, 1.67, 0.00, NULL, 0, 1, 0, CURDATE());
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES
(1, 'AGENCY', 'Agencia'),
(2, 'DELIVERY', 'Reparto'),
(3, 'PICKUP', 'Recogida'),
(4, 'OTHER', 'Otros');
INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`, `date_make`, `first_row_stamp`, `confirm_date`)
VALUES
(1, DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 3, 1, 121, 442, NULL, 'TPV', 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH)),

View File

@ -2414,43 +2414,37 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `tarifa_componentes`
-- Temporary table structure for view `tarifa_componentes`
--
DROP TABLE IF EXISTS `tarifa_componentes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tarifa_componentes` (
`Id_Componente` int(11) NOT NULL AUTO_INCREMENT,
`Componente` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`tarifa_componentes_series_id` int(11) NOT NULL,
`tarifa_class` smallint(6) DEFAULT NULL,
`tax` double DEFAULT NULL,
`is_renewable` tinyint(2) NOT NULL DEFAULT '1',
`code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`Id_Componente`),
KEY `series_componentes_idx` (`tarifa_componentes_series_id`),
KEY `comp` (`tarifa_class`),
CONSTRAINT `serie_componente` FOREIGN KEY (`tarifa_componentes_series_id`) REFERENCES `tarifa_componentes_series` (`tarifa_componentes_series_id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `tarifa_componentes` AS SELECT
1 AS `Id_Componente`,
1 AS `Componente`,
1 AS `tarifa_componentes_series_id`,
1 AS `tarifa_class`,
1 AS `tax`,
1 AS `is_renewable`,
1 AS `code`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `tarifa_componentes_series`
-- Temporary table structure for view `tarifa_componentes_series`
--
DROP TABLE IF EXISTS `tarifa_componentes_series`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tarifa_componentes_series` (
`tarifa_componentes_series_id` int(11) NOT NULL AUTO_INCREMENT,
`Serie` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`base` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos',
`margen` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`tarifa_componentes_series_id`),
UNIQUE KEY `Serie_UNIQUE` (`Serie`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes';
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `tarifa_componentes_series` AS SELECT
1 AS `tarifa_componentes_series_id`,
1 AS `Serie`,
1 AS `base`,
1 AS `margen`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `tarifa_premisas`
@ -20849,11 +20843,11 @@ CREATE TABLE `agencyMode` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`deliveryMethodFk` int(11) DEFAULT '0',
`deliveryMethodFk` int(11) DEFAULT NULL,
`m3` double DEFAULT '0',
`cod71` tinyint(3) unsigned DEFAULT '0',
`web` smallint(1) unsigned zerofill NOT NULL DEFAULT '0',
`agencyFk` smallint(6) NOT NULL,
`agencyFk` smallint(5) unsigned NOT NULL,
`agencyServiceFk` tinyint(4) NOT NULL DEFAULT '1',
`inflation` decimal(5,2) NOT NULL DEFAULT '0.00' COMMENT 'Este valor se utiliza para aumentar el valor del componente porte.',
`isVolumetric` tinyint(1) NOT NULL DEFAULT '0',
@ -20865,7 +20859,10 @@ CREATE TABLE `agencyMode` (
`code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `Agencias` (`name`),
KEY `Vista` (`deliveryMethodFk`)
KEY `Vista` (`deliveryMethodFk`),
KEY `agencyMode_agencyFk` (`agencyFk`),
CONSTRAINT `agencyMode_agencyFk` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON UPDATE CASCADE,
CONSTRAINT `agencyMode_deliveryMethodFk` FOREIGN KEY (`deliveryMethodFk`) REFERENCES `deliveryMethod` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@ -22496,22 +22493,26 @@ CREATE TABLE `companyGroup` (
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Temporary table structure for view `component`
-- Table structure for table `component`
--
DROP TABLE IF EXISTS `component`;
/*!50001 DROP VIEW IF EXISTS `component`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `component` AS SELECT
1 AS `id`,
1 AS `name`,
1 AS `typeFk`,
1 AS `classRate`,
1 AS `tax`,
1 AS `isRenewable`,
1 AS `code`*/;
SET character_set_client = @saved_cs_client;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `component` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`typeFk` int(11) NOT NULL,
`classRate` smallint(6) DEFAULT NULL,
`tax` double DEFAULT NULL,
`isRenewable` tinyint(2) NOT NULL DEFAULT '1',
`code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `series_componentes_idx` (`typeFk`),
KEY `comp` (`classRate`),
CONSTRAINT `serie_componente` FOREIGN KEY (`typeFk`) REFERENCES `componentType` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Temporary table structure for view `componentRate__`
@ -22532,19 +22533,21 @@ SET character_set_client = utf8;
SET character_set_client = @saved_cs_client;
--
-- Temporary table structure for view `componentType`
-- Table structure for table `componentType`
--
DROP TABLE IF EXISTS `componentType`;
/*!50001 DROP VIEW IF EXISTS `componentType`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `componentType` AS SELECT
1 AS `id`,
1 AS `type`,
1 AS `base`,
1 AS `isMargin`*/;
SET character_set_client = @saved_cs_client;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `componentType` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`isBase` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos',
`isMargin` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `Serie_UNIQUE` (`type`)
) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Temporary table structure for view `componentTypeRate__`
@ -22560,6 +22563,39 @@ SET character_set_client = utf8;
1 AS `base`*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary table structure for view `componentType__`
--
DROP TABLE IF EXISTS `componentType__`;
/*!50001 DROP VIEW IF EXISTS `componentType__`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `componentType__` AS SELECT
1 AS `id`,
1 AS `type`,
1 AS `isBase`,
1 AS `isMargin`*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary table structure for view `component__`
--
DROP TABLE IF EXISTS `component__`;
/*!50001 DROP VIEW IF EXISTS `component__`*/;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
/*!50001 CREATE VIEW `component__` AS SELECT
1 AS `id`,
1 AS `name`,
1 AS `typeFk`,
1 AS `classRate`,
1 AS `tax`,
1 AS `isRenewable`,
1 AS `code`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `confectionType`
--
@ -27951,7 +27987,7 @@ CREATE TABLE `saleComponent` (
PRIMARY KEY (`saleFk`,`componentFk`),
KEY `fk_mov_comp_idx` (`componentFk`),
CONSTRAINT `mc_fk1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `mc_fk2` FOREIGN KEY (`componentFk`) REFERENCES `bi`.`tarifa_componentes` (`Id_Componente`) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT `mc_fk2` FOREIGN KEY (`componentFk`) REFERENCES `component` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@ -28140,6 +28176,7 @@ CREATE TABLE `sector` (
`path` int(11) DEFAULT NULL,
`isPreviousPrepared` tinyint(1) NOT NULL DEFAULT '0',
`isPackagingArea` tinyint(1) NOT NULL DEFAULT '0',
`labelReport` int(11) DEFAULT NULL,
PRIMARY KEY (`id`,`warehouseFk`),
UNIQUE KEY `code_UNIQUE` (`code`),
KEY `sector_fk1_idx` (`warehouseFk`),
@ -36544,7 +36581,7 @@ BEGIN
LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL;
DELETE FROM claim WHERE ticketCreated < v18Month;
DELETE FROM message WHERE sendDate < vDateShort;
DELETE FROM travelLog WHERE creationDate < v18Month;
DELETE FROM travelLog WHERE creationDate < v3Month;
DELETE sc FROM saleChecked sc
JOIN sale s ON sc.saleFk = s.id WHERE s.created < vDateShort;
DELETE bm
@ -37831,6 +37868,45 @@ BEGIN
JOIN vn.warehouse w ON w.id = t.warehouseFk
WHERE tc.collectionFk = vCollectionFk;
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 `collectionSticker_print` */;
/*!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 `collectionSticker_print`(vCollectionFk INT, vSectorFk INT)
BEGIN
DECLARE vLabelReport INT;
UPDATE vn.ticket t
JOIN vn.ticketCollection tc ON tc.ticketFk = t.id
SET t.notes = CONCAT('COL ',vCollectionFk,'-',tc.`level`)
WHERE tc.collectionFk = vCollectionFk;
SELECT labelReport INTO vLabelReport
FROM vn.sector
WHERE id = vSectorFk;
IF vLabelReport THEN
INSERT INTO vn.printServerQueue(reportFk, param1, workerFk)
SELECT vLabelReport, ticketFk, getUser()
FROM vn.ticketCollection
WHERE collectionFk = vCollectionFk;
END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -37852,7 +37928,8 @@ BEGIN
SELECT tc.ticketFk,
tc.level,
am.name as agencyName
am.name as agencyName,
t.warehouseFk
FROM vn.ticketCollection tc
JOIN vn.ticket t ON t.id = tc.ticketFk
LEFT JOIN vn.zone z ON z.id = t.zoneFk
@ -38122,14 +38199,9 @@ proc:BEGIN
DECLARE vVolumetryHeightTop INT;
DECLARE vVolumetryHeightFloor INT;
DECLARE vDone BOOLEAN DEFAULT FALSE;
DECLARE vWorkerCode VARCHAR(3);
DECLARE cVolumetry CURSOR FOR
SELECT level, liters, `lines`, height
FROM vn.collectionVolumetry
@ -38369,6 +38441,224 @@ proc:BEGIN
CLOSE cTicket;
-- DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
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 `collection_new__` */;
/*!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 `collection_new__`(vSectorFk INT)
proc:BEGIN
DECLARE vIsPreviousPrepared BOOLEAN;
DECLARE vCollectionFk INT;
DECLARE vWarehouseFk INT;
DECLARE vTicketLiters INT;
DECLARE vTicketLines INT;
DECLARE vTicketFk INT;
DECLARE vIsTicketCollected BOOLEAN;
DECLARE vMaxTickets INT;
DECLARE vStateFk INT;
DECLARE vVolumetryLiters INT;
DECLARE vVolumetryLines INT;
DECLARE vVolumetryFk INT;
DECLARE vVolumetryLevel INT;
DECLARE vVolumetryLitersMax INT;
DECLARE vVolumetryLinesMax INT;
DECLARE vDone BOOLEAN DEFAULT FALSE;
DECLARE vWorkerCode VARCHAR(3);
DECLARE cVolumetry CURSOR FOR
SELECT level, liters, `lines`
FROM vn.collectionVolumetry
ORDER BY `level`;
DECLARE cTicket CURSOR FOR
SELECT *
FROM tmp.ticket;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
SELECT isPreviousPrepared, warehouseFk
INTO vIsPreviousPrepared, vWarehouseFk
FROM vn.sector
WHERE id = vSectorFk;
SELECT w.code
INTO vWorkerCode
FROM vn.worker w
WHERE w.id = account.myUserGetId();
IF vIsPreviousPrepared THEN
SELECT id INTO vStateFk
FROM vn.state
WHERE `code` = 'PREVIOUS_PREPARATION';
ELSE
SELECT id INTO vStateFk
FROM vn.state
WHERE `code` = 'ON_PREPARATION';
END IF;
SELECT COUNT(*), sum(liters), sum(`lines`)
INTO vMaxTickets, vVolumetryLitersMax, vVolumetryLinesMax
FROM vn.collectionVolumetry;
CALL vn2008.production_control_source(vWarehouseFk, 0);
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
IF (SELECT pb.Agencia
FROM tmp.production_buffer pb
JOIN vn.state s ON s.id = pb.state
LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = pb.Id_Ticket
WHERE pb.problems = 0
AND tc.ticketFk IS NULL
AND (s.isPreparable OR (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode))
ORDER BY (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode) DESC, pb.Hora, pb.Minuto, m3 DESC, pb.lines DESC
LIMIT 1) = 'REC_SILLA' THEN
CREATE TEMPORARY TABLE tmp.ticket
SELECT pb.Id_Ticket ticketFk,
pb.lines,
pb.m3 * 1000 liters
FROM tmp.production_buffer pb
JOIN vn.state s ON s.id = pb.state
LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = pb.Id_Ticket
WHERE pb.problems = 0
AND tc.ticketFk IS NULL
AND (s.isPreparable OR (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode))
ORDER BY (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode) DESC, pb.Hora, pb.Minuto, m3 DESC, pb.lines DESC
LIMIT 1;
ELSE
CREATE TEMPORARY TABLE tmp.ticket
SELECT pb.Id_Ticket ticketFk,
pb.lines,
pb.m3 * 1000 liters
FROM tmp.production_buffer pb
JOIN vn.state s ON s.id = pb.state
LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = pb.Id_Ticket
WHERE pb.problems = 0
AND pb.Agencia != 'REC_SILLA'
AND tc.ticketFk IS NULL
AND (s.isPreparable OR (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode))
ORDER BY (s.code = 'PICKER_DESIGNED' AND pb.CodigoTrabajador = vWorkerCode) DESC, pb.Hora, pb.Minuto, m3 DESC, pb.lines DESC
LIMIT vMaxTickets;
END IF;
-- Empieza el bucle
OPEN cVolumetry;
OPEN cTicket;
FETCH cTicket INTO vTicketFk, vTicketLines, vTicketLiters;
FETCH cVolumetry INTO vVolumetryLevel, vVolumetryLiters, vVolumetryLines;
IF NOT vDone THEN
INSERT INTO vn.collection
SET workerFk = account.myUserGetId();
SELECT LAST_INSERT_ID() INTO vCollectionFk;
END IF;
bucle:WHILE NOT vDone DO
IF (vVolumetryLitersMax < vTicketLiters OR vVolumetryLinesMax < vTicketLines) AND vVolumetryLevel > 1 THEN
LEAVE bucle;
END IF;
SELECT COUNT(*) INTO vIsTicketCollected
FROM vn.ticketCollection
WHERE ticketFk = vTicketFk
AND collectionFk = vCollectionFk;
IF vIsTicketCollected THEN
UPDATE vn.ticketCollection
SET level = CONCAT(level, vVolumetryLevel)
WHERE ticketFk = vTicketFk
AND collectionFk = vCollectionFk;
ELSE
INSERT INTO vn.ticketCollection
SET collectionFk = vCollectionFk,
ticketFk = vTicketFk,
level = vVolumetryLevel;
INSERT INTO vncontrol.inter
SET state_id = vStateFk,
Id_Ticket = vTicketFk,
Id_Trabajador = account.myUserGetId();
END IF;
SET vVolumetryLitersMax = GREATEST(0,vVolumetryLitersMax - vVolumetryLiters);
SET vVolumetryLinesMax = GREATEST(0,vVolumetryLinesMax - vVolumetryLines);
SET vTicketLiters = GREATEST(0,vTicketLiters - vVolumetryLiters);
SET vTicketLines = GREATEST(0,vTicketLines - vVolumetryLines);
IF vVolumetryLitersMax = 0 OR vVolumetryLinesMax = 0 THEN
LEAVE bucle;
END IF;
IF vTicketLiters > 0 OR vTicketLines > 0 THEN
FETCH cVolumetry INTO vVolumetryLevel, vVolumetryLiters, vVolumetryLines;
ELSE
FETCH cTicket INTO vTicketFk, vTicketLines, vTicketLiters;
FETCH cVolumetry INTO vVolumetryLevel, vVolumetryLiters, vVolumetryLines;
END IF;
END WHILE;
UPDATE vn.collection c
JOIN vn.state st ON st.code = 'ON_PREPARATION'
SET c.stateFk = st.id
WHERE c.id = vCollectionFk;
INSERT IGNORE INTO vn.ticketDown(ticketFk)
SELECT DISTINCT tc.ticketFk
FROM vn.ticketCollection tc
JOIN vncontrol.inter vi ON vi.Id_Ticket = tc.ticketFk
JOIN vn.state st ON st.id = vi.state_id
JOIN vn.ticket t ON t.id = tc.ticketFk
JOIN vn.warehouse w ON w.id = t.warehouseFk
WHERE tc.collectionFk = vCollectionFk
AND w.name = 'Silla FV'
AND st.code = 'PREVIOUS_PREPARATION';
SELECT vCollectionFk;
CLOSE cVolumetry;
CLOSE cTicket;
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -50943,9 +51233,9 @@ DELIMITER ;
/*!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 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 ;;
@ -51075,7 +51365,7 @@ BEGIN
FROM saleComponent sc
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
JOIN `component` c ON c.id = sc.componentFk
JOIN componentType ct on ct.id = c.typeFk AND ct.base
JOIN componentType ct on ct.id = c.typeFk AND ct.isBase
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
SET s.priceFixed = sumValue, s.isPriceFixed = 1;
@ -57572,6 +57862,42 @@ USE `bi`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `tarifa_componentes`
--
/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tarifa_componentes` AS select `c`.`id` AS `Id_Componente`,`c`.`name` AS `Componente`,`c`.`typeFk` AS `tarifa_componentes_series_id`,`c`.`classRate` AS `tarifa_class`,`c`.`tax` AS `tax`,`c`.`isRenewable` AS `is_renewable`,`c`.`code` AS `code` from `vn`.`component` `c` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `tarifa_componentes_series`
--
/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `tarifa_componentes_series` AS select `ct`.`id` AS `tarifa_componentes_series_id`,`ct`.`type` AS `Serie`,`ct`.`isBase` AS `base`,`ct`.`isMargin` AS `margen` from `vn`.`componentType` `ct` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Current Database: `bs`
--
@ -58454,24 +58780,6 @@ USE `vn`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `component`
--
/*!50001 DROP VIEW IF EXISTS `component`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `component` AS select `t`.`Id_Componente` AS `id`,`t`.`Componente` AS `name`,`t`.`tarifa_componentes_series_id` AS `typeFk`,`t`.`tarifa_class` AS `classRate`,`t`.`tax` AS `tax`,`t`.`is_renewable` AS `isRenewable`,`t`.`code` AS `code` from `bi`.`tarifa_componentes` `t` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `componentRate__`
--
@ -58490,24 +58798,6 @@ USE `vn`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `componentType`
--
/*!50001 DROP VIEW IF EXISTS `componentType`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `componentType` AS select `t`.`tarifa_componentes_series_id` AS `id`,`t`.`Serie` AS `type`,`t`.`base` AS `base`,`t`.`margen` AS `isMargin` from `bi`.`tarifa_componentes_series` `t` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `componentTypeRate__`
--
@ -58526,6 +58816,42 @@ USE `vn`;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `componentType__`
--
/*!50001 DROP VIEW IF EXISTS `componentType__`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `componentType__` AS select `t`.`tarifa_componentes_series_id` AS `id`,`t`.`Serie` AS `type`,`t`.`base` AS `isBase`,`t`.`margen` AS `isMargin` from `bi`.`tarifa_componentes_series` `t` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `component__`
--
/*!50001 DROP VIEW IF EXISTS `component__`*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8 */;
/*!50001 SET character_set_results = utf8 */;
/*!50001 SET collation_connection = utf8_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `component__` AS select `t`.`Id_Componente` AS `id`,`t`.`Componente` AS `name`,`t`.`tarifa_componentes_series_id` AS `typeFk`,`t`.`tarifa_class` AS `classRate`,`t`.`tax` AS `tax`,`t`.`is_renewable` AS `isRenewable`,`t`.`code` AS `code` from `bi`.`tarifa_componentes` `t` */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view `defaulter`
--
@ -59639,4 +59965,4 @@ USE `vncontrol`;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2020-01-22 14:08:58
-- Dump completed on 2020-01-23 12:02:32

View File

@ -49,13 +49,8 @@ TABLES=(
state
sample
department
)
dump_tables ${TABLES[@]}
TABLES=(
bi
tarifa_componentes
tarifa_componentes_series
component
componentType
)
dump_tables ${TABLES[@]}

View File

@ -2,7 +2,6 @@
SCHEMAS=(
account
bi
bs
cache
edi

View File

@ -7,7 +7,7 @@ describe('Client activeWorkersWithRole', () => {
let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson');
expect(result.length).toEqual(15);
expect(result.length).toEqual(14);
expect(isSalesPerson).toBeTruthy();
});

View File

@ -6,7 +6,7 @@ describe('Client listWorkers', () => {
.then(result => {
let amountOfEmployees = Object.keys(result).length;
expect(amountOfEmployees).toEqual(50);
expect(amountOfEmployees).toEqual(49);
done();
})
.catch(done.fail);

View File

@ -16,10 +16,7 @@
"type": "String"
},
"isBase":{
"type":"String",
"mysql": {
"columnName": "base"
}
"type":"String"
}
}
}