From 3d6593b0205ad05ae00f2d6c10d42c34448db595 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 6 Sep 2018 11:51:24 +0200 Subject: [PATCH] update structure db local --- services/db/install/changes/1.0.9/01-acl.sql | 6 - .../changes/1.0.9/02-logAddWithUser.sql | 32 ---- .../changes/1.0.9/03-ticketCreateWithUser.sql | 82 ---------- .../install/changes/1.0.9/05-clientSample.sql | 16 -- .../changes/1.1.0/01-claimBeginning.sql | 13 -- .../changes/1.1.0/03-clientGetDebtDiary.sql | 98 ------------ .../install/changes/1.1.0/04-orderListTax.sql | 16 -- .../changes/1.1.0/05-ticketGetProblems.sql | 151 ------------------ .../changes/1.1.0/07-agencyHourGetLanded.sql | 42 ----- .../install/changes/1.1.0/09-itemCategory.sql | 14 -- .../changes/1.1.0/10-ticketCalculate.sql | 117 -------------- .../changes/1.1.0/11-clientGetDebt.sql | 70 -------- .../db/install/changes/1.1.0/12-itemDiary.sql | 115 ------------- 13 files changed, 772 deletions(-) delete mode 100644 services/db/install/changes/1.0.9/01-acl.sql delete mode 100644 services/db/install/changes/1.0.9/02-logAddWithUser.sql delete mode 100644 services/db/install/changes/1.0.9/03-ticketCreateWithUser.sql delete mode 100644 services/db/install/changes/1.0.9/05-clientSample.sql delete mode 100644 services/db/install/changes/1.1.0/01-claimBeginning.sql delete mode 100644 services/db/install/changes/1.1.0/03-clientGetDebtDiary.sql delete mode 100644 services/db/install/changes/1.1.0/04-orderListTax.sql delete mode 100644 services/db/install/changes/1.1.0/05-ticketGetProblems.sql delete mode 100644 services/db/install/changes/1.1.0/07-agencyHourGetLanded.sql delete mode 100644 services/db/install/changes/1.1.0/09-itemCategory.sql delete mode 100644 services/db/install/changes/1.1.0/10-ticketCalculate.sql delete mode 100644 services/db/install/changes/1.1.0/11-clientGetDebt.sql delete mode 100644 services/db/install/changes/1.1.0/12-itemDiary.sql diff --git a/services/db/install/changes/1.0.9/01-acl.sql b/services/db/install/changes/1.0.9/01-acl.sql deleted file mode 100644 index 0124a6ad3..000000000 --- a/services/db/install/changes/1.0.9/01-acl.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (95, 'ClientNotification', '*', '*', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (96, 'ClaimAction', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (97, 'ClaimAction', '*', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (98, 'ClaimDetail', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (99, 'claimDevelopment', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (100, 'claimDevelopment', '*', 'WRITE', 'ALLOW', 'ROLE', 'salesAssistant'); \ No newline at end of file diff --git a/services/db/install/changes/1.0.9/02-logAddWithUser.sql b/services/db/install/changes/1.0.9/02-logAddWithUser.sql deleted file mode 100644 index 68dee9352..000000000 --- a/services/db/install/changes/1.0.9/02-logAddWithUser.sql +++ /dev/null @@ -1,32 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `logAddWithUser`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `logAddWithUser`(vOriginFk INT, vUserId INT, vActionCode VARCHAR(45), vEntity VARCHAR(45), vDescription TEXT) -BEGIN -/** - * Guarda las acciones realizadas por el usuario - * - * @param vOriginFk Id del registro de origen. - * @param vUserId Id del usuario. - * @param vActionCode Código de la acción {insert | delete | update}. - * @param vEntity Nombre que hace referencia a la tabla. - * @param descripcion Descripción de la acción realizada por el usuario. - */ - DECLARE vTableName VARCHAR(45); - - SET vTableName = CONCAT(vEntity, 'Log'); - - SET @qryLog := CONCAT( - 'INSERT INTO ', vTableName, ' (originFk, userFk, action, description)', - ' VALUES (', vOriginFk, ', ', vUserId, ', "', vActionCode, '", "', vDescription, '")' - ); - - PREPARE stmt FROM @qryLog; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.9/03-ticketCreateWithUser.sql b/services/db/install/changes/1.0.9/03-ticketCreateWithUser.sql deleted file mode 100644 index 6fc1abb2f..000000000 --- a/services/db/install/changes/1.0.9/03-ticketCreateWithUser.sql +++ /dev/null @@ -1,82 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketCreateWithUser`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`( - vClientId INT - ,vShipped DATE - ,vWarehouseId INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyType INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,OUT vNewTicket INT) -BEGIN - - DECLARE vClientOrnamentales INT DEFAULT 5270; - DECLARE vCompanyOrn INT DEFAULT 1381; - DECLARE vProvinceName VARCHAR(255); - - SELECT p.name INTO vProvinceName - FROM vn.client c - JOIN province p ON p.id = c.provinceFk - WHERE c.id = vClientId; - - IF vProvinceName IN ('SANTA CRUZ DE TENERIFE', 'LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN - SET vCompanyFk = vCompanyOrn; - END IF; - - IF NOT vAddressFk THEN - SELECT id INTO vAddressFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - INSERT INTO vn2008.Tickets ( - Id_Cliente, - Fecha, - Id_Consigna, - Id_Agencia, - Alias, - warehouse_id, - Id_Ruta, - empresa_id, - landing - ) - SELECT - vClientId, - vShipped, - a.id, - IF(vAgencyType, vAgencyType, a.agencyModeFk), - a.nickname, - vWarehouseId, - IF(vRouteFk,vRouteFk,NULL), - vCompanyFk, - vlanded - FROM address a - JOIN agencyMode am ON am.id = a.agencyModeFk - WHERE a.id = vAddressFk; - - SET vNewTicket = LAST_INSERT_ID(); - - INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) - SELECT vNewTicket, ao.observationTypeFk, ao.description - FROM addressObservation ao - JOIN address a ON a.id = ao.addressFk - WHERE a.id = vAddressFk; - - CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); - - IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> FALSE THEN - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, vNewTicket, getWorker() - FROM state - WHERE `code` = 'DELIVERED'; - END IF; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.9/05-clientSample.sql b/services/db/install/changes/1.0.9/05-clientSample.sql deleted file mode 100644 index 92b2f3d4a..000000000 --- a/services/db/install/changes/1.0.9/05-clientSample.sql +++ /dev/null @@ -1,16 +0,0 @@ -USE `vn`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `clientSample` AS - SELECT - `e`.`id` AS `id`, - `e`.`Id_Cliente` AS `clientFk`, - `e`.`escritos_id` AS `typeFk`, - `e`.`fecha` AS `created`, - `e`.`Id_Trabajador` AS `workerFk`, - `e`.`userFk` AS `userFk`, - `e`.`empresa_id` AS `companyFk` - FROM - `vn2008`.`escritos_det` `e`; \ No newline at end of file diff --git a/services/db/install/changes/1.1.0/01-claimBeginning.sql b/services/db/install/changes/1.1.0/01-claimBeginning.sql deleted file mode 100644 index e675c0fbe..000000000 --- a/services/db/install/changes/1.1.0/01-claimBeginning.sql +++ /dev/null @@ -1,13 +0,0 @@ -USE `vn`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `claimBeginning` AS - SELECT - `c`.`id` AS `id`, - `c`.`cl_main_id` AS `claimFk`, - `c`.`Id_Movimiento` AS `saleFk`, - `c`.`numero` AS `quantity` - FROM - `vn2008`.`cl_det` `c`; diff --git a/services/db/install/changes/1.1.0/03-clientGetDebtDiary.sql b/services/db/install/changes/1.1.0/03-clientGetDebtDiary.sql deleted file mode 100644 index 0ee4c653c..000000000 --- a/services/db/install/changes/1.1.0/03-clientGetDebtDiary.sql +++ /dev/null @@ -1,98 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `clientGetDebtDiary`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `clientGetDebtDiary`(vClientFK INT, vCompanyFk INT) -BEGIN -/** - * Devuelve el registro de deuda - * - * @param vClientFK Id del cliente - * @param vCompanyFk Id de la empresa - */ - DECLARE vDate DATETIME DEFAULT CURDATE(); - - SET @balance:= 0; - - SELECT MAX(issued) INTO vDate FROM - (SELECT - created, - issued, - @balance:= ROUND(amount, 2) + @balance AS balance - FROM invoiceOut - WHERE clientFk = vClientFk AND companyFk = vCompanyFk - - UNION ALL - - SELECT - created, - payed, - @balance:= ROUND(-1 * amountPaid, 2) + @balance AS balance - FROM receipt - WHERE clientFk = vClientFk AND companyFk = vCompanyFk - ORDER BY issued, created) balance - WHERE balance = 0; - - SELECT - issued, - CAST(debtOut AS DECIMAL(10,2)) debtOut, - CAST(debtIn AS DECIMAL(10,2)) debtIn, - ref, - companyFk, - priority - FROM - (SELECT - NULL AS issued, - SUM(amountUnpaid) AS debtOut, - NULL AS debtIn, - 'Saldo Anterior' AS ref, - companyFk, - 0 as priority - FROM - (SELECT SUM(amount) AS amountUnpaid, companyFk, 0 - FROM invoiceOut - WHERE clientFk = vClientFK - AND issued < vDate - GROUP BY companyFk - - UNION ALL - - SELECT SUM(-1 * amountPaid), companyFk, 0 - FROM receipt - WHERE clientFk = vClientFK - AND payed < vDate - GROUP BY companyFk) AS transactions - GROUP BY companyFk - - UNION ALL - - SELECT - issued, - amount as debtOut, - NULL AS debtIn, - id AS ref, - companyFk, - 1 - FROM invoiceOut - WHERE clientFk = vClientFK - AND issued >= vDate - UNION ALL - - SELECT - r.payed, - NULL as debtOut, - r.amountPaid, - r.id, - r.companyFk, - 0 - FROM receipt r - WHERE r.clientFk = vClientFK - AND r.payed >= vDate) t - INNER JOIN `client` c ON c.id = vClientFK - HAVING debtOut <> 0 OR debtIn <> 0 - ORDER BY issued, priority DESC, debtIn; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/04-orderListTax.sql b/services/db/install/changes/1.1.0/04-orderListTax.sql deleted file mode 100644 index cd1cc9296..000000000 --- a/services/db/install/changes/1.1.0/04-orderListTax.sql +++ /dev/null @@ -1,16 +0,0 @@ -USE `hedera`; -DROP procedure IF EXISTS `orderListTax`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `orderListTax`(IN vOrderId INT) -BEGIN - - CALL hedera.orderGetTax(vOrderId); - - SELECT * FROM tmp.orderTax; - -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/05-ticketGetProblems.sql b/services/db/install/changes/1.1.0/05-ticketGetProblems.sql deleted file mode 100644 index 169ee6ff2..000000000 --- a/services/db/install/changes/1.1.0/05-ticketGetProblems.sql +++ /dev/null @@ -1,151 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketGetProblems`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`() -BEGIN -/* - * Obtiene los problemas de uno o varios tickets - * - * @table tmp.ticketGetProblems(ticketFk, clientFk, warehouseFk, shipped) - * @return tmp.ticketProblems - */ - DECLARE vWarehouse INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vVisibleCache INT; - DECLARE vDone INT DEFAULT 0; - - DECLARE vCursor CURSOR FOR - SELECT DISTINCT tt.warehouseFk, date(tt.shipped) - FROM tmp.ticketGetProblems tt - WHERE DATE(tt.shipped) BETWEEN CURDATE() - AND TIMESTAMPADD(DAY, 1.9, CURDATE()); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; - CREATE TEMPORARY TABLE tmp.ticketProblems ( - ticketFk INT(11), - problem VARCHAR(50), - INDEX (ticketFk) - ) - ENGINE = MEMORY; - - -- CONGELADO - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT DISTINCT tt.ticketFk, 'Freezed' - FROM tmp.ticketGetProblems tt - JOIN vn.client c ON c.id = tt.clientFk - WHERE c.isFreezed; - - -- eliminamos tickets con problemas para no volverlos a mirar - DROP TEMPORARY TABLE IF EXISTS tmp.ticketListFiltered; - - CREATE TEMPORARY TABLE tmp.ticketListFiltered - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT tt.ticketFk, c.id - FROM tmp.ticketGetProblems tt - JOIN vn.client c ON c.id = tt.clientFk - WHERE c.isFreezed = 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT DISTINCT tt.clientFk - FROM tmp.ticketGetProblems tt; - - -- RIESGO - CALL clientGetDebt(CURDATE()); - - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT DISTINCT tt.ticketFk, 'Risk' - FROM tmp.ticketListFiltered tt - JOIN vn.ticket t ON t.id = tt.ticketFk - JOIN vn.agencyMode a ON t.agencyModeFk = a.id - JOIN tmp.risk r ON r.clientFk = t.clientFk - JOIN vn.client c ON c.id = t.clientFk - WHERE r.risk > c.credit + 10 - AND a.deliveryMethodFk != 3; -- para que las recogidas se preparen - - -- eliminamos tickets con problemas para no volverlos a mirar - DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; - - -- CODIGO 100 - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT DISTINCT tt.ticketFk, 'Code 100' - FROM tmp.ticketGetProblems tt - JOIN sale s ON s.ticketFk = tt.ticketFk - WHERE s.itemFk = 100; - - -- eliminamos tickets con problemas para no volverlos a mirar - DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; - - OPEN vCursor; - - WHILE NOT vDone - DO - FETCH vCursor INTO vWarehouse, vDate; - - CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse); - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); - - -- El disponible es menor que 0 - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT tt.ticketFk, i.name - FROM tmp.ticketListFiltered tt - JOIN vn.ticket t ON t.id = tt.ticketFk - LEFT JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN cache.visible v ON i.id = v.item_id - AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - WHERE date(t.shipped) = vDate - AND categoryFk != 6 - AND s.quantity > IFNULL(v.visible, 0) - AND IFNULL(av.available, 0) < 0 - AND s.isPicked = FALSE - AND NOT i.generic - AND vWarehouse = t.warehouseFk; - - -- eliminamos tickets con problemas para no volverlos a mirar - DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; - - -- Amarillo: El disponible es mayor que cero y la cantidad supera el visible, estando aun sin preparar - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT tt.ticketFk, CONCAT('Delay', i.name) - FROM tmp.ticketListFiltered tt - JOIN vn.ticket t ON t.id = tt.ticketFk - LEFT JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache - LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache - WHERE IFNULL(av.available, 0) >= 0 - AND s.quantity > IFNULL(v.visible, 0) - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND date(t.shipped) = vDate - AND NOT i.generic - AND CURDATE() = vDate - AND t.warehouseFk = vWarehouse; - END WHILE; - - CLOSE vCursor; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - tmp.ticketListFiltered; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/07-agencyHourGetLanded.sql b/services/db/install/changes/1.1.0/07-agencyHourGetLanded.sql deleted file mode 100644 index 091720df5..000000000 --- a/services/db/install/changes/1.1.0/07-agencyHourGetLanded.sql +++ /dev/null @@ -1,42 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `agencyHourGetLanded`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetLanded`(vDated DATE, vAddress INT, vAgency INT, vWarehouse INT) -BEGIN -/** - * Devuelve una tabla temporal con el dia de recepcion para vDated. - * - * @param vDated Fecha de preparacion de mercancia - * @param vAddress Id de consignatario, %NULL para recogida - * @param vAgency Id agencia - * @table tmp.agencyHourGetLanded Datos de recepción - */ - DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetLanded; - CREATE TEMPORARY TABLE tmp.agencyHourGetLanded - ENGINE = MEMORY - SELECT vWarehouse warehouseFk, landed FROM ( - SELECT * FROM ( - SELECT vWarehouse, TIMESTAMPADD(DAY, ah.substractDay, vDated) landed, ah.substractDay, ah.maxHour - FROM agencyHour ah - LEFT JOIN address a ON a.id = vAddress - WHERE (ah.weekDay = WEEKDAY(TIMESTAMPADD(DAY, ah.substractDay, vDated)) OR ah.weekDay IS NULL) - AND (ah.agencyFk = vAgency OR ah.agencyFk IS NULL) - AND ah.warehouseFk = vWarehouse - AND (ah.provinceFk = a.provinceFk OR ah.provinceFk IS NULL OR vAddress IS NULL) - ORDER BY ( - (ah.weekDay IS NOT NULL) + - (ah.agencyFk IS NOT NULL) + - (- ah.substractDay) + - ((ah.provinceFk IS NOT NULL)*3) - ) DESC - ) t - LIMIT 1 - ) t - WHERE IF(vDated = CURDATE(), t.maxHour > HOUR(NOW()), TRUE) AND t.substractDay < 225; - -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/09-itemCategory.sql b/services/db/install/changes/1.1.0/09-itemCategory.sql deleted file mode 100644 index cfb9781c0..000000000 --- a/services/db/install/changes/1.1.0/09-itemCategory.sql +++ /dev/null @@ -1,14 +0,0 @@ -USE `vn`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `itemCategory` AS - SELECT - `r`.`id` AS `id`, - `r`.`reino` AS `name`, - `r`.`display` AS `display`, - `r`.`color` AS `color`, - r.icon - FROM - `vn2008`.`reinos` `r`; diff --git a/services/db/install/changes/1.1.0/10-ticketCalculate.sql b/services/db/install/changes/1.1.0/10-ticketCalculate.sql deleted file mode 100644 index ae5f91804..000000000 --- a/services/db/install/changes/1.1.0/10-ticketCalculate.sql +++ /dev/null @@ -1,117 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketCalculate`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculate`( - vDate DATE, - vAddress INT, - vAgencyMode INT) -proc: BEGIN -/** - * Calcula los articulos disponibles y sus precios - * - * @param vDate Fecha de recepcion de mercancia - * @param vAddress Id del consignatario - * @param vAgencyMode Id de la agencia - * @return tmp.ticketCalculateItem, tmp.ticketComponentPrice - **/ - - DECLARE vAvailableCalc INT; - DECLARE vShipment DATE; - DECLARE vAgencyId INT; - DECLARE vClient INT; - DECLARE vWarehouseFk SMALLINT; - DECLARE vDone BOOL; - DECLARE cTravelTree CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.agencyHourGetShipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Establece los almacenes y las fechas que van a entrar al disponible - - SELECT agencyFk INTO vAgencyId - FROM agencyMode WHERE id = vAgencyMode; - - SELECT clientFk INTO vClient - FROM address WHERE id = vAddress; - - CALL vn.agencyHourGetShipped(vDate, vAddress, vAgencyId); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot( - `warehouseFk` smallint(5) unsigned NOT NULL, - `itemFk` int(11) NOT NULL, - `available` double DEFAULT NULL, - `buyFk` int(11) DEFAULT NULL, - `fix` tinyint(3) unsigned DEFAULT '0', - KEY `itemFk` (`itemFk`), - KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH - ) ENGINE=MEMORY DEFAULT CHARSET=utf8; - - OPEN cTravelTree; - - l: LOOP - SET vDone = FALSE; - FETCH cTravelTree INTO vWarehouseFk, vShipment; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipment); - CALL buyUltimate (vWarehouseFk, vShipment); - - INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk) - SELECT - vWarehouseFk, - i.item_id, - IFNULL(i.available, 0), - bu.buyFk - FROM `cache`.available i - JOIN tmp.item br ON br.itemFk = i.item_id - LEFT JOIN item it ON it.id = i.item_id - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.item_id - WHERE i.calc_id = vAvailableCalc - AND it.id != 100 - AND i.available > 0; - - DROP TEMPORARY TABLE tmp.buyUltimate; - END LOOP; - - CLOSE cTravelTree; - - CALL vn.ticketComponentCalculate(vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem; - CREATE TEMPORARY TABLE tmp.ticketCalculateItem - ENGINE = MEMORY - SELECT - b.itemFk, - SUM(b.available) available, - p.name producer, - i.name item, - i.size size, - i.stems, - i.category, - i.inkFk, - i.image, - o.code origin, bl.price - FROM tmp.ticketLot b - JOIN item i ON b.itemFk = i.id - LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible - JOIN origin o ON o.id = i.originFk - JOIN ( - SELECT MIN(price) price, itemFk - FROM tmp.ticketComponentPrice - GROUP BY itemFk - ) bl ON bl.itemFk = b.itemFk - GROUP BY b.itemFk; - - DROP TEMPORARY TABLE - tmp.ticketComponent, - tmp.ticketLot; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/11-clientGetDebt.sql b/services/db/install/changes/1.1.0/11-clientGetDebt.sql deleted file mode 100644 index 62ded4d69..000000000 --- a/services/db/install/changes/1.1.0/11-clientGetDebt.sql +++ /dev/null @@ -1,70 +0,0 @@ -DROP procedure IF EXISTS vn.`clientGetDebt`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE vn.`clientGetDebt`(vDate DATE) -BEGIN -/** - * Calcula el riesgo para los clientes activos - * - * @table tmp.clientGetDebt(clientFk) - * @param vDate Fecha maxima de los registros - * @return tmp.risk - */ - DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE()); - DECLARE vEnded DATETIME; - - SET vEnded = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59'); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk, c.clientFk - FROM ticket t - JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk - WHERE refFk IS NULL - AND shipped BETWEEN vStarted AND vEnded; - - CALL ticketGetTotal(); - - DROP TEMPORARY TABLE IF EXISTS tClientRisk; - CREATE TEMPORARY TABLE tClientRisk - ENGINE = MEMORY - SELECT cr.customer_id clientFk, SUM(cr.amount) amount - FROM bi.customer_risk cr - JOIN tmp.clientGetDebt c ON c.clientFk = cr.customer_id - GROUP BY cr.customer_id; - - INSERT INTO tClientRisk - SELECT c.clientFk, SUM(r.amountPaid) - FROM receipt r - JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk - WHERE r.payed > vStarted - GROUP BY c.clientFk; - - INSERT INTO tClientRisk - SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) - FROM hedera.tpvTransaction t - JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk - WHERE t.receiptFk IS NULL - AND t.status = 'ok' - GROUP BY t.clientFk; - - INSERT INTO tClientRisk - SELECT t.clientFk, total - FROM tmp.ticketTotal tt - JOIN tmp.ticket t ON t.ticketFk = tt.ticketFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.risk; - CREATE TEMPORARY TABLE tmp.risk - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT clientFk, SUM(amount) risk - FROM client c - JOIN tClientRisk cr ON cr.clientFk = c.id - WHERE c.isActive - GROUP BY c.id; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.1.0/12-itemDiary.sql b/services/db/install/changes/1.1.0/12-itemDiary.sql deleted file mode 100644 index 4f7ba662e..000000000 --- a/services/db/install/changes/1.1.0/12-itemDiary.sql +++ /dev/null @@ -1,115 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `itemDiary`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT) -BEGIN - DECLARE vDateInventory DATETIME; - DECLARE vCurdate DATE DEFAULT CURDATE(); - DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate); - -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance - SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores; - SET @a = 0; - SELECT sql_no_cache DATE(date) AS date, - alertLevel, - stateName, - origin, - reference, - name, - `in`, - `out`, - @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance, - isPicked, - isTicket - FROM - ( SELECT tr.landed as date, - b.quantity as `in`, - NULL as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin, - TRUE isPicked, - FALSE AS isTicket - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.landed >= vDateInventory - AND vWarehouse = tr.warehouseInFk - AND b.itemFk = vItemId - AND e.isInventory = 0 - - UNION ALL - - SELECT tr.shipped as date, - NULL as `in`, - b.quantity as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin, - TRUE isPicked, - FALSE AS isTicket - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.warehouse w ON w.id = tr.warehouseOutFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.shipped >= vDateInventory - AND vWarehouse =tr.warehouseOutFk - AND s.id <> 4 - AND b.itemFk = vItemId - AND e.isInventory = 0 - AND w.isFeedStock = 0 - - UNION ALL - - SELECT t.shipped as date, - NULL as `in`, - s.quantity as `out`, - al.alertLevel as alertLevel, - st.name AS stateName, - t.nickname as name, - t.refFk as reference, - t.id as origin, - TRUE as isPicked, -- stk.id as isPicked - TRUE as isTicket - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticket = t.id - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN t.shipped < vCurdate THEN 3 - WHEN t.shipped > vDayEnd THEN 0 - ELSE IFNULL(ts.alertLevel, 0) - END - JOIN vn.state st ON st.code = al.code - -- LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = 14 - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemId - AND vWarehouse =t.warehouseFk - ) AS itemDiary - ORDER BY date, alertLevel DESC, isPicked DESC, `in` DESC, `out` DESC; -END$$ - -DELIMITER ; -