update structure from production
This commit is contained in:
parent
5187a7e15b
commit
1ea032eba8
|
@ -1,89 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCalculateClon`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT)
|
||||
BEGIN
|
||||
/*
|
||||
* @vTicketNew id del nuevo ticket clonado
|
||||
* @vTicketOld id ticket original, a partir del qual se clonara el nuevo
|
||||
* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo
|
||||
*/
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vClient INT;
|
||||
DECLARE vWarehouse SMALLINT;
|
||||
DECLARE vAgencyMode INT;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vLanded DATE;
|
||||
DECLARE vAgency INT;
|
||||
|
||||
|
||||
REPLACE INTO orderTicket(orderFk,ticketFk)
|
||||
SELECT orderFk, vTicketNew
|
||||
FROM orderTicket
|
||||
WHERE ticketFk = vTicketOld;
|
||||
|
||||
SELECT t.clientFk , t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk
|
||||
INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency
|
||||
FROM vn.agencyMode a
|
||||
JOIN vn.ticket t ON t.agencyModeFk = a.id
|
||||
WHERE t.id = vTicketNew;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped;
|
||||
CREATE TEMPORARY TABLE tmp.agencyHourGetShipped ENGINE = MEMORY
|
||||
SELECT vWarehouse warehouseFk, vShipped shipped, vLanded landed;
|
||||
|
||||
CALL buyUltimate(vWarehouse, vShipped); -- rellena la tabla tmp.buyUltimate con la ultima compra
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot
|
||||
SELECT vWarehouse warehouseFk,NULL available,s.itemFk, bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk;
|
||||
|
||||
CALL ticketComponentCalculate(vAddress,vAgencyMode);
|
||||
|
||||
-- Bionizamos lineas con Preu = 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew AND s.price = 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(1);
|
||||
|
||||
-- Bionizamos lineas con Preu > 0
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
|
||||
SELECT s.id saleFk, vWarehouse warehouseFk
|
||||
FROM sale s
|
||||
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew
|
||||
AND s.price > 0;
|
||||
|
||||
CALL ticketComponentUpdateSale(6);
|
||||
|
||||
IF vLanded IS NULL THEN
|
||||
CALL agencyHourGetLanded(vShipped, vAddress, vAgency,vWarehouse);
|
||||
|
||||
UPDATE ticket t
|
||||
JOIN tmp.agencyHourGetLanded ah ON t.warehouseFk = ah.warehouseFk
|
||||
SET t.landed = ah.landed
|
||||
WHERE t.id = vTicketNew;
|
||||
END IF;
|
||||
|
||||
-- Log
|
||||
CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket');
|
||||
|
||||
-- Limpieza
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
SET FOREIGN_KEY_CHECKS=0;
|
||||
DROP TABLE IF EXISTS `vn2008`.`department`;
|
||||
|
||||
CREATE TABLE `vn2008`.`department` (
|
||||
`department_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`lft` int(11) NOT NULL,
|
||||
`rgt` int(11) NOT NULL,
|
||||
`Id_Trabajador` int(11) DEFAULT NULL COMMENT 'Id_Trabajador es el jefe del departamento',
|
||||
`company_id` int(11) NOT NULL,
|
||||
`father_id` int(11) DEFAULT NULL,
|
||||
`boss_id` int(11) DEFAULT NULL,
|
||||
`x` int(11) DEFAULT NULL,
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`production` tinyint(4) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`department_id`),
|
||||
UNIQUE KEY `lft_UNIQUE` (`lft`),
|
||||
UNIQUE KEY `rgt_UNIQUE` (`rgt`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`),
|
||||
KEY `fk_department_Trabajadores1_idx` (`Id_Trabajador`),
|
||||
KEY `dep_org_ibfk_3_idx` (`company_id`),
|
||||
KEY `fk_department_department1_idx` (`father_id`),
|
||||
KEY `fk_department_department1_idx_idx` (`father_id`),
|
||||
CONSTRAINT `fk_department_Trabajadores1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_department_department1_idx` FOREIGN KEY (`father_id`) REFERENCES `department` (`department_id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||||
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=1;
|
|
@ -1,6 +0,0 @@
|
|||
CREATE OR REPLACE VIEW vn.labourHolidayType
|
||||
AS SELECT
|
||||
`cf`.`calendar_free_id` AS `id`,
|
||||
`cf`.`type` AS `name`,
|
||||
`cf`.`rgb` AS `rgb`
|
||||
FROM `postgresql`.`calendar_free` `cf`;
|
|
@ -1,5 +0,0 @@
|
|||
CREATE OR REPLACE VIEW vn.labourHolidayLegend
|
||||
AS SELECT
|
||||
`cll`.`calendar_labour_legend_id` AS `id`,
|
||||
`cll`.`descripcion` AS `description`
|
||||
FROM `postgresql`.`calendar_labour_legend` `cll`;
|
|
@ -1,8 +0,0 @@
|
|||
CREATE OR REPLACE VIEW vn.labourHoliday
|
||||
AS SELECT
|
||||
`cl`.`calendar_labour_legend_id` AS `labourHolidayLegendFk`,
|
||||
`cl`.`calendar_free_id` AS `labourHolidayTypeFk`,
|
||||
`cl`.`workcenter_id` AS `workCenterFk`,
|
||||
`cl`.`day` AS `dated`
|
||||
FROM
|
||||
`postgresql`.`calendar_labour` `cl`;
|
|
@ -1,34 +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 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(255) DEFAULT CONCAT(IFNULL(vEntity, ''), 'Log');
|
||||
|
||||
SET @sqlQuery = CONCAT(
|
||||
'INSERT INTO vn.', vTableName, ' SET originFk = ?, userFk = ?, action = ?, description = ?'
|
||||
);
|
||||
SET @originFk = vOriginFk;
|
||||
SET @userFk = vUserId;
|
||||
SET @action = vActionCode;
|
||||
SET @description = vDescription;
|
||||
|
||||
PREPARE stmt FROM @sqlQuery;
|
||||
EXECUTE stmt USING @originFk, @userFk, @action, @description;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
SET @sqlQuery = NULL;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `logAdd`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `logAdd`(vOriginFk 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 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
|
||||
*/
|
||||
|
||||
CALL logAddWithUser(vOriginFk, account.userGetId(), vActionCode, vEntity, vDescription);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketCreate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreate`(
|
||||
vClientId INT
|
||||
,vShipped DATE
|
||||
,vWarehouseId INT
|
||||
,vCompanyFk INT
|
||||
,vAddressFk INT
|
||||
,vAgencyType INT
|
||||
,vRouteFk INT
|
||||
,vlanded DATE
|
||||
,OUT vNewTicket INT)
|
||||
BEGIN
|
||||
CALL `ticketCreateWithUser`(vClientId, vShipped, vWarehouseId, vCompanyFk, vAddressFk, vAgencyType, vRouteFk, vlanded, account.userGetId(), vNewTicket);
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -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 OR vAddressFk IS NULL 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 ;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `orderConfirm`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirm`(vOrder INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Confirms an order, creating each of its tickets on
|
||||
* the corresponding date and store.
|
||||
*
|
||||
* @param vOrder The order identifier
|
||||
*/
|
||||
CALL orderConfirmWithUser(vOrder, account.userGetId());
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,233 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `orderConfirmWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirmWithUser`(vOrder INT, vUserId INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Confirms an order, creating each of its tickets on
|
||||
* the corresponding date, store and user
|
||||
*
|
||||
* @param vOrder The order identifier
|
||||
*@param vUser The user identifier
|
||||
*/
|
||||
DECLARE vOk BOOL;
|
||||
DECLARE vDone BOOL DEFAULT FALSE;
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vShipment DATETIME;
|
||||
DECLARE vTicket INT;
|
||||
DECLARE vNotes VARCHAR(255);
|
||||
DECLARE vItem INT;
|
||||
DECLARE vConcept VARCHAR(30);
|
||||
DECLARE vAmount INT;
|
||||
DECLARE vPrice DECIMAL(10,2);
|
||||
DECLARE vSale INT;
|
||||
DECLARE vRate INT;
|
||||
DECLARE vRowId INT;
|
||||
DECLARE vDelivery DATE;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vAgency INT;
|
||||
DECLARE vIsConfirmed BOOL;
|
||||
DECLARE vClientId INT;
|
||||
DECLARE vCompanyId INT;
|
||||
DECLARE vAgencyModeId INT;
|
||||
|
||||
DECLARE TICKET_FREE INT DEFAULT 2;
|
||||
DECLARE SYSTEM_WORKER INT DEFAULT 20;
|
||||
|
||||
DECLARE cDates CURSOR FOR
|
||||
SELECT ah.shipped, r.warehouse_id
|
||||
FROM `order` o
|
||||
JOIN order_row r ON r.order_id = o.id
|
||||
LEFT JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = r.warehouse_id
|
||||
WHERE o.id = vOrder AND r.amount != 0
|
||||
GROUP BY warehouse_id;
|
||||
|
||||
DECLARE cRows CURSOR FOR
|
||||
SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate
|
||||
FROM order_row r
|
||||
JOIN vn2008.Articles a ON a.Id_Article = r.item_id
|
||||
WHERE r.amount != 0
|
||||
AND r.warehouse_id = vWarehouse
|
||||
AND r.order_id = vOrder
|
||||
ORDER BY r.rate DESC;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
-- Carga los datos del pedido
|
||||
|
||||
SELECT o.date_send, o.address_id, o.note, a.agency_id,
|
||||
o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id
|
||||
INTO vDelivery, vAddress, vNotes, vAgency,
|
||||
vIsConfirmed, vClientId, vCompanyId, vAgencyModeId
|
||||
FROM hedera.`order` o
|
||||
JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id
|
||||
JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id
|
||||
WHERE id = vOrder;
|
||||
|
||||
-- Comprueba que el pedido no está confirmado
|
||||
|
||||
IF vIsConfirmed THEN
|
||||
CALL util.throw ('ORDER_ALREADY_CONFIRMED');
|
||||
END IF;
|
||||
|
||||
-- Comprueba que el pedido no está vacío
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vOk
|
||||
FROM order_row WHERE order_id = vOrder AND amount > 0;
|
||||
|
||||
IF !vOk THEN
|
||||
CALL util.throw ('ORDER_EMPTY');
|
||||
END IF;
|
||||
|
||||
-- Carga las fechas de salida de cada almacén
|
||||
|
||||
CALL vn.agencyHourGetShipped (vDelivery, vAddress, vAgency);
|
||||
|
||||
-- Trabajador que realiza la acción
|
||||
|
||||
IF vUserId IS NULL THEN
|
||||
SELECT employeeFk INTO vUserId FROM orderConfig;
|
||||
END IF;
|
||||
|
||||
-- Crea los tickets del pedido
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
OPEN cDates;
|
||||
|
||||
lDates:
|
||||
LOOP
|
||||
SET vTicket = NULL;
|
||||
SET vDone = FALSE;
|
||||
FETCH cDates INTO vShipment, vWarehouse;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE lDates;
|
||||
END IF;
|
||||
|
||||
-- Busca un ticket existente que coincida con los parametros del nuevo pedido
|
||||
|
||||
SELECT Id_Ticket INTO vTicket
|
||||
FROM vn2008.Tickets t
|
||||
LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
|
||||
JOIN `order` o
|
||||
ON o.address_id = t.Id_Consigna
|
||||
AND vWarehouse = t.warehouse_id
|
||||
AND o.agency_id = t.Id_Agencia
|
||||
AND t.landing = o.date_send
|
||||
AND vShipment = DATE(t.Fecha)
|
||||
WHERE o.id = vOrder
|
||||
AND t.Factura IS NULL
|
||||
AND IFNULL(tls.alertLevel,0) = 0
|
||||
AND t.Id_Cliente <> 1118
|
||||
LIMIT 1;
|
||||
|
||||
-- Crea el ticket en el caso de no existir uno adecuado
|
||||
|
||||
IF vTicket IS NULL
|
||||
THEN
|
||||
CALL vn.ticketCreateWithUser(
|
||||
vClientId,
|
||||
IFNULL(vShipment, CURDATE()),
|
||||
vWarehouse,
|
||||
vCompanyId,
|
||||
vAddress,
|
||||
vAgencyModeId,
|
||||
NULL,
|
||||
vDelivery,
|
||||
vUserId,
|
||||
vTicket
|
||||
);
|
||||
ELSE
|
||||
INSERT INTO vncontrol.inter
|
||||
SET Id_Ticket = vTicket,
|
||||
Id_Trabajador = SYSTEM_WORKER,
|
||||
state_id = TICKET_FREE;
|
||||
END IF;
|
||||
|
||||
INSERT IGNORE INTO vn2008.order_Tickets
|
||||
SET order_id = vOrder,
|
||||
Id_Ticket = vTicket;
|
||||
|
||||
-- Añade las notas
|
||||
|
||||
IF vNotes IS NOT NULL AND vNotes != ''
|
||||
THEN
|
||||
INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text)
|
||||
VALUES (vTicket, 4/*comercial*/ , vNotes)
|
||||
ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text);
|
||||
END IF;
|
||||
|
||||
-- Añade los movimientos y sus componentes
|
||||
|
||||
OPEN cRows;
|
||||
|
||||
lRows:
|
||||
LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE lRows;
|
||||
END IF;
|
||||
|
||||
INSERT INTO vn2008.Movimientos
|
||||
SET
|
||||
Id_Article = vItem,
|
||||
Id_Ticket = vTicket,
|
||||
Concepte = vConcept,
|
||||
Cantidad = vAmount,
|
||||
Preu = vPrice,
|
||||
CostFixat = 0,
|
||||
PrecioFijado = TRUE;
|
||||
|
||||
SET vSale = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor)
|
||||
SELECT vSale, cm.component_id, cm.price
|
||||
FROM order_component cm
|
||||
JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id
|
||||
WHERE cm.order_row_id = vRowId
|
||||
GROUP BY vSale, cm.component_id;
|
||||
|
||||
UPDATE order_row SET Id_Movimiento = vSale
|
||||
WHERE id = vRowId;
|
||||
|
||||
END LOOP;
|
||||
|
||||
CLOSE cRows;
|
||||
|
||||
-- Fija el Costfixat
|
||||
|
||||
UPDATE vn2008.Movimientos m
|
||||
JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento
|
||||
FROM vn2008.Movimientos_componentes mc
|
||||
JOIN bi.tarifa_componentes tc USING(Id_Componente)
|
||||
JOIN bi.tarifa_componentes_series tcs on tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id AND tcs.base
|
||||
JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
|
||||
WHERE m.Id_Ticket = vTicket
|
||||
GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento
|
||||
SET m.CostFixat = sum_valor;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cDates;
|
||||
|
||||
DELETE FROM basketOrder WHERE orderFk = vOrder;
|
||||
UPDATE `order` SET confirmed = TRUE, confirm_date = NOW()
|
||||
WHERE id = vOrder;
|
||||
|
||||
COMMIT;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `department` AS
|
||||
SELECT
|
||||
`b`.`department_id` AS `id`,
|
||||
`b`.`name` AS `name`,
|
||||
`b`.`father_id` AS `fatherFk`,
|
||||
`b`.`production` AS `isProduction`
|
||||
FROM
|
||||
`vn2008`.`department` `b`;
|
|
@ -1,17 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `workerMedia` AS
|
||||
SELECT
|
||||
`p`.`id_trabajador` AS `workerFk`,
|
||||
`m`.`value` AS `mediaValue`
|
||||
FROM
|
||||
((((`postgresql`.`person` `p`
|
||||
JOIN `postgresql`.`profile` `po` ON ((`po`.`person_id` = `p`.`person_id`)))
|
||||
JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`)))
|
||||
JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`)))
|
||||
JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`)))
|
||||
WHERE
|
||||
(`mt`.`name` = 'movil empresa');
|
|
@ -1,30 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn2008`.`expeditionsBeforeInsert`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn2008`$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `expeditionsBeforeInsert`
|
||||
BEFORE INSERT ON `expeditions` FOR EACH ROW
|
||||
-- Edit trigger body code below this line. Do not edit lines above this one
|
||||
BEGIN
|
||||
DECLARE intcounter INT;
|
||||
DECLARE vShipFk INT;
|
||||
|
||||
IF NEW.EsBulto > 0 THEN
|
||||
|
||||
UPDATE Tickets SET Bultos = nz(Bultos) + 1 WHERE Id_Ticket = NEW.ticket_id;
|
||||
SELECT IFNULL(MAX(counter),0) +1 INTO intcounter FROM expeditions e
|
||||
INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket
|
||||
LEFT JOIN vn.ticketState ts ON ts.ticket = t1.Id_Ticket
|
||||
INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha) AND t1.warehouse_id = t2.warehouse_id
|
||||
WHERE t2.Id_Ticket = NEW.ticket_id AND ts.alertLevel < 3 AND t1.empresa_id = t2.empresa_id AND t1.Id_Agencia = t2.Id_Agencia;
|
||||
SET NEW.`counter` = intcounter;
|
||||
END IF;
|
||||
SET NEW.workerFk=get_Trabajador();
|
||||
|
||||
-- JGF 14/01/19 si existe un polizon queda anulado
|
||||
SELECT shipFk INTO vShipFk FROM vn.stowaway WHERE id = NEW.ticket_id;
|
||||
IF vShipFk THEN
|
||||
CALL vn.stowawayUnBoarding(vShipFk, NEW.ticket_id);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,19 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn2008`.`expeditionsBeforeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn2008`$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`expeditionsBeforeUpdate`
|
||||
BEFORE UPDATE ON `vn2008`.`expeditions`
|
||||
FOR EACH ROW
|
||||
-- Edit trigger body code below this line. Do not edit lines above this one
|
||||
BEGIN
|
||||
IF NEW.counter <> OLD.counter THEN
|
||||
IF (SELECT COUNT(*) FROM expeditions e
|
||||
INNER JOIN Tickets t1 ON e.ticket_id = t1.Id_Ticket
|
||||
INNER JOIN Tickets t2 ON t2.Id_Consigna = t1.Id_Consigna AND DATE(t2.Fecha) = DATE(t1.Fecha)
|
||||
WHERE t1.Id_Ticket = NEW.ticket_id AND counter = NEW.counter) > 0 THEN
|
||||
SET NEW.expeditions_id = NULL;
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,72 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `clientGetDebt`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `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 > vEnded
|
||||
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 ;
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`workerDepartment` AS
|
||||
SELECT
|
||||
`p`.`id_trabajador` AS `workerFk`,
|
||||
`d`.`name` AS `departmentFk`
|
||||
FROM
|
||||
(((`postgresql`.`person` `p`
|
||||
JOIN `postgresql`.`profile` `pr` ON ((`pr`.`person_id` = `p`.`person_id`)))
|
||||
LEFT JOIN (`postgresql`.`business` `b`
|
||||
LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) ON ((`pr`.`profile_id` = `b`.`client_id`)))
|
||||
JOIN `vn`.`department` `d` ON ((`d`.`id` = `bl`.`department_id`)))
|
||||
WHERE
|
||||
(ISNULL(`b`.`date_end`)
|
||||
OR (`b`.`date_end` > CURDATE()));
|
|
@ -1,11 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`businessReasonEnd` AS
|
||||
SELECT
|
||||
`b`.`id` AS `id`,
|
||||
`b`.`reason` AS `reason`
|
||||
FROM
|
||||
`vn2008`.`businessReasonEnd` `b`;
|
|
@ -1,13 +0,0 @@
|
|||
ALTER TABLE `postgresql`.`business_labour`
|
||||
DROP FOREIGN KEY `business_labour_department`;
|
||||
|
||||
|
||||
|
||||
ALTER TABLE `postgresql`.`business_labour`
|
||||
ADD INDEX `business_labour_department_idx` (`department_id` ASC);
|
||||
ALTER TABLE `postgresql`.`business_labour`
|
||||
ADD CONSTRAINT `business_labour_department`
|
||||
FOREIGN KEY (`department_id`)
|
||||
REFERENCES `vn2008`.`department` (`department_id`)
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE CASCADE;
|
|
@ -1,13 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn2008`.`expeditionsBeforeDelete`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn2008`$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`expeditionsBeforeDelete`
|
||||
BEFORE DELETE ON `expeditions` FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE Tickets SET Bultos = (SELECT COUNT(counter)-1
|
||||
FROM expeditions WHERE ticket_id = OLD.ticket_id and EsBulto)
|
||||
WHERE Id_Ticket = OLD.ticket_id;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
CREATE TABLE `salix`.`userConfigView` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`userFk` int(10) unsigned NOT NULL,
|
||||
`tableCode` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`configuration` text COLLATE utf8_unicode_ci,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniqueUser_TableCode` (`userFk`,`tableCode`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
|
@ -1,2 +0,0 @@
|
|||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (144, 'Stowaway', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (145, 'Ticket', 'getPossibleStowaways', 'READ', 'ALLOW', 'ROLE', 'employee');
|
|
@ -1,23 +0,0 @@
|
|||
ALTER TABLE `vn2008`.`expeditions`
|
||||
ADD COLUMN `externalId` BIGINT(25) NULL DEFAULT NULL AFTER `workerFk`;
|
||||
|
||||
|
||||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`expedition` AS
|
||||
SELECT
|
||||
`e`.`expeditions_id` AS `id`,
|
||||
`e`.`agency_id` AS `agencyModeFk`,
|
||||
`e`.`ticket_id` AS `ticketFk`,
|
||||
`e`.`EsBulto` AS `isBox`,
|
||||
`e`.`odbc_date` AS `created`,
|
||||
`e`.`Id_Article` AS `itemFk`,
|
||||
`e`.`counter` AS `counter`,
|
||||
`e`.`checked` AS `checked`,
|
||||
`e`.`workerFk` AS `workerFk`,
|
||||
`e`.`externalId` AS `externalId`
|
||||
FROM
|
||||
`vn2008`.`expeditions` `e`;
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue