From ae2fa8d0afade6c40bf4d27e21fb994393917370 Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 23 May 2019 09:31:37 +0200 Subject: [PATCH] 1459 export production to local --- db/changes/10002-lent/00-ACL.sql | 3 - .../10002-lent/00-clientGetSalesPerson.sql | 76 - db/changes/10002-lent/00-greugesShipped.sql | 1 - db/changes/10002-lent/00-invoiceOut.sql | 9 - db/changes/10002-lent/00-printQueue.sql | 13 - db/changes/10002-lent/00-routeLog.sql | 21 - db/changes/10002-lent/00-sharingCart.sql | 14 - db/changes/10002-lent/00-sharingclient.sql | 13 - db/changes/10002-lent/00-ticketConfig.sql | 4 - .../10002-lent/00-ticketCreateWithUser.sql | 74 - .../10002-lent/00-ticketServiceType.sql | 13 - .../10002-lent/00-workerGetHierarch.sql | 46 - db/changes/10003-easter/00-ACL.sql | 6 - db/changes/10003-easter/00-dmsView.sql | 20 - db/changes/10003-easter/00-nodeAdd.sql | 71 - db/changes/10003-easter/00-nodeDelete.sql | 34 - db/changes/10003-easter/00-nodeRecalc.sql | 23 - .../10003-easter/01-dmsTicketRename.sql | 12 - .../10003-easter/02-dmsTypeAddRoleFields.sql | 7 - db/changes/10003-easter/03-dmsType.sql | 13 - db/dump/dumpedFixtures.sql | 34 +- db/dump/structure.sql | 6703 +++++++++-------- .../05-ticket-module/12_descriptor.spec.js | 2 +- .../specs/activeWorkersWithRole.spec.js | 2 +- 24 files changed, 3759 insertions(+), 3455 deletions(-) delete mode 100644 db/changes/10002-lent/00-ACL.sql delete mode 100644 db/changes/10002-lent/00-clientGetSalesPerson.sql delete mode 100644 db/changes/10002-lent/00-greugesShipped.sql delete mode 100644 db/changes/10002-lent/00-invoiceOut.sql delete mode 100644 db/changes/10002-lent/00-printQueue.sql delete mode 100644 db/changes/10002-lent/00-routeLog.sql delete mode 100644 db/changes/10002-lent/00-sharingCart.sql delete mode 100644 db/changes/10002-lent/00-sharingclient.sql delete mode 100644 db/changes/10002-lent/00-ticketConfig.sql delete mode 100644 db/changes/10002-lent/00-ticketCreateWithUser.sql delete mode 100644 db/changes/10002-lent/00-ticketServiceType.sql delete mode 100644 db/changes/10002-lent/00-workerGetHierarch.sql delete mode 100644 db/changes/10003-easter/00-ACL.sql delete mode 100644 db/changes/10003-easter/00-dmsView.sql delete mode 100644 db/changes/10003-easter/00-nodeAdd.sql delete mode 100644 db/changes/10003-easter/00-nodeDelete.sql delete mode 100644 db/changes/10003-easter/00-nodeRecalc.sql delete mode 100644 db/changes/10003-easter/01-dmsTicketRename.sql delete mode 100644 db/changes/10003-easter/02-dmsTypeAddRoleFields.sql delete mode 100644 db/changes/10003-easter/03-dmsType.sql diff --git a/db/changes/10002-lent/00-ACL.sql b/db/changes/10002-lent/00-ACL.sql deleted file mode 100644 index bc2e7f068..000000000 --- a/db/changes/10002-lent/00-ACL.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - (160, 'TicketServiceType', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10002-lent/00-clientGetSalesPerson.sql b/db/changes/10002-lent/00-clientGetSalesPerson.sql deleted file mode 100644 index f93e528a2..000000000 --- a/db/changes/10002-lent/00-clientGetSalesPerson.sql +++ /dev/null @@ -1,76 +0,0 @@ - -DROP function IF EXISTS `vn`.`clientGetSalesPerson`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` FUNCTION `vn`.`clientGetSalesPerson`(vClientFk INT, vDated DATE) RETURNS int(11) - DETERMINISTIC -BEGIN -/** - * Dado un id cliente y una fecha, devuelve su comercial para ese dia, teniendo - * en cuenta la jerarquía de las tablas: 1º la de sharingClient, 2º la de - * sharingCart y tercero la de clientes. - * - * @param vClientFk El id del cliente - * @param vDated Fecha a comprobar - * @return El id del comercial para la fecha dada - **/ - DECLARE vSalesperson INT DEFAULT NULL; - DECLARE vSubstitute INT DEFAULT NULL; - DECLARE vLoop BOOLEAN; - - -- Obtiene el comercial original y el de sharingClient - - SELECT c.salesPersonFk, s.workerFk - INTO vSalesperson, vSubstitute - FROM client c - LEFT JOIN sharingClient s - ON c.id = s.clientFk - AND vDated BETWEEN s.started AND s.ended - WHERE c.id = vClientFk - ORDER BY s.id - LIMIT 1; - - -- Si no hay ninguno en sharingClient busca en sharingCart - - IF vSubstitute IS NOT NULL - THEN - SET vSalesperson = vSubstitute; - ELSEIF vSalesperson IS NOT NULL - THEN - DROP TEMPORARY TABLE IF EXISTS tmp.stack; - CREATE TEMPORARY TABLE tmp.stack - (INDEX (substitute)) - ENGINE = MEMORY - SELECT vSalesperson substitute; - - l: LOOP - SELECT workerSubstitute INTO vSubstitute - FROM sharingCart - WHERE vDated BETWEEN started AND ended - AND workerFk = vSalesperson - ORDER BY id - LIMIT 1; - - IF vSubstitute IS NULL THEN - LEAVE l; - END IF; - - SELECT COUNT(*) > 0 INTO vLoop - FROM tmp.stack WHERE substitute = vSubstitute; - - IF vLoop THEN - LEAVE l; - END IF; - - INSERT INTO tmp.stack SET - substitute = vSubstitute; - - SET vSalesperson = vSubstitute; - END LOOP; - - DROP TEMPORARY TABLE tmp.stack; - END IF; - - RETURN vSalesperson; -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/db/changes/10002-lent/00-greugesShipped.sql b/db/changes/10002-lent/00-greugesShipped.sql deleted file mode 100644 index 25cb4df2f..000000000 --- a/db/changes/10002-lent/00-greugesShipped.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `vn2008`.`Greuges` CHANGE COLUMN `Fecha` `Fecha` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ; \ No newline at end of file diff --git a/db/changes/10002-lent/00-invoiceOut.sql b/db/changes/10002-lent/00-invoiceOut.sql deleted file mode 100644 index ed58227ac..000000000 --- a/db/changes/10002-lent/00-invoiceOut.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE `vn2008`.`Facturas` -DROP FOREIGN KEY `invoice_bank_id`; -ALTER TABLE `vn2008`.`Facturas` -CHANGE COLUMN `Id_Banco` `Id_Banco` INT(11) NULL DEFAULT NULL ; -ALTER TABLE `vn2008`.`Facturas` -ADD CONSTRAINT `invoice_bank_id` - FOREIGN KEY (`Id_Banco`) - REFERENCES `vn2008`.`Bancos` (`Id_Banco`) - ON UPDATE CASCADE; diff --git a/db/changes/10002-lent/00-printQueue.sql b/db/changes/10002-lent/00-printQueue.sql deleted file mode 100644 index f4fd5b569..000000000 --- a/db/changes/10002-lent/00-printQueue.sql +++ /dev/null @@ -1,13 +0,0 @@ -ALTER TABLE `vn2008`.`Colas` -DROP FOREIGN KEY `Colas_ibfk_1`, -DROP FOREIGN KEY `Colas_ibfk_2`, -DROP FOREIGN KEY `Colas_ibfk_3`, -DROP FOREIGN KEY `Colas_ibfk_5`; -ALTER TABLE `vn2008`.`Colas` -CHANGE COLUMN `Id_Impresora` `Id_Impresora` TINYINT(3) UNSIGNED NULL DEFAULT NULL , -CHANGE COLUMN `Id_Prioridad` `Id_Prioridad` TINYINT(3) UNSIGNED NULL DEFAULT NULL ; -ALTER TABLE `vn2008`.`Colas` -ADD CONSTRAINT `Colas_ibfk_3` - FOREIGN KEY (`Id_Prioridad`) - REFERENCES `vn2008`.`Prioridades` (`Id_Prioridad`) - ON UPDATE CASCADE; diff --git a/db/changes/10002-lent/00-routeLog.sql b/db/changes/10002-lent/00-routeLog.sql deleted file mode 100644 index b6430fcb6..000000000 --- a/db/changes/10002-lent/00-routeLog.sql +++ /dev/null @@ -1,21 +0,0 @@ -DROP TABLE IF EXISTS `vn`.`routeLog`; - -CREATE TABLE `vn`.`routeLog` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `originFk` int(10) unsigned 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 `originFk` (`originFk`), - KEY `userFk` (`userFk`), - CONSTRAINT `routeLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Rutas` (`Id_Ruta`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `routeLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - diff --git a/db/changes/10002-lent/00-sharingCart.sql b/db/changes/10002-lent/00-sharingCart.sql deleted file mode 100644 index 1267cd044..000000000 --- a/db/changes/10002-lent/00-sharingCart.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE - ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`sharingCart` AS - SELECT - `s`.`id` AS `id`, - `s`.`Id_Trabajador` AS `workerFk`, - `s`.`datSTART` AS `started`, - `s`.`datEND` AS `ended`, - `s`.`Id_Suplente` AS `workerSubstitute`, - `s`.`odbc_date` AS `created` - FROM - `vn2008`.`sharingcart` `s` \ No newline at end of file diff --git a/db/changes/10002-lent/00-sharingclient.sql b/db/changes/10002-lent/00-sharingclient.sql deleted file mode 100644 index ab76ec6c5..000000000 --- a/db/changes/10002-lent/00-sharingclient.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`sharingClient` AS - SELECT - `s`.`id` AS `id`, - `s`.`Id_Trabajador` AS `workerFk`, - `s`.`datSTART` AS `started`, - `s`.`datEND` AS `ended`, - `s`.`Id_Cliente` AS `clientFk` - FROM - `vn2008`.`sharingclient` `s`; diff --git a/db/changes/10002-lent/00-ticketConfig.sql b/db/changes/10002-lent/00-ticketConfig.sql deleted file mode 100644 index 8c93d084f..000000000 --- a/db/changes/10002-lent/00-ticketConfig.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP TABLE IF EXISTS `vn`.`ticketConfig`; - -CREATE TABLE `vn`.`ticketConfig` (`id` INT NOT NULL AUTO_INCREMENT, `scopeDays` TINYINT(3) NULL, PRIMARY KEY (`id`)); -INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) VALUES ('1', '6'); diff --git a/db/changes/10002-lent/00-ticketCreateWithUser.sql b/db/changes/10002-lent/00-ticketCreateWithUser.sql deleted file mode 100644 index e8578ac98..000000000 --- a/db/changes/10002-lent/00-ticketCreateWithUser.sql +++ /dev/null @@ -1,74 +0,0 @@ - -DROP procedure IF EXISTS `vn`.`ticketCreateWithUser`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketCreateWithUser`( - vClientId INT - ,vShipped DATE - ,vWarehouseId INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyType INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,OUT vNewTicket INT) -BEGIN - - IF vClientId IS NULL THEN - CALL util.throw ('CLIENT_NOT_ESPECIFIED'); - 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)); - INSERT INTO vn.ticketLog - SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); - - IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.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/db/changes/10002-lent/00-ticketServiceType.sql b/db/changes/10002-lent/00-ticketServiceType.sql deleted file mode 100644 index 5f887a10f..000000000 --- a/db/changes/10002-lent/00-ticketServiceType.sql +++ /dev/null @@ -1,13 +0,0 @@ -DROP TABLE IF EXISTS `vn`.`ticketServiceType`; - -CREATE TABLE vn.`ticketServiceType` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de los posibles servicios a elegir'; - -INSERT INTO `vn`.`ticketServiceType` (`name`) VALUES ('Porte Agencia'); -INSERT INTO `vn`.`ticketServiceType` (`name`) VALUES ('Portes Retorno'); -INSERT INTO `vn`.`ticketServiceType` (`name`) VALUES ('Porte Carry'); -INSERT INTO `vn`.`ticketServiceType` (`name`) VALUES ('Cargo FITOSANITARIO'); -INSERT INTO `vn`.`ticketServiceType` (`name`) VALUES ('Documentos'); diff --git a/db/changes/10002-lent/00-workerGetHierarch.sql b/db/changes/10002-lent/00-workerGetHierarch.sql deleted file mode 100644 index 8070a0ee2..000000000 --- a/db/changes/10002-lent/00-workerGetHierarch.sql +++ /dev/null @@ -1,46 +0,0 @@ -DROP procedure IF EXISTS `vn`.`worker_getHierarch`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`worker_getHierarch`(vBoss INT) -BEGIN - DECLARE EXIT HANDLER FOR 1062 BEGIN - CALL util.throw('INFINITE_LOOP'); - END; - - DROP TEMPORARY TABLE IF EXISTS workerHierarch; - CREATE TEMPORARY TABLE workerHierarch - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchList; - CREATE TEMPORARY TABLE tmp.workerHierarchList - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk, 0 AS isChecked; - - - WHILE (SELECT COUNT(*) FROM tmp.workerHierarchList WHERE NOT isChecked) > 0 DO - - INSERT INTO tmp.workerHierarchList - SELECT w.id, 0 - FROM worker w - JOIN workerHierarch wh ON wh.workerFk = w.bossFk; - - UPDATE tmp.workerHierarchList whl - JOIN workerHierarch wh ON wh.workerFk = whl.workerFk - SET whl.isChecked = 1; - - TRUNCATE workerHierarch; - - INSERT INTO workerHierarch - SELECT workerFk - FROM tmp.workerHierarchList - WHERE NOT isChecked; - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS workerHierarch; -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/db/changes/10003-easter/00-ACL.sql b/db/changes/10003-easter/00-ACL.sql deleted file mode 100644 index 7485b5a0e..000000000 --- a/db/changes/10003-easter/00-ACL.sql +++ /dev/null @@ -1,6 +0,0 @@ -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (161, 'TicketConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (162, 'InvoiceOut', 'delete', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (163, 'InvoiceOut', 'book', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (164, 'InvoiceOut', 'regenerate', 'WRITE', 'ALLOW', 'ROLE', 'invoicing'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (165, 'TicketDms', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (166, 'Dms', 'download', 'READ', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10003-easter/00-dmsView.sql b/db/changes/10003-easter/00-dmsView.sql deleted file mode 100644 index 88d32f93c..000000000 --- a/db/changes/10003-easter/00-dmsView.sql +++ /dev/null @@ -1,20 +0,0 @@ -USE `vn`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`dms` AS - SELECT - `g`.`id` AS `id`, - `g`.`gesttip_id` AS `dmsTypeFk`, - `g`.`file` AS `file`, - `g`.`trabajador_id` AS `workerFk`, - `g`.`warehouse_id` AS `warehouseFk`, - `g`.`emp_id` AS `companyFk`, - `g`.`orden` AS `priority`, - `g`.`file` AS `hasFile`, - `g`.`sref` AS `reference`, - `g`.`brief` AS `description`, - `g`.`odbc_date` AS `created` - FROM - `vn2008`.`gestdoc` `g` \ No newline at end of file diff --git a/db/changes/10003-easter/00-nodeAdd.sql b/db/changes/10003-easter/00-nodeAdd.sql deleted file mode 100644 index 80c716b45..000000000 --- a/db/changes/10003-easter/00-nodeAdd.sql +++ /dev/null @@ -1,71 +0,0 @@ -DROP procedure IF EXISTS `nst`.`nodeAdd`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeAdd`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100)) -BEGIN - DECLARE vSql TEXT; - DECLARE vTableClone VARCHAR(45); - - SET vTableClone = CONCAT(vTable, 'Clone'); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); - CALL util.exec(CONCAT( - 'CREATE TEMPORARY TABLE tmp.', vTableClone, - ' ENGINE = MEMORY', - ' SELECT * FROM ', vScheme, '.', vTable - )); - - CALL util.exec(CONCAT( - 'SELECT COUNT(c.id) INTO @childs', - ' FROM ', vScheme, '.', vTable, ' p', - ' LEFT JOIN tmp.', vTableClone, ' c ON c.lft', - ' BETWEEN p.lft AND p.rgt AND c.id != ', vParentFk, - ' WHERE p.id = ', vParentFk - )); - - IF @childs = 0 THEN - CALL util.exec(CONCAT( - 'SELECT lft INTO @vLeft', - ' FROM ', vScheme, '.', vTable, - ' WHERE id = ', vParentFk - )); - ELSE - CALL util.exec(CONCAT( - 'SELECT c.rgt INTO @vLeft', - ' FROM ', vScheme, '.', vTable, ' p', - ' JOIN tmp.', vTableClone, ' c ON c.lft BETWEEN p.lft AND p.rgt', - ' WHERE p.id = ', vParentFk, - ' ORDER BY c.lft', - ' DESC LIMIT 1' - )); - END IF; - - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET rgt = rgt + 2', - ' WHERE rgt > @vLeft', - ' ORDER BY rgt DESC' - )); - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET lft = lft + 2', - ' WHERE lft > @vLeft', - ' ORDER BY lft DESC' - )); - - SET vChild = REPLACE(vChild, "'", "\\'"); - - CALL util.exec(CONCAT( - 'INSERT INTO ', vScheme, '.', vTable, ' (name, lft, rgt)', - ' VALUES ("', vChild, '", @vLeft + 1, @vLeft + 2)' - )); - - CALL util.exec(CONCAT( - 'SELECT id, name, lft, rgt, depth, sons', - ' FROM ', vScheme, '.', vTable, - ' WHERE id = LAST_INSERT_ID()' - )); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); -END$$ - -DELIMITER ; - diff --git a/db/changes/10003-easter/00-nodeDelete.sql b/db/changes/10003-easter/00-nodeDelete.sql deleted file mode 100644 index 906428c88..000000000 --- a/db/changes/10003-easter/00-nodeDelete.sql +++ /dev/null @@ -1,34 +0,0 @@ -DROP procedure IF EXISTS `nst`.`nodeDelete`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeDelete`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vNodeId` INT) -BEGIN - DECLARE vMyRight INT; - DECLARE vMyLeft INT; - DECLARE vMyWidth INT; - - CALL util.exec(CONCAT( - 'SELECT t.rgt, t.lft, t.rgt - t.lft + 1', - ' INTO @vMyRight, @vMyLeft, @vMyWidth', - ' FROM ', vScheme, '.', vTable, ' t', - ' WHERE t.id = ', vNodeId - )); - - CALL util.exec(CONCAT( - 'DELETE FROM ', vScheme, '.', vTable, - ' WHERE lft BETWEEN @vMyLeft AND @vMyRight' - )); - - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET rgt = rgt - @vMyWidth' - ' WHERE rgt > @vMyRight ORDER BY rgt' - )); - - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET lft = lft - @vMyWidth' - ' WHERE lft > @vMyRight ORDER BY lft' - )); -END$$ - -DELIMITER ; - diff --git a/db/changes/10003-easter/00-nodeRecalc.sql b/db/changes/10003-easter/00-nodeRecalc.sql deleted file mode 100644 index ff103bda7..000000000 --- a/db/changes/10003-easter/00-nodeRecalc.sql +++ /dev/null @@ -1,23 +0,0 @@ -DROP procedure IF EXISTS `nst`.`nodeRecalc`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45)) -BEGIN - CALL util.exec(CONCAT ( - 'UPDATE ', vScheme, '.', vTable, ' d', - ' JOIN (SELECT', - ' node.id,', - ' COUNT(parent.id) - 1 as depth,', - ' cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons', - ' FROM ', - ' ', vScheme, '.', vTable, ' AS node,', - ' ', vScheme, '.', vTable, ' AS parent', - ' WHERE node.lft BETWEEN parent.lft AND parent.rgt', - ' GROUP BY node.id', - ' ORDER BY node.lft) n ON n.id = d.id ', - ' SET d.`depth` = n.depth, d.sons = n.sons' - )); -END$$ - -DELIMITER ; - diff --git a/db/changes/10003-easter/01-dmsTicketRename.sql b/db/changes/10003-easter/01-dmsTicketRename.sql deleted file mode 100644 index 60318dfdb..000000000 --- a/db/changes/10003-easter/01-dmsTicketRename.sql +++ /dev/null @@ -1,12 +0,0 @@ -DROP VIEW IF EXISTS `vn`.`dmsTicket` ; -USE `vn`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`ticketDms` AS - SELECT - `g`.`Id_Ticket` AS `ticketFk`, - `g`.`gestdoc_id` AS `dmsFk` - FROM - `vn2008`.`tickets_gestdoc` `g`; diff --git a/db/changes/10003-easter/02-dmsTypeAddRoleFields.sql b/db/changes/10003-easter/02-dmsTypeAddRoleFields.sql deleted file mode 100644 index 3898fb813..000000000 --- a/db/changes/10003-easter/02-dmsTypeAddRoleFields.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `vn2008`.`gesttip` -ADD COLUMN `writeRoleFk` INT(10) UNSIGNED NULL AFTER `path`, -ADD COLUMN `readRoleFk` INT(10) UNSIGNED NULL AFTER `writeRoleFk`, -ADD CONSTRAINT `readRoleFk` FOREIGN KEY (`readRoleFk`) REFERENCES `account`.`role` (`id`), -ADD CONSTRAINT `writeRoleFk` FOREIGN KEY (`writeRoleFk`) REFERENCES `account`.`role` (`id`); - -UPDATE `vn2008`.`gesttip` SET `readRoleFk`='1' WHERE `id`='14'; diff --git a/db/changes/10003-easter/03-dmsType.sql b/db/changes/10003-easter/03-dmsType.sql deleted file mode 100644 index 6f38571e6..000000000 --- a/db/changes/10003-easter/03-dmsType.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`dmsType` AS - SELECT - `g`.`id` AS `id`, - `g`.`tipo` AS `name`, - `g`.`path` AS `path`, - `g`.`readRoleFk` AS `readRoleFk`, - `g`.`writeRoleFk` AS `writeRoleFk` - FROM - `vn2008`.`gesttip` `g`; diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index f8d1b3a9a..5d72827cf 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -23,7 +23,7 @@ USE `util`; LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'10001',0,'production',NULL); +INSERT INTO `config` VALUES (1,'10003',0,'production',NULL); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -36,7 +36,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:47 +-- Dump completed on 2019-05-23 8:39:40 USE `account`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -71,7 +71,7 @@ UNLOCK TABLES; LOCK TABLES `roleInherit` WRITE; /*!40000 ALTER TABLE `roleInherit` DISABLE KEYS */; -INSERT INTO `roleInherit` VALUES (9,0),(5,1),(13,1),(18,1),(31,1),(32,1),(34,1),(35,1),(37,1),(40,1),(42,1),(44,1),(47,1),(51,1),(53,1),(54,1),(56,1),(58,1),(1,2),(1,3),(30,5),(39,5),(60,5),(11,6),(1,11),(2,11),(3,11),(16,13),(20,13),(21,13),(22,13),(34,13),(41,13),(43,13),(45,13),(48,13),(50,13),(52,13),(55,13),(57,13),(59,13),(16,15),(21,18),(5,19),(17,20),(30,20),(19,21),(22,21),(39,21),(30,22),(5,33),(34,33),(15,35),(20,35),(52,35),(49,36),(17,37),(38,37),(17,39),(41,40),(43,42),(36,44),(45,44),(36,47),(48,47),(50,49),(60,50),(52,51),(21,53),(30,53),(55,54),(57,56),(49,58),(59,58),(50,59); +INSERT INTO `roleInherit` VALUES (9,0),(5,1),(13,1),(18,1),(31,1),(32,1),(34,1),(35,1),(37,1),(40,1),(42,1),(44,1),(47,1),(51,1),(53,1),(54,1),(56,1),(58,1),(1,2),(1,3),(30,5),(39,5),(60,5),(11,6),(1,11),(2,11),(3,11),(16,13),(20,13),(21,13),(22,13),(34,13),(41,13),(43,13),(45,13),(48,13),(50,13),(52,13),(55,13),(57,13),(59,13),(16,15),(21,18),(5,19),(52,19),(17,20),(30,20),(19,21),(22,21),(39,21),(30,22),(5,33),(34,33),(15,35),(20,35),(52,35),(49,36),(17,37),(38,37),(17,39),(41,40),(43,42),(36,44),(45,44),(36,47),(48,47),(50,49),(60,50),(52,51),(21,53),(30,53),(55,54),(57,56),(60,57),(49,58),(59,58),(50,59); /*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; UNLOCK TABLES; @@ -81,7 +81,7 @@ UNLOCK TABLES; LOCK TABLES `roleRole` WRITE; /*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (0,0),(0,1),(0,2),(0,3),(0,5),(0,6),(0,9),(0,11),(0,13),(0,15),(0,16),(0,17),(0,18),(0,19),(0,20),(0,21),(0,22),(0,30),(0,31),(0,32),(0,33),(0,34),(0,35),(0,36),(0,37),(0,38),(0,39),(0,40),(0,41),(0,42),(0,43),(0,44),(0,45),(0,47),(0,48),(0,49),(0,50),(0,51),(0,52),(0,53),(0,54),(0,55),(0,56),(0,57),(0,58),(0,59),(0,60),(1,1),(1,2),(1,3),(1,6),(1,11),(2,2),(2,6),(2,11),(3,3),(3,6),(3,11),(5,1),(5,2),(5,3),(5,5),(5,6),(5,11),(5,13),(5,18),(5,19),(5,21),(5,33),(5,53),(6,6),(9,0),(9,1),(9,2),(9,3),(9,5),(9,6),(9,9),(9,11),(9,13),(9,15),(9,16),(9,17),(9,18),(9,19),(9,20),(9,21),(9,22),(9,30),(9,31),(9,32),(9,33),(9,34),(9,35),(9,36),(9,37),(9,38),(9,39),(9,40),(9,41),(9,42),(9,43),(9,44),(9,45),(9,47),(9,48),(9,49),(9,50),(9,51),(9,52),(9,53),(9,54),(9,55),(9,56),(9,57),(9,58),(9,59),(9,60),(11,6),(11,11),(13,1),(13,2),(13,3),(13,6),(13,11),(13,13),(15,1),(15,2),(15,3),(15,6),(15,11),(15,15),(15,35),(16,1),(16,2),(16,3),(16,6),(16,11),(16,13),(16,15),(16,16),(16,35),(17,1),(17,2),(17,3),(17,5),(17,6),(17,11),(17,13),(17,17),(17,18),(17,19),(17,20),(17,21),(17,33),(17,35),(17,37),(17,39),(17,53),(18,1),(18,2),(18,3),(18,6),(18,11),(18,18),(19,1),(19,2),(19,3),(19,6),(19,11),(19,13),(19,18),(19,19),(19,21),(19,53),(20,1),(20,2),(20,3),(20,6),(20,11),(20,13),(20,20),(20,35),(21,1),(21,2),(21,3),(21,6),(21,11),(21,13),(21,18),(21,21),(21,53),(22,1),(22,2),(22,3),(22,6),(22,11),(22,13),(22,18),(22,21),(22,22),(22,53),(30,1),(30,2),(30,3),(30,5),(30,6),(30,11),(30,13),(30,18),(30,19),(30,20),(30,21),(30,22),(30,30),(30,33),(30,35),(30,53),(31,1),(31,2),(31,3),(31,6),(31,11),(31,31),(32,1),(32,2),(32,3),(32,6),(32,11),(32,32),(33,33),(34,1),(34,2),(34,3),(34,6),(34,11),(34,13),(34,33),(34,34),(35,1),(35,2),(35,3),(35,6),(35,11),(35,35),(36,1),(36,2),(36,3),(36,6),(36,11),(36,36),(36,44),(36,47),(37,1),(37,2),(37,3),(37,6),(37,11),(37,37),(38,1),(38,2),(38,3),(38,6),(38,11),(38,37),(38,38),(39,1),(39,2),(39,3),(39,5),(39,6),(39,11),(39,13),(39,18),(39,19),(39,21),(39,33),(39,39),(39,53),(40,1),(40,2),(40,3),(40,6),(40,11),(40,40),(41,1),(41,2),(41,3),(41,6),(41,11),(41,13),(41,40),(41,41),(42,1),(42,2),(42,3),(42,6),(42,11),(42,42),(43,1),(43,2),(43,3),(43,6),(43,11),(43,13),(43,42),(43,43),(44,1),(44,2),(44,3),(44,6),(44,11),(44,44),(45,1),(45,2),(45,3),(45,6),(45,11),(45,13),(45,44),(45,45),(47,1),(47,2),(47,3),(47,6),(47,11),(47,47),(48,1),(48,2),(48,3),(48,6),(48,11),(48,13),(48,47),(48,48),(49,1),(49,2),(49,3),(49,6),(49,11),(49,36),(49,44),(49,47),(49,49),(49,58),(50,1),(50,2),(50,3),(50,6),(50,11),(50,13),(50,36),(50,44),(50,47),(50,49),(50,50),(50,58),(50,59),(51,1),(51,2),(51,3),(51,6),(51,11),(51,51),(52,1),(52,2),(52,3),(52,6),(52,11),(52,13),(52,35),(52,51),(52,52),(53,1),(53,2),(53,3),(53,6),(53,11),(53,53),(54,1),(54,2),(54,3),(54,6),(54,11),(54,54),(55,1),(55,2),(55,3),(55,6),(55,11),(55,13),(55,54),(55,55),(56,1),(56,2),(56,3),(56,6),(56,11),(56,56),(57,1),(57,2),(57,3),(57,6),(57,11),(57,13),(57,56),(57,57),(58,1),(58,2),(58,3),(58,6),(58,11),(58,58),(59,1),(59,2),(59,3),(59,6),(59,11),(59,13),(59,58),(59,59),(60,1),(60,2),(60,3),(60,5),(60,6),(60,11),(60,13),(60,18),(60,19),(60,21),(60,33),(60,36),(60,44),(60,47),(60,49),(60,50),(60,53),(60,58),(60,59),(60,60); +INSERT INTO `roleRole` VALUES (0,0),(0,1),(0,2),(0,3),(0,5),(0,6),(0,9),(0,11),(0,13),(0,15),(0,16),(0,17),(0,18),(0,19),(0,20),(0,21),(0,22),(0,30),(0,31),(0,32),(0,33),(0,34),(0,35),(0,36),(0,37),(0,38),(0,39),(0,40),(0,41),(0,42),(0,43),(0,44),(0,45),(0,47),(0,48),(0,49),(0,50),(0,51),(0,52),(0,53),(0,54),(0,55),(0,56),(0,57),(0,58),(0,59),(0,60),(1,1),(1,2),(1,3),(1,6),(1,11),(2,2),(2,6),(2,11),(3,3),(3,6),(3,11),(5,1),(5,2),(5,3),(5,5),(5,6),(5,11),(5,13),(5,18),(5,19),(5,21),(5,33),(5,53),(6,6),(9,0),(9,1),(9,2),(9,3),(9,5),(9,6),(9,9),(9,11),(9,13),(9,15),(9,16),(9,17),(9,18),(9,19),(9,20),(9,21),(9,22),(9,30),(9,31),(9,32),(9,33),(9,34),(9,35),(9,36),(9,37),(9,38),(9,39),(9,40),(9,41),(9,42),(9,43),(9,44),(9,45),(9,47),(9,48),(9,49),(9,50),(9,51),(9,52),(9,53),(9,54),(9,55),(9,56),(9,57),(9,58),(9,59),(9,60),(11,6),(11,11),(13,1),(13,2),(13,3),(13,6),(13,11),(13,13),(15,1),(15,2),(15,3),(15,6),(15,11),(15,15),(15,35),(16,1),(16,2),(16,3),(16,6),(16,11),(16,13),(16,15),(16,16),(16,35),(17,1),(17,2),(17,3),(17,5),(17,6),(17,11),(17,13),(17,17),(17,18),(17,19),(17,20),(17,21),(17,33),(17,35),(17,37),(17,39),(17,53),(18,1),(18,2),(18,3),(18,6),(18,11),(18,18),(19,1),(19,2),(19,3),(19,6),(19,11),(19,13),(19,18),(19,19),(19,21),(19,53),(20,1),(20,2),(20,3),(20,6),(20,11),(20,13),(20,20),(20,35),(21,1),(21,2),(21,3),(21,6),(21,11),(21,13),(21,18),(21,21),(21,53),(22,1),(22,2),(22,3),(22,6),(22,11),(22,13),(22,18),(22,21),(22,22),(22,53),(30,1),(30,2),(30,3),(30,5),(30,6),(30,11),(30,13),(30,18),(30,19),(30,20),(30,21),(30,22),(30,30),(30,33),(30,35),(30,53),(31,1),(31,2),(31,3),(31,6),(31,11),(31,31),(32,1),(32,2),(32,3),(32,6),(32,11),(32,32),(33,33),(34,1),(34,2),(34,3),(34,6),(34,11),(34,13),(34,33),(34,34),(35,1),(35,2),(35,3),(35,6),(35,11),(35,35),(36,1),(36,2),(36,3),(36,6),(36,11),(36,36),(36,44),(36,47),(37,1),(37,2),(37,3),(37,6),(37,11),(37,37),(38,1),(38,2),(38,3),(38,6),(38,11),(38,37),(38,38),(39,1),(39,2),(39,3),(39,5),(39,6),(39,11),(39,13),(39,18),(39,19),(39,21),(39,33),(39,39),(39,53),(40,1),(40,2),(40,3),(40,6),(40,11),(40,40),(41,1),(41,2),(41,3),(41,6),(41,11),(41,13),(41,40),(41,41),(42,1),(42,2),(42,3),(42,6),(42,11),(42,42),(43,1),(43,2),(43,3),(43,6),(43,11),(43,13),(43,42),(43,43),(44,1),(44,2),(44,3),(44,6),(44,11),(44,44),(45,1),(45,2),(45,3),(45,6),(45,11),(45,13),(45,44),(45,45),(47,1),(47,2),(47,3),(47,6),(47,11),(47,47),(48,1),(48,2),(48,3),(48,6),(48,11),(48,13),(48,47),(48,48),(49,1),(49,2),(49,3),(49,6),(49,11),(49,36),(49,44),(49,47),(49,49),(49,58),(50,1),(50,2),(50,3),(50,6),(50,11),(50,13),(50,36),(50,44),(50,47),(50,49),(50,50),(50,58),(50,59),(51,1),(51,2),(51,3),(51,6),(51,11),(51,51),(52,1),(52,2),(52,3),(52,6),(52,11),(52,13),(52,18),(52,19),(52,21),(52,35),(52,51),(52,52),(52,53),(53,1),(53,2),(53,3),(53,6),(53,11),(53,53),(54,1),(54,2),(54,3),(54,6),(54,11),(54,54),(55,1),(55,2),(55,3),(55,6),(55,11),(55,13),(55,54),(55,55),(56,1),(56,2),(56,3),(56,6),(56,11),(56,56),(57,1),(57,2),(57,3),(57,6),(57,11),(57,13),(57,56),(57,57),(58,1),(58,2),(58,3),(58,6),(58,11),(58,58),(59,1),(59,2),(59,3),(59,6),(59,11),(59,13),(59,58),(59,59),(60,1),(60,2),(60,3),(60,5),(60,6),(60,11),(60,13),(60,18),(60,19),(60,21),(60,33),(60,36),(60,44),(60,47),(60,49),(60,50),(60,53),(60,56),(60,57),(60,58),(60,59),(60,60); /*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -94,7 +94,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:47 +-- Dump completed on 2019-05-23 8:39:40 USE `salix`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -119,7 +119,7 @@ USE `salix`; LOCK TABLES `ACL` WRITE; /*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','salesPerson'),(123,'Worker','*','READ','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'WorkerCalendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'WorkerCalendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'); +INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','salesPerson'),(123,'Worker','*','READ','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'WorkerCalendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'WorkerCalendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(164,'InvoiceOut','regenerate','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','READ','ALLOW','ROLE','employee'),(166,'Dms','download','READ','ALLOW','ROLE','employee'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; @@ -142,7 +142,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:47 +-- Dump completed on 2019-05-23 8:39:40 USE `vn`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -250,7 +250,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:47 +-- Dump completed on 2019-05-23 8:39:40 USE `vn2008`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -355,7 +355,7 @@ UNLOCK TABLES; LOCK TABLES `department` WRITE; /*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,'VERDNATURA',1,52,1,0,NULL,NULL,NULL,NULL,0,0,0,0),(22,'COMPRAS',29,30,NULL,72,49,596,2,5,0,0,0,0),(23,'CAMARA',23,23,NULL,72,49,604,2,6,1,0,0,0),(31,'INFORMATICA',40,41,NULL,72,44,127,3,9,0,0,0,0),(34,'CONTABILIDAD',35,36,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(35,'FINANZAS',33,34,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(36,'LABORAL',37,38,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(37,'PRODUCCION',42,49,NULL,72,44,230,3,11,0,0,0,0),(38,'SACADO',47,48,NULL,72,37,230,4,14,1,0,0,0),(39,'ENCAJADO',45,46,NULL,72,37,230,4,12,1,0,0,0),(40,'CONTROLADORES',43,44,NULL,72,37,619,4,13,0,0,0,0),(41,'ADMINISTRACION',32,39,NULL,72,44,599,3,8,0,0,0,0),(42,'COMERCIAL',26,31,NULL,72,49,1002,2,3,0,0,0,0),(43,'VENTAS',27,28,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(44,'GERENCIA',24,25,NULL,72,49,300,2,7,0,0,0,0),(45,'LOGISTICA',18,45,NULL,72,44,596,3,19,0,0,0,0),(46,'REPARTO',21,22,NULL,72,44,659,3,10,0,0,0,0),(47,'CARGA',15,16,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(48,'ALMACENAJE',12,17,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(49,'PROPIEDAD',10,11,NULL,72,NULL,1008,1,1,0,0,0,0),(51,'DESCARGA',13,14,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(52,'CARGA AEREA',19,20,NULL,72,66,163,4,28,0,0,0,0),(53,'MARKETING Y COMUNICACIÓN',50,51,NULL,72,44,1238,0,0,0,0,0,0),(54,'ORNAMENTALES',54,54,NULL,72,44,433,3,21,0,2,0,0),(55,'TALLER Y CONFECCION',4,9,NULL,72,49,695,2,23,0,0,0,0),(56,'TALLER ARTIFICIAL',7,8,NULL,72,49,1780,2,24,0,0,0,0),(57,'SECO',5,6,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(58,'CAMPOS',2,3,NULL,72,49,225,2,2,0,0,0,0),(59,'MANTENIMIENTO',52,53,NULL,72,37,230,4,16,0,1,0,0),(60,'RECLAMACIONES',60,60,NULL,72,42,563,3,20,0,2,0,0),(61,'VNH',61,61,NULL,73,44,1297,3,17,0,2,0,0),(63,'VENTAS FRANCIA',63,63,NULL,72,49,277,2,27,0,2,0,0),(64,'PLANTAS',64,64,NULL,72,49,617,2,25,0,2,0,0),(66,'VERDNAMADRID',66,66,NULL,72,44,163,3,18,0,0,0,0),(68,'COMPLEMENTOS',68,68,NULL,72,64,617,3,26,1,0,0,0),(69,'VERDNABARNA',69,69,NULL,74,44,432,3,22,0,0,0,0),(77,'PALETIZADO',77,77,NULL,72,37,230,4,15,1,0,0,0),(80,'EQUIPO J VALLES',80,80,NULL,72,42,693,3,4,0,0,0,0),(86,'LIMPIEZA',86,86,NULL,72,44,599,0,0,0,0,0,0),(88,'CONTROL',88,88,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(89,'COORDINACION',89,89,NULL,0,NULL,NULL,NULL,NULL,1,0,0,0),(90,'TRAILER',90,90,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0); +INSERT INTO `department` VALUES (1,'VERDNATURA',1,52,1,0,NULL,NULL,NULL,NULL,0,0,0,0),(22,'COMPRAS',29,30,NULL,72,49,596,2,5,0,0,0,0),(23,'CAMARA',23,23,NULL,72,49,604,2,6,1,0,0,0),(31,'INFORMATICA',40,41,NULL,72,44,127,3,9,0,0,0,0),(34,'CONTABILIDAD',35,36,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(35,'FINANZAS',33,34,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(36,'LABORAL',37,38,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(37,'PRODUCCION',42,49,NULL,72,44,230,3,11,0,0,0,0),(38,'SACADO',47,48,NULL,72,37,230,4,14,1,0,0,0),(39,'ENCAJADO',45,46,NULL,72,37,230,4,12,1,0,0,0),(40,'CONTROLADORES',43,44,NULL,72,37,619,4,13,0,0,0,0),(41,'ADMINISTRACION',32,39,NULL,72,44,599,3,8,0,0,0,0),(42,'COMERCIAL',26,31,NULL,72,49,1002,2,3,0,0,0,0),(43,'VENTAS',27,28,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(44,'GERENCIA',24,25,NULL,72,49,300,2,7,0,0,0,0),(45,'LOGISTICA',18,45,NULL,72,44,596,3,19,0,0,0,0),(46,'REPARTO',21,22,NULL,72,44,659,3,10,0,0,0,0),(47,'CARGA',15,16,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(48,'ALMACENAJE',12,17,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(49,'PROPIEDAD',10,11,NULL,72,NULL,1008,1,1,0,0,0,0),(51,'DESCARGA',13,14,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(52,'CARGA AEREA',19,20,NULL,72,66,163,4,28,0,0,0,0),(53,'MARKETING Y COMUNICACIÓN',50,51,NULL,72,44,1238,0,0,0,0,0,0),(54,'ORNAMENTALES',54,54,NULL,72,44,433,3,21,0,2,0,0),(55,'TALLER Y CONFECCION',4,9,NULL,72,49,695,2,23,0,0,0,0),(56,'TALLER ARTIFICIAL',7,8,NULL,72,49,1780,2,24,0,0,0,0),(57,'SECO',5,6,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(58,'CAMPOS',2,3,NULL,72,49,225,2,2,0,0,0,0),(59,'MANTENIMIENTO',52,53,NULL,72,37,1907,4,16,0,1,0,0),(60,'RECLAMACIONES',60,60,NULL,72,42,563,3,20,0,2,0,0),(61,'VNH',61,61,NULL,73,44,1297,3,17,0,2,0,0),(63,'VENTAS FRANCIA',63,63,NULL,72,49,277,2,27,0,2,0,0),(64,'PLANTAS',64,64,NULL,72,49,617,2,25,0,2,0,0),(66,'VERDNAMADRID',66,66,NULL,72,44,163,3,18,0,0,0,0),(68,'COMPLEMENTOS',68,68,NULL,72,64,617,3,26,1,0,0,0),(69,'VERDNABARNA',69,69,NULL,74,44,432,3,22,0,0,0,0),(77,'PALETIZADO',77,77,NULL,72,37,230,4,15,1,0,0,0),(80,'EQUIPO J VALLES',80,80,NULL,72,42,693,3,4,0,0,0,0),(86,'LIMPIEZA',86,86,NULL,72,44,599,0,0,0,0,0,0),(88,'CONTROL',88,88,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0),(89,'COORDINACION',89,89,NULL,0,NULL,NULL,NULL,NULL,1,0,0,0),(90,'TRAILER',90,90,NULL,0,NULL,NULL,NULL,NULL,0,0,0,0); /*!40000 ALTER TABLE `department` ENABLE KEYS */; UNLOCK TABLES; @@ -375,7 +375,7 @@ UNLOCK TABLES; LOCK TABLES `Gastos` WRITE; /*!40000 ALTER TABLE `Gastos` DISABLE KEYS */; -INSERT INTO `Gastos` VALUES ('2000000000',1,'Inmovilizado pendiente',1,0,0),('2000000000',3,'Compra de bienes de inmovilizado',1,0,0),('2600000000',1,'Fianzas',0,0,0),('4600000000',1,'Anticipos de remuneraciones',1,0,0),('4600000001',1,'Anticpos de remuneración',1,0,0),('4751000000',0,'Retenciones',0,1,0),('4751000000',1,'Retenciones',0,1,0),('4751000000',6,'Retencion',0,0,0),('4759000000',1,'Embargos salariales',1,0,0),('5200000006',1,'Deudas a c/p CRA',1,0,0),('5200000008',0,'Prestamo CP Transolver IVECO 269',1,0,0),('5200000008',1,'Prestamo Transolver 201600269',1,0,0),('5200000009',0,'Prestamo CP Transolver IVECO 270',1,0,0),('5200000009',1,'Prestamo Transolver 201600270',1,0,0),('5200000010',0,'Prestamo CP Transolver IVECO 271',1,0,0),('5200000010',1,'Prestamo Transolver 201600271',1,0,0),('5200000011',1,'Prestamo Transolver 339',0,0,0),('5200000012',1,'Prestamo Transolver 340',1,0,0),('5200000013',1,'Prestamo Transolver 341',1,0,0),('5200000014',1,'Prestamo a c/p BBVA 600.000€',1,0,0),('5200000022',1,'Linea comercio exterior',1,0,0),('5240000001',1,'Leasing BBVA',1,0,0),('5240000002',1,'Leasing c/p 0265670-03',1,0,0),('5240000003',1,'Leasing La Caixa 0265878-21',0,0,0),('5240002032',1,'Leasing Iveco',1,0,0),('5240002066',1,'Leasing c/p Man',1,0,0),('5240002104',1,'Leasing c/p La caixa 3 vehículos',1,0,0),('5325000003',6,'Prestamo a partes vinculadas',0,0,0),('5420000001',1,'Prestamo concedido',1,0,0),('5650000001',1,'Fianza c/p vehiculo',0,0,0),('5660000001',1,'Suplidos',0,0,0),('5660000001',20,'Suplidos',1,0,0),('5660000002',0,'Suplidos',0,0,0),('5660000002',1,'Suplidos Transitarios nacionales',1,0,0),('5660000003',1,'Deposito c/p Ebury',1,0,0),('5660000003',4,'Deposito Ebury',0,0,0),('5660000004',4,'Deposito Global Reach',0,0,0),('6001000000',1,'Compras a terceros nacional',1,0,0),('6001000000',18,'Compras a terceros nacional',1,0,0),('6001000000',19,'Compras a terceros nacional',1,0,0),('6001000001',1,'Adquisiones en Europa',0,0,0),('6001000001',3,'Adquisición en Europa',1,0,0),('6001000002',1,'Compras a terceros Mascotas',1,0,0),('6001000002',3,'Compras a terceros mascotas',1,0,0),('6001000002',19,'Compras a terceros Mascotas',1,0,0),('6002000000',1,'Transportes de compras',1,0,0),('6002000001',1,'Tranportes de compra Europa',1,0,0),('6002000001',4,'Transportes de compras Europa',1,0,0),('6002000567',0,'Transporte de compras VNH',1,0,0),('6003000000',1,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',5,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',6,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000567',0,'Compra de mercancia extracomunitaria VNH',1,0,0),('6004000000',1,'Transporte compras Sudamérica',1,0,0),('6004000000',4,'Transporte compras Sudamérica',1,0,0),('6004000000',6,'Transporte compras Sudamérica',1,0,0),('6010000000',1,'Materias primas',1,0,0),('6020000000',1,'Otros aprovisionamientos',1,0,0),('6020000001',1,'Embalajes',1,0,0),('6020000002',1,'Otros aprov. Taller artíficial',1,0,0),('6070000000',1,'Trabajos de produccion encargados a terceros',1,0,0),('6090000000',6,'Rappels por compras',1,0,0),('6100000000',0,'Variacion existencias',1,0,0),('6210000000',1,'Arrendamientos',1,0,0),('6210000001',1,'Arrendamiento vehículo',1,0,0),('6210000001',4,'Gastos de arrendamiento vehículos',1,0,0),('6210000002',1,'Arrendamiento nave',1,0,0),('6210000003',1,'Arrendamiento espacio virtual-informatic',1,0,0),('6210000004',1,'Arrendamiento elementos para el proceso de informa',1,0,0),('6210000005',1,'Arrendamiento CC y banddejas',1,0,0),('6210000567',0,'Alquiler VNH',1,0,0),('6220000000',1,'Reparaciones y conservacion',1,0,0),('6220000001',1,'Reparación-Informatica',1,0,0),('6220000001',4,'Reparacion y mantenimiento informatica',1,0,0),('6220000003',1,'Reparación-Vehiculos',1,0,0),('6220000004',1,'Reparación-Instalaciones',1,0,0),('6220000005',1,'Reparación y mantenimineto CCs',1,0,0),('6220000006',1,'Repracion y conser maquinaria',1,0,0),('6230000000',1,'Servicios de profesionales independientes',1,0,0),('6230000000',4,'Servicio de profesionales',0,0,0),('6230000000',6,'Servicios de profesionales',1,0,0),('6230000001',1,'Servicios por gestión de ventas',1,0,0),('6230000001',4,'Servicios por gestión de ventas',1,0,0),('6240000000',1,'Transportes de ventas rutas',1,0,0),('6240000000',4,'Transportes de ventas',1,0,0),('6240000001',1,'Transporte ventas agencias',1,0,0),('6240000002',1,'Transporte ventas reclamaciones',1,0,0),('6240000567',1,'Transporte ventas VNH',1,0,0),('6250000000',1,'Primas de seguros',1,0,0),('6250000000',4,'Prima de Seguros',1,0,0),('6250000001',1,'Primas de seguros-Personales',1,0,0),('6250000002',1,'Primas de seguros-Colectivos',1,0,0),('6250000003',1,'Primas de seguros-Vehiculos',1,0,0),('6250000004',1,'Primas de seguros-Inmuebles',1,0,0),('6250000567',0,'Seguros VNH',1,0,0),('6260000000',1,'Gastos bancarios',1,0,0),('6260000000',4,'Gastos bancarios',0,0,0),('6260000000',6,'Gastos bancarios',1,0,0),('6260000001',1,'Gastos bancarios datafono',1,0,0),('6260000002',1,'Gastos bancarios transferencia nacional',1,0,0),('6260000003',1,'Gastos bancarios transferencia Europa',1,0,0),('6260000004',1,'Gastos bancarios transferencia divisas',1,0,0),('6260000567',0,'Gastos bancarios VNH',1,0,0),('6270000000',1,'Publicidad y RRPP',1,0,0),('6270000000',3,'Publicidad, propaganda y RR PP',1,0,0),('6270000000',6,'Publicidad',1,0,0),('6270000000',14,'Publicidad, propaganda RRPP',1,0,0),('6270000001',1,'Patrocinio',0,0,0),('6280000000',1,'Suministros',1,0,0),('6280000001',1,'Telefonos',1,0,0),('6280000002',1,'Gasoil',1,0,0),('6280000003',1,'Suministros-Electricidad',1,0,0),('6280000004',1,'Internet',1,0,0),('6280000567',0,'Suministros VNH',1,0,0),('6280001567',0,'Suministros telefono VNH',1,0,0),('6280003567',0,'Suministro luz VNH',1,0,0),('6290000000',1,'Otros servicios',1,0,0),('6290000000',6,'Otros gastos varios',1,0,0),('6290000001',1,'Material de oficina',1,0,0),('6290000002',1,'Gastos en formacion',1,0,0),('6290000003',1,'Asesoria juridica',1,0,0),('6290000004',4,'Otros servicios UE',1,0,0),('6290000005',1,'Gastos varios-Correos',1,0,0),('6290000006',1,'Otros servicios extranjero',1,0,0),('6290000006',5,'Otros servicios extranjero',1,0,0),('6290000006',6,'Otros servicios extranjero',1,0,0),('6290000007',1,'Gastos pequeño material',1,0,0),('6290000007',3,'Compras pequeño material',1,0,0),('6290000007',6,'Pequeño material',1,0,0),('6290000008',1,'Gastos varios-uniformes personal',1,0,0),('6290000008',3,'Compra uniformes',1,0,0),('6290000009',1,'Gastos-CC Container',1,0,0),('6290000010',1,'Gastos formación clientes',1,0,0),('6290000012',1,'Gastos gestión contra-reembolsos',1,0,0),('6290000013',1,'Arrendamiento Vilassar',1,0,0),('6290000014',1,'Gasto laboral espresas ETT',1,0,0),('6290000015',1,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',3,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',6,'Gasto compra terminales moviles y similares',1,0,0),('6290000016',1,'Gasto gestión cobro ventas',1,0,0),('6290000553',1,'Gastos viaje administrador',1,0,0),('6290000553',4,'Gastos viaje administrador-gerente',1,0,0),('6290000553',6,'Gastos viaje administrador',1,0,0),('6290001000',1,'Gastos de viaje',1,0,0),('6290001000',4,'Gastos viajes otros departamentos',1,0,0),('6290001000',6,'Gastos viaje personal otros departamentos',1,0,0),('6290001001',1,'Gastos R.R.P.P. Gerente',1,0,0),('6290001002',1,'Gastos R.R.P.P. Comerciales',1,0,0),('6290001567',0,'Gastos material oficina',1,0,0),('6300000000',1,'Impuesto de sociedades',1,0,0),('6310000000',1,'Otros tributos',1,0,0),('6380000000',1,'Ajustes positivos s/b Bº',1,0,0),('6400000000',0,'Sueldos y salarios',1,0,0),('6400000000',1,'Salarios',0,0,0),('6400000001',0,'Productividad',1,0,0),('6400000567',0,'Salarios VNH',1,0,0),('6410000001',1,'Indemnizaciones',1,0,0),('6420000000',0,'Seguridad Social a cargo de la empresa',1,0,0),('6420000000',1,'Seguridad Social',0,0,0),('6490000000',1,'Otros gastos sociales',1,0,0),('6500000000',1,'Impagados definitivos',1,0,0),('6620000000',0,'Intereses Bancarios',1,0,0),('6620000001',1,'Intereses deudas a l/p',1,0,0),('6620000002',1,'Intereses Leasing La caixa 0265670-03',1,0,0),('6620000003',1,'Interses Leasing La caixa 0265878-21',1,0,0),('6620000006',1,'Intereses deuda prestamo CRA',1,0,0),('6620000007',1,'Intereses La Caixa linea comercio exterior',1,0,0),('6620000007',16,'Intereses La Caixa Linea Comercio Exterior',0,0,0),('6620000008',1,'Intereses Prestamos Transolver 2016',1,0,0),('6620000011',1,'Intereses BBVA linea comercio exterior',1,0,0),('6620000014',1,'Intereses Prestamo BBVA',1,0,0),('6620000015',1,'Interés Póliza Deutsche Bank Comercio Exterior',0,0,0),('6620000023',1,'Intereses Bankinter Póliza Comercio Exterior',0,0,0),('6620002032',1,'Intereses Leaing Iveco',1,0,0),('6620002066',1,'Leasing Intereses Man',1,0,0),('6620002104',1,'Intereses Leasing La caixa 3 vehículos',1,0,0),('6622000000',20,'Intereses deudas otras partes vinculadas',1,0,0),('6660000000',1,'Perdidas en valores representativos de deuda a l/p',0,0,0),('6681000000',1,'Diferencia negativa tipo de cambio',1,0,0),('6681000000',4,'Diferencia negativa tipo de cambio',0,0,0),('6681000000',6,'Diferencia negativa tipo de cambio',1,0,0),('6681000567',0,'Diferencias de cambio VNH',1,0,0),('6690000000',1,'Otros gastos financieros',1,0,0),('6690000000',6,'Gastos financieros',1,0,0),('6720000000',16,'Perdidas procedentes de inversiones',0,0,0),('6780000000',1,'Gastos extraordinarios',1,0,0),('6780000001',1,'Gastos no deducibles',1,0,0),('6780000001',16,'Gasto no deducible',0,0,0),('6800000000',1,'Amortización inmovilizado intangible',1,0,0),('6800000001',0,'Amortizacion inmovilizado material',1,0,0),('6800000001',1,'Amortización del inmovilizado material',1,0,0),('6810000000',0,'Amortizaciones inmovilizado',1,0,0),('6810000000',1,'Amortizacion inmovilizado material',1,0,0),('7000000000',0,'Ventas',1,0,0),('7000000001',1,'Venta entre empresas',1,0,0),('7000010000',0,'Terceros Flor',1,0,0),('7000020000',0,'Terceros Planta',1,0,0),('7000030000',0,'Terceros Complementos',1,0,0),('7000040000',0,'Terceros Artificial',1,0,0),('7000050000',0,'Terceros Verdes',1,0,0),('7000060000',0,'Terceros Otros',1,0,0),('7000070000',0,'Terceros Confección',1,0,0),('7000080000',1,'Terceros Logística',1,0,0),('7001000000',1,'Mercaderia',1,0,1),('7001010000',0,'Grupo Flor',1,0,0),('7001020000',0,'Grupo Planta',1,0,0),('7001030000',0,'Grupo Complementos',1,0,0),('7001040000',0,'Grupo Artificial',1,0,0),('7001050000',0,'Grupo Verdes',1,0,0),('7001060000',0,'Grupo Otros',1,0,0),('7001070000',0,'Grupo Confección',1,0,0),('7001080000',1,'Grupo Logística',1,0,0),('7002010000',0,'Asociados Flor',1,0,0),('7002020000',0,'Asociados Planta',1,0,0),('7002030000',0,'Asociados Complementos',1,0,0),('7002040000',0,'Asociados Artificial',1,0,0),('7002050000',0,'Asociados Verdes',1,0,0),('7002060000',0,'Asociados Otros',1,0,0),('7002070000',0,'Asociados Confección',1,0,0),('7002080000',1,'Asociados Logística',1,0,0),('7040000000',1,'Embalajes',1,0,1),('7050000000',1,'Prestacion de servicios',1,0,1),('7400000000',1,'Subvenciones, donaciones a la explotacion',1,0,0),('7550000000',0,'Ingresos por serivicios al personal',1,0,0),('7620000000',16,'Intereses de créditos a l/p',1,0,0),('768,0',0,NULL,1,0,0),('7680000000',0,'Diferencias positivas de cambio',1,0,0),('7680000000',1,'Diferenica positiva tipo de cambio',1,0,0),('7680000000',4,'Diferenica positiva tipo de cambio',0,0,0),('7680000000',6,'Diferenica positiva tipo de cambio',1,0,0),('7690000000',1,'Otros ingresos financieros',1,0,0),('7710000000',20,'Beneficio procendente vta inm',1,0,0),('7780000000',1,'Ingresos excepcionales',1,0,0),('7780000000',16,'Ingreso extraordinario',0,0,0),('7780000001',1,'Indemnizaciones transporte',1,0,0),('7780000001',4,'Indemnizaciones agencias transporte',1,0,0),('7780000001',5,'Indemnizaciones agencias transporte',1,0,0),('7780000001',6,'Indemnizaciones transporte',1,0,0),('7940000000',1,'Reversión impagos',1,0,0),('7940000000',16,'Reversión impagos',0,0,0); +INSERT INTO `Gastos` VALUES ('2000000000',1,'Inmovilizado pendiente',1,0,0),('2000000000',3,'Compra de bienes de inmovilizado',1,0,0),('2600000000',1,'Fianzas',0,0,0),('4600000000',1,'Anticipos de remuneraciones',1,0,0),('4600000001',1,'Anticpos de remuneración',1,0,0),('4751000000',0,'Retenciones',0,1,0),('4751000000',1,'Retenciones',0,1,0),('4751000000',6,'Retencion',0,0,0),('4759000000',1,'Embargos salariales',1,0,0),('5200000006',1,'Deudas a c/p CRA',1,0,0),('5200000008',0,'Prestamo CP Transolver IVECO 269',1,0,0),('5200000008',1,'Prestamo Transolver 201600269',1,0,0),('5200000009',0,'Prestamo CP Transolver IVECO 270',1,0,0),('5200000009',1,'Prestamo Transolver 201600270',1,0,0),('5200000010',0,'Prestamo CP Transolver IVECO 271',1,0,0),('5200000010',1,'Prestamo Transolver 201600271',1,0,0),('5200000011',1,'Prestamo Transolver 339',0,0,0),('5200000012',1,'Prestamo Transolver 340',1,0,0),('5200000013',1,'Prestamo Transolver 341',1,0,0),('5200000014',1,'Prestamo a c/p BBVA 600.000€',1,0,0),('5200000022',1,'Linea comercio exterior',1,0,0),('5240000001',1,'Leasing BBVA',1,0,0),('5240000002',1,'Leasing c/p 0265670-03',1,0,0),('5240000003',1,'Leasing La Caixa 0265878-21',0,0,0),('5240002032',1,'Leasing Iveco',1,0,0),('5240002066',1,'Leasing c/p Man',1,0,0),('5240002104',1,'Leasing c/p La caixa 3 vehículos',1,0,0),('5325000003',6,'Prestamo a partes vinculadas',0,0,0),('5420000001',1,'Prestamo concedido',1,0,0),('5650000001',1,'Fianza c/p vehiculo',0,0,0),('5660000001',1,'Suplidos',0,0,0),('5660000001',20,'Suplidos',1,0,0),('5660000002',0,'Suplidos',0,0,0),('5660000002',1,'Suplidos Transitarios nacionales',1,0,0),('5660000003',1,'Deposito c/p Ebury',1,0,0),('5660000003',4,'Deposito Ebury',0,0,0),('5660000004',4,'Deposito Global Reach',0,0,0),('6001000000',1,'Compras a terceros nacional',1,0,0),('6001000000',18,'Compras a terceros nacional',1,0,0),('6001000000',19,'Compras a terceros nacional',1,0,0),('6001000001',1,'Adquisiones en Europa',0,0,0),('6001000001',3,'Adquisición en Europa',1,0,0),('6002000000',1,'Transportes de compras',1,0,0),('6002000001',1,'Tranportes de compra Europa',1,0,0),('6002000001',4,'Transportes de compras Europa',1,0,0),('6002000567',0,'Transporte de compras VNH',1,0,0),('6003000000',1,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',5,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',6,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000567',0,'Compra de mercancia extracomunitaria VNH',1,0,0),('6004000000',1,'Transporte compras Sudamérica',1,0,0),('6004000000',4,'Transporte compras Sudamérica',1,0,0),('6004000000',6,'Transporte compras Sudamérica',1,0,0),('6010000000',1,'Materias primas',1,0,0),('6020000000',1,'Otros aprovisionamientos',1,0,0),('6020000001',1,'Embalajes',1,0,0),('6020000002',1,'Otros aprov. Taller artíficial',1,0,0),('6070000000',1,'Trabajos de produccion encargados a terceros',1,0,0),('6090000000',6,'Rappels por compras',1,0,0),('6100000000',0,'Variacion existencias',1,0,0),('6210000000',1,'Arrendamientos',1,0,0),('6210000001',1,'Arrendamiento vehículo',1,0,0),('6210000001',4,'Gastos de arrendamiento vehículos',1,0,0),('6210000002',1,'Arrendamiento nave',1,0,0),('6210000003',1,'Arrendamiento espacio virtual-informatic',1,0,0),('6210000004',1,'Arrendamiento elementos para el proceso de informa',1,0,0),('6210000005',1,'Arrendamiento CC y banddejas',1,0,0),('6210000567',0,'Alquiler VNH',1,0,0),('6220000000',1,'Reparaciones y conservacion',1,0,0),('6220000001',1,'Reparación-Informatica',1,0,0),('6220000001',4,'Reparacion y mantenimiento informatica',1,0,0),('6220000003',1,'Reparación-Vehiculos',1,0,0),('6220000004',1,'Reparación-Instalaciones',1,0,0),('6220000005',1,'Reparación y mantenimineto CCs',1,0,0),('6220000006',1,'Repracion y conser maquinaria',1,0,0),('6230000000',1,'Servicios de profesionales independientes',1,0,0),('6230000000',4,'Servicio de profesionales',0,0,0),('6230000000',6,'Servicios de profesionales',1,0,0),('6230000001',1,'Servicios por gestión de ventas',1,0,0),('6230000001',4,'Servicios por gestión de ventas',1,0,0),('6240000000',1,'Transportes de ventas rutas',1,0,0),('6240000000',4,'Transportes de ventas',1,0,0),('6240000001',1,'Transporte ventas agencias',1,0,0),('6240000002',1,'Transporte ventas reclamaciones',1,0,0),('6240000567',1,'Transporte ventas VNH',1,0,0),('6250000000',1,'Primas de seguros',1,0,0),('6250000000',4,'Prima de Seguros',1,0,0),('6250000001',1,'Primas de seguros-Personales',1,0,0),('6250000002',1,'Primas de seguros-Colectivos',1,0,0),('6250000003',1,'Primas de seguros-Vehiculos',1,0,0),('6250000004',1,'Primas de seguros-Inmuebles',1,0,0),('6250000567',0,'Seguros VNH',1,0,0),('6260000000',1,'Gastos bancarios',1,0,0),('6260000000',4,'Gastos bancarios',0,0,0),('6260000000',6,'Gastos bancarios',1,0,0),('6260000001',1,'Gastos bancarios datafono',1,0,0),('6260000002',1,'Gastos bancarios transferencia nacional',1,0,0),('6260000003',1,'Gastos bancarios transferencia Europa',1,0,0),('6260000004',1,'Gastos bancarios transferencia divisas',1,0,0),('6260000567',0,'Gastos bancarios VNH',1,0,0),('6270000000',1,'Publicidad y RRPP',1,0,0),('6270000000',3,'Publicidad, propaganda y RR PP',1,0,0),('6270000000',6,'Publicidad',1,0,0),('6270000000',14,'Publicidad, propaganda RRPP',1,0,0),('6270000001',1,'Patrocinio',0,0,0),('6280000000',1,'Suministros',1,0,0),('6280000001',1,'Telefonos',1,0,0),('6280000002',1,'Gasoil',1,0,0),('6280000003',1,'Suministros-Electricidad',1,0,0),('6280000004',1,'Internet',1,0,0),('6280000567',0,'Suministros VNH',1,0,0),('6280001567',0,'Suministros telefono VNH',1,0,0),('6280003567',0,'Suministro luz VNH',1,0,0),('6290000000',1,'Otros servicios',1,0,0),('6290000000',6,'Otros gastos varios',1,0,0),('6290000001',1,'Material de oficina',1,0,0),('6290000002',1,'Gastos en formacion',1,0,0),('6290000003',1,'Asesoria juridica',1,0,0),('6290000004',4,'Otros servicios UE',1,0,0),('6290000005',1,'Gastos varios-Correos',1,0,0),('6290000006',1,'Otros servicios extranjero',1,0,0),('6290000006',5,'Otros servicios extranjero',1,0,0),('6290000006',6,'Otros servicios extranjero',1,0,0),('6290000007',1,'Gastos pequeño material',1,0,0),('6290000007',3,'Compras pequeño material',1,0,0),('6290000007',6,'Pequeño material',1,0,0),('6290000008',1,'Gastos varios-uniformes personal',1,0,0),('6290000008',3,'Compra uniformes',1,0,0),('6290000009',1,'Gastos-CC Container',1,0,0),('6290000010',1,'Gastos formación clientes',1,0,0),('6290000012',1,'Gastos gestión contra-reembolsos',1,0,0),('6290000013',1,'Arrendamiento Vilassar',1,0,0),('6290000014',1,'Gasto laboral espresas ETT',1,0,0),('6290000015',1,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',3,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',6,'Gasto compra terminales moviles y similares',1,0,0),('6290000016',1,'Gasto gestión cobro ventas',1,0,0),('6290000553',1,'Gastos viaje administrador',1,0,0),('6290000553',4,'Gastos viaje administrador-gerente',1,0,0),('6290000553',6,'Gastos viaje administrador',1,0,0),('6290001000',1,'Gastos de viaje',1,0,0),('6290001000',4,'Gastos viajes otros departamentos',1,0,0),('6290001000',6,'Gastos viaje personal otros departamentos',1,0,0),('6290001001',1,'Gastos R.R.P.P. Gerente',1,0,0),('6290001002',1,'Gastos R.R.P.P. Comerciales',1,0,0),('6290001567',0,'Gastos material oficina',1,0,0),('6300000000',1,'Impuesto de sociedades',1,0,0),('6310000000',1,'Otros tributos',1,0,0),('6380000000',1,'Ajustes positivos s/b Bº',1,0,0),('6400000000',0,'Sueldos y salarios',1,0,0),('6400000000',1,'Salarios',0,0,0),('6400000001',0,'Productividad',1,0,0),('6400000567',0,'Salarios VNH',1,0,0),('6410000001',1,'Indemnizaciones',1,0,0),('6420000000',0,'Seguridad Social a cargo de la empresa',1,0,0),('6420000000',1,'Seguridad Social',0,0,0),('6490000000',1,'Otros gastos sociales',1,0,0),('6500000000',1,'Impagados definitivos',1,0,0),('6620000000',0,'Intereses Bancarios',1,0,0),('6620000001',1,'Intereses deudas a l/p',1,0,0),('6620000002',1,'Intereses Leasing La caixa 0265670-03',1,0,0),('6620000003',1,'Interses Leasing La caixa 0265878-21',1,0,0),('6620000006',1,'Intereses deuda prestamo CRA',1,0,0),('6620000007',1,'Intereses La Caixa linea comercio exterior',1,0,0),('6620000007',16,'Intereses La Caixa Linea Comercio Exterior',0,0,0),('6620000008',1,'Intereses Prestamos Transolver 2016',1,0,0),('6620000011',1,'Intereses BBVA linea comercio exterior',1,0,0),('6620000014',1,'Intereses Prestamo BBVA',1,0,0),('6620000015',1,'Interés Póliza Deutsche Bank Comercio Exterior',0,0,0),('6620000023',1,'Intereses Bankinter Póliza Comercio Exterior',0,0,0),('6620002032',1,'Intereses Leaing Iveco',1,0,0),('6620002066',1,'Leasing Intereses Man',1,0,0),('6620002104',1,'Intereses Leasing La caixa 3 vehículos',1,0,0),('6622000000',20,'Intereses deudas otras partes vinculadas',1,0,0),('6660000000',1,'Perdidas en valores representativos de deuda a l/p',0,0,0),('6681000000',1,'Diferencia negativa tipo de cambio',1,0,0),('6681000000',4,'Diferencia negativa tipo de cambio',0,0,0),('6681000000',6,'Diferencia negativa tipo de cambio',1,0,0),('6681000567',0,'Diferencias de cambio VNH',1,0,0),('6690000000',1,'Otros gastos financieros',1,0,0),('6690000000',6,'Gastos financieros',1,0,0),('6720000000',16,'Perdidas procedentes de inversiones',0,0,0),('6780000000',1,'Gastos extraordinarios',1,0,0),('6780000001',1,'Gastos no deducibles',1,0,0),('6780000001',16,'Gasto no deducible',0,0,0),('6800000000',1,'Amortización inmovilizado intangible',1,0,0),('6800000001',0,'Amortizacion inmovilizado material',1,0,0),('6800000001',1,'Amortización del inmovilizado material',1,0,0),('6810000000',0,'Amortizaciones inmovilizado',1,0,0),('6810000000',1,'Amortizacion inmovilizado material',1,0,0),('7000000000',0,'Ventas',1,0,0),('7000000001',1,'Venta entre empresas',1,0,0),('7000010000',0,'Terceros Flor',1,0,0),('7000020000',0,'Terceros Planta',1,0,0),('7000030000',0,'Terceros Complementos',1,0,0),('7000040000',0,'Terceros Artificial',1,0,0),('7000050000',0,'Terceros Verdes',1,0,0),('7000060000',0,'Terceros Otros',1,0,0),('7000070000',0,'Terceros Confección',1,0,0),('7000080000',1,'Terceros Logística',1,0,0),('7001000000',1,'Mercaderia',1,0,1),('7001010000',0,'Grupo Flor',1,0,0),('7001020000',0,'Grupo Planta',1,0,0),('7001030000',0,'Grupo Complementos',1,0,0),('7001040000',0,'Grupo Artificial',1,0,0),('7001050000',0,'Grupo Verdes',1,0,0),('7001060000',0,'Grupo Otros',1,0,0),('7001070000',0,'Grupo Confección',1,0,0),('7001080000',1,'Grupo Logística',1,0,0),('7002010000',0,'Asociados Flor',1,0,0),('7002020000',0,'Asociados Planta',1,0,0),('7002030000',0,'Asociados Complementos',1,0,0),('7002040000',0,'Asociados Artificial',1,0,0),('7002050000',0,'Asociados Verdes',1,0,0),('7002060000',0,'Asociados Otros',1,0,0),('7002070000',0,'Asociados Confección',1,0,0),('7002080000',1,'Asociados Logística',1,0,0),('7040000000',1,'Embalajes',1,0,1),('7050000000',1,'Prestacion de servicios',1,0,1),('7400000000',1,'Subvenciones, donaciones a la explotacion',1,0,0),('7550000000',0,'Ingresos por serivicios al personal',1,0,0),('7620000000',16,'Intereses de créditos a l/p',1,0,0),('768,0',0,NULL,1,0,0),('7680000000',0,'Diferencias positivas de cambio',1,0,0),('7680000000',1,'Diferenica positiva tipo de cambio',1,0,0),('7680000000',4,'Diferenica positiva tipo de cambio',0,0,0),('7680000000',6,'Diferenica positiva tipo de cambio',1,0,0),('7690000000',1,'Otros ingresos financieros',1,0,0),('7710000000',20,'Beneficio procendente vta inm',1,0,0),('7780000000',1,'Ingresos excepcionales',1,0,0),('7780000000',16,'Ingreso extraordinario',0,0,0),('7780000001',1,'Indemnizaciones transporte',1,0,0),('7780000001',4,'Indemnizaciones agencias transporte',1,0,0),('7780000001',5,'Indemnizaciones agencias transporte',1,0,0),('7780000001',6,'Indemnizaciones transporte',1,0,0),('7940000000',1,'Reversión impagos',1,0,0),('7940000000',16,'Reversión impagos',0,0,0); /*!40000 ALTER TABLE `Gastos` ENABLE KEYS */; UNLOCK TABLES; @@ -438,7 +438,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:48 +-- Dump completed on 2019-05-23 8:39:41 USE `bi`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -486,7 +486,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:48 +-- Dump completed on 2019-05-23 8:39:41 USE `cache`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -524,7 +524,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:48 +-- Dump completed on 2019-05-23 8:39:41 USE `hedera`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -582,7 +582,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:48 +-- Dump completed on 2019-05-23 8:39:41 USE `postgresql`; -- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64) -- @@ -637,7 +637,7 @@ UNLOCK TABLES; LOCK TABLES `professional_category` WRITE; /*!40000 ALTER TABLE `professional_category` DISABLE KEYS */; -INSERT INTO `professional_category` VALUES (1,'Mozos',5,1,27.5),(2,'Encargados',3,1,27.5),(3,'Jefe de grupo',NULL,1,27.5),(4,'Comprador',3,1,27.5),(5,'Aux Administracion',4,1,27.5),(6,'Of Administracion',3,1,27.5),(7,'Jefe Administracion',2,1,27.5),(8,'Informatico',3,1,27.5),(9,'Directivo',1,0,27.5),(10,'Aux Ventas',5,1,27.5),(11,'Vendedor',4,1,27.5),(12,'Jefe de Ventas',3,0,27.5),(13,'Repartidor',5,1,27.5),(14,'Aprendices',6,1,27.5),(15,'Técnicos',2,1,27.5),(16,'Aux Florista',5,1,27.5),(17,'Florista',4,1,27.5),(18,'Jefe Floristas',2,1,27.5),(19,'Técnico marketing',5,1,27.5),(20,'Auxiliar marketing',5,1,27.5),(21,'Aux Informática',2,1,27.5),(22,'Peón agrícola',5,1,27.5),(23,'Oficial mantenimiento',5,1,27.5),(24,'Aux mantenimiento',5,1,27.5),(25,'Mozo Aeropuerto',5,1,27.5); +INSERT INTO `professional_category` VALUES (1,'Mozos',5,1,27.5),(2,'Encargados',3,1,27.5),(4,'Comprador',3,1,27.5),(5,'Aux Administracion',4,1,27.5),(6,'Of Administracion',3,1,27.5),(7,'Jefe Administracion',2,1,27.5),(8,'Informatico',3,1,27.5),(9,'Directivo',1,0,27.5),(10,'Aux Ventas',4,1,27.5),(11,'Vendedor',4,1,27.5),(12,'Jefe de Ventas',4,0,27.5),(13,'Repartidor',5,1,27.5),(14,'Aprendices',6,1,27.5),(15,'Técnicos',2,1,27.5),(16,'Aux Florista',5,1,27.5),(17,'Florista',4,1,27.5),(18,'Jefe Floristas',2,1,27.5),(19,'Técnico marketing',3,1,27.5),(20,'Auxiliar marketing',4,1,27.5),(21,'Aux Informática',4,1,27.5),(22,'Peón agrícola',5,1,27.5),(23,'Oficial mantenimiento',4,1,27.5),(24,'Aux mantenimiento',5,1,27.5),(25,'Mozo Aeropuerto',5,1,27.5),(26,'Coordinador',2,1,27.5),(28,'Aux Logistica',4,1,27.5),(29,'Oficial Logistica',3,1,27.5),(30,'Subencargado',4,1,27.5); /*!40000 ALTER TABLE `professional_category` ENABLE KEYS */; UNLOCK TABLES; @@ -657,7 +657,7 @@ UNLOCK TABLES; LOCK TABLES `workcenter` WRITE; /*!40000 ALTER TABLE `workcenter` DISABLE KEYS */; -INSERT INTO `workcenter` VALUES (1,'Silla',20,906,1),(2,'Mercaflor',19,NULL,NULL),(3,'Marjales',26,20006,NULL),(4,'VNH',NULL,NULL,3),(5,'Madrid',28,2845,5),(6,'Vilassar',88,88014,2),(7,'Tenerife',NULL,NULL,10),(8,'Silla-Agrario',26,NULL,NULL); +INSERT INTO `workcenter` VALUES (1,'Silla',20,906,1),(2,'Mercaflor',19,NULL,NULL),(3,'Marjales',26,20006,NULL),(4,'VNH',NULL,NULL,3),(5,'Madrid',28,2846,5),(6,'Vilassar',88,88014,2),(7,'Tenerife',NULL,NULL,10),(8,'Silla-Agrario',26,NULL,NULL); /*!40000 ALTER TABLE `workcenter` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -670,4 +670,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-09 8:55:48 +-- Dump completed on 2019-05-23 8:39:41 diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 58d5d938a..38148086d 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -187,7 +187,7 @@ CREATE TABLE `mailAlias` ( `isPublic` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `alias` (`alias`) -) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases'; +) ENGINE=InnoDB AUTO_INCREMENT=78 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -376,7 +376,7 @@ CREATE TABLE `user` ( KEY `nickname` (`nickname`), KEY `lang` (`lang`), CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15696 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; +) ENGINE=InnoDB AUTO_INCREMENT=15790 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1918,7 +1918,7 @@ CREATE TABLE `XDiario_ALL` ( KEY `Cuenta` (`SUBCTA`), KEY `empresa` (`empresa_id`), KEY `Fecha` (`Fecha`) -) ENGINE=InnoDB AUTO_INCREMENT=1161872 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1580132 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -1991,7 +1991,7 @@ CREATE TABLE `analisis_ventas` ( `Importe` double NOT NULL, PRIMARY KEY (`id`), KEY `Año` (`Año`,`Semana`) -) ENGINE=InnoDB AUTO_INCREMENT=29682160 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=35776915 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2500,7 +2500,7 @@ CREATE TABLE `rutasBoard` ( KEY `rutasBoard_ix1` (`year`), KEY `rutasBoard_ix2` (`month`), KEY `rutasBoard_ix3` (`warehouse_id`) -) ENGINE=InnoDB AUTO_INCREMENT=80158 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=93457 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4830,17 +4830,17 @@ DELIMITER ; /*!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 `rutas_m3_add` */; +/*!50003 DROP PROCEDURE IF EXISTS `rutas_m3_addKK` */; /*!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 ;; -CREATE DEFINER=`root`@`%` PROCEDURE `rutas_m3_add`() +CREATE DEFINER=`root`@`%` PROCEDURE `rutas_m3_addKK`() BEGIN DECLARE vStartDate DATE DEFAULT TIMESTAMPADD(DAY, -90, CURDATE()); DECLARE vEndDate DATE DEFAULT CURDATE(); @@ -5273,7 +5273,7 @@ CREATE TABLE `m3` ( `dayName` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `euros` decimal(10,2) DEFAULT '0.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=178350 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=193695 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5423,7 +5423,7 @@ CREATE TABLE `nightTask` ( `schema` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `procedure` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5492,7 +5492,7 @@ CREATE TABLE `payMethodClient` ( KEY `FkDateClientPayMethod` (`dated`,`clientFk`), CONSTRAINT `FkClientPayMethod` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FkPayMethodClient` FOREIGN KEY (`payMethodFk`) REFERENCES `vn2008`.`pay_met` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2813258 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +) ENGINE=InnoDB AUTO_INCREMENT=3042620 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5562,7 +5562,7 @@ CREATE TABLE `productivity` ( `numComplementos` int(11) NOT NULL DEFAULT '0', `costComplementos` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=29590671 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=31310151 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7575,33 +7575,53 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `salePersonEvolutionAdd`(IN vDateStart DATETIME) BEGIN - - TRUNCATE bs.salePersonEvolution ; - INSERT INTO bs.salePersonEvolution (dated, amount, equalizationTax, salesPersonFk) - SELECT dated, amount, equalizationTax, salesPersonFk - FROM - (SELECT dated, - salesPersonFk , - if(@vSalesPersonFk = salesPersonFk, "", @vAggregateAmount := 0 ), - if(@vSalesPersonFk = salesPersonFk, "", @vAggregateEqualizationTax := 0 ), - if(@vSalesPersonFk = salesPersonFk, "", @vSalesPersonFk := salesPersonFk), - @vAggregateAmount:= @vAggregateAmount + amount amount, - @vAggregateEqualizationTax:= @vAggregateEqualizationTax + equalizationTax equalizationTax - FROM - (SELECT fecha dated, - CAST(SUM(importe) AS DECIMAL(10,2) ) amount, - CAST(SUM(recargo) AS DECIMAL(10,2) ) equalizationTax , - IFNULL(salesPersonFk,0) salesPersonFk - FROM bs.ventas v - JOIN vn.client c ON v.Id_Cliente = c.id - JOIN vn.company co ON co.id = v.empresa_id - WHERE co.code = "VNL" AND fecha >= vDateStart - GROUP BY fecha,salesPersonFk - ORDER BY salesPersonFk,dated ASC - )sub - ORDER BY salesPersonFk,dated ASC - )sub2; - + DELETE FROM bs.salePersonEvolution + WHERE dated <= DATE_SUB(CURDATE(), INTERVAL 1 YEAR); + + + INSERT INTO bs.salePersonEvolution (dated, amount, equalizationTax, salesPersonFk) + SELECT fecha dated, + CAST(SUM(importe) AS DECIMAL(10,2) ) amount, + CAST(SUM(recargo) AS DECIMAL(10,2) ) equalizationTax , + IFNULL(salesPersonFk,0) salesPersonFk + FROM bs.ventas v + JOIN vn.client c ON v.Id_Cliente = c.id + JOIN vn.company co ON co.id = v.empresa_id + WHERE co.code = "VNL" AND fecha >= vDateStart + GROUP BY v.fecha,c.salesPersonFk + ORDER BY salesPersonFk,dated ASC; +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 `userSundayRole` */; +/*!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 `userSundayRole`() +BEGIN + -- 4996 Fran Natek Echevarria + DECLARE vDay INT; + SET vDay := (SELECT DAYOFWEEK(CURDATE())); + IF vDay = 1 THEN + UPDATE account.user u + JOIN account.role r + SET u.role = r.id + WHERE u.id = 4996 AND r.name = "salesAssistant"; + ELSE + UPDATE account.user u + JOIN account.role r + SET u.role = r.id + WHERE u.id = 4996 AND r.name = "salesPerson"; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -8212,7 +8232,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDB AUTO_INCREMENT=328867 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=337624 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8280,7 +8300,7 @@ CREATE TABLE `prod_graphic_source` ( `alert_level` int(11) NOT NULL DEFAULT '0', `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=680942 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=764562 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9469,7 +9489,7 @@ CREATE TABLE `batch` ( KEY `buy_edi_id` (`buy_edi_id`), CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=463788 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=478514 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9570,7 +9590,7 @@ CREATE TABLE `deliveryInformation` ( KEY `fgbSupplyResponse_idx2` (`FirstOrderDateTime`), KEY `fgbSupplyResponse_idx3` (`LatestOrderDateTime`), CONSTRAINT `fgbSupplyResponse` FOREIGN KEY (`supplyResponseID`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=17698154 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=18264966 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9874,7 +9894,7 @@ CREATE TABLE `message` ( UNIQUE KEY `mail_id` (`mail_id`), KEY `sender_id` (`sender_id`), CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=487808 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=503105 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10098,7 +10118,7 @@ CREATE TABLE `supplyResponse` ( `MarketFormCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '"002" Standard Sales\n"005" Catalogue (optional)\n"001" Committed (optional)\n"003" Buffer (optional, Clock Pre Sales) ', PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=5776843 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=6038803 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11123,7 +11143,7 @@ CREATE TABLE `news` ( KEY `tag` (`tag`), CONSTRAINT `news_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`account` (`id`) ON UPDATE CASCADE, CONSTRAINT `news_ibfk_2` FOREIGN KEY (`tag`) REFERENCES `newsTag` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=13067 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=13068 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11174,54 +11194,48 @@ CREATE TABLE `order` ( CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1889709 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `orderCheck` --- - -DROP TABLE IF EXISTS `orderCheck`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderCheck` ( - `id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT, - `maxTime` time NOT NULL, - `denySunday` tinyint(1) NOT NULL, - `denyDay` date DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Conditions to check when an order is confirmed'; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `orderCheckFestive` --- - -DROP TABLE IF EXISTS `orderCheckFestive`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderCheckFestive` ( - `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, - `date` date NOT NULL, - `acceptOrders` tinyint(1) NOT NULL DEFAULT '1', - PRIMARY KEY (`id`), - UNIQUE KEY `date` (`date`) -) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `orderCheckWday` --- - -DROP TABLE IF EXISTS `orderCheckWday`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderCheckWday` ( - `weekday` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday', - `maxTime` time NOT NULL, - PRIMARY KEY (`weekday`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1917144 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +/*!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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` + AFTER UPDATE ON `order` + FOR EACH ROW +BEGIN + CALL stock.log_add('order', OLD.id, NEW.id); +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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`order_beforeDelete` + BEFORE DELETE ON `order` + FOR EACH ROW +BEGIN + DELETE FROM orderRow WHERE orderFk = OLD.id; +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 */ ; -- -- Table structure for table `orderConfig` @@ -11275,19 +11289,19 @@ CREATE TABLE `orderRow` ( KEY `created` (`created`), KEY `warehouse_shipment` (`warehouseFk`,`shipment`), CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE, - CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11449709 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=11602292 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!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 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 ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `orderRowBeforeInsert` +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `orderRow_beforeInsert` BEFORE INSERT ON `orderRow` FOR EACH ROW BEGIN @@ -11307,6 +11321,66 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterInsert` + AFTER INSERT ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', NULL, NEW.id); +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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterUpdate` + AFTER UPDATE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', OLD.id, NEW.id); +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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`orderRow_afterDelete` + AFTER DELETE ON `orderRow` + FOR EACH ROW +BEGIN + CALL stock.log_add('orderRow', OLD.id, NULL); +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 */ ; -- -- Table structure for table `orderRowComponent` @@ -11636,7 +11710,7 @@ CREATE TABLE `tpvTransaction` ( CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=307387 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=312517 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11671,7 +11745,7 @@ CREATE TABLE `visit` ( PRIMARY KEY (`id`), KEY `firstAgent` (`firstAgent`), CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1744715 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1771677 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11691,7 +11765,7 @@ CREATE TABLE `visitAccess` ( KEY `visit_access_idx_agent` (`agent`), KEY `stamp` (`stamp`), CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3819507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3877888 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11716,7 +11790,7 @@ CREATE TABLE `visitAgent` ( KEY `firstAccess` (`firstAccess`), CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2344700 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2376206 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11736,7 +11810,7 @@ CREATE TABLE `visitUser` ( KEY `date_time` (`stamp`), KEY `user_id` (`user`), CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3401307 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3442690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11778,17 +11852,17 @@ DELIMITER ; /*!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 FUNCTION IF EXISTS `myBasketGetId` */; +/*!50003 DROP FUNCTION IF EXISTS `myBasket_getId` */; /*!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 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`@`%` FUNCTION `myBasketGetId`() RETURNS int(11) +CREATE DEFINER=`root`@`%` FUNCTION `MYBASKET_GETID`() RETURNS int(11) DETERMINISTIC BEGIN DECLARE vOrder INT; @@ -11903,266 +11977,6 @@ DELIMITER ; /*!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 `basketAddItem` */; -/*!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 `basketAddItem`( - vWarehouse INT, - vItem INT, - vAmount INT) -BEGIN - DECLARE vOrder INT; - - SET vOrder = myBasketGetId(); - - CALL orderAddItem(vOrder,vWarehouse, vItem, vAmount); -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 `basketCheck` */; -/*!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 `basketCheck`() -BEGIN -/** - * Comprueba que la cesta esta creada y que su configuración es - * correcta. Si la configuración es correcta pero lleva mucho - * tiempo creada actualiza los precios y cantidades de los artículos. - * - * @select El id del pedido y el estado de la cesta - */ - DECLARE vOrder INT; - DECLARE vCreated DATETIME; - DECLARE vStatus VARCHAR(15) DEFAULT 'OK'; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vStatus = 'NOT_EXISTS'; - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET vStatus = 'BAD_CONFIG'; - - SELECT id, made - INTO vOrder, vCreated - FROM myBasket; - - IF vStatus = 'OK' - THEN - CALL orderCheckConfig(vOrder); - - IF vStatus = 'OK' AND vCreated < TIMESTAMPADD(DAY, -1, NOW()) - THEN - CALL orderUpdate(vOrder); - SET vStatus = 'UPDATED'; - END IF; - END IF; - - SELECT vStatus stat; -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 `basketConfigure` */; -/*!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 `basketConfigure`( - vDelivery DATE, - vDeliveryMethod VARCHAR(45), - vAgency INT, - vAddress INT) -BEGIN -/** - * Configura la cesta de la compra utilizando los parámetros - * pasados. Si los parámetros no son válidos devuelve un error. - * - * @param vDelivery Fecha de recogida - * @param vAgency Id de la agencia - * @param vAddress Id de dirección de envío, @NULL si es recogida - */ - DECLARE vOrder INT; - DECLARE vCompany INT; - DECLARE vDeliveryMethodId INT; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vOrder = NULL; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT id INTO vDeliveryMethodId - FROM vn.deliveryMethod - WHERE code = vDeliveryMethod; - - IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL - THEN - SELECT defaultAddressFk INTO vAddress - FROM myClient; - END IF; - - SET vOrder = myBasketGetId(); - - IF vOrder IS NULL - THEN - SELECT companyFk INTO vCompany - FROM vn.clientDefaultCompany - WHERE ClientFk = account.userGetId() - AND CURDATE() BETWEEN started AND finished - LIMIT 1; - - IF vCompany IS NULL - THEN - SELECT defaultCompanyFk INTO vCompany - FROM orderConfig; - END IF; - - INSERT INTO `order` - SET - customer_id = account.userGetId(), - date_send = vDelivery, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgency, - address_id = vAddress, - source_app = 'WEB', - company_id = vCompany; - - SET vOrder = LAST_INSERT_ID(); - - INSERT INTO basketOrder SET - clientFk = account.userGetId(), - orderFk = vOrder; - ELSE - UPDATE `order` - SET - date_send = vDelivery, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgency, - address_id = vAddress - WHERE - id = vOrder; - - CALL orderUpdate (vOrder); - END IF; - - CALL orderCheckConfig (vOrder); - - COMMIT; -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 `basketConfigureForGuest` */; -/*!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 `basketConfigureForGuest`() -BEGIN - DECLARE vMethod VARCHAR(45); - DECLARE vAgency INT; - - SELECT guestMethod, guestAgencyFk - INTO vMethod, vAgency - FROM orderConfig - LIMIT 1; - - CALL basketConfigure (CURDATE(), vMethod, vAgency, NULL); -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 `basketConfirm` */; -/*!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 `basketConfirm`() -BEGIN - DECLARE vOrder INT DEFAULT myBasketGetId(); - - IF vOrder IS NOT NULL - THEN - CALL orderConfirm(vOrder); - - DELETE FROM basketOrder - WHERE orderFk = vOrder; - 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 `basketGetTax` */; -/*!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 = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `basketGetTax`() - READS SQL DATA -BEGIN -/** - * Returns the taxes for the current client basket. - * - * @treturn tmp.orderTax - */ - DROP TEMPORARY TABLE IF EXISTS tmp.order; - CREATE TEMPORARY TABLE tmp.order - ENGINE = MEMORY - SELECT myBasketGetId() orderFk; - - CALL orderGetTax(); - - DROP TEMPORARY TABLE IF EXISTS tmp.order; -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 `bionicCalcWithDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12222,34 +12036,6 @@ DELIMITER ; /*!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 `bionic_from_basket` */; -/*!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 `bionic_from_basket`() -BEGIN - DECLARE vOrder INT; - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT id, sent, addressFk, agencyModeFk - INTO vOrder, vDate, vAddress, vAgencyMode - FROM myBasket; - - CALL vn2008.bionic_from_order(vDate, vAddress, vAgencyMode, vOrder); -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 `bionic_from_item` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12277,90 +12063,17 @@ DELIMITER ; /*!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 `catalogGetAvailable` */; +/*!50003 DROP PROCEDURE IF EXISTS `catalog_getTags` */; /*!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 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 `catalogGetAvailable`() -BEGIN -/** - * Gets the available items list that meets the tag filter. - * - * @table tItems - */ - CALL itemGetAvailable; - - DELETE t FROM tItems t - JOIN tmp.itemAvailable a ON a.id = t.id - WHERE a.id IS NULL; - - DROP TEMPORARY TABLE tmp.itemAvailable; -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 `catalogGetItems` */; -/*!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 `catalogGetItems`() -BEGIN -/** - * Returns the list of items. - * - * @table tItems The list of items - * @select The list of items - */ - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; - CREATE TEMPORARY TABLE tmp.bionic_calc - (INDEX (item_id)) - ENGINE = MEMORY - SELECT id item_id FROM tItems; - - CALL bionic_calc (); - DROP TEMPORARY TABLE tmp.bionic_calc; - - SELECT i.id, i.name, i.description, i.category, i.size, i.image, i.inkFk, - IF(i.stems > 1, i.stems, NULL) stems, b.available, b.price, b.producer, - a.tag1, a.val1, a.tag2, a.val2, a.tag3, a.val3 - FROM tmp.bionic_item b - JOIN vn.item i ON i.id = b.item_id - LEFT JOIN vn.itemTagArranged a ON a.itemFk = i.id - LEFT JOIN vn.producer p ON p.id = i.producerFk - WHERE b.available > 0 - ORDER BY i.relevancy DESC, i.name, i.size - LIMIT 40; -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 `catalogGetTags` */; -/*!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 `catalogGetTags`(vLimit INT) +CREATE DEFINER=`root`@`%` PROCEDURE `catalog_getTags`(vLimit INT) BEGIN /** * Returns the main tags for a list of items. @@ -12392,17 +12105,17 @@ DELIMITER ; /*!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 `catalogGetTagValues` */; +/*!50003 DROP PROCEDURE IF EXISTS `catalog_getTagValues` */; /*!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 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 `catalogGetTagValues`(vTag INT) +CREATE DEFINER=`root`@`%` PROCEDURE `catalog_getTagValues`(vTag INT) BEGIN /** * Returns the list of available values for a tag and a list of items. @@ -12425,35 +12138,13 @@ DELIMITER ; /*!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 `itemAllocator` */; +/*!50003 DROP PROCEDURE IF EXISTS `itemGetAvailable` */; /*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemAllocator`(IN `vWh` TINYINT, IN `vDate` DATE, IN `vType` INT, IN `vPrefix` VARCHAR(255), IN `vUseIds` BOOLEAN) -BEGIN -/** - * @deprecated Use item_listAllocation() instead - */ - CALL item_listAllocation(vWh, vDate, vType, vPrefix, vUseIds); -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 `itemGetAvailable` */; -/*!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 collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -12537,49 +12228,49 @@ DELIMITER ; /*!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 `itemGetList` */; +/*!50003 DROP PROCEDURE IF EXISTS `item_getList` */; /*!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_unicode_ci */ ; +/*!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 `itemGetList`(IN `vWarehouse` SMALLINT, IN `vShipping` DATE, IN `vCategory` INT, IN `vRate` TINYINT) -BEGIN - DECLARE vCalc INT; - - CALL cache.available_refresh(vCalc, FALSE, vWarehouse, vShipping); - CALL vn2008.item_last_buy_(vWarehouse, vShipping); - - SELECT a.id, a.`name`, a.category, a.size, a.stems, a.inkFk, a.typeFk, a.image, - c.available, o.`name` origin, t.`name` `type`, - CASE b.groupingMode - WHEN 0 THEN 1 - WHEN 2 THEN b.packing - ELSE b.`grouping` - END AS `grouping`, - CASE vRate - WHEN 1 THEN b.price1 - WHEN 2 THEN b.price2 - WHEN 3 THEN b.price3 - ELSE NULL - END AS price - FROM cache.available c - JOIN vn.item a ON a.id = c.item_id - JOIN vn.itemType t ON t.id = a.typeFk - JOIN vn.itemCategory r ON r.id = t.categoryFk - LEFT JOIN vn.origin o ON o.id = a.originFk - JOIN vn2008.t_item_last_buy l ON l.item_id = a.id - JOIN vn.buy b ON b.id = l.buy_id - WHERE c.calc_id = vCalc - AND c.available > 0 - AND a.id != 90 - AND r.display - AND (vCategory IS NULL OR vCategory = r.id) - ORDER BY a.typeFk, a.`name`, a.size; +CREATE DEFINER=`root`@`%` PROCEDURE `item_getList`(IN `vWarehouse` SMALLINT, IN `vShipping` DATE, IN `vCategory` INT, IN `vRate` TINYINT) +BEGIN + DECLARE vCalc INT; + + CALL cache.available_refresh(vCalc, FALSE, vWarehouse, vShipping); + CALL vn2008.item_last_buy_(vWarehouse, vShipping); + + SELECT a.id, a.`name`, a.category, a.size, a.stems, a.inkFk, a.typeFk, a.image, + c.available, o.`name` origin, t.`name` `type`, + CASE b.groupingMode + WHEN 0 THEN 1 + WHEN 2 THEN b.packing + ELSE b.`grouping` + END AS `grouping`, + CASE vRate + WHEN 1 THEN b.price1 + WHEN 2 THEN b.price2 + WHEN 3 THEN b.price3 + ELSE NULL + END AS price + FROM cache.available c + JOIN vn.item a ON a.id = c.item_id + JOIN vn.itemType t ON t.id = a.typeFk + JOIN vn.itemCategory r ON r.id = t.categoryFk + LEFT JOIN vn.origin o ON o.id = a.originFk + JOIN vn2008.t_item_last_buy l ON l.item_id = a.id + JOIN vn.buy b ON b.id = l.buy_id + WHERE c.calc_id = vCalc + AND c.available > 0 + AND a.id != 90 + AND r.display + AND (vCategory IS NULL OR vCategory = r.id) + ORDER BY a.typeFk, a.`name`, a.size; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -12744,6 +12435,261 @@ DELIMITER ; /*!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 `myBasket_addItem` */; +/*!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 `myBasket_addItem`( + vWarehouse INT, + vItem INT, + vAmount INT) +BEGIN + CALL order_addItem(myBasket_getId(), vWarehouse, vItem, vAmount); +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 `myBasket_check` */; +/*!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 `myBasket_check`() +BEGIN +/** + * Comprueba que la cesta esta creada y que su configuración es + * correcta. Si la configuración es correcta pero lleva mucho + * tiempo creada actualiza los precios y cantidades de los artículos. + * + * @select El id del pedido y el estado de la cesta + */ + DECLARE vSelf INT; + DECLARE vCreated DATETIME; + DECLARE vStatus VARCHAR(15) DEFAULT 'OK'; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vStatus = 'NOT_EXISTS'; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET vStatus = 'BAD_CONFIG'; + + SELECT id, made + INTO vSelf, vCreated + FROM myBasket; + + IF vStatus = 'OK' + THEN + CALL orderCheckConfig(vSelf); + + IF vStatus = 'OK' AND vCreated < TIMESTAMPADD(DAY, -1, NOW()) + THEN + CALL order_update(vSelf); + SET vStatus = 'UPDATED'; + END IF; + END IF; + + SELECT vStatus stat; +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 `myBasket_configure` */; +/*!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 `myBasket_configure`( + vDelivery DATE, + vDeliveryMethod VARCHAR(45), + vAgency INT, + vAddress INT) +BEGIN +/** + * Configura la cesta de la compra utilizando los parámetros + * pasados. Si los parámetros no son válidos devuelve un error. + * + * @param vDelivery Fecha de recogida + * @param vAgency Id de la agencia + * @param vAddress Id de dirección de envío, @NULL si es recogida + */ + DECLARE vSelf INT; + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT id INTO vDeliveryMethodId + FROM vn.deliveryMethod + WHERE code = vDeliveryMethod; + + IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL + THEN + SELECT defaultAddressFk INTO vAddress + FROM myClient; + END IF; + + SET vSelf = myBasket_getId(); + + IF vSelf IS NULL + THEN + SELECT companyFk INTO vCompany + FROM vn.clientDefaultCompany + WHERE clientFk = account.userGetId() + AND CURDATE() BETWEEN started AND finished + LIMIT 1; + + IF vCompany IS NULL + THEN + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + END IF; + + INSERT INTO `order` + SET + customer_id = account.userGetId(), + date_send = vDelivery, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgency, + address_id = vAddress, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + INSERT INTO basketOrder SET + clientFk = account.userGetId(), + orderFk = vSelf; + ELSE + UPDATE `order` + SET + date_send = vDelivery, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgency, + address_id = vAddress + WHERE + id = vSelf; + + CALL order_update(vSelf); + END IF; + + CALL orderCheckConfig(vSelf); + + COMMIT; +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 `myBasket_configureForGuest` */; +/*!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 `myBasket_configureForGuest`() +BEGIN + DECLARE vMethod VARCHAR(45); + DECLARE vAgency INT; + + SELECT guestMethod, guestAgencyFk + INTO vMethod, vAgency + FROM orderConfig + LIMIT 1; + + CALL myBasket_configure(CURDATE(), vMethod, vAgency, NULL); +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 `myBasket_confirm` */; +/*!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 `myBasket_confirm`() +BEGIN + DECLARE vSelf INT DEFAULT myBasket_getId(); + + IF vSelf IS NOT NULL THEN + CALL order_confirm(vSelf); + + DELETE FROM basketOrder + WHERE orderFk = vSelf; + 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 `myBasket_getTax` */; +/*!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 `myBasket_getTax`() + READS SQL DATA +BEGIN +/** + * Returns the taxes for the current client basket. + * + * @treturn tmp.orderTax + */ + DROP TEMPORARY TABLE IF EXISTS tmp.order; + CREATE TEMPORARY TABLE tmp.`order` + ENGINE = MEMORY + SELECT myBasket_getId() orderFk; + + CALL orderGetTax(); + + DROP TEMPORARY TABLE IF EXISTS tmp.`order`; +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 `myItemGetAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12857,27 +12803,27 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `myOrderAddItem`(vOrder INT, +CREATE DEFINER=`root`@`%` PROCEDURE `myOrderAddItem`( + vSelf INT, vWarehouse INT, vItem INT, vAmount INT) BEGIN - DECLARE isMine BOOLEAN; - - SELECT COUNT(*) INTO isMine - FROM myOrder - WHERE id = vOrder; - - IF isMine THEN - CALL orderAddItem(vOrder,vWarehouse,vItem,vAmount); - END IF; + DECLARE isMine BOOL; + SELECT COUNT(*) INTO isMine + FROM myOrder + WHERE id = vSelf; + + IF isMine THEN + CALL order_addItem(vSelf, vWarehouse, vItem, vAmount); + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -12888,25 +12834,23 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `myOrderConfirm`(vOrderFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `myOrderConfirm`(vSelf INT) BEGIN - DECLARE isMine BOOLEAN; - DECLARE vTicketFk BOOLEAN; + DECLARE isMine BOOL; SELECT COUNT(*) INTO isMine FROM myOrder - WHERE id = vOrderFk; + WHERE id = vSelf; IF isMine THEN - CALL orderConfirm(vOrderFk); + CALL order_confirm(vSelf); END IF; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -12990,22 +12934,22 @@ DELIMITER ; /*!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 `myTicketGet` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTicket_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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `myTicketGet`(vTicket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `myTicket_get`(vSelf INT) BEGIN /** * Returns a current user ticket header. * - * @param vTicket The ticket identifier + * @param vSelf The ticket identifier */ DECLARE vTaxBase DECIMAL(10,2); DECLARE vTax DECIMAL(10,2); @@ -13014,7 +12958,7 @@ BEGIN CREATE TEMPORARY TABLE tmp.ticket ENGINE = MEMORY SELECT id ticketFk FROM myTicket - WHERE id = vTicket; + WHERE id = vSelf; CALL vn.ticketGetTax; @@ -13031,7 +12975,7 @@ BEGIN JOIN vn.agencyMode ag ON ag.id = t.agencyModeFk LEFT JOIN vn.deliveryMethod m ON m.id = ag.deliveryMethodFk LEFT JOIN vn.province p ON p.id = a.provinceFk - WHERE t.id = vTicket; + WHERE t.id = vSelf; DROP TEMPORARY TABLE tmp.ticket, @@ -13043,22 +12987,22 @@ DELIMITER ; /*!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 `myTicketGetPackages` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTicket_getPackages` */; /*!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 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 `myTicketGetPackages`(vTicket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `myTicket_getPackages`(vSelf INT) BEGIN /** * Returns a current user ticket packages. * - * @param vTicket The ticket identifier + * @param vSelf The ticket identifier * @select The ticket packages */ SELECT i.image, i.id, i.name, tp.quantity @@ -13066,50 +13010,49 @@ BEGIN JOIN vn.ticketPackaging tp ON tp.ticketFk = t.id JOIN vn.packaging p ON p.id = tp.packagingFk JOIN vn.item i ON i.id = p.itemFk - WHERE t.id = vTicket; + WHERE t.id = vSelf; 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 `myTicketGetRows` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTicket_getRows` */; /*!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_unicode_ci */ ; +/*!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 `myTicketGetRows`(`vTicket` INT) -BEGIN - - SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, - i.image, i.category, i.size, i.stems, i.inkFk, - i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7 - FROM myTicketRow r - JOIN vn.item i ON i.id = r.itemFk - WHERE r.ticketFk = vTicket - ORDER BY r.concept; +CREATE DEFINER=`root`@`%` PROCEDURE `myTicket_getRows`(vSelf INT) +BEGIN + SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, + i.image, i.category, i.size, i.stems, i.inkFk, + i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7 + FROM myTicketRow r + JOIN vn.item i ON i.id = r.itemFk + WHERE r.ticketFk = vSelf + ORDER BY r.concept; 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 `myTicketList` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTicket_list` */; /*!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 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 `myTicketList`(vFrom DATE, vTo DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `myTicket_list`(vFrom DATE, vTo DATE) BEGIN /** * Returns the current user list of tickets between two dates reange. @@ -13150,62 +13093,148 @@ DELIMITER ; /*!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 `myTicketLogAccess` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTicket_logAccess` */; /*!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 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 `myTicketLogAccess`(vTicket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `myTicket_logAccess`(vSelf INT) BEGIN /** * Logs an access to a ticket. * - * @param vTicket The ticket identifier + * @param vSelf The ticket identifier */ INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - SELECT vTicket, account.userGetId(), 'select', 'Accede a ticket' + SELECT vSelf, account.userGetId(), 'select', 'Accede a ticket' FROM myTicket t - WHERE t.id = vTicket; + WHERE t.id = vSelf; 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 `myTicketSetDelivered` */; +/*!50003 DROP PROCEDURE IF EXISTS `myTpvTransaction_end` */; /*!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 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 `myTicketSetDelivered`(vTicketFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `myTpvTransaction_end`(vSelf INT, vStatus VARCHAR(12)) BEGIN - - UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1061'); - UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1121'); - UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1134'); - UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1148'); - UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1920'); - - IF vTicketFk is null THEN - call util.throw ('AGENCIA ACTUALIZADA'); +/** + * Finaliza una transaccción estableciendo su estado a 'ok' o + * 'ko' en función de si esta se ha realizado correctamente. + * Este procedimiento debe ser llamado directamente por el cliente + * nada mas finalizar la transacción y solo tiene validez hasta que + * llega la notificacion definitiva desde el banco. + * + * @param vSelf El identificador de la transacción + * @param vStatus El estado, 'ok' o 'ko' + */ + IF vStatus IN ('ok', 'ko') + THEN + UPDATE myTpvTransaction SET status = vStatus + WHERE id = vSelf AND response IS NULL; END IF; - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT s.id, vTicketFk, vn.getWorker() - FROM vn.state s - JOIN myTicket m ON m.id = vTicketFk - WHERE `code` = 'DELIVERED' AND m.id = vTicketFk; +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 `myTpvTransaction_start` */; +/*!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 `myTpvTransaction_start`(vAmount INT, vCompany INT) +BEGIN +/** + * Inicia una nueva transacción con el TPV virtual, generando + * un identificador de transacción y devolviendo con un SELECT + * los parámetros que deben enviarse a la URL del servicio web + * del banco. + * + * @param vAmount Cantidad a pagar en céntimos + * @param vCompany El identificador de la empresa + * + * @select Los parámetros que deben pasarse al banco + */ + DECLARE vSelf CHAR(12); + DECLARE vMerchant INT; + DECLARE vUrl VARCHAR(255); + DECLARE vKey VARCHAR(50); + DECLARE vTestMode BOOLEAN; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF vCompany IS NULL + THEN + SELECT companyFk INTO vCompany + FROM tpvMerchantEnable LIMIT 1; + END IF; + + SELECT merchantFk INTO vMerchant + FROM tpvMerchantEnable WHERE companyFk = vCompany; + + SELECT testMode INTO vTestMode + FROM tpvConfig; + + IF NOT vTestMode + THEN + SELECT c.url, m.secretKey INTO vUrl, vKey + FROM tpvMerchant m + JOIN tpvConfig c + WHERE m.id = vMerchant; + ELSE + SELECT testUrl, testKey INTO vUrl, vKey + FROM tpvConfig; + END IF; + + INSERT INTO myTpvTransaction + SET + merchantFk = vMerchant + ,clientFk = account.userGetId() + ,amount = vAmount; + + SET vSelf = LAST_INSERT_ID(); + + SELECT + vAmount amount + ,vSelf transactionId + ,vMerchant merchant + ,currency + ,transactionType + ,terminal + ,merchantUrl + ,vUrl url + ,vKey secretKey + FROM tpvConfig; + + COMMIT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -13218,109 +13247,20 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!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 `orderAddItem`(IN `vOrder` INT, IN `vWarehouse` INT, IN `vItem` INT, IN `vAmount` INT) -BEGIN - DECLARE vRow INT; - DECLARE vAdd INT; - DECLARE vAvailable INT; - DECLARE vDone BOOL; - DECLARE vGrouping INT; - DECLARE vRate INT; - DECLARE vShipment DATE; - DECLARE vPrice DECIMAL(10,2); - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - DECLARE cur CURSOR FOR - SELECT `grouping`, price, rate - FROM tmp.bionic_price - WHERE warehouse_id = vWarehouse - AND item_id = vItem - ORDER BY `grouping` DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SELECT date_send, address_id, agency_id - INTO vDate, vAddress, vAgencyMode - FROM `order` - WHERE id = vOrder; - - CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem); - - START TRANSACTION; - - SELECT shipped INTO vShipment - FROM tmp.travel_tree - WHERE warehouseFk = vWarehouse; - - SELECT available INTO vAvailable - FROM tmp.bionic_lot - WHERE warehouse_id = vWarehouse - AND item_id = vItem; - - IF vAmount > IFNULL(vAvailable, 0) - THEN - CALL util.throw ('ORDER_ROW_UNAVAILABLE'); - END IF; - - OPEN cur; - - l: LOOP - SET vDone = FALSE; - FETCH cur INTO vGrouping, vPrice, vRate; - - IF vDone THEN - LEAVE l; - END IF; - - SET vAdd = vAmount - MOD(vAmount, vGrouping); - SET vAmount = vAmount - vAdd; - - IF vAdd = 0 THEN - ITERATE l; - END IF; - - INSERT INTO order_row SET - order_id = vOrder, - item_id = vItem, - warehouse_id = vWarehouse, - shipment = vShipment, - rate = vRate, - amount = vAdd, - price = vPrice; - - SET vRow = LAST_INSERT_ID(); - - INSERT INTO order_component (order_row_id, component_id, price) - SELECT vRow, c.component_id, c.cost - FROM tmp.bionic_component c - JOIN bi.tarifa_componentes t - ON t.Id_Componente = c.component_id - AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate) - WHERE c.warehouse_id = vWarehouse - AND c.item_id = vItem; - END LOOP; - - CLOSE cur; - - IF vAmount > 0 - THEN - CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING'); - END IF; - - COMMIT; - CALL vn2008.bionic_free (); +CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`( + vSelf INT, + vWarehouse INT, + vItem INT, + vAmount INT) +BEGIN +/** + * @deprecated Use order_addItem(); + */ + CALL order_addItem(vSelf, vWarehouse, vItem, vAmount); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -13376,78 +13316,22 @@ DELIMITER ; /*!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 `orderCheckDate` */; -/*!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 `orderCheckDate`(vDate DATE) -BEGIN - DECLARE vMaxTime TIME; - DECLARE vFestive BOOLEAN; - DECLARE vDenyDay DATE; - DECLARE vDenySunday BOOLEAN; - - SELECT COUNT(*) INTO vFestive - FROM orderCheckFestive - WHERE TIMESTAMPADD(YEAR, -YEAR(vDate), vDate) = date - AND acceptOrders = FALSE; - - IF vDate < CURDATE() - THEN - CALL util.throw ('ORDER_DATE_PAST'); - ELSEIF vFestive > 0 - THEN - CALL util.throw ('ORDER_DATE_HOLIDAY'); - ELSE - SELECT c.denySunday, c.denyDay, IFNULL(w.maxTime, c.maxTime) - INTO vDenySunday, vDenyDay, vMaxTime - FROM orderCheck c - LEFT JOIN orderCheckWday w - ON w.weekday = WEEKDAY(CURDATE()); - - IF vDate = CURDATE() AND CURTIME() > vMaxTime - THEN - CALL util.throw ('ORDER_DATE_LAST'); - ELSEIF WEEKDAY(vDate) = 6 AND vDenySunday - THEN - CALL util.throw ('ORDER_DATE_SUNDAY'); - ELSEIF vDate = vDenyDay - THEN - CALL util.throw ('ORDER_DATE_SATURATED'); - 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 `orderConfirm` */; /*!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 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 `orderConfirm`(vOrder INT) +CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirm`(vSelf INT) BEGIN /** - * Confirms an order, creating each of its tickets on - * the corresponding date and store. - * - * @param vOrder The order identifier + * @deprecated Use order_confirm(); */ - CALL orderConfirmWithUser(vOrder, account.userGetId()); - + CALL order_confirm(vSelf); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -13460,11 +13344,285 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!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 `orderConfirmWithUser`(IN `vOrder` INT, IN `vUserId` INT) +CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirmWithUser`(vSelf INT, vUserId INT) +BEGIN +/** + * @deprecated Use order_confirmWithUser() + */ + CALL order_confirmWithUser(vSelf, vUserId); +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 `orderGetTax` */; +/*!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 = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`() + READS SQL DATA +BEGIN +/** + * Calcula el IVA, y el recargo de equivalencia de un pedido + * desglosados por tipos. + * + * @param vOrder El identificador del pedido + * @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia + */ + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + (INDEX (addressFk, companyFk)) + ENGINE = MEMORY + SELECT DISTINCT o.address_id addressFk, o.company_id companyFk + FROM tmp.order tmpOrder + JOIN hedera.order o ON o.id = tmpOrder.orderFk; + + CALL vn.addressTaxArea (); + + -- Calcula el IVA y el recargo desglosado. + DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; + CREATE TEMPORARY TABLE tmp.orderTax + (INDEX (orderFk)) + ENGINE = MEMORY + SELECT o.id orderFk, + tc.code, + SUM(m.amount * m.price) taxableBase, + pgc.rate + FROM tmp.order tmpOrder + JOIN `order` o ON o.id = tmpOrder.orderFk + JOIN orderRow m ON m.orderFk = o.id + JOIN vn.item i ON i.id = m.itemFk + JOIN vn.client c ON c.id = o.customer_id + JOIN vn.supplier s ON s.id = o.company_id + JOIN tmp.addressTaxArea ata + ON ata.addressFk = o.address_id AND ata.companyFk = o.company_id + JOIN vn.itemTaxCountry itc + ON itc.itemFk = i.id AND itc.countryFk = s.countryFk + JOIN vn.bookingPlanner bp + ON bp.countryFk = s.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = itc.taxClassFk + JOIN vn.pgc ON pgc.code = bp.pgcFk + JOIN vn.taxClass tc ON tc.id = bp.taxClassFk + GROUP BY tmpOrder.orderFk, pgc.code,pgc.rate + HAVING taxableBase != 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.orderAmount; + CREATE TEMPORARY TABLE tmp.orderAmount + (INDEX (orderFk)) + ENGINE = MEMORY + SELECT orderFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code + FROM tmp.orderTax + GROUP BY orderFk, code; + +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 `orderGetTotal` */; +/*!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 `orderGetTotal`() +BEGIN +/** +* Calcula el total con IVA para un conjunto de orders. +* +* @table tmp.order(orderFk) Identificadores de las ordenes a calcular +* @return tmp.orderTotal Total para cada order +*/ + CALL orderGetTax; + + DROP TEMPORARY TABLE IF EXISTS tmp.orderTotal; + CREATE TEMPORARY TABLE tmp.orderTotal + (INDEX (orderFk)) + ENGINE = MEMORY + SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total + FROM tmp.order o + LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk + GROUP BY orderFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; +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 `order_addItem` */; +/*!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 `order_addItem`( + vSelf INT, + vWarehouse INT, + vItem INT, + vAmount INT) +BEGIN + DECLARE vRow INT; + DECLARE vAdd INT; + DECLARE vAvailable INT; + DECLARE vDone BOOL; + DECLARE vGrouping INT; + DECLARE vRate INT; + DECLARE vShipment DATE; + DECLARE vPrice DECIMAL(10,2); + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; + DECLARE cur CURSOR FOR + SELECT `grouping`, price, rate + FROM tmp.bionic_price + WHERE warehouse_id = vWarehouse + AND item_id = vItem + ORDER BY `grouping` DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT date_send, address_id, agency_id + INTO vDate, vAddress, vAgencyMode + FROM `order` + WHERE id = vSelf; + + CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem); + + START TRANSACTION; + + SELECT shipped INTO vShipment + FROM tmp.travel_tree + WHERE warehouseFk = vWarehouse; + + SELECT available INTO vAvailable + FROM tmp.bionic_lot + WHERE warehouse_id = vWarehouse + AND item_id = vItem; + + IF vAmount > IFNULL(vAvailable, 0) + THEN + CALL util.throw ('ORDER_ROW_UNAVAILABLE'); + END IF; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + FETCH cur INTO vGrouping, vPrice, vRate; + + IF vDone THEN + LEAVE l; + END IF; + + SET vAdd = vAmount - MOD(vAmount, vGrouping); + SET vAmount = vAmount - vAdd; + + IF vAdd = 0 THEN + ITERATE l; + END IF; + + INSERT INTO order_row SET + order_id = vSelf, + item_id = vItem, + warehouse_id = vWarehouse, + shipment = vShipment, + rate = vRate, + amount = vAdd, + price = vPrice; + + SET vRow = LAST_INSERT_ID(); + + INSERT INTO order_component (order_row_id, component_id, price) + SELECT vRow, c.component_id, c.cost + FROM tmp.bionic_component c + JOIN bi.tarifa_componentes t + ON t.Id_Componente = c.component_id + AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate) + WHERE c.warehouse_id = vWarehouse + AND c.item_id = vItem; + END LOOP; + + CLOSE cur; + + IF vAmount > 0 + THEN + CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING'); + END IF; + + COMMIT; + CALL vn2008.bionic_free (); +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 `order_confirm` */; +/*!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 `order_confirm`(vSelf INT) +BEGIN +/** + * Confirms an order, creating each of its tickets on + * the corresponding date and store. + * + * @param vSelf The order identifier + */ + CALL order_confirmWithUser(vSelf, account.userGetId()); +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 `order_confirmWithUser` */; +/*!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 `order_confirmWithUser`(IN `vOrder` INT, IN `vUserId` INT) BEGIN /** * Confirms an order, creating each of its tickets on the corresponding @@ -13546,9 +13704,9 @@ BEGIN SELECT COUNT(*) > 0 INTO vOk FROM order_row WHERE order_id = vOrder AND amount > 0; - IF !vOk THEN + IF !vOk THEN CALL util.throw ('ORDER_EMPTY'); - END IF; + END IF; -- Carga las fechas de salida de cada almacén @@ -13710,157 +13868,50 @@ DELIMITER ; /*!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 `orderDelete` */; -/*!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 `orderDelete`(IN vId INT) -BEGIN - - DELETE FROM hedera.`order` where id = vId; - - 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 `orderGetTax` */; -/*!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 = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`() - READS SQL DATA -BEGIN -/** - * Calcula el IVA, y el recargo de equivalencia de un pedido - * desglosados por tipos. - * - * @param vOrder El identificador del pedido - * @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia - */ - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - CREATE TEMPORARY TABLE tmp.addressCompany - (INDEX (addressFk, companyFk)) - ENGINE = MEMORY - SELECT DISTINCT o.address_id addressFk, o.company_id companyFk - FROM tmp.order tmpOrder - JOIN hedera.order o ON o.id = tmpOrder.orderFk; - - CALL vn.addressTaxArea (); - - -- Calcula el IVA y el recargo desglosado. - DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; - CREATE TEMPORARY TABLE tmp.orderTax - (INDEX (orderFk)) - ENGINE = MEMORY - SELECT o.id orderFk, - tc.code, - SUM(m.amount * m.price) taxableBase, - pgc.rate - FROM tmp.order tmpOrder - JOIN `order` o ON o.id = tmpOrder.orderFk - JOIN orderRow m ON m.orderFk = o.id - JOIN vn.item i ON i.id = m.itemFk - JOIN vn.client c ON c.id = o.customer_id - JOIN vn.supplier s ON s.id = o.company_id - JOIN tmp.addressTaxArea ata - ON ata.addressFk = o.address_id AND ata.companyFk = o.company_id - JOIN vn.itemTaxCountry itc - ON itc.itemFk = i.id AND itc.countryFk = s.countryFk - JOIN vn.bookingPlanner bp - ON bp.countryFk = s.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = itc.taxClassFk - JOIN vn.pgc ON pgc.code = bp.pgcFk - JOIN vn.taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tmpOrder.orderFk, pgc.code,pgc.rate - HAVING taxableBase != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.orderAmount; - CREATE TEMPORARY TABLE tmp.orderAmount - (INDEX (orderFk)) - ENGINE = MEMORY - SELECT orderFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code - FROM tmp.orderTax - GROUP BY orderFk, code; - -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 `orderGetTotal` */; -/*!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 `orderGetTotal`() -BEGIN -/** -* Calcula el total con IVA para un conjunto de orders. -* -* @table tmp.order(orderFk) Identificadores de las ordenes a calcular -* @return tmp.orderTotal Total para cada order -*/ - CALL orderGetTax; - - DROP TEMPORARY TABLE IF EXISTS tmp.orderTotal; - CREATE TEMPORARY TABLE tmp.orderTotal - (INDEX (orderFk)) - ENGINE = MEMORY - SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total - FROM tmp.order o - LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk - GROUP BY orderFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; -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 `orderUpdate` */; +/*!50003 DROP PROCEDURE IF EXISTS `order_confirm_bionic` */; /*!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_unicode_ci */ ; +/*!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 `orderUpdate`(IN `vOrder` INT) +CREATE DEFINER=`root`@`%` PROCEDURE `order_confirm_bionic`(vSelf INT) +BEGIN +/** + * @deprecated Use order_confirm() + */ + CALL order_confirm(vSelf); +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 `order_update` */; +/*!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 `order_update`(vSelf INT) proc: BEGIN /** * Actualiza la líneas de un pedido. * - * @param vOrder Id del pedido + * @param vSelf Id del pedido */ DECLARE vDate DATE; DECLARE vAddress INT; DECLARE vAgency INT; DECLARE vNRows INT; - + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; @@ -13870,21 +13921,21 @@ proc: BEGIN START TRANSACTION; SELECT COUNT(*) INTO vNRows - FROM order_row WHERE order_id = vOrder; + FROM order_row WHERE order_id = vSelf; IF vNRows > 0 THEN SELECT date_send, address_id, agency_id INTO vDate, vAddress, vAgency FROM `order` - WHERE id = vOrder; + WHERE id = vSelf; - CALL vn2008.bionic_from_order (vDate, vAddress, vAgency, vOrder); + CALL vn2008.bionic_from_order (vDate, vAddress, vAgency, vSelf); DELETE c FROM order_row r JOIN order_component c ON c.order_row_id = r.id - WHERE r.order_id = vOrder; + WHERE r.order_id = vSelf; UPDATE order_row r LEFT JOIN tmp.bionic_price l @@ -13897,7 +13948,7 @@ proc: BEGIN r.price = l.price, r.amount = IF(l.item_id IS NOT NULL, r.amount + IF(@m := MOD(r.amount, l.`grouping`), l.`grouping` - @m, 0), 0), r.shipment = t.shipped - WHERE r.order_id = vOrder; + WHERE r.order_id = vSelf; INSERT INTO order_component (order_row_id, component_id, price) SELECT r.id, c.component_id, c.cost @@ -13908,11 +13959,11 @@ proc: BEGIN JOIN bi.tarifa_componentes t ON t.Id_Componente = c.component_id AND (t.tarifa_class IS NULL OR t.tarifa_class = r.rate) - WHERE r.order_id = vOrder; + WHERE r.order_id = vSelf; END IF; UPDATE `order` SET date_make = NOW() - WHERE id = vOrder; + WHERE id = vSelf; COMMIT; END ;; @@ -13921,57 +13972,31 @@ DELIMITER ; /*!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 `order_confirm_bionic` */; +/*!50003 DROP PROCEDURE IF EXISTS `survey_vote` */; /*!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 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 `order_confirm_bionic`(vOrder INT) -BEGIN -/** - * Confirma un pedido, creando cada uno de sus tickets en la fecha - * y almacén correspondientes. - * - * @deprecated Use orderConfirm() instead - * - * @param vOrder Identificador del pedido - */ - CALL orderConfirm (vOrder); -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 `surveyVote` */; -/*!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 `surveyVote`(vAnswer INT) +CREATE DEFINER=`root`@`%` PROCEDURE `survey_vote`(vAnswer INT) BEGIN DECLARE vSurvey INT; DECLARE vCount TINYINT; DECLARE EXIT HANDLER FOR 1062 - CALL util.throw ('SURVEY_MAX_ONE_VOTE'); + CALL util.throw('You cannot vote twice to the same survey'); - SELECT survey_id INTO vSurvey - FROM survey_answer WHERE id = vAnswer; + SELECT durveyFk INTO vSurvey + FROM surveyAnswer WHERE id = vAnswer; - INSERT INTO survey_vote - VALUES (vSurvey, account.userGetId()); + INSERT INTO surveyVote SET + surveyFk = vSurvey, + userFk = account.userGetId(); - UPDATE survey_answer SET votes = votes + 1 + UPDATE surveyAnswer SET votes = votes + 1 WHERE id = vAnswer; END ;; DELIMITER ; @@ -13979,17 +14004,61 @@ DELIMITER ; /*!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 `tpvTransactionConfirm` */; +/*!50003 DROP PROCEDURE IF EXISTS `tpvTransactionConfirmById` */; /*!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 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 `tpvTransactionConfirm`( +CREATE DEFINER=`root`@`%` PROCEDURE `tpvTransactionConfirmById`(vSelf INT) +BEGIN +/** + * @deprecated Use tpvTransaction_confirmById() + */ + CALL tpvTransaction_confirmById(vSelf); +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 `tpvTransactionUndo` */; +/*!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 `tpvTransactionUndo`(vSelf INT) +BEGIN +/** + * @deprecated Use tpvTransaction_undo() + */ + CALL tpvTransaction_undo(vSelf); +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 `tpvTransaction_confirm` */; +/*!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 `tpvTransaction_confirm`( vAmount INT ,vOrder INT ,vMerchant INT @@ -14108,17 +14177,17 @@ DELIMITER ; /*!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 `tpvTransactionConfirmAll` */; +/*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_confirmAll` */; /*!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 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 `tpvTransactionConfirmAll`(vDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `tpvTransaction_confirmAll`(vDate DATE) BEGIN /** * Confirma todas las transacciones confirmadas por el cliente pero no @@ -14149,7 +14218,7 @@ BEGIN LEAVE l; END IF; - CALL tpvTransactionConfirmById (vOrder); + CALL tpvTransaction_confirmById (vOrder); END LOOP l; CLOSE cTransactions; @@ -14159,17 +14228,17 @@ DELIMITER ; /*!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 `tpvTransactionConfirmById` */; +/*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_confirmById` */; /*!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 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 `tpvTransactionConfirmById`(vOrder INT) +CREATE DEFINER=`root`@`%` PROCEDURE `tpvTransaction_confirmById`(vOrder INT) BEGIN /** * Confirma manualmente una transacción espedificando su identificador. @@ -14187,7 +14256,7 @@ BEGIN JOIN tpvConfig c WHERE t.id = vOrder; - CALL tpvTransactionConfirm ( + CALL tpvTransaction_confirm( vAmount ,vOrder ,vMerchant @@ -14201,139 +14270,17 @@ DELIMITER ; /*!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 `tpvTransactionEnd` */; +/*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_undo` */; /*!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 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 `tpvTransactionEnd`(vTransaction INT, vStatus VARCHAR(12)) -BEGIN -/** - * Finaliza una transaccción estableciendo su estado a 'ok' o - * 'ko' en función de si esta se ha realizado correctamente. - * Este procedimiento debe ser llamado directamente por el cliente - * nada mas finalizar la transacción y solo tiene validez hasta que - * llega la notificacion definitiva desde el banco. - * - * @param vTransaction El identificador de la transacción - * @param vStatus El estado, 'ok' o 'ko' - */ - IF vStatus IN ('ok', 'ko') - THEN - UPDATE myTpvTransaction SET status = vStatus - WHERE id = vTransaction AND response IS NULL; - 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 `tpvTransactionStart` */; -/*!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 `tpvTransactionStart`(vAmount INT, vCompany INT) -BEGIN -/** - * Inicia una nueva transacción con el TPV virtual, generando - * un identificador de transacción y devolviendo con un SELECT - * los parámetros que deben enviarse a la URL del servicio web - * del banco. - * - * @param vAmount Cantidad a pagar en céntimos - * @param vCompany El identificador de la empresa - * - * @select Los parámetros que deben pasarse al banco - */ - DECLARE vTransaction CHAR(12); - DECLARE vMerchant INT; - DECLARE vUrl VARCHAR(255); - DECLARE vKey VARCHAR(50); - DECLARE vTestMode BOOLEAN; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - IF vCompany IS NULL - THEN - SELECT companyFk INTO vCompany - FROM tpvMerchantEnable LIMIT 1; - END IF; - - SELECT merchantFk INTO vMerchant - FROM tpvMerchantEnable WHERE companyFk = vCompany; - - SELECT testMode INTO vTestMode - FROM tpvConfig; - - IF NOT vTestMode - THEN - SELECT c.url, m.secretKey INTO vUrl, vKey - FROM tpvMerchant m - JOIN tpvConfig c - WHERE m.id = vMerchant; - ELSE - SELECT testUrl, testKey INTO vUrl, vKey - FROM tpvConfig; - END IF; - - INSERT INTO myTpvTransaction - SET - merchantFk = vMerchant - ,clientFk = account.userGetId() - ,amount = vAmount; - - SET vTransaction = LAST_INSERT_ID(); - - SELECT - vAmount amount - ,vTransaction transactionId - ,vMerchant merchant - ,currency - ,transactionType - ,terminal - ,merchantUrl - ,vUrl url - ,vKey secretKey - FROM tpvConfig; - - COMMIT; -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 `tpvTransactionUndo` */; -/*!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 `tpvTransactionUndo`( - vOrder INT -) +CREATE DEFINER=`root`@`%` PROCEDURE `tpvTransaction_undo`(vSelf INT) BEGIN DECLARE vCustomer INT; DECLARE vAmount DOUBLE; @@ -14366,7 +14313,7 @@ BEGIN FROM tpvTransaction t JOIN tpvMerchant m ON m.id = t.merchantFk JOIN tpvConfig c - WHERE t.id = vOrder + WHERE t.id = vSelf FOR UPDATE; -- Elimina el recibo @@ -14408,7 +14355,7 @@ BEGIN UPDATE tpvTransaction SET response = NULL, status = 'started' - WHERE id = vOrder; + WHERE id = vSelf; COMMIT; END ;; @@ -14417,17 +14364,51 @@ DELIMITER ; /*!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 `visitRegister` */; +/*!50003 DROP PROCEDURE IF EXISTS `visitUser_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 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 `visitRegister`( +CREATE DEFINER=`root`@`%` PROCEDURE `visitUser_new`( + vAccess INT + ,vSsid VARCHAR(64) +) +BEGIN + DECLARE vUserVisit INT; + + INSERT INTO visitUser SET + access = vAccess, + user = account.userGetId(); + + SET vUserVisit = LAST_INSERT_ID(); + + UPDATE userSession SET userVisit = vUserVisit + WHERE ssid = vSsid; + + DELETE FROM userSession + WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, NOW()); +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 `visit_register` */; +/*!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 `visit_register`( vVisit INT ,vPlatform VARCHAR(30) ,vBrowser VARCHAR(30) @@ -14505,257 +14486,176 @@ DELIMITER ; /*!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 `visitUserNew` */; +/*!50003 DROP PROCEDURE IF EXISTS `__bionic_from_basket` */; /*!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 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 `visitUserNew`( - vAccess INT - ,vSsid VARCHAR(64) -) +CREATE DEFINER=`root`@`%` PROCEDURE `__bionic_from_basket`() BEGIN - DECLARE vUserVisit INT; - - INSERT INTO visitUser SET - access = vAccess, - user = account.userGetId(); - - SET vUserVisit = LAST_INSERT_ID(); + DECLARE vOrder INT; + DECLARE vDate DATE; + DECLARE vAddress INT; + DECLARE vAgencyMode INT; - UPDATE userSession SET userVisit = vUserVisit - WHERE ssid = vSsid; + SELECT id, sent, addressFk, agencyModeFk + INTO vOrder, vDate, vAddress, vAgencyMode + FROM myBasket; - DELETE FROM userSession - WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, NOW()); + CALL vn2008.bionic_from_order(vDate, vAddress, vAgencyMode, vOrder); 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 `__orderConfirmWithUser` */; +/*!50003 DROP PROCEDURE IF EXISTS `__catalog_getAvailable` */; /*!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_unicode_ci */ ; +/*!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 `__orderConfirmWithUser`(vOrder INT, vUserId INT) +CREATE DEFINER=`root`@`%` PROCEDURE `__catalog_getAvailable`() +BEGIN +/** + * Gets the available items list that meets the tag filter. + * + * @table tItems + */ + CALL itemGetAvailable; + + DELETE t FROM tItems t + JOIN tmp.itemAvailable a ON a.id = t.id + WHERE a.id IS NULL; + + DROP TEMPORARY TABLE tmp.itemAvailable; +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 `__catalog_getItems` */; +/*!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 `__catalog_getItems`() +BEGIN +/** + * Returns the list of items. + * + * @table tItems The list of items + * @select The list of items + */ + DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; + CREATE TEMPORARY TABLE tmp.bionic_calc + (INDEX (item_id)) + ENGINE = MEMORY + SELECT id item_id FROM tItems; + + CALL bionic_calc (); + DROP TEMPORARY TABLE tmp.bionic_calc; + + SELECT i.id, i.name, i.description, i.category, i.size, i.image, i.inkFk, + IF(i.stems > 1, i.stems, NULL) stems, b.available, b.price, b.producer, + a.tag1, a.val1, a.tag2, a.val2, a.tag3, a.val3 + FROM tmp.bionic_item b + JOIN vn.item i ON i.id = b.item_id + LEFT JOIN vn.itemTagArranged a ON a.itemFk = i.id + LEFT JOIN vn.producer p ON p.id = i.producerFk + WHERE b.available > 0 + ORDER BY i.relevancy DESC, i.name, i.size + LIMIT 40; +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 `__myTicketSetDelivered` */; +/*!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 `__myTicketSetDelivered`(vTicketFk INT) +BEGIN + + UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1061'); + UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1121'); + UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1134'); + UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1148'); + UPDATE `vn2008`.`agency_hour` SET `subtract_day` = '0' WHERE (`agency_hour_id` = '1920'); + + IF vTicketFk is null THEN + call util.throw ('AGENCIA ACTUALIZADA'); + END IF; + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT s.id, vTicketFk, vn.getWorker() + FROM vn.state s + JOIN myTicket m ON m.id = vTicketFk + WHERE `code` = 'DELIVERED' AND m.id = vTicketFk; +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 `__orderDelete` */; +/*!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 `__orderDelete`(vSelf INT) +BEGIN + DELETE FROM `order` where id = vSelf; +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 `__orderUpdate` */; +/*!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 `__orderUpdate`(vSelf INT) BEGIN - - 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; - - - 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; - - - IF vIsConfirmed THEN - CALL util.throw ('ORDER_ALREADY_CONFIRMED'); - END IF; - - - 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; - - - CALL vn.agencyHourGetShipped (vDelivery, vAddress, vAgency); - - - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - - - START TRANSACTION; - - OPEN cDates; - - lDates: - LOOP - SET vTicket = NULL; - SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; - - IF vDone THEN - LEAVE lDates; - END IF; - - - 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; - - - 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; - - - IF vNotes IS NOT NULL AND vNotes != '' - THEN - INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text) - VALUES (vTicket, 4 , vNotes) - ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text); - END IF; - - - 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; - - - 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; - +/** + * @deprecated Use order_update() + */ + CALL order_update(vSelf); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -14872,71 +14772,58 @@ BEGIN CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); CALL util.exec(CONCAT( 'CREATE TEMPORARY TABLE tmp.', vTableClone, - ' ENGINE = MEMORY' + ' ENGINE = MEMORY', ' SELECT * FROM ', vScheme, '.', vTable )); - - - SET vSql = sql_printf(' - SELECT COUNT(c.id) INTO @childs - FROM %t.%t p - LEFT JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt AND c.id != %v - WHERE p.id = %v', - vScheme, vTable, 'tmp', vTableClone, vParentFk, vParentFk); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; + CALL util.exec(CONCAT( + 'SELECT COUNT(c.id) INTO @childs', + ' FROM ', vScheme, '.', vTable, ' p', + ' LEFT JOIN tmp.', vTableClone, ' c ON c.lft', + ' BETWEEN p.lft AND p.rgt AND c.id != ', vParentFk, + ' WHERE p.id = ', vParentFk + )); IF @childs = 0 THEN - SET vSql = sql_printf('SELECT lft INTO @vLeft FROM %t.%t WHERE id = %v', vScheme, vTable, vParentFk); - SET @qrySql := vSql; - ELSE - SET vSql = sql_printf(' - SELECT c.rgt INTO @vLeft - FROM %t.%t p - JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt - WHERE p.id = %v - ORDER BY c.lft - DESC LIMIT 1', - vScheme, vTable, 'tmp', vTableClone, vParentFk); - SET @qrySql := vSql; + CALL util.exec(CONCAT( + 'SELECT lft INTO @vLeft', + ' FROM ', vScheme, '.', vTable, + ' WHERE id = ', vParentFk + )); + ELSE + CALL util.exec(CONCAT( + 'SELECT c.rgt INTO @vLeft', + ' FROM ', vScheme, '.', vTable, ' p', + ' JOIN tmp.', vTableClone, ' c ON c.lft BETWEEN p.lft AND p.rgt', + ' WHERE p.id = ', vParentFk, + ' ORDER BY c.lft', + ' DESC LIMIT 1' + )); END IF; - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - - SET vSql = sql_printf('UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC', vScheme, vTable, @vLeft); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - SET vSql = sql_printf('UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC', vScheme, vTable, @vLeft); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - + CALL util.exec(CONCAT( + 'UPDATE ', vScheme, '.', vTable, ' SET rgt = rgt + 2', + ' WHERE rgt > @vLeft', + ' ORDER BY rgt DESC' + )); + CALL util.exec(CONCAT( + 'UPDATE ', vScheme, '.', vTable, ' SET lft = lft + 2', + ' WHERE lft > @vLeft', + ' ORDER BY lft DESC' + )); SET vChild = REPLACE(vChild, "'", "\\'"); + CALL util.exec(CONCAT( + 'INSERT INTO ', vScheme, '.', vTable, ' (name, lft, rgt)', + ' VALUES ("', vChild, '", @vLeft + 1, @vLeft + 2)' + )); - SET vSql = sql_printf('INSERT INTO %t.%t (name, lft, rgt) VALUES (%v, %v, %v)', vScheme, vTable, vChild, @vLeft + 1, @vLeft + 2); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - SELECT id, name, lft, rgt, depth, sons FROM vn.department - WHERE id = LAST_INSERT_ID(); + CALL util.exec(CONCAT( + 'SELECT id, name, lft, rgt, depth, sons', + ' FROM ', vScheme, '.', vTable, + ' WHERE id = LAST_INSERT_ID()' + )); CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); END ;; @@ -14961,29 +14848,26 @@ BEGIN DECLARE vMyLeft INT; DECLARE vMyWidth INT; - CALL util.exec (sql_printf ( - 'SELECT t.rgt, t.lft, t.rgt - t.lft + 1 INTO @vMyRight, @vMyLeft, @vMyWidth FROM %t.%t t WHERE t.id = %v' - ,vScheme - ,vTable - ,vNodeId - )); - - CALL util.exec (sql_printf ( - 'DELETE FROM %t.%t WHERE lft BETWEEN @vMyLeft AND @vMyRight' - ,vScheme - ,vTable + CALL util.exec(CONCAT( + 'SELECT t.rgt, t.lft, t.rgt - t.lft + 1', + ' INTO @vMyRight, @vMyLeft, @vMyWidth', + ' FROM ', vScheme, '.', vTable, ' t', + ' WHERE t.id = ', vNodeId )); - CALL util.exec (sql_printf ( - 'UPDATE %t.%t SET rgt = rgt - @vMyWidth WHERE rgt > @vMyRight ORDER BY rgt' - ,vScheme - ,vTable + CALL util.exec(CONCAT( + 'DELETE FROM ', vScheme, '.', vTable, + ' WHERE lft BETWEEN @vMyLeft AND @vMyRight' )); - CALL util.exec (sql_printf ( - 'UPDATE %t.%t SET lft = lft - @vMyWidth WHERE lft > @vMyRight ORDER BY lft' - ,vScheme - ,vTable + CALL util.exec(CONCAT( + 'UPDATE ', vScheme, '.', vTable, ' SET rgt = rgt - @vMyWidth' + ' WHERE rgt > @vMyRight ORDER BY rgt' + )); + + CALL util.exec(CONCAT( + 'UPDATE ', vScheme, '.', vTable, ' SET lft = lft - @vMyWidth' + ' WHERE lft > @vMyRight ORDER BY lft' )); END ;; DELIMITER ; @@ -15086,25 +14970,19 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45)) BEGIN - CALL util.exec (sql_printf ( - 'UPDATE %t.%t d - JOIN (SELECT - node.id, - COUNT(parent.id) - 1 as depth, - cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons - FROM - %t.%t AS node, - %t.%t AS parent - WHERE node.lft BETWEEN parent.lft AND parent.rgt - GROUP BY node.id - ORDER BY node.lft) n ON n.id = d.id - SET d.`depth` = n.depth, d.sons = n.sons', - vScheme, - vTable, - vScheme, - vTable, - vScheme, - vTable + CALL util.exec(CONCAT ( + 'UPDATE ', vScheme, '.', vTable, ' d', + ' JOIN (SELECT', + ' node.id,', + ' COUNT(parent.id) - 1 as depth,', + ' cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons', + ' FROM ', + ' ', vScheme, '.', vTable, ' AS node,', + ' ', vScheme, '.', vTable, ' AS parent', + ' WHERE node.lft BETWEEN parent.lft AND parent.rgt', + ' GROUP BY node.id', + ' ORDER BY node.lft) n ON n.id = d.id ', + ' SET d.`depth` = n.depth, d.sons = n.sons' )); END ;; DELIMITER ; @@ -15295,7 +15173,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=InnoDB AUTO_INCREMENT=273159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=277508 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16057,7 +15935,7 @@ CREATE TABLE `address` ( KEY `address_town_id_idx` (`town_id`), CONSTRAINT `address_ibfk_1` FOREIGN KEY (`address_type_id`) REFERENCES `address_type` (`address_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `address_ibfk_2` FOREIGN KEY (`town_id`) REFERENCES `town` (`town_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=801 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=803 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16103,7 +15981,7 @@ CREATE TABLE `bank_account` ( CONSTRAINT `bank_account_bank_account_type_id_fkey` FOREIGN KEY (`bank_account_type_id`) REFERENCES `bank_account_type` (`bank_account_type_id`) ON UPDATE CASCADE, CONSTRAINT `bank_account_nation_id_fkey` FOREIGN KEY (`nation_id`) REFERENCES `nation` (`nation_id`) ON UPDATE CASCADE, CONSTRAINT `bank_profile` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=796 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=799 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16158,7 +16036,7 @@ CREATE TABLE `business` ( KEY `bussiness_provider` (`provider_id`), CONSTRAINT `business_client` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `bussiness_provider` FOREIGN KEY (`provider_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2463 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=2481 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16330,6 +16208,25 @@ CREATE TABLE `currency` ( ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `currentWorkersStats` +-- + +DROP TABLE IF EXISTS `currentWorkersStats`; +/*!50001 DROP VIEW IF EXISTS `currentWorkersStats`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `currentWorkersStats` AS SELECT + 1 AS `business_id`, + 1 AS `sex`, + 1 AS `name`, + 1 AS `firstname`, + 1 AS `department`, + 1 AS `category_name`, + 1 AS `level_name`, + 1 AS `salarioMedio`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `income_employee` -- @@ -16350,7 +16247,7 @@ CREATE TABLE `income_employee` ( KEY `fperson_id` (`person_id`), CONSTRAINT `fincometype_id` FOREIGN KEY (`id_incomeType`) REFERENCES `incometype_employee` (`id_incometype`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fperson_id` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=63742 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=63753 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16377,14 +16274,14 @@ DROP TABLE IF EXISTS `journey`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `journey` ( `journey_id` int(11) NOT NULL AUTO_INCREMENT, - `day_id` smallint(6) NOT NULL DEFAULT '1', + `day_id` smallint(6) NOT NULL DEFAULT '1' COMMENT 'Lunes = 1 \nDomingo = 7', `start` time DEFAULT NULL, `end` time DEFAULT NULL, `business_id` int(11) NOT NULL, PRIMARY KEY (`journey_id`), KEY `fki_business_journey` (`business_id`), CONSTRAINT `business_journey` FOREIGN KEY (`business_id`) REFERENCES `business_labour` (`business_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1364 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=1505 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16420,7 +16317,7 @@ CREATE TABLE `media` ( PRIMARY KEY (`media_id`), KEY `media_media_type_id_idx` (`media_type_id`), CONSTRAINT `media_ibfk_1` FOREIGN KEY (`media_type_id`) REFERENCES `media_type` (`media_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=990 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=998 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16500,7 +16397,7 @@ CREATE TABLE `person` ( UNIQUE KEY `nis_UNIQUE` (`nis`), KEY `index1` (`person_id`,`name`,`nickname`,`firstname`), KEY `person_worker` (`id_trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=1031 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=1033 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16518,7 +16415,7 @@ CREATE TABLE `professional_category` ( `holiday_days` decimal(3,1) DEFAULT NULL, PRIMARY KEY (`professional_category_id`), UNIQUE KEY `professional_category_name_category_key` (`category_name`) -) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16551,7 +16448,7 @@ CREATE TABLE `profile` ( KEY `profile_person_id_idx` (`person_id`), KEY `profile_profile_type_id_idx` (`profile_type_id`), CONSTRAINT `person_fk` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=910 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=912 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16568,7 +16465,7 @@ CREATE TABLE `profile_address` ( PRIMARY KEY (`profile_address_id`), KEY `profile_address_address_id_idx` (`address_id`), KEY `profile_address_profile_id_idx` (`profile_id`) -) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=140 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16587,7 +16484,7 @@ CREATE TABLE `profile_media` ( KEY `profile_media_profile_id_idx` (`profile_id`), CONSTRAINT `fk_profile_media_media1` FOREIGN KEY (`media_id`) REFERENCES `media` (`media_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `media_ibfk_20` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`profile_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1142 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=1150 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16705,7 +16602,7 @@ CREATE TABLE `ACL` ( `principalType` set('ROLE','USER') COLLATE utf8_unicode_ci DEFAULT 'ROLE', `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16825,7 +16722,7 @@ CREATE TABLE `userConfigView` ( `configuration` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `uniqueUser_TableCode` (`userFk`,`tableCode`) -) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -16895,42 +16792,36 @@ DELIMITER ; -- Current Database: `stock` -- -CREATE DATABASE /*!32312 IF NOT EXISTS*/ `stock` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */; +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `stock` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `stock`; -- --- Table structure for table `buy` +-- Table structure for table `inbound` -- -DROP TABLE IF EXISTS `buy`; +DROP TABLE IF EXISTS `inbound`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `buy` ( - `isSync` tinyint(1) NOT NULL DEFAULT '0', - `buyFk` int(10) unsigned NOT NULL, - `entryFk` int(10) unsigned NOT NULL, - `travelFk` int(10) unsigned NOT NULL, +CREATE TABLE `inbound` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `tableName` set('buy','sale') NOT NULL, + `tableId` int(10) unsigned NOT NULL, + `isSync` tinyint(4) NOT NULL, + `isPicked` tinyint(4) NOT NULL DEFAULT '0', + `warehouseFk` int(10) unsigned NOT NULL, `itemFk` int(10) unsigned NOT NULL, - `shipped` datetime DEFAULT NULL, - `warehouseOutFk` smallint(6) unsigned DEFAULT NULL, - `isDelivered` tinyint(1) NOT NULL DEFAULT '0', - `landed` datetime DEFAULT NULL, - `warehouseInFk` smallint(6) unsigned DEFAULT NULL, - `isReceived` tinyint(1) NOT NULL DEFAULT '0', - `isRaid` tinyint(1) NOT NULL DEFAULT '0', + `dated` datetime NOT NULL, `expired` datetime DEFAULT NULL, - `quantity` int(11) NOT NULL DEFAULT '0', + `quantity` int(10) unsigned NOT NULL, `available` int(10) unsigned DEFAULT NULL, - `lack` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`buyFk`), - KEY `itemFk` (`itemFk`,`warehouseInFk`,`expired`,`landed`,`available`) USING BTREE, - KEY `itemFkOut` (`itemFk`,`warehouseOutFk`,`shipped`) USING BTREE, - KEY `isSync` (`isSync`), - KEY `entryFk` (`entryFk`), - KEY `travelFk` (`travelFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + PRIMARY KEY (`id`), + UNIQUE KEY `source` (`tableName`,`tableId`), + KEY `warehouseFk` (`warehouseFk`,`itemFk`,`dated`,`expired`,`available`), + KEY `isSync` (`isSync`) +) ENGINE=InnoDB AUTO_INCREMENT=2048 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -16940,19 +16831,17 @@ CREATE TABLE `buy` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_afterInsert` - AFTER INSERT ON `buy` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`inbound_beforeInsert` + BEFORE INSERT ON `inbound` + FOR EACH ROW BEGIN - CALL visible_logBuy( - NEW.itemFk, - NEW.quantity, - NEW.isRaid, - NEW.warehouseInFk, - NEW.landed, - NEW.isReceived, - NEW.warehouseOutFk, - NEW.shipped, - NEW.isDelivered + SET NEW.isPicked = NEW.isPicked OR NEW.dated < CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, + NEW.itemFk, + NEW.quantity ); END */;; DELIMITER ; @@ -16960,6 +16849,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -16969,23 +16859,25 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`buy_beforeDelete` - BEFORE DELETE ON `buy` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`inbound_afterDelete` + AFTER DELETE ON `inbound` + FOR EACH ROW BEGIN - CALL visible_logBuy( - OLD.itemFk, - -OLD.quantity, - OLD.isRaid, - OLD.warehouseInFk, - OLD.landed, - OLD.isReceived, - OLD.warehouseOutFk, - OLD.shipped, - OLD.isDelivered - ); + UPDATE outbound o + JOIN inboundOut ou ON ou.outboundFk = o.id + SET o.lack = o.lack + ou.quantity, + o.isSync = FALSE + WHERE ou.inboundFk = OLD.id; - UPDATE buySale SET buyFk = NULL - WHERE buyFk = OLD.buyFk; + DELETE FROM inboundOut + WHERE inboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + -OLD.quantity + ); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -16994,35 +16886,19 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- --- Table structure for table `buyOut` +-- Table structure for table `inboundOut` -- -DROP TABLE IF EXISTS `buyOut`; +DROP TABLE IF EXISTS `inboundOut`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `buyOut` ( - `buyFk` int(10) unsigned NOT NULL, - `buyOutFk` int(10) unsigned NOT NULL, - `quantity` int(10) NOT NULL, - PRIMARY KEY (`buyFk`,`buyOutFk`), - KEY `outBuyFk` (`buyOutFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `buySale` --- - -DROP TABLE IF EXISTS `buySale`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `buySale` ( - `buyFk` int(10) unsigned DEFAULT NULL, - `saleFk` int(10) unsigned DEFAULT NULL, +CREATE TABLE `inboundOut` ( + `inboundFk` int(10) unsigned DEFAULT NULL, + `outboundFk` int(10) unsigned DEFAULT NULL, `quantity` int(11) NOT NULL, - UNIQUE KEY `buyFk` (`buyFk`,`saleFk`), - KEY `saleFk` (`saleFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + UNIQUE KEY `buyFk` (`inboundFk`,`outboundFk`), + KEY `saleFk` (`outboundFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -17037,35 +16913,53 @@ CREATE TABLE `log` ( `operation` set('insert','delete') NOT NULL, `tableName` varchar(255) NOT NULL, `tableId` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + PRIMARY KEY (`id`), + UNIQUE KEY `tableName` (`tableName`,`tableId`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `sale` +-- Table structure for table `logLock` -- -DROP TABLE IF EXISTS `sale`; +DROP TABLE IF EXISTS `logLock`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `sale` ( - `isSync` tinyint(1) NOT NULL DEFAULT '0', - `saleFk` int(10) unsigned NOT NULL, - `ticketFk` int(10) unsigned NOT NULL, - `itemFk` int(10) unsigned NOT NULL, - `warehouseFk` smallint(6) unsigned NOT NULL, - `shipped` datetime NOT NULL, - `isPicked` tinyint(1) NOT NULL DEFAULT '0', - `quantity` int(11) NOT NULL DEFAULT '0', - `created` datetime NOT NULL, - `lack` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`saleFk`), - KEY `isSync` (`isSync`), - KEY `ticketFk` (`ticketFk`), - KEY `created` (`created`), - KEY `itemFk` (`itemFk`,`warehouseFk`,`shipped`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +CREATE TABLE `logLock` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `connectionId` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `outbound` +-- + +DROP TABLE IF EXISTS `outbound`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `outbound` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `tableName` set('sale','buy','orderRow') NOT NULL, + `tableId` int(10) unsigned NOT NULL, + `isSync` tinyint(3) unsigned NOT NULL, + `isPicked` tinyint(4) NOT NULL DEFAULT '0', + `warehouseFk` int(10) unsigned NOT NULL, + `itemFk` int(10) unsigned NOT NULL, + `dated` datetime NOT NULL, + `created` datetime NOT NULL, + `expired` datetime DEFAULT NULL, + `quantity` int(10) unsigned NOT NULL, + `lack` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `source` (`tableName`,`tableId`), + KEY `warehouseFk` (`warehouseFk`,`itemFk`,`dated`), + KEY `expired` (`expired`), + KEY `isSync` (`isSync`) +) ENGINE=InnoDB AUTO_INCREMENT=131071 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17075,15 +16969,18 @@ CREATE TABLE `sale` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`sale_afterInsert` - AFTER INSERT ON `sale` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`outbound_beforeInsert` + BEFORE INSERT ON `outbound` + FOR EACH ROW BEGIN - CALL visible_log( - NEW.warehouseFk, + SET NEW.lack = NEW.quantity; + SET NEW.isPicked = NEW.isPicked OR NEW.dated < CURDATE(); + + CALL visible_log( + NEW.isPicked, + NEW.warehouseFk, NEW.itemFk, - -NEW.quantity, - NEW.shipped, - NEW.isPicked + -NEW.quantity ); END */;; DELIMITER ; @@ -17091,6 +16988,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17100,19 +16998,25 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`sale_beforeDelete` - BEFORE DELETE ON `sale` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `stock`.`outbound_afterDelete` + AFTER DELETE ON `outbound` + FOR EACH ROW BEGIN - CALL visible_log( - OLD.warehouseFk, - OLD.itemFk, - OLD.quantity, - OLD.shipped, - OLD.isPicked - ); + UPDATE inbound i + JOIN inboundOut ou ON ou.inboundFk = i.id + SET i.available = i.available + ou.quantity, + i.isSync = FALSE + WHERE ou.outboundFk = OLD.id; - UPDATE buySale SET saleFk = NULL - WHERE saleFk = OLD.saleFk; + DELETE FROM inboundOut + WHERE outboundFk = OLD.id; + + CALL visible_log( + OLD.isPicked, + OLD.warehouseFk, + OLD.itemFk, + OLD.quantity + ); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -17132,14 +17036,14 @@ CREATE TABLE `visible` ( `warehouseFk` int(10) unsigned NOT NULL, `quantity` int(11) NOT NULL, PRIMARY KEY (`itemFk`,`warehouseFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping events for database 'stock' -- /*!50106 SET @save_time_zone= @@TIME_ZONE */ ; -/*!50106 DROP EVENT IF EXISTS `log_pop` */; +/*!50106 DROP EVENT IF EXISTS `log_syncNoWait` */; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; /*!50003 SET @saved_cs_results = @@character_set_results */ ;; @@ -17151,7 +17055,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `log_pop` ON SCHEDULE EVERY 10 SECOND STARTS '2017-06-27 17:15:02' ON COMPLETION NOT PRESERVE DISABLE DO CALL log_pop */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `log_syncNoWait` ON SCHEDULE EVERY 5 SECOND STARTS '2017-06-27 17:15:02' ON COMPLETION NOT PRESERVE ENABLE DO CALL log_syncNoWait */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -17163,7 +17067,8 @@ DELIMITER ; -- -- Dumping routines for database 'stock' -- -/*!50003 DROP PROCEDURE IF EXISTS `buySale_apply` */; +/*!50003 DROP PROCEDURE IF EXISTS `inboundOut_apply` */; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17173,32 +17078,33 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `buySale_apply`( - `vBuyFk` INT, - `vSaleFk` INT, +CREATE DEFINER=`root`@`%` PROCEDURE `inboundOut_apply`( + `vInboundFk` INT, + `vOutboundFk` INT, `vQuantity` INT) BEGIN /** * Deletes a row. * - * @param vSaleFk The sale identifier - * @param vBuyFk The buy identifier date + * @param vInboundFk The inbound identifier + * @param vOutboundFk The outbound identifier * @param vQuantity The quantity to discount */ - UPDATE buy + UPDATE inbound SET available = available - vQuantity - WHERE buyFk = vBuyFk; + WHERE id = vInboundFk; - UPDATE sale + UPDATE outbound SET lack = lack - vQuantity - WHERE saleFk = vSaleFk; + WHERE id = vOutboundFk; 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 `buy_attach` */; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; +/*!50003 DROP PROCEDURE IF EXISTS `inbound_requestQuantity` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17208,146 +17114,173 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `buy_attach`(`vBuyFk` INT) -BEGIN -/** - * Associates a buy with their possible sales, updating it's available. - * - * @param vBuyFk The buy identifier - */ - DECLARE vLanded DATETIME; +CREATE DEFINER=`root`@`%` PROCEDURE `inbound_requestQuantity`( + vSelf INT, + vRequested INT, + vDated DATETIME, + OUT vGranted INT) +BEGIN +/** + * Requests a quantity from an inbound to fulfill an outbound. + * If the demanded quantity exceeds the available, it also + * disassociates it's outbounds after the given date until the + * demanded quantity is satisfied or there is no more available. + * + * @param vSelf The inbound reference + * @param vRequested The requested quantity + * @param vDate The starting date for the associated outbounds + * @param vGranted The granted quantity + */ + DECLARE vQuantity INT; + DECLARE vAvailable INT; + DECLARE vOutboundFk INT; + DECLARE vLinkQuantity INT; + DECLARE vLinkGranted INT; + DECLARE vDone BOOL; + + DECLARE cInboundOuts CURSOR FOR + SELECT ou.outboundFk, ou.quantity + FROM inboundOut ou + JOIN outbound o ON o.id = ou.outboundFk + WHERE ou.inboundFk = vSelf + AND o.dated > vDated + ORDER BY o.dated DESC, o.created DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT quantity, available INTO vQuantity, vAvailable + FROM inbound + WHERE id = vSelf; + + SET vGranted = LEAST(vRequested, vAvailable); + + IF vGranted < vRequested AND vAvailable < vQuantity THEN + OPEN cInboundOuts; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cInboundOuts INTO vOutboundFk, vLinkQuantity; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vLinkGranted = LEAST(vRequested - vGranted, vLinkQuantity); + SET vGranted = vGranted + vLinkGranted; + + IF vLinkGranted < vLinkQuantity THEN + UPDATE inboundOut + SET quantity = quantity - vLinkGranted + WHERE outboundFk = vOutboundFk AND inboundFk = vSelf; + ELSE + DELETE FROM inboundOut + WHERE outboundFk = vOutboundFk AND inboundFk = vSelf; + END IF; + + UPDATE outbound SET isSync = FALSE + WHERE id = vOutboundFk; + + CALL inboundOut_apply(vOutboundFk, vSelf, -vLinkGranted); + + IF vGranted >= vRequested THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE cInboundOuts; + 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 `inbound_sync` */; +/*!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 `inbound_sync`(vSelf INT) +BEGIN +/** + * Associates a inbound with their possible outbounds, updating it's available. + * + * @param vSelf The inbound identifier + */ + DECLARE vDated DATETIME; DECLARE vExpired DATETIME; - DECLARE vItem INT; + DECLARE vItem INT; DECLARE vWarehouse INT; - DECLARE vQuantity INT; - DECLARE vAvailable INT; - DECLARE vSaleFk INT; - DECLARE vRest INT; - DECLARE vDone BOOL; - - DECLARE cSales CURSOR FOR - SELECT saleFk - FROM sale - WHERE shipped >= vLanded - AND (vExpired IS NULL OR shipped <= vExpired) - AND warehouseFk = vWarehouse - AND itemFk = vItem - ORDER BY created; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SELECT warehouseInFk, itemFk, available, quantity, expired, landed - INTO vWarehouse, vItem, vAvailable, vQuantity, vExpired, vLanded - FROM buy - WHERE buyFk = vBuyFk; + DECLARE vQuantity INT; + DECLARE vAvailable INT; + DECLARE vOutboundFk INT; + DECLARE vGranted INT; + DECLARE vDone BOOL; + + DECLARE cOutbound CURSOR FOR + SELECT id + FROM outbound + WHERE warehouseFk = vWarehouse + AND itemFk = vItem + AND dated >= vDated + AND (vExpired IS NULL OR dated < vExpired) + ORDER BY dated, created; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT warehouseFk, itemFk, available, quantity, expired, dated + INTO vWarehouse, vItem, vAvailable, vQuantity, vExpired, vDated + FROM inbound + WHERE id = vSelf; IF vAvailable IS NULL THEN SET vAvailable = vQuantity; - UPDATE buy SET available = vQuantity - WHERE buyFk = vBuyFk; - END IF; - - OPEN cSales; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cSales INTO vSaleFk; - - IF vDone THEN - LEAVE myLoop; - END IF; - - CALL sale_detachAfterDate(vSaleFk, vLanded, vAvailable, vRest); - - IF vRest > 0 THEN - SET vAvailable = vAvailable - vRest; - - INSERT INTO buySale - SET - buyFk = vBuyFk, - saleFk = vSaleFk, - quantity = vRest - ON DUPLICATE KEY UPDATE - quantity = quantity + vRest; - - CALL buySale_apply(vBuyFk, vSaleFk, vRest); - END IF; - - IF vAvailable <= 0 THEN - LEAVE myLoop; - END IF; - END LOOP; - - CLOSE cSales; -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 `buy_refresh` */; -/*!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 `buy_refresh`( - `vOperation` VARCHAR(255), - `vTableName` VARCHAR(255), - `vTableId` INT) -proc: BEGIN - IF vTableId IS NOT NULL THEN - DELETE FROM buy - WHERE (vTableName = 'travel' AND travelFk = vTableId) - OR (vTableName = 'entry' AND entryFk = vTableId) - OR (vTableName = 'buy' AND buyFk = vTableId); - END IF; - - IF vOperation != 'insert' THEN - LEAVE proc; + UPDATE inbound SET available = vQuantity + WHERE id = vSelf; END IF; - REPLACE INTO buy ( - buyFk, entryFk, travelFk, itemFk, - shipped, warehouseOutFk, isDelivered, - landed, warehouseInFk, isReceived, - isRaid, expired, quantity, lack - ) - SELECT - b.id buyFk, - e.id entryFk, - t.id travelFk, - b.itemFk, - ADDTIME(t.shipped, - IFNULL(t.shipmentHour, '00:00:00')) shipped, - t.warehouseOutFk, - t.isDelivered != FALSE isDelivered, - @landed := ADDTIME(t.landed, - IFNULL(t.landingHour, '00:00:00')) landed, - t.warehouseInFk, - t.isReceived != FALSE isReceived, - e.isRaid != FALSE isRaid, - TIMESTAMPADD(DAY, tp.life, @landed) expired, - b.quantity, - GREATEST(0, b.quantity) lack - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.item i ON i.id = b.itemFk - JOIN vn.itemType tp ON tp.id = i.typeFk - WHERE ( - vTableId IS NULL - OR (vTableName = 'travel' AND t.id = vTableId) - OR (vTableName = 'entry' AND e.id = vTableId) - OR (vTableName = 'buy' AND b.id = vTableId) - ) - AND t.landed >= vn.getInventoryDate() - AND b.quantity != 0; + OPEN cOutbound; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cOutbound INTO vOutboundFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL outbound_requestQuantity(vOutboundFk, vAvailable, vDated, vGranted); + + IF vGranted > 0 THEN + SET vAvailable = vAvailable - vGranted; + + INSERT INTO inboundOut + SET + inboundFk = vSelf, + outboundFk = vOutboundFk, + quantity = vGranted + ON DUPLICATE KEY UPDATE + quantity = quantity + vGranted; + + CALL inboundOut_apply(vSelf, vOutboundFk, vGranted); + END IF; + + IF vAvailable <= 0 THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE cOutbound; + + UPDATE inbound SET isSync = TRUE + WHERE id = vSelf; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -17360,24 +17293,28 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!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 `log_add`(IN `vTableName` VARCHAR(255), IN `vNewId` VARCHAR(255), IN `vOldId` VARCHAR(255)) +CREATE DEFINER=`root`@`%` PROCEDURE `log_add`( + vTableName VARCHAR(255), + vNewId VARCHAR(255), + vOldId VARCHAR(255) +) proc: BEGIN -- XXX: Disabled while testing - LEAVE proc; + -- LEAVE proc; IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) THEN - INSERT INTO `log` SET + INSERT IGNORE INTO `log` SET tableName = vTableName, tableId = vOldId, operation = 'delete'; END IF; IF vNewId IS NOT NULL THEN - INSERT INTO `log` SET + INSERT IGNORE INTO `log` SET tableName = vTableName, tableId = vNewId, operation = 'insert'; @@ -17388,7 +17325,7 @@ DELIMITER ; /*!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 `log_pop` */; +/*!50003 DROP PROCEDURE IF EXISTS `log_delete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17398,33 +17335,327 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `log_pop`() +CREATE DEFINER=`root`@`%` PROCEDURE `log_delete`(vTableName VARCHAR(255), vTableId INT) proc: BEGIN /** - * Process peding operations from #log table. + * Processes orphan transactions. */ + IF vTableName NOT IN ('buy', 'sale', 'orderRow') THEN + LEAVE proc; + END IF; + + DELETE FROM inbound + WHERE tableName = vTableName COLLATE utf8_general_ci + AND tableId = vTableId; + + DELETE FROM outbound + WHERE tableName = vTableName COLLATE utf8_general_ci + AND tableId = vTableId; +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 `log_refreshAll` */; +/*!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 `log_refreshAll`() +BEGIN +/** + * Recalculates the entire cache. It takes a considerable time, + * please avoid calls to this procedure from commonly used operations. + */ + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('stock.log_sync'); + RESIGNAL; + END; + + IF !GET_LOCK('stock.log_sync', 30) THEN + CALL util.throw('Lock timeout exceeded'); + END IF; + + TRUNCATE TABLE stock.`log`; + TRUNCATE TABLE stock.`inbound`; + TRUNCATE TABLE stock.`inboundOut`; + TRUNCATE TABLE stock.`outbound`; + TRUNCATE TABLE stock.`visible`; + + CALL log_refreshSale(NULL, NULL); + CALL log_refreshBuy(NULL, NULL); + CALL log_refreshOrder(NULL, NULL); + + UPDATE outbound SET isSync = TRUE; + CALL log_sync(TRUE); + + DO RELEASE_LOCK('stock.log_sync'); +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 `log_refreshBuy` */; +/*!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 `log_refreshBuy`( + `vTableName` VARCHAR(255), + `vTableId` INT) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tValues; + CREATE TEMPORARY TABLE tValues + ENGINE = MEMORY + SELECT + b.id buyFk, + e.id entryFk, + t.id travelFk, + b.itemFk, + e.isRaid, + ADDTIME(t.shipped, + IFNULL(t.shipmentHour, '00:00:00')) shipped, + t.warehouseOutFk, + t.isDelivered, + ADDTIME(t.landed, + IFNULL(t.landingHour, '00:00:00')) landed, + t.warehouseInFk, + t.isReceived, + tp.life, + ABS(b.quantity) quantity, + b.created, + b.quantity > 0 isIn, + t.shipped < vn.getInventoryDate() lessThanInventory + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType tp ON tp.id = i.typeFk + WHERE ( + vTableId IS NULL + OR (vTableName = 'travel' AND t.id = vTableId) + OR (vTableName = 'entry' AND e.id = vTableId) + OR (vTableName = 'buy' AND b.id = vTableId) + ) + AND t.landed >= vn.getInventoryDate() + AND b.quantity != 0; + + REPLACE INTO inbound ( + tableName, tableId, warehouseFk, dated, + itemFk, expired, quantity, isPicked + ) + SELECT 'buy', + buyFk, + IF(isIn, warehouseInFk, warehouseOutFk), + @dated := IF(isIn, landed, shipped), + itemFk, + TIMESTAMPADD(DAY, life, @dated), + quantity, + IF(isIn, isReceived, isDelivered) AND !isRaid + FROM tValues + WHERE isIn OR !lessThanInventory; + + REPLACE INTO outbound ( + tableName, tableId, warehouseFk, dated, + itemFk, created, quantity, isPicked + ) + SELECT 'buy', + buyFk, + IF(isIn, warehouseOutFk, warehouseInFk), + IF(isIn, shipped, landed), + itemFk, + created, + quantity, + IF(isIn, isDelivered, isReceived) AND !isRaid + FROM tValues + WHERE !isIn OR !lessThanInventory; + + DROP TEMPORARY TABLE tValues; +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 `log_refreshOrder` */; +/*!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 `log_refreshOrder`( + `vTableName` VARCHAR(255), + `vTableId` INT) +BEGIN + DECLARE vExpireTime INT DEFAULT 10; + DECLARE vExpired DATETIME DEFAULT TIMESTAMPADD(MINUTE, -vExpireTime, NOW()); + + DROP TEMPORARY TABLE IF EXISTS tValues; + CREATE TEMPORARY TABLE tValues + ENGINE = MEMORY + SELECT + r.id rowFk, + r.itemFk, + r.warehouseFk, + r.shipment shipped, + r.amount quantity, + r.created + FROM hedera.orderRow r + JOIN hedera.`order` o ON o.id = r.orderFk + WHERE ( + vTableId IS NULL + OR (vTableName = 'order' AND o.id = vTableId) + OR (vTableName = 'orderRow' AND r.id = vTableId) + ) + AND !o.confirmed + AND r.created >= vExpired + AND r.amount != 0; + + REPLACE INTO outbound ( + tableName, tableId, warehouseFk, dated, + itemFk, created, expired, quantity + ) + SELECT 'orderRow', + rowFk, + warehouseFk, + shipped, + itemFk, + created, + TIMESTAMPADD(MINUTE, -vExpireTime, created), + quantity + FROM tValues; + + DROP TEMPORARY TABLE tValues; +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 `log_refreshSale` */; +/*!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 `log_refreshSale`( + `vTableName` VARCHAR(255), + `vTableId` INT) +BEGIN + DROP TEMPORARY TABLE IF EXISTS tValues; + CREATE TEMPORARY TABLE tValues + ENGINE = MEMORY + SELECT + m.id saleFk, + m.ticketFk, + m.itemFk, + t.warehouseFk, + t.shipped, + ABS(m.quantity) quantity, + m.created, + TIMESTAMPADD(DAY, tp.life, t.shipped) expired, + m.quantity < 0 isIn, + m.isPicked OR s.alertLevel > 1 isPicked + FROM vn.sale m + JOIN vn.ticket t ON t.id = m.ticketFk + JOIN vn.ticketState s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = m.itemFk + JOIN vn.itemType tp ON tp.id = i.typeFk + WHERE ( + vTableId IS NULL + OR (vTableName = 'ticket' AND t.id = vTableId) + OR (vTableName = 'sale' AND m.id = vTableId) + ) + AND t.shipped >= vn.getInventoryDate() + AND m.quantity != 0; + + REPLACE INTO inbound ( + tableName, tableId, warehouseFk, dated, + itemFk, expired, quantity, isPicked + ) + SELECT 'sale', + saleFk, + warehouseFk, + shipped, + itemFk, + expired, + quantity, + isPicked + FROM tValues + WHERE isIn; + + REPLACE INTO outbound ( + tableName, tableId, warehouseFk, dated, + itemFk, created, quantity, isPicked + ) + SELECT 'sale', + saleFk, + warehouseFk, + shipped, + itemFk, + created, + quantity, + isPicked + FROM tValues + WHERE !isIn; + + DROP TEMPORARY TABLE tValues; +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 `log_sync` */; +/*!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 `log_sync`(vSync BOOL) +proc: BEGIN DECLARE vDone BOOL; DECLARE vLogId INT; DECLARE vOperation VARCHAR(255); DECLARE vTableName VARCHAR(255); DECLARE vTableId VARCHAR(255); - DECLARE vBuyFk INT; - DECLARE vSaleFk INT; - DECLARE vIsDesync BOOL DEFAULT FALSE; + DECLARE vInboundFk INT; + DECLARE vOutboundFk INT; - DECLARE cOps CURSOR FOR - SELECT id, operation, tableName, tableId - FROM `log` ORDER BY id; + DECLARE cInbound CURSOR FOR + SELECT id FROM inbound + WHERE !isSync + ORDER BY dated; - DECLARE cBuys CURSOR FOR - SELECT buyFk FROM buy - WHERE NOT isSync - ORDER BY landed; - - DECLARE cSales CURSOR FOR - SELECT saleFk FROM sale - WHERE NOT isSync - ORDER BY created; + DECLARE cOutbound CURSOR FOR + SELECT id FROM outbound + WHERE !isSync + ORDER BY dated; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -17432,355 +17663,294 @@ proc: BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN ROLLBACK; - DO RELEASE_LOCK('stock.log_pop'); RESIGNAL; END; - IF NOT GET_LOCK('stock.log_pop', 0) THEN - LEAVE proc; - END IF; - - -- Attaches desync buys + -- Applies changes opsLoop: LOOP + START TRANSACTION; + SET vDone = FALSE; SELECT id, operation, tableName, tableId INTO vLogId, vOperation, vTableName, vTableId FROM `log` - ORDER BY id LIMIT 1; + ORDER BY id LIMIT 1 + FOR UPDATE; IF vDone THEN + COMMIT; LEAVE opsLoop; END IF; - - SET vIsDesync = TRUE; - START TRANSACTION; - IF vTableName IN ('travel', 'entry', 'buy') THEN - CALL buy_refresh(vOperation, vTableName, vTableId); - ELSEIF vTableName IN ('ticket', 'sale') THEN - CALL sale_refresh(vOperation, vTableName, vTableId); + CALL log_delete(vTableName, vTableId); + + IF vOperation = 'insert' THEN + IF vTableName IN ('travel', 'entry', 'buy') THEN + CALL log_refreshBuy(vTableName, vTableId); + ELSEIF vTableName IN ('ticket', 'sale') THEN + CALL log_refreshSale(vTableName, vTableId); + ELSEIF vTableName IN ('order', 'orderRow') THEN + CALL log_refreshOrder(vTableName, vTableId); + END IF; END IF; DELETE FROM `log` WHERE id = vLogId; + SET vSync = TRUE; + COMMIT; END LOOP; - - IF NOT vIsDesync THEN - DO RELEASE_LOCK('stock.log_pop'); - LEAVE proc; - END IF; - - -- Processes orphan transactions - - START TRANSACTION; - - UPDATE sale s - JOIN buySale bs ON bs.saleFk = s.saleFk - SET s.lack = s.lack + bs.quantity, - s.isSync = FALSE - WHERE bs.buyFk IS NULL; - - UPDATE buy b - JOIN buySale bs ON bs.buyFk = b.buyFk - SET b.available = b.available + bs.quantity, - b.isSync = FALSE - WHERE bs.saleFk IS NULL; - - DELETE FROM buySale - WHERE saleFk IS NULL - OR buyFk IS NULL; - - COMMIT; - - -- Attaches desync buys - - OPEN cBuys; - - buysLoop: LOOP - SET vDone = FALSE; - FETCH cBuys INTO vBuyFk; - - IF vDone THEN - LEAVE buysLoop; - END IF; - - START TRANSACTION; - CALL buy_attach(vBuyFk); - UPDATE buy SET isSync = TRUE WHERE buyFk = vBuyFk; - COMMIT; - END LOOP; - - CLOSE cBuys; - - -- Attaches desync sales - -- XXX: Under development - DO RELEASE_LOCK('stock.log_pop'); - LEAVE proc; - - OPEN cSales; - - salesLoop: LOOP - SET vDone = FALSE; - FETCH cSales INTO vSaleFk; - - IF vDone THEN - LEAVE salesLoop; - END IF; - - START TRANSACTION; - CALL sale_attach(vSaleFk); - UPDATE sale SET isSync = TRUE WHERE saleFk = vSaleFk; - COMMIT; - END LOOP; - - CLOSE cSales; - - DO RELEASE_LOCK('stock.log_pop'); -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 `refresh_all` */; -/*!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 `refresh_all`() -BEGIN -/** - * Recalculates the entire cache. - */ - TRUNCATE TABLE stock.`log`; - TRUNCATE TABLE stock.buy; - TRUNCATE TABLE stock.sale; - TRUNCATE TABLE stock.buySale; - TRUNCATE TABLE stock.visible; - - CALL buy_refresh('insert', NULL, NULL); - CALL sale_refresh('insert', NULL, NULL); -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 `sale_attach` */; -/*!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 `sale_attach`(`vSaleFk` INT) -BEGIN -/** - * Attaches a sale with available buys. - * - * @param vSaleFk The sale identifier - */ - DECLARE vShipped DATETIME; - DECLARE vLack INT; - DECLARE vBuyFk DATETIME; - DECLARE vAvailable DATETIME; - DECLARE vRest INT; - DECLARE vDone BOOL; - - DECLARE cSales CURSOR FOR - SELECT buyFk, available - FROM buy - WHERE available > 0 - AND landed <= vShipped - AND (expired IS NULL OR expired >= vShipped) - ORDER BY landed; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SELECT shipped, lack INTO vShipped, vLack - FROM sale - WHERE saleFk = vSaleFk; - - OPEN cSales; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cSales INTO vBuyFk, vAvailable; - - IF vDone THEN - LEAVE myLoop; - END IF; - - SET vRest = LEAST(vAvailable, vLack); - SET vLack = vLack - vRest; - - INSERT INTO buySale SET - buyFk = vBuyFk, - saleFk = vSaleFk, - amount = vRest; - - CALL buySale_apply(vBuyFk, vSaleFk, -vRest); - - IF vLack = 0 THEN - LEAVE myLoop; - END IF; - END LOOP; - - CLOSE cSales; -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 `sale_detachAfterDate` */; -/*!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 `sale_detachAfterDate`( - `vSaleFk` INT, - `vLanded` DATETIME, - `vMaxQuantity` INT, - OUT `vRest` INT) -BEGIN -/** - * Detaches a sale from all buys after the given date. - * - * @param vSaleFk The sale identifier - * @param vDate The staring date - * @param vMaxQuantity Maximum quantity to detach - */ - DECLARE vQuantity INT; - DECLARE vLack INT; - DECLARE vBuyFk INT; - DECLARE vBuyQuantity INT; - DECLARE vBuyRest INT; - DECLARE vDone BOOL; - - DECLARE cSaleBuys CURSOR FOR - SELECT bs.buyFk, bs.quantity - FROM buySale bs - JOIN buy b ON b.buyFk = bs.buyFk - WHERE bs.saleFk = vSaleFk - AND b.landed > vLanded - ORDER BY b.landed DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SELECT quantity, lack INTO vQuantity, vLack - FROM sale - WHERE saleFk = vSaleFk; - - SET vRest = LEAST(vMaxQuantity, vLack); - - IF vLack < vQuantity AND vRest < vMaxQuantity THEN - OPEN cSaleBuys; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cSaleBuys INTO vBuyFk, vBuyQuantity; - - IF vDone THEN - LEAVE myLoop; - END IF; - - SET vBuyRest = LEAST(vMaxQuantity - vRest, vBuyQuantity); - SET vRest = vRest + vBuyRest; - - IF vBuyRest < vBuyQuantity THEN - UPDATE buySale - SET quantity = quantity - vBuyRest - WHERE buyFk = vBuyFk AND saleFk = vSaleFk; - ELSE - DELETE FROM buySale - WHERE buyFk = vBuyFk AND saleFk = vSaleFk; - END IF; - - UPDATE buy SET isSync = FALSE - WHERE buyFk = vBuyFk; - - CALL buySale_apply(vBuyFk, vSaleFk, -vBuyRest); - - IF vRest >= vMaxQuantity THEN - LEAVE myLoop; - END IF; - END LOOP; - - CLOSE cSaleBuys; - 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 `sale_refresh` */; -/*!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 `sale_refresh`( - `vOperation` VARCHAR(255), - `vTableName` VARCHAR(255), - `vTableId` INT) -proc: BEGIN - IF vTableId IS NOT NULL THEN - DELETE FROM sale - WHERE (vTableName = 'ticket' AND ticketFk = vTableId) - OR (vTableName = 'sale' AND saleFk = vTableId); - END IF; - - IF vOperation != 'insert' THEN + IF !vSync THEN LEAVE proc; END IF; - REPLACE INTO sale ( - saleFk, ticketFk, itemFk, warehouseFk, - shipped, isPicked, quantity, lack, created - ) - SELECT - m.id saleFk, - m.ticketFk, - m.itemFk, - t.warehouseFk, - t.shipped, - m.isPicked OR s.alertLevel > 1 isPicked, - m.quantity, - GREATEST(0, m.quantity) lack, - m.created - FROM vn.sale m - JOIN vn.ticket t ON t.id = m.ticketFk - JOIN vn.ticketState s ON s.ticketFk = t.id - WHERE ( - vTableId IS NULL - OR (vTableName = 'ticket' AND t.id = vTableId) - OR (vTableName = 'sale' AND m.id = vTableId) - ) - AND (t.shipped >= vn.getInventoryDate() - AND m.quantity != 0); + -- Deletes expired outbounds + + DELETE FROM outbound WHERE expired <= NOW(); + + -- Attaches desync inbounds + + OPEN cInbound; + + inboundLoop: LOOP + SET vDone = FALSE; + FETCH cInbound INTO vInboundFk; + + IF vDone THEN + LEAVE inboundLoop; + END IF; + + START TRANSACTION; + CALL inbound_sync(vInboundFk); + COMMIT; + END LOOP; + + CLOSE cInbound; + + -- Attaches desync outbounds + + OPEN cOutbound; + + outboundLoop: LOOP + SET vDone = FALSE; + FETCH cOutbound INTO vOutboundFk; + + IF vDone THEN + LEAVE outboundLoop; + END IF; + + START TRANSACTION; + CALL outbound_sync(vOutboundFk); + COMMIT; + END LOOP; + + CLOSE cOutbound; +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 `log_syncNoWait` */; +/*!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=`z-developer`@`%` PROCEDURE `log_syncNoWait`() +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('stock.log_sync'); + RESIGNAL; + END; + + IF GET_LOCK('stock.log_sync', 0) THEN + CALL log_sync(FALSE); + END IF; + + DO RELEASE_LOCK('stock.log_sync'); +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 `outbound_requestQuantity` */; +/*!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 `outbound_requestQuantity`( + vSelf INT, + vRequested INT, + vDated DATETIME, + OUT vGranted INT) +BEGIN +/** + * Requests a quantity from an outbound to fulfill an inbound. + * If the demanded quantity exceeds the lack, it also + * disassociates it's inbounds after the given date until the + * demanded quantity is satisfied or there is no more lack. + * + * @param vSelf The outbound reference + * @param vRequested The requested quantity + * @param vDate The starting date for the associated inbounds + * @param vGranted The granted quantity + */ + DECLARE vQuantity INT; + DECLARE vLack INT; + DECLARE vInboundFk INT; + DECLARE vLinkQuantity INT; + DECLARE vLinkGranted INT; + DECLARE vDone BOOL; + + DECLARE cOutboundIns CURSOR FOR + SELECT ou.inboundFk, ou.quantity + FROM inboundOut ou + JOIN inbound i ON i.id = ou.inboundFk + WHERE ou.outboundFk = vSelf + AND i.dated > vDated + ORDER BY i.dated DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT quantity, lack INTO vQuantity, vLack + FROM outbound + WHERE id = vSelf; + + SET vGranted = LEAST(vRequested, vLack); + + IF vLack < vQuantity AND vGranted < vRequested THEN + OPEN cOutboundIns; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cOutboundIns INTO vInboundFk, vLinkQuantity; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SET vLinkGranted = LEAST(vRequested - vGranted, vLinkQuantity); + SET vGranted = vGranted + vLinkGranted; + + IF vLinkGranted < vLinkQuantity THEN + UPDATE inboundOut + SET quantity = quantity - vLinkGranted + WHERE inboundFk = vInboundFk AND outboundFk = vSelf; + ELSE + DELETE FROM inboundOut + WHERE inboundFk = vInboundFk AND outboundFk = vSelf; + END IF; + + UPDATE inbound SET isSync = FALSE + WHERE id = vInboundFk; + + CALL inboundOut_apply(vInboundFk, vSelf, -vLinkGranted); + + IF vGranted >= vRequested THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE cOutboundIns; + 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 `outbound_sync` */; +/*!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 `outbound_sync`(vSelf INT) +BEGIN +/** + * Attaches a outbound with available inbounds. + * + * @param vSelf The outbound reference + */ + DECLARE vDated DATETIME; + DECLARE vItem INT; + DECLARE vWarehouse INT; + DECLARE vLack INT; + DECLARE vInboundFk INT; + DECLARE vAvailable INT; + DECLARE vGranted INT; + DECLARE vDone BOOL; + + DECLARE cInbound CURSOR FOR + SELECT id, available + FROM inbound + WHERE warehouseFk = vWarehouse + AND itemFk = vItem + AND dated <= vDated + AND (expired IS NULL OR expired > vDated) + ORDER BY dated; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT warehouseFk, itemFk, dated, lack + INTO vWarehouse, vItem, vDated, vLack + FROM outbound + WHERE id = vSelf; + + OPEN cInbound; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cInbound INTO vInboundFk, vAvailable; + + IF vDone THEN + LEAVE myLoop; + END IF; + + CALL inbound_requestQuantity(vInboundFk, vLack, vDated, vGranted); + + IF vGranted > 0 THEN + SET vLack = vLack - vGranted; + + INSERT INTO inboundOut + SET + inboundFk = vInboundFk, + outboundFk = vSelf, + quantity = vGranted + ON DUPLICATE KEY UPDATE + quantity = quantity + vGranted; + + CALL inboundOut_apply(vInboundFk, vSelf, vGranted); + END IF; + + IF vLack = 0 THEN + LEAVE myLoop; + END IF; + END LOOP; + + CLOSE cInbound; + + UPDATE outbound SET isSync = TRUE + WHERE id = vSelf; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -17788,6 +17958,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_log` */; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -17798,71 +17969,29 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `visible_log`( - vWarehouseFk INT, + vIsPicked BOOL, + vWarehouseFk INT, vItemFk INT, - vQuantity INT, - vDate DATE, - vIsPicked BOOL) + vQuantity INT +) proc: BEGIN - DECLARE vToday DATE DEFAULT CURDATE(); - - IF vDate > vToday - OR vDate = vToday AND NOT vIsPicked - THEN + IF !vIsPicked THEN LEAVE proc; - END IF; + END IF; - INSERT INTO visible + INSERT INTO visible SET itemFk = vItemFk, warehouseFk = vWarehouseFk, quantity = vQuantity ON DUPLICATE KEY UPDATE - quantity = quantity + vQuantity; -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 `visible_logBuy` */; -/*!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 `visible_logBuy`( - vItem INT, - vQuantity INT, - vIsRaid BOOL, - vWarehouseIn INT, - vLanded DATETIME, - vIsReceived BOOL, - vWarehouseOut INT, - vShipped DATETIME, - vIsDelivered BOOL -) -proc: BEGIN -/** - * Updates visible. - * - * @param vItem The item id - */ - IF vIsRaid THEN - LEAVE proc; - END IF; - - CALL visible_log(vWarehouseIn, vItem, vQuantity, vLanded, vIsReceived); - CALL visible_log(vWarehouseOut, vItem, -vQuantity, vShipped, vIsDelivered); + quantity = quantity + VALUES(quantity); 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 */ ; +ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; -- -- Current Database: `util` @@ -18845,7 +18974,7 @@ CREATE TABLE `autoRadioLogCall` ( PRIMARY KEY (`id`), KEY `ticket_idx` (`ticketFk`), CONSTRAINT `ticket` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=634 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=735 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19406,7 +19535,7 @@ CREATE TABLE `clientContact` ( `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4123 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4127 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19480,7 +19609,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=206528 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=209402 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19905,7 +20034,7 @@ CREATE TABLE `creditClassification` ( KEY `creditClassifClientFk_idx` (`client`), KEY `creditClassifdateEnd_idx` (`dateEnd`), CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3120 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3130 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -19950,7 +20079,7 @@ CREATE TABLE `creditInsurance` ( PRIMARY KEY (`id`), KEY `CreditInsurance_Fk1_idx` (`creditClassification`), CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2672 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB AUTO_INCREMENT=2694 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -20085,24 +20214,13 @@ SET character_set_client = utf8; 1 AS `workerFk`, 1 AS `warehouseFk`, 1 AS `companyFk`, + 1 AS `priority`, + 1 AS `hasFile`, 1 AS `reference`, 1 AS `description`, 1 AS `created`*/; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `dmsTicket` --- - -DROP TABLE IF EXISTS `dmsTicket`; -/*!50001 DROP VIEW IF EXISTS `dmsTicket`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `dmsTicket` AS SELECT - 1 AS `ticketFk`, - 1 AS `dmsFk`*/; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `dmsType` -- @@ -20114,7 +20232,9 @@ SET character_set_client = utf8; /*!50001 CREATE VIEW `dmsType` AS SELECT 1 AS `id`, 1 AS `name`, - 1 AS `path`*/; + 1 AS `path`, + 1 AS `readRoleFk`, + 1 AS `writeRoleFk`*/; SET character_set_client = @saved_cs_client; -- @@ -20164,7 +20284,7 @@ CREATE TABLE `dua` ( CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `vn2008`.`gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `dua_fk2` FOREIGN KEY (`awbFk`) REFERENCES `vn2008`.`awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `dua_fk4` FOREIGN KEY (`companyFk`) REFERENCES `vn2008`.`empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3840 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3866 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20205,7 +20325,7 @@ CREATE TABLE `duaIntrastat` ( KEY `duaIntrastat_fk2_idx` (`duaFk`), CONSTRAINT `duaIntrastat_fk1` FOREIGN KEY (`intrastatFk`) REFERENCES `vn2008`.`Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `duaIntrastat_fk2` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5970 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=6058 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20225,7 +20345,7 @@ CREATE TABLE `duaInvoiceIn` ( KEY `duaInvoiceIn_fk2_idx` (`invoiceInFk`), CONSTRAINT `duaInvoiceIn_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaInvoiceIn_fk2` FOREIGN KEY (`invoiceInFk`) REFERENCES `vn2008`.`recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4734 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; +) ENGINE=InnoDB AUTO_INCREMENT=4765 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20250,7 +20370,7 @@ CREATE TABLE `duaTax` ( CONSTRAINT `duaTax_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaTax_fk2` FOREIGN KEY (`supplierFk`) REFERENCES `vn2008`.`Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `duaTax_fk3` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5086 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5312 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20346,7 +20466,7 @@ CREATE TABLE `entryLog` ( KEY `entryLog_ibfk_2` (`userFk`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=132982 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=136785 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20380,7 +20500,7 @@ CREATE TABLE `envialiaCity` ( PRIMARY KEY (`id`), KEY `agencyFk` (`agencyFk`), KEY `postalCode` (`postalCode`) -) ENGINE=InnoDB AUTO_INCREMENT=1100732 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1141101 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -20847,7 +20967,7 @@ CREATE TABLE `inventoryFailure` ( CONSTRAINT `inventoryFailure_fk3` FOREIGN KEY (`guiltyFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk4` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10650 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=11720 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21118,7 +21238,7 @@ CREATE TABLE `invoiceOutExpence` ( KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`), CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=110644 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; +) ENGINE=InnoDB AUTO_INCREMENT=110733 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21161,7 +21281,7 @@ CREATE TABLE `invoiceOutTax` ( KEY `pgcFk` (`pgcFk`), CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1086126 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1086225 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21359,7 +21479,7 @@ CREATE TABLE `itemLog` ( KEY `itemLogUserFk_idx` (`userFk`), CONSTRAINT `itemLogItemFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=12584 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=18231 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21402,7 +21522,7 @@ CREATE TABLE `itemPlacementSupply` ( CONSTRAINT `itemPlacementSupply_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk3` FOREIGN KEY (`repoUserFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=17544 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; +) ENGINE=InnoDB AUTO_INCREMENT=20850 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21474,7 +21594,7 @@ CREATE TABLE `itemShelving` ( CONSTRAINT `itemShelving_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelving_fk2` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelving_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=81101 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla utilizada para localizar los artículos dentro de los carros. Usado para la gestión del almacén en el altillo '; +) ENGINE=InnoDB AUTO_INCREMENT=85512 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla utilizada para localizar los artículos dentro de los carros. Usado para la gestión del almacén en el altillo '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21578,7 +21698,7 @@ CREATE TABLE `itemShelvingPlacementSupply` ( KEY `itemShelvingPlacementSupply_fk3_idx` (`userFk`), CONSTRAINT `itemShelvingPlacementSupply_fk1` FOREIGN KEY (`itemShelvingFk`) REFERENCES `itemShelving` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelvingPlacementSupply_fk2` FOREIGN KEY (`itemPlacementSupplyFk`) REFERENCES `itemPlacementSupply` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15463 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; +) ENGINE=InnoDB AUTO_INCREMENT=18644 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21625,7 +21745,7 @@ CREATE TABLE `itemShelvingSale` ( CONSTRAINT `itemShelvingSale_fk1` FOREIGN KEY (`itemShelvingFk`) REFERENCES `itemShelving` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelvingSale_fk2` FOREIGN KEY (`saleFk`) REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) ON UPDATE CASCADE, CONSTRAINT `itemShelvingSale_fk3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5714 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle del producto que se retira de los carros, relacionando la linea de movimiento correspondiente'; +) ENGINE=InnoDB AUTO_INCREMENT=7079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle del producto que se retira de los carros, relacionando la linea de movimiento correspondiente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -21709,7 +21829,7 @@ CREATE TABLE `itemTag` ( KEY `priorityItem` (`priority`,`itemFk`), KEY `value` (`value`), CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1154887 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1178986 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -21811,7 +21931,7 @@ CREATE TABLE `itemTaxCountry` ( CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=699731 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB AUTO_INCREMENT=718998 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22081,7 +22201,7 @@ CREATE TABLE `medicalReview` ( KEY `frgnkWorker_idx` (`workerFk`), CONSTRAINT `frgcenter` FOREIGN KEY (`centerFk`) REFERENCES `medicalCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnkWorker` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=216 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=220 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22102,7 +22222,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB AUTO_INCREMENT=1835058 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1851169 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22124,7 +22244,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB AUTO_INCREMENT=2001645 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2018582 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -22358,7 +22478,7 @@ CREATE TABLE `parking` ( UNIQUE KEY `code_UNIQUE` (`code`), KEY `parking_fk1_idx` (`sectorFk`), CONSTRAINT `parking_fk1` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=25362 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla con los parkings del altillo'; +) ENGINE=InnoDB AUTO_INCREMENT=25479 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla con los parkings del altillo'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -23021,7 +23141,7 @@ CREATE TABLE `routeAction` ( `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `price` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23042,7 +23162,7 @@ CREATE TABLE `routeComplement` ( KEY `fgn_routeActionFk_idx` (`routeActionFk`), CONSTRAINT `fgn_routeActionFk` FOREIGN KEY (`routeActionFk`) REFERENCES `routeAction` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgn_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23130,13 +23250,22 @@ DROP TABLE IF EXISTS `routeLog`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `routeLog` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `originFk` int(11) NOT NULL, - `userFk` int(10) unsigned NOT NULL, + `originFk` int(10) unsigned 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 COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=841307 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + `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 `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `routeLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Rutas` (`Id_Ruta`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `routeLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=3267 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23315,6 +23444,39 @@ CREATE TABLE `sector` ( ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `sharingCart` +-- + +DROP TABLE IF EXISTS `sharingCart`; +/*!50001 DROP VIEW IF EXISTS `sharingCart`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `sharingCart` AS SELECT + 1 AS `id`, + 1 AS `workerFk`, + 1 AS `started`, + 1 AS `ended`, + 1 AS `workerSubstitute`, + 1 AS `created`*/; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `sharingClient` +-- + +DROP TABLE IF EXISTS `sharingClient`; +/*!50001 DROP VIEW IF EXISTS `sharingClient`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `sharingClient` AS SELECT + 1 AS `id`, + 1 AS `workerFk`, + 1 AS `started`, + 1 AS `ended`, + 1 AS `clientFk`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `shelving` -- @@ -23376,7 +23538,7 @@ CREATE TABLE `sms` ( `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=129172 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=131004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23541,7 +23703,7 @@ CREATE TABLE `stockBuyed` ( UNIQUE KEY `date_UNIQUE` (`date`,`user`), KEY `stockBuyed_user_idx` (`user`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=634161 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=655667 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23798,6 +23960,33 @@ SET character_set_client = utf8; 1 AS `created`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `ticketConfig` +-- + +DROP TABLE IF EXISTS `ticketConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `ticketConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `scopeDays` tinyint(3) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `ticketDms` +-- + +DROP TABLE IF EXISTS `ticketDms`; +/*!50001 DROP VIEW IF EXISTS `ticketDms`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketDms` AS SELECT + 1 AS `ticketFk`, + 1 AS `dmsFk`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketDown` -- @@ -23853,7 +24042,7 @@ CREATE TABLE `ticketLog` ( KEY `logTicketuserFk` (`userFk`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5477234 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5651565 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23925,7 +24114,7 @@ CREATE TABLE `ticketPackaging` ( CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk3` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=59004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=60590 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24027,7 +24216,7 @@ CREATE TABLE `ticketServiceType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de los posibles servicios a elegir'; +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de los posibles servicios a elegir'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24292,7 +24481,7 @@ CREATE TABLE `trainingCourse` ( CONSTRAINT `frgnCenter` FOREIGN KEY (`centerFk`) REFERENCES `trainingCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnTrainingCourseType` FOREIGN KEY (`trainingCourseTypeFk`) REFERENCES `trainingCourseType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnWorker` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=260 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; +) ENGINE=InnoDB AUTO_INCREMENT=265 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24352,6 +24541,19 @@ CREATE TABLE `travelObservation` ( ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `travelRecalc` +-- + +DROP TABLE IF EXISTS `travelRecalc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `travelRecalc` ( + `travelFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`travelFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Travels to recalc it''s entry count'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `unary` -- @@ -24647,7 +24849,7 @@ CREATE TABLE `workerDocument` ( KEY `workerDocument_ibfk_2` (`document`), CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE, CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10252 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10462 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24697,7 +24899,7 @@ CREATE TABLE `workerJourney` ( UNIQUE KEY `userFk_UNIQUE` (`userFk`,`dated`), KEY `fk_workerJourney_user_idx` (`userFk`), CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=32569910 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=33852830 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24736,7 +24938,7 @@ CREATE TABLE `workerLog` ( KEY `userFk_idx` (`userFk`), CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=10731 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10915 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24799,7 +25001,7 @@ CREATE TABLE `workerTimeControl` ( KEY `warehouseFkfk1_idx` (`warehouseFk`), CONSTRAINT `warehouseFk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerTimeControl_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2996961 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; +) ENGINE=InnoDB AUTO_INCREMENT=3589864 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24930,7 +25132,7 @@ CREATE TABLE `zone` ( KEY `fk_zone_2_idx` (`agencyModeFk`), CONSTRAINT `fk_zone_1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fk_zone_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24964,7 +25166,8 @@ CREATE TABLE `zoneGeo` ( `sons` decimal(10,0) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `zoneGeo_lft_IDX` (`lft`) USING BTREE, - UNIQUE KEY `zoneGeo_rgt_IDX` (`rgt`) USING BTREE + UNIQUE KEY `zoneGeo_rgt_IDX` (`rgt`) USING BTREE, + KEY `zoneGeo_name_idx` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -25101,6 +25304,24 @@ DELIMITER ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; +/*!50106 DROP EVENT IF EXISTS `travel_doRecalc` */;; +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_unicode_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`z-developer`@`%`*/ /*!50106 EVENT `travel_doRecalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-05-17 10:52:29' ON COMPLETION PRESERVE ENABLE DO CALL travel_doRecalc */ ;; +/*!50003 SET time_zone = @saved_time_zone */ ;; +/*!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 */ ;; DELIMITER ; /*!50106 SET TIME_ZONE= @save_time_zone */ ; @@ -25510,6 +25731,92 @@ DELIMITER ; /*!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 FUNCTION IF EXISTS `clientGetSalesPerson` */; +/*!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`@`%` FUNCTION `clientGetSalesPerson`(vClientFk INT, vDated DATE) RETURNS int(11) + DETERMINISTIC +BEGIN +/** + * Dado un id cliente y una fecha, devuelve su comercial para ese dia, teniendo + * en cuenta la jerarquía de las tablas: 1º la de sharingClient, 2º la de + * sharingCart y tercero la de clientes. + * + * @param vClientFk El id del cliente + * @param vDated Fecha a comprobar + * @return El id del comercial para la fecha dada + **/ + DECLARE vSalesperson INT DEFAULT NULL; + DECLARE vSubstitute INT DEFAULT NULL; + DECLARE vLoop BOOLEAN; + + -- Obtiene el comercial original y el de sharingClient + + SELECT c.salesPersonFk, s.workerFk + INTO vSalesperson, vSubstitute + FROM client c + LEFT JOIN sharingClient s + ON c.id = s.clientFk + AND vDated BETWEEN s.started AND s.ended + WHERE c.id = vClientFk + ORDER BY s.id + LIMIT 1; + + -- Si no hay ninguno en sharingClient busca en sharingCart + + IF vSubstitute IS NOT NULL + THEN + SET vSalesperson = vSubstitute; + ELSEIF vSalesperson IS NOT NULL + THEN + DROP TEMPORARY TABLE IF EXISTS tmp.stack; + CREATE TEMPORARY TABLE tmp.stack + (INDEX (substitute)) + ENGINE = MEMORY + SELECT vSalesperson substitute; + + l: LOOP + SELECT workerSubstitute INTO vSubstitute + FROM sharingCart + WHERE vDated BETWEEN started AND ended + AND workerFk = vSalesperson + ORDER BY id + LIMIT 1; + + IF vSubstitute IS NULL THEN + LEAVE l; + END IF; + + SELECT COUNT(*) > 0 INTO vLoop + FROM tmp.stack WHERE substitute = vSubstitute; + + IF vLoop THEN + LEAVE l; + END IF; + + INSERT INTO tmp.stack SET + substitute = vSubstitute; + + SET vSalesperson = vSubstitute; + END LOOP; + + DROP TEMPORARY TABLE tmp.stack; + END IF; + + RETURN vSalesperson; +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 FUNCTION IF EXISTS `clientTaxArea` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25581,6 +25888,78 @@ BEGIN RETURN curRate; +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 FUNCTION IF EXISTS `entry_calcCommission` */; +/*!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`@`%` FUNCTION `entry_calcCommission`( + vCurrentCommission INT, + vTravelFk INT, + vCurrencyFk INT +) RETURNS int(11) + READS SQL DATA +BEGIN + DECLARE vCommission INT; + + IF vCurrencyFk != 2 /* Dollar */ THEN + RETURN vCurrentCommission; + END IF; + + SELECT ROUND(-100 * (1 - (1 / r.rate))) INTO vCommission + FROM travel t + LEFT JOIN vn2008.reference_min r + ON r.moneda_id = vCurrencyFk AND r.`date` <= t.shipped + WHERE t.id = vTravelFk + ORDER BY r.`date` DESC + LIMIT 1; + + SET vCommission = IFNULL(vCommission, 0); + + RETURN vCommission; +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 FUNCTION IF EXISTS `entry_getCurrency` */; +/*!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`@`%` FUNCTION `entry_getCurrency`( + vCurrency INT, + vSupplierFk INT +) RETURNS int(11) + READS SQL DATA +BEGIN + DECLARE vIsDollarAccount BOOL; + + SELECT account LIKE '___4______' INTO vIsDollarAccount + FROM vn.supplier WHERE id = vSupplierFk; + + IF vIsDollarAccount THEN + RETURN 2; + ELSE + RETURN vCurrency; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -26074,27 +26453,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; -/*!50003 DROP FUNCTION IF EXISTS `getUserKk` */; -/*!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`@`%` FUNCTION `getUserKk`() RETURNS int(11) - DETERMINISTIC -BEGIN -/* JGF 2019-03-04 obsoleto, usar account.userGetId() */ - RETURN getWorker(); -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 FUNCTION IF EXISTS `getWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -27700,6 +28058,96 @@ DELIMITER ; /*!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 `buy_afterUpsert` */; +/*!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 `buy_afterUpsert`(vSelf INT) +BEGIN +/** + * Triggered actions when a buy is updated or inserted. + * + * @param vSelf The buy reference + */ + DECLARE vEntryFk INT; + DECLARE vItemFk INT; + DECLARE vStickers INT; + DECLARE vPacking INT; + DECLARE vWarehouse INT; + DECLARE vWarehouseOut INT; + DECLARE vIsMerchandise BOOL; + DECLARE vIsFeedStock BOOL; + + SELECT entryFk, itemFk, stickers, packing + INTO vEntryFk, vItemFk, vStickers, vPacking + FROM buy + WHERE id = vSelf; + + SELECT t.warehouseInFk, t.warehouseOutFk + INTO vWarehouse, vWarehouseOut + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.id = vEntryFk; + + SELECT k.merchandise INTO vIsMerchandise + FROM itemCategory k + JOIN itemType it ON it.categoryFk = k.id + JOIN item i ON i.typeFk = it.id + WHERE i.id = vItemFk; + + IF vIsMerchandise THEN + REPLACE bi.rotacion SET + Id_Article = vItemFk, + warehouse_id = vWarehouse, + cm3 = vn2008.cm3_unidad(vSelf); + END IF; + + SELECT isFeedStock INTO vIsFeedStock + FROM warehouse WHERE id = vWarehouseOut AND id <> 13; + + IF vIsFeedStock AND vn2008.has_notify_passport(vItemFk, vSelf) THEN + CALL vn2008.notify_passport(vItemFk, vStickers, vPacking, vSelf); + CALL vn2008.insert_producer_plantpassport(vSelf); + 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 `buy_checkGrouping` */; +/*!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 `buy_checkGrouping`(vGrouping INT) +BEGIN +/** + * Checks the buy grouping, throws an error if it's invalid. + * + * @param vGrouping The grouping + */ + IF vGrouping = 0 THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Grouping cannot be zero'; + 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 `carrosOficialesANoOficiales` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -27973,7 +28421,17 @@ BEGIN JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE() JOIN vn.config ON TRUE SET c.isFreezed = TRUE - WHERE d.amount > config.defaultersMaxAmount AND c.typeFk = 'normal'; + WHERE d.amount > config.defaultersMaxAmount + AND c.payMethodFk NOT IN (5,8) + AND c.typeFk = 'normal'; + + UPDATE vn.client c + JOIN bi.defaulters d ON d.client = c.id AND d.date = TIMESTAMPADD(DAY,10,CURDATE()) + JOIN vn.config ON TRUE + SET c.isFreezed = TRUE + WHERE d.amount > config.defaultersMaxAmount + AND c.payMethodFk IN (5,8) + AND c.typeFk = 'normal'; END IF; @@ -31924,89 +32382,104 @@ 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_unicode_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 ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemCard`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT) -BEGIN - - DECLARE vCacheVisibleFk INT; - DECLARE vCacheAvailableFk INT; - DECLARE vVisibleAltillo INT; - DECLARE vItemFk INT; - - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk); - CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE()); - /* - SELECT max(id) INTO vCacheVisibleFk - FROM cache.cache_calc - WHERE cacheName = 'visible' - AND params = vWarehouseFk; - - SELECT max(id) INTO vCacheAvailableFk - FROM cache.cache_calc - WHERE cacheName = 'available' - AND params = CONCAT(vWarehouseFk,'/',date(CURDATE())); - */ - /* - SELECT sum(visible) INTO vVisibleAltillo - FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.`code` = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk - WHERE ish.itemFk = vItemFk - AND s.warehouseFk = vWarehouseFk; - */ - SELECT visible INTO vVisibleAltillo - FROM vn.itemShelvingStock - WHERE itemFk = vItemFk; - - CALL vn2008.item_last_buy_(vWarehouseFk,vItemFk); - - SELECT i.id, - i.longName, - i.value5, - i.value6, - i.value7, - i.image, - i.size, - i.stems, - i.category, - i.minimum as min, - i.upToDown as repo, - p.name as producer, - o.code as origin, - ip.code as nicho, - ip.reserve as reserva, - v.visible - IFNULL(vVisibleAltillo,0) as enNicho, - a.available, - vVisibleAltillo as enAltillo, - v.visible as total, - c.`grouping` as `grouping`, - c.Packing as packing - FROM vn.item i - LEFT JOIN vn.producer p ON p.id = i.producerFk - LEFT JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id - LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id - LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id - LEFT JOIN - (SELECT b.item_id,c.`grouping`,c.Packing - FROM vn2008.t_item_last_buy b - INNER JOIN vn2008.Compres c ON c.Id_Compra = b.buy_id - where b.warehouse_id = vWarehouseFk) c - ON i.id= c.item_id - WHERE i.id = vItemFk - AND IFNULL(ip.warehouseFk, vWarehouseFk) = vWarehouseFk; - - DROP TEMPORARY TABLE t_item_last_buy; - - +CREATE DEFINER=`root`@`%` PROCEDURE `itemCard`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT, isBarcode BOOL) +BEGIN + + DECLARE vCacheVisibleFk INT; + DECLARE vCacheAvailableFk INT; + DECLARE vVisibleAltillo INT; + DECLARE vItemFk INT; + + IF isBarcode THEN + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + ELSE + SELECT i.id INTO vItemFk + FROM vn.item i + WHERE i.name LIKE CONCAT('%',vBarcode,'%') + ORDER BY i.id ASC + LIMIT 1; + END IF; + + + IF vItemFk IS NULL THEN + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + END IF; + + + + CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk); + CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, CURDATE()); + /* + SELECT max(id) INTO vCacheVisibleFk + FROM cache.cache_calc + WHERE cacheName = 'visible' + AND params = vWarehouseFk; + + SELECT max(id) INTO vCacheAvailableFk + FROM cache.cache_calc + WHERE cacheName = 'available' + AND params = CONCAT(vWarehouseFk,'/',date(CURDATE())); + */ + /* + SELECT sum(visible) INTO vVisibleAltillo + FROM vn.itemShelving ish + JOIN vn.shelving sh ON sh.`code` = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE ish.itemFk = vItemFk + AND s.warehouseFk = vWarehouseFk; + */ + SELECT visible INTO vVisibleAltillo + FROM vn.itemShelvingStock + WHERE itemFk = vItemFk; + + CALL vn2008.item_last_buy_(vWarehouseFk,vItemFk); + + SELECT i.id, + i.longName, + i.value5, + i.value6, + i.value7, + i.image, + i.size, + i.stems, + i.category, + i.minimum as min, + i.upToDown as repo, + p.name as producer, + o.code as origin, + ip.code as nicho, + ip.reserve as reserva, + v.visible - IFNULL(vVisibleAltillo,0) as enNicho, + a.available, + vVisibleAltillo as enAltillo, + v.visible as total, + c.`grouping` as `grouping`, + c.Packing as packing + FROM vn.item i + LEFT JOIN vn.producer p ON p.id = i.producerFk + LEFT JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id + LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id + LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id + LEFT JOIN + (SELECT b.item_id,c.`grouping`,c.Packing + FROM vn2008.t_item_last_buy b + INNER JOIN vn2008.Compres c ON c.Id_Compra = b.buy_id + where b.warehouse_id = vWarehouseFk) c + ON i.id= c.item_id + WHERE i.id = vItemFk + AND IFNULL(ip.warehouseFk, vWarehouseFk) = vWarehouseFk; + + DROP TEMPORARY TABLE t_item_last_buy; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33061,6 +33534,81 @@ BEGIN WHERE i.id = vItemFk; +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 `itemShelvingMakeFromDate` */; +/*!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 `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vShelve` VARCHAR(2), IN `vDeep` INT, IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, IN `vLevel` INT,`vCreated` VARCHAR(22)) +BEGIN + + + + DECLARE vItemFk INT; + + + + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + + + SELECT itemFk INTO vItemFk + FROM vn.buy b + WHERE b.id = vItemFk; + + + IF (SELECT COUNT(*) FROM vn.shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN + + INSERT IGNORE INTO vn.parking(`code`) VALUES(vShelvingFk); + INSERT INTO vn.shelving(`code`, parkingFk) + SELECT vShelvingFk, id + FROM vn.parking + WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; + + END IF; + + + INSERT INTO itemShelving( itemFk, + shelvingFk, + shelve, + deep, + quantity, + visible, + available, + created, + `grouping`, + packing, + packagingFk, + level) + SELECT + vItemFk, + vShelvingFk, + vShelve, + vDeep, + vQuantity, + vQuantity, + vQuantity, + vCreated, + IF(vGrouping = 0, IFNULL(b.packing, vPacking), vGrouping) as `grouping`, + IF(vPacking = 0, b.packing, vPacking) as packing, + IF(vPackagingFk = '', b.packageFk, vPackagingFk) as packaging, + vLevel + FROM vn.item i + LEFT JOIN bi.Last_buy_id lb ON i.id = lb.Id_Article AND lb.warehouse_id = vWarehouseFk + LEFT JOIN vn.buy b ON b.id = lb.Id_Compra + WHERE i.id = vItemFk; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33671,11 +34219,17 @@ CREATE DEFINER=`root`@`%` PROCEDURE `itemShelvingTransfer`(vItemFk INT,shelvingF BEGIN DECLARE vPacking INT; + DECLARE vDate VARCHAR(22); SELECT packing INTO vPacking FROM vn.itemShelving WHERE shelvingFk = shelvingFkO COLLATE utf8_unicode_ci AND itemFk = vItemFk LIMIT 1; + + SELECT created INTO vDate + FROM vn.itemShelving + WHERE shelvingFk = shelvingFkO COLLATE utf8_unicode_ci AND itemFk = vItemFk + LIMIT 1; UPDATE vn.itemShelving SET quantity = quantity - ( vPacking * vQuantity ), @@ -33683,7 +34237,7 @@ BEGIN available = available - ( vPacking * vQuantity ) WHERE shelvingFk = shelvingFkO COLLATE utf8_unicode_ci AND itemFk = vItemFk; - CALL vn.itemShelvingMake(shelvingFkD,vItemFk,'A',0,( vPacking * vQuantity ),'',0,vPacking,1,1); + CALL vn.itemShelvingMakeFromDate(shelvingFkD,vItemFk,'A',0,( vPacking * vQuantity ),'',0,vPacking,1,1,vDate); SELECT true; @@ -34064,6 +34618,82 @@ BEGIN FROM itemTag 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 `itemTopSeller` */; +/*!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 `itemTopSeller`() +BEGIN + DECLARE vCategoryFk INTEGER; + DECLARE vDone INT DEFAULT FALSE; + DECLARE rs CURSOR FOR + SELECT DISTINCT id + FROM vn.itemCategory + WHERE merchandise <> FALSE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + RESIGNAL; + END; + + DROP TABLE IF EXISTS tmp.topSellerMin; + CREATE TEMPORARY TABLE tmp.topSellerMin ENGINE = MEMORY + SELECT s.itemFk, SUM(s.quantity) AS total, v.tipo_id typeFk + FROM vn.sale s + INNER JOIN bs.ventas v ON v.Id_Movimiento = s.id + WHERE v.fecha BETWEEN TIMESTAMPADD(DAY, - 7, CURDATE()) AND CURDATE() + GROUP BY s.itemFk; + + DROP TABLE IF EXISTS tmp.topSeller; + CREATE TEMPORARY TABLE tmp.topSeller + ( + `id` int(11) NOT NULL DEFAULT '0', + `typeFk` smallint(5) unsigned NOT NULL, + `itemCategoryFk` int(10) unsigned NOT NULL, + `total` bigint(21) NOT NULL DEFAULT '0' + ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + + OPEN rs; + read_loop: LOOP + FETCH rs INTO vCategoryFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + INSERT INTO tmp.topSeller + SELECT tsm.itemFk, tsm.typeFk, it.categoryFk, tsm.total + FROM tmp.topSellerMin tsm + INNER JOIN vn.itemType it ON it.id = tsm.typeFk + WHERE it.categoryFk = vCategoryFk + ORDER BY tsm.itemFk ,tsm.total DESC + LIMIT 5; + + END LOOP; + CLOSE rs; + + SELECT i.name ,i.id, i.image, i.typeFk, it.categoryFk AS itemCategoryFk, + ic.name AS itemCategoryName, it.name AS itemTypeName, ts.total + FROM tmp.topSeller ts + INNER JOIN vn.item i ON i.id = ts.id + INNER JOIN vn.itemType it ON it.id = ts.typeFk + INNER JOIN vn.itemCategory ic ON ic.id = it.categoryFk; + + DROP TABLE IF EXISTS topSellerMin; + DROP TABLE IF EXISTS tmp.topSeller; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35469,6 +36099,32 @@ DELIMITER ; /*!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 `routeUpdateM3` */; +/*!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 `routeUpdateM3`(vRoute INT) +BEGIN + + UPDATE vn.route r + JOIN (SELECT Id_Ruta, SUM(volume) AS m3 + FROM vn2008.v_Movimientos_Volumen_shipping_charge + WHERE Id_Ruta = vRoute + ) v ON v.Id_Ruta = r.id + SET r.m3 = v.m3; + +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 `rutasAnalyze` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -38814,7 +39470,7 @@ BEGIN INSERT INTO vn.ticketLog SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); - IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> FALSE THEN + IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) SELECT id, vNewTicket, getWorker() FROM state @@ -39932,6 +40588,116 @@ DELIMITER ; /*!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 `travel_checkDates` */; +/*!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 `travel_checkDates`(vShipped DATE, vLanded DATE) +BEGIN +/** + * Checks the landing/shipment dates of travel, throws an error + * ir they are not correct. + * + * @param vShipped The shipment date + * @param vLanded The landing date + */ + IF vLanded < vShipped THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'Landing cannot be lesser than shipment'; + 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 `travel_doRecalc` */; +/*!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 `travel_doRecalc`() +BEGIN +/** + * Recounts the number of entries of changed travels. + */ + DECLARE vDone BOOL; + DECLARE vTravelFk INT; + DECLARE vTotalEntries INT; + + DECLARE cCur CURSOR FOR + SELECT travelFk FROM travelRecalc; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + OPEN cCur; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cCur INTO vTravelFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + SELECT COUNT(*) INTO vTotalEntries + FROM entry + WHERE travelFk = vTravelFk; + + UPDATE travel + SET totalEntries = vTotalEntries + WHERE id = vTravelFk; + + DELETE FROM travelRecalc WHERE travelFk = vTravelFk; + END LOOP; + + CLOSE cCur; +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 `travel_requestRecalc` */; +/*!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 `travel_requestRecalc`(vSelf INT) +proc: BEGIN +/** + * Adds a request to recount the number of entries for the travel. + * + * @param vSelf The travel reference + */ + IF vSelf IS NULL THEN + LEAVE proc; + END IF; + + INSERT IGNORE INTO travelRecalc SET travelFk = vSelf; +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 `typeTagMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -40404,10 +41170,7 @@ BEGIN AND isUpdated = FALSE AND vUserFk IN (0,userFk); - -- CALL workerTimeControlSetOrder; - /* CAP con parametros de fecha*/ - /* CAP es necesaraio, ya hay un orden en tmp.workerTimeControlSetOrder*/ - + -- Se inicia la tabla con todas las fechas posibles para cada uno de los trabajadores que han fichado en el rango de fechas. INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) SELECT w.userFk, tm.dated, b.business_id @@ -40426,7 +41189,7 @@ BEGIN UPDATE workerJourney wj JOIN workerTimeControl_Journey j ON wj.dated = j.dated AND wj.userFk = j.userFk SET wj.total = j.Journey, - wj.lunch = IF(j.Journey < 4,0,0.33) + wj.lunch = IF(j.Journey < 5,0,0.33) WHERE wj.dated BETWEEN vFromDate AND vToDate AND wj.isPaid = FALSE AND wj.isUpdated = FALSE @@ -40754,6 +41517,62 @@ DELIMITER ; /*!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 `worker_getHierarch` */; +/*!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 `worker_getHierarch`(vBoss INT) +BEGIN + DECLARE EXIT HANDLER FOR 1062 BEGIN + CALL util.throw('INFINITE_LOOP'); + END; + + DROP TEMPORARY TABLE IF EXISTS workerHierarch; + CREATE TEMPORARY TABLE workerHierarch + (PRIMARY KEY (workerFk)) + ENGINE = MEMORY + SELECT vBoss AS workerFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchList; + CREATE TEMPORARY TABLE tmp.workerHierarchList + (PRIMARY KEY (workerFk)) + ENGINE = MEMORY + SELECT vBoss AS workerFk, 0 AS isChecked; + + + WHILE (SELECT COUNT(*) FROM tmp.workerHierarchList WHERE NOT isChecked) > 0 DO + + INSERT INTO tmp.workerHierarchList + SELECT w.id, 0 + FROM worker w + JOIN workerHierarch wh ON wh.workerFk = w.bossFk; + + UPDATE tmp.workerHierarchList whl + JOIN workerHierarch wh ON wh.workerFk = whl.workerFk + SET whl.isChecked = 1; + + TRUNCATE workerHierarch; + + INSERT INTO workerHierarch + SELECT workerFk + FROM tmp.workerHierarchList + WHERE NOT isChecked; + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS workerHierarch; +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 `workingHours` */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -40943,7 +41762,8 @@ BEGIN am.description, am.deliveryMethodFk, TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - zi.isIncluded + zi.isIncluded, + z.warehouseFk FROM zoneGeo zgSon JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt JOIN zoneIncluded zi ON zi.geoFk = zgFather.id @@ -41048,6 +41868,7 @@ BEGIN AND zc.delivered = TIMESTAMPADD(DAY,z.travelingDays, vShipped) AND IF(vShipped = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) AND z.agencyModeFk = vAgencyMode + AND z.warehouseFk = vWarehouse ORDER BY zgFather.depth DESC) t GROUP BY zoneFk HAVING isIncluded > 0 @@ -41474,7 +42295,7 @@ CREATE TABLE `Agencias` ( PRIMARY KEY (`Id_Agencia`), KEY `Agencias` (`Agencia`), KEY `Vista` (`Vista`) -) ENGINE=InnoDB AUTO_INCREMENT=1225 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1226 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41493,7 +42314,7 @@ CREATE TABLE `Agencias_dits` ( `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idAgencia_dits`) -) ENGINE=InnoDB AUTO_INCREMENT=39610 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=39926 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41613,7 +42434,7 @@ CREATE TABLE `Articles` ( CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=347435 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=350407 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -41795,7 +42616,7 @@ CREATE TABLE `Articles_dits` ( KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=21429 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21430 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41818,7 +42639,7 @@ CREATE TABLE `Articles_nicho` ( KEY `Articles_nicho_wh_fk` (`warehouse_id`), CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=762800 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=777965 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41885,7 +42706,7 @@ CREATE TABLE `Bancos_poliza` ( KEY `Id_Poliza_Empresa_idx` (`empresa_id`), CONSTRAINT `Id_Banco_Poliza` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `Id_Poliza_Empresa` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41944,7 +42765,7 @@ CREATE TABLE `Cajas` ( KEY `warehouse_id` (`warehouse_id`), KEY `fk_Cajas_Proveedores_account1_idx` (`Proveedores_account_Id`), CONSTRAINT `Cajas_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=683784 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=688389 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42076,7 +42897,7 @@ CREATE TABLE `Clientes` ( CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`chanel_id`) REFERENCES `chanel` (`chanel_id`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientes_tipo_id`) REFERENCES `clientes_tipo` (`clientes_tipo_id`) ON UPDATE CASCADE, CONSTRAINT `typeFk` FOREIGN KEY (`typeFk`) REFERENCES `clientes_tipo` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=15696 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15790 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42333,8 +43154,8 @@ DROP TABLE IF EXISTS `Colas`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Colas` ( `Id_Cola` int(10) unsigned NOT NULL AUTO_INCREMENT, - `Id_Impresora` tinyint(3) unsigned DEFAULT '0', - `Id_Prioridad` tinyint(3) unsigned DEFAULT '2', + `Id_Impresora` tinyint(3) unsigned DEFAULT NULL, + `Id_Prioridad` tinyint(3) unsigned DEFAULT NULL, `Id_Informe` tinyint(3) unsigned DEFAULT '0', `Id_Estado` tinyint(3) unsigned DEFAULT '1', `Hora_Inicio` datetime DEFAULT NULL, @@ -42351,12 +43172,9 @@ CREATE TABLE `Colas` ( KEY `Id_Informe` (`Id_Informe`), KEY `Id_Prioridad` (`Id_Prioridad`), KEY `Id_Trabajador` (`Id_Trabajador`), - CONSTRAINT `Colas_ibfk_1` FOREIGN KEY (`Id_Informe`) REFERENCES `Informes` (`Id_Informe`) ON UPDATE CASCADE, - CONSTRAINT `Colas_ibfk_2` FOREIGN KEY (`Id_Estado`) REFERENCES `Estados` (`Id_Estado`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, - CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, - CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7497 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=40628 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42438,54 +43256,54 @@ CREATE TABLE `Compres` ( CONSTRAINT `Compres_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_2` FOREIGN KEY (`Id_Cubo`) REFERENCES `Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_3` FOREIGN KEY (`container_id`) REFERENCES `container` (`container_id`) ON UPDATE CASCADE, - CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=306987079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; + CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=309537117 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!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 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 ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Compres_beforeInsert` BEFORE INSERT ON `Compres` FOR EACH ROW bi:BEGIN +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeInsert` + BEFORE INSERT ON `Compres` + FOR EACH ROW +trig: BEGIN DECLARE vWarehouse INT; DECLARE vLanding DATE; - DECLARE vGroup INT; - DECLARE vIsBox BOOL; + DECLARE vGrouping INT; + DECLARE vGroupingMode TINYINT; IF @isModeInventory THEN - LEAVE bi; + LEAVE trig; END IF; - IF NEW.`grouping` = 0 THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'ERROR_GROUPING_ZERO'; - END IF; + CALL vn.buy_checkGrouping(NEW.`grouping`); - SELECT warehouse_id, landing INTO vWarehouse, vLanding - FROM Entradas E - JOIN travel T ON T.id = E.travel_id - WHERE E.Id_Entrada = NEW.Id_Entrada; + SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding + FROM vn.entry e + JOIN vn.travel t ON t.id = e.travelFk + WHERE e.id = NEW.Id_Entrada; - SELECT `grouping`, caja INTO vGroup, vIsBox - FROM Compres C - JOIN Entradas E USING(Id_Entrada) - JOIN travel T ON T.id = E.travel_id - WHERE T.landing <= vLanding - AND C.Id_Article = NEW.Id_Article - AND NOT C.Novincular - ORDER BY warehouse_id = vWarehouse DESC,landing DESC, Id_Compra DESC + SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE t.landed <= vLanding + AND b.itemFk = NEW.Id_Article + AND !b.isIgnored + ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC, b.id DESC LIMIT 1; IF NEW.`grouping` IS NULL THEN - SET NEW.`grouping` = IFNULL(vGroup, NEW.`grouping`); + SET NEW.`grouping` = vGrouping; END IF; IF NEW.caja IS NULL THEN - SET NEW.caja = IFNULL(vIsBox, NEW.caja); + SET NEW.caja = vGroupingMode; END IF; END */;; DELIMITER ; @@ -42498,56 +43316,21 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Compres_afterInsert` AFTER INSERT ON `Compres` FOR EACH ROW ai: BEGIN - DECLARE vWarehouse INT; - DECLARE vWarehouseOut INT; - DECLARE isMerchandise BOOLEAN; - - CALL stock.log_add('buy', NULL, NEW.Id_Compra); - - IF @isModeInventory THEN - LEAVE ai; - END IF; - - SELECT warehouse_id, warehouse_id_out INTO vWarehouse, vWarehouseOut - FROM Entradas E - JOIN travel T ON T.id = E.travel_id - WHERE E.Id_Entrada = NEW.Id_Entrada; - - -- Actualiza el volumen unitario - - SELECT k.merchandise INTO isMerchandise - FROM vn.itemCategory k - JOIN vn.itemType it ON it.categoryFk = k.id - JOIN vn.item i ON i.typeFk = it.id - WHERE i.id = NEW.Id_Article; - - If isMerchandise THEN - REPLACE bi.rotacion(Id_Article, warehouse_id, cm3) - VALUES (NEW.Id_Article, vWarehouse, vn2008.cm3_unidad(NEW.Id_Compra)); - END IF; - - IF (SELECT fuente FROM warehouse WHERE id = vWarehouseOut AND id <> 13) AND - (SELECT has_notify_passport(NEW.Id_Article,NEW.Id_Compra)) - THEN - CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing, NEW.Id_Compra); - CALL insert_producer_plantpassport(NEW.Id_Compra); - END IF; -/* - IF (SELECT isFeedStock - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseOutFk - WHERE b.id = NEW.Id_Compra) - THEN - UPDATE vn.item i SET i.lastPrice = NEW.Costefijo; - END IF; -*/ +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_afterInsert` + AFTER INSERT ON `Compres` + FOR EACH ROW +trig: BEGIN + CALL stock.log_add('buy', NULL, NEW.Id_Compra); + + IF @isModeInventory THEN + LEAVE trig; + END IF; + + CALL vn.buy_afterUpsert(NEW.Id_Compra); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -42559,15 +43342,17 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Compres_beforeUpdate` BEFORE UPDATE ON `Compres` FOR EACH ROW BEGIN - IF NEW.`grouping` = 0 AND OLD.`grouping` <> 0 THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT ='ERROR_GROUPING_ZERO'; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeUpdate` + BEFORE UPDATE ON `Compres` + FOR EACH ROW +BEGIN + IF !(NEW.`grouping` <=> OLD.`grouping`) THEN + CALL vn.buy_checkGrouping(NEW.`grouping`); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -42579,50 +43364,33 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Compres_afterUpdate` AFTER UPDATE ON `Compres` FOR EACH ROW bloc: BEGIN - DECLARE vWarehouse INT; - DECLARE vWarehouseOut INT; - DECLARE isMerchandise BOOLEAN; - - CALL stock.log_add('buy', OLD.Id_Compra, NEW.Id_Compra); - - IF @disableTriggers THEN - LEAVE bloc; - END IF; - - SELECT warehouse_id, warehouse_id_out INTO vWarehouse, vWarehouseOut - FROM Entradas E - JOIN travel T ON T.id = E.travel_id - WHERE E.Id_Entrada = NEW.Id_Entrada; - - SELECT k.merchandise INTO isMerchandise - FROM vn.itemCategory k - JOIN vn.itemType it ON it.categoryFk = k.id - JOIN vn.item i ON i.typeFk = it.id - WHERE i.id = NEW.Id_Article; - - IF NOT (NEW.weight <=> OLD.weight) THEN - -- Peso en gramos volumen en cm3 - UPDATE Articles - SET density = (NEW.weight * NEW.packing) / (cm3_2(NEW.Id_Cubo, NEW.Id_Article) / 1000) - WHERE Id_Article = NEW.Id_Article; - END IF; - - IF isMerchandise AND NOT(NEW.Id_Cubo <=> OLD.Id_Cubo AND NEW.Id_Entrada <=> OLD.Id_Entrada) THEN - REPLACE bi.rotacion(Id_Article, warehouse_id, cm3) - VALUES (NEW.Id_ARticle, vWarehouse, cm3_unidad(NEW.Id_Compra)); - END IF; - - IF (SELECT fuente FROM warehouse where id = vWarehouseOut AND id <> 13) AND - (SELECT has_notify_passport(NEW.Id_Article,NEW.Id_Compra)) > 0 - THEN - CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing,NEW.Id_Compra); - CALL insert_producer_plantpassport(NEW.Id_Compra); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_afterUpdate` + AFTER UPDATE ON `Compres` + FOR EACH ROW +trig: BEGIN + IF !(NEW.Id_Compra <=> OLD.Id_Compra) + OR !(NEW.Id_Entrada <=> OLD.Id_Entrada) + OR !(NEW.Id_Article <=> OLD.Id_Article) + OR !(NEW.Cantidad <=> OLD.Cantidad) + OR !(NEW.odbc_date <=> OLD.odbc_date) THEN + CALL stock.log_add('buy', OLD.Id_Compra, NEW.Id_Compra); + END IF; + + IF @isModeInventory THEN + LEAVE trig; + END IF; + + CALL vn.buy_afterUpsert(NEW.Id_Compra); + + IF !(NEW.weight <=> OLD.weight) THEN + UPDATE vn.item + SET density = (NEW.weight * NEW.packing) / (cm3_2(NEW.Id_Cubo, NEW.Id_Article) / 1000) + WHERE id = NEW.Id_Article; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -42634,22 +43402,38 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET collation_connection = utf8mb4_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Compres_afterDelete` AFTER DELETE ON `Compres` FOR EACH ROW BEGIN - DECLARE vProvider INT; - - CALL stock.log_add('buy', OLD.Id_Compra, NULL); - - SELECT Id_Proveedor INTO vProvider - FROM Entradas WHERE Id_Entrada = OLD.Id_Entrada; - - IF OLD.Vida > 0 AND vProvider <> 4 THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'ERROR_DELETING_LIFE'; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_beforeDelete` + BEFORE DELETE ON `Compres` + FOR EACH ROW +BEGIN + IF OLD.Vida > 0 THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'A buy from which labels have been printed cannot be deleted'; + 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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `buy_afterDelete` + AFTER DELETE ON `Compres` + FOR EACH ROW +BEGIN + CALL stock.log_add('buy', OLD.Id_Compra, NULL); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -42693,7 +43477,7 @@ CREATE TABLE `Compres_ok` ( KEY `Id_Movimiento` (`Id_Compra`), KEY `Id_Accion` (`Id_Accion`), CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=27968 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=27969 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42737,7 +43521,7 @@ CREATE TABLE `Consignatarios` ( CONSTRAINT `Consignatarios_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_4` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=27567 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=27726 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -42865,7 +43649,7 @@ CREATE TABLE `Contactos` ( PRIMARY KEY (`Id_Contacto`), KEY `Telefono` (`Telefono`), KEY `Movil` (`Movil`) -) ENGINE=InnoDB AUTO_INCREMENT=2701 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2705 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43062,7 +43846,7 @@ CREATE TABLE `Entradas` ( CONSTRAINT `Entradas_ibfk_1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_6` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_7` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=166666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB AUTO_INCREMENT=168096 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43073,13 +43857,12 @@ CREATE TABLE `Entradas` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Entradas_beforeInsert` - BEFORE INSERT ON `Entradas` FOR EACH ROW -BEGIN - IF (SELECT cuenta LIKE '___4______' FROM Proveedores WHERE Id_Proveedor = NEW.Id_Proveedor) THEN - SET NEW.Id_Moneda = 2; - END IF; - -- Actualizar travel.totalEntries +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `entry_beforeInsert` + BEFORE INSERT ON `Entradas` + FOR EACH ROW +BEGIN + SET NEW.Id_Moneda = vn.entry_getCurrency(NEW.Id_Moneda, NEW.Id_Proveedor); + SET NEW.comision = vn.entry_calcCommission(NEW.comision, NEW.travel_id, NEW.Id_Moneda); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43095,51 +43878,66 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Entradas_beforeUpdate` - BEFORE UPDATE ON `Entradas` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`entry_afterInsert` + AFTER INSERT ON `Entradas` + FOR EACH ROW BEGIN - IF (SELECT Id_Entrada FROM Entradas_Auto WHERE Id_Entrada = NEW.Id_Entrada) AND (NEW.travel_id <> OLD.travel_id) THEN - IF - (SELECT warehouse_id FROM travel WHERE id = NEW.travel_id) <> (SELECT warehouse_id FROM travel WHERE id = OLD.travel_id) OR - (SELECT warehouse_id_out FROM travel WHERE id = NEW.travel_id) <> (SELECT warehouse_id_out FROM travel WHERE id = OLD.travel_id) - THEN - SET NEW.travel_id = OLD.travel_id; + CALL vn.travel_requestRecalc(NEW.travel_id); +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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `entry_beforeUpdate` + BEFORE UPDATE ON `Entradas` + FOR EACH ROW +BEGIN + DECLARE vIsClone BOOL; + DECLARE vHasDistinctWarehouses BOOL; + + IF !(NEW.travel_id <=> OLD.travel_id) THEN + SELECT COUNT(*) > 0 INTO vIsClone + FROM vn2008.Entradas_Auto WHERE Id_Entrada = NEW.Id_Entrada; + + SELECT !(o.warehouseInFk <=> n.warehouseInFk) + OR !(o.warehouseOutFk <=> n.warehouseOutFk) + INTO vHasDistinctWarehouses + FROM vn.travel o, vn.travel n + WHERE o.id = OLD.travel_id + AND n.id = NEW.travel_id; + + IF vIsClone AND vHasDistinctWarehouses THEN + SIGNAL SQLSTATE '45000' + SET MESSAGE_TEXT = 'A cloned entry cannot be moved to travel with different warehouses'; END IF; END IF; - IF (NEW.gestdoc_id IS NOT NULL) AND (NEW.gestdoc_id <> OLD.gestdoc_id) THEN - UPDATE - recibida_entrada re - INNER JOIN recibida r ON re.recibida_id = r.id - INNER JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada - SET r.gestdoc_id = e.gestdoc_id - WHERE - e.Id_Entrada = NEW.Id_Entrada - AND r.gestdoc_id IS NULL; - END IF; - - IF NEW.anotadoencaja <> OLD.anotadoencaja THEN - INSERT INTO Entradas_dits (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) - VALUES (105,get_Trabajador(),NEW.Id_Entrada,OLD.anotadoencaja,NEW.anotadoencaja); - END IF; - - IF NEW.Pedida <> FALSE AND OLD.Pedida = FALSE AND - (SELECT COUNT(*) FROM travel WHERE id = NEW.travel_id AND warehouse_id = 5 AND warehouse_id_out = 1) - THEN - INSERT INTO mail(`to`, reply_to, subject, text) - VALUES('madrid@verdnatura.es', 'logistica@verdnatura.es', - 'Preparacion movimiento Madrid', - CONCAT('Se ha empezado a preparar el movimiento ',NEW.Id_Entrada)); + IF !(NEW.Id_Proveedor <=> OLD.Id_Proveedor) THEN + SET NEW.Id_Moneda = vn.entry_getCurrency(NEW.Id_Moneda, NEW.Id_Proveedor); END IF; - IF NEW.Id_Proveedor <> OLD.Id_Proveedor THEN - IF (SELECT cuenta LIKE '___4______' FROM Proveedores WHERE Id_Proveedor = NEW.Id_Proveedor) THEN - SET NEW.Id_Moneda = 2; - END IF; + IF !(NEW.travel_id <=> OLD.travel_id) + OR !(NEW.Id_Moneda <=> OLD.Id_Moneda) THEN + SET NEW.comision = vn.entry_calcCommission(NEW.comision, NEW.travel_id, NEW.Id_Moneda); END IF; - - IF NEW.Id_Moneda = 2 THEN - SET NEW.comision = getComision(NEW.Id_Entrada, NEW.Id_Moneda); + + IF !(ABS(NEW.anotadoencaja) <=> ABS(OLD.anotadoencaja)) THEN + INSERT INTO vn2008.Entradas_dits SET + idaccion_dits = 105, + Id_Trabajador = vn.getWorker(), + Id_Ticket = NEW.Id_Entrada, + value_old = OLD.anotadoencaja, + value_new = NEW.anotadoencaja; END IF; END */;; DELIMITER ; @@ -43156,10 +43954,20 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Entradas_afterUpdate` - AFTER UPDATE ON `Entradas` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `entry_afterUpdate` + AFTER UPDATE ON `Entradas` + FOR EACH ROW BEGIN - CALL stock.log_add('entry', OLD.Id_Entrada, NEW.Id_Entrada); + IF !(NEW.Id_Entrada <=> OLD.Id_Entrada) + OR !(NEW.travel_id <=> OLD.travel_id) + OR !(NEW.Redada <=> OLD.Redada) THEN + CALL stock.log_add('entry', OLD.Id_Entrada, NEW.Id_Entrada); + END IF; + + IF !(NEW.travel_id <=> OLD.travel_id) THEN + CALL vn.travel_requestRecalc(OLD.travel_id); + CALL vn.travel_requestRecalc(NEW.travel_id); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43175,10 +43983,31 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Entradas_afterDelete` - AFTER DELETE ON `Entradas` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`entry_beforeDelete` + BEFORE DELETE ON `Entradas` + FOR EACH ROW +BEGIN + DELETE FROM vn.buy WHERE entryFk = OLD.Id_Entrada; +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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`entry_afterDelete` + AFTER DELETE ON `Entradas` + FOR EACH ROW BEGIN - CALL stock.log_add('entry', OLD.Id_Entrada, NULL); + CALL vn.travel_requestRecalc(OLD.travel_id); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -43212,7 +44041,7 @@ CREATE TABLE `Entradas_dits` ( `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, - `Id_Trabajador` int(11) NOT NULL, + `Id_Trabajador` int(11) DEFAULT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idEntrada_dits`), @@ -43222,7 +44051,7 @@ CREATE TABLE `Entradas_dits` ( CONSTRAINT `Entradas_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3533707 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3571464 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43240,7 +44069,7 @@ CREATE TABLE `Entradas_kop` ( PRIMARY KEY (`Id_Entradas_kop`), KEY `entradas_entradas_kop_idx` (`Id_Entrada`), CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=329 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +) ENGINE=InnoDB AUTO_INCREMENT=489 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43328,7 +44157,7 @@ CREATE TABLE `Equipos` ( PRIMARY KEY (`id`), KEY `trabajador_id` (`trabajador_id`), CONSTRAINT `Equipos_ibfk_1` FOREIGN KEY (`trabajador_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=209 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=210 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43445,7 +44274,7 @@ CREATE TABLE `Facturas` ( `Fecha` date DEFAULT NULL, `Importe` decimal(12,2) DEFAULT '0.00', `Vencimiento` datetime DEFAULT NULL, - `Id_Banco` int(11) DEFAULT '0', + `Id_Banco` int(11) DEFAULT NULL, `Id_Cliente` int(11) DEFAULT '0', `Id_Remesa` int(11) DEFAULT NULL, `Remesar` tinyint(1) NOT NULL DEFAULT '0', @@ -43484,7 +44313,7 @@ CREATE TABLE `Facturas` ( CONSTRAINT `Facturas_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_bank_id` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=498230 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=498319 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43654,7 +44483,7 @@ CREATE TABLE `Greuges` ( `Id_Cliente` int(10) unsigned NOT NULL, `Comentario` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Importe` decimal(10,2) NOT NULL, - `Fecha` datetime NOT NULL, + `Fecha` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `Greuges_type_id` int(11) DEFAULT NULL, `Id_Ticket` int(11) DEFAULT NULL, @@ -43663,7 +44492,7 @@ CREATE TABLE `Greuges` ( KEY `Id_Ticket_Greuge_Ticket_idx` (`Id_Ticket`), CONSTRAINT `Id_Ticket_Greuge_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuges_type_fk` FOREIGN KEY (`Greuges_type_id`) REFERENCES `Greuges_type` (`Greuges_type_id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3303917 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT; +) ENGINE=InnoDB AUTO_INCREMENT=3353601 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43864,7 +44693,7 @@ CREATE TABLE `Movimientos` ( KEY `itemFk_ticketFk` (`Id_Article`,`Id_Ticket`), CONSTRAINT `Movimientos_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `movement_ticket_id` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24400027 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=24546128 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43875,8 +44704,9 @@ CREATE TABLE `Movimientos` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Movimientos_afterInsert` - AFTER INSERT ON `Movimientos` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_afterInsert` + AFTER INSERT ON `Movimientos` + FOR EACH ROW BEGIN CALL stock.log_add('sale', NULL, NEW.Id_Movimiento); END */;; @@ -43894,14 +44724,42 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Movimientos_beforeUpdate` - BEFORE UPDATE ON `Movimientos` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_beforeUpdate` + BEFORE UPDATE ON `Movimientos` + FOR EACH ROW BEGIN IF NEW.Descuento > 100 THEN SET NEW.Descuento = 0; 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 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_afterUpdate` + AFTER UPDATE ON `Movimientos` + FOR EACH ROW +BEGIN + IF !(NEW.Id_Movimiento <=> OLD.Id_Movimiento) + OR !(NEW.Id_Ticket <=> OLD.Id_Movimiento) + OR !(NEW.Id_Article <=> OLD.Id_Article) + OR !(NEW.Cantidad <=> OLD.Cantidad) + OR !(NEW.odbc_date <=> OLD.odbc_date) + OR !(NEW.OK <=> OLD.OK) THEN + CALL stock.log_add('sale', OLD.Id_Movimiento, NEW.Id_Movimiento); + END IF; - IF OLD.Id_Ticket <> NEW.Id_Ticket THEN + IF !(OLD.Id_Ticket <=> NEW.Id_Ticket) THEN UPDATE Ordenes SET ticketFk = NEW.Id_Ticket WHERE Id_Movimiento = NEW.Id_Movimiento; END IF; @@ -43920,27 +44778,9 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Movimientos_afterUpdate` - AFTER UPDATE ON `Movimientos` FOR EACH ROW -BEGIN - CALL stock.log_add('sale', OLD.Id_Movimiento, NEW.Id_Movimiento); -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 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 ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Movimientos_afterDelete` - AFTER DELETE ON `Movimientos` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `sale_afterDelete` + AFTER DELETE ON `Movimientos` + FOR EACH ROW BEGIN CALL stock.log_add('sale', OLD.Id_Movimiento, NULL); END */;; @@ -44023,7 +44863,7 @@ CREATE TABLE `Movimientos_mark` ( KEY `Id_Movimiento` (`Id_Movimiento`), KEY `fgnStateFk_idx` (`stateFk`), CONSTRAINT `fgnStateFk` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=16262463 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=16634920 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44128,7 +44968,7 @@ CREATE TABLE `Ordenes` ( CONSTRAINT `fgnAtender` FOREIGN KEY (`atenderFk`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fgnRequester` FOREIGN KEY (`requesterFk`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fgnTicket` FOREIGN KEY (`ticketFk`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=43183 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=43961 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44232,7 +45072,7 @@ CREATE TABLE `Pagares` ( KEY `empresa_id` (`kk_empresa_id`), KEY `pago_id` (`pago_id`), CONSTRAINT `Pagares_ibfk_2` FOREIGN KEY (`pago_id`) REFERENCES `pago` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2865 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2868 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44358,7 +45198,7 @@ CREATE TABLE `Proveedores` ( CONSTRAINT `pay_dem_id` FOREIGN KEY (`pay_dem_id`) REFERENCES `pay_dem` (`id`) ON UPDATE CASCADE, CONSTRAINT `pay_met_id` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2758 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2775 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44384,7 +45224,7 @@ CREATE TABLE `Proveedores_account` ( KEY `fk_Proveedores_account_entity1_idx` (`entity_id`), KEY `fk_banco_prov_account_idx` (`Id_Banco`), CONSTRAINT `fk_banco_prov_account` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=777 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=784 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44477,7 +45317,7 @@ CREATE TABLE `Recibos` ( CONSTRAINT `Recibos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Recibos_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=560485 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=563772 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44568,7 +45408,7 @@ CREATE TABLE `Relaciones` ( KEY `Id_Contacto` (`Id_Contacto`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Id_Cliente` (`Id_Cliente`) -) ENGINE=InnoDB AUTO_INCREMENT=2700 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2706 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44588,7 +45428,7 @@ CREATE TABLE `Remesas` ( KEY `empresa_id` (`empresa_id`), CONSTRAINT `Remesas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1262 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1274 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44613,7 +45453,7 @@ CREATE TABLE `Reservas` ( PRIMARY KEY (`Id_Reserva`), KEY `Id_1` (`Id_Ticket`), KEY `Id_Article` (`Id_Article`) -) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=669 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44644,7 +45484,7 @@ CREATE TABLE `Rutas` ( KEY `Fecha` (`Fecha`), KEY `gestdoc_id` (`gestdoc_id`), CONSTRAINT `Rutas_ibfk_1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=51587 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=52190 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44653,6 +45493,28 @@ CREATE TABLE `Rutas` ( /*!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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Rutas_BEFORE_UPDATE` BEFORE UPDATE ON `Rutas` FOR EACH ROW +BEGIN + IF NEW.ok <> FALSE AND OLD.ok = FALSE THEN + SET NEW.m3 = (SELECT SUM(volume) + FROM vn2008.v_Movimientos_Volumen_shipping_charge + WHERE Id_Ruta = NEW.Id_Ruta); + 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 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 = '' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Rutas_au` AFTER UPDATE ON `Rutas` FOR EACH ROW @@ -44797,7 +45659,7 @@ CREATE TABLE `Saldos_Prevision` ( KEY `empresa_prevision_idx` (`empresa_id`), CONSTRAINT `banco_prevision` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `empresa_prevision` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=193 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; +) ENGINE=InnoDB AUTO_INCREMENT=205 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44832,7 +45694,7 @@ CREATE TABLE `Split_lines` ( KEY `Id_Compra` (`Id_Compra`), CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Split_lines_ibfk_1` FOREIGN KEY (`Id_Split`) REFERENCES `Splits` (`Id_Split`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=352800 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=353542 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44850,7 +45712,7 @@ CREATE TABLE `Splits` ( `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Split`), KEY `Id_Entrada` (`Id_Entrada`) -) ENGINE=InnoDB AUTO_INCREMENT=36630 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36641 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44878,7 +45740,7 @@ CREATE TABLE `Stockcontrol` ( CONSTRAINT `Stockcontrol_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_2` FOREIGN KEY (`Id_Remitente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_3` FOREIGN KEY (`Id_Solver`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24045 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=24055 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44936,7 +45798,7 @@ CREATE TABLE `Tickets` ( CONSTRAINT `Tickets_ibfk_9` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON UPDATE CASCADE, CONSTRAINT `ticket_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `tickets_fk10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2236755 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2256546 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44947,8 +45809,9 @@ CREATE TABLE `Tickets` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Tickets_afterInsert` - AFTER INSERT ON `Tickets` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ticket_afterInsert` + AFTER INSERT ON `Tickets` + FOR EACH ROW BEGIN DECLARE vEmployee INT; @@ -44988,8 +45851,9 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Tickets_beforeUpdate` - BEFORE UPDATE ON `Tickets` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ticket_beforeUpdate` + BEFORE UPDATE ON `Tickets` + FOR EACH ROW BEGIN DECLARE vAgency INT; DECLARE vEmployee INT; @@ -45049,16 +45913,21 @@ 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 ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Tickets_afterUpdate` - AFTER UPDATE ON `Tickets` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `ticket_afterUpdate` + AFTER UPDATE ON `Tickets` + FOR EACH ROW BEGIN - CALL stock.log_add('ticket', OLD.Id_Ticket, NEW.Id_Ticket); + IF !(NEW.Id_Ticket <=> OLD.Id_Ticket) + OR !(NEW.warehouse_id <=> OLD.warehouse_id) + OR !(NEW.Fecha <=> OLD.Fecha) THEN + CALL stock.log_add('ticket', OLD.Id_Ticket, NEW.Id_Ticket); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45074,10 +45943,11 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `Tickets_afterDelete` - AFTER DELETE ON `Tickets` FOR EACH ROW +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ticket_beforeDelete` + BEFORE DELETE ON `vn2008`.`Tickets` + FOR EACH ROW BEGIN - CALL stock.log_add('ticket', OLD.Id_Ticket, NULL); + DELETE FROM vn.sale WHERE ticketFk = OLD.Id_Ticket; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -45107,7 +45977,7 @@ CREATE TABLE `Tickets_dits` ( CONSTRAINT `Tickets_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=64590237 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=64638685 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45188,7 +46058,7 @@ CREATE TABLE `Tickets_turno` ( `weekDay` tinyint(1) DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2236682 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2253858 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45258,7 +46128,7 @@ CREATE TABLE `Tipos` ( CONSTRAINT `Tipos_ibfk_2` FOREIGN KEY (`roleCodeFk`) REFERENCES `account`.`role` (`name`) ON UPDATE CASCADE, CONSTRAINT `Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `warehouseFk5` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=266 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; +) ENGINE=InnoDB AUTO_INCREMENT=269 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45346,7 +46216,7 @@ CREATE TABLE `Trabajadores` ( KEY `sub` (`sub`), CONSTRAINT `Clientes` FOREIGN KEY (`Id_Cliente_Interno`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1295 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1297 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45481,7 +46351,7 @@ CREATE TABLE `Vehiculos_consumo` ( PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `Vehiculos` (`Id_Vehiculo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11122 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; +) ENGINE=InnoDB AUTO_INCREMENT=11249 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45595,7 +46465,7 @@ CREATE TABLE `XDiario` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3786200 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3795836 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45681,7 +46551,7 @@ CREATE TABLE `account_conciliacion` ( KEY `fg_accconciliacion_key1_idx` (`Id_Proveedores_account`), KEY `index_id_calculated` (`id_calculated`), CONSTRAINT `fg_key1_accountconc` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24789 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=25763 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45848,7 +46718,7 @@ CREATE TABLE `agency_hour` ( CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5609 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5656 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46014,7 +46884,7 @@ CREATE TABLE `albaran` ( CONSTRAINT `fk_albaran_empresa1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3176 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3209 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46092,7 +46962,7 @@ CREATE TABLE `awb` ( CONSTRAINT `awbInvoiceIn` FOREIGN KEY (`invoiceInFk`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `awbTransitoryFk` FOREIGN KEY (`transitario_id`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3180 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3206 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46258,7 +47128,7 @@ CREATE TABLE `awb_component` ( CONSTRAINT `awb_component_` FOREIGN KEY (`awb_component_type_id`) REFERENCES `awb_component_type` (`awb_component_type_id`) ON UPDATE CASCADE, CONSTRAINT `awb_role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=22665 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23406 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46292,7 +47162,7 @@ CREATE TABLE `awb_component_template` ( CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk1` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE, CONSTRAINT `role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=752 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=783 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46373,7 +47243,7 @@ CREATE TABLE `awb_gestdoc` ( KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2794 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2820 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46492,7 +47362,7 @@ CREATE TABLE `barcodes` ( UNIQUE KEY `Id_Article_2` (`Id_Article`,`code`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=40222 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=40412 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46636,7 +47506,7 @@ CREATE TABLE `buy_edi` ( KEY `barcode` (`barcode`), KEY `fec` (`fec`), KEY `putOrderFk` (`putOrderFk`) -) ENGINE=InnoDB AUTO_INCREMENT=895923 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=914073 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46852,7 +47722,7 @@ CREATE TABLE `cl_act` ( CONSTRAINT `cl_act_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_4` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=105646 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=106818 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46886,7 +47756,7 @@ CREATE TABLE `cl_cau` ( CONSTRAINT `cl_cau_ibfk_7` FOREIGN KEY (`cl_mot_id`) REFERENCES `cl_mot` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_8` FOREIGN KEY (`cl_con_id`) REFERENCES `cl_con` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_9` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=54909 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=55411 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46936,7 +47806,7 @@ CREATE TABLE `cl_det` ( KEY `cl_main_id` (`cl_main_id`), CONSTRAINT `cl_det_ibfk_7` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_8` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=140841 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=141898 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47024,7 +47894,7 @@ CREATE TABLE `cl_main` ( CONSTRAINT `cl_main_ibfk_4` FOREIGN KEY (`cl_dep_id`) REFERENCES `cl_dep` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_5` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_main_ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `Tickets` (`Id_Ticket`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=62135 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB AUTO_INCREMENT=62732 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47140,7 +48010,7 @@ CREATE TABLE `client_observation` ( KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `client_observation_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `client_observation_ibfk_2` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=74314 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=74758 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47308,7 +48178,7 @@ CREATE TABLE `consignatarios_observation` ( `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`consignatarios_observation_id`), UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`) -) ENGINE=InnoDB AUTO_INCREMENT=3780 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB AUTO_INCREMENT=3821 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47390,7 +48260,7 @@ CREATE TABLE `credit` ( KEY `credit_ClienteFk` (`Id_Cliente`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=76440 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=77168 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47533,13 +48403,13 @@ CREATE TABLE `device_user` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `dhl` +-- Table structure for table `dhlKk` -- -DROP TABLE IF EXISTS `dhl`; +DROP TABLE IF EXISTS `dhlKk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dhl` ( +CREATE TABLE `dhlKk` ( `codigo_postal` mediumint(8) unsigned NOT NULL, `frecuencia` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`codigo_postal`) @@ -47865,7 +48735,7 @@ CREATE TABLE `entity` ( UNIQUE KEY `bic_UNIQUE` (`bic`), KEY `fg_entity1_idx` (`pais_id`), CONSTRAINT `fg_entity1` FOREIGN KEY (`pais_id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=30035 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; +) ENGINE=InnoDB AUTO_INCREMENT=30036 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47905,7 +48775,7 @@ CREATE TABLE `escritos_det` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `escritos_det_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=17395 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=17463 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47935,7 +48805,7 @@ CREATE TABLE `expeditions` ( KEY `index4` (`ticket_id`), CONSTRAINT `Id_Agencia` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3011487 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3041462 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48179,7 +49049,7 @@ CREATE TABLE `gestdoc` ( UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`), KEY `trabajador_id` (`trabajador_id`), KEY `warehouse_id` (`warehouse_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1227244 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; +) ENGINE=InnoDB AUTO_INCREMENT=1239493 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48257,7 +49127,13 @@ CREATE TABLE `gesttip` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tipo` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `path` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`id`) + `writeRoleFk` int(10) unsigned DEFAULT NULL, + `readRoleFk` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `readRoleFk` (`readRoleFk`), + KEY `writeRoleFk` (`writeRoleFk`), + CONSTRAINT `readRoleFk` FOREIGN KEY (`readRoleFk`) REFERENCES `account`.`role` (`id`), + CONSTRAINT `writeRoleFk` FOREIGN KEY (`writeRoleFk`) REFERENCES `account`.`role` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -48378,7 +49254,7 @@ CREATE TABLE `intrastat_data` ( KEY `recibida` (`recibida_id`), CONSTRAINT `intrastat_data_ibfk_1` FOREIGN KEY (`intrastat_id`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `intrastat_data_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=75202 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=75627 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -48673,7 +49549,7 @@ CREATE TABLE `mail` ( `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1699019 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1716246 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -48731,7 +49607,7 @@ CREATE TABLE `mandato` ( CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`idmandato_tipo`) REFERENCES `mandato_tipo` (`idmandato_tipo`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=16403 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=16433 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48940,7 +49816,7 @@ CREATE TABLE `pago` ( CONSTRAINT `pago_moneda` FOREIGN KEY (`id_moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `pago_pay_met` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`id_proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=48630 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=48841 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49437,7 +50313,7 @@ CREATE TABLE `price_fixed` ( KEY `date_end` (`date_end`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `price_fixed_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=62158 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=62548 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49499,7 +50375,7 @@ CREATE TABLE `producer` ( `visible` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`producer_id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=9102 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9646 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -49668,7 +50544,7 @@ CREATE TABLE `recibida` ( CONSTRAINT `recibida_ibfk_5` FOREIGN KEY (`cplusInvoiceType472Fk`) REFERENCES `vn`.`cplusInvoiceType472` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_6` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_7` FOREIGN KEY (`cplusTrascendency472Fk`) REFERENCES `vn`.`cplusTrascendency472` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=80790 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=81370 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50257,7 +51133,7 @@ CREATE TABLE `recibida_iva` ( CONSTRAINT `recibida_iva_ibfk_2` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_5` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_6` FOREIGN KEY (`gastos_id`) REFERENCES `Gastos` (`Id_Gasto`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=130627 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=132318 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -50280,7 +51156,7 @@ CREATE TABLE `recibida_vencimiento` ( KEY `banco_id` (`banco_id`), CONSTRAINT `recibida_vencimiento_ibfk_6` FOREIGN KEY (`banco_id`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibida_vencimiento_ibfk_7` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=128315 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=130058 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50323,7 +51199,7 @@ CREATE TABLE `recovery` ( KEY `cliente_idx` (`Id_Cliente`), CONSTRAINT `cliente333` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `cliente_cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=298 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a '; +) ENGINE=InnoDB AUTO_INCREMENT=299 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -50505,7 +51381,7 @@ CREATE TABLE `scan` ( `name` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=91574 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +) ENGINE=InnoDB AUTO_INCREMENT=93136 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -50546,7 +51422,7 @@ CREATE TABLE `scan_line` ( PRIMARY KEY (`scan_line_id`), KEY `id_scan_id_idx` (`scan_id`), CONSTRAINT `id_scan_id` FOREIGN KEY (`scan_id`) REFERENCES `scan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1140666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1163000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -50568,7 +51444,7 @@ CREATE TABLE `sharingcart` ( KEY `Suplent` (`Id_Suplente`), CONSTRAINT `Suplent_key` FOREIGN KEY (`Id_Suplente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2033 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2052 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50796,7 +51672,7 @@ CREATE TABLE `tarifas` ( PRIMARY KEY (`tarifa_id`), KEY `tarifa_warehouse` (`warehouse_id`), CONSTRAINT `tarifa_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=176 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -51010,7 +51886,7 @@ CREATE TABLE `ticket_observation` ( KEY `observation_type_id` (`observation_type_id`), CONSTRAINT `ticket_observation_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticket_observation_ibfk_2` FOREIGN KEY (`observation_type_id`) REFERENCES `observation_type` (`observation_type_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1341101 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=1355598 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -51134,7 +52010,7 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouse_id_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores_cargueras` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=128896 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=130347 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51146,16 +52022,10 @@ CREATE TABLE `travel` ( /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travel_beforeInsert` - BEFORE INSERT ON `travel` FOR EACH ROW -BEGIN - -- Evita fechas absurdas - - IF NEW.landing < TIMESTAMPADD(YEAR, -10, CURDATE()) - OR NEW.shipment < TIMESTAMPADD(YEAR, -10, CURDATE()) - OR NEW.landing < NEW.shipment - THEN - SET NEW.landing = NULL; - END IF; + BEFORE INSERT ON `travel` + FOR EACH ROW +BEGIN + CALL vn.travel_checkDates(NEW.shipment, NEW.landing); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51172,33 +52042,12 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travel_beforeUpdate` - BEFORE UPDATE ON `travel` FOR EACH ROW -BEGIN - DECLARE trabajador INT; - - -- Volem permetre dates iguals de eixida i arribada per al magatzems filiats en warehouse_tree - - IF NEW.landing < NEW.shipment THEN - SET NEW.shipment = NEW.landing; - END IF; - - -- Evita fechas absurdas - - IF NEW.landing < TIMESTAMPADD(YEAR,-10, CURDATE()) - OR NEW.shipment < TIMESTAMPADD(YEAR,-10,CURDATE()) - THEN - SET NEW.landing = NULL; - END IF; - - -- Ditacio para averiguar cuando se marca como delivered = true los travels, pues aparecen por la mañana sin explicacion - - IF ABS(NEW.delivered) > ABS(OLD.delivered) - THEN - SELECT Id_Trabajador INTO trabajador - FROM Trabajadores where user_id = account.userGetId(); - - INSERT INTO travel_dits (idaccion_dits, Id_Trabajador, Id_Ticket, value_old, value_new) - VALUES (89/*Cambia delivered*/, IFNULL(trabajador, 20), NEW.id,OLD.delivered, CONCAT(NEW.delivered,' desde ' , user())); + BEFORE UPDATE ON `travel` + FOR EACH ROW +BEGIN + IF !(NEW.landing <=> OLD.landing) + OR !(NEW.shipment <=> OLD.shipment) THEN + CALL vn.travel_checkDates(NEW.shipment, NEW.landing); END IF; END */;; DELIMITER ; @@ -51216,34 +52065,26 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travel_afterUpdate` - AFTER UPDATE ON `travel` FOR EACH ROW -BEGIN + AFTER UPDATE ON `travel` + FOR EACH ROW +BEGIN CALL stock.log_add('travel', OLD.id, NEW.id); - - IF NEW.shipment != OLD.shipment THEN - UPDATE Entradas - SET comision = getComision(Id_Entrada, Id_Moneda) - WHERE travel_id = NEW.id; + + IF !(NEW.shipment <=> OLD.shipment) THEN + UPDATE vn.entry + SET commission = vn.entry_calcCommission(commission, travelFk, currencyFk) + WHERE travelFk = NEW.id; 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 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 ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `travel_afterDelete` - AFTER DELETE ON `travel` FOR EACH ROW -BEGIN - CALL stock.log_add('travel', OLD.id, NULL); + + IF !(ABS(NEW.delivered) <=> ABS(OLD.delivered)) + THEN + INSERT INTO vn2008.travel_dits SET + idaccion_dits = 89, + Id_Trabajador = vn.getWorker(), + Id_Ticket = NEW.id, + value_old = OLD.delivered, + value_new = NEW.delivered; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51263,7 +52104,7 @@ CREATE TABLE `travel_dits` ( `idaccion_dits` int(11) NOT NULL, `ODBC_DATE` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) NOT NULL, - `Id_Trabajador` int(11) NOT NULL, + `Id_Trabajador` int(11) DEFAULT NULL, `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idtravel_dits`), @@ -51271,7 +52112,7 @@ CREATE TABLE `travel_dits` ( KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `travel_dits_ibfk_1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=217714 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=220286 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -51301,7 +52142,7 @@ CREATE TABLE `travel_pattern` ( CONSTRAINT `travel_pattern_ibfk_4` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_5` FOREIGN KEY (`warehouse_in`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_6` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=340 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=341 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -52637,13 +53478,13 @@ SET character_set_client = utf8; SET character_set_client = @saved_cs_client; -- --- Table structure for table `zeleris` +-- Table structure for table `zelerisKk` -- -DROP TABLE IF EXISTS `zeleris`; +DROP TABLE IF EXISTS `zelerisKk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `zeleris` ( +CREATE TABLE `zelerisKk` ( `codigo_postal` mediumint(8) unsigned NOT NULL, `franja` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`codigo_postal`) @@ -53662,37 +54503,6 @@ BEGIN SET bouquetId = (SELECT @vItem); RETURN bouquetId; -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 FUNCTION IF EXISTS `getComision` */; -/*!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`@`%` FUNCTION `getComision`(vEntry INT, vMoneda INT) RETURNS int(11) -BEGIN - - DECLARE vComision INT; - - SELECT IFNULL(round(-100 * (1 - (1 / rm.rate))),0) INTO vComision - FROM Entradas e - JOIN travel tr ON tr.id = e.travel_id - LEFT JOIN reference_min rm ON rm.moneda_id = vMoneda AND tr.shipment >= rm.`date` - WHERE e.Id_Entrada = vEntry - ORDER BY rm.date DESC - LIMIT 1; - - RETURN IFNULL(vComision,0); - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53819,31 +54629,38 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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`@`%` FUNCTION `has_notify_passport`(idA INT, idCompra INT) RETURNS tinyint(1) +CREATE DEFINER=`root`@`%` FUNCTION `has_notify_passport`(vItemFk INT, vBuyFk INT) RETURNS tinyint(1) + READS SQL DATA BEGIN - DECLARE has_passport BOOLEAN; - DECLARE is_already_sent BOOLEAN; - - SELECT COUNT(*) INTO has_passport FROM vn2008.botanic_export be JOIN - vn2008.Articles_botanical ab ON be.edi_genus_id = ab.genus_id - AND IFNULL(be.edi_specie_id, ab.specie_id) = ab.specie_id - AND be.restriction = 'pasaporte fitosanitario' - JOIN vn2008.Articles a ON a.Id_Article = ab.Id_Article - JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id - WHERE ab.Id_Article = idA AND t.reino_id = 2; - - IF has_passport THEN - SELECT COUNT(*) INTO is_already_sent FROM mail M - JOIN vn2008.Compres c ON c.Id_Compra = idCompra - WHERE `text` LIKE CONCAT('%',c.buy_edi_id,'%') limit 1; - END IF; - RETURN has_passport && NOT is_already_sent; + DECLARE vHasPassport BOOL; + DECLARE vIsAlreadySent BOOL; + + SELECT COUNT(*) INTO vHasPassport + FROM botanic_export be + JOIN Articles_botanical ab + ON be.edi_genus_id = ab.genus_id + AND IFNULL(be.edi_specie_id, ab.specie_id) = ab.specie_id + AND be.restriction = 'pasaporte fitosanitario' + JOIN Articles a ON a.Id_Article = ab.Id_Article + JOIN Tipos t ON t.tipo_id = a.tipo_id + WHERE ab.Id_Article = vItemFk + AND t.reino_id = 2; + + IF vHasPassport THEN + SELECT COUNT(*) INTO vIsAlreadySent + FROM mail m + JOIN Compres c ON c.Id_Compra = vBuyFk + WHERE m.`text` LIKE CONCAT('%', c.buy_edi_id, '%') + LIMIT 1; + END IF; + + RETURN vHasPassport AND NOT vIsAlreadySent; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54999,6 +55816,37 @@ DELIMITER ; /*!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 FUNCTION IF EXISTS `__getComision` */; +/*!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`@`%` FUNCTION `__getComision`(vEntry INT, vMoneda INT) RETURNS int(11) + READS SQL DATA +BEGIN + DECLARE vComision INT; + + SELECT IFNULL(ROUND(-100 * (1 - (1 / rm.rate))), 0) INTO vComision + FROM Entradas e + JOIN travel tr ON tr.id = e.travel_id + LEFT JOIN reference_min rm + ON rm.moneda_id = vMoneda AND tr.shipment >= rm.`date` + WHERE e.Id_Entrada = vEntry + ORDER BY rm.date DESC + LIMIT 1; + + RETURN IFNULL(vComision, 0); +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 `account_conciliacion_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56685,112 +57533,6 @@ DELIMITER ; /*!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 `basketAddItem` */; -/*!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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `basketAddItem`(IN `vWarehouse` INT, IN `vItem` INT, IN `vAmount` INT) -BEGIN - DECLARE vOrder INT; - DECLARE vRow INT; - DECLARE vAdd INT; - DECLARE vAvailable INT; - DECLARE vDone BOOL; - DECLARE vGrouping INT; - DECLARE vRate INT; - DECLARE vShipment DATE; - DECLARE vPrice DECIMAL(10,2); - - DECLARE cur CURSOR FOR - SELECT `grouping`, price, rate - FROM tmp.bionic_price - WHERE warehouse_id = vWarehouse - AND item_id = vItem - ORDER BY `grouping` DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - CALL bionic_from_item (vItem); - - START TRANSACTION; - - SET vOrder = myBasketGetId(); - - SELECT Fecha_envio INTO vShipment - FROM tmp.travel_tree - WHERE warehouse_id = vWarehouse; - - SELECT available INTO vAvailable - FROM tmp.bionic_lot - WHERE warehouse_id = vWarehouse - AND item_id = vItem; - - IF vAmount > vAvailable - THEN - CALL util.throw ('ORDER_ROW_UNAVAILABLE'); - END IF; - - OPEN cur; - - l: LOOP - SET vDone = FALSE; - FETCH cur INTO vGrouping, vPrice, vRate; - - IF vDone THEN - LEAVE l; - END IF; - - SET vAdd = vAmount - MOD(vAmount, vGrouping); - SET vAmount = vAmount - vAdd; - - IF vAdd = 0 THEN - ITERATE l; - END IF; - - INSERT INTO order_row SET - order_id = vOrder, - item_id = vItem, - warehouse_id = vWarehouse, - shipment = vShipment, - rate = vRate, - amount = vAdd, - price = vPrice; - - SET vRow = LAST_INSERT_ID(); - - INSERT INTO order_component (order_row_id, component_id, price) - SELECT vRow, c.component_id, c.cost - FROM tmp.bionic_component c - JOIN bi.tarifa_componentes t - ON t.Id_Componente = c.component_id - AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate) - WHERE c.warehouse_id = vWarehouse - AND c.item_id = vItem; - END LOOP; - - CLOSE cur; - COMMIT; - - CALL vn2008.bionic_free (); -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 `bionic_available_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58391,8 +59133,6 @@ Este procedimiento "rebioniza" una linea, eliminando los componentes existentes DECLARE v_agencia INT; DECLARE v_consigna INT; DECLARE v_landing DATE; - - REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente , t.warehouse_id, date(t.Fecha), Id_Consigna , Id_Agencia INTO v_customer ,v_wh, v_shipment , v_consigna , v_agencia @@ -58540,8 +59280,6 @@ Este procedimiento trata de "rebionizar" un ticket, eliminando los componentes e INTO v_ticket_free FROM Tickets WHERE Id_Ticket = v_ticket;*/ - - REPLACE order_Tickets(order_id, Id_Ticket) VALUES(48, v_ticket); SELECT Id_Cliente, t.warehouse_id, date(t.Fecha), Id_Consigna, t.Id_Agencia, landing, a.agency_id INTO v_customer, v_wh, v_shipment, v_consigna, v_agencia, v_landing, v_agency @@ -61789,12 +62527,12 @@ DELIMITER ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!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 `clean`(IN `v_full` TINYINT(1)) -BEGIN +proc: BEGIN DECLARE v_date DATETIME; DECLARE v_date18 DATETIME; DECLARE v_date8 DATE; @@ -61897,7 +62635,7 @@ BEGIN END IF; -- Tickets Nulos PAK 11/10/2016 - + UPDATE vn2008.Tickets SET empresa_id = 965 WHERE Id_Cliente = 31 @@ -61932,18 +62670,15 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `clean_launcher`() BEGIN - - call vn2008.clean(TRUE); - - + CALL clean(TRUE); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64304,33 +65039,6 @@ join warehouse w on w.id = mov.warehouse_id 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 `entradaCambioUpdate` */; -/*!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 `entradaCambioUpdate`(IN vIdEntrada INT) -BEGIN - - DECLARE vMoneda INT; - - SELECT Id_Moneda INTO vMoneda FROM Entradas WHERE Id_Entrada = vIdEntrada; - - UPDATE Entradas - SET comision = getComision(vIdEntrada, vMoneda) - WHERE Id_Entrada = vIdEntrada; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64433,29 +65141,6 @@ SET c.Cantidad = c.Cantidad - sub.Cantidad WHERE Id_Entrada = Id_Minuendo; -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 `entryComisionUpdate` */; -/*!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 `entryComisionUpdate`(IN vIdEntrada INT) -BEGIN - - UPDATE Entradas - SET comision = getComision(vIdEntrada) - WHERE Id_Entrada = vIdEntrada; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64602,29 +65287,6 @@ DELIMITER ; /*!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 `entryUpdateComision` */; -/*!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 `entryUpdateComision`(IN vIdEntrada INT) -BEGIN - - UPDATE Entradas - SET comision = getComision(vIdEntrada, Id_Moneda) - WHERE Id_Entrada = vIdEntrada; - -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 `envios_masivos` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66449,29 +67111,29 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `insert_producer_plantpassport`(IN idCompra INT) +CREATE DEFINER=`root`@`%` PROCEDURE `insert_producer_plantpassport`(vBuyFk INT) BEGIN DECLARE last_insert INTEGER; - INSERT IGNORE INTO producer (`name`) + INSERT IGNORE INTO producer(`name`) SELECT es.company_name - FROM vn2008.Compres c - JOIN vn2008.buy_edi be ON be.id = c.buy_edi_id + FROM Compres c + JOIN buy_edi be ON be.id = c.buy_edi_id JOIN edi.supplier es ON es.supplier_id = be.pro - WHERE c.Id_Compra = idCompra; + WHERE c.Id_Compra = vBuyFk; -- SELECT LAST_INSERT_ID() INTO last_insert; /* IF last_insert > 0 THEN UPDATE Articles a JOIN Compres c - ON a.Id_Article = c.Id_Article SET a.producer_id = last_insert WHERE c.Id_Compra = idCompra; + ON a.Id_Article = c.Id_Article SET a.producer_id = last_insert WHERE c.Id_Compra = vBuyFk; END IF;*/ END ;; DELIMITER ; @@ -70295,28 +70957,39 @@ 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 = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!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 `notify_passport`(IN idA INT, IN idEti SMALLINT, IN idPacking SMALLINT, IN idCompra INT) +CREATE DEFINER=`root`@`%` PROCEDURE `notify_passport`( + IN vItemFk INT, + IN vStickers SMALLINT, + IN vPacking SMALLINT, + IN vBuyFk INT +) BEGIN INSERT INTO vn2008.mail(`subject`,`text`,`to`) SELECT 'Solicitar pasaporte', - CONCAT('Etiquetas: ',ifnull(idEti,0),', Packing: ',ifnull(idPacking,0),', Nombre: ',ifnull(a.Article,0),', buy_edi: ',ifnull(be.id,0),', Nombre botánico: ', - IFNULL(g.latin_genus_name,''),' ',IFNULL(s.latin_species_name,''),' , Productor: ',IFNULL(es.company_name,IFNULL(p.`name`,''))) + CONCAT( + 'Etiquetas: ', IFNULL(vStickers, 0), + ', Packing: ', IFNULL(vPacking, 0), + ', Nombre: ', IFNULL(a.Article, 0), + ', buy_edi: ', IFNULL(be.id, 0), + ', Nombre botánico: ', IFNULL(g.latin_genus_name, ''), ' ', IFNULL(s.latin_species_name, ''), + ', Productor: ',IFNULL(es.company_name, IFNULL(p.`name`, '')) + ) ,'ekt@verdnatura.es' - FROM vn2008.Articles a - LEFT JOIN vn2008.Articles_botanical ab ON ab.Id_Article = a.Id_Article + FROM Articles a + LEFT JOIN Articles_botanical ab ON ab.Id_Article = a.Id_Article LEFT JOIN edi.genus g ON g.genus_id = ab.genus_id - LEFT JOIN edi.specie s ON IFNULL(s.specie_id,ab.specie_id) = ab.specie_id - LEFT JOIN vn2008.producer p ON p.producer_id = a.producer_id - LEFT JOIN vn2008.Compres c ON c.Id_Compra = idCompra - LEFT JOIN vn2008.buy_edi be ON c.buy_edi_id = be.id + LEFT JOIN edi.specie s ON IFNULL(s.specie_id, ab.specie_id) = ab.specie_id + LEFT JOIN producer p ON p.producer_id = a.producer_id + LEFT JOIN Compres c ON c.Id_Compra = vBuyFk + LEFT JOIN buy_edi be ON c.buy_edi_id = be.id LEFT JOIN edi.supplier es ON es.supplier_id = be.pro - WHERE a.Id_Article = idA; + WHERE a.Id_Article = vItemFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70807,6 +71480,9 @@ BEGIN FROM tmp.ticket_list tt JOIN Tickets t on t.Id_Ticket = tt.Id_Ticket LEFT JOIN vn2008.Movimientos M ON M.Id_Ticket = t.Id_Ticket + LEFT JOIN `vn`.`saleTracking` `stPrevious` + ON `stPrevious`.`saleFk` = M.Id_Movimiento + AND `stPrevious`.`stateFk` = 26 JOIN vn2008.Articles A ON A.Id_Article = M.Id_Article JOIN vn2008.Tipos tp on tp.tipo_id = A.tipo_id LEFT JOIN cache.visible v ON A.Id_Article = v.item_id AND v.calc_id = vVisibleCache @@ -70818,6 +71494,7 @@ BEGIN WHERE IFNULL(av.available,0) >= 0 AND M.Cantidad > IFNULL(v.visible,0) AND M.OK = FALSE + AND stPrevious.saleFk IS NULL AND M.Reservado = FALSE AND reino_id NOT IN (8,6) AND date(t.Fecha) = vDate @@ -75682,8 +76359,6 @@ update travel tr join Entradas e on tr.id = e.travel_id set warehouse_id_out = 1 update Tickets set warehouse_id = @w where Id_Ticket = @t; -REPLACE order_Tickets(order_id, Id_Ticket) VALUES(48,@t); - delete mc.* from Movimientos_componentes mc join Movimientos m using(Id_Movimiento) where Id_Ticket = @t; insert into Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) @@ -78826,6 +79501,54 @@ DELIMITER ; /*!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 `__entradaCambioUpdate` */; +/*!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 `__entradaCambioUpdate`(IN vIdEntrada INT) +BEGIN + + DECLARE vMoneda INT; + + SELECT Id_Moneda INTO vMoneda FROM Entradas WHERE Id_Entrada = vIdEntrada; + + UPDATE Entradas + SET comision = getComision(vIdEntrada, vMoneda) + WHERE Id_Entrada = vIdEntrada; + +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 `__entryUpdateComision` */; +/*!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 `__entryUpdateComision`(vIdEntrada INT) +BEGIN + UPDATE Entradas + SET comision = getComision(vIdEntrada, Id_Moneda) + WHERE Id_Entrada = vIdEntrada; +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 `__item_cache_cleaner` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79960,7 +80683,7 @@ CREATE TABLE `inter` ( CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=16832457 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=17175179 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80681,12 +81404,12 @@ USE `hedera`; /*!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 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `myBasket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `made`,`o`.`date_send` AS `sent`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `notes` from `hedera`.`order` `o` where (`o`.`id` = `myBasketGetId`()) */ +/*!50001 VIEW `myBasket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `made`,`o`.`date_send` AS `sent`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `notes` from `hedera`.`order` `o` where (`o`.`id` = `MYBASKET_GETID`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -80718,12 +81441,12 @@ USE `hedera`; /*!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 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `myBasketItem` AS select `r`.`id` AS `id`,`r`.`orderFk` AS `orderFk`,`r`.`warehouseFk` AS `warehouseFk`,`r`.`itemFk` AS `itemFk`,`r`.`amount` AS `amount`,`r`.`price` AS `price` from `hedera`.`orderRow` `r` where (`r`.`orderFk` = `myBasketGetId`()) */ +/*!50001 VIEW `myBasketItem` AS select `r`.`id` AS `id`,`r`.`orderFk` AS `orderFk`,`r`.`warehouseFk` AS `warehouseFk`,`r`.`itemFk` AS `itemFk`,`r`.`amount` AS `amount`,`r`.`price` AS `price` from `hedera`.`orderRow` `r` where (`r`.`orderFk` = `MYBASKET_GETID`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -81092,6 +81815,24 @@ USE `pbx`; USE `postgresql`; +-- +-- Final view structure for view `currentWorkersStats` +-- + +/*!50001 DROP VIEW IF EXISTS `currentWorkersStats`*/; +/*!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 `currentWorkersStats` AS select `b`.`business_id` AS `business_id`,`p`.`sex` AS `sex`,`p`.`name` AS `name`,`p`.`firstname` AS `firstname`,`d`.`name` AS `department`,`pc`.`category_name` AS `category_name`,`pl`.`level_name` AS `level_name`,cast(((40 * `blp`.`importepactado`) / `clt`.`hours_week`) as decimal(10,2)) AS `salarioMedio` from ((((((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`business_labour` `bl` on((`bl`.`business_id` = `b`.`business_id`))) join `vn2008`.`department` `d` on((`d`.`department_id` = `bl`.`department_id`))) join `postgresql`.`professional_category` `pc` on((`pc`.`professional_category_id` = `bl`.`professional_category_id`))) join `postgresql`.`professional_levels` `pl` on((`pl`.`professional_levels_id` = `pc`.`professional_levels_id`))) join `postgresql`.`business_labour_payroll` `blp` on((`blp`.`business_id` = `b`.`business_id`))) join `postgresql`.`calendar_labour_type` `clt` on((`clt`.`calendar_labour_type_id` = `bl`.`calendar_labour_type_id`))) where ((`b`.`date_start` <= curdate()) and (ifnull(`b`.`date_end`,curdate()) >= curdate()) and (`b`.`provider_id` = 442)) order by `blp`.`importepactado` desc */; +/*!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: `salix` -- @@ -82137,25 +82878,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `dms` AS select `g`.`id` AS `id`,`g`.`gesttip_id` AS `dmsTypeFk`,`g`.`file` AS `file`,`g`.`trabajador_id` AS `workerFk`,`g`.`warehouse_id` AS `warehouseFk`,`g`.`emp_id` AS `companyFk`,`g`.`sref` AS `reference`,`g`.`brief` AS `description`,`g`.`odbc_date` AS `created` from `vn2008`.`gestdoc` `g` */; -/*!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 `dmsTicket` --- - -/*!50001 DROP VIEW IF EXISTS `dmsTicket`*/; -/*!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 `dmsTicket` AS select `g`.`Id_Ticket` AS `ticketFk`,`g`.`gestdoc_id` AS `dmsFk` from `vn2008`.`tickets_gestdoc` `g` */; +/*!50001 VIEW `dms` AS select `g`.`id` AS `id`,`g`.`gesttip_id` AS `dmsTypeFk`,`g`.`file` AS `file`,`g`.`trabajador_id` AS `workerFk`,`g`.`warehouse_id` AS `warehouseFk`,`g`.`emp_id` AS `companyFk`,`g`.`orden` AS `priority`,`g`.`file` AS `hasFile`,`g`.`sref` AS `reference`,`g`.`brief` AS `description`,`g`.`odbc_date` AS `created` from `vn2008`.`gestdoc` `g` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82173,7 +82896,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `dmsType` AS select `g`.`id` AS `id`,`g`.`tipo` AS `name`,`g`.`path` AS `path` from `vn2008`.`gesttip` `g` */; +/*!50001 VIEW `dmsType` AS select `g`.`id` AS `id`,`g`.`tipo` AS `name`,`g`.`path` AS `path`,`g`.`readRoleFk` AS `readRoleFk`,`g`.`writeRoleFk` AS `writeRoleFk` from `vn2008`.`gesttip` `g` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83906,6 +84629,42 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `sharingCart` +-- + +/*!50001 DROP VIEW IF EXISTS `sharingCart`*/; +/*!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 `sharingCart` AS select `s`.`id` AS `id`,`s`.`Id_Trabajador` AS `workerFk`,`s`.`datSTART` AS `started`,`s`.`datEND` AS `ended`,`s`.`Id_Suplente` AS `workerSubstitute`,`s`.`odbc_date` AS `created` from `vn2008`.`sharingcart` `s` */; +/*!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 `sharingClient` +-- + +/*!50001 DROP VIEW IF EXISTS `sharingClient`*/; +/*!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 `sharingClient` AS select `s`.`id` AS `id`,`s`.`Id_Trabajador` AS `workerFk`,`s`.`datSTART` AS `started`,`s`.`datEND` AS `ended`,`s`.`Id_Cliente` AS `clientFk` from `vn2008`.`sharingclient` `s` */; +/*!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 `specialPrice` -- @@ -84104,6 +84863,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketDms` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketDms`*/; +/*!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 `ticketDms` AS select `g`.`Id_Ticket` AS `ticketFk`,`g`.`gestdoc_id` AS `dmsFk` from `vn2008`.`tickets_gestdoc` `g` */; +/*!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 `ticketDownBuffer` -- @@ -86177,4 +86954,4 @@ USE `vncontrol`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-05-08 8:59:18 +-- Dump completed on 2019-05-23 8:39:14 diff --git a/e2e/paths/05-ticket-module/12_descriptor.spec.js b/e2e/paths/05-ticket-module/12_descriptor.spec.js index 5d47d504d..e84212201 100644 --- a/e2e/paths/05-ticket-module/12_descriptor.spec.js +++ b/e2e/paths/05-ticket-module/12_descriptor.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; -describe('Ticket descriptor path', () => { +fdescribe('Ticket descriptor path', () => { const nightmare = createNightmare(); beforeAll(() => { diff --git a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js b/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js index 578073c0e..ac981d804 100644 --- a/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js +++ b/modules/client/back/methods/client/specs/activeWorkersWithRole.spec.js @@ -7,7 +7,7 @@ describe('Client activeWorkersWithRole', () => { let isSalesPerson = await app.models.Account.hasRole(result[0].id, 'salesPerson'); - expect(result.length).toEqual(11); + expect(result.length).toEqual(12); expect(isSalesPerson).toBeTruthy(); });